ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_DriftCircleContainerCnv_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
14
15// Gaudi
16#include "GaudiKernel/ISvcLocator.h"
17#include "GaudiKernel/Bootstrap.h"
18#include "GaudiKernel/StatusCode.h"
19#include "GaudiKernel/Service.h"
20#include "GaudiKernel/MsgStream.h"
21
22// Athena
24
25
26
28
29void InDet::TRT_DriftCircleContainerCnv_p1::transToPers(const InDet::TRT_DriftCircleContainer* transCont, InDet::InDetPRD_Container_p1* persCont, MsgStream &log)
30{
31
32 // The transient model has a container holding collections and the
33 // collections hold channels.
34 //
35 // The persistent model flattens this so that the persistent
36 // container has two vectors:
37 // 1) all collections, and
38 // 2) all RDO
39 //
40 // The persistent collections, then only maintain indexes into the
41 // container's vector of all channels.
42 //
43 // So here we loop over all collection and add their channels
44 // to the container's vector, saving the indexes in the
45 // collection.
46
47 using TRANS = InDet::TRT_DriftCircleContainer;
49
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
59 for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
60 // Add in new collection
61 const InDet::TRT_DriftCircleCollection& collection = (**it_Coll);
62 chanBegin = chanEnd;
63 chanEnd += collection.size();
64 InDet::InDetPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
65 pcollection.m_id = collection.identify().get_compact();
66 pcollection.m_hashId = (unsigned int) collection.identifyHash();
67 pcollection.m_begin = chanBegin;
68 pcollection.m_end = chanEnd;
69 // Add in channels
70 persCont->m_PRD.resize(chanEnd);
71 for (unsigned int i = 0; i < collection.size(); ++i) {
72 const InDet::TRT_DriftCircle* chan = collection[i];
73 persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
74 }
75 }
76// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing TRT_DriftCircleContainer ***" << endmsg;
77}
78
79void InDet::TRT_DriftCircleContainerCnv_p1::persToTrans(const InDet::InDetPRD_Container_p1* persCont, InDet::TRT_DriftCircleContainer* transCont, MsgStream &log)
80{
81
82 // The transient model has a container holding collections and the
83 // collections hold channels.
84 //
85 // The persistent model flattens this so that the persistent
86 // container has two vectors:
87 // 1) all collections, and
88 // 2) all channels
89 //
90 // The persistent collections, then only maintain indexes into the
91 // container's vector of all channels.
92 //
93 // So here we loop over all collection and extract their channels
94 // from the vector.
95
96
97 InDet::TRT_DriftCircleCollection* coll = nullptr;
98
101
102// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
103 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
104
105 // Create trans collection - is NOT owner of TRT_DriftCircle (SG::VIEW_ELEMENTS)
106 // IDet collection don't have the Ownership policy c'tor
107 const InDet::InDetPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
108 //Identifier collID(Identifier(pcoll.m_id));
109 IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
110 coll = new InDet::TRT_DriftCircleCollection(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::TRT_BaseElement * de = m_trtMgr->getElement(collIDHash);
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::TRT_DriftCircle* chan = dynamic_cast<InDet::TRT_DriftCircle*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
119 if (chan) {
120 chan->m_detEl = de;
121 (*coll)[ichan] = chan;
122 }
123 }
124
125 // register the rdo collection in IDC with hash - faster addCollection
126 StatusCode sc = transCont->addCollection(coll, collIDHash);
127 if (sc.isFailure()) {
128 throw std::runtime_error("Failed to add collection to ID Container");
129 }
130// if (log.level() <= MSG::DEBUG) {
131// log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
132// collID.get_compact() << ", added to Identifiable container." << endmsg;
133// }
134 }
135
136// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading TRT_DriftCircleContainer" << endmsg;
137}
138
139
140
141//================================================================
142InDet::TRT_DriftCircleContainer* InDet::TRT_DriftCircleContainerCnv_p1::createTransient(const InDet::InDetPRD_Container_p1* persObj, MsgStream& log) {
143 if(!m_isInitialized) {
144 if (this->initialize(log) != StatusCode::SUCCESS) {
145 log << MSG::FATAL << "Could not initialize TRT_DriftCircleContainerCnv_p1 " << endmsg;
146 }
147 }
148 std::unique_ptr<InDet::TRT_DriftCircleContainer> trans(std::make_unique<InDet::TRT_DriftCircleContainer>(m_trtId->module_hash_max()));
149 persToTrans(persObj, trans.get(), log);
150 return(trans.release());
151}
152
154 // Do not initialize again:
155 m_isInitialized=true;
156
157 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
158 CHECK( detStore.isValid() );
159 CHECK( detStore->retrieve(m_trtId, "TRT_ID") );
160 CHECK( detStore->retrieve(m_trtMgr) );
161 return StatusCode::SUCCESS;
162}
#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 TRT 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.
Virtual base class of TRT readout elements.
std::vector< InDet::InDetPRD_Collection_p1 > m_collections
const InDetDD::TRT_DetectorManager * m_trtMgr
virtual InDet::TRT_DriftCircleContainer * createTransient(const InDet::InDetPRD_Container_p1 *persObj, MsgStream &log)
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
This class is an object reference used in Athena persistent data model.
Definition TPObjRef.h:20
void initialize()