ATLAS Offline Software
MdtPrepDataContainerCnv_p1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 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
23 #include "StoreGate/StoreGateSvc.h"
24 
25 
26 
27 #include "AthAllocators/DataPool.h"
28 
30  // Do not initialize again:
31  m_isInitialized=true;
32 
33  // Get Storegate, ID helpers, and so on
34  ISvcLocator* svcLocator = Gaudi::svcLocator();
35  // get StoreGate service
36  StatusCode sc = svcLocator->service("StoreGateSvc", m_storeGate);
37  if (sc.isFailure()) {
38  log << MSG::FATAL << "StoreGate service not found !" << endmsg;
39  return StatusCode::FAILURE;
40  }
41 
42  // get DetectorStore service
44  sc = svcLocator->service("DetectorStore", detStore);
45  if (sc.isFailure()) {
46  log << MSG::FATAL << "DetectorStore service not found !" << endmsg;
47  return StatusCode::FAILURE;
48  } else {
49  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found DetectorStore." << endmsg;
50  }
51 
52  // Get the pixel helper from the detector store
53  sc = detStore->retrieve(m_MdtId);
54  if (sc.isFailure()) {
55  log << MSG::FATAL << "Could not get Mdt ID helper !" << endmsg;
56  return StatusCode::FAILURE;
57  } else {
58  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found the Mdt ID helper." << endmsg;
59  }
60 
61  if (m_eventCnvTool.retrieve().isFailure()) {
62  log << MSG::FATAL << "Could not get DetectorDescription manager" << endmsg;
63  return StatusCode::FAILURE;
64  }
65 
66  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized." << endmsg;
67  return StatusCode::SUCCESS;
68 }
70  const Trk::ITrkEventCnvTool* cnv_tool = m_eventCnvTool->getCnvTool(id);
71  if (!cnv_tool) return nullptr;
72  return dynamic_cast<const MuonGM::MdtReadoutElement*>(cnv_tool->getDetectorElement(id));
73 }
75 {
76 
77  // The transient model has a container holding collections and the
78  // collections hold channels.
79  //
80  // The persistent model flattens this so that the persistent
81  // container has two vectors:
82  // 1) all collections, and
83  // 2) all PRDs
84  //
85  // The persistent collections, then only maintain indexes into the
86  // container's vector of all channels.
87  //
88  // So here we loop over all collection and add their channels
89  // to the container's vector, saving the indexes in the
90  // collection.
91 
94 
95  MdtPrepDataCnv_p1 chanCnv;
96  TRANS::const_iterator it_Coll = transCont->begin();
97  TRANS::const_iterator it_CollEnd = transCont->end();
98  unsigned int collIndex= 0;
99  unsigned int chanBegin = 0;
100  unsigned int chanEnd = 0;
101  int numColl = transCont->numberOfCollections();
102  // if(numColl == transCont->hashFunc().max() ) { // let's count how many collections we have:
103  // numColl = 0;
104  // for ( ; it_Coll != it_CollEnd; it_Coll++)
105  // numColl++;
106  // it_Coll = transCont->begin(); // reset the iterator, we used it!
107  // }
108  persCont->m_collections.resize(numColl);
109  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
110 
111  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
112  // Add in new collection
113  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " New collection" << endmsg;
114  const Muon::MdtPrepDataCollection& collection = (**it_Coll);
115  chanBegin = chanEnd;
116  chanEnd += collection.size();
117  Muon::MuonPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
118  pcollection.m_id = collection.identify().get_identifier32().get_compact();
119  pcollection.m_hashId = (unsigned int) collection.identifyHash();
120  pcollection.m_begin = chanBegin;
121  pcollection.m_end = chanEnd;
122  // Add in channels
123  persCont->m_PRD.resize(chanEnd);
124  for (unsigned int i = 0; i < collection.size(); ++i) {
125  const Muon::MdtPrepData* chan = collection[i];
126  persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
127  }
128  }
129  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing MdtPrepDataContainer ***" << endmsg;
130 }
131 
133 {
134 
135  // The transient model has a container holding collections and the
136  // collections hold channels.
137  //
138  // The persistent model flattens this so that the persistent
139  // container has two vectors:
140  // 1) all collections, and
141  // 2) all channels
142  //
143  // The persistent collections, then only maintain indexes into the
144  // container's vector of all channels.
145  //
146  // So here we loop over all collection and extract their channels
147  // from the vector.
148 
149 
150  Muon::MdtPrepDataCollection* coll = nullptr;
151 
152  MdtPrepDataCnv_p1 chanCnv;
154 
155  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
156  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
157 
158  // Create trans collection - is NOT owner of MdtPrepData (SG::VIEW_ELEMENTS)
159  // IDet collection don't have the Ownership policy c'tor
160  const Muon::MuonPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
161  Identifier collID(Identifier(pcoll.m_id));
162  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
163  coll = new Muon::MdtPrepDataCollection(collIDHash);
164  coll->setIdentifier(Identifier(pcoll.m_id));
165  unsigned int nchans = pcoll.m_end - pcoll.m_begin;
166  coll->resize(nchans);
167 // No hash based lookup for Mdts?
168  // Fill with channels
169  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
170  const TPObjRef pchan = persCont->m_PRD[ichan + pcoll.m_begin];
171  Muon::MdtPrepData* chan = dynamic_cast<Muon::MdtPrepData*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
172  if (chan!=nullptr) {
173  const MuonGM::MdtReadoutElement * de = getReadOutElement(chan->identify());
174  chan->m_detEl = de;
175  (*coll)[ichan] = chan;
176  } else {
177  log<<MSG::WARNING<<"Dynamic cast or createTransFromPStore failed - channel missing"<<endmsg;
178  }
179  }
180 
181  // register the rdo collection in IDC with hash - faster addCollection
182  StatusCode sc = transCont->addCollection(coll, collIDHash);
183  if (sc.isFailure()) {
184  throw std::runtime_error("Failed to add collection to ID Container");
185  }
186  if (log.level() <= MSG::DEBUG) {
187  log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
188  collID.get_compact() << ", added to Identifiable container." << endmsg;
189  }
190  }
191 
192  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading MdtPrepDataContainer" << endmsg;
193 }
194 
195 
196 
197 //================================================================
199 {
200  if(!m_isInitialized) {
201  if (this->initialize(log) != StatusCode::SUCCESS) {
202  log << MSG::FATAL << "Could not initialize MdtPrepDataContainerCnv_p1 " << endmsg;
203  return nullptr;
204  }
205  }
206  std::unique_ptr<Muon::MdtPrepDataContainer> trans(new Muon::MdtPrepDataContainer(m_MdtId->module_hash_max()));
207  persToTrans(persObj, trans.get(), log);
208  return(trans.release());
209 }
210 
211 
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:300
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
MdtPrepData.h
Muon::MdtPrepDataContainerCnv_p1::initialize
StatusCode initialize(MsgStream &log)
Definition: MdtPrepDataContainerCnv_p1.cxx:29
MdtPrepDataContainerCnv_p1.h
Muon::MdtPrepDataContainerCnv_p1::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: MdtPrepDataContainerCnv_p1.cxx:74
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:132
TPObjRef
Definition: TPObjRef.h:20
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Muon::MdtPrepDataContainerCnv_p1::m_storeGate
StoreGateSvc * m_storeGate
Definition: MdtPrepDataContainerCnv_p1.h:42
MuonPRD_Container_p1.h
MdtPrepDataContainer.h
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
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:216
Identifier32::get_compact
value_type get_compact(void) const
Get the compact id.
Definition: Identifier32.h:171
MuonGM::MdtReadoutElement
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MdtReadoutElement.h:50
lumiFormat.i
int i
Definition: lumiFormat.py:92
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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:41
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:242
IdentifiableContainerMT::const_iterator
Definition: IdentifiableContainerMT.h:82
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:236
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:44
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
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:37
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:69
MdtPrepDataCnv_p1
Definition: MdtPrepDataCnv_p1.h:23
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
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:43
Muon::MuonPRD_Container_p1
Definition: MuonPRD_Container_p1.h:14
IdentifierHash
Definition: IdentifierHash.h:38
Identifier::get_identifier32
Identifier32 get_identifier32(void) const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
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:198