ATLAS Offline Software
Loading...
Searching...
No Matches
PixelClusterContainerCnv_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"
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
74 pcollection.m_hashId = deltaId;
75 idLast=collection.identifyHash();
76 pcollection.m_size = collection.size();
77 // Add in channels
78 persCont->m_rawdata.resize(chanEnd);
79 for (unsigned int i = 0; i < collection.size(); ++i) {
80 InDet::PixelCluster_p3* pchan = &(persCont->m_rawdata[i + chanBegin]);
81 const InDet::PixelCluster* chan = static_cast<const InDet::PixelCluster*>(collection[i]);
82 chanCnv.transToPers(chan, pchan, log);
83 }
84 }
85}
86
87void PixelClusterContainerCnv_p3::persToTrans(const InDet::PixelClusterContainer_p3* persCont, InDet::PixelClusterContainer* transCont, MsgStream &log)
88{
89
90 // The transient model has a container holding collections and the
91 // collections hold channels.
92 //
93 // The persistent model flattens this so that the persistent
94 // container has two vectors:
95 // 1) all collections, and
96 // 2) all channels
97 //
98 // The persistent collections, then only maintain indexes into the
99 // container's vector of all channels.
100 //
101 // So here we loop over all collection and extract their channels
102 // from the vector.
103
104 const InDetDD::SiDetectorElementCollection* elements(nullptr);
106 try {
108 elements = pixelDetEleHandle1.cptr();
109 } catch (const SG::ExcNoCondCont& e) {
110 log << MSG::DEBUG << m_pixelDetEleCollKey << " is not available - probably RUN4, trying "<<m_pixelITkEleCollKey<<" instead."<< endmsg;
111 // If the first key fails, try the second key
112 try {
114 elements = pixelDetEleHandle2.cptr();
115 } catch (const SG::ExcNoCondCont& e) {
116 log << MSG::FATAL << "No valid Pixel detector element collection keys available." << endmsg;
117 return;
118 }
119 }
120 }
121
122 InDet::PixelClusterCollection* coll = nullptr;
123
124 //PixelClusterCnv_p3 chanCnv;
126 unsigned int collBegin(0);
127 // this is the id of the latest collection read in
128 // This starts from the base of the TRT identifiers
129 unsigned int idLast(0);
130 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
131 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
132
133 // Create trans collection - in NOT owner of PixelDriftCircle (SG::VIEW_ELEMENTS)
134 // IDet collection don't have the Ownership policy c'tor
135 const InDet::InDetPRD_Collection_p2& pcoll = persCont->m_collections[icoll];
136 idLast += pcoll.m_hashId;
137 // Identifier collID= Identifier(idLast);
138 IdentifierHash collIDHash=IdentifierHash((unsigned int) idLast);
139 Identifier collID = m_pixId->wafer_id(collIDHash);
140 coll = new InDet::PixelClusterCollection(collIDHash);
141 coll->setIdentifier(Identifier(collID));
142 unsigned int nchans = pcoll.m_size;
143 coll->resize(nchans);
144 const InDetDD::SiDetectorElement * de = (elements==nullptr ? nullptr : elements->getDetectorElement(collIDHash));
145 // Fill with channels:
146 // This is used to read the vector of errMat
147 // values and lenght of the value are specified in separate vectors
148 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Reading collection with " << nchans << "Channels " << endmsg;
149 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
150 const InDet::PixelCluster_p3* pchan = &(persCont->m_rawdata[ichan + collBegin]);
151 // In preparation for 64-bit ids, set the initial cluster
152 // id to the wafer id. Actual cluster id will be set in
153 // the converter from diff.
155 (chanCnv.createPixelCluster (pchan, collID, de, log));
156 // DC Bugfix: Set the hash index!
157 chan->setHashAndIndex(collIDHash, ichan);
158 (*coll)[ichan] = chan;
159 }
160 collBegin += pcoll.m_size;
161
162 // register the PRD collection in IDC with hash - faster addCollection
163 StatusCode sc = transCont->addCollection(coll, collIDHash);
164 if (sc.isFailure()) {
165 throw std::runtime_error("Failed to add collection to ID Container");
166 }
167 // if (log.level() <= MSG::DEBUG) {
168 // log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " << collID << ", added to Identifiable container." << endmsg;
169 // }
170 }
171
172 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading InDet::PixelClusterContainer" << endmsg;
173}
174
175
176
177//================================================================
178InDet::PixelClusterContainer* PixelClusterContainerCnv_p3::createTransient(const InDet::PixelClusterContainer_p3* persObj, MsgStream& log) {
179 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "PixelClusterContainerCnv_p3::createTransient called " << endmsg;
180 if(!m_isInitialized) {
181 if (this->initialize(log) != StatusCode::SUCCESS) {
182 log << MSG::FATAL << "Could not initialize PixelClusterContainerCnv_p3 " << endmsg;
183 }
184 }
185 if (not m_pixId) {
186 log << MSG::FATAL << "nullptr for m_pixId in PixelClusterContainerCnv_p3::createTransient" << endmsg;
187 return nullptr;
188 }
189 std::unique_ptr<InDet::PixelClusterContainer> trans(std::make_unique<InDet::PixelClusterContainer>(m_pixId->wafer_hash_max()));
190 persToTrans(persObj, trans.get(), log);
191 return(trans.release());
192}
193
194
196 // Do not initialize again:
197 m_isInitialized=true;
198
199 // Get Storegate, ID helpers, and so on
200 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
201 CHECK( detStore.isValid() );
202
203 // Get the Pixel helper from the detector store
204 CHECK( detStore->retrieve(m_pixId, "PixelID") );
205
208
209 return StatusCode::SUCCESS;
210}
211
212void PixelClusterContainerCnv_p3::setUseDetectorElement(const bool useDetectorElement) {
213 m_useDetectorElement = useDetectorElement;
214}
#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()