ATLAS Offline Software
SCT_ClusterContainerCnv_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"
10 #include "InDetIdentifier/SCT_ID.h"
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  // 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 PRD
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 
42  using TRANS = InDet::SCT_ClusterContainer;
43 
44  // this is the id of the latest collection read in
45  // This starts from the base of the TRT identifiers
46  unsigned int idLast(0);
47 
48  //
49 
50  TRANS::const_iterator it_Coll = transCont->begin();
51  TRANS::const_iterator it_CollEnd = transCont->end();
52  unsigned int collIndex;
53  unsigned int chanBegin = 0;
54  unsigned int chanEnd = 0;
55 
56  //to retrieve the SCT_ID helper
57  if(!m_isInitialized) {
58  if (this->initialize(log) != StatusCode::SUCCESS) {
59  log << MSG::FATAL << "Could not initialize SCT_ClusterContainerCnv_p2 " << endmsg;
60  }
61  }
62 
63  SCT_ClusterCnv_p3 chanCnv(m_sctId);
64 
65  persCont->m_collections.resize(transCont->numberOfCollections());
66 
67  // to avoid the inside-loop resize
68  int totSize = 0;
69  //for ( ; it_Coll != it_CollEnd; it_Coll++) {
70  for ( it_Coll=transCont->begin(); it_Coll != it_CollEnd; ++it_Coll) {
71  const InDet::SCT_ClusterCollection& collection = (**it_Coll);
72  totSize+=collection.size();
73  }
74  persCont->m_rawdata.resize(totSize);
75  persCont->m_prdDeltaId.resize(totSize);
76 
77  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
78  //for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, it_Coll++) {
79  for (collIndex = 0, it_Coll=transCont->begin(); it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
80  // Add in new collection
81  const InDet::SCT_ClusterCollection& collection = (**it_Coll);
82  chanBegin = chanEnd;
83  chanEnd += collection.size();
84  InDet::InDetPRD_Collection_p2& pcollection = persCont->m_collections[collIndex];
85  unsigned int deltaId = (collection.identifyHash()-idLast);
86 
87  pcollection.m_hashId = deltaId;
88  idLast=collection.identifyHash();
89  pcollection.m_size = collection.size();
90  // Add in channels
91 
92  for (unsigned int i = 0; i < collection.size(); ++i) {
93  InDet::SCT_Cluster_p3* pchan = &(persCont->m_rawdata[i + chanBegin]);
94  const InDet::SCT_Cluster* chan = dynamic_cast<const InDet::SCT_Cluster*>(collection[i]);
95  chanCnv.transToPers(chan, pchan, log);
96 
97  persCont->m_prdDeltaId[i+chanBegin]=m_sctId->calc_offset(collection.identify(), chan->identify() );
98  }
99  }
100 
101 }
102 
104 {
105  if(!m_isInitialized) {
106  if (this->initialize(log) != StatusCode::SUCCESS) {
107  log << MSG::FATAL << "Could not initialize SCT_ClusterContainerCnv_p3 from persToTrans" << endmsg;
108  }
109  }
110 
111  // The transient model has a container holding collections and the
112  // collections hold channels.
113  //
114  // The persistent model flattens this so that the persistent
115  // container has two vectors:
116  // 1) all collections, and
117  // 2) all channels
118  //
119  // The persistent collections, then only maintain indexes into the
120  // container's vector of all channels.
121  //
122  // So here we loop over all collection and extract their channels
123  // from the vector.
124 
125  const InDetDD::SiDetectorElementCollection* elements(nullptr);
126  if (m_useDetectorElement) {
127  try {
129  elements = sctDetEleHandle1.cptr();
130  } catch (const SG::ExcNoCondCont& e) {
131  log << MSG::DEBUG << m_SCTDetEleCollKey << " is not available - probably RUN4, trying "<<m_ITkStripDetEleCollKey<<" instead."<< endmsg;
132  // If the first key fails, try the second key
133  try {
135  elements = sctDetEleHandle2.cptr();
136  } catch (const SG::ExcNoCondCont& e) {
137  log << MSG::FATAL << "No valid SCT detector element collection keys available." << endmsg;
138  return;
139  }
140  }
141  }
142 
143  InDet::SCT_ClusterCollection* coll = nullptr;
144 
145  //SCT_ClusterCnv_p2 chanCnv;
146  SCT_ClusterCnv_p3 chanCnv(m_sctId);
147  unsigned int collBegin(0);
148  // this is the id of the latest collection read in
149  // This starts from the base of the TRT identifiers
150  unsigned int idLast(0);
151  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
152  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
153 
154  // Create trans collection - in NOT owner of SCT_DriftCircle (SG::VIEW_ELEMENTS)
155  // IDet collection don't have the Ownership policy c'tor
156  const InDet::InDetPRD_Collection_p2& pcoll = persCont->m_collections[icoll];
157  idLast += pcoll.m_hashId;
158  // Identifier collID= Identifier(idLast);
159  IdentifierHash collIDHash=IdentifierHash((unsigned int) idLast);
160  Identifier collID = m_sctId->wafer_id(collIDHash);
161  coll = new InDet::SCT_ClusterCollection(collIDHash);
162  coll->setIdentifier(Identifier(collID));
163  unsigned int nchans = pcoll.m_size;
164  coll->resize(nchans);
165  const InDetDD::SiDetectorElement * de = (elements==nullptr ? nullptr : elements->getDetectorElement(collIDHash));
166  // Fill with channels:
167  // This is used to read the vector of errMat
168  // values and lenght of the value are specified in separate vectors
169  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Reading collection with " << nchans << "Channels " << endmsg;
170  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
171  const InDet::SCT_Cluster_p3* pchan = &(persCont->m_rawdata[ichan + collBegin]);
172  //chan->m_clusId=Identifier(collID.get_compact()+persCont->m_prdDeltaId[ichan + collBegin]);
173  Identifier clusId=m_sctId->strip_id_offset(coll->identify() , persCont->m_prdDeltaId[ichan + collBegin]);
175  (chanCnv.createSCT_Cluster (pchan, clusId, de, log));
176 
177  // chan->m_rdoList.resize(1);
178  // chan->m_rdoList[0]=chan->m_clusId;
179  //DC Bugfix: Set the idhash for this channel
180  chan->setHashAndIndex(collIDHash,ichan);
181  (*coll)[ichan] = chan;
182  }
183  collBegin += pcoll.m_size;
184 
185  // register the PRD collection in IDC with hash - faster addCollection
186  StatusCode sc = transCont->addCollection(coll, collIDHash);
187  if (sc.isFailure()) {
188  throw std::runtime_error("Failed to add collection to ID Container");
189  }
190 
191  }
192 
193 
194 }
195 
196 
197 
198 //================================================================
200  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "SCT_ClusterContainerCnv_p2::createTransient called " << endmsg;
201  if(!m_isInitialized) {
202  if (this->initialize(log) != StatusCode::SUCCESS) {
203  log << MSG::FATAL << "Could not initialize SCT_ClusterContainerCnv_p3 " << endmsg;
204  }
205  }
206  std::unique_ptr<InDet::SCT_ClusterContainer> trans(std::make_unique<InDet::SCT_ClusterContainer>(m_sctId->wafer_hash_max()));
207  persToTrans(persObj, trans.get(), log);
208  return(trans.release());
209 }
210 
211 
213  // Do not initialize again:
214  m_isInitialized=true;
215  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "SCT_ClusterContainerCnv_p2::initialize called " << endmsg;
216  // Get Storegate, ID helpers, and so on
217  ISvcLocator* svcLocator = Gaudi::svcLocator();
218  // get StoreGate service
219  StatusCode sc = svcLocator->service("StoreGateSvc", m_storeGate);
220  if (sc.isFailure()) {
221  log << MSG::FATAL << "StoreGate service not found !" << endmsg;
222  return StatusCode::FAILURE;
223  }
224 
225  // get DetectorStore service
227  sc = svcLocator->service("DetectorStore", detStore);
228  if (sc.isFailure()) {
229  log << MSG::FATAL << "DetectorStore service not found !" << endmsg;
230  return StatusCode::FAILURE;
231  }
232  // else {
233  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found DetectorStore." << endmsg;
234  // }
235 
236  // Get the sct helper from the detector store
237  sc = detStore->retrieve(m_sctId, "SCT_ID");
238  if (sc.isFailure()) {
239  log << MSG::FATAL << "Could not get SCT_ID helper !" << endmsg;
240  return StatusCode::FAILURE;
241  }
242  // else {
243  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found the SCT_ID helper." << endmsg;
244  // }
245 
248  // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized." << endmsg;
249  return StatusCode::SUCCESS;
250 }
251 
252 // Methods for test/SCT_ClusterContainerCnv_p3_test.cxx
254  m_sctId = sct_id;
255 }
256 
257 void SCT_ClusterContainerCnv_p3::setUseDetectorElement(const bool useDetectorElement) {
258  m_useDetectorElement = useDetectorElement;
259 }
InDet::InDetPRD_Collection_p2::m_hashId
unsigned short m_hashId
Definition: InDetPRD_Collection_p2.h:35
SCT_ClusterContainerCnv_p3::m_sctId
const SCT_ID * m_sctId
Definition: SCT_ClusterContainerCnv_p3.h:45
SCT_ClusterContainerCnv_p3::transToPers
virtual void transToPers(const InDet::SCT_ClusterContainer *transCont, InDet::SCT_ClusterContainer_p3 *persCont, MsgStream &log)
Definition: SCT_ClusterContainerCnv_p3.cxx:25
InDetPRD_Collection_p2.h
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
SCT_ClusterCnv_p3.h
InDet::SCT_ClusterContainer_p3::m_rawdata
std::vector< InDet::SCT_Cluster_p3 > m_rawdata
Definition: SCT_ClusterContainer_p3.h:29
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_ClusterContainer_p3::m_prdDeltaId
std::vector< Identifier::diff_type > m_prdDeltaId
Definition: SCT_ClusterContainer_p3.h:32
InDet::SCT_ClusterContainer
Trk::PrepRawDataContainer< SCT_ClusterCollection > SCT_ClusterContainer
Definition: SCT_ClusterContainer.h:27
InDet::SCT_ClusterContainer_p3::m_collections
std::vector< InDet::InDetPRD_Collection_p2 > m_collections
Definition: SCT_ClusterContainer_p3.h:28
SCT_Cluster.h
SG::ExcNoCondCont
Exception — Can't retrieve CondCont from ReadCondHandle.
Definition: Control/StoreGate/StoreGate/exceptions.h:330
InDet::SCT_Cluster_p3
Definition: SCT_Cluster_p3.h:18
SCT_ClusterContainerCnv_p3::m_isInitialized
bool m_isInitialized
Definition: SCT_ClusterContainerCnv_p3.h:50
ReadCondHandle.h
SCT_Cluster_p3.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SCT_ID::calc_offset
Identifier::diff_type calc_offset(const Identifier &base, const Identifier &target) const
Calculate a channel offset between the two identifiers.
Definition: SCT_ID.h:679
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
InDet::InDetPRD_Collection_p2::m_size
unsigned short m_size
Definition: InDetPRD_Collection_p2.h:40
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
SCT_ClusterContainerCnv_p3::initialize
StatusCode initialize(MsgStream &log)
Definition: SCT_ClusterContainerCnv_p3.cxx:212
InDet::InDetPRD_Collection_p2
Definition: InDetPRD_Collection_p2.h:11
SCT_ClusterContainerCnv_p3::m_ITkStripDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_ITkStripDetEleCollKey
Definition: SCT_ClusterContainerCnv_p3.h:48
SCT_ClusterCnv_p3::transToPers
void transToPers(const InDet::SCT_Cluster *, InDet::SCT_Cluster_p3 *, MsgStream &)
Definition: SCT_ClusterCnv_p3.cxx:76
SCT_ClusterContainerCnv_p3::setUseDetectorElement
void setUseDetectorElement(const bool useDetectorElement)
Definition: SCT_ClusterContainerCnv_p3.cxx:257
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SCT_ClusterContainerCnv_p3.h
SCT_ClusterContainerCnv_p3::m_useDetectorElement
bool m_useDetectorElement
Definition: SCT_ClusterContainerCnv_p3.h:49
InDet::SCT_Cluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/SCT_Cluster.h:34
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
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:639
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)
SCT_ClusterContainerCnv_p3::setIdHelper
void setIdHelper(const SCT_ID *sct_id)
Definition: SCT_ClusterContainerCnv_p3.cxx:253
SCT_ClusterContainerCnv_p3::m_SCTDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
Definition: SCT_ClusterContainerCnv_p3.h:47
SCT_ClusterCnv_p3
Definition: SCT_ClusterCnv_p3.h:29
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
SCT_ID
Definition: SCT_ID.h:68
InDet::SCT_ClusterContainer_p3
Definition: SCT_ClusterContainer_p3.h:23
SCT_ClusterContainerCnv_p3::m_storeGate
StoreGateSvc * m_storeGate
Definition: SCT_ClusterContainerCnv_p3.h:46
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
SCT_ClusterCnv_p3::createSCT_Cluster
InDet::SCT_Cluster createSCT_Cluster(const InDet::SCT_Cluster_p3 *persObj, Identifier clusId, const InDetDD::SiDetectorElement *detEl, MsgStream &log)
Definition: SCT_ClusterCnv_p3.cxx:26
SCT_ID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition: SCT_ID.h:464
IdentifierHash
Definition: IdentifierHash.h:38
InDet::SCT_ClusterCollection
Trk::PrepRawDataCollection< SCT_Cluster > SCT_ClusterCollection
Definition: SCT_ClusterCollection.h:26
SCT_ClusterContainerCnv_p3::createTransient
virtual InDet::SCT_ClusterContainer * createTransient(const InDet::SCT_ClusterContainer_p3 *persObj, MsgStream &log)
Definition: SCT_ClusterContainerCnv_p3.cxx:199
StoreGateSvc.h
InDetDD::SiDetectorElementCollection::getDetectorElement
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Definition: SiDetectorElementCollection.cxx:15
SCT_ClusterContainerCnv_p3::persToTrans
virtual void persToTrans(const InDet::SCT_ClusterContainer_p3 *persCont, InDet::SCT_ClusterContainer *transCont, MsgStream &log)
Definition: SCT_ClusterContainerCnv_p3.cxx:103
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition: ReadCondHandle.h:67
SCT_ID::strip_id_offset
Identifier strip_id_offset(const Identifier &base, Identifier::diff_type offset) const
Create an identifier with a given base and channel offset.
Definition: SCT_ID.h:687