ATLAS Offline Software
PixelClusterContainerCnv_p1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Athena
15 #include "StoreGate/StoreGateSvc.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 
25 {
26 
27  // The transient model has a container holding collections and the
28  // collections hold channels.
29  //
30  // The persistent model flattens this so that the persistent
31  // container has two vectors:
32  // 1) all collections, and
33  // 2) all RDO
34  //
35  // The persistent collections, then only maintain indexes into the
36  // container's vector of all channels.
37  //
38  // So here we loop over all collection and add their channels
39  // to the container's vector, saving the indexes in the
40  // collection.
41 
44 
45  PixelClusterCnv_p1 chanCnv;
46  TRANS::const_iterator it_Coll = transCont->begin();
47  TRANS::const_iterator it_CollEnd = transCont->end();
48  unsigned int collIndex;
49  unsigned int chanBegin = 0;
50  unsigned int chanEnd = 0;
51  persCont->m_collections.resize(transCont->numberOfCollections());
52 
53  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
54  // Add in new collection
55  const InDet::PixelClusterCollection& collection = (**it_Coll);
56  chanBegin = chanEnd;
57  chanEnd += collection.size();
58  InDet::InDetPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
59  pcollection.m_id = collection.identify().get_compact();
60  pcollection.m_hashId = (unsigned int) collection.identifyHash();
61  pcollection.m_begin = chanBegin;
62  pcollection.m_end = chanEnd;
63  // Add in channels
64  persCont->m_PRD.resize(chanEnd);
65  for (unsigned int i = 0; i < collection.size(); ++i) {
66  const InDet::PixelCluster* chan = collection[i];
67  persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
68  }
69  }
70 }
71 
73 {
74 
75  // The transient model has a container holding collections and the
76  // collections hold channels.
77  //
78  // The persistent model flattens this so that the persistent
79  // container has two vectors:
80  // 1) all collections, and
81  // 2) all channels
82  //
83  // The persistent collections, then only maintain indexes into the
84  // container's vector of all channels.
85  //
86  // So here we loop over all collection and extract their channels
87  // from the vector.
88 
89  const InDetDD::SiDetectorElementCollection* elements(nullptr);
92  const InDetDD::SiDetectorElementCollection* elements = *pixelDetEleHandle;
93  if (not pixelDetEleHandle.isValid() or elements==nullptr) {
94  log << MSG::FATAL << m_pixelDetEleCollKey.fullKey() << " is not available." << endmsg;
95  return;
96  }
97  }
98 
99  InDet::PixelClusterCollection* coll = nullptr;
100 
101  PixelClusterCnv_p1 chanCnv;
103 
104  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
105 
106  // Create trans collection - is NOT owner of PixelCluster (SG::VIEW_ELEMENTS)
107  // IDet collection don't have the Ownership policy c'tor
108  const InDet::InDetPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
109  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
110  coll = new InDet::PixelClusterCollection(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::SiDetectorElement * de = (elements ? elements->getDetectorElement(collIDHash) : nullptr);
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::PixelCluster* chan = dynamic_cast<InDet::PixelCluster*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
119  if (chan){
120  chan->m_detEl = de;
121  (*coll)[ichan] = chan;
122  } else {
123  log << MSG::WARNING << "Cast to InDet::PixelCluster* failed in PixelClusterContainerCnv_p1" << endmsg;
124  }
125  }
126 
127  // register the rdo collection in IDC with hash - faster addCollection
128  StatusCode sc = transCont->addCollection(coll, collIDHash);
129  if (sc.isFailure()) {
130  throw std::runtime_error("Failed to add collection to ID Container");
131  }
132 
133  }
134 
135 }
136 
137 
138 
139 //================================================================
141 {
142  if(!m_isInitialized) {
143  if (this->initialize(log) != StatusCode::SUCCESS) {
144  log << MSG::FATAL << "Could not initialize PixelClusterContainerCnv_p1 " << endmsg;
145  return nullptr;
146  }
147  }
148  if (not m_pixId) {
149  log << MSG::FATAL << "PixelID helper is null in PixelClusterContainerCnv_p1::createTransient" << endmsg;
150  return nullptr;
151  }
152  std::unique_ptr<InDet::PixelClusterContainer> trans(std::make_unique<InDet::PixelClusterContainer>(m_pixId->wafer_hash_max()));
153  persToTrans(persObj, trans.get(), log);
154  return(trans.release());
155 }
156 
158  // Do not initialize again:
159  m_isInitialized=true;
160 
161  // Get Storegate, ID helpers, and so on
162  ISvcLocator* svcLocator = Gaudi::svcLocator();
163  // get StoreGate service
164  StatusCode sc = svcLocator->service("StoreGateSvc", m_storeGate);
165  if (sc.isFailure()) {
166  log << MSG::FATAL << "StoreGate service not found !" << endmsg;
167  return StatusCode::FAILURE;
168  }
169 
170  // get DetectorStore service
172  sc = svcLocator->service("DetectorStore", detStore);
173  if (sc.isFailure()) {
174  log << MSG::FATAL << "DetectorStore service not found !" << endmsg;
175  return StatusCode::FAILURE;
176  }
177 
178 
179  // Get the pixel helper from the detector store
180  sc = detStore->retrieve(m_pixId, "PixelID");
181  if (sc.isFailure()) {
182  log << MSG::FATAL << "Could not get PixelID helper !" << endmsg;
183  return StatusCode::FAILURE;
184  }
185 
187 
188  return StatusCode::SUCCESS;
189 }
190 
191 // Method for test/PixelClusterContainerCnv_p1_test.cxx
193  m_useDetectorElement = useDetectorElement;
194 }
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
InDet::InDetPRD_Container_p1::m_PRD
std::vector< TPObjRef > m_PRD
Definition: InDetPRD_Container_p1.h:20
PixelClusterCnv_p1.h
ITPConverterFor< Trk::PrepRawData >
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
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
InDet::PixelClusterContainerCnv_p1::TRANS
InDet::PixelClusterContainer TRANS
Definition: PixelClusterContainerCnv_p1.h:32
PixelCluster.h
InDet::PixelClusterContainerCnv_p1::createTransient
virtual InDet::PixelClusterContainer * createTransient(const InDet::InDetPRD_Container_p1 *persObj, MsgStream &log)
Definition: PixelClusterContainerCnv_p1.cxx:140
InDet::PixelClusterContainerCnv_p1::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: PixelClusterContainerCnv_p1.cxx:24
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:205
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::PixelClusterContainer
Trk::PrepRawDataContainer< PixelClusterCollection > PixelClusterContainer
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelClusterContainer.h:28
InDet::InDetPRD_Collection_p1
Definition: InDetPRD_Collection_p1.h:11
PixelCluster_p1.h
TPObjRef
Definition: TPObjRef.h:20
ReadCondHandle.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
InDet::PixelClusterContainerCnv_p1::m_isInitialized
bool m_isInitialized
Definition: PixelClusterContainerCnv_p1.h:43
InDet::PixelClusterContainerCnv_p1::initialize
StatusCode initialize(MsgStream &log)
Definition: PixelClusterContainerCnv_p1.cxx:157
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
PixelClusterCnv_p1
Definition: PixelClusterCnv_p1.h:23
lumiFormat.i
int i
Definition: lumiFormat.py:92
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
PixelClusterContainerCnv_p1.h
InDet::InDetPRD_Collection_p1::m_begin
unsigned int m_begin
Definition: InDetPRD_Collection_p1.h:41
InDetPRD_Container_p1.h
InDet::PixelClusterContainerCnv_p1::m_pixId
const PixelID * m_pixId
Definition: PixelClusterContainerCnv_p1.h:39
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
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
PixelClusterContainer.h
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)
PixelID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: PixelID.cxx:912
InDet::PixelCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:49
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
InDet::PixelClusterContainerCnv_p1::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: PixelClusterContainerCnv_p1.h:41
InDet::PixelClusterContainerCnv_p1::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: PixelClusterContainerCnv_p1.cxx:72
InDet::PixelClusterContainerCnv_p1::m_useDetectorElement
bool m_useDetectorElement
Definition: PixelClusterContainerCnv_p1.h:42
IdentifierHash
Definition: IdentifierHash.h:38
InDet::PixelClusterContainerCnv_p1::m_storeGate
StoreGateSvc * m_storeGate
Definition: PixelClusterContainerCnv_p1.h:40
InDet::PixelClusterContainerCnv_p1::setUseDetectorElement
void setUseDetectorElement(const bool useDetectorElement)
Definition: PixelClusterContainerCnv_p1.cxx:192
StoreGateSvc.h
InDetDD::SiDetectorElementCollection::getDetectorElement
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Definition: SiDetectorElementCollection.cxx:15
InDet::PixelClusterCollection
Trk::PrepRawDataCollection< PixelCluster > PixelClusterCollection
Definition: PixelClusterCollection.h:26
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