ATLAS Offline Software
xAODCnvSvc.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2017 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  ::AthCnvSvc( name, pSvcLocator, POOL_ROOTTREE_StorageType )
38 {
39  //
40  // Property declaration
41  //
42  //declareProperty( "Property", m_nProperty );
43 
44  // std::cerr << "::xAODCnvSvc(" << name << ")...\n";
45 }
46 
47 // Destructor
50 {}
51 
52 // Athena Service's Hooks
56 {
57  ATH_MSG_DEBUG ("Initializing " << name() << "...");
58 
59  return AthCnvSvc::initialize();
60 }
61 
64 {
65  ATH_MSG_DEBUG ("Finalizing " << name() << "...");
66 
67  return AthCnvSvc::finalize();
68 }
69 
70 // Query the interfaces.
71 // Input: riid, Requested interface ID
72 // ppvInterface, Pointer to requested interface
73 // Return: StatusCode indicating SUCCESS or FAILURE.
74 // N.B. Don't forget to release the interface after use!!!
76 xAODCnvSvc::queryInterface(const InterfaceID& riid, void** ppvInterface)
77 {
78  if ( IConversionSvc::interfaceID().versionMatch(riid) ) {
79  *ppvInterface = dynamic_cast<IConversionSvc*>(this);
80  } else {
81  // Interface is not directly available : try out a base class
82  return ::AthCnvSvc::queryInterface(riid, ppvInterface);
83  }
84  addRef();
85  return StatusCode::SUCCESS;
86 }
87 
91 xAODCnvSvc::updateServiceState(IOpaqueAddress* pAddress)
92 {
93  ATH_MSG_DEBUG("updateServiceState(" << pAddress << ")...");
94  if (pAddress) {
95  return dynamic_cast<GenericAddress*>(pAddress)
96  ? StatusCode::SUCCESS
97  : StatusCode::FAILURE;
98  }
99  return StatusCode::FAILURE;
100 }
101 
106 StatusCode
107 xAODCnvSvc::createObj(IOpaqueAddress* pAddress, DataObject*& refpObject)
108 {
109  ATH_MSG_DEBUG("-->createObj(" << pAddress->par()[0] << "/" << pAddress->par()[1]
110  << ", " << refpObject << ")...");
111  GenericAddress *addr = dynamic_cast<GenericAddress*>(pAddress);
112  if (!addr) {
113  ATH_MSG_DEBUG(pAddress->par()[0] << "/" << pAddress->par()[1]
114  << " is NOT a GenericAddress!");
115  return StatusCode::FAILURE;
116  }
117  ATH_MSG_DEBUG(" par: " << pAddress->par()[0] << "/" << pAddress->par()[1]
118  << endmsg <<
119  " ipar: " << *pAddress->ipar());
120  return AthCnvSvc::createObj(pAddress, refpObject);
121 }
122 
128 StatusCode
129 xAODCnvSvc::createRep(DataObject* pObject, IOpaqueAddress*& refpAddress)
130 {
131  ATH_MSG_DEBUG("::createRep(" << refpAddress << ", " << pObject << ")...");
132  //std::cerr << "::NCS::createRep(" << this->name() << ", " << pObject << ")...\n";
133  if (0==pObject) {
134  ATH_MSG_ERROR("::createRep: received null ptr to DataObject");
135  return StatusCode::FAILURE;
136  }
137  return ::AthCnvSvc::createRep(pObject, refpAddress);
138 }
139 
145 StatusCode
146 xAODCnvSvc::fillRepRefs(IOpaqueAddress* pAddress, DataObject* pObject)
147 {
148  ATH_MSG_DEBUG("::fillRepRefs(" << pAddress << ", " << pObject << ")...");
149  if (0==pAddress || 0==pObject) {
150  ATH_MSG_ERROR("::fillRepRefs: null ptr received! (paddr=" << pAddress
151  << ", pobj=" << pObject << ")");
152  return StatusCode::FAILURE;
153  }
154  return ::AthCnvSvc::fillRepRefs(pAddress, pObject);
155 }
156 
161 StatusCode
162 xAODCnvSvc::connectOutput(const std::string& outputConnectionSpec,
163  const std::string& openMode)
164 {
165  ATH_MSG_DEBUG("::connectOutput("
166  << outputConnectionSpec << ", "
167  << openMode << ")");
168  // std::cerr << "::connectOutput(" << outputConnectionSpec << ", openmode="
169  // << openMode << ")...\n";
170  TFile *f = TFile::Open(outputConnectionSpec.c_str(), "recreate");
171  if (f == 0) {
172  return StatusCode::FAILURE;
173  }
174 
175  return StatusCode::SUCCESS;
176 }
177 
182 xAODCnvSvc::connectOutput(const std::string& outputConnectionSpec)
183 {
184  ATH_MSG_DEBUG("::connectOutput("
185  << outputConnectionSpec << ")");
186  // std::cerr << "::connectOutput(" << outputConnectionSpec << ")...\n";
187  TFile *f = TFile::Open(outputConnectionSpec.c_str(), "recreate");
188  if (f == 0) {
189  return StatusCode::FAILURE;
190  }
191  return StatusCode::SUCCESS;
192 }
193 
195 StatusCode
196 xAODCnvSvc::commitOutput(const std::string& outputConnectionSpec,
197  bool doCommit)
198 {
199  ATH_MSG_DEBUG("::commitOutput(" << outputConnectionSpec
200  << ", " << doCommit << ")...");
201  return StatusCode::SUCCESS;
202 }
204 
205 
207 
208 
218  const CLID& clid,
219  const std::string* par,
220  const unsigned long* ip,
221  IOpaqueAddress*& refpAddress)
222 {
223  ATH_MSG_DEBUG("::createAddress(" << svcType << ", " << clid
224  << ", " << par << ", " << ip << ", " << refpAddress
225  << ")...");
226  return ::AthCnvSvc::createAddress(svcType, clid, par, ip, refpAddress);
227 }
228 
232 StatusCode
233 xAODCnvSvc::convertAddress(const IOpaqueAddress* pAddress,
234  std::string& refAddress)
235 {
236  ATH_MSG_DEBUG("::convertAddress(" << pAddress << ", "
237  << refAddress << ")...");
238  if (pAddress) {
239  refAddress = *pAddress->par();
240  return StatusCode::SUCCESS;
241  }
242  ATH_MSG_ERROR("::convertAddress: null pointer to IOpaqueAddress !");
243  return StatusCode::FAILURE;
244 }
245 
251 StatusCode
253  const CLID& clid,
254  const std::string& refAddress,
255  IOpaqueAddress*& refpAddress)
256 {
257  ATH_MSG_VERBOSE("::createAddress(" << svcType << ", " << clid
258  << ", " << refAddress << ", " << refpAddress
259  << ")...");
260  if (svcType != POOL_ROOTTREE_StorageType) {
261  ATH_MSG_ERROR("::createAddress: svcType != root-type");
262  ATH_MSG_ERROR(" svcType = [" << svcType << "]");
263  ATH_MSG_ERROR(" root-type = [" << POOL_ROOTTREE_StorageType << "]");
264  return StatusCode::FAILURE;
265  }
266  refpAddress = new GenericAddress(POOL_ROOTTREE_StorageType, clid, refAddress);
267  return StatusCode::SUCCESS;
268 }
270 
272 // Const methods:
274 
276 // Non-const methods:
278 
280 // Protected methods:
282 
284 IConverter*
286  const CLID& clid,
287  const ICnvFactory* fac)
288 {
289  ATH_MSG_VERBOSE("xAODCnvSvc::createConverter(" << typ << ", " << clid
290  << ", " << fac << ")...");
291  IConverter* cnv = new Athena::xAODCnv(clid, serviceLocator());
292  ATH_MSG_VERBOSE("xAODCnvSvc::createConverter 2");
293  if (cnv) {
294  ATH_MSG_VERBOSE("xAODCnvSvc::createConverter 3");
295  return cnv;
296  }
297  ATH_MSG_VERBOSE("xAODCnvSvc::createConverter 4");
298  return AthCnvSvc::createConverter(typ, clid, fac);
299 }
300 
302 // Const methods:
304 
306 // Non-const methods:
308 
309 } //> end namespace Athena
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
AthCnvSvc::finalize
virtual StatusCode finalize()
Definition: AthCnvSvc.cxx:116
Athena::xAODCnvSvc::updateServiceState
virtual StatusCode updateServiceState(IOpaqueAddress *pAddress)
IConversionSvc and IConverter interfaces
Definition: xAODCnvSvc.cxx:91
Athena::xAODCnvSvc::createRep
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Implementation of IConverter: Convert the transient object to the requested representation.
Definition: xAODCnvSvc.cxx:129
AthCnvSvc::initialize
virtual StatusCode initialize()
Gaudi Service Implementation.
Definition: AthCnvSvc.cxx:111
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Athena::xAODCnvSvc::queryInterface
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
Definition: xAODCnvSvc.cxx:76
Athena::xAODCnvSvc::convertAddress
virtual StatusCode convertAddress(const IOpaqueAddress *pAddress, std::string &refAddress)
Convert address to string form.
Definition: xAODCnvSvc.cxx:233
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:217
Athena::xAODCnvSvc::fillRepRefs
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)
Implementation of IConverter: Resolve the references of the converted object.
Definition: xAODCnvSvc.cxx:146
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAODCnvSvc.h
Athena::xAODCnvSvc::~xAODCnvSvc
virtual ~xAODCnvSvc()
Destructor:
Definition: xAODCnvSvc.cxx:49
Athena::xAODCnvSvc::commitOutput
virtual StatusCode commitOutput(const std::string &outputConnectionSpec, bool doCommit)
Commit pending output.
Definition: xAODCnvSvc.cxx:196
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
AthCnvSvc::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject)
Implementation of IConverter: Create the transient representation of an object.
Definition: AthCnvSvc.cxx:273
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
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:195
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
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:285
AthCnvSvc::createConverter
virtual IConverter * createConverter(long typ, const CLID &clid, const ICnvFactory *fac)
Create new Converter using factory.
Definition: AthCnvSvc.cxx:491
Athena::xAODCnvSvc::initialize
virtual StatusCode initialize()
Gaudi Service Implementation.
Definition: xAODCnvSvc.cxx:55
RootBranchAddress.h
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:162
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:107
Athena::xAODCnvSvc::finalize
virtual StatusCode finalize()
Definition: xAODCnvSvc.cxx:63
AthCnvSvc
Definition: AthCnvSvc.h:67
Athena::xAODCnvSvc::xAODCnvSvc
xAODCnvSvc()
Default constructor: