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
24// ROOT includes
25#include "TFile.h"
26
27namespace Athena {
28
30// Public methods:
32
33// Constructors
35xAODCnvSvc::xAODCnvSvc( const std::string& name,
36 ISvcLocator* pSvcLocator ) :
37 base_class( name, pSvcLocator, POOL_ROOTTREE_StorageType )
38{
39}
40
41// Destructor
45
46// Athena Service's Hooks
48StatusCode
50{
51 ATH_MSG_DEBUG ("Initializing " << name() << "...");
52
53 return AthCnvSvc::initialize();
54}
55
56StatusCode
58{
59 ATH_MSG_DEBUG ("Finalizing " << name() << "...");
60
61 return AthCnvSvc::finalize();
62}
63
66StatusCode
67xAODCnvSvc::updateServiceState(IOpaqueAddress* pAddress)
68{
69 ATH_MSG_DEBUG("updateServiceState(" << pAddress << ")...");
70 if (pAddress) {
71 return dynamic_cast<GenericAddress*>(pAddress)
72 ? StatusCode::SUCCESS
73 : StatusCode::FAILURE;
74 }
75 return StatusCode::FAILURE;
76}
77
82StatusCode
83xAODCnvSvc::createObj(IOpaqueAddress* pAddress, DataObject*& refpObject)
84{
85 ATH_MSG_DEBUG("-->createObj(" << pAddress->par()[0] << "/" << pAddress->par()[1]
86 << ", " << refpObject << ")...");
87 GenericAddress *addr = dynamic_cast<GenericAddress*>(pAddress);
88 if (!addr) {
89 ATH_MSG_DEBUG(pAddress->par()[0] << "/" << pAddress->par()[1]
90 << " is NOT a GenericAddress!");
91 return StatusCode::FAILURE;
92 }
93 ATH_MSG_DEBUG(" par: " << pAddress->par()[0] << "/" << pAddress->par()[1]
94 << endmsg <<
95 " ipar: " << *pAddress->ipar());
96 return AthCnvSvc::createObj(pAddress, refpObject);
97}
98
104StatusCode
105xAODCnvSvc::createRep(DataObject* pObject, IOpaqueAddress*& refpAddress)
106{
107 ATH_MSG_DEBUG("::createRep(" << refpAddress << ", " << pObject << ")...");
108 //std::cerr << "::NCS::createRep(" << this->name() << ", " << pObject << ")...\n";
109 if (0==pObject) {
110 ATH_MSG_ERROR("::createRep: received null ptr to DataObject");
111 return StatusCode::FAILURE;
112 }
113 return ::AthCnvSvc::createRep(pObject, refpAddress);
114}
115
121StatusCode
122xAODCnvSvc::fillRepRefs(IOpaqueAddress* pAddress, DataObject* pObject)
123{
124 ATH_MSG_DEBUG("::fillRepRefs(" << pAddress << ", " << pObject << ")...");
125 if (0==pAddress || 0==pObject) {
126 ATH_MSG_ERROR("::fillRepRefs: null ptr received! (paddr=" << pAddress
127 << ", pobj=" << pObject << ")");
128 return StatusCode::FAILURE;
129 }
130 return ::AthCnvSvc::fillRepRefs(pAddress, pObject);
131}
132
137StatusCode
138xAODCnvSvc::connectOutput(const std::string& outputConnectionSpec,
139 const std::string& openMode)
140{
141 ATH_MSG_DEBUG("::connectOutput("
142 << outputConnectionSpec << ", "
143 << openMode << ")");
144 // std::cerr << "::connectOutput(" << outputConnectionSpec << ", openmode="
145 // << openMode << ")...\n";
146 TFile *f = TFile::Open(outputConnectionSpec.c_str(), "recreate");
147 if (f == 0) {
148 return StatusCode::FAILURE;
149 }
150
151 return StatusCode::SUCCESS;
152}
153
157StatusCode
158xAODCnvSvc::connectOutput(const std::string& outputConnectionSpec)
159{
160 ATH_MSG_DEBUG("::connectOutput("
161 << outputConnectionSpec << ")");
162 // std::cerr << "::connectOutput(" << outputConnectionSpec << ")...\n";
163 TFile *f = TFile::Open(outputConnectionSpec.c_str(), "recreate");
164 if (f == 0) {
165 return StatusCode::FAILURE;
166 }
167 return StatusCode::SUCCESS;
168}
169
171StatusCode
172xAODCnvSvc::commitOutput(const std::string& outputConnectionSpec,
173 bool doCommit)
174{
175 ATH_MSG_DEBUG("::commitOutput(" << outputConnectionSpec
176 << ", " << doCommit << ")...");
177 return StatusCode::SUCCESS;
178}
179
180
181
183
184
192StatusCode
194 const CLID& clid,
195 const std::string* par,
196 const unsigned long* ip,
197 IOpaqueAddress*& refpAddress)
198{
199 ATH_MSG_DEBUG("::createAddress(" << svcType << ", " << clid
200 << ", " << par << ", " << ip << ", " << refpAddress
201 << ")...");
202 return ::AthCnvSvc::createAddress(svcType, clid, par, ip, refpAddress);
203}
204
208StatusCode
209xAODCnvSvc::convertAddress(const IOpaqueAddress* pAddress,
210 std::string& refAddress)
211{
212 ATH_MSG_DEBUG("::convertAddress(" << pAddress << ", "
213 << refAddress << ")...");
214 if (pAddress) {
215 refAddress = *pAddress->par();
216 return StatusCode::SUCCESS;
217 }
218 ATH_MSG_ERROR("::convertAddress: null pointer to IOpaqueAddress !");
219 return StatusCode::FAILURE;
220}
221
227StatusCode
229 const CLID& clid,
230 const std::string& refAddress,
231 IOpaqueAddress*& refpAddress)
232{
233 ATH_MSG_VERBOSE("::createAddress(" << svcType << ", " << clid
234 << ", " << refAddress << ", " << refpAddress
235 << ")...");
236 if (svcType != POOL_ROOTTREE_StorageType) {
237 ATH_MSG_ERROR("::createAddress: svcType != root-type");
238 ATH_MSG_ERROR(" svcType = [" << svcType << "]");
239 ATH_MSG_ERROR(" root-type = [" << POOL_ROOTTREE_StorageType << "]");
240 return StatusCode::FAILURE;
241 }
242 refpAddress = new GenericAddress(POOL_ROOTTREE_StorageType, clid, refAddress);
243 return StatusCode::SUCCESS;
244}
245
246
248// Const methods:
250
252// Non-const methods:
254
256// Protected methods:
258
260IConverter*
262 const CLID& clid,
263 const ICnvFactory* fac)
264{
265 ATH_MSG_VERBOSE("xAODCnvSvc::createConverter(" << typ << ", " << clid
266 << ", " << fac << ")...");
267 IConverter* cnv = new Athena::xAODCnv(clid, serviceLocator());
268 ATH_MSG_VERBOSE("xAODCnvSvc::createConverter 2");
269 if (cnv) {
270 ATH_MSG_VERBOSE("xAODCnvSvc::createConverter 3");
271 return cnv;
272 }
273 ATH_MSG_VERBOSE("xAODCnvSvc::createConverter 4");
274 return AthCnvSvc::createConverter(typ, clid, fac);
275}
276
278// Const methods:
280
282// Non-const methods:
284
285} //> 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....