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