ATLAS Offline Software
RpcPadContainerCnv_p2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "MuonRDO/RpcPad.h"
11 #include "RpcPadCnv_p1.h"
12 #include "GaudiKernel/Bootstrap.h"
13 #include "GaudiKernel/StatusCode.h"
14 #include "GaudiKernel/Service.h"
15 #include "GaudiKernel/MsgStream.h"
16 #include "StoreGate/StoreGateSvc.h"
17 #include "AthAllocators/DataPool.h"
18 
20  m_isInitialized(false){
21 }
22 
23 
25 
26  // Do not initialize again:
27  m_isInitialized=true;
28 
29  // Get the helper from the detector store
30  ISvcLocator* svcLocator = Gaudi::svcLocator();
32  StatusCode sc = svcLocator->service("DetectorStore", detStore);
33  if (sc.isFailure()) {
34  log << MSG::FATAL << "DetectorStore service not found !" << endmsg;
35  return StatusCode::FAILURE;
36  } else {
37  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Found DetectorStore." << endmsg;
38  }
39 
40  sc = detStore->retrieve(m_rpcIdHelper);
41  if (sc.isFailure()) {
42  log << MSG::FATAL << "Could not get ID helper !" << endmsg;
43  return StatusCode::FAILURE;
44  }
45  else log<<MSG::DEBUG<<" got RpcIdHelper"<<endmsg;
46 
47  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized." << endmsg;
48  return sc;
49 }
50 
51 void RpcPadContainerCnv_p2::transToPers(const RpcPadContainer* transCont, RpcPadContainer_p2* persCont, MsgStream &log)
52 {
53 
54  typedef RpcPadContainer TRANS;
55 
56  RpcPadCnv_p1 cnv;
57  TRANS::const_iterator it_Coll = transCont->begin();
58  TRANS::const_iterator it_CollEnd = transCont->end();
59  unsigned int collIndex;
60 
61  int numColl = transCont->numberOfCollections();
62  persCont->m_pads.resize(numColl); log << MSG::DEBUG << " Preparing " << persCont->m_pads.size() << "Collections" << endmsg;
63 
64  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
65  RpcPad_p1* pcoll = &( persCont->m_pads[collIndex] );
66  cnv.transToPers( &(**it_Coll), pcoll , log);
67  }
68  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing RpcPadContainer ***" << endmsg;
69 }
70 
71 void RpcPadContainerCnv_p2::persToTrans(const RpcPadContainer_p2* persCont, RpcPadContainer* transCont, MsgStream &log)
72 {
73  RpcPadCnv_p1 cnv;
74 
75  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_pads.size() << "Collections" << endmsg;
76  for (unsigned int icoll = 0; icoll < persCont->m_pads.size(); ++icoll) {
77 
78  RpcPad* coll = new RpcPad;
79  cnv.persToTrans( &( persCont->m_pads[icoll]), coll, log);
80  // another check - see if already added
81  const auto *ptr = transCont->indexFindPtr(coll->identifyHash());
82  if (ptr!=nullptr ) {
83  log << MSG::WARNING<<"Collection with hash="<<coll->identifyHash()<<" already exists in container (with "<<ptr->size()<<" elements). "
84  << "Will therefore DISCARD this collection which has "<<coll->size()<<" elements)!"<<endmsg;
85  delete coll;
86  } else {
87  StatusCode sc = transCont->addCollection(coll, coll->identifyHash());
88  if (sc.isFailure()) {
89  log << MSG::WARNING<<"Could not add collection with hash="<<coll->identifyHash()
90  <<" to IDC which has hash max of "<<transCont->size()<<" (PadHashFunction gives "<<m_rpcIdHelper->module_hash_max()<<endmsg;
91  throw std::runtime_error("Failed to add collection to ID Container. Hash = "+std::to_string(coll->identifyHash()));
92  }
93  }
94  }
95 
96  log << MSG::DEBUG << " *** Reading RpcPadContainer" << endmsg;
97 }
98 
99 
100 
101 //================================================================
103 {
104  if(!m_isInitialized) {
105  if (this->initialize(log) != StatusCode::SUCCESS) {
106  log << MSG::FATAL << "Could not initialize RpcPadContainerCnv_p2 " << endmsg;
107  return nullptr;
108  }
109  }
110  std::unique_ptr<RpcPadContainer> trans(new RpcPadContainer(m_rpcIdHelper->module_hash_max()));
111 
112  persToTrans(persObj, trans.get(), log);
113  return(trans.release());
114 }
115 
116 
RpcPadContainerCnv_p2::m_isInitialized
bool m_isInitialized
Definition: RpcPadContainerCnv_p2.h:34
RpcPadContainer
Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current Athena::TPCnvVers::Current Athena::TPCnvVers::Current RpcPadContainer
Definition: MuonEventAthenaPoolTPCnv.cxx:156
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
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
RpcPadContainerCnv_p2::initialize
StatusCode initialize(MsgStream &log)
Definition: RpcPadContainerCnv_p2.cxx:24
RpcPad
Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current Athena::TPCnvVers::Current RpcPad
Definition: MuonEventAthenaPoolTPCnv.cxx:146
IdentifiableContainerMT::size
size_t size() const
Duplicate of fullSize for backwards compatability.
Definition: IdentifiableContainerMT.h:209
RpcPadCnv_p1.h
RpcPadContainerCnv_p2::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: RpcPadContainerCnv_p2.cxx:51
RpcPadContainerCnv_p2::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: RpcPadContainerCnv_p2.cxx:71
RpcPad_p1
Definition: RpcPad_p1.h:14
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
RpcPad.h
RpcPadContainerCnv_p2::m_rpcIdHelper
const RpcIdHelper * m_rpcIdHelper
Definition: RpcPadContainerCnv_p2.h:35
RpcPadContainer_p2.h
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
RpcPadCnv_p1
Definition: RpcPadCnv_p1.h:26
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
RpcPad_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
DataPool.h
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
RpcPad::identifyHash
IdentifierHash identifyHash() const
Returns the OFFLINE identifier hash for this collection.
Definition: RpcPad.h:103
RpcPad
Definition: RpcPad.h:21
MuonIdHelper::module_hash_max
size_type module_hash_max() const
the maximum hash value
Definition: MuonIdHelper.cxx:752
RpcPadCnv_p1::transToPers
virtual void transToPers(const RpcPad *transColl, RpcPad_p1 *persColl, MsgStream &log)
Definition: RpcPadCnv_p1.cxx:12
RpcPadContainerCnv_p2::createTransient
virtual RpcPadContainer * createTransient(const RpcPadContainer_p2 *persObj, MsgStream &log)
Definition: RpcPadContainerCnv_p2.cxx:102
IdentifiableContainerMT::indexFindPtr
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
Definition: IdentifiableContainerMT.h:292
RpcPadContainerCnv_p2::RpcPadContainerCnv_p2
RpcPadContainerCnv_p2()
Definition: RpcPadContainerCnv_p2.cxx:19
RpcPadContainer_p2
Definition: RpcPadContainer_p2.h:18
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
RpcPadContainer.h
RpcPadContainerCnv_p2.h
RpcPadContainerCnv_p2::TRANS
RpcPadContainer TRANS
Definition: RpcPadContainerCnv_p2.h:27
StoreGateSvc.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
RpcPadContainer_p2::m_pads
std::vector< RpcPad_p1 > m_pads
Definition: RpcPadContainer_p2.h:20
RpcPadCnv_p1::persToTrans
virtual void persToTrans(const RpcPad_p1 *persColl, RpcPad *transColl, MsgStream &log)
Definition: RpcPadCnv_p1.cxx:28
RpcPadContainer
Use IdentifiableContainer with RpcPad.
Definition: RpcPadContainer.h:23