ATLAS Offline Software
Loading...
Searching...
No Matches
PixelClusterContainerCnv_p1.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
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 indexes 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 const InDetDD::SiDetectorElementCollection* elements(nullptr);
92 const InDetDD::SiDetectorElementCollection* elements = *pixelDetEleHandle;
93 if (not pixelDetEleHandle.isValid() or elements==nullptr) {
94 log << MSG::FATAL << m_pixelDetEleCollKey.fullKey() << " is not available." << endmsg;
95 return;
96 }
97 }
98
99 InDet::PixelClusterCollection* coll = nullptr;
100
101 PixelClusterCnv_p1 chanCnv;
103
104 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
105
106 // Create trans collection - is NOT owner of PixelCluster (SG::VIEW_ELEMENTS)
107 // IDet collection don't have the Ownership policy c'tor
108 const InDet::InDetPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
109 IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
110 coll = new InDet::PixelClusterCollection(collIDHash);
111 coll->setIdentifier(Identifier(pcoll.m_id));
112 unsigned int nchans = pcoll.m_end - pcoll.m_begin;
113 coll->resize(nchans);
114 const InDetDD::SiDetectorElement * de = (elements ? elements->getDetectorElement(collIDHash) : nullptr);
115 // Fill with channels
116 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
117 const TPObjRef pchan = persCont->m_PRD[ichan + pcoll.m_begin];
118 InDet::PixelCluster* chan = dynamic_cast<InDet::PixelCluster*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
119 if (chan){
120 chan->m_detEl = de;
121 (*coll)[ichan] = chan;
122 } else {
123 log << MSG::WARNING << "Cast to InDet::PixelCluster* failed in PixelClusterContainerCnv_p1" << endmsg;
124 }
125 }
126
127 // register the rdo collection in IDC with hash - faster addCollection
128 StatusCode sc = transCont->addCollection(coll, collIDHash);
129 if (sc.isFailure()) {
130 throw std::runtime_error("Failed to add collection to ID Container");
131 }
132
133 }
134
135}
136
137
138
139//================================================================
140InDet::PixelClusterContainer* InDet::PixelClusterContainerCnv_p1::createTransient(const InDet::InDetPRD_Container_p1* persObj, MsgStream& log)
141{
142 if(!m_isInitialized) {
143 if (this->initialize(log) != StatusCode::SUCCESS) {
144 log << MSG::FATAL << "Could not initialize PixelClusterContainerCnv_p1 " << endmsg;
145 return nullptr;
146 }
147 }
148 if (not m_pixId) {
149 log << MSG::FATAL << "PixelID helper is null in PixelClusterContainerCnv_p1::createTransient" << endmsg;
150 return nullptr;
151 }
152 std::unique_ptr<InDet::PixelClusterContainer> trans(std::make_unique<InDet::PixelClusterContainer>(m_pixId->wafer_hash_max()));
153 persToTrans(persObj, trans.get(), log);
154 return(trans.release());
155}
156
158 // Do not initialize again:
159 m_isInitialized=true;
160
161 // get StoreGate service
162 CHECK( m_storeGate.retrieve() );
163
164 // get DetectorStore service
165 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
166 CHECK( detStore.isValid() );
167
168 // Get the pixel helper from the detector store
169 CHECK( detStore->retrieve(m_pixId, "PixelID") );
170
172
173 return StatusCode::SUCCESS;
174}
175
176// Method for test/PixelClusterContainerCnv_p1_test.cxx
178 m_useDetectorElement = useDetectorElement;
179}
#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.
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
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()