ATLAS Offline Software
SCT_ClusterContainerCnv_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 
6 
10 #include "InDetIdentifier/SCT_ID.h"
12 
13 // Athena
16 #include "StoreGate/StoreGateSvc.h"
17 
18 // Gaudi
19 #include "GaudiKernel/Bootstrap.h"
20 #include "GaudiKernel/ISvcLocator.h"
21 #include "GaudiKernel/MsgStream.h"
22 #include "GaudiKernel/Service.h"
23 #include "GaudiKernel/StatusCode.h"
24 
26 {
27 
28  // The transient model has a container holding collections and the
29  // collections hold channels.
30  //
31  // The persistent model flattens this so that the persistent
32  // container has two vectors:
33  // 1) all collections, and
34  // 2) all RDO
35  //
36  // The persistent collections, then only maintain indexes into the
37  // container's vector of all channels.
38  //
39  // So here we loop over all collection and add their channels
40  // to the container's vector, saving the indexes in the
41  // collection.
42 
45 
46  SCT_ClusterCnv_p1 chanCnv;
47  TRANS::const_iterator it_Coll = transCont->begin();
48  TRANS::const_iterator it_CollEnd = transCont->end();
49  unsigned int collIndex;
50  unsigned int chanBegin = 0;
51  unsigned int chanEnd = 0;
52  persCont->m_collections.resize(transCont->numberOfCollections());
53 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
54 
55  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
56  // Add in new collection
57 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " New collection" << endmsg;
58  const InDet::SCT_ClusterCollection& collection = (**it_Coll);
59  chanBegin = chanEnd;
60  chanEnd += collection.size();
61  InDet::InDetPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
62  pcollection.m_id = collection.identify().get_compact();
63  pcollection.m_hashId = (unsigned int) collection.identifyHash();
64  pcollection.m_begin = chanBegin;
65  pcollection.m_end = chanEnd;
66  // Add in channels
67  persCont->m_PRD.resize(chanEnd);
68  for (unsigned int i = 0; i < collection.size(); ++i) {
69  const InDet::SCT_Cluster* chan = collection[i];
70  persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
71  }
72  }
73 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing SCT_ClusterContainer ***" << endmsg;
74 }
75 
77 {
78 
79  // The transient model has a container holding collections and the
80  // collections hold channels.
81  //
82  // The persistent model flattens this so that the persistent
83  // container has two vectors:
84  // 1) all collections, and
85  // 2) all channels
86  //
87  // The persistent collections, then only maintain indexes into the
88  // container's vector of all channels.
89  //
90  // So here we loop over all collection and extract their channels
91  // from the vector.
92 
93  const InDetDD::SiDetectorElementCollection* elements(nullptr);
96  elements = *sctDetEleHandle;
97  if (not sctDetEleHandle.isValid() or elements==nullptr) {
98  log << MSG::FATAL << m_SCTDetEleCollKey.fullKey() << " is not available." << endmsg;
99  return;
100  }
101  }
102 
103  InDet::SCT_ClusterCollection* coll = nullptr;
104 
105  SCT_ClusterCnv_p1 chanCnv;
107 
108 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
109  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
110 
111  // Create trans collection - is NOT owner of SCT_Cluster (SG::VIEW_ELEMENTS)
112  // IDet collection don't have the Ownership policy c'tor
113  const InDet::InDetPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
114  //Identifier collID(Identifier(pcoll.m_id));
115  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
116  coll = new InDet::SCT_ClusterCollection(collIDHash);
117  coll->setIdentifier(Identifier(pcoll.m_id));
118  unsigned int nchans = pcoll.m_end - pcoll.m_begin;
119  coll->resize(nchans);
120  const InDetDD::SiDetectorElement * de = (m_useDetectorElement ? elements->getDetectorElement(collIDHash) : nullptr);
121  // Fill with channels
122  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
123  const TPObjRef pchan = persCont->m_PRD[ichan + pcoll.m_begin];
124  InDet::SCT_Cluster* chan = dynamic_cast<InDet::SCT_Cluster*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
125  if (chan) {
126  chan->m_detEl = de;
127  (*coll)[ichan] = chan;
128  }
129  }
130 
131  // register the rdo collection in IDC with hash - faster addCollection
132  StatusCode sc = transCont->addCollection(coll, collIDHash);
133  if (sc.isFailure()) {
134  throw std::runtime_error("Failed to add collection to ID Container");
135  }
136 // if (log.level() <= MSG::DEBUG) {
137 // log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
138 // collID.get_compact() << ", added to Identifiable container." << endmsg;
139 // }
140  }
141 
142 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading SCT_ClusterContainer" << endmsg;
143 }
144 
145 
146 
147 //================================================================
149 {
150  if(!m_isInitialized) {
151  if (this->initialize(log) != StatusCode::SUCCESS) {
152  log << MSG::FATAL << "Could not initialize SCT_ClusterContainerCnv_p1 " << endmsg;
153  }
154  }
155  std::unique_ptr<InDet::SCT_ClusterContainer> trans(std::make_unique<InDet::SCT_ClusterContainer>(m_sctId->wafer_hash_max()));
156  persToTrans(persObj, trans.get(), log);
157  return(trans.release());
158 }
159 
161  // Do not initialize again:
162  m_isInitialized=true;
163 
164  CHECK( m_storeGate.retrieve() );
165 
166  // get DetectorStore service
167  SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
168  CHECK( detStore.isValid() );
169 
170  // Get the SCT helper from the detector store
171  CHECK( detStore->retrieve(m_sctId, "SCT_ID") );
172 
174 
175  return StatusCode::SUCCESS;
176 }
177 
178 // Method for test/SCT_ClusterContainerCnv_p1_test.cxx
179 void InDet::SCT_ClusterContainerCnv_p1::setUseDetectorElement(const bool useDetectorElement) {
180  m_useDetectorElement = useDetectorElement;
181 }
InDet::InDetPRD_Container_p1::m_PRD
std::vector< TPObjRef > m_PRD
Definition: InDetPRD_Container_p1.h:20
ITPConverterFor< Trk::PrepRawData >
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
InDet::InDetPRD_Collection_p1::m_hashId
unsigned int m_hashId
Definition: InDetPRD_Collection_p1.h:38
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
InDet::SCT_ClusterContainerCnv_p1::setUseDetectorElement
void setUseDetectorElement(const bool useDetectorElement)
Definition: SCT_ClusterContainerCnv_p1.cxx:179
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
InDet::InDetPRD_Collection_p1::m_id
unsigned int m_id
Definition: InDetPRD_Collection_p1.h:32
InDet::SCT_ClusterContainerCnv_p1::TRANS
InDet::SCT_ClusterContainer TRANS
Definition: SCT_ClusterContainerCnv_p1.h:32
InDet::SCT_ClusterContainer
Trk::PrepRawDataContainer< SCT_ClusterCollection > SCT_ClusterContainer
Definition: SCT_ClusterContainer.h:27
InDet::SCT_ClusterContainerCnv_p1::m_SCTDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
Definition: SCT_ClusterContainerCnv_p1.h:42
InDet::InDetPRD_Container_p1::m_collections
std::vector< InDet::InDetPRD_Collection_p1 > m_collections
Definition: InDetPRD_Container_p1.h:19
InDet::InDetPRD_Collection_p1
Definition: InDetPRD_Collection_p1.h:11
SCT_Cluster.h
TPObjRef
Definition: TPObjRef.h:20
ReadCondHandle.h
InDet::SCT_ClusterContainerCnv_p1::m_storeGate
ServiceHandle< StoreGateSvc > m_storeGate
Definition: SCT_ClusterContainerCnv_p1.h:41
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SCT_ClusterContainerCnv_p1.h
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
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
InDet::SCT_ClusterContainerCnv_p1::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: SCT_ClusterContainerCnv_p1.cxx:25
InDet::SCT_ClusterContainerCnv_p1::m_sctId
const SCT_ID * m_sctId
Definition: SCT_ClusterContainerCnv_p1.h:40
InDet::SCT_Cluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/SCT_Cluster.h:34
SCT_ClusterCnv_p1
Definition: SCT_ClusterCnv_p1.h:24
InDet::SCT_ClusterContainerCnv_p1::m_isInitialized
bool m_isInitialized
Definition: SCT_ClusterContainerCnv_p1.h:45
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
SCT_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: SCT_ID.cxx:636
errorcheck.h
Helpers for checking error return status codes and reporting errors.
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
InDet::SCT_ClusterContainerCnv_p1::createTransient
virtual InDet::SCT_ClusterContainer * createTransient(const InDet::InDetPRD_Container_p1 *persObj, MsgStream &log)
Definition: SCT_ClusterContainerCnv_p1.cxx:148
SCT_ClusterCnv_p1.h
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
InDet::SCT_ClusterContainerCnv_p1::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: SCT_ClusterContainerCnv_p1.cxx:76
InDet::SCT_ClusterContainerCnv_p1::initialize
StatusCode initialize(MsgStream &log)
Definition: SCT_ClusterContainerCnv_p1.cxx:160
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::SCT_ClusterCollection
Trk::PrepRawDataCollection< SCT_Cluster > SCT_ClusterCollection
Definition: SCT_ClusterCollection.h:26
StoreGateSvc.h
InDetDD::SiDetectorElementCollection::getDetectorElement
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Definition: SiDetectorElementCollection.cxx:15
SiCluster_p1.h
InDet::SCT_ClusterContainerCnv_p1::m_useDetectorElement
bool m_useDetectorElement
Definition: SCT_ClusterContainerCnv_p1.h:44
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