ATLAS Offline Software
Loading...
Searching...
No Matches
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"
17
21
22
23StatusCode RpcPadContainerCnv_p2::initialize(MsgStream & /*log*/) {
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
36void 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
56void 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
#define endmsg
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
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
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,...
const RpcIdHelper * m_rpcIdHelper
virtual RpcPadContainer * createTransient(const RpcPadContainer_p2 *persObj, MsgStream &log)
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
StatusCode initialize(MsgStream &log)
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
std::vector< RpcPad_p1 > m_pads
Use IdentifiableContainer with RpcPad.
IdentifierHash identifyHash() const
Returns the OFFLINE identifier hash for this collection.
Definition RpcPad.h:103
void initialize()