ATLAS Offline Software
Loading...
Searching...
No Matches
PixelClusterContainerCnv_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
5// Athena
7#include "Identifier/Identifier.h"
18
19// Gaudi
20#include "GaudiKernel/ISvcLocator.h"
21#include "GaudiKernel/Bootstrap.h"
22#include "GaudiKernel/StatusCode.h"
23#include "GaudiKernel/Service.h"
24#include "GaudiKernel/MsgStream.h"
25
26void PixelClusterContainerCnv_p2::transToPers(const InDet::PixelClusterContainer* transCont, InDet::PixelClusterContainer_p2* persCont, MsgStream &log) {
27
28 // The transient model has a container holding collections and the
29 // collections hold channels.
30 //
31 // The persistent model flattens this so that the persistent
32 // container has two vectors:
33 // 1) all collections, and
34 // 2) all PRD
35 //
36 // The persistent collections, then only maintain indexes into the
37 // container's vector of all channels.
38 //
39 // So here we loop over all collection and add their channels
40 // to the container's vector, saving the indexes in the
41 // collection.
42
43 using TRANS = InDet::PixelClusterContainer;
44
45 // this is the id of the latest collection read in
46 // This starts from the base of the TRT identifiers
47 unsigned int idLast(0);
48
49 //
50 PixelClusterCnv_p2 chanCnv;
51 TRANS::const_iterator it_Coll = transCont->begin();
52 TRANS::const_iterator it_CollEnd = transCont->end();
53 unsigned int collIndex;
54 unsigned int chanBegin = 0;
55 unsigned int chanEnd = 0;
56 persCont->m_collections.resize(transCont->numberOfCollections());
57 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
58 for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
59 // Add in new collection
60 const InDet::PixelClusterCollection& collection = (**it_Coll);
61 chanBegin = chanEnd;
62 chanEnd += collection.size();
63 InDet::InDetPRD_Collection_p2& pcollection = persCont->m_collections[collIndex];
64 unsigned int deltaId = (collection.identifyHash()-idLast);
65 // unsigned int deltaId = (collection.identify().get_compact()-idLast)/IDJUMP;
66 // if(deltaId*IDJUMP != collection.identify().get_compact()-idLast )
67 // log << MSG::FATAL << "THere is a mistake in Identifiers of the collection" << endmsg;
68 // if(deltaId > 0xFFFF) {
69 // log << MSG::FATAL << "Fixme!!! This is too big, something needs to be done " << endmsg;
70 // }
71 // pcollection.m_idDelta = (unsigned short) deltaId;
72 // idLast = collection.identify().get_compact(); // then update the last identifier
73 pcollection.m_hashId = deltaId;
74 idLast=collection.identifyHash();
75 pcollection.m_size = collection.size();
76 // Add in channels
77 persCont->m_rawdata.resize(chanEnd);
78 log << MSG::VERBOSE << "Reading collections with " << collection.size() << "PRDs " << endmsg;
79 for (unsigned int i = 0; i < collection.size(); ++i) {
80 InDet::PixelCluster_p2* pchan = &(persCont->m_rawdata[i + chanBegin]);
81 const InDet::PixelCluster* chan = dynamic_cast<const InDet::PixelCluster*>(collection[i]);
82 chanCnv.transToPers(chan, pchan, log);
83 }
84 }
85 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing InDet::PixelClusterContainer" << endmsg;
86}
87
88void PixelClusterContainerCnv_p2::persToTrans(const InDet::PixelClusterContainer_p2* persCont, InDet::PixelClusterContainer* transCont, MsgStream &log)
89{
90
91 // The transient model has a container holding collections and the
92 // collections hold channels.
93 //
94 // The persistent model flattens this so that the persistent
95 // container has two vectors:
96 // 1) all collections, and
97 // 2) all channels
98 //
99 // The persistent collections, then only maintain indexes into the
100 // container's vector of all channels.
101 //
102 // So here we loop over all collection and extract their channels
103 // from the vector.
104
105 const InDetDD::SiDetectorElementCollection* elements(nullptr);
108 elements = *pixelDetEleHandle;
109 if (not pixelDetEleHandle.isValid() or elements==nullptr) {
110 log << MSG::FATAL << m_pixelDetEleCollKey.fullKey() << " is not available." << endmsg;
111 return;
112 }
113 }
114
115 InDet::PixelClusterCollection* coll = nullptr;
116
117 PixelClusterCnv_p2 chanCnv;
118 unsigned int collBegin(0);
119 // this is the id of the latest collection read in
120 // This starts from the base of the TRT identifiers
121 unsigned int idLast(0);
122 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
123 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
124
125 // Create trans collection - in NOT owner of PixelDriftCircle (SG::VIEW_ELEMENTS)
126 // IDet collection don't have the Ownership policy c'tor
127 const InDet::InDetPRD_Collection_p2& pcoll = persCont->m_collections[icoll];
128 idLast += pcoll.m_hashId;
129 // Identifier collID= Identifier(idLast);
130 IdentifierHash collIDHash=IdentifierHash((unsigned int) idLast);
131 Identifier collID = m_pixId->wafer_id(collIDHash);
132 coll = new InDet::PixelClusterCollection(collIDHash);
133 coll->setIdentifier(Identifier(collID));
134 unsigned int nchans = pcoll.m_size;
135 coll->resize(nchans);
136 const InDetDD::SiDetectorElement * de = (elements==nullptr ? nullptr : elements->getDetectorElement(collIDHash));
137 // Fill with channels:
138 // This is used to read the vector of errMat
139 // values and lenght of the value are specified in separate vectors
140 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Reading collection with " << nchans << "Channels " << endmsg;
141 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
142 const InDet::PixelCluster_p2* pchan = &(persCont->m_rawdata[ichan + collBegin]);
144 chanCnv.persToTrans(pchan, chan, log);
145 chan->setDetectorElement(de);
146 // DC Bugfix: Set the hash index!
147 chan->setHashAndIndex(collIDHash, ichan);
148 (*coll)[ichan] = chan;
149 }
150 collBegin += pcoll.m_size;
151
152 // register the PRD collection in IDC with hash - faster addCollection
153 StatusCode sc = transCont->addCollection(coll, collIDHash);
154 if (sc.isFailure()) {
155 throw std::runtime_error("Failed to add collection to ID Container");
156 }
157 // if (log.level() <= MSG::DEBUG) {
158 // log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " << collID << ", added to Identifiable container." << endmsg;
159 // }
160 }
161
162 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading InDet::PixelClusterContainer" << endmsg;
163}
164
165
166
167//================================================================
168InDet::PixelClusterContainer* PixelClusterContainerCnv_p2::createTransient(const InDet::PixelClusterContainer_p2* persObj, MsgStream& log) {
169 if(!m_isInitialized) {
170 if (this->initialize(log) != StatusCode::SUCCESS) {
171 log << MSG::FATAL << "Could not initialize PixelClusterContainerCnv_p2 " << endmsg;
172 }
173 }
174 if (not m_pixId) {
175 log << MSG::FATAL << "nullptr for m_pixId in PixelClusterContainerCnv_p2::createTransient" << endmsg;
176 return nullptr;
177 }
178 std::unique_ptr<InDet::PixelClusterContainer> trans(std::make_unique<InDet::PixelClusterContainer>(m_pixId->wafer_hash_max()));
179 persToTrans(persObj, trans.get(), log);
180 return(trans.release());
181}
182
183
185 // Do not initialize again:
186 m_isInitialized=true;
187
188 // Get Storegate, ID helpers, and so on
189 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
190 CHECK( detStore.isValid() );
191
192 // Get the sct helper from the detector store
193 CHECK( detStore->retrieve(m_pixId, "PixelID") );
194
196
197 return StatusCode::SUCCESS;
198}
199
200void PixelClusterContainerCnv_p2::setUseDetectorElement(const bool useDetectorElement) {
201 m_useDetectorElement = useDetectorElement;
202}
#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()