2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
5 #include "Identifier/IdentifierHash.h"
6 #include "TrkPrepRawData/PrepRawData.h"
7 #include "TrkRIO_OnTrack/RIO_OnTrack.h"
8 #include "StoreGate/ReadHandle.h"
13 template <class CONT, class ROT>
14 void Trk::ITrkEventCnvTool::prepareRIO_OnTrackElementLink(const ROT* rot,
16 ELIndex_t& index) const
18 // verify pointer is ok
19 // assume EL is correct
20 // get data handles to convertors
22 key = rot->m_rio.dataID();
23 index = rot->m_rio.index();
25 bool isPersistifiable = (rot->m_rio.key() != 0
26 and IdentContIndex(index).isValid());
28 if (isPersistifiable) {
29 return; // Already set - bail out.
32 // When doing AOD to AOD copy we expect the PRD links to be zero.
33 if (rot->prepRawData()==nullptr) {
34 MsgStream log(&(*m_msgSvc), name());
35 log<<MSG::DEBUG<<"No PRD for this ROT: "<<(*rot)<<endmsg;
39 SG::ConstIterator<CONT> dh, dhEnd;
40 StatusCode sc = m_storeGate->retrieve(dh, dhEnd);
42 MsgStream log(&(*m_msgSvc), name());
43 log << MSG::WARNING <<"No containers found!"<< endmsg;
48 for ( ; dh!=dhEnd; ++dh) {
49 const Trk::PrepRawData* prd = rot->prepRawData();
50 unsigned int oindex = prd->getHashAndIndex().objIndex(); // prd index within collection
51 IdentifierHash idHash = prd->getHashAndIndex().collHash(); // idHash of collection
53 const CONT& cont = *dh; // container
54 auto coll = cont.indexFindPtr(idHash); //matching collection
57 // check prd exists in collection
58 // check pointer value the same.
59 if ( (coll!=nullptr)&& (coll->size()>oindex) && (prd==(*coll)[oindex]) ) {
60 // okay, so we found the correct PRD in the container.
61 // Return EL components.
62 // dh.key() is the name of the container. oindex is the index within the collection. IdHash????
64 index = prd->getHashAndIndex().hashAndIndex();
65 return; //exit loop and function. We're done.
68 // so, we obviously didn't have the correct container (or something else went wrong)
69 MsgStream log(&(*m_msgSvc), name());
70 log << MSG::ERROR<<"Could not find matching PRD container for this ROT. ROT will be written out in incomplete state. "
71 << "Dumping ROT: "<<*rot<<endmsg;
76 template <class CONT, class ROT>
77 void Trk::ITrkEventCnvTool::prepareRIO_OnTrackElementLink(ROT* rot) const
81 prepareRIO_OnTrackElementLink<CONT> (rot, key, index);
82 rot->m_rio.resetWithKeyAndIndex (key, index);
85 inline void Trk::ITrkEventCnvTool::setRoT_Values(std::pair<const Trk::TrkDetElementBase *, const Trk::PrepRawData *>& pair, Trk::RIO_OnTrack *RoT) const {
86 RoT->setValues(pair.first, pair.second);
89 template <class CONT, class ROT>
90 bool Trk::ITrkEventCnvTool::getHashAndIndex(const ROT* rot,
91 const SG::ReadHandleKey<CONT>& contName,
92 typename ElementLink<CONT>::index_type& hashAndIndex) const {
93 if (rot==nullptr) return false;
95 const Trk::PrepRawData* prd{rot->prepRawData()};
96 if (prd==nullptr) return false;
98 SG::ReadHandle<CONT> cont (contName);
99 if (not cont.isValid()) return false;
101 const IdentContIndex& idContIndex{prd->getHashAndIndex()};
102 const IdentifierHash& idHash{idContIndex.collHash()}; // idHash of collection
103 auto contItr = cont->indexFindPtr(idHash); //matching collection
104 if (contItr==nullptr) return false;
106 unsigned int index{idContIndex.objIndex()}; // prd index within collection
107 if ((contItr->size()>index) and (prd==(*contItr)[index])) {
108 hashAndIndex = idContIndex.hashAndIndex();