ATLAS Offline Software
Loading...
Searching...
No Matches
RpcPrepDataContainerCnv_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
13// Gaudi
14#include "GaudiKernel/ISvcLocator.h"
15#include "GaudiKernel/Bootstrap.h"
16#include "GaudiKernel/StatusCode.h"
17#include "GaudiKernel/Service.h"
18#include "GaudiKernel/MsgStream.h"
19
20// Athena
23
24
25
27
29 // Do not initialize again:
30 m_isInitialized=true;
31
32 // get DetectorStore service
33 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
34 CHECK( detStore.isValid() );
35
36 // Get the helper from the detector store
37 CHECK( detStore->retrieve(m_RpcId) );
38
39 CHECK( m_eventCnvTool.retrieve() );
40
41 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized." << endmsg;
42 return StatusCode::SUCCESS;
43}
45 const Trk::ITrkEventCnvTool* cnv_tool = m_eventCnvTool->getCnvTool(id);
46 if (!cnv_tool) return nullptr;
47 return dynamic_cast<const MuonGM::RpcReadoutElement*>(cnv_tool->getDetectorElement(id));
48}
50{
51
52 // The transient model has a container holding collections and the
53 // collections hold channels.
54 //
55 // The persistent model flattens this so that the persistent
56 // container has two vectors:
57 // 1) all collections, and
58 // 2) all RDO
59 //
60 // The persistent collections, then only maintain indexes into the
61 // container's vector of all channels.
62 //
63 // So here we loop over all collection and add their channels
64 // to the container's vector, saving the indexes in the
65 // collection.
66
69
70 RpcPrepDataCnv_p2 chanCnv;
71 TRANS::const_iterator it_Coll = transCont->begin();
72 TRANS::const_iterator it_CollEnd = transCont->end();
73 unsigned int collIndex = 0;
74 unsigned int chanBegin = 0;
75 unsigned int chanEnd = 0;
76 int numColl = transCont->numberOfCollections();
77
78 persCont->m_collections.resize(numColl); log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
79
80 for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
81 // Add in new collection
82 log << MSG::DEBUG << " New collection" << endmsg;
83 const Muon::RpcPrepDataCollection& collection = (**it_Coll);
84 chanBegin = chanEnd;
85 chanEnd += collection.size();
86 Muon::MuonPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
87 pcollection.m_id = collection.identify().get_identifier32().get_compact();
88 pcollection.m_hashId = (unsigned int) collection.identifyHash();
89 pcollection.m_begin = chanBegin;
90 pcollection.m_end = chanEnd;
91 // Add in channels
92 persCont->m_PRD.resize(chanEnd);
93 for (unsigned int i = 0; i < collection.size(); ++i) {
94 const Muon::RpcPrepData* chan = collection[i];
95 persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
96 }
97 }
98 log << MSG::DEBUG << " *** Writing RpcPrepDataContainer ***" << endmsg;
99}
100
102{
103
104 // The transient model has a container holding collections and the
105 // collections hold channels.
106 //
107 // The persistent model flattens this so that the persistent
108 // container has two vectors:
109 // 1) all collections, and
110 // 2) all channels
111 //
112 // The persistent collections, then only maintain indexes into the
113 // container's vector of all channels.
114 //
115 // So here we loop over all collection and extract their channels
116 // from the vector.
117
118
119 Muon::RpcPrepDataCollection* coll = nullptr;
120
121 RpcPrepDataCnv_p2 chanCnv;
123
124 log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
125 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
126
127 // Create trans collection - is NOT owner of RpcPrepData (SG::VIEW_ELEMENTS)
128 // IDet collection don't have the Ownership policy c'tor
129 const Muon::MuonPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
130 Identifier collID(Identifier(pcoll.m_id));
131 IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
132 coll = new Muon::RpcPrepDataCollection(collIDHash);
133 coll->setIdentifier(Identifier(pcoll.m_id));
134 unsigned int nchans = pcoll.m_end - pcoll.m_begin;
135 coll->resize(nchans);
136 // Fill with channels
137 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
138 const TPObjRef pchan = persCont->m_PRD[ichan + pcoll.m_begin];
139 Muon::RpcPrepData* chan = dynamic_cast<Muon::RpcPrepData*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
140 if (!chan) {
141 log << MSG::ERROR << "AthenaPoolTPCnvIDCont::persToTrans: Cannot get RpcPrepData!" << endmsg;
142 continue;
143 }
144 const MuonGM::RpcReadoutElement * de = getReadOutElement(chan->identify());
145 chan->m_detEl = de;
146 (*coll)[ichan] = chan;
147 }
148
149 // register the rdo collection in IDC with hash - faster addCollection
150 StatusCode sc = transCont->addCollection(coll, collIDHash);
151 if (sc.isFailure()) {
152 throw std::runtime_error("Failed to add collection to ID Container");
153 }
154 if (log.level() <= MSG::DEBUG) {
155 log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
156 collID.get_compact() << ", added to Identifiable container." << endmsg;
157 }
158 }
159
160 log << MSG::DEBUG << " *** Reading RpcPrepDataContainer" << endmsg;
161}
162
163
164
165//================================================================
167{
168 if(!m_isInitialized) {
169 if (this->initialize(log) != StatusCode::SUCCESS) {
170 log << MSG::FATAL << "Could not initialize RpcPrepDataContainerCnv_p2 " << endmsg;
171 return nullptr;
172 }
173 }
174 std::unique_ptr<Muon::RpcPrepDataContainer> trans(new Muon::RpcPrepDataContainer(m_RpcId->module_hash_max()));
175 persToTrans(persObj, trans.get(), log);
176 return(trans.release());
177}
178
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
void resize(size_type sz)
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
const_iterator end() const
return const_iterator for end of container
virtual size_t numberOfCollections() const override final
return number of collections
virtual StatusCode addCollection(const T *coll, IdentifierHash hashId) override final
insert collection into container with id hash if IDC should not take ownership of collection,...
const_iterator begin() const
return const_iterator for first entry
value_type get_compact() const
Get the compact id.
This is a "hash" representation of an Identifier.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
An RpcReadoutElement corresponds to a single RPC module; therefore typicaly a barrel muon station con...
unsigned int m_end
End index into master collection.
unsigned int m_hashId
Hash Identifier of this collection (write this one as well, so we don't rely on the IdHelper for it)
unsigned int m_begin
Begin index into master collection.
unsigned int m_id
Identifier of this collection.
std::vector< Muon::MuonPRD_Collection_p1 > m_collections
std::vector< TPObjRef > m_PRD
virtual Identifier identify() const override final
virtual void setIdentifier(Identifier id)
virtual IdentifierHash identifyHash() const override final
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
const MuonGM::RpcReadoutElement * getReadOutElement(const Identifier &id) const
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
virtual Muon::RpcPrepDataContainer * createTransient(const Muon::MuonPRD_Container_p1 *persObj, MsgStream &log)
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
Class to represent RPC measurements.
Definition RpcPrepData.h:35
This class is an object reference used in Athena persistent data model.
Definition TPObjRef.h:20
virtual const Trk::TrkDetElementBase * getDetectorElement(const Identifier &id, const IdentifierHash &idHash) const =0
Returns the detectorElement associated with this Identifier & Hash.
MuonPrepDataContainerT< RpcPrepData > RpcPrepDataContainer
MuonPrepDataCollection< RpcPrepData > RpcPrepDataCollection
void initialize()