ATLAS Offline Software
Loading...
Searching...
No Matches
PixelClusterContainerCnv_p3.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"
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
27void PixelClusterContainerCnv_p3::transToPers(const InDet::PixelClusterContainer* transCont, InDet::PixelClusterContainer_p3* persCont, MsgStream &log) {
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 }
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
96void PixelClusterContainerCnv_p3::persToTrans(const InDet::PixelClusterContainer_p3* persCont, InDet::PixelClusterContainer* transCont, MsgStream &log)
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);
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;
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//================================================================
187InDet::PixelClusterContainer* PixelClusterContainerCnv_p3::createTransient(const InDet::PixelClusterContainer_p3* persObj, MsgStream& log) {
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
208 // Get Storegate, ID helpers, and so on
209 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
210 CHECK( detStore.isValid() );
211
212 // Get the Pixel helper from the detector store
213 CHECK( detStore->retrieve(m_pixId, "PixelID") );
214
217
218 return StatusCode::SUCCESS;
219}
220
221void PixelClusterContainerCnv_p3::setUseDetectorElement(const bool useDetectorElement) {
222 m_useDetectorElement = useDetectorElement;
223}
#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 Pixel 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::InDetPRD_Collection_p2 > m_collections
std::vector< InDet::PixelCluster_p3 > m_rawdata
InDet::PixelCluster createPixelCluster(const InDet::PixelCluster_p3 *persObj, const Identifier &waferId, const InDetDD::SiDetectorElement *delEl, MsgStream &log)
void transToPers(const InDet::PixelCluster *, InDet::PixelCluster_p3 *, MsgStream &)
virtual void transToPers(const InDet::PixelClusterContainer *transCont, InDet::PixelClusterContainer_p3 *persCont, MsgStream &log)
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelITkEleCollKey
void setUseDetectorElement(const bool useDetectorElement)
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
virtual InDet::PixelClusterContainer * createTransient(const InDet::PixelClusterContainer_p3 *persObj, MsgStream &log)
virtual void persToTrans(const InDet::PixelClusterContainer_p3 *persCont, InDet::PixelClusterContainer *transCont, MsgStream &log)
Exception — Can't retrieve CondCont from ReadCondHandle.
const_pointer_type cptr()
void initialize()