ATLAS Offline Software
RpcCoinDataContainerCnv_p1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /* Takashi Kubota - June 30, 2008 */
10 
11 
16 
17 // // Gaudi
18 #include "GaudiKernel/ISvcLocator.h"
19 #include "GaudiKernel/Bootstrap.h"
20 
21 // Athena
22 #include "StoreGate/StoreGateSvc.h"
23 #include "AthAllocators/DataPool.h"
24 
25 
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  StatusCode 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  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  log << MSG::DEBUG << "Found the Rpc ID helper." << endmsg;
57  }
58 
59  sc = detStore->retrieve(m_muonDetMgr);
60  if (sc.isFailure()) {
61  log << MSG::FATAL << "Could not get RpcDetectorDescription" << endmsg;
62  return sc;
63  }
64 
65  log << MSG::DEBUG << "Converter initialized." << endmsg;
66  return StatusCode::SUCCESS;
67 }
68 
70 {
71  // The transient model has a container holding collections and the
72  // collections hold channels.
73  //
74  // The persistent model flattens this so that the persistent
75  // container has two vectors:
76  // 1) all collections, and
77  // 2) all PRD
78  //
79  // The persistent collections, then only maintain indexes into the
80  // container's vector of all channels.
81  //
82  // So here we loop over all collection and add their channels
83  // to the container's vector, saving the indexes in the
84  // collection.
85 
87 
88  RpcCoinDataCnv_p1 chanCnv;
89  TRANS::const_iterator it_Coll = transCont->begin();
90  TRANS::const_iterator it_CollEnd = transCont->end();
91  unsigned int pcollIndex; // index to the persistent collection we're filling
92  unsigned int pcollBegin = 0; // index to start of persistent collection we're filling, in long list of persistent PRDs
93  unsigned int pcollEnd = 0; // index to end
94  int numColl = transCont->numberOfCollections();
95  persCont->m_collections.resize(numColl);
96  log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
97  for (pcollIndex = 0; it_Coll != it_CollEnd; ++pcollIndex, ++it_Coll) {
98  // Add in new collection
99  const Muon::MuonCoinDataCollection<RpcCoinData>& collection = (**it_Coll);
100  Muon::MuonPRD_Collection_p2& pcollection = persCont->m_collections[pcollIndex];
101 
102  pcollBegin = pcollEnd; // Next collection starts at end of previous one.
103  pcollEnd += collection.size();
104 
105  pcollection.m_hashId = collection.identifyHash();
106  pcollection.m_id = collection.identify().get_identifier32().get_compact();
107  pcollection.m_size = collection.size();
108 
109 
110  // Add in channels
111  persCont->m_prds.resize(pcollEnd);
112  persCont->m_prdDeltaId.resize(pcollEnd);
113  log << MSG::VERBOSE << "Reading collections with " << collection.size() << "PRDs " << endmsg;
114  for (unsigned int i = 0; i < collection.size(); ++i) {
115  unsigned int pchanIndex=i+pcollBegin;
116  const Muon::RpcCoinData* chan = collection[i];
117  Muon::RpcCoinData_p1* pchan = &(persCont->m_prds[pchanIndex]);
118  chanCnv.transToPers(chan, pchan, log);
119  persCont->m_prdDeltaId[pchanIndex]=chan->identify().get_identifier32().get_compact() - collection.identify().get_identifier32().get_compact(); //store delta identifiers, rather than full identifiers
120  }
121  }
122  log << MSG::DEBUG << " *** Writing Muon::RpcCoinDataContainer" << endmsg;
123 }
124 
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 
143 
144  RpcCoinDataCnv_p1 chanCnv;
145  unsigned int pchanIndex(0); // position within persCont->m_prds. Incremented inside innermost loop
146  unsigned int pCollEnd = persCont->m_collections.size();
147  log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
148  for (unsigned int pcollIndex = 0; pcollIndex < pCollEnd; ++pcollIndex) {
149  const Muon::MuonPRD_Collection_p2& pcoll = persCont->m_collections[pcollIndex];
150  // Identifier collID= Identifier(idLast);
151  IdentifierHash collIDHash=IdentifierHash(pcoll.m_hashId);
152  coll = new Muon::RpcCoinDataCollection(collIDHash);
153  coll->setIdentifier(Identifier(pcoll.m_id));
154 
155  unsigned int pchanEnd = pchanIndex+pcoll.m_size;
156  unsigned int chanIndex = 0; // transient index
157 
158  coll->resize(pcoll.m_size);
159  // Fill with channels:
160  for (; pchanIndex < pchanEnd; ++ pchanIndex, ++chanIndex) {
161  const Muon::RpcCoinData_p1* pchan = &(persCont->m_prds[pchanIndex]);
162  Identifier clusId(pcoll.m_id + persCont->m_prdDeltaId[pchanIndex]);
163 
164  // The reason I need to do the following is that one collection can have several detector elements in, the collection hashes!=detector element hashes
165  IdentifierHash deIDHash;
166  int result = m_RpcId->get_detectorElement_hash(clusId, deIDHash);
167  if (result) log << MSG::WARNING << " Muon::RpcCoinDataContainerCnv_p1::persToTrans: problem converting Identifier to DE hash "<<endmsg;
168  const MuonGM::RpcReadoutElement* detEl =
169  m_muonDetMgr->getRpcReadoutElement(deIDHash);
170 
171  auto chan = std::make_unique<Muon::RpcCoinData>
172  (chanCnv.createRpcCoinData (pchan,
173  clusId,
174  detEl,
175  log));
176 
177  chan->setHashAndIndex(collIDHash, chanIndex);
178  (*coll)[chanIndex] = std::move(chan);
179  }
180 
181  // register the PRD 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  << coll->identify().get_compact() << ", added to Identifiable container." << endmsg;
189  }
190  }
191 
192  log << MSG::DEBUG << " *** Reading Muon::MuonCoinDataCollection<RpcCoinData>" << endmsg;
193 
194 }
195 
196 //================================================================
198 {
199  if(!m_isInitialized) {
200  if (this->initialize(log) != StatusCode::SUCCESS) {
201  log << MSG::FATAL << "Could not initialize RpcCoinDataContainerCnv_p1 " << endmsg;
202  return nullptr;
203  }
204  }
205  std::unique_ptr<Muon::RpcCoinDataContainer> trans(new Muon::RpcCoinDataContainer(m_RpcId->module_hash_max()));
206  persToTrans(persObj, trans.get(), log);
207  return(trans.release());
208 }
209 
210 
RpcCoinDataContainer.h
Muon::RpcCoinDataContainerCnv_p1::m_muonDetMgr
const MuonGM::MuonDetectorManager * m_muonDetMgr
Definition: RpcCoinDataContainerCnv_p1.h:44
RpcCoinDataContainerCnv_p1.h
get_generator_info.result
result
Definition: get_generator_info.py:21
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_Container_p2::m_prds
std::vector< PRD > m_prds
Definition: MuonPRD_Container_p2.h:31
RpcCoinData_p1.h
initialize
void initialize()
Definition: run_EoverP.cxx:894
Muon::MuonCoinDataCollection
Definition: MuonCoinDataCollection.h:25
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::RpcCoinDataContainerCnv_p1::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: RpcCoinDataContainerCnv_p1.cxx:125
Muon::MuonCoinDataCollection::identify
Identifier identify() const
RpcCoinData.h
Muon::RpcCoinData
Definition: RpcCoinData.h:25
RpcIdHelper.h
Muon::RpcCoinData_p1
Persistent representation of the transient Muon::RpcCoinData class.
Definition: RpcCoinData_p1.h:24
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
RpcCoinDataCnv_p1::createRpcCoinData
static Muon::RpcCoinData createRpcCoinData(const Muon::RpcCoinData_p1 *persObj, const Identifier &id, const MuonGM::RpcReadoutElement *detEl, MsgStream &log)
Definition: RpcCoinDataCnv_p1.cxx:16
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:216
Muon::MuonPRD_Collection_p2::m_size
unsigned short m_size
Collection size into master collection Note I use a short.
Definition: MuonPRD_Collection_p2.h:51
Muon::RpcCoinDataContainerCnv_p1::m_isInitialized
bool m_isInitialized
Definition: RpcCoinDataContainerCnv_p1.h:45
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
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
Muon::RpcCoinDataCollection
MuonCoinDataCollection< RpcCoinData > RpcCoinDataCollection
Definition: RpcCoinDataCollection.h:13
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::MuonPRD_Collection_p2
Class to hold the persistent representation of MuonPRD_Collection.
Definition: MuonPRD_Collection_p2.h:22
MuonCoinDataContainer_p1.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::MuonPRD_Container_p2::m_collections
std::vector< MuonPRD_Collection_p2 > m_collections
Definition: MuonPRD_Container_p2.h:29
RpcCoinDataCnv_p1
Definition: RpcCoinDataCnv_p1.h:23
DataPool.h
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
Muon::RpcCoinDataContainerCnv_p1::m_RpcId
const RpcIdHelper * m_RpcId
Definition: RpcCoinDataContainerCnv_p1.h:42
DataVector< CoinDataT >::resize
void resize(size_type sz)
Resizes the collection to the specified number of elements.
Muon::MuonCoinDataContainer
Definition: MuonCoinDataContainer.h:32
Muon::MuonPRD_Container_p2
Class to contain the Muon Prep Raw Data.
Definition: MuonPRD_Container_p2.h:26
Muon::MuonPRD_Collection_p2::m_hashId
unsigned int m_hashId
Hash Identifier of this collection.
Definition: MuonPRD_Collection_p2.h:46
MuonDetectorManager.h
Muon::MuonCoinDataCollection::identifyHash
IdentifierHash identifyHash() const
Muon::MuonPRD_Container_p2::m_prdDeltaId
std::vector< unsigned short > m_prdDeltaId
The delta identifiers of the PRD i.e.
Definition: MuonPRD_Container_p2.h:33
Muon::RpcCoinDataContainerCnv_p1::createTransient
virtual TRANS * createTransient(const PERS *persObj, MsgStream &log)
Definition: RpcCoinDataContainerCnv_p1.cxx:197
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Muon::RpcCoinDataContainerCnv_p1::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: RpcCoinDataContainerCnv_p1.cxx:69
Muon::MuonCoinDataCollection::setIdentifier
void setIdentifier(Identifier id)
RpcCoinDataCnv_p1.h
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py: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.
Muon::RpcCoinDataContainerCnv_p1::initialize
StatusCode initialize(MsgStream &log)
Definition: RpcCoinDataContainerCnv_p1.cxx:27
StoreGateSvc.h
DataVector< CoinDataT >::size
size_type size() const noexcept
Returns the number of elements in the collection.
RpcCoinDataCnv_p1::transToPers
void transToPers(const Muon::RpcCoinData *transObj, Muon::RpcCoinData_p1 *persObj, MsgStream &log)
Definition: RpcCoinDataCnv_p1.cxx:63
Muon::MuonPRD_Collection_p2::m_id
unsigned int m_id
Identifier of this collection.
Definition: MuonPRD_Collection_p2.h:43