ATLAS Offline Software
TRT_DriftCircleContainerCnv_p1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
14 
15 // Gaudi
16 #include "GaudiKernel/ISvcLocator.h"
17 #include "GaudiKernel/Bootstrap.h"
18 #include "GaudiKernel/StatusCode.h"
19 #include "GaudiKernel/Service.h"
20 #include "GaudiKernel/MsgStream.h"
21 
22 // Athena
23 #include "StoreGate/StoreGateSvc.h"
24 
25 
26 
27 #include "AthAllocators/DataPool.h"
28 
30 {
31 
32  // The transient model has a container holding collections and the
33  // collections hold channels.
34  //
35  // The persistent model flattens this so that the persistent
36  // container has two vectors:
37  // 1) all collections, and
38  // 2) all RDO
39  //
40  // The persistent collections, then only maintain indexes into the
41  // container's vector of all channels.
42  //
43  // So here we loop over all collection and add their channels
44  // to the container's vector, saving the indexes in the
45  // collection.
46 
49 
50  TRT_DriftCircleCnv_p1 chanCnv;
51  TRANS::const_iterator it_Coll = transCont->begin();
52  TRANS::const_iterator it_CollEnd = transCont->end();
53  unsigned int collIndex;
54  unsigned int chanBegin = 0;
55  unsigned int chanEnd = 0;
56  persCont->m_collections.resize(transCont->numberOfCollections());
57 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
58 
59  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
60  // Add in new collection
61  const InDet::TRT_DriftCircleCollection& collection = (**it_Coll);
62  chanBegin = chanEnd;
63  chanEnd += collection.size();
64  InDet::InDetPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
65  pcollection.m_id = collection.identify().get_compact();
66  pcollection.m_hashId = (unsigned int) collection.identifyHash();
67  pcollection.m_begin = chanBegin;
68  pcollection.m_end = chanEnd;
69  // Add in channels
70  persCont->m_PRD.resize(chanEnd);
71  for (unsigned int i = 0; i < collection.size(); ++i) {
72  const InDet::TRT_DriftCircle* chan = collection[i];
73  persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
74  }
75  }
76 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing TRT_DriftCircleContainer ***" << endmsg;
77 }
78 
80 {
81 
82  // The transient model has a container holding collections and the
83  // collections hold channels.
84  //
85  // The persistent model flattens this so that the persistent
86  // container has two vectors:
87  // 1) all collections, and
88  // 2) all channels
89  //
90  // The persistent collections, then only maintain indexes into the
91  // container's vector of all channels.
92  //
93  // So here we loop over all collection and extract their channels
94  // from the vector.
95 
96 
97  InDet::TRT_DriftCircleCollection* coll = nullptr;
98 
99  TRT_DriftCircleCnv_p1 chanCnv;
101 
102 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
103  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
104 
105  // Create trans collection - is NOT owner of TRT_DriftCircle (SG::VIEW_ELEMENTS)
106  // IDet collection don't have the Ownership policy c'tor
107  const InDet::InDetPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
108  //Identifier collID(Identifier(pcoll.m_id));
109  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
110  coll = new InDet::TRT_DriftCircleCollection(collIDHash);
111  coll->setIdentifier(Identifier(pcoll.m_id));
112  unsigned int nchans = pcoll.m_end - pcoll.m_begin;
113  coll->resize(nchans);
114  const InDetDD::TRT_BaseElement * de = m_trtMgr->getElement(collIDHash);
115  // Fill with channels
116  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
117  const TPObjRef pchan = persCont->m_PRD[ichan + pcoll.m_begin];
118  InDet::TRT_DriftCircle* chan = dynamic_cast<InDet::TRT_DriftCircle*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
119  if (chan) {
120  chan->m_detEl = de;
121  (*coll)[ichan] = chan;
122  }
123  }
124 
125  // register the rdo collection in IDC with hash - faster addCollection
126  StatusCode sc = transCont->addCollection(coll, collIDHash);
127  if (sc.isFailure()) {
128  throw std::runtime_error("Failed to add collection to ID Container");
129  }
130 // if (log.level() <= MSG::DEBUG) {
131 // log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
132 // collID.get_compact() << ", added to Identifiable container." << endmsg;
133 // }
134  }
135 
136 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading TRT_DriftCircleContainer" << endmsg;
137 }
138 
139 
140 
141 //================================================================
143  if(!m_isInitialized) {
144  if (this->initialize(log) != StatusCode::SUCCESS) {
145  log << MSG::FATAL << "Could not initialize TRT_DriftCircleContainerCnv_p1 " << endmsg;
146  }
147  }
148  std::unique_ptr<InDet::TRT_DriftCircleContainer> trans(std::make_unique<InDet::TRT_DriftCircleContainer>(m_trtId->module_hash_max()));
149  persToTrans(persObj, trans.get(), log);
150  return(trans.release());
151 }
152 
154  // Do not initialize again:
155  m_isInitialized=true;
156 
157  SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
158  CHECK( detStore.isValid() );
159  CHECK( detStore->retrieve(m_trtId, "TRT_ID") );
160  CHECK( detStore->retrieve(m_trtMgr) );
161  return StatusCode::SUCCESS;
162 }
InDet::InDetPRD_Container_p1::m_PRD
std::vector< TPObjRef > m_PRD
Definition: InDetPRD_Container_p1.h:20
InDet::TRT_DriftCircleContainerCnv_p1::createTransient
virtual InDet::TRT_DriftCircleContainer * createTransient(const InDet::InDetPRD_Container_p1 *persObj, MsgStream &log)
Definition: TRT_DriftCircleContainerCnv_p1.cxx:142
ITPConverterFor< Trk::PrepRawData >
InDet::InDetPRD_Collection_p1::m_hashId
unsigned int m_hashId
Definition: InDetPRD_Collection_p1.h:38
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
TRT_DetectorManager.h
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
InDet::InDetPRD_Collection_p1::m_id
unsigned int m_id
Definition: InDetPRD_Collection_p1.h:32
InDet::InDetPRD_Container_p1::m_collections
std::vector< InDet::InDetPRD_Collection_p1 > m_collections
Definition: InDetPRD_Container_p1.h:19
InDet::TRT_DriftCircleContainerCnv_p1::m_trtMgr
const InDetDD::TRT_DetectorManager * m_trtMgr
Definition: TRT_DriftCircleContainerCnv_p1.h:41
InDet::InDetPRD_Collection_p1
Definition: InDetPRD_Collection_p1.h:11
InDet::TRT_DriftCircleContainerCnv_p1::m_isInitialized
bool m_isInitialized
Definition: TRT_DriftCircleContainerCnv_p1.h:42
TPObjRef
Definition: TPObjRef.h:20
InDet::TRT_DriftCircle
Definition: TRT_DriftCircle.h:32
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
InDet::TRT_DriftCircleContainerCnv_p1::initialize
StatusCode initialize(MsgStream &log)
Definition: TRT_DriftCircleContainerCnv_p1.cxx:153
TRT_ID::module_hash_max
size_type module_hash_max(void) const
Definition: TRT_ID.h:911
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_p1::m_begin
unsigned int m_begin
Definition: InDetPRD_Collection_p1.h:41
InDetPRD_Container_p1.h
TRT_DriftCircleCnv_p1
Definition: TRT_DriftCircleCnv_p1.h:25
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
InDet::TRT_DriftCircleContainerCnv_p1::TRANS
InDet::TRT_DriftCircleContainer TRANS
Definition: TRT_DriftCircleContainerCnv_p1.h:31
TRT_DriftCircle.h
DataPool.h
InDet::TRT_DriftCircleContainer
Trk::PrepRawDataContainer< TRT_DriftCircleCollection > TRT_DriftCircleContainer
Definition: TRT_DriftCircleContainer.h:27
TRT_DriftCircleContainer.h
ITPConverterFor::toPersistent
TPObjRef toPersistent(CNV **cnv, const typename CNV::TransBase_t *transObj, MsgStream &log) const
Persistify an object and store the persistent represenation in the storage vector of the top-level pe...
Definition: TPConverter.h:119
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
InDet::InDetPRD_Collection_p1::m_end
unsigned int m_end
Definition: InDetPRD_Collection_p1.h:44
defineDB.ichan
int ichan
Definition: JetTagCalibration/share/defineDB.py:28
InDetDD::TRT_DetectorManager::getElement
const TRT_BaseElement * getElement(Identifier id) const
Access Elements Generically---------------------------------------------—.
Definition: TRT_DetectorManager.cxx:148
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
TRT_DriftCircle_p1.h
TRT_DriftCircleCnv_p1.h
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
InDet::TRT_DriftCircleContainerCnv_p1::m_trtId
const TRT_ID * m_trtId
Definition: TRT_DriftCircleContainerCnv_p1.h:40
TRT_DriftCircleContainerCnv_p1.h
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
InDet::TRT_DriftCircleContainerCnv_p1::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: TRT_DriftCircleContainerCnv_p1.cxx:79
StoreGateSvc.h
InDet::TRT_DriftCircleContainerCnv_p1::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: TRT_DriftCircleContainerCnv_p1.cxx:29
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
ITPConverterFor::createTransFromPStore
CNV::Trans_t * createTransFromPStore(CNV **cnv, const TPObjRef &ref, MsgStream &log) const
Create transient representation of a persistent object, stored in the the top-level persistent object...
Definition: TPConverter.h:172
InDet::InDetPRD_Container_p1
Definition: InDetPRD_Container_p1.h:14
Identifier
Definition: IdentifierFieldParser.cxx:14