ATLAS Offline Software
RpcPrepDataContainerCnv_p2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
13 // Gaudi
14 #include "GaudiKernel/ISvcLocator.h"
15 #include "GaudiKernel/Bootstrap.h"
16 #include "GaudiKernel/StatusCode.h"
17 #include "GaudiKernel/Service.h"
18 #include "GaudiKernel/MsgStream.h"
19 
20 // Athena
21 #include "StoreGate/StoreGateSvc.h"
22 
23 
24 
25 #include "AthAllocators/DataPool.h"
26 
28  // Do not initialize again:
29  m_isInitialized=true;
30 
31  // Get Storegate, ID helpers, and so on
32  ISvcLocator* svcLocator = Gaudi::svcLocator();
33  // get StoreGate service
34  StatusCode sc = svcLocator->service("StoreGateSvc", m_storeGate);
35  if (sc.isFailure()) {
36  log << MSG::FATAL << "StoreGate service not found !" << endmsg;
37  return StatusCode::FAILURE;
38  }
39 
40  // get DetectorStore service
42  sc = svcLocator->service("DetectorStore", detStore);
43  if (sc.isFailure()) {
44  log << MSG::FATAL << "DetectorStore service not found !" << endmsg;
45  return StatusCode::FAILURE;
46  } else {
47  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found DetectorStore." << endmsg;
48  }
49 
50  // Get the pixel helper from the detector store
51  sc = detStore->retrieve(m_RpcId);
52  if (sc.isFailure()) {
53  log << MSG::FATAL << "Could not get Rpc ID helper !" << endmsg;
54  return StatusCode::FAILURE;
55  } else {
56  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found the Rpc ID helper." << endmsg;
57  }
58 
59  if (m_eventCnvTool.retrieve().isFailure()) {
60  log << MSG::FATAL << "Could not get DetectorDescription manager" << endmsg;
61  return StatusCode::FAILURE;
62  }
63 
64  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized." << endmsg;
65  return StatusCode::SUCCESS;
66 }
68  const Trk::ITrkEventCnvTool* cnv_tool = m_eventCnvTool->getCnvTool(id);
69  if (!cnv_tool) return nullptr;
70  return dynamic_cast<const MuonGM::RpcReadoutElement*>(cnv_tool->getDetectorElement(id));
71 }
73 {
74 
75  // The transient model has a container holding collections and the
76  // collections hold channels.
77  //
78  // The persistent model flattens this so that the persistent
79  // container has two vectors:
80  // 1) all collections, and
81  // 2) all RDO
82  //
83  // The persistent collections, then only maintain indexes into the
84  // container's vector of all channels.
85  //
86  // So here we loop over all collection and add their channels
87  // to the container's vector, saving the indexes in the
88  // collection.
89 
92 
93  RpcPrepDataCnv_p2 chanCnv;
94  TRANS::const_iterator it_Coll = transCont->begin();
95  TRANS::const_iterator it_CollEnd = transCont->end();
96  unsigned int collIndex = 0;
97  unsigned int chanBegin = 0;
98  unsigned int chanEnd = 0;
99  int numColl = transCont->numberOfCollections();
100 
101  persCont->m_collections.resize(numColl); log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
102 
103  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
104  // Add in new collection
105  log << MSG::DEBUG << " New collection" << endmsg;
106  const Muon::RpcPrepDataCollection& collection = (**it_Coll);
107  chanBegin = chanEnd;
108  chanEnd += collection.size();
109  Muon::MuonPRD_Collection_p1& pcollection = persCont->m_collections[collIndex];
110  pcollection.m_id = collection.identify().get_identifier32().get_compact();
111  pcollection.m_hashId = (unsigned int) collection.identifyHash();
112  pcollection.m_begin = chanBegin;
113  pcollection.m_end = chanEnd;
114  // Add in channels
115  persCont->m_PRD.resize(chanEnd);
116  for (unsigned int i = 0; i < collection.size(); ++i) {
117  const Muon::RpcPrepData* chan = collection[i];
118  persCont->m_PRD[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
119  }
120  }
121  log << MSG::DEBUG << " *** Writing RpcPrepDataContainer ***" << endmsg;
122 }
123 
125 {
126 
127  // The transient model has a container holding collections and the
128  // collections hold channels.
129  //
130  // The persistent model flattens this so that the persistent
131  // container has two vectors:
132  // 1) all collections, and
133  // 2) all channels
134  //
135  // The persistent collections, then only maintain indexes into the
136  // container's vector of all channels.
137  //
138  // So here we loop over all collection and extract their channels
139  // from the vector.
140 
141 
142  Muon::RpcPrepDataCollection* coll = nullptr;
143 
144  RpcPrepDataCnv_p2 chanCnv;
146 
147  log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
148  for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
149 
150  // Create trans collection - is NOT owner of RpcPrepData (SG::VIEW_ELEMENTS)
151  // IDet collection don't have the Ownership policy c'tor
152  const Muon::MuonPRD_Collection_p1& pcoll = persCont->m_collections[icoll];
153  Identifier collID(Identifier(pcoll.m_id));
154  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
155  coll = new Muon::RpcPrepDataCollection(collIDHash);
156  coll->setIdentifier(Identifier(pcoll.m_id));
157  unsigned int nchans = pcoll.m_end - pcoll.m_begin;
158  coll->resize(nchans);
159  // Fill with channels
160  for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
161  const TPObjRef pchan = persCont->m_PRD[ichan + pcoll.m_begin];
162  Muon::RpcPrepData* chan = dynamic_cast<Muon::RpcPrepData*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
163  if (!chan) {
164  log << MSG::ERROR << "AthenaPoolTPCnvIDCont::persToTrans: Cannot get RpcPrepData!" << endmsg;
165  continue;
166  }
167  const MuonGM::RpcReadoutElement * de = getReadOutElement(chan->identify());
168  chan->m_detEl = de;
169  (*coll)[ichan] = chan;
170  }
171 
172  // register the rdo collection in IDC with hash - faster addCollection
173  StatusCode sc = transCont->addCollection(coll, collIDHash);
174  if (sc.isFailure()) {
175  throw std::runtime_error("Failed to add collection to ID Container");
176  }
177  if (log.level() <= MSG::DEBUG) {
178  log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
179  collID.get_compact() << ", added to Identifiable container." << endmsg;
180  }
181  }
182 
183  log << MSG::DEBUG << " *** Reading RpcPrepDataContainer" << endmsg;
184 }
185 
186 
187 
188 //================================================================
190 {
191  if(!m_isInitialized) {
192  if (this->initialize(log) != StatusCode::SUCCESS) {
193  log << MSG::FATAL << "Could not initialize RpcPrepDataContainerCnv_p2 " << endmsg;
194  return nullptr;
195  }
196  }
197  std::unique_ptr<Muon::RpcPrepDataContainer> trans(new Muon::RpcPrepDataContainer(m_RpcId->module_hash_max()));
198  persToTrans(persObj, trans.get(), log);
199  return(trans.release());
200 }
201 
202 
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::RpcPrepDataCollection
MuonPrepDataCollection< RpcPrepData > RpcPrepDataCollection
Definition: MuonPrepDataCollection.h:107
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::RpcPrepDataContainerCnv_p2::m_isInitialized
bool m_isInitialized
Definition: RpcPrepDataContainerCnv_p2.h:44
MuonGM::RpcReadoutElement
An RpcReadoutElement corresponds to a single RPC module; therefore typicaly a barrel muon station con...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/RpcReadoutElement.h:54
Muon::RpcPrepDataContainerCnv_p2::m_eventCnvTool
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
Definition: RpcPrepDataContainerCnv_p2.h:43
RpcPrepDataContainer.h
RpcPrepDataCnv_p2.h
Muon::MuonPrepDataCollection::setIdentifier
virtual void setIdentifier(Identifier id)
TPObjRef
Definition: TPObjRef.h:20
Muon::RpcPrepDataContainerCnv_p2::initialize
StatusCode initialize(MsgStream &log)
Definition: RpcPrepDataContainerCnv_p2.cxx:27
RpcIdHelper.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Muon::RpcPrepDataContainerCnv_p2::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: RpcPrepDataContainerCnv_p2.cxx:124
MuonPRD_Container_p1.h
ITrkEventCnvTool.h
Muon::RpcPrepDataContainerCnv_p2::m_storeGate
StoreGateSvc * m_storeGate
Definition: RpcPrepDataContainerCnv_p2.h:42
Muon::RpcPrepDataContainerCnv_p2::getReadOutElement
const MuonGM::RpcReadoutElement * getReadOutElement(const Identifier &id) const
Definition: RpcPrepDataContainerCnv_p2.cxx:67
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
lumiFormat.i
int i
Definition: lumiFormat.py:92
Muon::RpcPrepData
Class to represent RPC measurements.
Definition: RpcPrepData.h:35
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::MuonPrepDataCollection::identify
virtual Identifier identify() const override final
Muon::RpcPrepDataContainerCnv_p2::m_RpcId
const RpcIdHelper * m_RpcId
Definition: RpcPrepDataContainerCnv_p2.h:41
Trk::ITrkEventCnvTool
Definition: ITrkEventCnvTool.h:31
RpcPrepDataContainerCnv_p2.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
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::RpcPrepDataContainerCnv_p2::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: RpcPrepDataContainerCnv_p2.cxx:72
Muon::MuonPRD_Collection_p1
Definition: MuonPRD_Collection_p1.h:11
Muon::MuonPRD_Container_p1::m_PRD
std::vector< TPObjRef > m_PRD
Definition: MuonPRD_Container_p1.h:20
Muon::RpcPrepDataContainerCnv_p2::createTransient
virtual Muon::RpcPrepDataContainer * createTransient(const Muon::MuonPRD_Container_p1 *persObj, MsgStream &log)
Definition: RpcPrepDataContainerCnv_p2.cxx:189
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.
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
RpcPrepDataCnv_p2
Definition: RpcPrepDataCnv_p2.h:23
Muon::MuonPRD_Container_p1
Definition: MuonPRD_Container_p1.h:14
RpcPrepData.h
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.
RpcPrepData_p2.h