ATLAS Offline Software
PixelClusterContainerCnv_p2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
188  // Get Storegate, ID helpers, and so on
189  SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
190  CHECK( detStore.isValid() );
191 
192  // Get the sct helper from the detector store
193  CHECK( detStore->retrieve(m_pixId, "PixelID") );
194 
196 
197  return StatusCode::SUCCESS;
198 }
199 
200 void PixelClusterContainerCnv_p2::setUseDetectorElement(const bool useDetectorElement) {
201  m_useDetectorElement = useDetectorElement;
202 }
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:43
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:42
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
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:41
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
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:200
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_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:907
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
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
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
PixelClusterCnv_p2.h
Identifier
Definition: IdentifierFieldParser.cxx:14