From 9ab4bc6999348a76466ad38a98d2d4de495aba88 Mon Sep 17 00:00:00 2001 From: scott snyder <sss@karma> Date: Sun, 22 Nov 2020 21:39:21 -0500 Subject: [PATCH] MuonTGC_CnvTools: Preparing to make TGC_RawDataProviderTool* const. Update TGC_RawDataProviderTool and TGC_RawDataProviderToolMT so that the interfaces can be made const. --- .../MuonCnv/MuonTGC_CnvTools/CMakeLists.txt | 2 +- .../MuonTGC_CnvTools/src/TGC_Hid2RESrcID.cxx | 22 +++---- .../MuonTGC_CnvTools/src/TGC_Hid2RESrcID.h | 20 +++---- .../src/TGC_RawDataProviderTool.cxx | 5 -- .../src/TGC_RawDataProviderToolCore.cxx | 57 ++++++++++--------- .../src/TGC_RawDataProviderToolCore.h | 5 +- .../src/TGC_RawDataProviderToolMT.cxx | 5 -- 7 files changed, 49 insertions(+), 67 deletions(-) diff --git a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/CMakeLists.txt b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/CMakeLists.txt index 02aaea33049..e5ab45b5ce9 100644 --- a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/CMakeLists.txt +++ b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/CMakeLists.txt @@ -19,7 +19,7 @@ atlas_add_component( MuonTGC_CnvTools src/*.cxx src/components/*.cxx INCLUDE_DIRS ${TDAQ-COMMON_INCLUDE_DIRS} - LINK_LIBRARIES ${TDAQ-COMMON_LIBRARIES} ByteStreamCnvSvcBaseLib ByteStreamData ByteStreamData_test GaudiKernel AthenaBaseComps Identifier EventPrimitives TGCcablingInterfaceLib MuonReadoutGeometry MuonDigitContainer MuonIdHelpersLib MuonRDO MuonPrepRawData MuonTrigCoinData TrkSurfaces MuonCnvToolInterfacesLib MuonTGC_CnvToolsLib ByteStreamCnvSvcLib ) + LINK_LIBRARIES ${TDAQ-COMMON_LIBRARIES} ByteStreamCnvSvcBaseLib ByteStreamData ByteStreamData_test GaudiKernel AthenaBaseComps Identifier EventPrimitives TGCcablingInterfaceLib MuonReadoutGeometry MuonDigitContainer MuonIdHelpersLib MuonRDO MuonPrepRawData MuonTrigCoinData TrkSurfaces MuonCnvToolInterfacesLib MuonTGC_CnvToolsLib ByteStreamCnvSvcLib CxxUtils ) # Install files from the package: atlas_install_joboptions( share/*.py ) diff --git a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_Hid2RESrcID.cxx b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_Hid2RESrcID.cxx index 5c49d5c5f83..26d493ce28f 100644 --- a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_Hid2RESrcID.cxx +++ b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_Hid2RESrcID.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "TGC_Hid2RESrcID.h" @@ -12,15 +12,8 @@ #include "eformat/SourceIdentifier.h" using eformat::helper::SourceIdentifier; -// Initialize the cabling service. -void Muon::TGC_Hid2RESrcID::set(const ITGCcablingSvc* p_cabling) { - m_cabling=p_cabling; - m_robIDs.clear(); - this->fillAllRobIds(); -} - // get source ID for a RDO -uint32_t Muon::TGC_Hid2RESrcID::getRodID(const TgcRdo *rdo) +uint32_t Muon::TGC_Hid2RESrcID::getRodID(const TgcRdo *rdo) const { // get Source ID SourceIdentifier sid(static_cast<eformat::SubDetector>(rdo->subDetectorId()), @@ -31,7 +24,7 @@ uint32_t Muon::TGC_Hid2RESrcID::getRodID(const TgcRdo *rdo) } // get source ID for a RDO -uint32_t Muon::TGC_Hid2RESrcID::getRodID(uint16_t subDetectorId, uint16_t rodId) +uint32_t Muon::TGC_Hid2RESrcID::getRodID(uint16_t subDetectorId, uint16_t rodId) const { // get Source ID SourceIdentifier sid(static_cast<eformat::SubDetector>(subDetectorId), rodId); @@ -41,11 +34,12 @@ uint32_t Muon::TGC_Hid2RESrcID::getRodID(uint16_t subDetectorId, uint16_t rodId) } // get source ID for an TgcDigitCollection -uint32_t Muon::TGC_Hid2RESrcID::getRodID(const Identifier& offlineId) const +uint32_t Muon::TGC_Hid2RESrcID::getRodID(const Identifier& offlineId, + const ITGCcablingSvc* cabling) const { int subDetectorId; int rodId; - m_cabling->getReadoutIDfromElementID(offlineId,subDetectorId,rodId); + cabling->getReadoutIDfromElementID(offlineId,subDetectorId,rodId); // get Source ID SourceIdentifier sid(static_cast<eformat::SubDetector>(subDetectorId), @@ -64,7 +58,7 @@ uint32_t Muon::TGC_Hid2RESrcID::getRobID(uint32_t rod_id) const } // mapping SrcID from ROB to ROS -uint32_t Muon::TGC_Hid2RESrcID::getRosID(uint32_t rob_id) +uint32_t Muon::TGC_Hid2RESrcID::getRosID(uint32_t rob_id) const { // Change Module Type to ROS, moduleid = 0 SourceIdentifier id(rob_id); @@ -75,7 +69,7 @@ uint32_t Muon::TGC_Hid2RESrcID::getRosID(uint32_t rob_id) } // mapping SrcID from ROS to Det -uint32_t Muon::TGC_Hid2RESrcID::getDetID(uint32_t ros_id) +uint32_t Muon::TGC_Hid2RESrcID::getDetID(uint32_t ros_id) const { // ROS to DET SourceIdentifier id(ros_id); diff --git a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_Hid2RESrcID.h b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_Hid2RESrcID.h index bdfc65c1dd5..695f81369ba 100644 --- a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_Hid2RESrcID.h +++ b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_Hid2RESrcID.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef MUONTGC_CNVTOOLS_TGC_HID2RESRCID @@ -30,36 +30,32 @@ namespace Muon public: /** Constrcutor */ - TGC_Hid2RESrcID () : m_cabling(0) {} + TGC_Hid2RESrcID () {} /** Destrcutor */ ~TGC_Hid2RESrcID () {} - /** Initialize the cabling service. */ - void set(const ITGCcablingSvc* p_cabling); - /** Make a ROD Source ID for TGC RDO. */ - uint32_t getRodID(const TgcRdo *rdo); + uint32_t getRodID(const TgcRdo *rdo) const; /** Make a ROD Source ID for SubDetector ID and ROD ID. */ - uint32_t getRodID(uint16_t subDetectorId, uint16_t rodId); + uint32_t getRodID(uint16_t subDetectorId, uint16_t rodId) const; /** Make a ROD Source ID for TgcDigitCollection. */ - uint32_t getRodID(const Identifier & offlineId) const; + uint32_t getRodID(const Identifier & offlineId, + const ITGCcablingSvc* cabling) const; /** Make a ROB Source ID from a ROD source ID. */ uint32_t getRobID (uint32_t rod_id) const; /** Make a ROS Source ID from a ROB source ID. */ - uint32_t getRosID (uint32_t rob_id); + uint32_t getRosID (uint32_t rob_id) const; /** Make a SubDetector ID from ROS source ID. */ - uint32_t getDetID (uint32_t ros_id); + uint32_t getDetID (uint32_t ros_id) const; /** Return all the ROB IDs. */ const std::vector<uint32_t>& allRobIds() const { return m_robIDs; } - private: /** Fill all the ROB IDs. */ void fillAllRobIds(); private: - const ITGCcablingSvc * m_cabling; std::vector<uint32_t> m_robIDs; }; diff --git a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderTool.cxx b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderTool.cxx index 811ae265151..3ee1703ce31 100644 --- a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderTool.cxx +++ b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderTool.cxx @@ -77,11 +77,6 @@ StatusCode Muon::TGC_RawDataProviderTool::convert(){ StatusCode Muon::TGC_RawDataProviderTool::convert(const EventContext& ctx) const { - if(!m_cabling) { - ATH_MSG_ERROR("Tgc cabling is not available and needs to be set in initialise"); - return StatusCode::FAILURE; - } - std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> vecOfRobf; const std::vector<uint32_t>& robIds = m_hid2re.allRobIds(); diff --git a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderToolCore.cxx b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderToolCore.cxx index b434fb4ef41..ff7b560e501 100644 --- a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderToolCore.cxx +++ b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderToolCore.cxx @@ -14,7 +14,6 @@ Muon::TGC_RawDataProviderToolCore::TGC_RawDataProviderToolCore( const std::string& n, const IInterface* p) : AthAlgTool(t, n, p), - m_cabling(nullptr), m_robDataProvider("ROBDataProviderSvc",n) { } @@ -38,11 +37,12 @@ StatusCode Muon::TGC_RawDataProviderToolCore::initialize() ATH_CHECK(m_rdoContainerKey.initialize()); //try to configure the cabling service - StatusCode sc = getCabling(); - if(sc.isFailure()) { - ATH_MSG_ERROR( "TGCcablingServerSvc not yet configured, but this needs to be available when TGC_RawDataProviderToolCore is initalised as we cannot create it on the fly during event processing inside const decode functions."); - return StatusCode::FAILURE; + if (!getCabling()) { + // ??? Is deferred initialization still needed here? + ATH_MSG_INFO( "TGCcablingServerSvc not yet configured; postpone TGCcabling initialization at first event. " ); } + + m_hid2re.fillAllRobIds(); return StatusCode::SUCCESS; } @@ -72,36 +72,37 @@ StatusCode Muon::TGC_RawDataProviderToolCore::convertIntoContainer(const std::ve return StatusCode::SUCCESS; } -StatusCode Muon::TGC_RawDataProviderToolCore::getCabling() { - const ITGCcablingServerSvc* TgcCabGet = 0; - StatusCode sc = service("TGCcablingServerSvc", TgcCabGet, true); - if(sc.isFailure()) { +const ITGCcablingSvc* Muon::TGC_RawDataProviderToolCore::getCabling() const +{ + const ITGCcablingSvc* cabling = m_cabling.get(); + if (cabling) { + return cabling; + } + + ServiceHandle<ITGCcablingServerSvc> TgcCabGet ("TGCcablingServerSvc", name()); + if (TgcCabGet.retrieve().isFailure()) { ATH_MSG_FATAL( "Could not get TGCcablingServerSvc !" ); - return StatusCode::FAILURE; - } else { - ATH_MSG_VERBOSE( " TGCcablingServerSvc retrieved" ); - } + return nullptr; + } - sc = TgcCabGet->giveCabling(m_cabling); - if(sc.isFailure()) { + if (TgcCabGet->giveCabling(cabling).isFailure()) { ATH_MSG_FATAL( "Could not get ITGCcablingSvc from the Server !" ); - return StatusCode::FAILURE; - } else { - ATH_MSG_VERBOSE( "ITGCcablingSvc obtained" ); - } - - m_hid2re.set(m_cabling); + return nullptr; + } + + m_cabling.set (cabling); - return StatusCode::SUCCESS; + return cabling; } -std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> Muon::TGC_RawDataProviderToolCore::getROBData(const std::vector<IdentifierHash>& rdoIdhVect) const { - +std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> Muon::TGC_RawDataProviderToolCore::getROBData(const std::vector<IdentifierHash>& rdoIdhVect) const +{ std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> vecOfRobf; - if(!m_cabling) { - ATH_MSG_ERROR("Could not get cabling, return empty vector of ROB fragments"); - return vecOfRobf; + const ITGCcablingSvc* cabling = getCabling(); + if(!cabling) { + ATH_MSG_ERROR("Could not get cabling, return empty vector of ROB fragments"); + return vecOfRobf; } IdContext tgcContext = m_idHelperSvc->tgcIdHelper().module_context(); @@ -116,7 +117,7 @@ std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> Muon::TGC_RawDataPr continue; } const Identifier tgcId = Id; - uint32_t rodId = m_hid2re.getRodID(tgcId); + uint32_t rodId = m_hid2re.getRodID(tgcId, cabling); uint32_t robId = m_hid2re.getRobID(rodId); std::vector<uint32_t>::iterator it_robId = std::find(robIds.begin(), robIds.end(), robId); if(it_robId==robIds.end()) { diff --git a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderToolCore.h b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderToolCore.h index cde75104c76..a3653a916ab 100644 --- a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderToolCore.h +++ b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderToolCore.h @@ -15,6 +15,7 @@ #include "ByteStreamCnvSvcBase/IROBDataProviderSvc.h" #include "MuonTGC_CnvTools/ITGC_RodDecoder.h" #include "TGCcablingInterface/ITGCcablingSvc.h" +#include "CxxUtils/CachedPointer.h" class TgcRdoContainer; @@ -57,11 +58,11 @@ namespace Muon { /** ID converter */ TGC_Hid2RESrcID m_hid2re; /** TGC cabling Svc */ - const ITGCcablingSvc *m_cabling; + CxxUtils::CachedPointer<const ITGCcablingSvc> m_cabling; /** Rob Data Provider handle */ ServiceHandle<IROBDataProviderSvc> m_robDataProvider; - StatusCode getCabling(); + const ITGCcablingSvc* getCabling() const; }; } // end of namespace diff --git a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderToolMT.cxx b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderToolMT.cxx index ee6595596ff..cf5f6167d4d 100644 --- a/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderToolMT.cxx +++ b/MuonSpectrometer/MuonCnv/MuonTGC_CnvTools/src/TGC_RawDataProviderToolMT.cxx @@ -83,11 +83,6 @@ StatusCode Muon::TGC_RawDataProviderToolMT::convert(){ StatusCode Muon::TGC_RawDataProviderToolMT::convert(const EventContext& ctx) const { - if(!m_cabling) { - ATH_MSG_ERROR("Tgc cabling is not available and needs to be set in initialise"); - return StatusCode::FAILURE; - } - std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> vecOfRobf; const std::vector<uint32_t>& robIds = m_hid2re.allRobIds(); -- GitLab