ATLAS Offline Software
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"
12 #include "InDetIdentifier/TRT_ID.h"
15 #include "AthAllocators/DataPool.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
25 #include "StoreGate/StoreGateSvc.h"
29 
30 // #define IDJUMP 0x400
31 
32 
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  //
58  TRT_DriftCircleCnv_p2 chanCnv;
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 
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);
130  if (m_useDetectorElement) {
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 //================================================================
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 
237 void TRT_DriftCircleContainerCnv_p2::setUseDetectorElement(const bool useDetectorElement) {
238  m_useDetectorElement = useDetectorElement;
239 }
240 
InDet::InDetPRD_Collection_p2::m_hashId
unsigned short m_hashId
Definition: InDetPRD_Collection_p2.h:35
TRT_ID::layer_id
Identifier layer_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer) const
For an individual straw layer.
Definition: TRT_ID.h:500
InDetPRD_Collection_p2.h
InDet::TRT_DriftCircleContainer_p2::m_rawdata
std::vector< InDet::TRT_DriftCircle_p2 > m_rawdata
Definition: TRT_DriftCircleContainer_p2.h:27
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
AthMsgStreamMacros.h
TRT_DriftCircleContainerCnv_p2::transToPers
virtual void transToPers(const InDet::TRT_DriftCircleContainer *transCont, InDet::TRT_DriftCircleContainer_p2 *persCont, MsgStream &log)
Definition: TRT_DriftCircleContainerCnv_p2.cxx:33
InDet::TRT_DriftCircleContainer_p2
Definition: TRT_DriftCircleContainer_p2.h:21
TRT_DriftCircleContainerCnv_p2::setIdHelper
void setIdHelper(const TRT_ID *trt_id)
Definition: TRT_DriftCircleContainerCnv_p2.cxx:233
TRT_ID::straw_layer_hash_max
size_type straw_layer_hash_max(void) const
Definition: TRT_ID.h:920
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
TRT_DriftCircleContainerCnv_p2::m_isInitialized
bool m_isInitialized
Definition: TRT_DriftCircleContainerCnv_p2.h:45
TRT_DriftCircleContainerCnv_p2::initialize
StatusCode initialize(MsgStream &log)
Definition: TRT_DriftCircleContainerCnv_p2.cxx:214
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
TRT_DriftCircleContainerCnv_p2::persToTrans
virtual void persToTrans(const InDet::TRT_DriftCircleContainer_p2 *persCont, InDet::TRT_DriftCircleContainer *transCont, MsgStream &log)
Definition: TRT_DriftCircleContainerCnv_p2.cxx:112
InDet::TRT_DriftCircle
Definition: TRT_DriftCircle.h:32
ReadCondHandle.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
InDet::TRT_DriftCircleContainer_p2::m_prdDeltaId
std::vector< unsigned short > m_prdDeltaId
Definition: TRT_DriftCircleContainer_p2.h:29
TRT_DriftCircleCnv_p2::transToPers
void transToPers(const InDet::TRT_DriftCircle *transObj, InDet::TRT_DriftCircle_p2 *persObj, MsgStream &log)
Definition: TRT_DriftCircleCnv_p2.cxx:55
TRT_DriftCircleContainerCnv_p2::m_trtId
const TRT_ID * m_trtId
Definition: TRT_DriftCircleContainerCnv_p2.h:44
TRT_DriftCircleContainerCnv_p2::m_trtDetEleContKey
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
Definition: TRT_DriftCircleContainerCnv_p2.h:46
InDet::InDetPRD_Collection_p2::m_size
unsigned short m_size
Definition: InDetPRD_Collection_p2.h:40
lumiFormat.i
int i
Definition: lumiFormat.py:85
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
InDet::InDetPRD_Collection_p2
Definition: InDetPRD_Collection_p2.h:11
TRT_DriftCircleCnv_p2
Definition: TRT_DriftCircleCnv_p2.h:25
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
TRT_DriftCircleContainerCnv_p2::createTransient
virtual InDet::TRT_DriftCircleContainer * createTransient(const InDet::TRT_DriftCircleContainer_p2 *persObj, MsgStream &log)
Definition: TRT_DriftCircleContainerCnv_p2.cxx:200
TRT_DriftCircleContainerCnv_p2::setUseDetectorElement
void setUseDetectorElement(const bool useDetectorElement)
Definition: TRT_DriftCircleContainerCnv_p2.cxx:237
TRT_DriftCircleCnv_p2.h
TRT_DriftCircle.h
DataPool.h
InDet::TRT_DriftCircleContainer
Trk::PrepRawDataContainer< TRT_DriftCircleCollection > TRT_DriftCircleContainer
Definition: TRT_DriftCircleContainer.h:27
TRT_DriftCircleContainer.h
TRT_DriftCircle_p2.h
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
InDet::TRT_DriftCircle_p2
Definition: TRT_DriftCircle_p2.h:20
defineDB.ichan
int ichan
Definition: JetTagCalibration/share/defineDB.py:28
errorcheck.h
Helpers for checking error return status codes and reporting errors.
InDet::TRT_DriftCircleCollection
Trk::PrepRawDataCollection< TRT_DriftCircle > TRT_DriftCircleCollection
Definition: TRT_DriftCircleCollection.h:26
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TRT_ID
Definition: TRT_ID.h:84
TRT_DriftCircleContainerCnv_p2.h
TRT_DriftCircleContainer_p2.h
InDetDD::TRT_DetElementCollection::getDetectorElement
const TRT_BaseElement * getDetectorElement(const IdentifierHash &hash) const
Definition: TRT_DetElementCollection.cxx:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TRT_DriftCircleContainerCnv_p2::m_useDetectorElement
bool m_useDetectorElement
Definition: TRT_DriftCircleContainerCnv_p2.h:47
InDetDD::TRT_DetElementCollection
Class to hold collection of TRT detector elements.
Definition: TRT_DetElementCollection.h:28
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
TRT_DriftCircleCnv_p2::createTRT_DriftCircle
InDet::TRT_DriftCircle createTRT_DriftCircle(const InDet::TRT_DriftCircle_p2 *persObj, Identifier clusId, std::vector< Identifier > &&rdoList, const InDetDD::TRT_BaseElement *detEl, MsgStream &log)
Definition: TRT_DriftCircleCnv_p2.cxx:19
StoreGateSvc.h
InDet::TRT_DriftCircleContainer_p2::m_collections
std::vector< InDet::InDetPRD_Collection_p2 > m_collections
Definition: TRT_DriftCircleContainer_p2.h:26
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
Identifier
Definition: IdentifierFieldParser.cxx:14