ATLAS Offline Software
Loading...
Searching...
No Matches
MMPrepDataContainerCnv_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
6
13
14// Gaudi
15#include "GaudiKernel/Bootstrap.h"
16#include "GaudiKernel/ISvcLocator.h"
17
18// Athena
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_MMId) );
32
33 CHECK( m_eventCnvTool.retrieve() );
34
35 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter 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::MMReadoutElement*>(cnv_tool->getDetectorElement(id));
42}
44 MsgStream& log) {
45 if (!m_isInitialized) {
46 if (this->initialize(log) != StatusCode::SUCCESS) {
47 log << MSG::FATAL << "Could not initialize MMPrepDataContainerCnv_p1 " << endmsg;
48 }
49 }
50 // The transient model has a container holding collections (= 64 modules in MmIdHelper
51 // each consisting of two MicroMegas quadruplets in reality) and the collections hold channels.
52 //
53 // The persistent model flattens this so that the persistent
54 // container has two vectors:
55 // 1) all collections, and
56 // 2) all PRDs
57 //
58 // The persistent collections, then only maintain indexes into the
59 // container's vector of all channels.
60 //
61 // So here we loop over all collection and add their channels
62 // to the container's vector, saving the indexes in the collection.
63
64 MMPrepDataCnv_p1 chanCnv;
66 Muon::MMPrepDataContainer::const_iterator it_CollEnd = transCont->end();
67 unsigned int pcollEnd = 0; // index to end
68 int numColl = transCont->numberOfCollections();
69 persCont->m_collections.resize(numColl);
70 if (log.level() <= MSG::DEBUG) { log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "collections" << endmsg; }
71
72 for (unsigned int pcollIndex = 0; it_Coll != it_CollEnd; ++pcollIndex, ++it_Coll) {
73 const Muon::MMPrepDataCollection& collection = (**it_Coll);
74 if (log.level() <= MSG::DEBUG) {
75 log << MSG::DEBUG << "Coll hash for " << pcollIndex << ": " << collection.identifyHash() << endmsg;
76 }
77 // Add in new collection
78 Muon::MuonPRD_Collection_p2& pcollection = persCont->m_collections[pcollIndex]; // get ref to collection we're going to fill
79
80 pcollEnd += collection.size();
81
82 pcollection.m_hashId = collection.identifyHash(); // the collection hash is the module hash in MmIdHelper
83 pcollection.m_id = collection.identify().get_identifier32().get_compact();
84 pcollection.m_size = collection.size();
85 // Add in channels
86 persCont->m_prds.reserve(pcollEnd);
87 persCont->m_prdDeltaId.reserve(pcollEnd);
88
89 for (unsigned int i = 0; i < collection.size(); ++i) {
90 const MMPrepData* chan = collection[i]; // channel being converted
91 MMPrepData_p1 pchan{}; // persistent version to fill
92 const Identifier chan_id = chan->identify();
93 chanCnv.transToPers(chan, &pchan, log); // convert from MMPrepData to MMPrepData_p1
94
95 // persCont->m_prdDeltaId is of data type unsigned short, thus we need to encode the channel (starting from the
96 // collection (module) is in contained) into 16 bits, we do it by storing multilayer, gasGap and channel
97 int multilayer = (m_MMId->multilayer(chan_id) - 1); // ranges between 1-2 (1bit)
98 int gasGap = (m_MMId->gasGap(chan_id) - 1); // ranges between 1-4 (2bits)
99 int channel = (m_MMId->channel(chan_id) - MmIdHelper::channelMin()); // ranges between 1-5012 (13bits)
100
101 // created an unsigned short and store multilayer, gasGap and channel by bit-shifts
102 unsigned short diff = (channel << 3 | gasGap << 1 | multilayer);
103 if (log.level() <= MSG::DEBUG) {
104 log << MSG::DEBUG << "Translated id=" << chan_id.get_compact() << " (multilayer=" << multilayer << ", gasGap=" << gasGap
105 << ", channel=" << channel << ") into diff=" << diff << endmsg;
106 }
107
108 persCont->m_prdDeltaId.emplace_back(diff); // store delta identifiers, rather than full identifiers
109
110 const MuonGM::MMReadoutElement* ele_from_mgr = getReadOutElement(chan_id);
111 if (log.level() <= MSG::WARNING && chan->detectorElement()->identify() != ele_from_mgr->identify()) {
112 log << MSG::WARNING << "DE from det manager (" << m_MMId->print_to_string(ele_from_mgr->identify())
113 << ") does not match that from PRD (" << m_MMId->print_to_string(chan->detectorElement()->identify()) << ") for PRD "
114 << m_MMId->print_to_string(chan_id) << endmsg;
115 }
116 persCont->m_prds.emplace_back(std::move(pchan));
117 }
118 }
119 log << MSG::DEBUG << " *** Writing MMPrepDataContainer ***" << endmsg;
120}
121
123 MsgStream& log) {
124 // The transient model has a container holding collections (= 64 modules in MmIdHelper
125 // each consisting of two MicroMegas quadruplets in reality) and the collections hold channels.
126 //
127 // The persistent model flattens this so that the persistent
128 // container has two vectors:
129 // 1) all collections, and
130 // 2) all channels
131 //
132 // The persistent collections, then only maintain indexes into the
133 // container's vector of all channels.
134 //
135 // So here we loop over all collection and extract their channels
136 // from the vector.
137
138 Muon::MMPrepDataCollection* coll = nullptr;
139
140 MMPrepDataCnv_p1 chanCnv;
141 unsigned int pchanIndex(0); // position within persCont->m_prds. Incremented inside innermost loop
142 unsigned int pCollEnd = persCont->m_collections.size();
143 if (log.level() <= MSG::DEBUG) { log << MSG::DEBUG << " Reading " << pCollEnd << "Collections" << endmsg; }
144 for (unsigned int pcollIndex = 0; pcollIndex < pCollEnd; ++pcollIndex) {
145 const Muon::MuonPRD_Collection_p2& pcoll = persCont->m_collections[pcollIndex];
146 IdentifierHash collIDHash(pcoll.m_hashId);
147 if (log.level() <= MSG::DEBUG) { log << MSG::DEBUG << "Coll hash for " << pcollIndex << ": " << collIDHash << endmsg; }
148
149 coll = new Muon::MMPrepDataCollection(collIDHash);
150 coll->setIdentifier(Identifier(pcoll.m_id));
151
152 unsigned int pchanEnd = pchanIndex + pcoll.m_size;
153 unsigned int chanIndex = 0; // transient index
154
155 coll->reserve(pcoll.m_size);
156 // Fill with channels
157 for (; pchanIndex < pchanEnd; ++pchanIndex, ++chanIndex) {
158 const MMPrepData_p1* pchan = &(persCont->m_prds[pchanIndex]);
159
161 unsigned short diff = persCont->m_prdDeltaId[pchanIndex];
162 // we need to redo the bit-shift to retrieve channel, gasGap and multilayer
163 int channel = (diff >> 3);
164 int gasGap = (3 & (diff >> 1));
165 int multilayer = (1 & diff);
166 Identifier clusId = m_MMId->channelID(Identifier(pcoll.m_id), multilayer + 1, gasGap + 1, channel + MmIdHelper::channelMin());
167 if (log.level() <= MSG::DEBUG) {
168 log << MSG::DEBUG << "Diff of " << diff << " translated into multilayer=" << multilayer << ", gasGap=" << gasGap
169 << ", channel=" << channel << " -> id=" << clusId.get_compact() << endmsg;
170 }
171
172 const MuonGM::MMReadoutElement* detEl = getReadOutElement(clusId);
173 if (!detEl) {
174 if (log.level() <= MSG::WARNING) {
175 log << MSG::WARNING << "Muon::MMPrepDataContainerCnv_p1::persToTrans: could not get valid det element for PRD with id="
176 << m_MMId->show_to_string(clusId) << ". Skipping." << endmsg;
177 }
178 continue;
179 }
180
181 auto chan = std::make_unique<MMPrepData>(chanCnv.createMMPrepData(pchan, clusId, detEl, log));
182
183 if (!m_MMId->valid(chan->identify())) {
184 log << MSG::WARNING << "MM PRD has invalid Identifier of " << chan->identify().get_compact()
185 << " - are you sure you have the correct geometry loaded, and NSW enabled?" << endmsg;
186 }
187
188 // chanCnv.persToTrans(pchan, chan, log); // Fill chan with data from pchan FIXME! Put this back once diff is sane.
189 if (log.level() <= MSG::DEBUG) { log << MSG::DEBUG << "chan identify(): " << chan->identify().get_compact() << endmsg; }
190
191 chan->setHashAndIndex(collIDHash, chanIndex);
192 coll->push_back(std::move(chan));
193 }
194
195 // register the rdo collection in IDC with hash - faster addCollection
196 StatusCode sc = transCont->addCollection(coll, collIDHash);
197 if (sc.isFailure()) { throw std::runtime_error("Failed to add collection to Identifiable Container"); }
198 if (log.level() <= MSG::DEBUG) {
199 log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int)collIDHash << " / "
200 << coll->identify().get_compact() << ", added to Identifiable container." << endmsg;
201 }
202 }
203 if (log.level() <= MSG::DEBUG) { log << MSG::DEBUG << " *** Reading MMPrepDataContainer ***" << endmsg; }
204}
205
207 if (!m_isInitialized) {
208 if (this->initialize(log) != StatusCode::SUCCESS) {
209 log << MSG::FATAL << "Could not initialize MMPrepDataContainerCnv_p1 " << endmsg;
210 return nullptr;
211 }
212 }
213 std::unique_ptr<Muon::MMPrepDataContainer> trans = std::make_unique<Muon::MMPrepDataContainer>(m_MMId->module_hash_max());
214 persToTrans(persObj, trans.get(), log);
215 return (trans.release());
216}
#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 diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
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.
static Muon::MMPrepData createMMPrepData(const Muon::MMPrepData_p1 *persObj, Identifier clusId, const MuonGM::MMReadoutElement *detEl, MsgStream &log)
function used to create an MMPrepDataObject when converting Pers to trans
void transToPers(const Muon::MMPrepData *transObj, Muon::MMPrepData_p1 *persObj, MsgStream &log)
static int channelMin()
An MMReadoutElement corresponds to a single STGC module; therefore typicaly a barrel muon station con...
Identifier identify() const override final
Returns the ATLAS Identifier of the MuonReadOutElement.
virtual void transToPers(const Muon::MMPrepDataContainer *transCont, Muon::MMPrepDataContainer_p1 *persCont, MsgStream &log)
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
virtual Muon::MMPrepDataContainer * createTransient(const Muon::MMPrepDataContainer_p1 *persObj, MsgStream &log)
const MuonGM::MMReadoutElement * getReadOutElement(const Identifier &id) const
virtual void persToTrans(const Muon::MMPrepDataContainer_p1 *persCont, Muon::MMPrepDataContainer *transCont, MsgStream &log)
We don't write out (from Trk::PrepRawData) m_indexAndHash (can be recomputed), m_clusId (can be recom...
Class to represent MM measurements.
Definition MMPrepData.h:22
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.
MuonPrepDataCollection< MMPrepData > MMPrepDataCollection
MuonPRD_Container_p2< MMPrepData_p1 > MMPrepDataContainer_p1
MuonPrepDataContainerT< MMPrepData > MMPrepDataContainer
void initialize()