ATLAS Offline Software
Loading...
Searching...
No Matches
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"
19
21 m_isInitialized(false),
22 m_rpcCabKey("RpcCablingCondData") {
23}
24
25
26StatusCode RpcPadContainerCnv_p1::initialize(MsgStream &log) {
27
28 m_isInitialized=true;
29
30 StatusCode sc = m_rpcCabKey.initialize();
31
32 log << MSG::DEBUG << "Converter initialized." << endmsg;
33
34 return sc;
35}
36
37void 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
58void 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
#define endmsg
static Double_t sc
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
size_type size() const noexcept
Returns the number of elements in the collection.
const_iterator end() const
return const_iterator for end of container
virtual size_t numberOfCollections() const override final
return number of collections
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,...
size_t size() const
Duplicate of fullSize for backwards compatability.
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,...
const_iterator begin() const
return const_iterator for first entry
This is a "hash" representation of an Identifier.
virtual void persToTrans(const RpcPad_p1 *persColl, RpcPad *transColl, MsgStream &log)
Converts vector of PERS::value_type objects to vector of TRANS::value_type objects,...
virtual void transToPers(const RpcPad *transColl, RpcPad_p1 *persColl, MsgStream &log)
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
StatusCode initialize(MsgStream &log)
SG::ReadCondHandleKey< RpcCablingCondData > m_rpcCabKey
virtual RpcPadContainer * createTransient(const RpcPadContainer_p1 *persObj, MsgStream &log) override
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log) override
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log) override
Use IdentifiableContainer with RpcPad.
Identifier identify() const
Definition RpcPad.h:100
IdentifierHash identifyHash() const
Returns the OFFLINE identifier hash for this collection.
Definition RpcPad.h:103
IdentifierHash m_idHash
Definition RpcPad.h:128
void initialize()