ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_ClusterContainerCnv_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
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#include "GaudiKernel/StatusCode.h"
24
25void SCT_ClusterContainerCnv_p2::transToPers(const InDet::SCT_ClusterContainer* transCont, InDet::SCT_ClusterContainer_p2* persCont, MsgStream &log) {
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 //SCT_ClusterCnv_p2 chanCnv;
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
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 // unsigned int deltaId = (collection.identify().get_compact()-idLast)/IDJUMP;
87 // if(deltaId*IDJUMP != collection.identify().get_compact()-idLast )
88 // log << MSG::FATAL << "THere is a mistake in Identifiers of the collection" << endmsg;
89 // if(deltaId > 0xFFFF) {
90 // log << MSG::FATAL << "Fixme!!! This is too big, something needs to be done " << endmsg;
91 // }
92 // pcollection.m_idDelta = (unsigned short) deltaId;
93 // idLast = collection.identify().get_compact(); // then update the last identifier
94 pcollection.m_hashId = deltaId;
95 idLast=collection.identifyHash();
96 pcollection.m_size = collection.size();
97 // Add in channels
98 //persCont->m_rawdata.resize(chanEnd);
99 //persCont->m_prdDeltaId.resize(chanEnd);
100 // if (log.level() <= MSG::VERBOSE) log << MSG::VERBOSE << "Reading collections with " << collection.size() << "PRDs " << endmsg;
101 for (unsigned int i = 0; i < collection.size(); ++i) {
102 InDet::SCT_Cluster_p2* pchan = &(persCont->m_rawdata[i + chanBegin]);
103 const InDet::SCT_Cluster* chan = dynamic_cast<const InDet::SCT_Cluster*>(collection[i]);
104 chanCnv.transToPers(chan, pchan, log);
105 //persCont->m_prdDeltaId[i+chanBegin]=chan->m_clusId.get_compact()-collection.identify().get_compact();
106 persCont->m_prdDeltaId[i+chanBegin]=m_sctId->calc_offset(collection.identify(), chan->identify() );
107 }
108 }
109 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing InDet::SCT_ClusterContainer" << endmsg;
110}
111
112void SCT_ClusterContainerCnv_p2::persToTrans(const InDet::SCT_ClusterContainer_p2* persCont, InDet::SCT_ClusterContainer* transCont, MsgStream &log)
113{
114
115 // The transient model has a container holding collections and the
116 // collections hold channels.
117 //
118 // The persistent model flattens this so that the persistent
119 // container has two vectors:
120 // 1) all collections, and
121 // 2) all channels
122 //
123 // The persistent collections, then only maintain indexes into the
124 // container's vector of all channels.
125 //
126 // So here we loop over all collection and extract their channels
127 // from the vector.
128
129 const InDetDD::SiDetectorElementCollection* elements(nullptr);
132 elements = *sctDetEleHandle;
133 if (not sctDetEleHandle.isValid() or elements==nullptr) {
134 log << MSG::FATAL << m_SCTDetEleCollKey.fullKey() << " is not available." << endmsg;
135 return;
136 }
137 }
138
139 InDet::SCT_ClusterCollection* coll = nullptr;
140
141 //SCT_ClusterCnv_p2 chanCnv;
142 SCT_ClusterCnv_p2 chanCnv(m_sctId);
143 unsigned int collBegin(0);
144 // this is the id of the latest collection read in
145 // This starts from the base of the TRT identifiers
146 unsigned int idLast(0);
147 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
148 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
149
150 // Create trans collection - in NOT owner of SCT_DriftCircle (SG::VIEW_ELEMENTS)
151 // IDet collection don't have the Ownership policy c'tor
152 const InDet::InDetPRD_Collection_p2& pcoll = persCont->m_collections[icoll];
153 idLast += pcoll.m_hashId;
154 // Identifier collID= Identifier(idLast);
155 IdentifierHash collIDHash=IdentifierHash((unsigned int) idLast);
156 Identifier collID = m_sctId->wafer_id(collIDHash);
157 coll = new InDet::SCT_ClusterCollection(collIDHash);
158 coll->setIdentifier(Identifier(collID));
159 unsigned int nchans = pcoll.m_size;
160 coll->resize(nchans);
161 const InDetDD::SiDetectorElement * de = (elements==nullptr ? nullptr : elements->getDetectorElement(collIDHash));
162 // Fill with channels:
163 // This is used to read the vector of errMat
164 // values and lenght of the value are specified in separate vectors
165 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Reading collection with " << nchans << "Channels " << endmsg;
166 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
167 const InDet::SCT_Cluster_p2* pchan = &(persCont->m_rawdata[ichan + collBegin]);
168 Identifier clusId=m_sctId->strip_id_offset(coll->identify() , persCont->m_prdDeltaId[ichan + collBegin]);
170 (chanCnv.createSCT_Cluster (pchan, clusId, de, log));
171 // chan->m_rdoList.resize(1);
172 // chan->m_rdoList[0]=chan->m_clusId;
173 //DC Bugfix: Set the idhash for this channel
174 chan->setHashAndIndex(collIDHash,ichan);
175 (*coll)[ichan] = chan;
176 }
177 collBegin += pcoll.m_size;
178
179 // register the PRD collection in IDC with hash - faster addCollection
180 StatusCode sc = transCont->addCollection(coll, collIDHash);
181 if (sc.isFailure()) {
182 throw std::runtime_error("Failed to add collection to ID Container");
183 }
184 // if (log.level() <= MSG::DEBUG) {
185 // log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " << collID << ", added to Identifiable container." << endmsg;
186 // }
187 }
188
189 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading InDet::SCT_ClusterContainer" << endmsg;
190}
191
192
193
194//================================================================
195InDet::SCT_ClusterContainer* SCT_ClusterContainerCnv_p2::createTransient(const InDet::SCT_ClusterContainer_p2* persObj, MsgStream& log) {
196 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "SCT_ClusterContainerCnv_p2::createTransient called " << endmsg;
197 if(!m_isInitialized) {
198 if (this->initialize(log) != StatusCode::SUCCESS) {
199 log << MSG::FATAL << "Could not initialize SCT_ClusterContainerCnv_p2 " << endmsg;
200 }
201 }
202 std::unique_ptr<InDet::SCT_ClusterContainer> trans(std::make_unique<InDet::SCT_ClusterContainer>(m_sctId->wafer_hash_max()));
203 persToTrans(persObj, trans.get(), log);
204 return(trans.release());
205}
206
207
209 // Do not initialize again:
210 m_isInitialized=true;
211
212 // Get Storegate, ID helpers, and so on
213 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
214 CHECK( detStore.isValid() );
215
216 // Get the sct helper from the detector store
217 CHECK( detStore->retrieve(m_sctId, "SCT_ID") );
218
220
221 return StatusCode::SUCCESS;
222}
223
224// Methods for test/SCT_ClusterContainerCnv_p2_test.cxx
226 m_sctId = sct_id;
227}
228
229void SCT_ClusterContainerCnv_p2::setUseDetectorElement(const bool useDetectorElement) {
230 m_useDetectorElement = useDetectorElement;
231}
#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< Identifier::diff_type > m_prdDeltaId
std::vector< InDet::SCT_Cluster_p2 > m_rawdata
std::vector< InDet::InDetPRD_Collection_p2 > m_collections
void transToPers(const InDet::SCT_Cluster *, InDet::SCT_Cluster_p2 *, MsgStream &)
InDet::SCT_Cluster createSCT_Cluster(const InDet::SCT_Cluster_p2 *persObj, Identifier clusId, const InDetDD::SiDetectorElement *detEl, MsgStream &log)
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
void setIdHelper(const SCT_ID *sct_id)
virtual void transToPers(const InDet::SCT_ClusterContainer *transCont, InDet::SCT_ClusterContainer_p2 *persCont, MsgStream &log)
StatusCode initialize(MsgStream &log)
void setUseDetectorElement(const bool useDetectorElement)
virtual void persToTrans(const InDet::SCT_ClusterContainer_p2 *persCont, InDet::SCT_ClusterContainer *transCont, MsgStream &log)
virtual InDet::SCT_ClusterContainer * createTransient(const InDet::SCT_ClusterContainer_p2 *persObj, MsgStream &log)
This is an Identifier helper class for the SCT subdetector.
Definition SCT_ID.h:68
void initialize()