ATLAS Offline Software
Loading...
Searching...
No Matches
MdtPrepDataContainerCnv_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
14// Gaudi
15#include "GaudiKernel/ISvcLocator.h"
16#include "GaudiKernel/Bootstrap.h"
17
18// Athena
21
22
24 // Do not initialize again:
25 m_isInitialized=true;
26
27 // get DetectorStore service
28 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
29 CHECK( detStore.isValid() );
30
31 // Get the helper from the detector store
32 CHECK( detStore->retrieve(m_MdtId) );
33
34 CHECK( m_eventCnvTool.retrieve() );
35
36 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized." << endmsg;
37 return StatusCode::SUCCESS;
38}
39
41 const Trk::ITrkEventCnvTool* cnv_tool = m_eventCnvTool->getCnvTool(id);
42 if (!cnv_tool) return nullptr;
43 return dynamic_cast<const MuonGM::MdtReadoutElement*>(cnv_tool->getDetectorElement(id));
44}
45
47{
48
49 // The transient model has a container holding collections and the
50 // collections hold channels.
51 //
52 // The persistent model flattens this so that the persistent
53 // container has two vectors:
54 // 1) all collections, and
55 // 2) all PRDs
56 //
57 // The persistent collections, then only maintain indexes into the
58 // container's vector of all channels.
59 //
60 // So here we loop over all collection and add their channels
61 // to the container's vector, saving the indexes in the
62 // collection.
63
64 typedef Muon::MdtPrepDataContainer TRANS;
65
66 MdtPrepDataCnv_p2 chanCnv;
67 TRANS::const_iterator it_Coll = transCont->begin();
68 TRANS::const_iterator it_CollEnd = transCont->end();
69 unsigned int pcollIndex =0; // index to the persistent collection we're filling
70 unsigned int pcollBegin = 0; // index to start of persistent collection we're filling, in long list of persistent PRDs
71 unsigned int pcollEnd = 0; // index to end
72 int numColl = transCont->numberOfCollections();
73 persCont->m_collections.resize(numColl);
74
75 if (log.level() <= MSG::DEBUG)
76 log << MSG::DEBUG<< " Preparing " << persCont->m_collections.size() << "Collections" <<endmsg;
77 for (pcollIndex = 0; it_Coll != it_CollEnd; ++pcollIndex, ++it_Coll) {
78 // Add in new collection
79 if (log.level() <= MSG::DEBUG)
80 log << MSG::DEBUG<<"New collection"<<endmsg;
81 const Muon::MdtPrepDataCollection& collection = (**it_Coll);
82 Muon::MuonPRD_Collection_p2& pcollection = persCont->m_collections[pcollIndex]; //get ref to collection we're going to fill
83
84 pcollBegin = pcollEnd; // Next collection starts at end of previous one.
85 pcollEnd += collection.size();
86
87 pcollection.m_hashId = collection.identifyHash();
88 pcollection.m_id = collection.identify().get_identifier32().get_compact();
89 pcollection.m_size = collection.size();
90
91 // Add in channels
92 persCont->m_prds.resize(pcollEnd); // FIXME! isn't this potentially a bit slow? Do a resize and a copy for each loop? EJWM.
93 persCont->m_prdDeltaId.resize(pcollEnd);
94
95 for (unsigned int i = 0; i < collection.size(); ++i) {
96 unsigned int pchanIndex=i+pcollBegin;
97 const MdtPrepData* chan = collection[i]; // channel being converted
98 MdtPrepData_p2* pchan = &(persCont->m_prds[pchanIndex]); // persistent version to fill
99 chanCnv.transToPers(chan, pchan, log); // convert from MdtPrepData to MdtPrepData_p2
100
101 persCont->m_prdDeltaId[pchanIndex]=chan->identify().get_identifier32().get_compact() - collection.identify().get_identifier32().get_compact(); //store delta identifiers, rather than full identifiers
102 }
103 }
104 if (log.level() <= MSG::DEBUG)
105 log << MSG::DEBUG<< " *** Writing MdtPrepDataContainer ***" <<endmsg;
106}
107
109{
110
111 // The transient model has a container holding collections and the
112 // collections hold channels.
113 //
114 // The persistent model flattens this so that the persistent
115 // container has two vectors:
116 // 1) all collections, and
117 // 2) all channels
118 //
119 // The persistent collections, then only maintain indexes into the
120 // container's vector of all channels.
121 //
122 // So here we loop over all collection and extract their channels
123 // from the vector.
124
125 Muon::MdtPrepDataCollection* coll = nullptr;
126
127 MdtPrepDataCnv_p2 chanCnv;
128 unsigned int pchanIndex(0); // position within persCont->m_prds. Incremented inside innermost loop
129 unsigned int pCollEnd = persCont->m_collections.size();
130 if (log.level() <= MSG::DEBUG)
131 log << MSG::DEBUG<< " Reading " << pCollEnd << "Collections" <<endmsg;
132 for (unsigned int pcollIndex = 0; pcollIndex < pCollEnd; ++pcollIndex) {
133 const Muon::MuonPRD_Collection_p2& pcoll = persCont->m_collections[pcollIndex];
134 IdentifierHash collIDHash(pcoll.m_hashId);
135 coll = new Muon::MdtPrepDataCollection(collIDHash);
136 coll->setIdentifier(Identifier(pcoll.m_id));
137
138
139 // FIXME - really would like to remove Identifier from collection, but cannot as there is :
140 // a) no way (apparently - find it hard to believe) to go from collection IdHash to collection Identifer.
141
142 unsigned int pchanEnd = pchanIndex+pcoll.m_size;
143 unsigned int chanIndex = 0; // transient index
144
145 coll->reserve(pcoll.m_size);
146 // Fill with channels
147 for (; pchanIndex < pchanEnd; ++ pchanIndex, ++chanIndex) {
148 const MdtPrepData_p2* pchan = &(persCont->m_prds[pchanIndex]);
149
150 Identifier clusId (pcoll.m_id + persCont->m_prdDeltaId[pchanIndex]);
151
152 // The reason I need to do the following is that one collection can have several detector elements in, the collection hashes!=detector element hashes
153 IdentifierHash deIDHash;
154 int result = m_MdtId->get_detectorElement_hash(clusId, deIDHash);
155 if (result&&log.level() <= MSG::WARNING)
156 log << MSG::WARNING<< " Muon::MdtPrepDataContainerCnv_p2::persToTrans: problem converting Identifier to DE hash "<<endmsg;
157 const MuonGM::MdtReadoutElement* detEl = getReadOutElement(clusId);
158
159 auto chan = std::make_unique<MdtPrepData>
160 (chanCnv.createMdtPrepData (pchan,
161 clusId,
162 detEl,
163 log));
164
165 chan->setHashAndIndex(collIDHash, chanIndex);
166 coll->push_back(std::move(chan));
167 }
168
169 // register the rdo collection in IDC with hash - faster addCollection
170 StatusCode sc = transCont->addCollection(coll, collIDHash);
171 if (sc.isFailure()) {
172 throw std::runtime_error("Failed to add collection to Identifiable Container");
173 }
174 if (log.level() <= MSG::DEBUG) {
175 log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
176 coll->identify().get_compact() << ", added to Identifiable container." << endmsg;
177 }
178 }
179
180 if (log.level() <= MSG::DEBUG)
181 log << MSG::DEBUG<< " *** Reading MdtPrepDataContainer ***" << endmsg;
182}
183
184
185
186//================================================================
188{
189 if(!m_isInitialized) {
190 if (this->initialize(log) != StatusCode::SUCCESS) {
191 log << MSG::FATAL << "Could not initialize MdtPrepDataContainerCnv_p2 " << endmsg;
192 return nullptr;
193 }
194 }
195 std::unique_ptr<Muon::MdtPrepDataContainer> trans(new Muon::MdtPrepDataContainer(m_MdtId->module_hash_max()));
196 persToTrans(persObj, trans.get(), log);
197 return(trans.release());
198}
199
200
#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.
void transToPers(const Muon::MdtPrepData *transObj, Muon::MdtPrepData_p2 *persObj, MsgStream &log)
static Muon::MdtPrepData createMdtPrepData(const Muon::MdtPrepData_p2 *persObj, const Identifier &id, const MuonGM::MdtReadoutElement *detEl, MsgStream &log)
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
virtual Muon::MdtPrepDataContainer * createTransient(const Muon::MdtPrepDataContainer_p2 *persObj, MsgStream &log)
const MuonGM::MdtReadoutElement * getReadOutElement(const Identifier &id) const
virtual void transToPers(const Muon::MdtPrepDataContainer *transCont, Muon::MdtPrepDataContainer_p2 *persCont, MsgStream &log)
virtual void persToTrans(const Muon::MdtPrepDataContainer_p2 *persCont, Muon::MdtPrepDataContainer *transCont, MsgStream &log)
Persistent representation of the transient Muon::MdtPrepData class.
Class to represent measurements from the Monitored Drift Tubes.
Definition MdtPrepData.h:33
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 const Trk::TrkDetElementBase * getDetectorElement(const Identifier &id, const IdentifierHash &idHash) const =0
Returns the detectorElement associated with this Identifier & Hash.
MuonPRD_Container_p2< MdtPrepData_p2 > MdtPrepDataContainer_p2
MuonPrepDataContainerT< MdtPrepData > MdtPrepDataContainer
MuonPrepDataCollection< MdtPrepData > MdtPrepDataCollection
void initialize()