diff --git a/InnerDetector/InDetEventCnv/InDetEventCnvTools/InDetEventCnvTools/InDetEventCnvTool.h b/InnerDetector/InDetEventCnv/InDetEventCnvTools/InDetEventCnvTools/InDetEventCnvTool.h index 7d9b10b17bce1c032e527e407def953f7790d75a..adcc449e2047f737b3b4ee35139d62b6fe69893a 100755 --- a/InnerDetector/InDetEventCnv/InDetEventCnvTools/InDetEventCnvTools/InDetEventCnvTool.h +++ b/InnerDetector/InDetEventCnv/InDetEventCnvTools/InDetEventCnvTools/InDetEventCnvTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #ifndef INDETEVENTCNVTOOL_H @@ -15,10 +15,6 @@ #include "StoreGate/ReadCondHandleKey.h" #include "StoreGate/ReadHandleKey.h" -#include "GaudiKernel/EventContext.h" -#include "GaudiKernel/ContextSpecificPtr.h" - -#include <mutex> #include <utility> class AtlasDetectorID; @@ -38,89 +34,77 @@ namespace Trk { } -//class PixelClusterContainer ; -//class TRT_DriftCircleContainer ; - namespace InDet { -/**Helper tool uses to convert InDet objects in generic tracking custom convertor TrkEventAthenaPool. + /**Helper tool uses to convert InDet objects in generic tracking custom convertor TrkEventAthenaPool. -See "mainpage" for discussion of jobOpts. -*/ -class InDetEventCnvTool : virtual public Trk::ITrkEventCnvTool, public AthAlgTool { + See "mainpage" for discussion of jobOpts. + */ + class InDetEventCnvTool : virtual public Trk::ITrkEventCnvTool, public AthAlgTool { public: - enum InDetConcreteType { SCT, Pixel, TRT, Unknown }; + enum InDetConcreteType { SCT, Pixel, TRT, Unknown }; - InDetEventCnvTool(const std::string&,const std::string&,const IInterface*); + InDetEventCnvTool(const std::string&,const std::string&,const IInterface*); - virtual ~InDetEventCnvTool (); + virtual ~InDetEventCnvTool() = default; - virtual StatusCode initialize(); + virtual StatusCode initialize(); - virtual void checkRoT( const Trk::RIO_OnTrack& rioOnTrack ); + virtual void checkRoT( const Trk::RIO_OnTrack& rioOnTrack ); - /** use the passed identifier to recreate the detector element and PRD links on the passed RIO_OnTrack - @param[in] rioOnTrack The RIO_OnTrack we're interested in - @return std::pair of the pointers to the two corresponding objects*/ - virtual std::pair<const Trk::TrkDetElementBase*, const Trk::PrepRawData*> + /** use the passed identifier to recreate the detector element and PRD links on the passed RIO_OnTrack + @param[in] rioOnTrack The RIO_OnTrack we're interested in + @return std::pair of the pointers to the two corresponding objects*/ + virtual std::pair<const Trk::TrkDetElementBase*, const Trk::PrepRawData*> getLinks( const Trk::RIO_OnTrack& rioOnTrack ); - /** @copydoc Trk::ITrkEventCnvTool::prepareRIO_OnTrack( Trk::RIO_OnTrack* rot)*/ - virtual void prepareRIO_OnTrack( Trk::RIO_OnTrack* rot); + /** @copydoc Trk::ITrkEventCnvTool::prepareRIO_OnTrack( Trk::RIO_OnTrack* rot)*/ + virtual void prepareRIO_OnTrack( Trk::RIO_OnTrack* rot); - /** @copydoc Trk::ITrkEventCnvTool::recreateRIO_OnTrack( Trk::RIO_OnTrack* rot)*/ - virtual void recreateRIO_OnTrack( Trk::RIO_OnTrack *RoT ); + /** @copydoc Trk::ITrkEventCnvTool::recreateRIO_OnTrack( Trk::RIO_OnTrack* rot)*/ + virtual void recreateRIO_OnTrack( Trk::RIO_OnTrack *RoT ); - /** Return the detectorElement associated with this Identifier*/ - virtual const Trk::TrkDetElementBase* getDetectorElement(const Identifier& id, const IdentifierHash& idHash); + /** Return the detectorElement associated with this Identifier*/ + virtual const Trk::TrkDetElementBase* getDetectorElement(const Identifier& id, const IdentifierHash& idHash); - /** Return the detectorElement associated with this Identifier*/ - virtual const Trk::TrkDetElementBase* getDetectorElement(const Identifier& id); + /** Return the detectorElement associated with this Identifier*/ + virtual const Trk::TrkDetElementBase* getDetectorElement(const Identifier& id); private: - /** use the passed identifier to recreate the pixel cluster link on the passed RIO_OnTrack*/ - virtual const Trk::PrepRawData* pixelClusterLink( const Identifier& id, const IdentifierHash& idHash); + /** use the passed identifier to recreate the pixel cluster link on the passed RIO_OnTrack*/ + virtual const Trk::PrepRawData* pixelClusterLink( const Identifier& id, const IdentifierHash& idHash); - /** use the passed identifier to recreate the SCT cluster link on the passed RIO_OnTrack*/ - virtual const Trk::PrepRawData* sctClusterLink( const Identifier& id, const IdentifierHash& idHash ); + /** use the passed identifier to recreate the SCT cluster link on the passed RIO_OnTrack*/ + virtual const Trk::PrepRawData* sctClusterLink( const Identifier& id, const IdentifierHash& idHash ); - /** use the passed identifier to recreate the TRT Drift circle link on the passed RIO_OnTrack*/ - virtual const Trk::PrepRawData* trtDriftCircleLink( const Identifier& id, const IdentifierHash& idHash ); + /** use the passed identifier to recreate the TRT Drift circle link on the passed RIO_OnTrack*/ + virtual const Trk::PrepRawData* trtDriftCircleLink( const Identifier& id, const IdentifierHash& idHash ); - /** use the passed IdentifierHash to get SiDetectorElement*/ - const InDetDD::SiDetectorElement* getSCTDetectorElement(const IdentifierHash& waferHash) const; + /** use the passed IdentifierHash to get SiDetectorElement*/ + const InDetDD::SiDetectorElement* getSCTDetectorElement(const IdentifierHash& waferHash) const; - std::string m_pixMgrLocation; //!< Location of sct Manager - const InDetDD::PixelDetectorManager* m_pixMgr; //!< SCT Detector Manager - std::string m_trtMgrLocation; //!< Location of sct Manager - const InDetDD::TRT_DetectorManager* m_trtMgr; //!< TRT Detector Manager - bool m_setPrepRawDataLink; //!< if true, attempt to recreate link to PRD + std::string m_pixMgrLocation; //!< Location of Pixel Manager + const InDetDD::PixelDetectorManager* m_pixMgr; //!< Pixel Detector Manager + std::string m_trtMgrLocation; //!< Location of TRT Manager + const InDetDD::TRT_DetectorManager* m_trtMgr; //!< TRT Detector Manager + bool m_setPrepRawDataLink; //!< if true, attempt to recreate link to PRD - //various id helpers - const AtlasDetectorID * m_IDHelper; - const SCT_ID * m_SCTHelper; + //various id helpers + const AtlasDetectorID* m_IDHelper; + const SCT_ID* m_SCTHelper; - // added to check TRT existence (SLHC geo check) - const IdDictManager * m_idDictMgr; + // added to check TRT existence (SLHC geo check) + const IdDictManager* m_idDictMgr; - // Mutex to protect the contents. - mutable std::mutex m_mutex; - // Cache to store events for slots - mutable std::vector<EventContext::ContextEvt_t> m_cacheSCTElements; - // Pointer of InDetDD::SiDetectorElementCollection - mutable Gaudi::Hive::ContextSpecificPtr<const InDetDD::SiDetectorElementCollection> m_sctDetectorElements; - - SG::ReadHandleKey<PixelClusterContainer> m_pixClusContName {this, "PixelClusterContainer" ,"PixelClusters" , "Pixel Cluster container name"}; //!< location of container of pixel clusters - SG::ReadHandleKey<SCT_ClusterContainer> m_sctClusContName {this, "SCT_ClusterContainer" ,"SCT_Clusters" , "SCT Cluster container name"} ; //!< location of container of sct clusters - SG::ReadHandleKey<TRT_DriftCircleContainer> m_trtDriftCircleContName{this, "TRT_DriftCircleContainer" ,"TRT_DriftCircleContainer" , "TRT DriftCircle Container"}; //!< location of container of TRT drift circles - - SG::ReadCondHandleKey<InDetDD::SiDetectorElementCollection> m_SCTDetEleCollKey{this, "SCTDetEleCollKey", "SCT_DetectorElementCollection", "Key of SiDetectorElementCollection for SCT"}; -}; + SG::ReadHandleKey<PixelClusterContainer> m_pixClusContName {this, "PixelClusterContainer", "PixelClusters", "Pixel Cluster container name"}; //!< location of container of pixel clusters + SG::ReadHandleKey<SCT_ClusterContainer> m_sctClusContName {this, "SCT_ClusterContainer", "SCT_Clusters", "SCT Cluster container name"}; //!< location of container of sct clusters + SG::ReadHandleKey<TRT_DriftCircleContainer> m_trtDriftCircleContName{this, "TRT_DriftCircleContainer", "TRT_DriftCircleContainer", "TRT DriftCircle Container"}; //!< location of container of TRT drift circles + SG::ReadCondHandleKey<InDetDD::SiDetectorElementCollection> m_SCTDetEleCollKey{this, "SCTDetEleCollKey", "SCT_DetectorElementCollection", "Key of SiDetectorElementCollection for SCT"}; + }; } #endif // MOORETOTRACKTOOL_H - diff --git a/InnerDetector/InDetEventCnv/InDetEventCnvTools/src/InDetEventCnvTool.cxx b/InnerDetector/InDetEventCnv/InDetEventCnvTools/src/InDetEventCnvTool.cxx index 68025136046bdfd4611c6ff5264287d59afc9d10..87982a7bb496780fb1f8276c18c38c4ba5802fba 100755 --- a/InnerDetector/InDetEventCnv/InDetEventCnvTools/src/InDetEventCnvTool.cxx +++ b/InnerDetector/InDetEventCnv/InDetEventCnvTools/src/InDetEventCnvTool.cxx @@ -1,11 +1,9 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #include "InDetEventCnvTools/InDetEventCnvTool.h" -//#include "StoreGate/StoreGateSvc.h" - #include "Identifier/Identifier.h" #include "Identifier/IdentifierHash.h" #include "AtlasDetDescr/AtlasDetectorID.h" @@ -30,10 +28,9 @@ #include <cassert> #include <iostream> -InDet::InDetEventCnvTool::InDetEventCnvTool( - const std::string& t, - const std::string& n, - const IInterface* p ) +InDet::InDetEventCnvTool::InDetEventCnvTool(const std::string& t, + const std::string& n, + const IInterface* p ) : AthAlgTool(t,n,p), m_pixMgrLocation("Pixel"), @@ -43,9 +40,7 @@ InDet::InDetEventCnvTool::InDetEventCnvTool( m_setPrepRawDataLink(false), m_IDHelper(nullptr), m_SCTHelper(nullptr), - m_idDictMgr(nullptr), - m_mutex{}, - m_cacheSCTElements{} + m_idDictMgr(nullptr) { declareInterface<ITrkEventCnvTool>(this); declareProperty("PixelMgrLocation", m_pixMgrLocation); @@ -54,25 +49,20 @@ InDet::InDetEventCnvTool::InDetEventCnvTool( } -InDet::InDetEventCnvTool::~InDetEventCnvTool() -{ -} - -StatusCode InDet::InDetEventCnvTool::initialize() -{ +StatusCode InDet::InDetEventCnvTool::initialize() { StatusCode sc = AthAlgTool::initialize(); if (sc.isFailure()) return sc; // get Pixel Detector Description Manager - if( detStore()->contains<InDetDD::PixelDetectorManager>(m_pixMgrLocation)){ + if (detStore()->contains<InDetDD::PixelDetectorManager>(m_pixMgrLocation)) { sc = detStore()->retrieve(m_pixMgr, m_pixMgrLocation); if (sc.isFailure()) { - ATH_MSG_FATAL("Could not get PixelDetectorDescription"); - return sc; + ATH_MSG_FATAL("Could not get PixelDetectorDescription"); + return sc; } } else { - ATH_MSG_INFO("No Pixels? Could not get PixelDetectorDescription"); + ATH_MSG_INFO("No Pixels? Could not get PixelDetectorDescription"); } // check if SLHC geo is used (TRT not implemented) @@ -82,8 +72,8 @@ StatusCode InDet::InDetEventCnvTool::initialize() std::cout << "Could not get IdDictManager !" << std::endl; return StatusCode::FAILURE; } - const IdDictDictionary* dict = m_idDictMgr->manager()->find_dictionary("InnerDetector"); - if(!dict) { + const IdDictDictionary* dict = m_idDictMgr->manager()->find_dictionary("InnerDetector"); + if (!dict) { std::cout << " Cannot access InnerDetector dictionary "<< std::endl; return StatusCode::FAILURE; } @@ -94,22 +84,21 @@ StatusCode InDet::InDetEventCnvTool::initialize() // Find string SLHC in dictionary file name - if found is SLHC geo if (dict->file_name().find("SLHC")!=std::string::npos) isSLHC=true; - if(!isSLHC && detStore()->contains<InDetDD::TRT_DetectorManager>(m_trtMgrLocation)){ + if (!isSLHC && detStore()->contains<InDetDD::TRT_DetectorManager>(m_trtMgrLocation)) { // Get TRT Detector Description Manager sc = detStore()->retrieve(m_trtMgr, m_trtMgrLocation); if (sc.isFailure()) { ATH_MSG_FATAL("Could not get TRT_DetectorDescription"); return sc; } - }else { - ATH_MSG_INFO("No TRT? Could not get TRT_DetectorDescription"); + } else { + ATH_MSG_INFO("No TRT? Could not get TRT_DetectorDescription"); } -//retrieving the various ID helpers + //retrieving the various ID helpers - if (detStore()->retrieve(m_IDHelper, "AtlasID").isFailure()) - { + if (detStore()->retrieve(m_IDHelper, "AtlasID").isFailure()) { ATH_MSG_FATAL( "Could not get ATLAS ID helper"); return StatusCode::FAILURE; } @@ -127,75 +116,66 @@ StatusCode InDet::InDetEventCnvTool::initialize() } void -InDet::InDetEventCnvTool::checkRoT( const Trk::RIO_OnTrack& rioOnTrack ) -{ +InDet::InDetEventCnvTool::checkRoT( const Trk::RIO_OnTrack& rioOnTrack ) { InDetConcreteType type=Unknown; if (0!=dynamic_cast<const SCT_ClusterOnTrack*>(&rioOnTrack) ) type = SCT; if (0!=dynamic_cast<const PixelClusterOnTrack*>(&rioOnTrack) ) type = Pixel; if (0!=dynamic_cast<const TRT_DriftCircleOnTrack*>(&rioOnTrack) ) type = TRT; if (type==Unknown) { ATH_MSG_ERROR("Type does not match known concrete type of InDet! Dumping RoT:"<<rioOnTrack); - }else{ + } else { ATH_MSG_VERBOSE("Type = "<<type); } - - // const Identifier& id = rioOnTrack.identify(); - return; } std::pair<const Trk::TrkDetElementBase*, const Trk::PrepRawData*> - InDet::InDetEventCnvTool::getLinks( const Trk::RIO_OnTrack& rioOnTrack ) +InDet::InDetEventCnvTool::getLinks( const Trk::RIO_OnTrack& rioOnTrack ) { using namespace Trk; const TrkDetElementBase* detEl = 0; const PrepRawData* prd = 0; const Identifier& id = rioOnTrack.identify(); - if (m_IDHelper->is_pixel(id) ) - { - ATH_MSG_DEBUG ("Set Pixel detector element."); + if (m_IDHelper->is_pixel(id) ) { + ATH_MSG_DEBUG ("Set Pixel detector element."); // use IdentifierHash for speed detEl = m_pixMgr->getDetectorElement( rioOnTrack.idDE() ) ; if (m_setPrepRawDataLink) prd = pixelClusterLink( id, rioOnTrack.idDE() ); - } - else if (m_IDHelper->is_sct(id) ) - { - ATH_MSG_DEBUG("Set SCT detector element" ); + } else if (m_IDHelper->is_sct(id)) { + ATH_MSG_DEBUG("Set SCT detector element" ); // use IdentifierHash for speed detEl = getSCTDetectorElement( rioOnTrack.idDE() ) ; if (m_setPrepRawDataLink) prd = sctClusterLink( id, rioOnTrack.idDE() ); - } - else if (m_IDHelper->is_trt(id)) - { - ATH_MSG_DEBUG("Set TRT detector element" ); + } else if (m_IDHelper->is_trt(id)) { + ATH_MSG_DEBUG("Set TRT detector element" ); // use IdentifierHash for speed detEl = m_trtMgr->getElement( rioOnTrack.idDE() ) ; if (m_setPrepRawDataLink) prd = trtDriftCircleLink( id, rioOnTrack.idDE() ); - }else{ + } else { ATH_MSG_WARNING("Unknown type of ID detector from identifier :" - << id<<", in string form:" - << m_IDHelper->show_to_string(id) - ); + << id<<", in string form:" + << m_IDHelper->show_to_string(id) + ); } - return std::pair<const Trk::TrkDetElementBase*, const Trk::PrepRawData*>(detEl,prd); + return std::pair<const Trk::TrkDetElementBase*, const Trk::PrepRawData*>(detEl,prd); } void InDet::InDetEventCnvTool::prepareRIO_OnTrack( Trk::RIO_OnTrack *RoT ) { InDet::PixelClusterOnTrack* pixel = dynamic_cast<InDet::PixelClusterOnTrack*>(RoT); - if (pixel!=0){ + if (pixel!=0) { prepareRIO_OnTrackElementLink<const InDet::PixelClusterContainer, InDet::PixelClusterOnTrack>(pixel); return; } InDet::SCT_ClusterOnTrack* sct = dynamic_cast<InDet::SCT_ClusterOnTrack*>(RoT); - if (sct!=0){ + if (sct!=0) { prepareRIO_OnTrackElementLink<const InDet::SCT_ClusterContainer, InDet::SCT_ClusterOnTrack>(sct); return; } InDet::TRT_DriftCircleOnTrack* trt = dynamic_cast<InDet::TRT_DriftCircleOnTrack*>(RoT); - if (trt!=0){ + if (trt!=0) { prepareRIO_OnTrackElementLink<const InDet::TRT_DriftCircleContainer, InDet::TRT_DriftCircleOnTrack>(trt); return; } @@ -209,77 +189,63 @@ void InDet::InDetEventCnvTool::recreateRIO_OnTrack( Trk::RIO_OnTrack *RoT ) { } const Trk::TrkDetElementBase* -InDet::InDetEventCnvTool::getDetectorElement(const Identifier& id, const IdentifierHash& idHash) -{ - +InDet::InDetEventCnvTool::getDetectorElement(const Identifier& id, const IdentifierHash& idHash) { + const Trk::TrkDetElementBase* detEl=0; -// if (m_pixMgr->getIdg()->is_pixel(id) ) - if (m_IDHelper->is_pixel(id) ) - { - - ATH_MSG_DEBUG("Set Pixel detector element."); + if (m_IDHelper->is_pixel(id)) { + + ATH_MSG_DEBUG("Set Pixel detector element."); // use IdentifierHash for speed detEl = m_pixMgr->getDetectorElement( idHash ) ; - } - else if (m_IDHelper->is_sct(id) ) - { + } else if (m_IDHelper->is_sct(id)) { - ATH_MSG_DEBUG("Set SCT detector element" ); + ATH_MSG_DEBUG("Set SCT detector element" ); // use IdentifierHash for speed detEl = getSCTDetectorElement( idHash ) ; - } - else if (m_IDHelper->is_trt(id) ) - { + } else if (m_IDHelper->is_trt(id)) { - ATH_MSG_DEBUG("Set TRT detector element" ); + ATH_MSG_DEBUG("Set TRT detector element" ); // use IdentifierHash for speed detEl = m_trtMgr->getElement( idHash ) ; - }else{ + } else { ATH_MSG_WARNING("Unknown type of ID detector from identifier :" - << id<<", in string form:" - << m_IDHelper->show_to_string(id) - ); + << id<<", in string form:" + << m_IDHelper->show_to_string(id) + ); } return detEl; } const Trk::TrkDetElementBase* -InDet::InDetEventCnvTool::getDetectorElement(const Identifier& id) -{ +InDet::InDetEventCnvTool::getDetectorElement(const Identifier& id) { const Trk::TrkDetElementBase* detEl=0; - if (m_IDHelper->is_pixel(id) ) - { + if (m_IDHelper->is_pixel(id) ) { - ATH_MSG_DEBUG("Set Pixel detector element."); + ATH_MSG_DEBUG("Set Pixel detector element."); // use IdentifierHash for speed detEl = m_pixMgr->getDetectorElement( id ) ; - } - else if (m_IDHelper->is_sct(id) ) - { + } else if (m_IDHelper->is_sct(id)) { - ATH_MSG_DEBUG("Set SCT detector element" ); + ATH_MSG_DEBUG("Set SCT detector element" ); const Identifier wafer_id = m_SCTHelper->wafer_id(id); const IdentifierHash wafer_hash = m_SCTHelper->wafer_hash(wafer_id); detEl = getSCTDetectorElement( wafer_hash ) ; - } - else if (m_IDHelper->is_trt(id) ) - { - ATH_MSG_DEBUG("Set TRT detector element" ); + } else if (m_IDHelper->is_trt(id)) { + ATH_MSG_DEBUG("Set TRT detector element"); // use IdentifierHash for speed detEl = m_trtMgr->getElement( id ) ; - }else{ - ATH_MSG_WARNING("Unknown type of ID detector from identifier :"<< id<<", in string form:" - << m_IDHelper->show_to_string(id) ); + } else { + ATH_MSG_WARNING("Unknown type of ID detector from identifier :"<< id<<", in string form:" + << m_IDHelper->show_to_string(id) ); } return detEl; } const Trk::PrepRawData* - InDet::InDetEventCnvTool::pixelClusterLink( const Identifier& id, const IdentifierHash& idHash ) -{ +InDet::InDetEventCnvTool::pixelClusterLink( const Identifier& id, const IdentifierHash& idHash ) { using namespace Trk; // need to retrieve pointers to collections // retrieve Pixel cluster container @@ -287,18 +253,16 @@ const Trk::PrepRawData* // obviously this can be optimised! EJWM SG::ReadHandle<PixelClusterContainer> h_pixClusCont (m_pixClusContName); if (!h_pixClusCont.isValid()) { - ATH_MSG_ERROR("Pixel Cluster container not found at "<<m_pixClusContName); - return 0; - } - else{ + ATH_MSG_ERROR("Pixel Cluster container not found at "<<m_pixClusContName); + return 0; + } else { ATH_MSG_DEBUG("Pixel Cluster Container found" ); } const PixelClusterContainer* pixClusCont = h_pixClusCont.cptr(); PixelClusterContainer::const_iterator it = pixClusCont->indexFind(idHash); // if we find PRD, then recreate link - if (it!=pixClusCont->end()) - { + if (it!=pixClusCont->end()) { //loop though collection to find matching PRD. PixelClusterCollection::const_iterator collIt = (*it)->begin(); PixelClusterCollection::const_iterator collItEnd = (*it)->end(); @@ -312,32 +276,29 @@ const Trk::PrepRawData* } const Trk::PrepRawData* - InDet::InDetEventCnvTool::sctClusterLink( const Identifier& id, const IdentifierHash& idHash ) -{ +InDet::InDetEventCnvTool::sctClusterLink( const Identifier& id, const IdentifierHash& idHash ) { using namespace Trk; // need to retrieve pointers to collections // retrieve Pixel cluster container // obviously this can be optimised! EJWM - SG::ReadHandle<SCT_ClusterContainer> h_sctClusCont (m_sctClusContName); + SG::ReadHandle<SCT_ClusterContainer> h_sctClusCont(m_sctClusContName); if (!h_sctClusCont.isValid()) { - ATH_MSG_ERROR("SCT Cluster container not found at "<<m_sctClusContName); - return 0; - } - else{ + ATH_MSG_ERROR("SCT Cluster container not found at "<<m_sctClusContName); + return 0; + } else { ATH_MSG_DEBUG("SCT Cluster Container found" ); } const SCT_ClusterContainer* sctClusCont = h_sctClusCont.cptr(); SCT_ClusterContainer::const_iterator it = sctClusCont->indexFind(idHash); // if we find PRD, then recreate link - if (it!=sctClusCont->end()) - { + if (it!=sctClusCont->end()) { //loop though collection to find matching PRD. SCT_ClusterCollection::const_iterator collIt = (*it)->begin(); SCT_ClusterCollection::const_iterator collItEnd = (*it)->end(); // there MUST be a faster way to do this!! - for ( ; collIt!=collItEnd; collIt++){ + for ( ; collIt!=collItEnd; collIt++) { if ( (*collIt)->identify()==id ) return *collIt; } } @@ -346,8 +307,7 @@ const Trk::PrepRawData* } const Trk::PrepRawData* - InDet::InDetEventCnvTool::trtDriftCircleLink( const Identifier& id, const IdentifierHash& idHash ) -{ +InDet::InDetEventCnvTool::trtDriftCircleLink( const Identifier& id, const IdentifierHash& idHash ) { using namespace Trk; // need to retrieve pointers to collections // retrieve Pixel cluster container @@ -355,23 +315,21 @@ const Trk::PrepRawData* // obviously this can be optimised! EJWM SG::ReadHandle<TRT_DriftCircleContainer> h_trtDriftCircleCont (m_trtDriftCircleContName); if (!h_trtDriftCircleCont.isValid()) { - ATH_MSG_ERROR("TRT Drift Circles container not found at "<<m_trtDriftCircleContName); - return 0; - } - else{ + ATH_MSG_ERROR("TRT Drift Circles container not found at "<<m_trtDriftCircleContName); + return 0; + } else { ATH_MSG_DEBUG("TRT Drift Circles Container found" ); } const TRT_DriftCircleContainer* trtDriftCircleCont = h_trtDriftCircleCont.cptr(); TRT_DriftCircleContainer::const_iterator it = trtDriftCircleCont->indexFind(idHash); // if we find PRD, then recreate link - if (it!=trtDriftCircleCont->end()) - { + if (it!=trtDriftCircleCont->end()) { //loop though collection to find matching PRD. TRT_DriftCircleCollection::const_iterator collIt = (*it)->begin(); TRT_DriftCircleCollection::const_iterator collItEnd = (*it)->end(); // there MUST be a faster way to do this!! - for ( ; collIt!=collItEnd; collIt++){ + for ( ; collIt!=collItEnd; collIt++) { if ( (*collIt)->identify()==id ) return *collIt; } } @@ -380,21 +338,7 @@ const Trk::PrepRawData* } const InDetDD::SiDetectorElement* InDet::InDetEventCnvTool::getSCTDetectorElement(const IdentifierHash& waferHash) const { - const EventContext& ctx{Gaudi::Hive::currentContext()}; - static const EventContext::ContextEvt_t invalidValue{EventContext::INVALID_CONTEXT_EVT}; - EventContext::ContextID_t slot{ctx.slot()}; - EventContext::ContextEvt_t evt{ctx.evt()}; - std::lock_guard<std::mutex> lock{m_mutex}; - if (slot>=m_cacheSCTElements.size()) { - m_cacheSCTElements.resize(slot+1, invalidValue); // Store invalid values in order to go to the next IF statement. - } - if (m_cacheSCTElements[slot]!=evt) { - SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> sctDetEle{m_SCTDetEleCollKey}; - if (not sctDetEle.isValid()) { - ATH_MSG_ERROR("Failed to get " << m_SCTDetEleCollKey.key()); - } - m_sctDetectorElements.set(*sctDetEle); - m_cacheSCTElements[slot] = evt; - } - return (m_sctDetectorElements.isValid() ? m_sctDetectorElements->getDetectorElement(waferHash) : nullptr); + SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> sctDetEle{m_SCTDetEleCollKey}; + if (not sctDetEle.isValid()) return nullptr; + return sctDetEle->getDetectorElement(waferHash); } diff --git a/InnerDetector/InDetEventCnv/InDetEventTPCnv/src/InDetRIO_OnTrack/SCT_ClusterOnTrackCnv_p2.cxx b/InnerDetector/InDetEventCnv/InDetEventTPCnv/src/InDetRIO_OnTrack/SCT_ClusterOnTrackCnv_p2.cxx index 0bd46c598e38d53af6508392f01e8371912fd574..b278f3340dcd8be45a368ba7ec10b309307e7800 100644 --- a/InnerDetector/InDetEventCnv/InDetEventTPCnv/src/InDetRIO_OnTrack/SCT_ClusterOnTrackCnv_p2.cxx +++ b/InnerDetector/InDetEventCnv/InDetEventTPCnv/src/InDetRIO_OnTrack/SCT_ClusterOnTrackCnv_p2.cxx @@ -1,81 +1,73 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ -#include "InDetRIO_OnTrack/SCT_ClusterOnTrack.h" - #include "InDetEventTPCnv/InDetRIO_OnTrack/SCT_ClusterOnTrackCnv_p2.h" + +#include "AthLinks/ElementLink.h" #include "Identifier/Identifier.h" +#include "InDetPrepRawData/SCT_ClusterContainer.h" +#include "InDetRIO_OnTrack/SCT_ClusterOnTrack.h" #include "TrkEventTPCnv/helpers/EigenHelpers.h" void SCT_ClusterOnTrackCnv_p2::persToTrans( const InDet::SCT_ClusterOnTrack_p2 *persObj, InDet::SCT_ClusterOnTrack *transObj, MsgStream &log ) { - ElementLinkToIDCSCT_ClusterContainer rio; - m_elCnv.persToTrans(&persObj->m_prdLink,&rio,log); + ElementLinkToIDCSCT_ClusterContainer rio; + m_elCnv.persToTrans(&persObj->m_prdLink,&rio,log); - Trk::LocalParameters localParams; - fillTransFromPStore( &m_localParCnv, persObj->m_localParams, &localParams, log ); + Trk::LocalParameters localParams; + fillTransFromPStore( &m_localParCnv, persObj->m_localParams, &localParams, log ); - Trk::ErrorMatrix dummy; - Amg::MatrixX localCovariance; - fillTransFromPStore( &m_errorMxCnv, persObj->m_localErrMat, &dummy, log ); - EigenHelpers::vectorToEigenMatrix(dummy.values, localCovariance, "SCT_ClusterOnTrackCnv_p2"); + Trk::ErrorMatrix dummy; + Amg::MatrixX localCovariance; + fillTransFromPStore( &m_errorMxCnv, persObj->m_localErrMat, &dummy, log ); + EigenHelpers::vectorToEigenMatrix(dummy.values, localCovariance, "SCT_ClusterOnTrackCnv_p2"); - // When reading in 32-bit id, must cast to unsigned int - const Identifier::value_type upper = 0XFFFFFFFF00000000LL; - const Identifier::value_type lower = 0X00000000FFFFFFFFLL; - const Identifier::value_type testUpper = persObj->m_id & upper; - const Identifier::value_type testLower = persObj->m_id & lower; - Identifier id; - if ( testUpper == 0 && testLower > 0) { - Identifier32::value_type id1 = persObj->m_id; - id = id1; - } - else id = persObj->m_id; - - *transObj = InDet::SCT_ClusterOnTrack (rio, - localParams, - localCovariance, - persObj->m_idDE, - id, - persObj->m_isbroad, - persObj->m_positionAlongStrip); + // When reading in 32-bit id, must cast to unsigned int + const Identifier::value_type upper = 0XFFFFFFFF00000000LL; + const Identifier::value_type lower = 0X00000000FFFFFFFFLL; + const Identifier::value_type testUpper = persObj->m_id & upper; + const Identifier::value_type testLower = persObj->m_id & lower; + Identifier id; + if ( testUpper == 0 && testLower > 0) { + Identifier32::value_type id1 = persObj->m_id; + id = id1; + } else { + id = persObj->m_id; + } - // Attempt to call supertool to fill in detElements - m_eventCnvTool->recreateRIO_OnTrack(transObj); - if (transObj->detectorElement()==0) - log << MSG::WARNING<<"Unable to reset DetEl for this RIO_OnTrack, " - << "probably because of a problem with the Identifier/IdentifierHash : (" - << transObj->identify()<<"/"<<transObj->idDE()<<endmsg; + *transObj = InDet::SCT_ClusterOnTrack (rio, + localParams, + localCovariance, + persObj->m_idDE, + id, + persObj->m_isbroad, + persObj->m_positionAlongStrip); + // Attempt to call supertool to fill in detElements + m_eventCnvTool->recreateRIO_OnTrack(transObj); + if (transObj->detectorElement()==0) { + log << MSG::WARNING<<"Unable to reset DetEl for this RIO_OnTrack, " + << "probably because of a problem with the Identifier/IdentifierHash : (" + << transObj->identify()<<"/"<<transObj->idDE()<<endmsg; + } } -void SCT_ClusterOnTrackCnv_p2::transToPers( const InDet::SCT_ClusterOnTrack*transObj, InDet::SCT_ClusterOnTrack_p2 *persObj, MsgStream &log ) { +void SCT_ClusterOnTrackCnv_p2::transToPers(const InDet::SCT_ClusterOnTrack* transObj, InDet::SCT_ClusterOnTrack_p2* persObj, MsgStream& log) { + if (transObj==nullptr or persObj==nullptr) return; - persObj->m_id = transObj->identify().get_compact(); - const Trk::RIO_OnTrack* tobj = static_cast<const Trk::RIO_OnTrack *>(transObj); + persObj->m_id = transObj->identify().get_compact(); + persObj->m_localParams = toPersistent( &m_localParCnv, &transObj->localParameters(), log ); + Trk::ErrorMatrix pMat; + EigenHelpers::eigenMatrixToVector(pMat.values, transObj->localCovariance(), "SCT_ClusterOnTrackCnv_p2"); + persObj->m_localErrMat = toPersistent( &m_errorMxCnv, &pMat, log ); + persObj->m_idDE = transObj->idDE(); + persObj->m_isbroad = transObj->isBroadCluster(); + persObj->m_positionAlongStrip = static_cast<float>(transObj->positionAlongStrip()); - m_eventCnvTool->prepareRIO_OnTrack(const_cast<Trk::RIO_OnTrack *>(tobj)); - persObj->m_localParams = toPersistent( &m_localParCnv, &transObj->localParameters(), log ); - // persObj->m_localErrMat = toPersistent( &m_errorMxCnv, &transObj->m_localErrMat, log ); - Trk::ErrorMatrix pMat; - EigenHelpers::eigenMatrixToVector(pMat.values, transObj->localCovariance(), "SCT_ClusterOnTrackCnv_p2"); - persObj->m_localErrMat = toPersistent( &m_errorMxCnv, &pMat, log ); - - - persObj->m_idDE = transObj->idDE(); - persObj->m_isbroad = transObj->isBroadCluster(); - - persObj->m_positionAlongStrip = (float) transObj->positionAlongStrip(); - - - if (!transObj->prepRawDataLink().dataID().empty()) { - persObj->m_prdLink.m_contName = transObj->prepRawDataLink().dataID(); - persObj->m_prdLink.m_elementIndex = transObj->prepRawDataLink().index(); - }else{ - persObj->m_prdLink.m_contName = ""; - persObj->m_prdLink.m_elementIndex = 0; - } + const std::string sctClusContName{"SCT_Clusters"}; + ElementLink<InDet::SCT_ClusterContainer>::index_type hashAndIndex{0}; + bool isFound{m_eventCnvTool->getHashAndIndex<InDet::SCT_ClusterContainer, InDet::SCT_ClusterOnTrack>(transObj, sctClusContName, hashAndIndex)}; + persObj->m_prdLink.m_contName = (isFound ? sctClusContName : ""); + persObj->m_prdLink.m_elementIndex = hashAndIndex; } - - diff --git a/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/EventCnvSuperTool.h b/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/EventCnvSuperTool.h index 80f6aa804b46296a8158c1f4ddd18e7972721bcf..f577cd907dd3e25b98827c91a186df9edb20b25d 100644 --- a/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/EventCnvSuperTool.h +++ b/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/EventCnvSuperTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #ifndef TRKEVENTCNVTOOLS_EVENTCNVSUPERTOOL @@ -8,7 +8,6 @@ #include "TrkEventCnvTools/IEventCnvSuperTool.h" #include "GaudiKernel/ToolHandle.h" #include "AthenaBaseComps/AthAlgTool.h" -//#include "AthenaPoolCnvSvc/T_AthenaPoolTPConverter.h" #include "AthenaPoolUtilities/TPObjRef.h" class Identifier; @@ -37,6 +36,7 @@ namespace Trk virtual StatusCode finalize(); Trk::ITrkEventCnvTool* getCnvTool(const Identifier& id); + const Trk::ITrkEventCnvTool* getCnvTool(const Identifier& id) const; /** From passed Identifier*/ virtual const Trk::Surface* getSurface(const Identifier& id); diff --git a/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/IEventCnvSuperTool.h b/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/IEventCnvSuperTool.h index 4e4470963028941d1d31b6a86b45db47e1ee79e5..1afc370322db579069c3dd179209fbeb4eba355f 100644 --- a/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/IEventCnvSuperTool.h +++ b/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/IEventCnvSuperTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #ifndef TRKEVENTCNVTOOLS_IEVENTCNVSUPERTOOL @@ -7,6 +7,8 @@ #include "GaudiKernel/IAlgTool.h" +#include "AthLinks/ElementLink.h" + class Identifier; class AtlasDetectorID; class TPObjRef; @@ -28,6 +30,7 @@ namespace Trk static const InterfaceID& interfaceID(); virtual Trk::ITrkEventCnvTool* getCnvTool(const Identifier& id)=0; + virtual const Trk::ITrkEventCnvTool* getCnvTool(const Identifier& id) const =0; /** From passed Identifier*/ virtual const Trk::Surface* getSurface(const Identifier& id)=0; @@ -38,6 +41,11 @@ namespace Trk /** Take the passed RoT and prepare the PRD ElementLink for writing to disc*/ virtual void prepareRIO_OnTrack( RIO_OnTrack* Rot) = 0; + /**This templated method will return the hashAndIndex of the passed RIO_OnTrack.*/ + template <class CONT, class ROT> bool getHashAndIndex(const ROT* rot, + const std::string contName, + typename ElementLink<CONT>::index_type& hashAndIndex) const; + /** returns false if e.g. no ID geometry available*/ virtual bool canHandleInDet() const =0; @@ -58,5 +66,6 @@ inline const InterfaceID& Trk::IEventCnvSuperTool::interfaceID() return IID_IIEventCnvSuperTool; } -#endif +#include "TrkEventCnvTools/IEventCnvSuperTool.icc" +#endif diff --git a/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/IEventCnvSuperTool.icc b/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/IEventCnvSuperTool.icc new file mode 100644 index 0000000000000000000000000000000000000000..bc92aafb56df345f4764780675588949e0f25495 --- /dev/null +++ b/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/IEventCnvSuperTool.icc @@ -0,0 +1,14 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#include "TrkEventCnvTools/ITrkEventCnvTool.h" + +template <class CONT, class ROT> +bool Trk::IEventCnvSuperTool::getHashAndIndex(const ROT* rot, + const std::string contName, + typename ElementLink<CONT>::index_type& hashAndIndex) const { + const Trk::ITrkEventCnvTool* cnvTool{getCnvTool(rot->identify())}; + if (cnvTool!=nullptr) return cnvTool->getHashAndIndex<CONT, ROT>(rot, contName, hashAndIndex); + return false; +} diff --git a/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/ITrkEventCnvTool.h b/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/ITrkEventCnvTool.h index b4d8946030d2b5956c56ffd2a620f0c3db73263f..f2e26e297ab591e5a1949738c340728b80b62ba2 100755 --- a/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/ITrkEventCnvTool.h +++ b/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/ITrkEventCnvTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #ifndef TRKEVENTCNVTOOLS_ITRKEVENTCNVTOOL @@ -7,10 +7,12 @@ #include "GaudiKernel/IAlgTool.h" -//#include "GaudiKernel/IMessageSvc.h" + +#include "AthLinks/ElementLink.h" #include "StoreGate/StoreGate.h" + #include "GaudiKernel/ServiceHandle.h" -#include <GaudiKernel/IMessageSvc.h> +#include "GaudiKernel/IMessageSvc.h" #include "GaudiKernel/MsgStream.h" class Identifier; @@ -50,6 +52,10 @@ class ITrkEventCnvTool : virtual public IAlgTool /**This templated method will set the EL for the passed RIO_OnTrack.*/ template <class CONT, class ROT> void prepareRIO_OnTrackElementLink(ROT* rot); + /**This templated method will return the hashAndIndex of the passed RIO_OnTrack.*/ + template <class CONT, class ROT> bool getHashAndIndex(const ROT* rot, + const std::string contName, + typename ElementLink<CONT>::index_type& hashAndIndex) const; /** Take the passed RoT and prepare the PRD ElementLink for writing to disk. The procedure should be: diff --git a/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/ITrkEventCnvTool.icc b/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/ITrkEventCnvTool.icc index cf842ffba0a6e49f4f5ce9ce352a949b41346d49..245873367d9c563ac8b45c938b53768845603957 100644 --- a/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/ITrkEventCnvTool.icc +++ b/Tracking/TrkEventCnv/TrkEventCnvTools/TrkEventCnvTools/ITrkEventCnvTool.icc @@ -1,112 +1,98 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ -#include "GaudiKernel/IAlgTool.h" -#include "StoreGate/StoreGate.h" -#include "TrkPrepRawData/PrepRawData.h" #include "Identifier/IdentifierHash.h" -#include "AthLinks/ElementLink.h" +#include "TrkPrepRawData/PrepRawData.h" #include "TrkRIO_OnTrack/RIO_OnTrack.h" -#include <typeinfo> +#include "StoreGate/ReadHandle.h" +#include "StoreGate/StoreGate.h" +#include <typeinfo> template <class CONT, class ROT> -void Trk::ITrkEventCnvTool::prepareRIO_OnTrackElementLink(ROT* rot){ - // verify pointer is ok - // assume EL is correct - // get data handles to convertors +void Trk::ITrkEventCnvTool::prepareRIO_OnTrackElementLink(ROT* rot) { + // verify pointer is ok + // assume EL is correct + // get data handles to convertors + bool isPersistifiable = (rot->m_rio.key() != 0 + and IdentContIndex(rot->m_rio.index()).isValid()); - // Do some checks to see if we can (or should) continue -// bool isPersistifiable = !(rot->m_rio.dataID().empty()) && -// IdentContIndex(rot->m_rio.index()).isValid(); + if (isPersistifiable) { + return; // Already set - bail out. + } + + // When doing AOD to AOD copy we expect the PRD links to be zero. + if (rot->prepRawData()==nullptr) { + MsgStream log(&(*m_msgSvc), name()); + log<<MSG::DEBUG<<"No PRD for this ROT: "<<(*rot)<<endmsg; + return; + } - bool isPersistifiable = - rot->m_rio.key() != 0 - && IdentContIndex(rot->m_rio.index()).isValid(); + const DataHandle<CONT> dh, dhEnd; + StatusCode sc = m_storeGate->retrieve(dh, dhEnd); + if (sc.isFailure()) { + MsgStream log(&(*m_msgSvc), name()); + log << MSG::WARNING <<"No containers found!"<< endmsg; + return; + } - if (isPersistifiable) - { - //std::cout<<"EL for "<<typeid(rot).name()<<" is already set to persistent so skip further checks"<<std::endl; - return; // Already set - bail out. - } -// std::cout<<"EL for "<<typeid(rot).name()<<" is NOT set to persistent - doing so now"<<std::endl; -// std::cout<<" - PersistentState::valid(&(rot->m_rio))"<< rot->m_rio.toPersistentState()<<std::endl; -// if (rot->m_rio.toPersistentState() ){ -// std::cout<<" - IdentContIndex(rot->m_rio.index()).isValid() "<< -//IdentContIndex(rot->m_rio.index()).isValid()<<std::endl; -// } - - // When doing AOD to AOD copy we expect the PRD links to be zero. - if (rot->prepRawData()==0) - { - MsgStream log(&(*m_msgSvc), name() ); - log<<MSG::DEBUG<<"No PRD for this ROT: "<<(*rot)<<endmsg; - return; - } - // else { - // std::cout<<"Continuing for ROT of type : "<<typeid(rot).name()<<std::endl; - // } - - const DataHandle<CONT> dh, dhEnd; - StatusCode sc = m_storeGate->retrieve(dh, dhEnd); - if (sc.isFailure()) - { - MsgStream log(&(*m_msgSvc), name() ); - log << MSG::WARNING <<"No containers found!"<< endmsg; - return; - } + // loop over dhs + for ( ; dh!=dhEnd; dh++) { + const Trk::PrepRawData* prd = rot->prepRawData(); + unsigned int index = prd->getHashAndIndex().objIndex(); // prd index within collection + IdentifierHash idHash = prd->getHashAndIndex().collHash(); // idHash of collection + + CONT* cont = dh; // container + typename CONT::const_iterator coll = cont->indexFind(idHash); //matching collection - //std::cout << "Found data handles and will now loop over them all."<<std::endl; - // loop over dhs - for ( ; dh!=dhEnd; dh++ ) - { - const Trk::PrepRawData* prd = rot->prepRawData(); - unsigned int index = prd->getHashAndIndex().objIndex(); // prd index within collection - IdentifierHash idHash = prd->getHashAndIndex().collHash(); // idHash of collection - - CONT* cont = dh; // container - typename CONT::const_iterator coll = cont->indexFind(idHash); //matching collection - - // does coll exist? - // check prd exists in collection - // check pointer value the same. - if ( (coll!=cont->end())&& ((*coll)->size()>index) && (prd==(**coll)[index]) ) - { - // okay, so we found the correct PRD in the container. - // Now set EL correctly. dh.key() is the name of the container. index is the index withtin the collection. IdHash???? - rot->m_rio.resetWithKeyAndIndex(dh.key(), prd->getHashAndIndex().hashAndIndex() ); - //std::cout<<"Successfully set (key, hash, index) for ROT : ("<<dh.key()<<","<<idHash<<","<<index<<")"<<std::endl; + // does coll exist? + // check prd exists in collection + // check pointer value the same. + if ( (coll!=cont->end())&& ((*coll)->size()>index) && (prd==(**coll)[index]) ) { + // okay, so we found the correct PRD in the container. + // Now set EL correctly. dh.key() is the name of the container. index is the index withtin the collection. IdHash???? + rot->m_rio.resetWithKeyAndIndex(dh.key(), prd->getHashAndIndex().hashAndIndex() ); - //Final sanity check - should remove later - // Do some checks to see if we can (or should) continue - - -//This block currently look useless. Commenting it out. - /* - bool isPersistifiable = !(rot->m_rio.dataID().empty()) && IdentContIndex(rot->m_rio.index()).isValid(); - if (isPersistifiable) - { - //std::cout<<"EL for "<<typeid(rot).name()<<" is set correctly."<<std::endl; - return; // Already set - bail out. - } else { - //std::cout<<"WARNING: "<<typeid(rot).name()<<" is still unfit for persistency."<<std::endl; - } - */ - - return; //exit loop and function. We're done. - } + return; //exit loop and function. We're done. } - // so, we obviously didn't have the correct container (or something else went wrong) - MsgStream log(&(*m_msgSvc), name() ); - log << MSG::ERROR<<"Could not find matching PRD container for this ROT. ROT will be written out in incomplete state. " - << "Dumping ROT: "<<*rot<<endmsg; + } + // so, we obviously didn't have the correct container (or something else went wrong) + MsgStream log(&(*m_msgSvc), name()); + log << MSG::ERROR<<"Could not find matching PRD container for this ROT. ROT will be written out in incomplete state. " + << "Dumping ROT: "<<*rot<<endmsg; - return; + return; } -inline void Trk::ITrkEventCnvTool::setRoT_Values(std::pair<const Trk::TrkDetElementBase *, const Trk::PrepRawData *>& pair, Trk::RIO_OnTrack *RoT ) -{ - RoT->setValues(pair.first, pair.second); +inline void Trk::ITrkEventCnvTool::setRoT_Values(std::pair<const Trk::TrkDetElementBase *, const Trk::PrepRawData *>& pair, Trk::RIO_OnTrack *RoT) { + RoT->setValues(pair.first, pair.second); +} + +template <class CONT, class ROT> +bool Trk::ITrkEventCnvTool::getHashAndIndex(const ROT* rot, + const std::string contName, + typename ElementLink<CONT>::index_type& hashAndIndex) const { + if (rot==nullptr) return false; + + const Trk::PrepRawData* prd{rot->prepRawData()}; + if (prd==nullptr) return false; + + SG::ReadHandle<CONT> cont{contName}; + if (not cont.isValid()) return false; + + const IdentContIndex& idContIndex{prd->getHashAndIndex()}; + const IdentifierHash& idHash{idContIndex.collHash()}; // idHash of collection + typename CONT::const_iterator contItr{cont->indexFind(idHash)}; //matching collection + if (contItr==cont->end()) return false; + if ((*contItr)==nullptr) return false; + + unsigned int index{idContIndex.objIndex()}; // prd index within collection + if (((*contItr)->size()>index) and (prd==(**contItr)[index])) { + hashAndIndex = idContIndex.hashAndIndex(); + return true; + } + + return false; } diff --git a/Tracking/TrkEventCnv/TrkEventCnvTools/src/EventCnvSuperTool.cxx b/Tracking/TrkEventCnv/TrkEventCnvTools/src/EventCnvSuperTool.cxx index b45385293d89fc0d6a253876d6f8928b733db008..9e47337788a8a9beec21fc5964c21fb2d8e0ec63 100644 --- a/Tracking/TrkEventCnv/TrkEventCnvTools/src/EventCnvSuperTool.cxx +++ b/Tracking/TrkEventCnv/TrkEventCnvTools/src/EventCnvSuperTool.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #include "TrkEventCnvTools/EventCnvSuperTool.h" @@ -135,6 +135,19 @@ Trk::EventCnvSuperTool::getCnvTool(const Identifier& id){ } +const Trk::ITrkEventCnvTool* +Trk::EventCnvSuperTool::getCnvTool(const Identifier& id) const { + if (m_detID==nullptr) return nullptr; + + if (m_detID->is_indet(id)) { + if (m_haveIdCnvTool) return &(*m_idCnvTool); + } else if(m_detID->is_muon(id)) { + if (m_haveMuonCnvTool) return &(*m_muonCnvTool); + } + + return nullptr; +} + const Trk::Surface* Trk::EventCnvSuperTool::getSurface(const Identifier& id){ const Surface* surface = 0; diff --git a/Tracking/TrkEventCnv/TrkEventTPCnv/test/SurfaceCnv_p2_test.cxx b/Tracking/TrkEventCnv/TrkEventTPCnv/test/SurfaceCnv_p2_test.cxx index 2764ee06a3ff5fc3fa12a3caf2df52bbcfb440f8..17c3e889f921da47da35afb2f709f4bef0327a18 100644 --- a/Tracking/TrkEventCnv/TrkEventTPCnv/test/SurfaceCnv_p2_test.cxx +++ b/Tracking/TrkEventCnv/TrkEventTPCnv/test/SurfaceCnv_p2_test.cxx @@ -34,6 +34,8 @@ public: virtual Trk::ITrkEventCnvTool* getCnvTool(const Identifier& /*id*/) override { std::abort(); } + virtual const Trk::ITrkEventCnvTool* getCnvTool(const Identifier& /*id*/) const override + { std::abort(); } virtual void recreateRIO_OnTrack( Trk::RIO_OnTrack */*RoT*/ ) override { std::abort(); } virtual void prepareRIO_OnTrack( Trk::RIO_OnTrack* /*Rot*/) override