ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_ClusterContainerCnv_p3.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// Athena
9#include "Identifier/Identifier.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
24void SCT_ClusterContainerCnv_p3::transToPers(const InDet::SCT_ClusterContainer* transCont, InDet::SCT_ClusterContainer_p3* persCont, MsgStream &log) {
25
26 // The transient model has a container holding collections and the
27 // collections hold channels.
28 //
29 // The persistent model flattens this so that the persistent
30 // container has two vectors:
31 // 1) all collections, and
32 // 2) all PRD
33 //
34 // The persistent collections, then only maintain indexes into the
35 // container's vector of all channels.
36 //
37 // So here we loop over all collection and add their channels
38 // to the container's vector, saving the indexes in the
39 // collection.
40
41 using TRANS = InDet::SCT_ClusterContainer;
42
43 // this is the id of the latest collection read in
44 // This starts from the base of the TRT identifiers
45 unsigned int idLast(0);
46
47 //
48
49 TRANS::const_iterator it_Coll = transCont->begin();
50 TRANS::const_iterator it_CollEnd = transCont->end();
51 unsigned int collIndex;
52 unsigned int chanBegin = 0;
53 unsigned int chanEnd = 0;
54
55 //to retrieve the SCT_ID helper
56 if(!m_isInitialized) {
57 if (this->initialize(log) != StatusCode::SUCCESS) {
58 log << MSG::FATAL << "Could not initialize SCT_ClusterContainerCnv_p2 " << endmsg;
59 }
60 }
61
63
64 persCont->m_collections.resize(transCont->numberOfCollections());
65
66 // to avoid the inside-loop resize
67 int totSize = 0;
68 //for ( ; it_Coll != it_CollEnd; it_Coll++) {
69 for ( it_Coll=transCont->begin(); it_Coll != it_CollEnd; ++it_Coll) {
70 const InDet::SCT_ClusterCollection& collection = (**it_Coll);
71 totSize+=collection.size();
72 }
73 persCont->m_rawdata.resize(totSize);
74 persCont->m_prdDeltaId.resize(totSize);
75
76 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
77 //for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, it_Coll++) {
78 for (collIndex = 0, it_Coll=transCont->begin(); it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
79 // Add in new collection
80 const InDet::SCT_ClusterCollection& collection = (**it_Coll);
81 chanBegin = chanEnd;
82 chanEnd += collection.size();
83 InDet::InDetPRD_Collection_p2& pcollection = persCont->m_collections[collIndex];
84 unsigned int deltaId = (collection.identifyHash()-idLast);
85
86 pcollection.m_hashId = deltaId;
87 idLast=collection.identifyHash();
88 pcollection.m_size = collection.size();
89 // Add in channels
90
91 for (unsigned int i = 0; i < collection.size(); ++i) {
92 InDet::SCT_Cluster_p3* pchan = &(persCont->m_rawdata[i + chanBegin]);
93 const InDet::SCT_Cluster* chan = static_cast<const InDet::SCT_Cluster*>(collection[i]);
94 chanCnv.transToPers(chan, pchan, log);
95
96 persCont->m_prdDeltaId[i+chanBegin]=m_sctId->calc_offset(collection.identify(), chan->identify() );
97 }
98 }
99
100}
101
102void SCT_ClusterContainerCnv_p3::persToTrans(const InDet::SCT_ClusterContainer_p3* persCont, InDet::SCT_ClusterContainer* transCont, MsgStream &log)
103{
104 if(!m_isInitialized) {
105 if (this->initialize(log) != StatusCode::SUCCESS) {
106 log << MSG::FATAL << "Could not initialize SCT_ClusterContainerCnv_p3 from persToTrans" << endmsg;
107 }
108 }
109
110 // The transient model has a container holding collections and the
111 // collections hold channels.
112 //
113 // The persistent model flattens this so that the persistent
114 // container has two vectors:
115 // 1) all collections, and
116 // 2) all channels
117 //
118 // The persistent collections, then only maintain indexes into the
119 // container's vector of all channels.
120 //
121 // So here we loop over all collection and extract their channels
122 // from the vector.
123
124 const InDetDD::SiDetectorElementCollection* elements(nullptr);
126 try {
128 elements = sctDetEleHandle1.cptr();
129 } catch (const SG::ExcNoCondCont& e) {
130 log << MSG::DEBUG << m_SCTDetEleCollKey << " is not available - probably RUN4, trying "<<m_ITkStripDetEleCollKey<<" instead."<< endmsg;
131 // If the first key fails, try the second key
132 try {
134 elements = sctDetEleHandle2.cptr();
135 } catch (const SG::ExcNoCondCont& e) {
136 log << MSG::FATAL << "No valid SCT detector element collection keys available." << endmsg;
137 return;
138 }
139 }
140 }
141
142 InDet::SCT_ClusterCollection* coll = nullptr;
143
144 //SCT_ClusterCnv_p2 chanCnv;
145 SCT_ClusterCnv_p3 chanCnv(m_sctId);
146 unsigned int collBegin(0);
147 // this is the id of the latest collection read in
148 // This starts from the base of the TRT identifiers
149 unsigned int idLast(0);
150 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
151 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
152
153 // Create trans collection - in NOT owner of SCT_DriftCircle (SG::VIEW_ELEMENTS)
154 // IDet collection don't have the Ownership policy c'tor
155 const InDet::InDetPRD_Collection_p2& pcoll = persCont->m_collections[icoll];
156 idLast += pcoll.m_hashId;
157 // Identifier collID= Identifier(idLast);
158 IdentifierHash collIDHash=IdentifierHash((unsigned int) idLast);
159 Identifier collID = m_sctId->wafer_id(collIDHash);
160 coll = new InDet::SCT_ClusterCollection(collIDHash);
161 coll->setIdentifier(Identifier(collID));
162 unsigned int nchans = pcoll.m_size;
163 coll->resize(nchans);
164 const InDetDD::SiDetectorElement * de = (elements==nullptr ? nullptr : elements->getDetectorElement(collIDHash));
165 // Fill with channels:
166 // This is used to read the vector of errMat
167 // values and lenght of the value are specified in separate vectors
168 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Reading collection with " << nchans << "Channels " << endmsg;
169 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
170 const InDet::SCT_Cluster_p3* pchan = &(persCont->m_rawdata[ichan + collBegin]);
171 //chan->m_clusId=Identifier(collID.get_compact()+persCont->m_prdDeltaId[ichan + collBegin]);
172 Identifier clusId=m_sctId->strip_id_offset(coll->identify() , persCont->m_prdDeltaId[ichan + collBegin]);
174 (chanCnv.createSCT_Cluster (pchan, clusId, de, log));
175
176 // chan->m_rdoList.resize(1);
177 // chan->m_rdoList[0]=chan->m_clusId;
178 //DC Bugfix: Set the idhash for this channel
179 chan->setHashAndIndex(collIDHash,ichan);
180 (*coll)[ichan] = chan;
181 }
182 collBegin += pcoll.m_size;
183
184 // register the PRD collection in IDC with hash - faster addCollection
185 StatusCode sc = transCont->addCollection(coll, collIDHash);
186 if (sc.isFailure()) {
187 throw std::runtime_error("Failed to add collection to ID Container");
188 }
189
190 }
191
192
193}
194
195
196
197//================================================================
198InDet::SCT_ClusterContainer* SCT_ClusterContainerCnv_p3::createTransient(const InDet::SCT_ClusterContainer_p3* persObj, MsgStream& log) {
199 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "SCT_ClusterContainerCnv_p2::createTransient called " << endmsg;
200 if(!m_isInitialized) {
201 if (this->initialize(log) != StatusCode::SUCCESS) {
202 log << MSG::FATAL << "Could not initialize SCT_ClusterContainerCnv_p3 " << endmsg;
203 }
204 }
205 std::unique_ptr<InDet::SCT_ClusterContainer> trans(std::make_unique<InDet::SCT_ClusterContainer>(m_sctId->wafer_hash_max()));
206 persToTrans(persObj, trans.get(), log);
207 return(trans.release());
208}
209
210
212 // Do not initialize again:
213 m_isInitialized=true;
214
215 // Get Storegate, ID helpers, and so on
216 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
217 CHECK( detStore.isValid() );
218
219 // Get the sct helper from the detector store
220 CHECK( detStore->retrieve(m_sctId, "SCT_ID") );
221
224
225 return StatusCode::SUCCESS;
226}
227
228// Methods for test/SCT_ClusterContainerCnv_p3_test.cxx
230 m_sctId = sct_id;
231}
232
233void SCT_ClusterContainerCnv_p3::setUseDetectorElement(const bool useDetectorElement) {
234 m_useDetectorElement = useDetectorElement;
235}
#define endmsg
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t sc
This is an Identifier helper class for the SCT subdetector.
size_type size() const noexcept
This is a "hash" representation of an Identifier.
Class to hold the SiDetectorElement objects to be put in the detector store.
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Class to hold geometrical description of a silicon detector element.
std::vector< InDet::SCT_Cluster_p3 > m_rawdata
std::vector< Identifier::diff_type > m_prdDeltaId
std::vector< InDet::InDetPRD_Collection_p2 > m_collections
void transToPers(const InDet::SCT_Cluster *, InDet::SCT_Cluster_p3 *, MsgStream &)
InDet::SCT_Cluster createSCT_Cluster(const InDet::SCT_Cluster_p3 *persObj, Identifier clusId, const InDetDD::SiDetectorElement *detEl, MsgStream &log)
virtual void transToPers(const InDet::SCT_ClusterContainer *transCont, InDet::SCT_ClusterContainer_p3 *persCont, MsgStream &log)
virtual InDet::SCT_ClusterContainer * createTransient(const InDet::SCT_ClusterContainer_p3 *persObj, MsgStream &log)
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_ITkStripDetEleCollKey
virtual void persToTrans(const InDet::SCT_ClusterContainer_p3 *persCont, InDet::SCT_ClusterContainer *transCont, MsgStream &log)
StatusCode initialize(MsgStream &log)
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
void setIdHelper(const SCT_ID *sct_id)
void setUseDetectorElement(const bool useDetectorElement)
This is an Identifier helper class for the SCT subdetector.
Definition SCT_ID.h:68
Exception — Can't retrieve CondCont from ReadCondHandle.
const_pointer_type cptr()
void initialize()