Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
RpcCoinDataContainerCnv_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 
5 /* Takashi Kubota - June 30, 2008 */
10 
11 
16 
17 // Gaudi
18 #include "GaudiKernel/ISvcLocator.h"
19 #include "GaudiKernel/Bootstrap.h"
20 
21 // Athena
23 #include "AthAllocators/DataPool.h"
24 #include "StoreGate/StoreGateSvc.h"
25 
26 
28  // Do not initialize again:
29  m_isInitialized=true;
30 
31  // get DetectorStore service
32  SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
33  CHECK( detStore.isValid() );
34 
35  // Get the helper from the detector store
36  CHECK( detStore->retrieve(m_RpcId) );
37 
38  CHECK( detStore->retrieve(m_muonDetMgr) );
39 
40 
41  log << MSG::DEBUG << "Converter initialized." << endmsg;
42  return StatusCode::SUCCESS;
43 }
44 
46 {
47  // The transient model has a container holding collections and the
48  // collections hold channels.
49  //
50  // The persistent model flattens this so that the persistent
51  // container has two vectors:
52  // 1) all collections, and
53  // 2) all PRD
54  //
55  // The persistent collections, then only maintain indexes into the
56  // container's vector of all channels.
57  //
58  // So here we loop over all collection and add their channels
59  // to the container's vector, saving the indexes in the
60  // collection.
61 
63 
64  RpcCoinDataCnv_p1 chanCnv;
65  TRANS::const_iterator it_Coll = transCont->begin();
66  TRANS::const_iterator it_CollEnd = transCont->end();
67  unsigned int pcollIndex; // index to the persistent collection we're filling
68  unsigned int pcollBegin = 0; // index to start of persistent collection we're filling, in long list of persistent PRDs
69  unsigned int pcollEnd = 0; // index to end
70  int numColl = transCont->numberOfCollections();
71  persCont->m_collections.resize(numColl);
72  log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
73  for (pcollIndex = 0; it_Coll != it_CollEnd; ++pcollIndex, ++it_Coll) {
74  // Add in new collection
75  const Muon::MuonCoinDataCollection<RpcCoinData>& collection = (**it_Coll);
76  Muon::MuonPRD_Collection_p2& pcollection = persCont->m_collections[pcollIndex];
77 
78  pcollBegin = pcollEnd; // Next collection starts at end of previous one.
79  pcollEnd += collection.size();
80 
81  pcollection.m_hashId = collection.identifyHash();
82  pcollection.m_id = collection.identify().get_identifier32().get_compact();
83  pcollection.m_size = collection.size();
84 
85 
86  // Add in channels
87  persCont->m_prds.resize(pcollEnd);
88  persCont->m_prdDeltaId.resize(pcollEnd);
89  log << MSG::VERBOSE << "Reading collections with " << collection.size() << "PRDs " << endmsg;
90  for (unsigned int i = 0; i < collection.size(); ++i) {
91  unsigned int pchanIndex=i+pcollBegin;
92  const Muon::RpcCoinData* chan = collection[i];
93  Muon::RpcCoinData_p1* pchan = &(persCont->m_prds[pchanIndex]);
94  chanCnv.transToPers(chan, pchan, log);
95  persCont->m_prdDeltaId[pchanIndex]=chan->identify().get_identifier32().get_compact() - collection.identify().get_identifier32().get_compact(); //store delta identifiers, rather than full identifiers
96  }
97  }
98  log << MSG::DEBUG << " *** Writing Muon::RpcCoinDataContainer" << endmsg;
99 }
100 
102 {
103  // The transient model has a container holding collections and the
104  // collections hold channels.
105  //
106  // The persistent model flattens this so that the persistent
107  // container has two vectors:
108  // 1) all collections, and
109  // 2) all channels
110  //
111  // The persistent collections, then only maintain indexes into the
112  // container's vector of all channels.
113  //
114  // So here we loop over all collection and extract their channels
115  // from the vector.
116 
117 
119 
120  RpcCoinDataCnv_p1 chanCnv;
121  unsigned int pchanIndex(0); // position within persCont->m_prds. Incremented inside innermost loop
122  unsigned int pCollEnd = persCont->m_collections.size();
123  log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
124  for (unsigned int pcollIndex = 0; pcollIndex < pCollEnd; ++pcollIndex) {
125  const Muon::MuonPRD_Collection_p2& pcoll = persCont->m_collections[pcollIndex];
126  // Identifier collID= Identifier(idLast);
127  IdentifierHash collIDHash=IdentifierHash(pcoll.m_hashId);
128  coll = new Muon::RpcCoinDataCollection(collIDHash);
129  coll->setIdentifier(Identifier(pcoll.m_id));
130 
131  unsigned int pchanEnd = pchanIndex+pcoll.m_size;
132  unsigned int chanIndex = 0; // transient index
133 
134  coll->resize(pcoll.m_size);
135  // Fill with channels:
136  for (; pchanIndex < pchanEnd; ++ pchanIndex, ++chanIndex) {
137  const Muon::RpcCoinData_p1* pchan = &(persCont->m_prds[pchanIndex]);
138  Identifier clusId(pcoll.m_id + persCont->m_prdDeltaId[pchanIndex]);
139 
140  // The reason I need to do the following is that one collection can have several detector elements in, the collection hashes!=detector element hashes
141  IdentifierHash deIDHash;
142  int result = m_RpcId->get_detectorElement_hash(clusId, deIDHash);
143  if (result) log << MSG::WARNING << " Muon::RpcCoinDataContainerCnv_p1::persToTrans: problem converting Identifier to DE hash "<<endmsg;
144  const MuonGM::RpcReadoutElement* detEl =
145  m_muonDetMgr->getRpcReadoutElement(deIDHash);
146 
147  auto chan = std::make_unique<Muon::RpcCoinData>
148  (chanCnv.createRpcCoinData (pchan,
149  clusId,
150  detEl,
151  log));
152 
153  chan->setHashAndIndex(collIDHash, chanIndex);
154  (*coll)[chanIndex] = std::move(chan);
155  }
156 
157  // register the PRD collection in IDC with hash - faster addCollection
158  StatusCode sc = transCont->addCollection(coll, collIDHash);
159  if (sc.isFailure()) {
160  throw std::runtime_error("Failed to add collection to ID Container");
161  }
162  if (log.level() <= MSG::DEBUG) {
163  log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / "
164  << coll->identify().get_compact() << ", added to Identifiable container." << endmsg;
165  }
166  }
167 
168  log << MSG::DEBUG << " *** Reading Muon::MuonCoinDataCollection<RpcCoinData>" << endmsg;
169 
170 }
171 
172 //================================================================
174 {
175  if(!m_isInitialized) {
176  if (this->initialize(log) != StatusCode::SUCCESS) {
177  log << MSG::FATAL << "Could not initialize RpcCoinDataContainerCnv_p1 " << endmsg;
178  return nullptr;
179  }
180  }
181  std::unique_ptr<Muon::RpcCoinDataContainer> trans(new Muon::RpcCoinDataContainer(m_RpcId->module_hash_max()));
182  persToTrans(persObj, trans.get(), log);
183  return(trans.release());
184 }
185 
186 
RpcCoinDataContainer.h
Muon::RpcCoinDataContainerCnv_p1::m_muonDetMgr
const MuonGM::MuonDetectorManager * m_muonDetMgr
Definition: RpcCoinDataContainerCnv_p1.h:42
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:18
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_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
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.
MuonGM::RpcReadoutElement
An RpcReadoutElement corresponds to a single RPC module; therefore typicaly a barrel muon station con...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/RpcReadoutElement.h:55
Muon::RpcCoinDataContainerCnv_p1::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: RpcCoinDataContainerCnv_p1.cxx:101
Muon::MuonCoinDataCollection::identify
Identifier identify() const
RpcCoinData.h
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
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
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:213
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:43
lumiFormat.i
int i
Definition: lumiFormat.py:85
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
Muon::RpcCoinDataCollection
MuonCoinDataCollection< RpcCoinData > RpcCoinDataCollection
Definition: RpcCoinDataCollection.h:13
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: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::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:41
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
errorcheck.h
Helpers for checking error return status codes and reporting errors.
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:173
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
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:45
Muon::MuonCoinDataCollection::setIdentifier
void setIdentifier(Identifier id)
RpcCoinDataCnv_p1.h
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:13
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
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
Identifier
Definition: IdentifierFieldParser.cxx:14