ATLAS Offline Software
PixelClusterContainerCnv_p3.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 // Athena
9 #include "Identifier/Identifier.h"
18 #include "StoreGate/StoreGateSvc.h"
19 
20 // Gaudi
21 #include "GaudiKernel/Bootstrap.h"
22 #include "GaudiKernel/ISvcLocator.h"
23 #include "GaudiKernel/MsgStream.h"
24 #include "GaudiKernel/Service.h"
25 #include "GaudiKernel/StatusCode.h"
26 
28 
29  // The transient model has a container holding collections and the
30  // collections hold channels.
31  //
32  // The persistent model flattens this so that the persistent
33  // container has two vectors:
34  // 1) all collections, and
35  // 2) all PRD
36  //
37  // The persistent collections, then only maintain indexes into the
38  // container's vector of all channels.
39  //
40  // So here we loop over all collection and add their channels
41  // to the container's vector, saving the indexes in the
42  // collection.
43 
44  using TRANS = InDet::PixelClusterContainer;
45 
46  // this is the id of the latest collection read in
47  // This starts from the base of the TRT identifiers
48  unsigned int idLast(0);
49 
50  //
51  //PixelClusterCnv_p3 chanCnv;
52  if(!m_isInitialized) {
53  if (this->initialize(log) != StatusCode::SUCCESS) {
54  log << MSG::FATAL << "Could not initialize PixelClusterContainerCnv_p3 " << endmsg;
55  }
56  }
57  PixelClusterCnv_p3 chanCnv(m_pixId);
58 
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  persCont->m_collections.resize(transCont->numberOfCollections());
65  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
66  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
67  // Add in new collection
68  const InDet::PixelClusterCollection& collection = (**it_Coll);
69  chanBegin = chanEnd;
70  chanEnd += collection.size();
71  InDet::InDetPRD_Collection_p2& pcollection = persCont->m_collections[collIndex];
72  unsigned int deltaId = (collection.identifyHash()-idLast);
73  // unsigned int deltaId = (collection.identify().get_compact()-idLast)/IDJUMP;
74  // if(deltaId*IDJUMP != collection.identify().get_compact()-idLast )
75  // log << MSG::FATAL << "THere is a mistake in Identifiers of the collection" << endmsg;
76  // if(deltaId > 0xFFFF) {
77  // log << MSG::FATAL << "Fixme!!! This is too big, something needs to be done " << endmsg;
78  // }
79  // pcollection.m_idDelta = (unsigned short) deltaId;
80  // idLast = collection.identify().get_compact(); // then update the last identifier
81  pcollection.m_hashId = deltaId;
82  idLast=collection.identifyHash();
83  pcollection.m_size = collection.size();
84  // Add in channels
85  persCont->m_rawdata.resize(chanEnd);
86  // if (log.level() <= MSG::VERBOSE) log << MSG::VERBOSE << "Reading collections with " << collection.size() << "PRDs " << endmsg;
87  for (unsigned int i = 0; i < collection.size(); ++i) {
88  InDet::PixelCluster_p3* pchan = &(persCont->m_rawdata[i + chanBegin]);
89  const InDet::PixelCluster* chan = dynamic_cast<const InDet::PixelCluster*>(collection[i]);
90  chanCnv.transToPers(chan, pchan, log);
91  }
92  }
93  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing InDet::PixelClusterContainer" << endmsg;
94 }
95 
97 {
98 
99  // The transient model has a container holding collections and the
100  // collections hold channels.
101  //
102  // The persistent model flattens this so that the persistent
103  // container has two vectors:
104  // 1) all collections, and
105  // 2) all channels
106  //
107  // The persistent collections, then only maintain indexes into the
108  // container's vector of all channels.
109  //
110  // So here we loop over all collection and extract their channels
111  // from the vector.
112 
113  const InDetDD::SiDetectorElementCollection* elements(nullptr);
114  if (m_useDetectorElement) {
115  try {
117  elements = pixelDetEleHandle1.cptr();
118  } catch (const SG::ExcNoCondCont& e) {
119  log << MSG::DEBUG << m_pixelDetEleCollKey << " is not available - probably RUN4, trying "<<m_pixelITkEleCollKey<<" instead."<< endmsg;
120  // If the first key fails, try the second key
121  try {
123  elements = pixelDetEleHandle2.cptr();
124  } catch (const SG::ExcNoCondCont& e) {
125  log << MSG::FATAL << "No valid Pixel detector element collection keys available." << endmsg;
126  return;
127  }
128  }
129  }
130 
131  InDet::PixelClusterCollection* coll = nullptr;
132 
133  //PixelClusterCnv_p3 chanCnv;
134  PixelClusterCnv_p3 chanCnv(m_pixId);
135  unsigned int collBegin(0);
136  // this is the id of the latest collection read in
137  // This starts from the base of the TRT identifiers
138  unsigned int idLast(0);
139  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
140  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
141 
142  // Create trans collection - in NOT owner of PixelDriftCircle (SG::VIEW_ELEMENTS)
143  // IDet collection don't have the Ownership policy c'tor
144  const InDet::InDetPRD_Collection_p2& pcoll = persCont->m_collections[icoll];
145  idLast += pcoll.m_hashId;
146  // Identifier collID= Identifier(idLast);
147  IdentifierHash collIDHash=IdentifierHash((unsigned int) idLast);
148  Identifier collID = m_pixId->wafer_id(collIDHash);
149  coll = new InDet::PixelClusterCollection(collIDHash);
150  coll->setIdentifier(Identifier(collID));
151  unsigned int nchans = pcoll.m_size;
152  coll->resize(nchans);
153  const InDetDD::SiDetectorElement * de = (elements==nullptr ? nullptr : elements->getDetectorElement(collIDHash));
154  // Fill with channels:
155  // This is used to read the vector of errMat
156  // values and lenght of the value are specified in separate vectors
157  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Reading collection with " << nchans << "Channels " << endmsg;
158  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
159  const InDet::PixelCluster_p3* pchan = &(persCont->m_rawdata[ichan + collBegin]);
160  // In preparation for 64-bit ids, set the initial cluster
161  // id to the wafer id. Actual cluster id will be set in
162  // the converter from diff.
164  (chanCnv.createPixelCluster (pchan, collID, de, log));
165  // DC Bugfix: Set the hash index!
166  chan->setHashAndIndex(collIDHash, ichan);
167  (*coll)[ichan] = chan;
168  }
169  collBegin += pcoll.m_size;
170 
171  // register the PRD collection in IDC with hash - faster addCollection
172  StatusCode sc = transCont->addCollection(coll, collIDHash);
173  if (sc.isFailure()) {
174  throw std::runtime_error("Failed to add collection to ID Container");
175  }
176  // if (log.level() <= MSG::DEBUG) {
177  // log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " << collID << ", added to Identifiable container." << endmsg;
178  // }
179  }
180 
181  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading InDet::PixelClusterContainer" << endmsg;
182 }
183 
184 
185 
186 //================================================================
188  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "PixelClusterContainerCnv_p3::createTransient called " << endmsg;
189  if(!m_isInitialized) {
190  if (this->initialize(log) != StatusCode::SUCCESS) {
191  log << MSG::FATAL << "Could not initialize PixelClusterContainerCnv_p3 " << endmsg;
192  }
193  }
194  if (not m_pixId) {
195  log << MSG::FATAL << "nullptr for m_pixId in PixelClusterContainerCnv_p3::createTransient" << endmsg;
196  return nullptr;
197  }
198  std::unique_ptr<InDet::PixelClusterContainer> trans(std::make_unique<InDet::PixelClusterContainer>(m_pixId->wafer_hash_max()));
199  persToTrans(persObj, trans.get(), log);
200  return(trans.release());
201 }
202 
203 
205  // Do not initialize again:
206  m_isInitialized=true;
207  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "PixelClusterContainerCnv_p3::initialize called " << endmsg;
208  // Get Storegate, ID helpers, and so on
209  ISvcLocator* svcLocator = Gaudi::svcLocator();
210  // get StoreGate service
211  StatusCode sc = svcLocator->service("StoreGateSvc", m_storeGate);
212  if (sc.isFailure()) {
213  log << MSG::FATAL << "StoreGate service not found !" << endmsg;
214  return StatusCode::FAILURE;
215  }
216 
217  // get DetectorStore service
219  sc = svcLocator->service("DetectorStore", detStore);
220  if (sc.isFailure()) {
221  log << MSG::FATAL << "DetectorStore service not found !" << endmsg;
222  return StatusCode::FAILURE;
223  }
224  // else {
225  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found DetectorStore." << endmsg;
226  // }
227 
228  // Get the Pixel helper from the detector store
229  sc = detStore->retrieve(m_pixId, "PixelID");
230  if (sc.isFailure()) {
231  log << MSG::FATAL << "Could not get PixelID helper !" << endmsg;
232  return StatusCode::FAILURE;
233  }
234  // else {
235  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found the PixelID helper." << endmsg;
236  // }
237 
240  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized." << endmsg;
241  return StatusCode::SUCCESS;
242 }
243 
244 void PixelClusterContainerCnv_p3::setUseDetectorElement(const bool useDetectorElement) {
245  m_useDetectorElement = useDetectorElement;
246 }
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...
InDetPRD_Collection_p2.h
InDet::PixelCluster_p3
Definition: PixelCluster_p3.h:18
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
PixelCluster_p3.h
InDet::PixelClusterContainer_p3::m_collections
std::vector< InDet::InDetPRD_Collection_p2 > m_collections
Definition: PixelClusterContainer_p3.h:26
PixelClusterCnv_p3::transToPers
void transToPers(const InDet::PixelCluster *, InDet::PixelCluster_p3 *, MsgStream &)
Definition: PixelClusterCnv_p3.cxx:127
PixelClusterContainerCnv_p3::persToTrans
virtual void persToTrans(const InDet::PixelClusterContainer_p3 *persCont, InDet::PixelClusterContainer *transCont, MsgStream &log)
Definition: PixelClusterContainerCnv_p3.cxx:96
PixelClusterCnv_p3::createPixelCluster
InDet::PixelCluster createPixelCluster(const InDet::PixelCluster_p3 *persObj, const Identifier &waferId, const InDetDD::SiDetectorElement *delEl, MsgStream &log)
Definition: PixelClusterCnv_p3.cxx:29
InDet::PixelClusterContainer
Trk::PrepRawDataContainer< PixelClusterCollection > PixelClusterContainer
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelClusterContainer.h:28
PixelClusterCnv_p3.h
InDet::PixelClusterContainer_p3::m_rawdata
std::vector< InDet::PixelCluster_p3 > m_rawdata
Definition: PixelClusterContainer_p3.h:27
SG::ExcNoCondCont
Exception — Can't retrieve CondCont from ReadCondHandle.
Definition: Control/StoreGate/StoreGate/exceptions.h:330
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_p3.h
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
PixelClusterContainerCnv_p3::m_storeGate
StoreGateSvc * m_storeGate
Definition: PixelClusterContainerCnv_p3.h:45
InDet::InDetPRD_Collection_p2::m_size
unsigned short m_size
Definition: InDetPRD_Collection_p2.h:40
PixelClusterCnv_p3
Definition: PixelClusterCnv_p3.h:29
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
PixelClusterContainerCnv_p3::initialize
StatusCode initialize(MsgStream &log)
Definition: PixelClusterContainerCnv_p3.cxx:204
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
defineDB.ichan
int ichan
Definition: JetTagCalibration/share/defineDB.py:28
PixelClusterContainerCnv_p3::m_useDetectorElement
bool m_useDetectorElement
Definition: PixelClusterContainerCnv_p3.h:48
PixelClusterContainer.h
PixelClusterContainerCnv_p3::m_isInitialized
bool m_isInitialized
Definition: PixelClusterContainerCnv_p3.h:49
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
PixelClusterContainerCnv_p3::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: PixelClusterContainerCnv_p3.h:46
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
PixelClusterContainerCnv_p3::createTransient
virtual InDet::PixelClusterContainer * createTransient(const InDet::PixelClusterContainer_p3 *persObj, MsgStream &log)
Definition: PixelClusterContainerCnv_p3.cxx:187
DEBUG
#define DEBUG
Definition: page_access.h:11
PixelClusterContainer_p3.h
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
PixelClusterContainerCnv_p3::transToPers
virtual void transToPers(const InDet::PixelClusterContainer *transCont, InDet::PixelClusterContainer_p3 *persCont, MsgStream &log)
Definition: PixelClusterContainerCnv_p3.cxx:27
PixelClusterContainerCnv_p3::m_pixelITkEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelITkEleCollKey
Definition: PixelClusterContainerCnv_p3.h:47
PixelClusterContainerCnv_p3::m_pixId
const PixelID * m_pixId
Definition: PixelClusterContainerCnv_p3.h:44
IdentifierHash
Definition: IdentifierHash.h:38
InDet::PixelClusterContainer_p3
Definition: PixelClusterContainer_p3.h:21
StoreGateSvc.h
InDetDD::SiDetectorElementCollection::getDetectorElement
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Definition: SiDetectorElementCollection.cxx:15
PixelClusterContainerCnv_p3::setUseDetectorElement
void setUseDetectorElement(const bool useDetectorElement)
Definition: PixelClusterContainerCnv_p3.cxx:244
InDet::PixelClusterCollection
Trk::PrepRawDataCollection< PixelCluster > PixelClusterCollection
Definition: PixelClusterCollection.h:26
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition: ReadCondHandle.h:67