ATLAS Offline Software
RpcPadContainerCnv_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 
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"
19 
21  m_isInitialized(false),
22  m_rpcCabKey("RpcCablingCondData") {
23 }
24 
25 
27 
28  m_isInitialized=true;
29 
31 
32  log << MSG::DEBUG << "Converter initialized." << endmsg;
33 
34  return sc;
35 }
36 
37 void RpcPadContainerCnv_p1::transToPers(const RpcPadContainer* transCont, RpcPadContainer_p1* persCont, MsgStream &log)
38 {
39 
40  typedef RpcPadContainer TRANS;
41 
42  RpcPadCnv_p1 cnv;
43  TRANS::const_iterator it_Coll = transCont->begin();
44  TRANS::const_iterator it_CollEnd = transCont->end();
45  unsigned int collIndex;
46 
47  int numColl = transCont->numberOfCollections();
48  persCont->resize(numColl); log << MSG::DEBUG << " Preparing " << persCont->size() << "Collections" << endmsg;
49 
50  for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
51  // Add in new collection
52  RpcPad_p1* pcoll = &( (*persCont)[collIndex] );
53  cnv.transToPers( &(**it_Coll), pcoll , log);
54  }
55  log << MSG::DEBUG << " *** Writing RpcPadContainer ***" << endmsg;
56 }
57 
58 void RpcPadContainerCnv_p1::persToTrans(const RpcPadContainer_p1* persCont, RpcPadContainer* transCont, MsgStream &log)
59 {
60  SG::ReadCondHandle<RpcCablingCondData> rpcCab(m_rpcCabKey, Gaudi::Hive::currentContext());
61  const RpcCablingCondData* rpcCabling=*rpcCab;
62  if (!rpcCab.isValid()||!rpcCabling) {
63  log << MSG::FATAL << m_rpcCabKey.fullKey() << " is not available." << endmsg;
64  return;
65  }
66  RpcPadCnv_p1 cnv;
67 
68  log << MSG::DEBUG << " Reading " << persCont->size() << "Collections" << endmsg;
69  for (unsigned int icoll = 0; icoll < persCont->size(); ++icoll) {
70 
71  RpcPad* coll = new RpcPad;
72  cnv.persToTrans( &( (*persCont)[icoll]), coll, log);
73 
74  int temp = rpcCabling->operator()(coll->identify());
75  if (temp==-1) {
76  coll->m_idHash = IdentifierHash();
77  log<<MSG::WARNING<<"get_hash failed - nothing else we can try!"<<endmsg;
78  } else{
79  coll->m_idHash = temp;
80  }
81 
82  // another check - see if already added
83  const auto *ptr = transCont->indexFindPtr(coll->identifyHash());
84  if (ptr!=nullptr ) {
85  log << MSG::WARNING<<"Collection with hash="<<coll->identifyHash()<<" already exists in container (with "<<ptr->size()<<" elements). "
86  << "Will therefore DISCARD this collection which has "<<coll->size()<<" elements)!"<<endmsg;
87  delete coll;
88  } else {
89  StatusCode sc = transCont->addCollection(coll, coll->identifyHash());
90  if (sc.isFailure()) {
91  log << MSG::WARNING<<"Could not add collection with hash="<<coll->identifyHash()
92  <<" to IDC which has hash max of "<<transCont->size()<<" (PadHashFunction gives "<<rpcCabling->max()<<")"<<endmsg;
93  throw std::runtime_error("Failed to add collection to ID Container. Hash = "+std::to_string(coll->identifyHash()));
94  }
95  }
96  }
97 
98  log << MSG::DEBUG << " *** Reading RpcPadContainer" << endmsg;
99 }
100 
101 
102 
103 //================================================================
105 {
106  if(!m_isInitialized) {
107  if (this->initialize(log) != StatusCode::SUCCESS) {
108  log << MSG::FATAL << "Could not initialize RpcPadContainerCnv_p1 " << endmsg;
109  return nullptr;
110  }
111  }
112  SG::ReadCondHandle<RpcCablingCondData> rpcCab(m_rpcCabKey, Gaudi::Hive::currentContext());
113  const RpcCablingCondData* rpcCabling=*rpcCab;
114  if (!rpcCab.isValid()||!rpcCabling) {
115  log << MSG::FATAL << m_rpcCabKey.fullKey() << " is not available." << endmsg;
116  return nullptr;
117  }
118  std::unique_ptr<RpcPadContainer> trans(new RpcPadContainer(rpcCabling->max()));
119  persToTrans(persObj, trans.get(), log);
120  return(trans.release());
121 }
122 
123 
RpcPad::identify
Identifier identify() const
Definition: RpcPad.h:100
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
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
RpcPadContainerCnv_p1::initialize
StatusCode initialize(MsgStream &log)
Definition: RpcPadContainerCnv_p1.cxx:26
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
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
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
RpcPadContainerCnv_p1::m_rpcCabKey
SG::ReadCondHandleKey< RpcCablingCondData > m_rpcCabKey
Definition: RpcPadContainerCnv_p1.h:36
RpcPadCnv_p1.h
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
RpcPadContainerCnv_p1::transToPers
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log) override
Definition: RpcPadContainerCnv_p1.cxx:37
RpcPad_p1
Definition: RpcPad_p1.h:14
ReadCondHandle.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
RpcCablingCondData
Definition: RpcCablingCondData.h:21
RpcPad.h
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:213
RpcCablingCondData::max
int max() const
Definition: RpcCablingCondData.cxx:126
RpcPad::m_idHash
IdentifierHash m_idHash
Definition: RpcPad.h:128
RpcPadContainerCnv_p1::TRANS
RpcPadContainer TRANS
Definition: RpcPadContainerCnv_p1.h:28
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
RpcPadContainerCnv_p1::persToTrans
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log) override
Definition: RpcPadContainerCnv_p1.cxx:58
RpcPad_p1.h
RpcPadContainer_p1.h
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:239
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
RpcPadContainerCnv_p1::m_isInitialized
bool m_isInitialized
Definition: RpcPadContainerCnv_p1.h:35
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
RpcPad::identifyHash
IdentifierHash identifyHash() const
Returns the OFFLINE identifier hash for this collection.
Definition: RpcPad.h:103
RpcPad
Definition: RpcPad.h:21
RpcPadCnv_p1::transToPers
virtual void transToPers(const RpcPad *transColl, RpcPad_p1 *persColl, MsgStream &log)
Definition: RpcPadCnv_p1.cxx:12
RpcPadContainerCnv_p1::RpcPadContainerCnv_p1
RpcPadContainerCnv_p1()
Definition: RpcPadContainerCnv_p1.cxx:20
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
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
RpcPadContainer.h
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
StoreGateSvc.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
RpcPadContainerCnv_p1.h
RpcPadCnv_p1::persToTrans
virtual void persToTrans(const RpcPad_p1 *persColl, RpcPad *transColl, MsgStream &log)
Definition: RpcPadCnv_p1.cxx:28
RpcPadContainerCnv_p1::createTransient
virtual RpcPadContainer * createTransient(const RpcPadContainer_p1 *persObj, MsgStream &log) override
Definition: RpcPadContainerCnv_p1.cxx:104
RpcPadContainer
Use IdentifiableContainer with RpcPad.
Definition: RpcPadContainer.h:23
RpcPadContainer_p1
Definition: RpcPadContainer_p1.h:19