ATLAS Offline Software
PixelClusterContainerCnv_p2.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
7 #include "Identifier/Identifier.h"
17 #include "StoreGate/StoreGateSvc.h"
18 
19 // Gaudi
20 #include "GaudiKernel/ISvcLocator.h"
21 #include "GaudiKernel/Bootstrap.h"
22 #include "GaudiKernel/StatusCode.h"
23 #include "GaudiKernel/Service.h"
24 #include "GaudiKernel/MsgStream.h"
25 
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 PRD
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 
43  using TRANS = InDet::PixelClusterContainer;
44 
45  // this is the id of the latest collection read in
46  // This starts from the base of the TRT identifiers
47  unsigned int idLast(0);
48 
49  //
50  PixelClusterCnv_p2 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  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
59  // Add in new collection
60  const InDet::PixelClusterCollection& collection = (**it_Coll);
61  chanBegin = chanEnd;
62  chanEnd += collection.size();
63  InDet::InDetPRD_Collection_p2& pcollection = persCont->m_collections[collIndex];
64  unsigned int deltaId = (collection.identifyHash()-idLast);
65  // unsigned int deltaId = (collection.identify().get_compact()-idLast)/IDJUMP;
66  // if(deltaId*IDJUMP != collection.identify().get_compact()-idLast )
67  // log << MSG::FATAL << "THere is a mistake in Identifiers of the collection" << endmsg;
68  // if(deltaId > 0xFFFF) {
69  // log << MSG::FATAL << "Fixme!!! This is too big, something needs to be done " << endmsg;
70  // }
71  // pcollection.m_idDelta = (unsigned short) deltaId;
72  // idLast = collection.identify().get_compact(); // then update the last identifier
73  pcollection.m_hashId = deltaId;
74  idLast=collection.identifyHash();
75  pcollection.m_size = collection.size();
76  // Add in channels
77  persCont->m_rawdata.resize(chanEnd);
78  log << MSG::VERBOSE << "Reading collections with " << collection.size() << "PRDs " << endmsg;
79  for (unsigned int i = 0; i < collection.size(); ++i) {
80  InDet::PixelCluster_p2* pchan = &(persCont->m_rawdata[i + chanBegin]);
81  const InDet::PixelCluster* chan = dynamic_cast<const InDet::PixelCluster*>(collection[i]);
82  chanCnv.transToPers(chan, pchan, log);
83  }
84  }
85  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing InDet::PixelClusterContainer" << endmsg;
86 }
87 
89 {
90 
91  // The transient model has a container holding collections and the
92  // collections hold channels.
93  //
94  // The persistent model flattens this so that the persistent
95  // container has two vectors:
96  // 1) all collections, and
97  // 2) all channels
98  //
99  // The persistent collections, then only maintain indexes into the
100  // container's vector of all channels.
101  //
102  // So here we loop over all collection and extract their channels
103  // from the vector.
104 
105  const InDetDD::SiDetectorElementCollection* elements(nullptr);
106  if (m_useDetectorElement) {
108  elements = *pixelDetEleHandle;
109  if (not pixelDetEleHandle.isValid() or elements==nullptr) {
110  log << MSG::FATAL << m_pixelDetEleCollKey.fullKey() << " is not available." << endmsg;
111  return;
112  }
113  }
114 
115  InDet::PixelClusterCollection* coll = nullptr;
116 
117  PixelClusterCnv_p2 chanCnv;
118  unsigned int collBegin(0);
119  // this is the id of the latest collection read in
120  // This starts from the base of the TRT identifiers
121  unsigned int idLast(0);
122  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
123  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
124 
125  // Create trans collection - in NOT owner of PixelDriftCircle (SG::VIEW_ELEMENTS)
126  // IDet collection don't have the Ownership policy c'tor
127  const InDet::InDetPRD_Collection_p2& pcoll = persCont->m_collections[icoll];
128  idLast += pcoll.m_hashId;
129  // Identifier collID= Identifier(idLast);
130  IdentifierHash collIDHash=IdentifierHash((unsigned int) idLast);
131  Identifier collID = m_pixId->wafer_id(collIDHash);
132  coll = new InDet::PixelClusterCollection(collIDHash);
133  coll->setIdentifier(Identifier(collID));
134  unsigned int nchans = pcoll.m_size;
135  coll->resize(nchans);
136  const InDetDD::SiDetectorElement * de = (elements==nullptr ? nullptr : elements->getDetectorElement(collIDHash));
137  // Fill with channels:
138  // This is used to read the vector of errMat
139  // values and lenght of the value are specified in separate vectors
140  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Reading collection with " << nchans << "Channels " << endmsg;
141  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
142  const InDet::PixelCluster_p2* pchan = &(persCont->m_rawdata[ichan + collBegin]);
144  chanCnv.persToTrans(pchan, chan, log);
145  chan->setDetectorElement(de);
146  // DC Bugfix: Set the hash index!
147  chan->setHashAndIndex(collIDHash, ichan);
148  (*coll)[ichan] = chan;
149  }
150  collBegin += pcoll.m_size;
151 
152  // register the PRD collection in IDC with hash - faster addCollection
153  StatusCode sc = transCont->addCollection(coll, collIDHash);
154  if (sc.isFailure()) {
155  throw std::runtime_error("Failed to add collection to ID Container");
156  }
157  // if (log.level() <= MSG::DEBUG) {
158  // log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " << collID << ", added to Identifiable container." << endmsg;
159  // }
160  }
161 
162  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading InDet::PixelClusterContainer" << endmsg;
163 }
164 
165 
166 
167 //================================================================
169  if(!m_isInitialized) {
170  if (this->initialize(log) != StatusCode::SUCCESS) {
171  log << MSG::FATAL << "Could not initialize PixelClusterContainerCnv_p2 " << endmsg;
172  }
173  }
174  if (not m_pixId) {
175  log << MSG::FATAL << "nullptr for m_pixId in PixelClusterContainerCnv_p2::createTransient" << endmsg;
176  return nullptr;
177  }
178  std::unique_ptr<InDet::PixelClusterContainer> trans(std::make_unique<InDet::PixelClusterContainer>(m_pixId->wafer_hash_max()));
179  persToTrans(persObj, trans.get(), log);
180  return(trans.release());
181 }
182 
183 
185  // Do not initialize again:
186  m_isInitialized=true;
187  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "PixelClusterContainerCnv_p2::initialize called " << endmsg;
188  // Get Storegate, ID helpers, and so on
189  ISvcLocator* svcLocator = Gaudi::svcLocator();
190  // get StoreGate service
191  StatusCode sc = svcLocator->service("StoreGateSvc", m_storeGate);
192  if (sc.isFailure()) {
193  log << MSG::FATAL << "StoreGate service not found !" << endmsg;
194  return StatusCode::FAILURE;
195  }
196 
197  // get DetectorStore service
199  sc = svcLocator->service("DetectorStore", detStore);
200  if (sc.isFailure()) {
201  log << MSG::FATAL << "DetectorStore service not found !" << endmsg;
202  return StatusCode::FAILURE;
203  }
204  // else {
205  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found DetectorStore." << endmsg;
206  // }
207 
208  // Get the sct helper from the detector store
209  sc = detStore->retrieve(m_pixId, "PixelID");
210  if (sc.isFailure()) {
211  log << MSG::FATAL << "Could not get PixelID helper !" << endmsg;
212  return StatusCode::FAILURE;
213  }
214  // else {
215  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found the PixelID helper." << endmsg;
216  // }
217 
219 
220  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized." << endmsg;
221  return StatusCode::SUCCESS;
222 }
223 
224 void PixelClusterContainerCnv_p2::setUseDetectorElement(const bool useDetectorElement) {
225  m_useDetectorElement = useDetectorElement;
226 }
InDet::InDetPRD_Collection_p2::m_hashId
unsigned short m_hashId
Definition: InDetPRD_Collection_p2.h:35
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
PixelClusterCnv_p2::transToPers
void transToPers(const InDet::PixelCluster *, InDet::PixelCluster_p2 *, MsgStream &)
Definition: PixelClusterCnv_p2.cxx:73
PixelClusterContainerCnv_p2::m_isInitialized
bool m_isInitialized
Definition: PixelClusterContainerCnv_p2.h:44
InDetPRD_Collection_p2.h
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
PixelCluster.h
PixelClusterContainerCnv_p2::m_useDetectorElement
bool m_useDetectorElement
Definition: PixelClusterContainerCnv_p2.h:43
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:205
PixelCluster_p2.h
InDet::PixelClusterContainer_p2
Definition: PixelClusterContainer_p2.h:21
InDet::PixelClusterContainer
Trk::PrepRawDataContainer< PixelClusterCollection > PixelClusterContainer
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelClusterContainer.h:28
PixelClusterContainerCnv_p2::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: PixelClusterContainerCnv_p2.h:42
InDet::PixelClusterContainer_p2::m_collections
std::vector< InDet::InDetPRD_Collection_p2 > m_collections
Definition: PixelClusterContainer_p2.h:26
PixelID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition: PixelID.h:364
ReadCondHandle.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
PixelClusterContainerCnv_p2::createTransient
virtual InDet::PixelClusterContainer * createTransient(const InDet::PixelClusterContainer_p2 *persObj, MsgStream &log)
Definition: PixelClusterContainerCnv_p2.cxx:168
PixelClusterContainerCnv_p2::transToPers
virtual void transToPers(const InDet::PixelClusterContainer *transCont, InDet::PixelClusterContainer_p2 *persCont, MsgStream &log)
Definition: PixelClusterContainerCnv_p2.cxx:26
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
PixelClusterContainerCnv_p2.h
InDet::PixelClusterContainer_p2::m_rawdata
std::vector< InDet::PixelCluster_p2 > m_rawdata
Definition: PixelClusterContainer_p2.h:27
InDet::InDetPRD_Collection_p2::m_size
unsigned short m_size
Definition: InDetPRD_Collection_p2.h:40
PixelClusterContainerCnv_p2::setUseDetectorElement
void setUseDetectorElement(const bool useDetectorElement)
Definition: PixelClusterContainerCnv_p2.cxx:224
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
InDet::InDetPRD_Collection_p2
Definition: InDetPRD_Collection_p2.h:11
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
PixelClusterContainerCnv_p2::m_pixId
const PixelID * m_pixId
Definition: PixelClusterContainerCnv_p2.h:40
PixelClusterCnv_p2::persToTrans
void persToTrans(const InDet::PixelCluster_p2 *, InDet::PixelCluster *, MsgStream &)
Definition: PixelClusterCnv_p2.cxx:67
PixelClusterContainerCnv_p2::persToTrans
virtual void persToTrans(const InDet::PixelClusterContainer_p2 *persCont, InDet::PixelClusterContainer *transCont, MsgStream &log)
Definition: PixelClusterContainerCnv_p2.cxx:88
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
PixelClusterCnv_p2
Definition: PixelClusterCnv_p2.h:27
PixelClusterContainerCnv_p2::initialize
StatusCode initialize(MsgStream &log)
Definition: PixelClusterContainerCnv_p2.cxx:184
defineDB.ichan
int ichan
Definition: JetTagCalibration/share/defineDB.py:28
PixelClusterContainer.h
errorcheck.h
Helpers for checking error return status codes and reporting errors.
PixelClusterContainer_p2.h
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::PixelCluster_p2
Definition: PixelCluster_p2.h:17
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
IdentifierHash
Definition: IdentifierHash.h:38
StoreGateSvc.h
PixelClusterContainerCnv_p2::m_storeGate
StoreGateSvc * m_storeGate
Definition: PixelClusterContainerCnv_p2.h:41
InDetDD::SiDetectorElementCollection::getDetectorElement
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Definition: SiDetectorElementCollection.cxx:15
InDet::PixelClusterCollection
Trk::PrepRawDataCollection< PixelCluster > PixelClusterCollection
Definition: PixelClusterCollection.h:26
PixelClusterCnv_p2.h