ATLAS Offline Software
Loading...
Searching...
No Matches
PixelClusterContainerCnv_p2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Athena
7#include "Identifier/Identifier.h"
18
19// Gaudi
20#include "GaudiKernel/ISvcLocator.h"
21#include "GaudiKernel/Bootstrap.h"
22#include "GaudiKernel/Service.h"
23#include "GaudiKernel/MsgStream.h"
24
25void PixelClusterContainerCnv_p2::transToPers(const InDet::PixelClusterContainer* transCont, InDet::PixelClusterContainer_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::PixelClusterContainer;
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 PixelClusterCnv_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 persCont->m_collections.resize(transCont->numberOfCollections());
56 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
57 for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
58 // Add in new collection
59 const InDet::PixelClusterCollection& collection = (**it_Coll);
60 chanBegin = chanEnd;
61 chanEnd += collection.size();
62 InDet::InDetPRD_Collection_p2& pcollection = persCont->m_collections[collIndex];
63 unsigned int deltaId = (collection.identifyHash()-idLast);
64 // unsigned int deltaId = (collection.identify().get_compact()-idLast)/IDJUMP;
65 // if(deltaId*IDJUMP != collection.identify().get_compact()-idLast )
66 // log << MSG::FATAL << "THere is a mistake in Identifiers of the collection" << endmsg;
67 // if(deltaId > 0xFFFF) {
68 // log << MSG::FATAL << "Fixme!!! This is too big, something needs to be done " << endmsg;
69 // }
70 // pcollection.m_idDelta = (unsigned short) deltaId;
71 // idLast = collection.identify().get_compact(); // then update the last identifier
72 pcollection.m_hashId = deltaId;
73 idLast=collection.identifyHash();
74 pcollection.m_size = collection.size();
75 // Add in channels
76 persCont->m_rawdata.resize(chanEnd);
77 log << MSG::VERBOSE << "Reading collections with " << collection.size() << "PRDs " << endmsg;
78 for (unsigned int i = 0; i < collection.size(); ++i) {
79 InDet::PixelCluster_p2* pchan = &(persCont->m_rawdata[i + chanBegin]);
80 const InDet::PixelCluster* chan = static_cast<const InDet::PixelCluster*>(collection[i]);
81 chanCnv.transToPers(chan, pchan, log);
82 }
83 }
84 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing InDet::PixelClusterContainer" << endmsg;
85}
86
87void PixelClusterContainerCnv_p2::persToTrans(const InDet::PixelClusterContainer_p2* 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);
107 elements = *pixelDetEleHandle;
108 if (not pixelDetEleHandle.isValid() or elements==nullptr) {
109 log << MSG::FATAL << m_pixelDetEleCollKey.fullKey() << " is not available." << endmsg;
110 return;
111 }
112 }
113
114 InDet::PixelClusterCollection* coll = nullptr;
115
116 PixelClusterCnv_p2 chanCnv;
117 unsigned int collBegin(0);
118 // this is the id of the latest collection read in
119 // This starts from the base of the TRT identifiers
120 unsigned int idLast(0);
121 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
122 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
123
124 // Create trans collection - in NOT owner of PixelDriftCircle (SG::VIEW_ELEMENTS)
125 // IDet collection don't have the Ownership policy c'tor
126 const InDet::InDetPRD_Collection_p2& pcoll = persCont->m_collections[icoll];
127 idLast += pcoll.m_hashId;
128 // Identifier collID= Identifier(idLast);
129 IdentifierHash collIDHash=IdentifierHash((unsigned int) idLast);
130 Identifier collID = m_pixId->wafer_id(collIDHash);
131 coll = new InDet::PixelClusterCollection(collIDHash);
132 coll->setIdentifier(Identifier(collID));
133 unsigned int nchans = pcoll.m_size;
134 coll->resize(nchans);
135 const InDetDD::SiDetectorElement * de = (elements==nullptr ? nullptr : elements->getDetectorElement(collIDHash));
136 // Fill with channels:
137 // This is used to read the vector of errMat
138 // values and lenght of the value are specified in separate vectors
139 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Reading collection with " << nchans << "Channels " << endmsg;
140 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
141 const InDet::PixelCluster_p2* pchan = &(persCont->m_rawdata[ichan + collBegin]);
143 chanCnv.persToTrans(pchan, chan, log);
144 chan->setDetectorElement(de);
145 // DC Bugfix: Set the hash index!
146 chan->setHashAndIndex(collIDHash, ichan);
147 (*coll)[ichan] = chan;
148 }
149 collBegin += pcoll.m_size;
150
151 // register the PRD collection in IDC with hash - faster addCollection
152 StatusCode sc = transCont->addCollection(coll, collIDHash);
153 if (sc.isFailure()) {
154 throw std::runtime_error("Failed to add collection to ID Container");
155 }
156 // if (log.level() <= MSG::DEBUG) {
157 // log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " << collID << ", added to Identifiable container." << endmsg;
158 // }
159 }
160
161 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading InDet::PixelClusterContainer" << endmsg;
162}
163
164
165
166//================================================================
167InDet::PixelClusterContainer* PixelClusterContainerCnv_p2::createTransient(const InDet::PixelClusterContainer_p2* persObj, MsgStream& log) {
168 if(!m_isInitialized) {
169 if (this->initialize(log) != StatusCode::SUCCESS) {
170 log << MSG::FATAL << "Could not initialize PixelClusterContainerCnv_p2 " << endmsg;
171 }
172 }
173 if (not m_pixId) {
174 log << MSG::FATAL << "nullptr for m_pixId in PixelClusterContainerCnv_p2::createTransient" << endmsg;
175 return nullptr;
176 }
177 std::unique_ptr<InDet::PixelClusterContainer> trans(std::make_unique<InDet::PixelClusterContainer>(m_pixId->wafer_hash_max()));
178 persToTrans(persObj, trans.get(), log);
179 return(trans.release());
180}
181
182
184 // Do not initialize again:
185 m_isInitialized=true;
186
187 // Get Storegate, ID helpers, and so on
188 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
189 CHECK( detStore.isValid() );
190
191 // Get the sct helper from the detector store
192 CHECK( detStore->retrieve(m_pixId, "PixelID") );
193
195
196 return StatusCode::SUCCESS;
197}
198
199void PixelClusterContainerCnv_p2::setUseDetectorElement(const bool useDetectorElement) {
200 m_useDetectorElement = useDetectorElement;
201}
#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_p2 > m_rawdata
void transToPers(const InDet::PixelCluster *, InDet::PixelCluster_p2 *, MsgStream &)
void persToTrans(const InDet::PixelCluster_p2 *, InDet::PixelCluster *, MsgStream &)
virtual void persToTrans(const InDet::PixelClusterContainer_p2 *persCont, InDet::PixelClusterContainer *transCont, MsgStream &log)
virtual InDet::PixelClusterContainer * createTransient(const InDet::PixelClusterContainer_p2 *persObj, MsgStream &log)
virtual void transToPers(const InDet::PixelClusterContainer *transCont, InDet::PixelClusterContainer_p2 *persCont, MsgStream &log)
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
void setUseDetectorElement(const bool useDetectorElement)
void initialize()