ATLAS Offline Software
Loading...
Searching...
No Matches
MuonRdoContainerCnv.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Gaudi
6#include "GaudiKernel/StatusCode.h"
7#include "GaudiKernel/MsgStream.h"
8
9// Athena
10#include "StoreGate/StoreGateSvc.h"
11
12#include <memory>
13
14template <class T>
15MuonRdoContainerCnv<T>::MuonRdoContainerCnv(ISvcLocator* svcloc)
16 : T_AthenaPoolCustCnv<T, DataVector<typename T::IDENTIFIABLE> >::T_AthenaPoolCustCnv(svcloc),
17 m_colV(SG::VIEW_ELEMENTS), // Must create DataVector that does NOT own elements
18 m_storeGate(0)
19{}
20
21
22template <class T>
23MuonRdoContainerCnv<T>::~MuonRdoContainerCnv()
24{}
25
26
27template <class T>
28StatusCode MuonRdoContainerCnv<T>::initialize()
29{
30 // Call base clase initialize
31 if (!AthenaPoolConverter::initialize().isSuccess()) {
32 return StatusCode::FAILURE;
33 }
34
35 // Get the messaging service, print where you are
36 MsgStream log(this->msgSvc(), "MuonRdoContainerCnv");
37 log << MSG::INFO << "MuonRdoContainerCnv::initialize()" << endmsg;
38
39 // get StoreGate service
40 StatusCode sc=this->service("StoreGateSvc",m_storeGate);
41 if (sc.isFailure())
42 {
43 log << MSG::FATAL << "StoreGate service not found !" << endmsg;
44 return StatusCode::FAILURE;
45 }
46
47 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Converter initialized" << endmsg;
48
49 return StatusCode::SUCCESS;
50}
51
52
53template <class T>
54StatusCode MuonRdoContainerCnv<T>::transToPers(T* rdoC, DataVector<typename T::IDENTIFIABLE>*& persObj)
55{
56 MsgStream log(this->msgSvc(), "MuonRdoContainerCnv" );
57
58 // Copy RDOs to vector
59 m_colV.clear();
60
61 // loop over collections
62 int iColl = 0;
63 typename T::const_iterator it_Coll = rdoC->begin() ;
64 typename T::const_iterator it_CollE = rdoC->end() ;
65 for (; it_Coll != it_CollE; ++it_Coll)
66 {
67 ++iColl;
68 COLLECTION_t *col = const_cast<COLLECTION_t *> (&(**it_Coll));
69 m_colV.push_back(col);
70 }
71
72 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Write RDO vector, size " << iColl << endmsg;
73
74 persObj = &m_colV;
75
76 return StatusCode::SUCCESS;
77}
78
79
80template <class T>
81StatusCode MuonRdoContainerCnv<T>::persToTrans(T*& rdoC, DataVector<typename T::IDENTIFIABLE>* colV)
82{
83 MsgStream log(this->msgSvc(), "MuonRdoContainerCnv" );
84
85 // create the IdentifiableContainer to contain the collections
86 rdoC = new T;
87
88 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Read RDO vector, size " << colV->size()
89 << endmsg;
90
91 // empty vector - just return
92 if (colV->size() == 0)
93 {
94 //delete colV;
95 return StatusCode::SUCCESS;
96 }
97
98 // loop over collections
99 typename COLL_vector::const_iterator it_Coll = colV->begin();
100 typename COLL_vector::const_iterator it_CollE = colV->end();
101 for (; it_Coll != it_CollE; ++it_Coll)
102 {
103 const COLLECTION_t *col = *it_Coll;
104
105 // register the rdo collection in IDC
106 typename COLLECTION_t::ID id_coll = col->identify();
107 const typename T::KEY key_rdo= rdoC->key(id_coll);
108 StatusCode sc=rdoC->addCollection(col,id_coll);
109 if (sc.isFailure())
110 {
111 log << MSG::FATAL << "RDOs could not be recorded in IDC"
112 << endmsg;
113 //delete colV;
114 return StatusCode::FAILURE;
115 }
116 else
117 {
118 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "RDOs " << key_rdo << " recorded in IDC"
119 << endmsg;
120 }
121 }
122
123 //delete colV;
124 return StatusCode::SUCCESS;
125}
126