diff --git a/LArCalorimeter/LArRecConditions/LArRecConditions/LArOnOffIdMapping.h b/LArCalorimeter/LArRecConditions/LArRecConditions/LArOnOffIdMapping.h new file mode 100644 index 0000000000000000000000000000000000000000..e24e17f856f19466b4fada122cda114bdf1cbb5c --- /dev/null +++ b/LArCalorimeter/LArRecConditions/LArRecConditions/LArOnOffIdMapping.h @@ -0,0 +1,126 @@ +//Dear emacs, this is -*-c++-*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef LARONOFFIDMAPPING_H +#define LARONOFFIDMAPPING_H + +#include "Identifier/HWIdentifier.h" +#include "Identifier/Identifier.h" +#include "Identifier/IdentifierHash.h" + +#include "CaloIdentifier/CaloCell_Base_ID.h" +#include "LArIdentifier/LArOnlineID_Base.h" + +#include <vector> + +class LArOnOffIdMapping { + + friend class LArOnOffMappingAlg; //The conditions alg filling this object + + public: + LArOnOffIdMapping()=delete; + + LArOnOffIdMapping(const LArOnlineID_Base* onlineId, const CaloCell_Base_ID * m_caloId); + + /** + * create a HWIdentifier from an Identifier (not inline)<br> + * + */ + HWIdentifier createSignalChannelID(const Identifier & id) const; + + + /** + * create a HWIdentifier from an Identifier (from hash) (inline)<br> + * + */ + HWIdentifier createSignalChannelIDFromHash(const IdentifierHash & id_hash) const; + + /** + * create an Identifier from a HWIdentifier (inline) <br> + * + */ + Identifier cnvToIdentifier(const HWIdentifier & sid) const; + + /** + * create an Identifier from a HWIdentifier (from hash) (inline) <br> + */ + Identifier cnvToIdentifierFromHash(const IdentifierHash & sid_hash) const; + + /** + * Test whether a HWIdentifier is connected of not (by online hash) (inline) <br> + */ + bool isOnlineConnectedFromHash(const IdentifierHash & sid_hash ) const; + + /** + * Test whether a HWIdentifier is connected of not (inline)<br> + */ + bool isOnlineConnected(const HWIdentifier & sid ) const; + + + + private: + const LArOnlineID_Base * m_onlineId ; + const CaloCell_Base_ID * m_caloId; + + std::vector<Identifier> m_onlHashToOffline; + std::vector<HWIdentifier> m_oflHashToOnline; + + ///Invalid default instance of Identifier + const Identifier m_idEmpty; + + ///Invalid default instance of HWIdentifier + const HWIdentifier m_hwidEmpty; + +}; + + +//Inline methods: + +inline bool LArOnOffIdMapping::isOnlineConnectedFromHash(const IdentifierHash & sid_hash ) const { + if (sid_hash <m_onlHashToOffline.size()) + return (m_idEmpty!=m_onlHashToOffline[sid_hash]); + + return false; +} + + +inline HWIdentifier LArOnOffIdMapping::createSignalChannelIDFromHash(const IdentifierHash & id_hash) const { + return m_oflHashToOnline[id_hash]; +} + + +inline Identifier LArOnOffIdMapping::cnvToIdentifierFromHash(const IdentifierHash & sid_hash) const { + if (sid_hash <m_onlHashToOffline.size()) + return m_onlHashToOffline[sid_hash]; + + return m_idEmpty; +} + +inline Identifier LArOnOffIdMapping::cnvToIdentifier(const HWIdentifier & sid) const { + const IdentifierHash sid_hash=m_onlineId->channel_Hash(sid); + return this->cnvToIdentifierFromHash(sid_hash); + } + +inline bool LArOnOffIdMapping::isOnlineConnected(const HWIdentifier & sid ) const { + const IdentifierHash sid_hash=m_onlineId->channel_Hash(sid); + return this->isOnlineConnectedFromHash(sid_hash); +} + +inline HWIdentifier LArOnOffIdMapping::createSignalChannelID(const Identifier & id) const { + const IdentifierHash id_hash=m_caloId->calo_cell_hash(id); + return this->createSignalChannelIDFromHash(id_hash); +} + + + +#include "CLIDSvc/CLASS_DEF.h" +CLASS_DEF( LArOnOffIdMapping,148608605 , 1) +#include "AthenaKernel/CondCont.h" +CLASS_DEF( CondCont<LArOnOffIdMapping>, 155467877 , 0) +#include "SGTools/BaseInfo.h" +SG_BASE( CondCont<LArOnOffIdMapping>, CondContBase ); + +#endif diff --git a/LArCalorimeter/LArRecConditions/src/LArOnOffIdMapping.cxx b/LArCalorimeter/LArRecConditions/src/LArOnOffIdMapping.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ac195e59e113b01ec08e91980cee1bdadf56e319 --- /dev/null +++ b/LArCalorimeter/LArRecConditions/src/LArOnOffIdMapping.cxx @@ -0,0 +1,15 @@ +#include "LArRecConditions/LArOnOffIdMapping.h" + +LArOnOffIdMapping::LArOnOffIdMapping(const LArOnlineID_Base* onlineId, const CaloCell_Base_ID * caloId) : + + m_onlineId(onlineId), + m_caloId(caloId) + +{ + unsigned nChan=m_onlineId->channelHashMax(); + m_onlHashToOffline.assign(nChan,m_idEmpty); + m_oflHashToOnline.assign(nChan,m_hwidEmpty); + +} + + diff --git a/LArCalorimeter/LArRecUtils/CMakeLists.txt b/LArCalorimeter/LArRecUtils/CMakeLists.txt index f3808e3f818eb2ded88d601010e9533a53e54c5d..5e11ebc443f6de0d5632899d89e48e73e73bc109 100644 --- a/LArCalorimeter/LArRecUtils/CMakeLists.txt +++ b/LArCalorimeter/LArRecUtils/CMakeLists.txt @@ -31,6 +31,7 @@ atlas_depends_on_subdirs( PUBLIC Control/SGTools Event/xAOD/xAODEventInfo LArCalorimeter/LArCOOLConditions + LArCalorimeter/LArRecConditions LArCalorimeter/LArRawUtils Tools/PathResolver ) @@ -46,13 +47,13 @@ atlas_add_library( LArRecUtilsLib INCLUDE_DIRS ${CORAL_INCLUDE_DIRS} PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} PRIVATE_DEFINITIONS ${CLHEP_DEFINITIONS} - LINK_LIBRARIES ${CORAL_LIBRARIES} CaloEvent CaloIdentifier AthenaBaseComps AthenaKernel AthAllocators AthenaPoolUtilities Identifier GaudiKernel LArIdentifier LArRawConditions LArRawEvent LArRecEvent CaloDetDescrLib CaloUtilsLib StoreGateLib SGtests LArCablingLib LArRawUtilsLib + LINK_LIBRARIES ${CORAL_LIBRARIES} CaloEvent CaloIdentifier AthenaBaseComps AthenaKernel AthAllocators AthenaPoolUtilities Identifier GaudiKernel LArIdentifier LArRawConditions LArRawEvent LArRecEvent CaloDetDescrLib CaloUtilsLib StoreGateLib SGtests LArCablingLib LArRawUtilsLib LArRecConditions PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} ${CLHEP_LIBRARIES} TestTools CaloGeoHelpers SGTools xAODEventInfo LArCOOLConditions PathResolver ) atlas_add_component( LArRecUtils src/components/*.cxx INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} - LINK_LIBRARIES ${Boost_LIBRARIES} ${CORAL_LIBRARIES} ${CLHEP_LIBRARIES} CaloDetDescrLib CaloEvent CaloIdentifier CaloUtilsLib AthenaBaseComps AthenaKernel AthAllocators StoreGateLib SGtests AthenaPoolUtilities Identifier GaudiKernel LArCablingLib LArIdentifier LArRawConditions LArRawEvent LArRecEvent TestTools CaloGeoHelpers SGTools xAODEventInfo LArCOOLConditions LArRawUtilsLib PathResolver LArRecUtilsLib ) + LINK_LIBRARIES ${Boost_LIBRARIES} ${CORAL_LIBRARIES} ${CLHEP_LIBRARIES} CaloDetDescrLib CaloEvent CaloIdentifier CaloUtilsLib AthenaBaseComps AthenaKernel AthAllocators StoreGateLib SGtests AthenaPoolUtilities Identifier GaudiKernel LArCablingLib LArIdentifier LArRawConditions LArRawEvent LArRecEvent TestTools CaloGeoHelpers SGTools xAODEventInfo LArCOOLConditions LArRawUtilsLib PathResolver LArRecUtilsLib LArRecConditions) atlas_add_test( dummy_test SOURCES diff --git a/LArCalorimeter/LArRecUtils/share/LArOnOffMappingAlg.py b/LArCalorimeter/LArRecUtils/share/LArOnOffMappingAlg.py new file mode 100644 index 0000000000000000000000000000000000000000..c7977df82dfebb8e9541a54bf75a8f2b68b59171 --- /dev/null +++ b/LArCalorimeter/LArRecUtils/share/LArOnOffMappingAlg.py @@ -0,0 +1,11 @@ +include.block("LArRecConditions/LArOnOffMappingAlg.py") + +from IOVDbSvc.CondDB import conddb +conddb.addFolder("LAR","/LAR/Identifier/OnOffIdMap",className="AthenaAttributeList") + +condSequence = AthSequencer("AthCondSeq") +from LArRecUtils.LArRecUtilsConf import LArOnOffMappingAlg + +condSequence+=LArOnOffMappingAlg(ReadKey="/LAR/Identifier/OnOffIdMap",OutputLevel=DEBUG) + + diff --git a/LArCalorimeter/LArRecUtils/src/LArOnOffMappingAlg.cxx b/LArCalorimeter/LArRecUtils/src/LArOnOffMappingAlg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a1d3753a5a56de6c4f7c2d64e93e467361e1a3c8 --- /dev/null +++ b/LArCalorimeter/LArRecUtils/src/LArOnOffMappingAlg.cxx @@ -0,0 +1,149 @@ +//dear emacs, this is -*-c++-*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "LArOnOffMappingAlg.h" +#include "AthenaPoolUtilities/AthenaAttributeList.h" +#include "CoralBase/Blob.h" + +#include "CaloIdentifier/CaloCell_ID.h" +#include "CaloIdentifier/CaloCell_SuperCell_ID.h" +#include "LArIdentifier/LArOnlineID.h" +#include "LArIdentifier/LArOnline_SuperCellID.h" + + +LArOnOffMappingAlg::LArOnOffMappingAlg(const std::string& name, ISvcLocator* pSvcLocator) : + AthAlgorithm(name, pSvcLocator), + m_readKey("/LAr/Identifier/LArOnOnffMap"), + m_writeKey("LArOnOffMap","LArOnOffMap"), + m_condSvc("CondSvc",name), + m_isSuperCell(false) +{ + declareProperty("ReadKey",m_readKey); + declareProperty("WriteKey",m_writeKey); + declareProperty("isSuperCell",m_isSuperCell,"switch to true to use the SuperCell Identfier helper"); +} + +LArOnOffMappingAlg::~LArOnOffMappingAlg() {} + +StatusCode LArOnOffMappingAlg::initialize() { + + ATH_MSG_DEBUG("initializing"); + + // CondSvc + ATH_CHECK( m_condSvc.retrieve() ); + // Read Handles + ATH_CHECK( m_readKey.initialize() ); + ATH_CHECK( m_writeKey.initialize() ); + // Register write handle + if (m_condSvc->regHandle(this, m_writeKey, m_writeKey.dbKey()).isFailure()) { + ATH_MSG_ERROR("unable to register WriteCondHandle " << m_writeKey.fullKey() << " with CondSvc"); + return StatusCode::FAILURE; + } + return StatusCode::SUCCESS; +} + + +StatusCode LArOnOffMappingAlg::execute() { + + + ATH_MSG_DEBUG("executing"); + + SG::WriteCondHandle<LArOnOffIdMapping> writeHandle{m_writeKey}; + + if (writeHandle.isValid()) { + writeHandle.updateStore(); //???? + ATH_MSG_WARNING("Found valid write handle"); + return StatusCode::SUCCESS; + } + + SG::ReadCondHandle<AthenaAttributeList> readHandle{m_readKey}; + const AthenaAttributeList* attr{*readHandle}; + + if (attr==nullptr) { + ATH_MSG_ERROR("Failed to retrieve CondAttributeListCollection with key " << m_readKey.key()); + return StatusCode::FAILURE; + } + + const LArOnlineID_Base* larOnlineID=nullptr; + const CaloCell_Base_ID* calocellID=nullptr; + + //Identifier helper: + if (m_isSuperCell) { + //SG::ReadCondHandle<LArOnline_SuperCellID> larOnlineHdl{m_larSCOnlineIDKey} + const LArOnline_SuperCellID* scidhelper; + ATH_CHECK(detStore()->retrieve(scidhelper,"LArOnline_SuperCellID")); + larOnlineID=scidhelper; //cast to base-class + + const CaloCell_SuperCell_ID* sccaloid; + ATH_CHECK(detStore()->retrieve(sccaloid,"CaloCell_SuperCell_ID")); + calocellID=sccaloid; //cast to base-class + + } + else {//regular cells + //SG::ReadCondHandle<LArOnlineID> larOnlineHdl{m_larOnlineIDKey}; + const LArOnlineID* idhelper; + ATH_CHECK(detStore()->retrieve(idhelper,"LArOnlineID")); + larOnlineID=idhelper; //cast to base-class + + const CaloCell_ID* sccaloid; + ATH_CHECK(detStore()->retrieve(sccaloid,"CaloCell_ID")); + calocellID=sccaloid; //cast to base-class + + } + + + std::unique_ptr<LArOnOffIdMapping> onOffMap=std::make_unique<LArOnOffIdMapping>(larOnlineID,calocellID); + + const coral::Blob& blobOnOff=(*attr)["OnlineHashToOfflineId"].data<coral::Blob>(); + unsigned nChan=blobOnOff.size()/sizeof(uint32_t); + const uint32_t* pBlobOnOff=static_cast<const uint32_t*>(blobOnOff.startingAddress()); + + if (nChan!=larOnlineID->channelHashMax()) { + ATH_MSG_ERROR("Number of channels read from DB (" << nChan << ") does not match online hash max (" + <<larOnlineID->channelHashMax() << ")"); + return StatusCode::FAILURE; + } + + + unsigned nConnected=0; + + for (unsigned i=0;i<nChan;++i) { + const Identifier id=Identifier(Identifier32(pBlobOnOff[i])); + //std::cout << "id[" << i <<"] " << std::hex << id.get_compact() << std::dec << std::endl; + if (id.is_valid()) { + const IdentifierHash oflHash=calocellID->calo_cell_hash(id); + const HWIdentifier hwid=larOnlineID->channel_Id(IdentifierHash(i)); + ++nConnected; + onOffMap->m_onlHashToOffline[i]=id; + onOffMap->m_oflHashToOnline[oflHash]=hwid; + } + }//end loop over channels + + ATH_MSG_INFO("Done reading online/offline identifier mapping"); + ATH_MSG_INFO("Found " << nChan << " online identifier and " << nConnected << " offline identifier. " + << nChan-nConnected << " disconnected channels."); + + + // Define validity of the output cond object and record it + EventIDRange rangeW; + if(!readHandle.range(rangeW)) { + ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle.key()); + return StatusCode::FAILURE; + } + + if(writeHandle.record(rangeW,onOffMap.release()).isFailure()) { + ATH_MSG_ERROR("Could not record LArOnOffMapping object with " + << writeHandle.key() + << " with EventRange " << rangeW + << " into Conditions Store"); + return StatusCode::FAILURE; + } + ATH_MSG_INFO("recorded new " << writeHandle.key() << " with range " << rangeW << " into Conditions Store"); + + + return StatusCode::SUCCESS; +} + diff --git a/LArCalorimeter/LArRecUtils/src/LArOnOffMappingAlg.h b/LArCalorimeter/LArRecUtils/src/LArOnOffMappingAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..502de861d7c175cacd944c53a79ca2734630bb0f --- /dev/null +++ b/LArCalorimeter/LArRecUtils/src/LArOnOffMappingAlg.h @@ -0,0 +1,39 @@ +//Dear emacs, this is -*- C++ -*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef LARRECCONDITIONS_LARONOFFMAPPINGALG_H +#define LARRECCONDITIONS_LARONOFFMAPPINGALG_H + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/ReadCondHandleKey.h" +#include "StoreGate/WriteCondHandleKey.h" +#include "GaudiKernel/ICondSvc.h" + +#include "AthenaPoolUtilities/CondAttrListCollection.h" +#include "LArRecConditions/LArOnOffIdMapping.h" + +class LArOnOffMappingAlg: public AthAlgorithm { + +public: + + LArOnOffMappingAlg(const std::string& name, ISvcLocator* pSvcLocator); + ~LArOnOffMappingAlg(); + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize() {return StatusCode::SUCCESS;} + + private: + SG::ReadCondHandleKey<AthenaAttributeList> m_readKey; + SG::WriteCondHandleKey<LArOnOffIdMapping> m_writeKey; + ServiceHandle<ICondSvc> m_condSvc; + bool m_isSuperCell; + +}; + + + +#endif diff --git a/LArCalorimeter/LArRecUtils/src/components/LArRecUtils_entries.cxx b/LArCalorimeter/LArRecUtils/src/components/LArRecUtils_entries.cxx index 65f7829c7d0c965470c428423f42329903c4b1f2..b8dce120f1c287ea8fb7be3a98d9d94f89432c20 100755 --- a/LArCalorimeter/LArRecUtils/src/components/LArRecUtils_entries.cxx +++ b/LArCalorimeter/LArRecUtils/src/components/LArRecUtils_entries.cxx @@ -18,6 +18,7 @@ #include "../LArFCalTowerBuilderToolTestAlg.h" #include "../LArHVScaleRetriever.h" #include "../LArFlatConditionsAlg.h" +#include "../LArOnOffMappingAlg.h" DECLARE_TOOL_FACTORY( LArADC2MeVTool ) DECLARE_TOOL_FACTORY( LArAutoCorrNoiseTool ) @@ -55,7 +56,7 @@ DECLARE_ALGORITHM_FACTORY( LArCondAlgShapeSC) DECLARE_ALGORITHM_FACTORY( LArCondAlgfSamplSC) DECLARE_ALGORITHM_FACTORY( LArCondAlguA2MeVFlat) DECLARE_ALGORITHM_FACTORY( LArCondAlguA2MeVSC) - +DECLARE_ALGORITHM_FACTORY( LArOnOffMappingAlg)