ATLAS Offline Software
xAODCnvSvc.cxx
Go to the documentation of this file.
1 
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 
27 namespace Athena {
28 
30 // Public methods:
32 
33 // Constructors
35 xAODCnvSvc::xAODCnvSvc( const std::string& name,
36  ISvcLocator* pSvcLocator ) :
37  base_class( name, pSvcLocator, POOL_ROOTTREE_StorageType )
38 {
39 }
40 
41 // Destructor
44 {}
45 
46 // Athena Service's Hooks
50 {
51  ATH_MSG_DEBUG ("Initializing " << name() << "...");
52 
53  return AthCnvSvc::initialize();
54 }
55 
58 {
59  ATH_MSG_DEBUG ("Finalizing " << name() << "...");
60 
61  return AthCnvSvc::finalize();
62 }
63 
67 xAODCnvSvc::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 
83 xAODCnvSvc::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 
104 StatusCode
105 xAODCnvSvc::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 
121 StatusCode
122 xAODCnvSvc::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 
137 StatusCode
138 xAODCnvSvc::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 
158 xAODCnvSvc::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 
171 StatusCode
172 xAODCnvSvc::commitOutput(const std::string& outputConnectionSpec,
173  bool doCommit)
174 {
175  ATH_MSG_DEBUG("::commitOutput(" << outputConnectionSpec
176  << ", " << doCommit << ")...");
177  return StatusCode::SUCCESS;
178 }
180 
181 
183 
184 
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 
208 StatusCode
209 xAODCnvSvc::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 
227 StatusCode
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 }
246 
248 // Const methods:
250 
252 // Non-const methods:
254 
256 // Protected methods:
258 
260 IConverter*
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
Athena::xAODCnvSvc::updateServiceState
virtual StatusCode updateServiceState(IOpaqueAddress *pAddress)
IConversionSvc and IConverter interfaces
Definition: xAODCnvSvc.cxx:67
Athena::xAODCnvSvc::createRep
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Implementation of IConverter: Convert the transient object to the requested representation.
Definition: xAODCnvSvc.cxx:105
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Athena::xAODCnvSvc::convertAddress
virtual StatusCode convertAddress(const IOpaqueAddress *pAddress, std::string &refAddress)
Convert address to string form.
Definition: xAODCnvSvc.cxx:209
Athena::xAODCnv
Definition: xAODCnv.h:37
Athena::xAODCnvSvc::createAddress
virtual StatusCode createAddress(long svcType, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)
IAddressCreator interfaces
Definition: xAODCnvSvc.cxx:193
Athena::xAODCnvSvc::fillRepRefs
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)
Implementation of IConverter: Resolve the references of the converted object.
Definition: xAODCnvSvc.cxx:122
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAODCnvSvc.h
Athena::xAODCnvSvc::~xAODCnvSvc
virtual ~xAODCnvSvc()
Destructor:
Definition: xAODCnvSvc.cxx:43
Athena::xAODCnvSvc::commitOutput
virtual StatusCode commitOutput(const std::string &outputConnectionSpec, bool doCommit)
Commit pending output.
Definition: xAODCnvSvc.cxx:172
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
hist_file_dump.f
f
Definition: hist_file_dump.py:135
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
AthCnvSvc::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject) override
Implementation of IConverter: Create the transient representation of an object.
Definition: AthCnvSvc.cxx:244
xAODCnv.h
Athena::xAODCnvSvc::createConverter
virtual IConverter * createConverter(long typ, const CLID &clid, const ICnvFactory *fac)
Create new Converter using factory (override AthCnvSvc::createConverter)
Definition: xAODCnvSvc.cxx:261
AthCnvSvc::createConverter
virtual IConverter * createConverter(long typ, const CLID &clid, const ICnvFactory *fac)
Create new Converter using factory.
Definition: AthCnvSvc.cxx:462
Athena::xAODCnvSvc::initialize
virtual StatusCode initialize()
Gaudi Service Implementation.
Definition: xAODCnvSvc.cxx:49
RootBranchAddress.h
AthCnvSvc::finalize
virtual StatusCode finalize() override
Definition: AthCnvSvc.cxx:112
Athena::xAODCnvSvc::connectOutput
virtual StatusCode connectOutput(const std::string &outputConnectionSpec, const std::string &openMode)
Connect the output connection specification to the service with open mode.
Definition: xAODCnvSvc.cxx:138
Athena::xAODCnvSvc::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject)
Implementation of IConverter: Create the transient representation of an object from persistent state.
Definition: xAODCnvSvc.cxx:83
Athena::xAODCnvSvc::finalize
virtual StatusCode finalize()
Definition: xAODCnvSvc.cxx:57
AthCnvSvc::initialize
virtual StatusCode initialize() override
Gaudi Service Implementation.
Definition: AthCnvSvc.cxx:104
Athena::xAODCnvSvc::xAODCnvSvc
xAODCnvSvc()
Default constructor: