ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_ClusterContainerCnv_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
6
12
13// Athena
17
18// Gaudi
19#include "GaudiKernel/Bootstrap.h"
20#include "GaudiKernel/ISvcLocator.h"
21#include "GaudiKernel/MsgStream.h"
22#include "GaudiKernel/Service.h"
23#include "GaudiKernel/StatusCode.h"
24
25void InDet::SCT_ClusterContainerCnv_p1::transToPers(const InDet::SCT_ClusterContainer* transCont, InDet::InDetPRD_Container_p1* persCont, MsgStream &log)
26{
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 RDO
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::SCT_ClusterContainer;
45
46 SCT_ClusterCnv_p1 chanCnv;
47 TRANS::const_iterator it_Coll = transCont->begin();
48 TRANS::const_iterator it_CollEnd = transCont->end();
49 unsigned int collIndex;
50 unsigned int chanBegin = 0;
51 unsigned int chanEnd = 0;
52 persCont->m_collections.resize(transCont->numberOfCollections());
53// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
54
55 for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
56 // Add in new collection
57// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " New collection" << endmsg;
58 const InDet::SCT_ClusterCollection& collection = (**it_Coll);
59 chanBegin = chanEnd;
60 chanEnd += collection.size();
61 InDet::InDetPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
62 pcollection.m_id = collection.identify().get_compact();
63 pcollection.m_hashId = (unsigned int) collection.identifyHash();
64 pcollection.m_begin = chanBegin;
65 pcollection.m_end = chanEnd;
66 // Add in channels
67 persCont->m_PRD.resize(chanEnd);
68 for (unsigned int i = 0; i < collection.size(); ++i) {
69 const InDet::SCT_Cluster* chan = collection[i];
70 persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
71 }
72 }
73// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing SCT_ClusterContainer ***" << endmsg;
74}
75
76void InDet::SCT_ClusterContainerCnv_p1::persToTrans(const InDet::InDetPRD_Container_p1* persCont, InDet::SCT_ClusterContainer* transCont, MsgStream &log)
77{
78
79 // The transient model has a container holding collections and the
80 // collections hold channels.
81 //
82 // The persistent model flattens this so that the persistent
83 // container has two vectors:
84 // 1) all collections, and
85 // 2) all channels
86 //
87 // The persistent collections, then only maintain indexes into the
88 // container's vector of all channels.
89 //
90 // So here we loop over all collection and extract their channels
91 // from the vector.
92
93 const InDetDD::SiDetectorElementCollection* elements(nullptr);
96 elements = *sctDetEleHandle;
97 if (not sctDetEleHandle.isValid() or elements==nullptr) {
98 log << MSG::FATAL << m_SCTDetEleCollKey.fullKey() << " is not available." << endmsg;
99 return;
100 }
101 }
102
103 InDet::SCT_ClusterCollection* coll = nullptr;
104
105 SCT_ClusterCnv_p1 chanCnv;
107
108// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
109 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
110
111 // Create trans collection - is NOT owner of SCT_Cluster (SG::VIEW_ELEMENTS)
112 // IDet collection don't have the Ownership policy c'tor
113 const InDet::InDetPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
114 //Identifier collID(Identifier(pcoll.m_id));
115 IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
116 coll = new InDet::SCT_ClusterCollection(collIDHash);
117 coll->setIdentifier(Identifier(pcoll.m_id));
118 unsigned int nchans = pcoll.m_end - pcoll.m_begin;
119 coll->resize(nchans);
120 const InDetDD::SiDetectorElement * de = (m_useDetectorElement ? elements->getDetectorElement(collIDHash) : nullptr);
121 // Fill with channels
122 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
123 const TPObjRef pchan = persCont->m_PRD[ichan + pcoll.m_begin];
124 InDet::SCT_Cluster* chan = dynamic_cast<InDet::SCT_Cluster*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
125 if (chan) {
126 chan->m_detEl = de;
127 (*coll)[ichan] = chan;
128 }
129 }
130
131 // register the rdo collection in IDC with hash - faster addCollection
132 StatusCode sc = transCont->addCollection(coll, collIDHash);
133 if (sc.isFailure()) {
134 throw std::runtime_error("Failed to add collection to ID Container");
135 }
136// if (log.level() <= MSG::DEBUG) {
137// log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
138// collID.get_compact() << ", added to Identifiable container." << endmsg;
139// }
140 }
141
142// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading SCT_ClusterContainer" << endmsg;
143}
144
145
146
147//================================================================
148InDet::SCT_ClusterContainer* InDet::SCT_ClusterContainerCnv_p1::createTransient(const InDet::InDetPRD_Container_p1* persObj, MsgStream& log)
149{
150 if(!m_isInitialized) {
151 if (this->initialize(log) != StatusCode::SUCCESS) {
152 log << MSG::FATAL << "Could not initialize SCT_ClusterContainerCnv_p1 " << endmsg;
153 }
154 }
155 std::unique_ptr<InDet::SCT_ClusterContainer> trans(std::make_unique<InDet::SCT_ClusterContainer>(m_sctId->wafer_hash_max()));
156 persToTrans(persObj, trans.get(), log);
157 return(trans.release());
158}
159
161 // Do not initialize again:
162 m_isInitialized=true;
163
164 CHECK( m_storeGate.retrieve() );
165
166 // get DetectorStore service
167 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
168 CHECK( detStore.isValid() );
169
170 // Get the SCT helper from the detector store
171 CHECK( detStore->retrieve(m_sctId, "SCT_ID") );
172
174
175 return StatusCode::SUCCESS;
176}
177
178// Method for test/SCT_ClusterContainerCnv_p1_test.cxx
180 m_useDetectorElement = useDetectorElement;
181}
#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 SCT 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 persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
ServiceHandle< StoreGateSvc > m_storeGate
virtual InDet::SCT_ClusterContainer * createTransient(const InDet::InDetPRD_Container_p1 *persObj, MsgStream &log)
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
void setUseDetectorElement(const bool useDetectorElement)
This class is an object reference used in Athena persistent data model.
Definition TPObjRef.h:20
void initialize()