ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_DriftCircleContainerCnv_p2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
10
11#include "Identifier/Identifier.h"
16
17// Gaudi
18#include "GaudiKernel/ISvcLocator.h"
19#include "GaudiKernel/Bootstrap.h"
20#include "GaudiKernel/StatusCode.h"
21#include "GaudiKernel/Service.h"
22#include "GaudiKernel/MsgStream.h"
23
24// Athena
29
30// #define IDJUMP 0x400
31
32
33void TRT_DriftCircleContainerCnv_p2::transToPers(const InDet::TRT_DriftCircleContainer* transCont, InDet::TRT_DriftCircleContainer_p2* persCont, MsgStream &log)
34{
35
36 // The transient model has a container holding collections and the
37 // collections hold channels.
38 //
39 // The persistent model flattens this so that the persistent
40 // container has two vectors:
41 // 1) all collections, and
42 // 2) all PRD
43 //
44 // The persistent collections, then only maintain indexes into the
45 // container's vector of all channels.
46 //
47 // So here we loop over all collection and add their channels
48 // to the container's vector, saving the indexes in the
49 // collection.
50
51 using TRANS = InDet::TRT_DriftCircleContainer;
52
53 // this is the id of the latest collection read in
54 // Thisstarts from the base of the TRT identifiers
55 unsigned int idLast(0);
56
57 //
59 TRANS::const_iterator it_Coll = transCont->begin();
60 TRANS::const_iterator it_CollEnd = transCont->end();
61 unsigned int collIndex;
62 unsigned int chanBegin = 0;
63 unsigned int chanEnd = 0;
64
65 persCont->m_collections.resize(transCont->numberOfCollections());
66
67 // to avoid the inside-loop resize
68 int totSize = 0;
69 //for ( ; it_Coll != it_CollEnd; it_Coll++) {
70 for ( it_Coll=transCont->begin(); it_Coll != it_CollEnd; ++it_Coll) {
71 const InDet::TRT_DriftCircleCollection& collection = (**it_Coll);
72 totSize+=collection.size();
73 }
74 persCont->m_rawdata.resize(totSize);
75 persCont->m_prdDeltaId.resize(totSize);
76
77 for (collIndex = 0, it_Coll=transCont->begin(); it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
78 // Add in new collection
79 const InDet::TRT_DriftCircleCollection& collection = (**it_Coll);
80 chanBegin = chanEnd;
81 chanEnd += collection.size();
82 InDet::InDetPRD_Collection_p2& pcollection = persCont->m_collections[collIndex];
83 unsigned int deltaId = (collection.identifyHash()-idLast);
84
85 pcollection.m_hashId = deltaId;
86 idLast = collection.identifyHash();
87 pcollection.m_size = collection.size();
88 // Add in channels
89
90 for (unsigned int i = 0; i < collection.size(); ++i) {
91 InDet::TRT_DriftCircle_p2* pchan = &(persCont->m_rawdata[i + chanBegin]);
92 const InDet::TRT_DriftCircle* chan = static_cast<const InDet::TRT_DriftCircle*>(collection[i]);
93 chanCnv.transToPers(chan, pchan, log);
94 persCont->m_prdDeltaId[i+chanBegin]=chan->identify().get_identifier32().get_compact()-collection.identify().get_identifier32().get_compact();
95 }
96 }
97}
98
99void TRT_DriftCircleContainerCnv_p2::persToTrans(const InDet::TRT_DriftCircleContainer_p2* persCont, InDet::TRT_DriftCircleContainer* transCont, MsgStream &log)
100{
101
102 // The transient model has a container holding collections and the
103 // collections hold channels.
104 //
105 // The persistent model flattens this so that the persistent
106 // container has two vectors:
107 // 1) all collections, and
108 // 2) all channels
109 //
110 // The persistent collections, then only maintain indexes into the
111 // container's vector of all channels.
112 //
113 // So here we loop over all collection and extract their channels
114 // from the vector.
115
116 const InDetDD::TRT_DetElementCollection* elements(nullptr);
119 elements = (*trtDetEleHandle)->getElements();
120 if (not trtDetEleHandle.isValid() or elements==nullptr) {
121 log << MSG::FATAL << m_trtDetEleContKey.fullKey() << " is not available." << endmsg;
122 return;
123 }
124 }
125
126 InDet::TRT_DriftCircleCollection* coll = nullptr;
127
128 TRT_DriftCircleCnv_p2 chanCnv;
129 unsigned int collBegin(0);
130 // this is the id of the latest collection read in
131 // This starts from the base of the TRT identifiers
132 unsigned int idLast(0);
133 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
134 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
135
136 // Create trans collection - in NOT owner of TRT_DriftCircle (SG::VIEW_ELEMENTS)
137 // IDet collection don't have the Ownership policy c'tor
138 const InDet::InDetPRD_Collection_p2& pcoll = persCont->m_collections[icoll];
139 // idLast+= pcoll.m_idDelta*IDJUMP;
140 // Identifier collID= Identifier(idLast);
141 idLast += pcoll.m_hashId;
142 IdentifierHash collIDHash=IdentifierHash((unsigned int) idLast);
143 Identifier collID = m_trtId->layer_id(collIDHash);
144 coll = new InDet::TRT_DriftCircleCollection(collIDHash);
145 coll->setIdentifier(collID);
146 unsigned int nchans = pcoll.m_size;
147 coll->resize(nchans);
148 const InDetDD::TRT_BaseElement* detEl = (elements==nullptr ? nullptr : elements->getDetectorElement(collIDHash));
149 // Fill with channels:
150 // This is used to read the vector of errMat
151 // values and lenght of the value are specified in separate vectors
152 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Reading collection with " << nchans << "Channels " << endmsg;
153 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
154 const InDet::TRT_DriftCircle_p2* pchan = &(persCont->m_rawdata[ichan + collBegin]);
155 Identifier clusId=Identifier(collID.get_identifier32().get_compact()+persCont->m_prdDeltaId[ichan + collBegin]);
156
157 std::vector<Identifier> rdoList(1);
158 rdoList[0]=clusId;
159
161 (chanCnv.createTRT_DriftCircle (pchan,
162 clusId,
163 std::move(rdoList),
164 detEl,
165 log));
166
167 // DC bugfix: set hash Id of the drift circle
168 chan->setHashAndIndex(collIDHash,ichan);
169 (*coll)[ichan] = chan;
170 }
171 collBegin += pcoll.m_size;
172
173 // register the PRD collection in IDC with hash - faster addCollection
174 StatusCode sc = transCont->addCollection(coll, collIDHash);
175 if (sc.isFailure()) {
176 throw std::runtime_error("Failed to add collection to ID Container");
177 }
178 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " << collID << ", added to Identifiable container." << endmsg;
179 }
180
181 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading InDet::TRT_DriftCircleContainer" << endmsg;
182}
183
184
185
186//================================================================
187InDet::TRT_DriftCircleContainer* TRT_DriftCircleContainerCnv_p2::createTransient(const InDet::TRT_DriftCircleContainer_p2* persObj, MsgStream& log) {
188 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "TRT_DriftCircleContainerCnv_p2::createTransient called " << endmsg;
189 if(!m_isInitialized) {
190 if (this->initialize(log) != StatusCode::SUCCESS) {
191 log << MSG::FATAL << "Could not initialize TRT_DriftCircleContainerCnv_p2 " << endmsg;
192 return nullptr; // if m_trtId not initialized return null pointer instead of dereferencing it later
193 }
194 }
195 std::unique_ptr<InDet::TRT_DriftCircleContainer> trans(std::make_unique<InDet::TRT_DriftCircleContainer>(m_trtId->straw_layer_hash_max()));
196 persToTrans(persObj, trans.get(), log);
197 return(trans.release());
198}
199
200
202
203
204 // Do not initialize again:
205 m_isInitialized=true;
206
207 // Get Storegate, ID helpers, and so on
208 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
209 CHECK( detStore.isValid() );
210
211 // Get the TRT helper from the detector store
212 CHECK( detStore->retrieve(m_trtId, "TRT_ID") );
213
215
216 return StatusCode::SUCCESS;
217}
218
219// Methods for test/TRT_DriftCircleContainerCnv_p2_test.cxx
221 m_trtId = trt_id;
222}
223
224void TRT_DriftCircleContainerCnv_p2::setUseDetectorElement(const bool useDetectorElement) {
225 m_useDetectorElement = useDetectorElement;
226}
227
#define endmsg
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t sc
This is an Identifier helper class for the TRT subdetector.
size_type size() const noexcept
value_type get_compact() const
Get the compact id.
This is a "hash" representation of an Identifier.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Virtual base class of TRT readout elements.
Class to hold collection of TRT detector elements.
const TRT_BaseElement * getDetectorElement(const IdentifierHash &hash) const
std::vector< InDet::InDetPRD_Collection_p2 > m_collections
std::vector< InDet::TRT_DriftCircle_p2 > m_rawdata
InDet::TRT_DriftCircle createTRT_DriftCircle(const InDet::TRT_DriftCircle_p2 *persObj, Identifier clusId, std::vector< Identifier > &&rdoList, const InDetDD::TRT_BaseElement *detEl, MsgStream &log)
void transToPers(const InDet::TRT_DriftCircle *transObj, InDet::TRT_DriftCircle_p2 *persObj, MsgStream &log)
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
virtual InDet::TRT_DriftCircleContainer * createTransient(const InDet::TRT_DriftCircleContainer_p2 *persObj, MsgStream &log)
virtual void transToPers(const InDet::TRT_DriftCircleContainer *transCont, InDet::TRT_DriftCircleContainer_p2 *persCont, MsgStream &log)
virtual void persToTrans(const InDet::TRT_DriftCircleContainer_p2 *persCont, InDet::TRT_DriftCircleContainer *transCont, MsgStream &log)
void setUseDetectorElement(const bool useDetectorElement)
This is an Identifier helper class for the TRT subdetector.
Definition TRT_ID.h:84
void initialize()