ATLAS Offline Software
Loading...
Searching...
No Matches
ITrkEventCnvTool.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "Identifier/IdentifierHash.h"
6#include "TrkPrepRawData/PrepRawData.h"
7#include "TrkRIO_OnTrack/RIO_OnTrack.h"
8#include "StoreGate/ReadHandle.h"
9
10#include <typeinfo>
11
12
13template <class CONT, class ROT>
14void Trk::ITrkEventCnvTool::prepareRIO_OnTrackElementLink(const ROT* rot,
15 ELKey_t& key,
16 ELIndex_t& index) const
17{
18 // verify pointer is ok
19 // assume EL is correct
20
21 key = rot->m_rio.dataID();
22 index = rot->m_rio.index();
23
24 bool isPersistifiable = (rot->m_rio.key() != 0
25 and IdentContIndex(index).isValid());
26
27 if (isPersistifiable) {
28 return; // Already set - bail out.
29 }
30
31 // When doing AOD to AOD copy we expect the PRD links to be zero.
32 if (rot->prepRawData()==nullptr) {
33 MsgStream log(&(*m_msgSvc), name());
34 log<<MSG::DEBUG<<"No PRD for this ROT: "<<(*rot)<<endmsg;
35 return;
36 }
37
38 SG::ConstIterator<CONT> obj, objEnd;
39 StatusCode sc = m_storeGate->retrieve(obj, objEnd);
40 if (sc.isFailure()) {
41 MsgStream log(&(*m_msgSvc), name());
42 log << MSG::WARNING <<"No containers found!"<< endmsg;
43 return;
44 }
45
46 // loop over dhs
47 for ( ; obj!=objEnd; ++obj) {
48 const Trk::PrepRawData* prd = rot->prepRawData();
49 unsigned int oindex = prd->getHashAndIndex().objIndex(); // prd index within collection
50 IdentifierHash idHash = prd->getHashAndIndex().collHash(); // idHash of collection
51
52 const CONT& cont = *obj; // container
53 auto coll = cont.indexFindPtr(idHash); //matching collection
54
55 // does coll exist?
56 // check prd exists in collection
57 // check pointer value the same.
58 if ( (coll!=nullptr)&& (coll->size()>oindex) && (prd==(*coll)[oindex]) ) {
59 // okay, so we found the correct PRD in the container.
60 // Return EL components.
61 // objh.key() is the name of the container. oindex is the index within the collection. IdHash????
62 key = obj.key();
63 index = prd->getHashAndIndex().hashAndIndex();
64 return; //exit loop and function. We're done.
65 }
66 }
67 // so, we obviously didn't have the correct container (or something else went wrong)
68 MsgStream log(&(*m_msgSvc), name());
69 log << MSG::ERROR<<"Could not find matching PRD container for this ROT. ROT will be written out in incomplete state. "
70 << "Dumping ROT: "<<*rot<<endmsg;
71
72 return;
73}
74
75template <class CONT, class ROT>
76void Trk::ITrkEventCnvTool::prepareRIO_OnTrackElementLink(ROT* rot) const
77{
78 ELKey_t key;
79 ELIndex_t index;
80 prepareRIO_OnTrackElementLink<CONT> (rot, key, index);
81 rot->m_rio.resetWithKeyAndIndex (key, index);
82}
83
84inline void Trk::ITrkEventCnvTool::setRoT_Values(std::pair<const Trk::TrkDetElementBase *, const Trk::PrepRawData *>& pair, Trk::RIO_OnTrack *RoT) const {
85 RoT->setValues(pair.first, pair.second);
86}
87
88template <class CONT, class ROT>
89bool Trk::ITrkEventCnvTool::getHashAndIndex(const ROT* rot,
90 const SG::ReadHandleKey<CONT>& contName,
91 typename ElementLink<CONT>::index_type& hashAndIndex) const {
92 if (rot==nullptr) return false;
93
94 const Trk::PrepRawData* prd{rot->prepRawData()};
95 if (prd==nullptr) return false;
96
97 SG::ReadHandle<CONT> cont (contName);
98 if (not cont.isValid()) return false;
99
100 const IdentContIndex& idContIndex{prd->getHashAndIndex()};
101 const IdentifierHash& idHash{idContIndex.collHash()}; // idHash of collection
102 auto contItr = cont->indexFindPtr(idHash); //matching collection
103 if (contItr==nullptr) return false;
104
105 unsigned int index{idContIndex.objIndex()}; // prd index within collection
106 if ((contItr->size()>index) and (prd==(*contItr)[index])) {
107 hashAndIndex = idContIndex.hashAndIndex();
108 return true;
109 }
110
111 return false;
112}