ATLAS Offline Software
RpcPadContainerCnv_p2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "MuonRDO/RpcPad.h"
11 #include "RpcPadCnv_p1.h"
12 #include "GaudiKernel/StatusCode.h"
13 #include "GaudiKernel/MsgStream.h"
14 #include "StoreGate/StoreGateSvc.h"
15 #include "AthAllocators/DataPool.h"
17 
19  m_isInitialized(false){
20 }
21 
22 
24 
25  // Do not initialize again:
26  m_isInitialized=true;
27 
28  // Get the helper from the detector store
29  SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
30  CHECK( detStore.isValid() );
31  CHECK( detStore->retrieve(m_rpcIdHelper) );
32 
33  return StatusCode::SUCCESS;
34 }
35 
36 void RpcPadContainerCnv_p2::transToPers(const RpcPadContainer* transCont, RpcPadContainer_p2* persCont, MsgStream &log)
37 {
38 
39  typedef RpcPadContainer TRANS;
40 
41  RpcPadCnv_p1 cnv;
42  TRANS::const_iterator it_Coll = transCont->begin();
43  TRANS::const_iterator it_CollEnd = transCont->end();
44  unsigned int collIndex;
45 
46  int numColl = transCont->numberOfCollections();
47  persCont->m_pads.resize(numColl); log << MSG::DEBUG << " Preparing " << persCont->m_pads.size() << "Collections" << endmsg;
48 
49  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
50  RpcPad_p1* pcoll = &( persCont->m_pads[collIndex] );
51  cnv.transToPers( &(**it_Coll), pcoll , log);
52  }
53  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing RpcPadContainer ***" << endmsg;
54 }
55 
56 void RpcPadContainerCnv_p2::persToTrans(const RpcPadContainer_p2* persCont, RpcPadContainer* transCont, MsgStream &log)
57 {
58  RpcPadCnv_p1 cnv;
59 
60  if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_pads.size() << "Collections" << endmsg;
61  for (unsigned int icoll = 0; icoll < persCont->m_pads.size(); ++icoll) {
62 
63  RpcPad* coll = new RpcPad;
64  cnv.persToTrans( &( persCont->m_pads[icoll]), coll, log);
65  // another check - see if already added
66  const auto *ptr = transCont->indexFindPtr(coll->identifyHash());
67  if (ptr!=nullptr ) {
68  log << MSG::WARNING<<"Collection with hash="<<coll->identifyHash()<<" already exists in container (with "<<ptr->size()<<" elements). "
69  << "Will therefore DISCARD this collection which has "<<coll->size()<<" elements)!"<<endmsg;
70  delete coll;
71  } else {
72  StatusCode sc = transCont->addCollection(coll, coll->identifyHash());
73  if (sc.isFailure()) {
74  log << MSG::WARNING<<"Could not add collection with hash="<<coll->identifyHash()
75  <<" to IDC which has hash max of "<<transCont->size()<<" (PadHashFunction gives "<<m_rpcIdHelper->module_hash_max()<<endmsg;
76  throw std::runtime_error("Failed to add collection to ID Container. Hash = "+std::to_string(coll->identifyHash()));
77  }
78  }
79  }
80 
81  log << MSG::DEBUG << " *** Reading RpcPadContainer" << endmsg;
82 }
83 
84 
85 
86 //================================================================
88 {
89  if(!m_isInitialized) {
90  if (this->initialize(log) != StatusCode::SUCCESS) {
91  log << MSG::FATAL << "Could not initialize RpcPadContainerCnv_p2 " << endmsg;
92  return nullptr;
93  }
94  }
95  std::unique_ptr<RpcPadContainer> trans(new RpcPadContainer(m_rpcIdHelper->module_hash_max()));
96 
97  persToTrans(persObj, trans.get(), log);
98  return(trans.release());
99 }
100 
101 
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: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
RpcPadContainerCnv_p2::initialize
StatusCode initialize(MsgStream &log)
Definition: RpcPadContainerCnv_p2.cxx:23
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:206
RpcPadCnv_p1.h
RpcPadContainerCnv_p2::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
Definition: RpcPadContainerCnv_p2.cxx:36
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
RpcPadContainerCnv_p2::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
Definition: RpcPadContainerCnv_p2.cxx:56
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
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:213
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: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
DataPool.h
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
errorcheck.h
Helpers for checking error return status codes and reporting errors.
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:754
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:87
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:289
RpcPadContainerCnv_p2::RpcPadContainerCnv_p2
RpcPadContainerCnv_p2()
Definition: RpcPadContainerCnv_p2.cxx:18
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