ATLAS Offline Software
MdtPrepDataContainerCnv_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 
9 
14 
15 // Gaudi
16 #include "GaudiKernel/ISvcLocator.h"
17 #include "GaudiKernel/Bootstrap.h"
18 #include "GaudiKernel/StatusCode.h"
19 #include "GaudiKernel/Service.h"
20 #include "GaudiKernel/MsgStream.h"
21 
22 // Athena
24 #include "StoreGate/StoreGateSvc.h"
25 #include "AthAllocators/DataPool.h"
26 
27 
29  // Do not initialize again:
30  m_isInitialized=true;
31 
32  // get DetectorStore service
33  SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
34  CHECK( detStore.isValid() );
35 
36  // Get the helper from the detector store
37  CHECK( detStore->retrieve(m_MdtId) );
38 
39  CHECK( m_eventCnvTool.retrieve() );
40 
41  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized." << endmsg;
42  return StatusCode::SUCCESS;
43 }
45  const Trk::ITrkEventCnvTool* cnv_tool = m_eventCnvTool->getCnvTool(id);
46  if (!cnv_tool) return nullptr;
47  return dynamic_cast<const MuonGM::MdtReadoutElement*>(cnv_tool->getDetectorElement(id));
48 }
50 {
51 
52  // The transient model has a container holding collections and the
53  // collections hold channels.
54  //
55  // The persistent model flattens this so that the persistent
56  // container has two vectors:
57  // 1) all collections, and
58  // 2) all PRDs
59  //
60  // The persistent collections, then only maintain indexes into the
61  // container's vector of all channels.
62  //
63  // So here we loop over all collection and add their channels
64  // to the container's vector, saving the indexes in the
65  // collection.
66 
69 
70  MdtPrepDataCnv_p1 chanCnv;
71  TRANS::const_iterator it_Coll = transCont->begin();
72  TRANS::const_iterator it_CollEnd = transCont->end();
73  unsigned int collIndex= 0;
74  unsigned int chanBegin = 0;
75  unsigned int chanEnd = 0;
76  int numColl = transCont->numberOfCollections();
77  // if(numColl == transCont->hashFunc().max() ) { // let's count how many collections we have:
78  // numColl = 0;
79  // for ( ; it_Coll != it_CollEnd; it_Coll++)
80  // numColl++;
81  // it_Coll = transCont->begin(); // reset the iterator, we used it!
82  // }
83  persCont->m_collections.resize(numColl);
84  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
85 
86  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
87  // Add in new collection
88  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " New collection" << endmsg;
89  const Muon::MdtPrepDataCollection& collection = (**it_Coll);
90  chanBegin = chanEnd;
91  chanEnd += collection.size();
92  Muon::MuonPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
93  pcollection.m_id = collection.identify().get_identifier32().get_compact();
94  pcollection.m_hashId = (unsigned int) collection.identifyHash();
95  pcollection.m_begin = chanBegin;
96  pcollection.m_end = chanEnd;
97  // Add in channels
98  persCont->m_PRD.resize(chanEnd);
99  for (unsigned int i = 0; i < collection.size(); ++i) {
100  const Muon::MdtPrepData* chan = collection[i];
101  persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
102  }
103  }
104  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing MdtPrepDataContainer ***" << endmsg;
105 }
106 
108 {
109 
110  // The transient model has a container holding collections and the
111  // collections hold channels.
112  //
113  // The persistent model flattens this so that the persistent
114  // container has two vectors:
115  // 1) all collections, and
116  // 2) all channels
117  //
118  // The persistent collections, then only maintain indexes into the
119  // container's vector of all channels.
120  //
121  // So here we loop over all collection and extract their channels
122  // from the vector.
123 
124 
125  Muon::MdtPrepDataCollection* coll = nullptr;
126 
127  MdtPrepDataCnv_p1 chanCnv;
129 
130  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
131  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
132 
133  // Create trans collection - is NOT owner of MdtPrepData (SG::VIEW_ELEMENTS)
134  // IDet collection don't have the Ownership policy c'tor
135  const Muon::MuonPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
136  Identifier collID(Identifier(pcoll.m_id));
137  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
138  coll = new Muon::MdtPrepDataCollection(collIDHash);
139  coll->setIdentifier(Identifier(pcoll.m_id));
140  unsigned int nchans = pcoll.m_end - pcoll.m_begin;
141  coll->resize(nchans);
142 // No hash based lookup for Mdts?
143  // Fill with channels
144  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
145  const TPObjRef pchan = persCont->m_PRD[ichan + pcoll.m_begin];
146  Muon::MdtPrepData* chan = dynamic_cast<Muon::MdtPrepData*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
147  if (chan!=nullptr) {
148  const MuonGM::MdtReadoutElement * de = getReadOutElement(chan->identify());
149  chan->m_detEl = de;
150  (*coll)[ichan] = chan;
151  } else {
152  log<<MSG::WARNING<<"Dynamic cast or createTransFromPStore failed - channel missing"<<endmsg;
153  }
154  }
155 
156  // register the rdo collection in IDC with hash - faster addCollection
157  StatusCode sc = transCont->addCollection(coll, collIDHash);
158  if (sc.isFailure()) {
159  throw std::runtime_error("Failed to add collection to ID Container");
160  }
161  if (log.level() <= MSG::DEBUG) {
162  log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
163  collID.get_compact() << ", added to Identifiable container." << endmsg;
164  }
165  }
166 
167  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading MdtPrepDataContainer" << endmsg;
168 }
169 
170 
171 
172 //================================================================
174 {
175  if(!m_isInitialized) {
176  if (this->initialize(log) != StatusCode::SUCCESS) {
177  log << MSG::FATAL << "Could not initialize MdtPrepDataContainerCnv_p1 " << endmsg;
178  return nullptr;
179  }
180  }
181  std::unique_ptr<Muon::MdtPrepDataContainer> trans(new Muon::MdtPrepDataContainer(m_MdtId->module_hash_max()));
182  persToTrans(persObj, trans.get(), log);
183  return(trans.release());
184 }
185 
186 
Muon::MuonPrepDataContainer
Template for Muon PRD containers (which are basically collections of MuonPrepDataCollections).
Definition: MuonPrepDataContainer.h:42
Muon::MuonPRD_Container_p1::m_collections
std::vector< Muon::MuonPRD_Collection_p1 > m_collections
Definition: MuonPRD_Container_p1.h:19
ITPConverterFor< Trk::PrepRawData >
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
IdentifiableContainerMT::addCollection
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,...
Definition: IdentifiableContainerMT.h:297
Muon::MuonPRD_Collection_p1::m_id
unsigned int m_id
Identifier of this collection.
Definition: MuonPRD_Collection_p1.h:31
Muon::MuonPRD_Collection_p1::m_hashId
unsigned int m_hashId
Hash Identifier of this collection (write this one as well, so we don't rely on the IdHelper for it)
Definition: MuonPRD_Collection_p1.h:35
Muon::MuonPRD_Collection_p1::m_end
unsigned int m_end
End index into master collection.
Definition: MuonPRD_Collection_p1.h:41
initialize
void initialize()
Definition: run_EoverP.cxx:894
Muon::MdtPrepDataCollection
MuonPrepDataCollection< MdtPrepData > MdtPrepDataCollection
Definition: MuonPrepDataCollection.h:106
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Identifier::get_compact
value_type get_compact() const
Get the compact id.
MdtPrepData.h
Muon::MdtPrepDataContainerCnv_p1::initialize
StatusCode initialize(MsgStream &log)
Definition: MdtPrepDataContainerCnv_p1.cxx:28
MdtPrepDataContainerCnv_p1.h
Muon::MdtPrepDataContainerCnv_p1::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: MdtPrepDataContainerCnv_p1.cxx:49
Muon::MuonPrepDataCollection::setIdentifier
virtual void setIdentifier(Identifier id)
Muon::MdtPrepDataContainerCnv_p1::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: MdtPrepDataContainerCnv_p1.cxx:107
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
TPObjRef
Definition: TPObjRef.h:20
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MuonPRD_Container_p1.h
MdtPrepDataContainer.h
Muon::MuonPrepDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:213
MuonGM::MdtReadoutElement
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MdtReadoutElement.h:51
lumiFormat.i
int i
Definition: lumiFormat.py:85
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Muon::MdtPrepDataContainerCnv_p1::m_MdtId
const MdtIdHelper * m_MdtId
Definition: MdtPrepDataContainerCnv_p1.h:40
Muon::MuonPrepDataCollection::identify
virtual Identifier identify() const override final
Trk::ITrkEventCnvTool
Definition: ITrkEventCnvTool.h:31
MdtIdHelper.h
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:239
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
IdentifiableContainerMT::const_iterator
Definition: IdentifiableContainerMT.h:79
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:233
Muon::MuonPrepDataCollection
Template to hold collections of MuonPrepRawData objects.
Definition: MuonPrepDataCollection.h:46
DataPool.h
Muon::MdtPrepDataContainerCnv_p1::m_isInitialized
bool m_isInitialized
Definition: MdtPrepDataContainerCnv_p1.h:42
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
DataVector::resize
void resize(size_type sz)
Resizes the collection to the specified number of elements.
defineDB.ichan
int ichan
Definition: JetTagCalibration/share/defineDB.py:28
errorcheck.h
Helpers for checking error return status codes and reporting errors.
Muon::MuonPRD_Collection_p1::m_begin
unsigned int m_begin
Begin index into master collection.
Definition: MuonPRD_Collection_p1.h:38
Muon::MuonPRD_Collection_p1
Definition: MuonPRD_Collection_p1.h:11
Muon::MdtPrepData
Class to represent measurements from the Monitored Drift Tubes.
Definition: MdtPrepData.h:33
MuonDetectorManager.h
Muon::MuonPRD_Container_p1::m_PRD
std::vector< TPObjRef > m_PRD
Definition: MuonPRD_Container_p1.h:20
Muon::MdtPrepDataContainerCnv_p1::getReadOutElement
const MuonGM::MdtReadoutElement * getReadOutElement(const Identifier &id) const
Definition: MdtPrepDataContainerCnv_p1.cxx:44
MdtPrepDataCnv_p1
Definition: MdtPrepDataCnv_p1.h:23
Trk::ITrkEventCnvTool::getDetectorElement
virtual const Trk::TrkDetElementBase * getDetectorElement(const Identifier &id, const IdentifierHash &idHash) const =0
Returns the detectorElement associated with this Identifier & Hash.
MdtPrepData_p1.h
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Muon::MdtPrepDataContainerCnv_p1::m_eventCnvTool
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
Definition: MdtPrepDataContainerCnv_p1.h:41
Muon::MuonPRD_Container_p1
Definition: MuonPRD_Container_p1.h:14
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
StoreGateSvc.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
MdtPrepDataCnv_p1.h
Muon::MdtPrepDataContainerCnv_p1::createTransient
virtual Muon::MdtPrepDataContainer * createTransient(const Muon::MuonPRD_Container_p1 *persObj, MsgStream &log)
Definition: MdtPrepDataContainerCnv_p1.cxx:173
Identifier
Definition: IdentifierFieldParser.cxx:14