ATLAS Offline Software
Loading...
Searching...
No Matches
RpcPrepDataContainerCnv_p3.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
12
13// Gaudi
14#include "GaudiKernel/ISvcLocator.h"
15#include "GaudiKernel/Bootstrap.h"
16
17// Athena
20
21
23 // Do not initialize again:
24 m_isInitialized=true;
25
26 // get DetectorStore service
27 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
28 CHECK( detStore.isValid() );
29
30 // Get the helper from the detector store
31 CHECK( detStore->retrieve(m_RpcId) );
32
33 CHECK( m_eventCnvTool.retrieve() );
34
35 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "RpcPrepDataContainerCnv_p3 initialized." << endmsg;
36 return StatusCode::SUCCESS;
37}
39 const Trk::ITrkEventCnvTool* cnv_tool = m_eventCnvTool->getCnvTool(id);
40 if (!cnv_tool) return nullptr;
41 return dynamic_cast<const MuonGM::RpcReadoutElement*>(cnv_tool->getDetectorElement(id));
42}
44{
45
46 // The transient model has a container holding collections and the
47 // collections hold channels.
48 //
49 // The persistent model flattens this so that the persistent
50 // container has two vectors:
51 // 1) all collections, and
52 // 2) all PRDs
53 //
54 // The persistent collections, then only maintain indexes into the
55 // container's vector of all channels.
56 //
57 // So here we loop over all collection and add their channels
58 // to the container's vector, saving the indexes in the
59 // collection.
60
61 if(log.level() <= MSG::DEBUG && !m_isInitialized) {
62 if (initialize(log) != StatusCode::SUCCESS) {
63 log << MSG::FATAL << "Could not initialize RpcPrepDataContainerCnv_p3 " << endmsg;
64 }
65 }
66
67 typedef Muon::RpcPrepDataContainer TRANS;
68
69 RpcPrepDataCnv_p3 chanCnv;
70 TRANS::const_iterator it_Coll = transCont->begin();
71 TRANS::const_iterator it_CollEnd = transCont->end();
72 unsigned int pcollIndex = 0; // index to the persistent collection we're filling
73 unsigned int pcollBegin = 0; // index to start of persistent collection we're filling, in long list of persistent PRDs
74 unsigned int pcollEnd = 0; // index to end
75 int numColl = transCont->numberOfCollections();
76 persCont->m_collections.resize(numColl);
77
78 if (log.level() <= MSG::DEBUG)
79 log << MSG::DEBUG<< "Preparing " << persCont->m_collections.size() << " Collections" <<endmsg;
80 for (pcollIndex = 0; it_Coll != it_CollEnd; ++pcollIndex, ++it_Coll) {
81 // Add in new collection
82 if (log.level() <= MSG::DEBUG)
83 log << MSG::DEBUG<<"New collection"<<endmsg;
84 const Muon::RpcPrepDataCollection& collection = (**it_Coll);
85 Muon::MuonPRD_Collection_p2& pcollection = persCont->m_collections[pcollIndex]; //get ref to collection we're going to fill
86
87 pcollBegin = pcollEnd; // Next collection starts at end of previous one.
88 pcollEnd += collection.size();
89
90 pcollection.m_hashId = collection.identifyHash();
91 pcollection.m_id = collection.identify().get_identifier32().get_compact();
92 pcollection.m_size = collection.size();
93
94 // Add in channels
95 persCont->m_prds.resize(pcollEnd); // FIXME! isn't this potentially a bit slow? Do a resize and a copy for each loop? EJWM.
96 persCont->m_prdDeltaId.resize(pcollEnd);
97
98 unsigned int lastPRDIdHash = 0;
99 for (unsigned int i = 0; i < collection.size(); ++i) {
100 unsigned int pchanIndex=i+pcollBegin;
101 const RpcPrepData* chan = collection[i]; // channel being converted
102 RpcPrepData_p3* pchan = &(persCont->m_prds[pchanIndex]); // persistent version to fill
103 chanCnv.transToPers(chan, pchan, log); // convert from RpcPrepData to RpcPrepData_p3
104
105 unsigned int clusIdCompact = chan->identify().get_identifier32().get_compact();
106 unsigned int collIdCompact = collection.identify().get_identifier32().get_compact();
107
108 persCont->m_prdDeltaId[pchanIndex]=clusIdCompact - collIdCompact; //store delta identifiers, rather than full identifiers
109 // sanity checks - to be removed at some point
110 if(log.level() <= MSG::DEBUG){
111 log << MSG::DEBUG<<i<<":\t clusId: "<<clusIdCompact<<", \t collectionId="<<collIdCompact<<"\t delta="<<persCont->m_prdDeltaId[pchanIndex]<<endmsg;
112 Identifier temp(pcollection.m_id + persCont->m_prdDeltaId[pchanIndex]);
113 if (temp!=chan->identify() )
114 log << MSG::WARNING << "PRD ids differ! Transient:"<<chan->identify()<<", From persistent:"<<temp<<" diff = "<<chan->identify().get_compact()-temp.get_compact()<<endmsg;
115 else
116 log << MSG::DEBUG <<" PRD ids match."<<endmsg;
117 if (lastPRDIdHash && lastPRDIdHash != chan->collectionHash() ) log << MSG::WARNING << "Collection Identifier hashes differ!"<<endmsg;
118 lastPRDIdHash = chan->collectionHash();
119 log << MSG::DEBUG<<"Collection hash = "<<lastPRDIdHash<<endmsg;
120 if (chan->collectionHash()!= collection.identifyHash() ) log << MSG::WARNING << "Collection's idHash does not match PRD collection hash!"<<endmsg;
121 if (chan->detectorElement() !=getReadOutElement(chan->identify()))
122 log << MSG::WARNING << "Getting de from identity didn't work!"<<endmsg;
123 else
124 log << MSG::DEBUG<<"Getting de from identity did work "<<endmsg;
125 if (chan->detectorElement() !=getReadOutElement(temp)) log << MSG::WARNING << "Getting de from reconstructed identity didn't work!"<<endmsg;
126 log << MSG::DEBUG<<"Finished loop"<<endmsg;
127 }
128 }
129 }
130 if (log.level() <= MSG::DEBUG)
131 log << MSG::DEBUG<< " *** Finished Writing RpcPrepDataContainer ***" <<endmsg;
132}
133
135{
136
137 // The transient model has a container holding collections and the
138 // collections hold channels.
139 //
140 // The persistent model flattens this so that the persistent
141 // container has two vectors:
142 // 1) all collections, and
143 // 2) all channels
144 //
145 // The persistent collections, then only maintain indexes into the
146 // container's vector of all channels.
147 //
148 // So here we loop over all collection and extract their channels
149 // from the vector.
150
151 Muon::RpcPrepDataCollection* coll = nullptr;
152
153 RpcPrepDataCnv_p3 chanCnv;
154 unsigned int pchanIndex(0); // position within persCont->m_prds. Incremented inside innermost loop
155 unsigned int pCollEnd = persCont->m_collections.size();
156 if (log.level() <= MSG::DEBUG)
157 log << MSG::DEBUG<< " Reading " << pCollEnd << "Collections" <<endmsg;
158 for (unsigned int pcollIndex = 0; pcollIndex < pCollEnd; ++pcollIndex) {
159 const Muon::MuonPRD_Collection_p2& pcoll = persCont->m_collections[pcollIndex];
160 IdentifierHash collIDHash(pcoll.m_hashId);
161 coll = new Muon::RpcPrepDataCollection(collIDHash);
162 coll->setIdentifier(Identifier(pcoll.m_id));
163
164
165 // FIXME - really would like to remove Identifier from collection, but cannot as there is :
166 // a) no way (apparently - find it hard to believe) to go from collection IdHash to collection Identifer.
167
168 unsigned int pchanEnd = pchanIndex+pcoll.m_size;
169 unsigned int chanIndex = 0; // transient index
170
171 coll->reserve(pcoll.m_size);
172 // Fill with channels
173 for (; pchanIndex < pchanEnd; ++ pchanIndex, ++chanIndex) {
174 const RpcPrepData_p3* pchan = &(persCont->m_prds[pchanIndex]);
175
176 Identifier clusId(pcoll.m_id + persCont->m_prdDeltaId[pchanIndex]);
177
178 // The reason I need to do the following is that one collection can have several detector elements in, the collection hashes!=detector element hashes
179 IdentifierHash deIDHash;
180 int result = m_RpcId->get_detectorElement_hash(clusId, deIDHash);
181 if (result&&log.level() <= MSG::WARNING)
182 log << MSG::WARNING<< " Muon::RpcPrepDataContainerCnv_p3::persToTrans: problem converting Identifier to DE hash "<<endmsg;
183 const MuonGM::RpcReadoutElement* detEl = getReadOutElement(clusId);
184
185 auto chan = std::make_unique<RpcPrepData>
186 (chanCnv.createRpcPrepData (pchan,
187 clusId,
188 detEl,
189 log));
190
191
192 chan->setHashAndIndex(collIDHash, chanIndex);
193 coll->push_back(std::move(chan));
194 }
195
196 // register the rdo collection in IDC with hash - faster addCollection
197 StatusCode sc = transCont->addCollection(coll, collIDHash);
198 if (sc.isFailure()) {
199 throw std::runtime_error("Failed to add collection to Identifiable Container");
200 }
201 if (log.level() <= MSG::DEBUG) {
202 log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
203 coll->identify().get_compact() << ", added to Identifiable container." << endmsg;
204 }
205 }
206
207 if (log.level() <= MSG::DEBUG)
208 log << MSG::DEBUG<< " *** Reading RpcPrepDataContainer ***" << endmsg;
209}
210
211
212
213//================================================================
215{
216 if (log.level() <= MSG::DEBUG)
217 log << MSG::DEBUG<< " Muon::RpcPrepDataContainerCnv_p3::createTransient" << endmsg;
218 if(!m_isInitialized) {
219 if (initialize(log) != StatusCode::SUCCESS) {
220 log << MSG::FATAL << "Could not initialize RpcPrepDataContainerCnv_p3 " << endmsg;
221 return nullptr;
222 }
223 }
224 std::unique_ptr<Muon::RpcPrepDataContainer> trans(new Muon::RpcPrepDataContainer(m_RpcId->module_hash_max()));
225 persToTrans(persObj, trans.get(), log);
226 return(trans.release());
227}
228
229
#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 reserve(size_type n)
value_type push_back(value_type pElem)
size_type size() const noexcept
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...
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.
virtual Identifier identify() const override final
virtual void setIdentifier(Identifier id)
virtual IdentifierHash identifyHash() const override final
virtual Muon::RpcPrepDataContainer * createTransient(const Muon::RpcPrepDataContainer_p3 *persObj, MsgStream &log)
virtual void persToTrans(const Muon::RpcPrepDataContainer_p3 *persCont, Muon::RpcPrepDataContainer *transCont, MsgStream &log)
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
virtual void transToPers(const Muon::RpcPrepDataContainer *transCont, Muon::RpcPrepDataContainer_p3 *persCont, MsgStream &log)
const MuonGM::RpcReadoutElement * getReadOutElement(const Identifier &id) const
We don't write out (from Trk::PrepRawData) m_indexAndHash (can be recomputed), m_clusId (can be recom...
Class to represent RPC measurements.
Definition RpcPrepData.h:35
void transToPers(const Muon::RpcPrepData *transObj, Muon::RpcPrepData_p3 *persObj, MsgStream &log)
static Muon::RpcPrepData createRpcPrepData(const Muon::RpcPrepData_p3 *persObj, const Identifier &id, const MuonGM::RpcReadoutElement *detEl, MsgStream &log)
virtual const Trk::TrkDetElementBase * getDetectorElement(const Identifier &id, const IdentifierHash &idHash) const =0
Returns the detectorElement associated with this Identifier & Hash.
MuonPrepDataContainerT< RpcPrepData > RpcPrepDataContainer
MuonPRD_Container_p2< RpcPrepData_p3 > RpcPrepDataContainer_p3
MuonPrepDataCollection< RpcPrepData > RpcPrepDataCollection
void initialize()