Skip to content
Snippets Groups Projects
Commit 4695d4aa authored by Mark Andrew Owen's avatar Mark Andrew Owen Committed by Edward Moyse
Browse files

Implement identifiable cache for MDT raw data decoding

Former-commit-id: f6bcf98f
parent e0aadc07
No related branches found
No related tags found
No related merge requests found
Showing
with 749 additions and 552 deletions
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
#include "MuonCacheCreator.h"
#include "MuonIdHelpers/MdtIdHelper.h"
/// Constructor
MuonCacheCreator::MuonCacheCreator(const std::string &name,ISvcLocator *pSvcLocator):
AthReentrantAlgorithm(name,pSvcLocator),
m_MdtCsmCacheKey("")
{
declareProperty("MdtCsmCacheKey", m_MdtCsmCacheKey);
}
MuonCacheCreator::~MuonCacheCreator() {
}
StatusCode MuonCacheCreator::initialize() {
ATH_CHECK( m_MdtCsmCacheKey.initialize(!m_MdtCsmCacheKey.key().empty()) );
ATH_CHECK( detStore()->retrieve(m_mdtIdHelper,"MDTIDHELPER") );
return StatusCode::SUCCESS;
}
StatusCode MuonCacheCreator::execute (const EventContext& ctx) const {
// Create the MDT cache container
auto maxHashMDTs = m_mdtIdHelper->stationNameIndex("BME") != -1 ?
m_mdtIdHelper->detectorElement_hash_max() : m_mdtIdHelper->module_hash_max();
ATH_CHECK(CreateContainer(m_MdtCsmCacheKey, maxHashMDTs, ctx));
ATH_MSG_INFO("Created cache container " << m_MdtCsmCacheKey);
return StatusCode::SUCCESS;
}
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
#pragma once
#include "AthenaBaseComps/AthReentrantAlgorithm.h"
#include "MuonRDO/MdtCsm_Cache.h"
class MdtIdHelper;
class MuonCacheCreator : public AthReentrantAlgorithm {
public:
/// Constructor
MuonCacheCreator(const std::string &name,ISvcLocator *pSvcLocator);
/// Destructor
virtual ~MuonCacheCreator() ;
/// Initialize the algorithm
virtual StatusCode initialize () override;
/// Execture the algorithm
virtual StatusCode execute (const EventContext& ctx) const override;
protected:
template<typename T>
StatusCode CreateContainer(const SG::WriteHandleKey<T>& , long unsigned int , const EventContext& ) const;
/// Write handle key for the MDT CSM cache container
SG::WriteHandleKey<MdtCsm_Cache> m_MdtCsmCacheKey;
/// ID helpers
const MdtIdHelper* m_mdtIdHelper = 0;
};//class MuonCacheCreator
// copied from http://acode-browser1.usatlas.bnl.gov/lxr/source/athena/InnerDetector/InDetRecAlgs/InDetPrepRawDataFormation/src/CacheCreator.h#0062
// maybe should figure out if this code can be shared
template<typename T>
StatusCode MuonCacheCreator::CreateContainer(const SG::WriteHandleKey<T>& containerKey, long unsigned int size, const EventContext& ctx) const{
if(containerKey.key().empty()){
ATH_MSG_DEBUG( "Creation of container "<< containerKey.key() << " is disabled (no name specified)");
return StatusCode::SUCCESS;
}
SG::WriteHandle<T> ContainerCacheKey(containerKey, ctx);
ATH_CHECK( ContainerCacheKey.recordNonConst ( std::make_unique<T>(IdentifierHash(size), nullptr) ));
ATH_MSG_DEBUG( "Container "<< containerKey.key() << " created to hold " << size );
return StatusCode::SUCCESS;
}
......@@ -6,6 +6,7 @@
#include "MuonByteStream/CscRdoContByteStreamCnv.h"
#include "MuonByteStream/RpcPadContByteStreamCnv.h"
#include "MuonByteStream/TgcRdoContByteStreamCnv.h"
#include "../MuonCacheCreator.h"
DECLARE_COMPONENT( Muon::MdtRawDataProvider )
DECLARE_COMPONENT( Muon::RpcRawDataProvider )
......@@ -16,3 +17,4 @@ DECLARE_CONVERTER( CscRdoContByteStreamCnv )
DECLARE_CONVERTER( RpcPadContByteStreamCnv )
DECLARE_CONVERTER( TgcRdoContByteStreamCnv )
DECLARE_COMPONENT( MuonCacheCreator )
......@@ -26,6 +26,7 @@ Muon::MDT_RawDataProviderTool::MDT_RawDataProviderTool(const std::string& t,
// template for property declaration
declareProperty ("Decoder", m_decoder);
declareProperty ("CsmContainerCacheKey", m_rdoContainerCacheKey, "Optional external cache for the CSM container");
}
......@@ -35,11 +36,6 @@ Muon::MDT_RawDataProviderTool::~MDT_RawDataProviderTool()
StatusCode Muon::MDT_RawDataProviderTool::initialize()
{
ATH_MSG_VERBOSE("Starting init");
StatusCode sc = service("ActiveStoreSvc", m_activeStore);
if ( !sc.isSuccess() ) {
ATH_MSG_FATAL("Could not get active store service");
return sc;
}
ATH_MSG_VERBOSE("Getting m_robDataProvider");
......@@ -55,7 +51,7 @@ StatusCode Muon::MDT_RawDataProviderTool::initialize()
if (detStore()->retrieve(m_muonMgr).isFailure())
{
ATH_MSG_ERROR("Cannot retrieve MuonDetectorManager");
return sc;
return StatusCode::FAILURE;
}
ATH_MSG_VERBOSE("Getting m_decoder");
......@@ -71,7 +67,7 @@ StatusCode Muon::MDT_RawDataProviderTool::initialize()
// Check if EventSelector has the ByteStreamCnvSvc
bool has_bytestream = false;
IJobOptionsSvc* jobOptionsSvc;
sc = service("JobOptionsSvc", jobOptionsSvc, false);
StatusCode sc = service("JobOptionsSvc", jobOptionsSvc, false);
if (sc.isFailure()) {
ATH_MSG_DEBUG("Could not find JobOptionsSvc");
jobOptionsSvc = 0;
......@@ -131,10 +127,8 @@ StatusCode Muon::MDT_RawDataProviderTool::initialize()
// return StatusCode::FAILURE;
//}
ATH_CHECK( m_rdoContainerCacheKey.initialize( !m_rdoContainerCacheKey.key().empty() ) );
// register the container only when the imput from ByteStream is set up
m_activeStore->setStore( &*evtStore() );
m_useContainer = (has_bytestream || m_rdoContainerKey.key() != "MDTCSM") && !m_rdoContainerKey.key().empty();
if(!m_useContainer)
......@@ -197,12 +191,7 @@ StatusCode Muon::MDT_RawDataProviderTool::convert( const std::vector<const OFFLI
StatusCode Muon::MDT_RawDataProviderTool::convert( const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs)
{
ATH_MSG_VERBOSE("convert(): " << vecRobs.size()<<" ROBFragments.");
// retrieve the container through the MuonRdoContainerManager becasue
// if the MuonByteStream CNV has to be used, the container must have been
// registered there!
m_activeStore->setStore( &*evtStore() );
if(m_useContainer==false)
{
ATH_MSG_DEBUG("Container " << m_rdoContainerKey.key()
......@@ -215,10 +204,26 @@ StatusCode Muon::MDT_RawDataProviderTool::convert( const std::vector<const OFFLI
// on the user experience
}
SG::WriteHandle<MdtCsmContainer> handle(m_rdoContainerKey);
if (handle.isPresent())
SG::WriteHandle<MdtCsmContainer> rdoContainerHandle(m_rdoContainerKey);
if (rdoContainerHandle.isPresent())
return StatusCode::SUCCESS;
auto csm = std::make_unique<MdtCsmContainer>(m_maxhashtoUse);
// here we have two paths. The first one we do not use an external cache, so just create
// the MDT CSM container and record it. For the second path, we create the container
// by passing in the container cache key so that the container is linked with the event
// wide cache.
const bool externalCacheRDO = !m_rdoContainerCacheKey.key().empty();
if (!externalCacheRDO) {
ATH_CHECK(rdoContainerHandle.record (std::make_unique<MdtCsmContainer>(m_maxhashtoUse)) );
ATH_MSG_DEBUG("Created container");
} else {
SG::UpdateHandle<MdtCsm_Cache> update(m_rdoContainerCacheKey);
ATH_CHECK(update.isValid());
ATH_CHECK(rdoContainerHandle.record (std::make_unique<MdtCsmContainer>(update.ptr())));
ATH_MSG_DEBUG("Created container using cache for " << m_rdoContainerCacheKey.key());
}
//auto csm = std::make_unique<MdtCsmContainer>(m_maxhashtoUse);
std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>::const_iterator itFrag;
......@@ -230,7 +235,7 @@ StatusCode Muon::MDT_RawDataProviderTool::convert( const std::vector<const OFFLI
//std::vector<IdentifierHash> coll =
// to_be_converted(**itFrag,collections);
if (m_decoder->fillCollections(**itFrag, *csm).isFailure())
if (m_decoder->fillCollections(**itFrag, *(rdoContainerHandle.ptr())).isFailure())
{
// store the error conditions into the StatusCode and continue
}
......@@ -247,8 +252,8 @@ StatusCode Muon::MDT_RawDataProviderTool::convert( const std::vector<const OFFLI
}
}
//in presence of errors return FAILURE
ATH_MSG_DEBUG("After processing numColls="<<csm->numberOfCollections());
ATH_CHECK( handle.record (std::move (csm)) );
ATH_MSG_DEBUG("After processing numColls="<<rdoContainerHandle.ptr()->numberOfCollections());
//ATH_CHECK( handle.record (std::move (csm)) );
return StatusCode::SUCCESS;
}
......@@ -17,11 +17,11 @@
#include "MuonCablingData/MuonMDT_CablingMap.h"
#include "StoreGate/ReadCondHandleKey.h"
#include "MuonRDO/MdtCsm_Cache.h"
class MdtCsmContainer;
class StoreGateSvc;
class ActiveStoreSvc;
class IROBDataProviderSvc;
namespace MuonGM {
......@@ -66,7 +66,6 @@ class MDT_RawDataProviderTool : virtual public IMuonRawDataProviderTool, virtual
SG::WriteHandleKey<MdtCsmContainer> m_rdoContainerKey{
this, "RdoLocation", "MDTCSM", "Name of the MDTCSM produced by RawDataProvider"};
const MuonGM::MuonDetectorManager* m_muonMgr;
ActiveStoreSvc* m_activeStore;
unsigned int m_maxhashtoUse;
bool m_useContainer;
// Rob Data Provider handle
......@@ -74,6 +73,9 @@ class MDT_RawDataProviderTool : virtual public IMuonRawDataProviderTool, virtual
SG::ReadCondHandleKey<MuonMDT_CablingMap> m_readKey{this, "ReadKey", "MuonMDT_CablingMap", "Key of MuonMDT_CablingMap"};
/// This is the key for the cache for the CSM containers, can be empty
SG::UpdateHandleKey<MdtCsm_Cache> m_rdoContainerCacheKey ;
};
}
......
......@@ -239,8 +239,6 @@ StatusCode MdtROD_Decoder::fillCollections(const OFFLINE_FRAGMENTS_NAMESPACE::RO
// }
/////////////////////////
MdtCsm* collection;
while (!m_csmReadOut->is_EOB()) {
while ((!m_csmReadOut->is_BOL()) && (!m_csmReadOut->is_EOB())) {
......@@ -348,9 +346,22 @@ StatusCode MdtROD_Decoder::fillCollections(const OFFLINE_FRAGMENTS_NAMESPACE::RO
// EJWM Removed: if ( moduleId == csmOfflineId)
// Can't see how to keep that in here now, and also not really sure what the point of it is
// Might be wrong though - job for experts to look into.
// FIXME
// FIXME
// get IdentifierHash for this module ID
auto idHash = getHash(moduleId);
// Create MdtCsm and try to get it from the cache via the IDC_WriteHandle
std::unique_ptr<MdtCsm> collection(nullptr);
MdtCsmContainer::IDC_WriteHandle lock = rdoIDC.getWriteHandle( idHash.first );
if( lock.alreadyPresent() ) {
ATH_MSG_DEBUG("collections already found, do not convert");
}else{
ATH_MSG_DEBUG(" Collection ID = " <<idHash.second.getString()
<< " does not exist, create it ");
collection = std::make_unique<MdtCsm>(idHash.second, idHash.first);
}
collection = getCollection(rdoIDC, moduleId);
// Set values (keep Identifier and IdentifierHash the same though)
if(collection) collection->set_values(collection->identify(), collection->identifyHash(), subdetId, mrodId, csmId);
......@@ -515,7 +526,7 @@ StatusCode MdtROD_Decoder::fillCollections(const OFFLINE_FRAGMENTS_NAMESPACE::RO
StationName == m_BMGid ? m_hptdcReadOut->decodeWord(vint[wordPos])
: m_amtReadOut->decodeWord(vint[wordPos]);
} // End of loop on TDCs
if(collection) ATH_CHECK(lock.addOrDelete(std::move(collection)));
// Collection has been found, go out
// return;
} // Check for the chamber offline id = collection offline id
......@@ -541,9 +552,7 @@ StatusCode MdtROD_Decoder::fillCollections(const OFFLINE_FRAGMENTS_NAMESPACE::RO
return StatusCode::SUCCESS;
}
MdtCsm* MdtROD_Decoder::getCollection (MdtCsmContainer& rdoIdc, Identifier ident) {
MdtCsm* theColl;
std::pair<IdentifierHash, Identifier> MdtROD_Decoder::getHash ( Identifier ident) {
//get hash from identifier.
IdentifierHash idHash;
Identifier regid;
......@@ -557,31 +566,7 @@ MdtCsm* MdtROD_Decoder::getCollection (MdtCsmContainer& rdoIdc, Identifier ident
regid = ident;
m_mdtIdHelper->get_module_hash(regid, idHash);
}
// Check if the Collection is already created.
MdtCsmContainer::const_iterator itColl = rdoIdc.indexFind( idHash );
if ( itColl != rdoIdc.end() ){
ATH_MSG_DEBUG("getCollection: collections already found, do not convert");
return 0;
}else{
ATH_MSG_DEBUG(" Collection ID = " <<regid.getString()
<< " does not exist, create it ");
// create new collection
theColl = new MdtCsm ( regid, idHash );
// add collection into IDC
StatusCode sc = rdoIdc.addCollection(theColl, idHash);
if ( sc.isFailure() )
{
ATH_MSG_WARNING("getCollection: Failed to add RDO collection to container");
delete theColl;
return 0;
}
}
return theColl;
return std::make_pair(idHash, regid);
}
......
......@@ -74,9 +74,9 @@ public:
StatusCode fillCollections(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment& robFrag,
MdtCsmContainer& rdoIDC);
int specialROBNumber() {return m_specialROBNumber;}
int specialROBNumber() const {return m_specialROBNumber;}
MdtCsm* getCollection (MdtCsmContainer& rdoIdc, Identifier ident);
std::pair<IdentifierHash, Identifier> getHash (Identifier ident);
private:
......
......@@ -2,7 +2,7 @@
# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
#
from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
from AthenaCommon.Constants import DEBUG, INFO
from AthenaCommon.Constants import VERBOSE, DEBUG, INFO
## This configuration function sets up everything for decoding RPC bytestream data into RDOs
#
......@@ -10,7 +10,7 @@ from AthenaCommon.Constants import DEBUG, INFO
# The function returns a ComponentAccumulator and the data-decoding algorithm, which should be added to the right sequence by the user
def RpcBytestreamDecodeCfg(flags, forTrigger=False):
acc = ComponentAccumulator()
# We need the RPC cabling to be setup
from MuonConfig.MuonCablingConfig import RPCCablingConfigCfg
acc.merge( RPCCablingConfigCfg(flags)[0] )
......@@ -82,6 +82,12 @@ def TgcBytestreamDecodeCfg(flags, forTrigger=False):
def MdtBytestreamDecodeCfg(flags, forTrigger=False):
acc = ComponentAccumulator()
# Configure the IdentifiableCaches when running for trigger
if forTrigger:
from MuonByteStream.MuonByteStreamConf import MuonCacheCreator
cacheCreator = MuonCacheCreator(MdtCsmCacheKey= "MdtCsmCache")
acc.addEventAlgo( cacheCreator )
# We need the MDT cabling to be setup
from MuonConfig.MuonCablingConfig import MDTCablingConfigCfg
acc.merge( MDTCablingConfigCfg(flags)[0] )
......@@ -105,7 +111,11 @@ def MdtBytestreamDecodeCfg(flags, forTrigger=False):
# Setup the RAW data provider tool
from MuonMDT_CnvTools.MuonMDT_CnvToolsConf import Muon__MDT_RawDataProviderTool
MuonMdtRawDataProviderTool = Muon__MDT_RawDataProviderTool(name = "MDT_RawDataProviderTool",
Decoder = MDTRodDecoder )
Decoder = MDTRodDecoder,
OutputLevel = VERBOSE)
if forTrigger:
MuonMdtRawDataProviderTool.CsmContainerCacheKey = "MdtCsmCache"
acc.addPublicTool( MuonMdtRawDataProviderTool ) # This should be removed, but now defined as PublicTool at MuFastSteering
# Setup the RAW data provider algorithm
......@@ -148,7 +158,6 @@ def CscBytestreamDecodeCfg(flags, forTrigger=False):
return acc, CscRawDataProvider
if __name__=="__main__":
# To run this, do e.g.
# python ../athena/MuonSpectrometer/MuonConfig/python/MuonBytestreamDecodeCfg.py
......@@ -158,7 +167,6 @@ if __name__=="__main__":
from AthenaConfiguration.AllConfigFlags import ConfigFlags
from AthenaConfiguration.TestDefaults import defaultTestFiles
ConfigFlags.Input.Files = defaultTestFiles.RAW
# Set global tag by hand for now
ConfigFlags.IOVDb.GlobalTag = "CONDBR2-BLKPA-2018-13"#"CONDBR2-BLKPA-2015-17"
......
......@@ -127,7 +127,6 @@ def CSCCablingConfigCfg(flags):
return acc, cscCablingSvc
if __name__ == '__main__':
from AthenaCommon.Configurable import Configurable
Configurable.configurableRun3Behavior=1
......
......@@ -155,8 +155,8 @@ def muonRdoDecodeTestData():
from AthenaConfiguration.AllConfigFlags import ConfigFlags
from AthenaConfiguration.TestDefaults import defaultTestFiles
ConfigFlags.Input.Files = defaultTestFiles.RAW
# Set global tag by hand for now
ConfigFlags.IOVDb.GlobalTag = "CONDBR2-BLKPA-2018-13"#"CONDBR2-BLKPA-2015-17"
ConfigFlags.GeoModel.AtlasVersion = "ATLAS-R2-2016-01-00-01"#"ATLAS-R2-2015-03-01-00"
......
This diff is collapsed.
......@@ -10,9 +10,11 @@
#include <string>
#include "MuonRDO/MdtCsm.h"
#include "MuonRDO/MdtCsmIdHash.h"
#include "MuonRDO/MdtCsm_Cache.h"
#include "AthenaKernel/CLASS_DEF.h"
#include "EventContainers/IdentifiableContainer.h"
/** This container provides acces to the MDT RDOs
@author Stefano Rosati, Mar 2003
*/
......@@ -20,7 +22,8 @@ class MdtCsmContainer
:public IdentifiableContainer<MdtCsm> {
public:
MdtCsmContainer() ;
MdtCsmContainer( unsigned int hashmax) ;
MdtCsmContainer( unsigned int hashmax) ;
MdtCsmContainer( MdtCsm_Cache* cache );
~MdtCsmContainer() ;
typedef MdtCsm::size_type size_type ;
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
#pragma once
#include "EventContainers/IdentifiableCache.h"
#include "MuonRDO/MdtCsm.h"
typedef EventContainers::IdentifiableCache< MdtCsm> MdtCsm_Cache;
CLASS_DEF( MdtCsm_Cache , 50449555 , 1 )
......@@ -23,4 +23,7 @@
#include "MuonRDO/TgcRdo.h"
#include "MuonRDO/CscRawDataCollection.h"
// cache
#include "MuonRDO/MdtCsm_Cache.h"
#endif
......@@ -58,6 +58,7 @@
<class name="MdtCsmContainer" />
<class name="std::vector<MdtCsm * >" />
<class name="DataVector<MdtCsm>" id="CFDA6FF6-557F-40CB-9C54-B5A7404A9175" />
<class name="MdtCsm_Cache" />
<class name="RpcPadContainer" />
<class name="std::vector<RpcPad * >" />
......
......@@ -40,6 +40,15 @@ MdtCsmContainer::MdtCsmContainer(unsigned int hashmax)
//**********************************************************************
//**********************************************************************
MdtCsmContainer::MdtCsmContainer(MdtCsm_Cache* cache)
: IdentifiableContainer<MdtCsm>(cache)
{
}
//**********************************************************************
// Destructor.
MdtCsmContainer::~MdtCsmContainer() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment