ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_DriftCircleContainerCnv_p2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
78 // for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, it_Coll++) {
79 for (collIndex = 0, it_Coll=transCont->begin(); it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
80 // Add in new collection
81 const InDet::TRT_DriftCircleCollection& collection = (**it_Coll);
82 chanBegin = chanEnd;
83 chanEnd += collection.size();
84 InDet::InDetPRD_Collection_p2& pcollection = persCont->m_collections[collIndex];
85 unsigned int deltaId = (collection.identifyHash()-idLast);
86 // if(deltaId*IDJUMP != collection.identify().get_compact()-idLast )
87 // log << MSG::FATAL << "THere is a mistake in Identifiers of the collection" << endmsg;
88 // if(deltaId > 0xFFFF) {
89 // log << MSG::FATAL << "Fixme!!! This is too big, something needs to be done " << endmsg;
90 // }
91 // pcollection.m_idDelta = (unsigned short) deltaId;
92 // idLast = collection.identify().get_compact(); // then update the last identifier
93 // pcollection.m_hashId = (unsigned short) collection.identifyHash();
94 pcollection.m_hashId = deltaId;
95 idLast = collection.identifyHash();
96 pcollection.m_size = collection.size();
97 // Add in channels
98 //persCont->m_rawdata.resize(chanEnd);
99 //persCont->m_prdDeltaId.resize(chanEnd);
100 // if (log.level() <= MSG::VERBOSE) log << MSG::VERBOSE << "Reading collections with " << collection.size() << "PRDs " << endmsg;
101 for (unsigned int i = 0; i < collection.size(); ++i) {
102 InDet::TRT_DriftCircle_p2* pchan = &(persCont->m_rawdata[i + chanBegin]);
103 const InDet::TRT_DriftCircle* chan = dynamic_cast<const InDet::TRT_DriftCircle*>(collection[i]);
104 chanCnv.transToPers(chan, pchan, log);
105 //persCont->m_prdDeltaId[i+chanBegin]=chan->m_clusId.get_compact()-collection.identify().get_compact();
106 persCont->m_prdDeltaId[i+chanBegin]=chan->identify().get_identifier32().get_compact()-collection.identify().get_identifier32().get_compact();
107 }
108 }
109 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing InDet::TRT_DriftCircleContainer" << endmsg;
110}
111
112void TRT_DriftCircleContainerCnv_p2::persToTrans(const InDet::TRT_DriftCircleContainer_p2* persCont, InDet::TRT_DriftCircleContainer* transCont, MsgStream &log)
113{
114
115 // The transient model has a container holding collections and the
116 // collections hold channels.
117 //
118 // The persistent model flattens this so that the persistent
119 // container has two vectors:
120 // 1) all collections, and
121 // 2) all channels
122 //
123 // The persistent collections, then only maintain indexes into the
124 // container's vector of all channels.
125 //
126 // So here we loop over all collection and extract their channels
127 // from the vector.
128
129 const InDetDD::TRT_DetElementCollection* elements(nullptr);
132 elements = (*trtDetEleHandle)->getElements();
133 if (not trtDetEleHandle.isValid() or elements==nullptr) {
134 log << MSG::FATAL << m_trtDetEleContKey.fullKey() << " is not available." << endmsg;
135 return;
136 }
137 }
138
139 InDet::TRT_DriftCircleCollection* coll = nullptr;
140
141 TRT_DriftCircleCnv_p2 chanCnv;
142 unsigned int collBegin(0);
143 // this is the id of the latest collection read in
144 // This starts from the base of the TRT identifiers
145 unsigned int idLast(0);
146 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
147 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
148
149 // Create trans collection - in NOT owner of TRT_DriftCircle (SG::VIEW_ELEMENTS)
150 // IDet collection don't have the Ownership policy c'tor
151 const InDet::InDetPRD_Collection_p2& pcoll = persCont->m_collections[icoll];
152 // idLast+= pcoll.m_idDelta*IDJUMP;
153 // Identifier collID= Identifier(idLast);
154 idLast += pcoll.m_hashId;
155 IdentifierHash collIDHash=IdentifierHash((unsigned int) idLast);
156 Identifier collID = m_trtId->layer_id(collIDHash);
157 coll = new InDet::TRT_DriftCircleCollection(collIDHash);
158 coll->setIdentifier(collID);
159 unsigned int nchans = pcoll.m_size;
160 coll->resize(nchans);
161 const InDetDD::TRT_BaseElement* detEl = (elements==nullptr ? nullptr : elements->getDetectorElement(collIDHash));
162 // Fill with channels:
163 // This is used to read the vector of errMat
164 // values and lenght of the value are specified in separate vectors
165 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Reading collection with " << nchans << "Channels " << endmsg;
166 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
167 const InDet::TRT_DriftCircle_p2* pchan = &(persCont->m_rawdata[ichan + collBegin]);
168 Identifier clusId=Identifier(collID.get_identifier32().get_compact()+persCont->m_prdDeltaId[ichan + collBegin]);
169
170 std::vector<Identifier> rdoList(1);
171 rdoList[0]=clusId;
172
174 (chanCnv.createTRT_DriftCircle (pchan,
175 clusId,
176 std::move(rdoList),
177 detEl,
178 log));
179
180 // DC bugfix: set hash Id of the drift circle
181 chan->setHashAndIndex(collIDHash,ichan);
182 (*coll)[ichan] = chan;
183 }
184 collBegin += pcoll.m_size;
185
186 // register the PRD collection in IDC with hash - faster addCollection
187 StatusCode sc = transCont->addCollection(coll, collIDHash);
188 if (sc.isFailure()) {
189 throw std::runtime_error("Failed to add collection to ID Container");
190 }
191 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " << collID << ", added to Identifiable container." << endmsg;
192 }
193
194 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading InDet::TRT_DriftCircleContainer" << endmsg;
195}
196
197
198
199//================================================================
200InDet::TRT_DriftCircleContainer* TRT_DriftCircleContainerCnv_p2::createTransient(const InDet::TRT_DriftCircleContainer_p2* persObj, MsgStream& log) {
201 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "TRT_DriftCircleContainerCnv_p2::createTransient called " << endmsg;
202 if(!m_isInitialized) {
203 if (this->initialize(log) != StatusCode::SUCCESS) {
204 log << MSG::FATAL << "Could not initialize TRT_DriftCircleContainerCnv_p2 " << endmsg;
205 return nullptr; // if m_trtId not initialized return null pointer instead of dereferencing it later
206 }
207 }
208 std::unique_ptr<InDet::TRT_DriftCircleContainer> trans(std::make_unique<InDet::TRT_DriftCircleContainer>(m_trtId->straw_layer_hash_max()));
209 persToTrans(persObj, trans.get(), log);
210 return(trans.release());
211}
212
213
215
216
217 // Do not initialize again:
218 m_isInitialized=true;
219
220 // Get Storegate, ID helpers, and so on
221 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
222 CHECK( detStore.isValid() );
223
224 // Get the TRT helper from the detector store
225 CHECK( detStore->retrieve(m_trtId, "TRT_ID") );
226
228
229 return StatusCode::SUCCESS;
230}
231
232// Methods for test/TRT_DriftCircleContainerCnv_p2_test.cxx
234 m_trtId = trt_id;
235}
236
237void TRT_DriftCircleContainerCnv_p2::setUseDetectorElement(const bool useDetectorElement) {
238 m_useDetectorElement = useDetectorElement;
239}
240
#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:82
void initialize()