ATLAS Offline Software
Loading...
Searching...
No Matches
xAODCnvSvc.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5*/
6
7// xAODCnvSvc.cxx
8// Implementation file for class Athena::xAODCnvSvc
9// Author: Johannes Elmsheuser, Will Buttinger
11
12// AthenaRootComps includes
13#include "xAODCnvSvc.h"
14#include "xAODCnv.h"
15#include "RootBranchAddress.h"
16
17// STL includes
18
19// FrameWork includes
20#include "GaudiKernel/GenericAddress.h"
21#include "GaudiKernel/IRegistry.h"
22#include "Gaudi/Property.h"
23#include "StorageSvc/DbType.h"
24
25// ROOT includes
26#include "TFile.h"
27
28namespace Athena {
29
31// Public methods:
33
34// Constructors
36xAODCnvSvc::xAODCnvSvc( const std::string& name,
37 ISvcLocator* pSvcLocator ) :
38 base_class( name, pSvcLocator, pool::ROOT_StorageType.type() )
39{
40}
41
42// Destructor
46
47// Athena Service's Hooks
49StatusCode
51{
52 ATH_MSG_DEBUG ("Initializing " << name() << "...");
53
54 return AthCnvSvc::initialize();
55}
56
57StatusCode
59{
60 ATH_MSG_DEBUG ("Finalizing " << name() << "...");
61
62 return AthCnvSvc::finalize();
63}
64
67StatusCode
68xAODCnvSvc::updateServiceState(IOpaqueAddress* pAddress)
69{
70 ATH_MSG_DEBUG("updateServiceState(" << pAddress << ")...");
71 if (pAddress) {
72 return dynamic_cast<GenericAddress*>(pAddress)
73 ? StatusCode::SUCCESS
74 : StatusCode::FAILURE;
75 }
76 return StatusCode::FAILURE;
77}
78
83StatusCode
84xAODCnvSvc::createObj(IOpaqueAddress* pAddress, DataObject*& refpObject)
85{
86 ATH_MSG_DEBUG("-->createObj(" << pAddress->par()[0] << "/" << pAddress->par()[1]
87 << ", " << refpObject << ")...");
88 GenericAddress *addr = dynamic_cast<GenericAddress*>(pAddress);
89 if (!addr) {
90 ATH_MSG_DEBUG(pAddress->par()[0] << "/" << pAddress->par()[1]
91 << " is NOT a GenericAddress!");
92 return StatusCode::FAILURE;
93 }
94 ATH_MSG_DEBUG(" par: " << pAddress->par()[0] << "/" << pAddress->par()[1]
95 << endmsg <<
96 " ipar: " << *pAddress->ipar());
97 return AthCnvSvc::createObj(pAddress, refpObject);
98}
99
105StatusCode
106xAODCnvSvc::createRep(DataObject* pObject, IOpaqueAddress*& refpAddress)
107{
108 ATH_MSG_DEBUG("::createRep(" << refpAddress << ", " << pObject << ")...");
109 //std::cerr << "::NCS::createRep(" << this->name() << ", " << pObject << ")...\n";
110 if (0==pObject) {
111 ATH_MSG_ERROR("::createRep: received null ptr to DataObject");
112 return StatusCode::FAILURE;
113 }
114 return ::AthCnvSvc::createRep(pObject, refpAddress);
115}
116
122StatusCode
123xAODCnvSvc::fillRepRefs(IOpaqueAddress* pAddress, DataObject* pObject)
124{
125 ATH_MSG_DEBUG("::fillRepRefs(" << pAddress << ", " << pObject << ")...");
126 if (0==pAddress || 0==pObject) {
127 ATH_MSG_ERROR("::fillRepRefs: null ptr received! (paddr=" << pAddress
128 << ", pobj=" << pObject << ")");
129 return StatusCode::FAILURE;
130 }
131 return ::AthCnvSvc::fillRepRefs(pAddress, pObject);
132}
133
138StatusCode
139xAODCnvSvc::connectOutput(const std::string& outputConnectionSpec,
140 const std::string& openMode)
141{
142 ATH_MSG_DEBUG("::connectOutput("
143 << outputConnectionSpec << ", "
144 << openMode << ")");
145 // std::cerr << "::connectOutput(" << outputConnectionSpec << ", openmode="
146 // << openMode << ")...\n";
147 TFile *f = TFile::Open(outputConnectionSpec.c_str(), "recreate");
148 if (f == 0) {
149 return StatusCode::FAILURE;
150 }
151
152 return StatusCode::SUCCESS;
153}
154
158StatusCode
159xAODCnvSvc::connectOutput(const std::string& outputConnectionSpec)
160{
161 ATH_MSG_DEBUG("::connectOutput("
162 << outputConnectionSpec << ")");
163 // std::cerr << "::connectOutput(" << outputConnectionSpec << ")...\n";
164 TFile *f = TFile::Open(outputConnectionSpec.c_str(), "recreate");
165 if (f == 0) {
166 return StatusCode::FAILURE;
167 }
168 return StatusCode::SUCCESS;
169}
170
172StatusCode
173xAODCnvSvc::commitOutput(const std::string& outputConnectionSpec,
174 bool doCommit)
175{
176 ATH_MSG_DEBUG("::commitOutput(" << outputConnectionSpec
177 << ", " << doCommit << ")...");
178 return StatusCode::SUCCESS;
179}
180
181
182
184
185
193StatusCode
195 const CLID& clid,
196 const std::string* par,
197 const unsigned long* ip,
198 IOpaqueAddress*& refpAddress)
199{
200 ATH_MSG_DEBUG("::createAddress(" << svcType << ", " << clid
201 << ", " << par << ", " << ip << ", " << refpAddress
202 << ")...");
203 return ::AthCnvSvc::createAddress(svcType, clid, par, ip, refpAddress);
204}
205
209StatusCode
210xAODCnvSvc::convertAddress(const IOpaqueAddress* pAddress,
211 std::string& refAddress)
212{
213 ATH_MSG_DEBUG("::convertAddress(" << pAddress << ", "
214 << refAddress << ")...");
215 if (pAddress) {
216 refAddress = *pAddress->par();
217 return StatusCode::SUCCESS;
218 }
219 ATH_MSG_ERROR("::convertAddress: null pointer to IOpaqueAddress !");
220 return StatusCode::FAILURE;
221}
222
228StatusCode
230 const CLID& clid,
231 const std::string& refAddress,
232 IOpaqueAddress*& refpAddress)
233{
234 ATH_MSG_VERBOSE("::createAddress(" << svcType << ", " << clid
235 << ", " << refAddress << ", " << refpAddress
236 << ")...");
237 if (svcType != pool::ROOT_StorageType.type()) {
238 ATH_MSG_ERROR("::createAddress: svcType != root-type");
239 ATH_MSG_ERROR(" svcType = [" << svcType << "]");
240 ATH_MSG_ERROR(" root-type = [" << pool::ROOT_StorageType.type() << "]");
241 return StatusCode::FAILURE;
242 }
243 refpAddress = new GenericAddress(pool::ROOT_StorageType.type(), clid, refAddress);
244 return StatusCode::SUCCESS;
245}
246
247
249// Const methods:
251
253// Non-const methods:
255
257// Protected methods:
259
261IConverter*
263 const CLID& clid,
264 const ICnvFactory* fac)
265{
266 ATH_MSG_VERBOSE("xAODCnvSvc::createConverter(" << typ << ", " << clid
267 << ", " << fac << ")...");
268 IConverter* cnv = new Athena::xAODCnv(clid, serviceLocator());
269 ATH_MSG_VERBOSE("xAODCnvSvc::createConverter 2");
270 if (cnv) {
271 ATH_MSG_VERBOSE("xAODCnvSvc::createConverter 3");
272 return cnv;
273 }
274 ATH_MSG_VERBOSE("xAODCnvSvc::createConverter 4");
275 return AthCnvSvc::createConverter(typ, clid, fac);
276}
277
279// Const methods:
281
283// Non-const methods:
285
286} //> end namespace Athena
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
uint32_t CLID
The Class ID type.
virtual IConverter * createConverter(long typ, const CLID &clid, const ICnvFactory *fac)
Create new Converter using factory.
virtual StatusCode finalize() override
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject) override
Implementation of IConverter: Create the transient representation of an object.
virtual StatusCode initialize() override
Gaudi Service Implementation.
virtual StatusCode initialize()
Gaudi Service Implementation.
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject)
Implementation of IConverter: Create the transient representation of an object from persistent state.
virtual StatusCode connectOutput(const std::string &outputConnectionSpec, const std::string &openMode)
Connect the output connection specification to the service with open mode.
virtual StatusCode convertAddress(const IOpaqueAddress *pAddress, std::string &refAddress)
Convert address to string form.
virtual IConverter * createConverter(long typ, const CLID &clid, const ICnvFactory *fac)
Create new Converter using factory (override AthCnvSvc::createConverter).
virtual StatusCode commitOutput(const std::string &outputConnectionSpec, bool doCommit)
Commit pending output.
virtual StatusCode updateServiceState(IOpaqueAddress *pAddress)
IConversionSvc and IConverter interfaces
virtual ~xAODCnvSvc()
Destructor:
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)
Implementation of IConverter: Resolve the references of the converted object.
virtual StatusCode createAddress(long svcType, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)
IAddressCreator interfaces
xAODCnvSvc()
Default constructor:
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Implementation of IConverter: Convert the transient object to the requested representation.
virtual StatusCode finalize()
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
Definition AthDsoUtils.h:10
Framework include files.
Definition libname.h:15
static const DbType ROOT_StorageType
Definition DbType.h:85