ATLAS Offline Software
Loading...
Searching...
No Matches
RpcCoinDataContainerCnv_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/* Takashi Kubota - June 30, 2008 */
10
11
16
17// Gaudi
18#include "GaudiKernel/ISvcLocator.h"
19#include "GaudiKernel/Bootstrap.h"
20
21// Athena
25
26
28 // Do not initialize again:
29 m_isInitialized=true;
30
31 // get DetectorStore service
32 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
33 CHECK( detStore.isValid() );
34
35 // Get the helper from the detector store
36 CHECK( detStore->retrieve(m_RpcId) );
37
38 CHECK( detStore->retrieve(m_muonDetMgr) );
39
40
41 log << MSG::DEBUG << "Converter initialized." << endmsg;
42 return StatusCode::SUCCESS;
43}
44
46{
47 // The transient model has a container holding collections and the
48 // collections hold channels.
49 //
50 // The persistent model flattens this so that the persistent
51 // container has two vectors:
52 // 1) all collections, and
53 // 2) all PRD
54 //
55 // The persistent collections, then only maintain indexes into the
56 // container's vector of all channels.
57 //
58 // So here we loop over all collection and add their channels
59 // to the container's vector, saving the indexes in the
60 // collection.
61
63
64 RpcCoinDataCnv_p1 chanCnv;
65 TRANS::const_iterator it_Coll = transCont->begin();
66 TRANS::const_iterator it_CollEnd = transCont->end();
67 unsigned int pcollIndex; // index to the persistent collection we're filling
68 unsigned int pcollBegin = 0; // index to start of persistent collection we're filling, in long list of persistent PRDs
69 unsigned int pcollEnd = 0; // index to end
70 int numColl = transCont->numberOfCollections();
71 persCont->m_collections.resize(numColl);
72 log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
73 for (pcollIndex = 0; it_Coll != it_CollEnd; ++pcollIndex, ++it_Coll) {
74 // Add in new collection
75 const Muon::MuonCoinDataCollection<RpcCoinData>& collection = (**it_Coll);
76 Muon::MuonPRD_Collection_p2& pcollection = persCont->m_collections[pcollIndex];
77
78 pcollBegin = pcollEnd; // Next collection starts at end of previous one.
79 pcollEnd += collection.size();
80
81 pcollection.m_hashId = collection.identifyHash();
82 pcollection.m_id = collection.identify().get_identifier32().get_compact();
83 pcollection.m_size = collection.size();
84
85
86 // Add in channels
87 persCont->m_prds.resize(pcollEnd);
88 persCont->m_prdDeltaId.resize(pcollEnd);
89 log << MSG::VERBOSE << "Reading collections with " << collection.size() << "PRDs " << endmsg;
90 for (unsigned int i = 0; i < collection.size(); ++i) {
91 unsigned int pchanIndex=i+pcollBegin;
92 const Muon::RpcCoinData* chan = collection[i];
93 Muon::RpcCoinData_p1* pchan = &(persCont->m_prds[pchanIndex]);
94 chanCnv.transToPers(chan, pchan, log);
95 persCont->m_prdDeltaId[pchanIndex]=chan->identify().get_identifier32().get_compact() - collection.identify().get_identifier32().get_compact(); //store delta identifiers, rather than full identifiers
96 }
97 }
98 log << MSG::DEBUG << " *** Writing Muon::RpcCoinDataContainer" << endmsg;
99}
100
102{
103 // The transient model has a container holding collections and the
104 // collections hold channels.
105 //
106 // The persistent model flattens this so that the persistent
107 // container has two vectors:
108 // 1) all collections, and
109 // 2) all channels
110 //
111 // The persistent collections, then only maintain indexes into the
112 // container's vector of all channels.
113 //
114 // So here we loop over all collection and extract their channels
115 // from the vector.
116
117
119
120 RpcCoinDataCnv_p1 chanCnv;
121 unsigned int pchanIndex(0); // position within persCont->m_prds. Incremented inside innermost loop
122 unsigned int pCollEnd = persCont->m_collections.size();
123 log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
124 for (unsigned int pcollIndex = 0; pcollIndex < pCollEnd; ++pcollIndex) {
125 const Muon::MuonPRD_Collection_p2& pcoll = persCont->m_collections[pcollIndex];
126 // Identifier collID= Identifier(idLast);
127 IdentifierHash collIDHash=IdentifierHash(pcoll.m_hashId);
128 coll = new Muon::RpcCoinDataCollection(collIDHash);
129 coll->setIdentifier(Identifier(pcoll.m_id));
130
131 unsigned int pchanEnd = pchanIndex+pcoll.m_size;
132 unsigned int chanIndex = 0; // transient index
133
134 coll->resize(pcoll.m_size);
135 // Fill with channels:
136 for (; pchanIndex < pchanEnd; ++ pchanIndex, ++chanIndex) {
137 const Muon::RpcCoinData_p1* pchan = &(persCont->m_prds[pchanIndex]);
138 Identifier clusId(pcoll.m_id + persCont->m_prdDeltaId[pchanIndex]);
139
140 // The reason I need to do the following is that one collection can have several detector elements in, the collection hashes!=detector element hashes
141 IdentifierHash deIDHash;
142 int result = m_RpcId->get_detectorElement_hash(clusId, deIDHash);
143 if (result) log << MSG::WARNING << " Muon::RpcCoinDataContainerCnv_p1::persToTrans: problem converting Identifier to DE hash "<<endmsg;
144 const MuonGM::RpcReadoutElement* detEl =
145 m_muonDetMgr->getRpcReadoutElement(deIDHash);
146
147 auto chan = std::make_unique<Muon::RpcCoinData>
148 (chanCnv.createRpcCoinData (pchan,
149 clusId,
150 detEl,
151 log));
152
153 chan->setHashAndIndex(collIDHash, chanIndex);
154 (*coll)[chanIndex] = std::move(chan);
155 }
156
157 // register the PRD collection in IDC with hash - faster addCollection
158 StatusCode sc = transCont->addCollection(coll, collIDHash);
159 if (sc.isFailure()) {
160 throw std::runtime_error("Failed to add collection to ID Container");
161 }
162 if (log.level() <= MSG::DEBUG) {
163 log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / "
164 << coll->identify().get_compact() << ", added to Identifiable container." << endmsg;
165 }
166 }
167
168 log << MSG::DEBUG << " *** Reading Muon::MuonCoinDataCollection<RpcCoinData>" << endmsg;
169
170}
171
172//================================================================
174{
175 if(!m_isInitialized) {
176 if (this->initialize(log) != StatusCode::SUCCESS) {
177 log << MSG::FATAL << "Could not initialize RpcCoinDataContainerCnv_p1 " << endmsg;
178 return nullptr;
179 }
180 }
181 std::unique_ptr<Muon::RpcCoinDataContainer> trans(new Muon::RpcCoinDataContainer(m_RpcId->module_hash_max()));
182 persToTrans(persObj, trans.get(), log);
183 return(trans.release());
184}
185
186
#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)
Resizes the collection to the specified number of elements.
size_type size() const noexcept
Returns the number of elements in the collection.
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...
IdentifierHash identifyHash() const
Class to hold the persistent representation of MuonPRD_Collection.
unsigned short m_size
Collection size into master collection Note I use a short.
unsigned int m_hashId
Hash Identifier of this collection.
unsigned int m_id
Identifier of this collection.
std::vector< MuonPRD_Collection_p2 > m_collections
std::vector< unsigned short > m_prdDeltaId
The delta identifiers of the PRD i.e.
Muon::MuonPRD_Container_p2< RpcCoinData_p1 > PERS
const MuonGM::MuonDetectorManager * m_muonDetMgr
virtual TRANS * createTransient(const PERS *persObj, MsgStream &log)
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Persistent representation of the transient Muon::RpcCoinData class.
void transToPers(const Muon::RpcCoinData *transObj, Muon::RpcCoinData_p1 *persObj, MsgStream &log)
static Muon::RpcCoinData createRpcCoinData(const Muon::RpcCoinData_p1 *persObj, const Identifier &id, const MuonGM::RpcReadoutElement *detEl, MsgStream &log)
MuonCoinDataCollection< RpcCoinData > RpcCoinDataCollection
MuonCoinDataContainer< RpcCoinDataCollection > RpcCoinDataContainer
void initialize()