ATLAS Offline Software
Loading...
Searching...
No Matches
PixelClusterContainerCnv_p1.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
16
17// Gaudi
18#include "GaudiKernel/ISvcLocator.h"
19#include "GaudiKernel/Bootstrap.h"
20#include "GaudiKernel/StatusCode.h"
21#include "GaudiKernel/Service.h"
22#include "GaudiKernel/MsgStream.h"
23
24void InDet::PixelClusterContainerCnv_p1::transToPers(const InDet::PixelClusterContainer* transCont, InDet::InDetPRD_Container_p1* persCont, MsgStream &log)
25{
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 RDO
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;
44
45 PixelClusterCnv_p1 chanCnv;
46 TRANS::const_iterator it_Coll = transCont->begin();
47 TRANS::const_iterator it_CollEnd = transCont->end();
48 unsigned int collIndex;
49 unsigned int chanBegin = 0;
50 unsigned int chanEnd = 0;
51 persCont->m_collections.resize(transCont->numberOfCollections());
52
53 for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
54 // Add in new collection
55 const InDet::PixelClusterCollection& collection = (**it_Coll);
56 chanBegin = chanEnd;
57 chanEnd += collection.size();
58 InDet::InDetPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
59 pcollection.m_id = collection.identify().get_compact();
60 pcollection.m_hashId = (unsigned int) collection.identifyHash();
61 pcollection.m_begin = chanBegin;
62 pcollection.m_end = chanEnd;
63 // Add in channels
64 persCont->m_PRD.resize(chanEnd);
65 for (unsigned int i = 0; i < collection.size(); ++i) {
66 const InDet::PixelCluster* chan = collection[i];
67 persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
68 }
69 }
70}
71
72void InDet::PixelClusterContainerCnv_p1::persToTrans(const InDet::InDetPRD_Container_p1* persCont, InDet::PixelClusterContainer* transCont, MsgStream &log)
73{
74
75 // The transient model has a container holding collections and the
76 // collections hold channels.
77 //
78 // The persistent model flattens this so that the persistent
79 // container has two vectors:
80 // 1) all collections, and
81 // 2) all channels
82 //
83 // The persistent collections then only maintain indices into the
84 // container's vector of all channels.
85 //
86 // So here we loop over all collection and extract their channels
87 // from the vector.
88
89 //see: coverity issue 22632, elements is unused. Left here to highlight this.
90 //const InDetDD::SiDetectorElementCollection* elements(nullptr);
93 const InDetDD::SiDetectorElementCollection* theseElements = *pixelDetEleHandle;
94 if (not pixelDetEleHandle.isValid() or theseElements==nullptr) {
95 log << MSG::FATAL << m_pixelDetEleCollKey.fullKey() << " is not available." << endmsg;
96 return;
97 }
98 }
99
100 InDet::PixelClusterCollection* coll = nullptr;
101
102 PixelClusterCnv_p1 chanCnv;
104
105 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
106
107 // Create trans collection - is NOT owner of PixelCluster (SG::VIEW_ELEMENTS)
108 // IDet collection don't have the Ownership policy c'tor
109 const InDet::InDetPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
110 IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
111 coll = new InDet::PixelClusterCollection(collIDHash);
112 coll->setIdentifier(Identifier(pcoll.m_id));
113 unsigned int nchans = pcoll.m_end - pcoll.m_begin;
114 coll->resize(nchans);
115 const InDetDD::SiDetectorElement * de = nullptr;//elements is nullptr, so this is also
116 // Fill with channels
117 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
118 const TPObjRef pchan = persCont->m_PRD[ichan + pcoll.m_begin];
119 InDet::PixelCluster* chan = dynamic_cast<InDet::PixelCluster*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
120 if (chan){
121 chan->m_detEl = de;
122 (*coll)[ichan] = chan;
123 } else {
124 log << MSG::WARNING << "Cast to InDet::PixelCluster* failed in PixelClusterContainerCnv_p1" << endmsg;
125 }
126 }
127
128 // register the rdo collection in IDC with hash - faster addCollection
129 StatusCode sc = transCont->addCollection(coll, collIDHash);
130 if (sc.isFailure()) {
131 throw std::runtime_error("Failed to add collection to ID Container");
132 }
133
134 }
135
136}
137
138
139
140//================================================================
141InDet::PixelClusterContainer* InDet::PixelClusterContainerCnv_p1::createTransient(const InDet::InDetPRD_Container_p1* persObj, MsgStream& log)
142{
143 if(!m_isInitialized) {
144 if (this->initialize(log) != StatusCode::SUCCESS) {
145 log << MSG::FATAL << "Could not initialize PixelClusterContainerCnv_p1 " << endmsg;
146 return nullptr;
147 }
148 }
149 if (not m_pixId) {
150 log << MSG::FATAL << "PixelID helper is null in PixelClusterContainerCnv_p1::createTransient" << endmsg;
151 return nullptr;
152 }
153 std::unique_ptr<InDet::PixelClusterContainer> trans(std::make_unique<InDet::PixelClusterContainer>(m_pixId->wafer_hash_max()));
154 persToTrans(persObj, trans.get(), log);
155 return(trans.release());
156}
157
159 // Do not initialize again:
160 m_isInitialized=true;
161
162 // get StoreGate service
163 CHECK( m_storeGate.retrieve() );
164
165 // get DetectorStore service
166 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
167 CHECK( detStore.isValid() );
168
169 // Get the pixel helper from the detector store
170 CHECK( detStore->retrieve(m_pixId, "PixelID") );
171
173
174 return StatusCode::SUCCESS;
175}
176
177// Method for test/PixelClusterContainerCnv_p1_test.cxx
179 m_useDetectorElement = useDetectorElement;
180}
#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
Common base class for all TP converters, specialized for a given transient type.
Definition TPConverter.h:37
CNV::Trans_t * createTransFromPStore(CNV **cnv, const TPObjRef &ref, MsgStream &log) const
TPObjRef toPersistent(CNV **cnv, const typename CNV::TransBase_t *transObj, MsgStream &log) const
This is a "hash" representation of an Identifier.
Class to hold the SiDetectorElement objects to be put in the detector store.
Class to hold geometrical description of a silicon detector element.
std::vector< InDet::InDetPRD_Collection_p1 > m_collections
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
virtual InDet::PixelClusterContainer * createTransient(const InDet::InDetPRD_Container_p1 *persObj, MsgStream &log)
void setUseDetectorElement(const bool useDetectorElement)
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
This class is an object reference used in Athena persistent data model.
Definition TPObjRef.h:20
void initialize()