ATLAS Offline Software
NtupleCnvSvc.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 // NtupleCnvSvc.cxx
8 // Implementation file for class Athena::NtupleCnvSvc
9 // Author: S.Binet<binet@cern.ch>
11 
12 // AthenaRootComps includes
13 #include "NtupleCnvSvc.h"
14 #include "LeafCnv.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 NtupleCnvSvc::NtupleCnvSvc( const std::string& name,
36  ISvcLocator* pSvcLocator ) :
37  ::AthCnvSvc( name, pSvcLocator, ROOT_StorageType )
38 {
39  //
40  // Property declaration
41  //
42  //declareProperty( "Property", m_nProperty );
43 
44  // std::cerr << "::NtupleCnvSvc(" << 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 NtupleCnvSvc::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 NtupleCnvSvc::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 NtupleCnvSvc::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 NtupleCnvSvc::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 NtupleCnvSvc::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 NtupleCnvSvc::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 NtupleCnvSvc::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 NtupleCnvSvc::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 NtupleCnvSvc::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_DEBUG("::createAddress(" << svcType << ", " << clid
258  << ", " << refAddress << ", " << refpAddress
259  << ")...");
260  if (svcType != ROOT_StorageType) {
261  ATH_MSG_ERROR("::createAddress: svcType != root-type");
262  ATH_MSG_ERROR(" svcType = [" << svcType << "]");
263  ATH_MSG_ERROR(" root-type = [" << ROOT_StorageType << "]");
264  return StatusCode::FAILURE;
265  }
266  refpAddress = new GenericAddress(ROOT_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_DEBUG("::createConverter(" << typ << ", " << clid
290  << ", " << fac << ")...");
291  IConverter* cnv = new Athena::LeafCnv(clid, serviceLocator());
292  if (cnv) {
293  return cnv;
294  }
295  return AthCnvSvc::createConverter(typ, clid, fac);
296 }
297 
299 // Const methods:
301 
303 // Non-const methods:
305 
306 } //> end namespace Athena
Athena::NtupleCnvSvc::~NtupleCnvSvc
virtual ~NtupleCnvSvc()
Destructor:
Definition: NtupleCnvSvc.cxx:49
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
AthCnvSvc::finalize
virtual StatusCode finalize()
Definition: AthCnvSvc.cxx:116
Athena::NtupleCnvSvc::fillRepRefs
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)
Implementation of IConverter: Resolve the references of the converted object.
Definition: NtupleCnvSvc.cxx:146
Athena::NtupleCnvSvc::connectOutput
virtual StatusCode connectOutput(const std::string &outputConnectionSpec, const std::string &openMode)
Connect the output connection specification to the service with open mode.
Definition: NtupleCnvSvc.cxx:162
LeafCnv.h
AthCnvSvc::initialize
virtual StatusCode initialize()
Gaudi Service Implementation.
Definition: AthCnvSvc.cxx:111
Athena::NtupleCnvSvc::commitOutput
virtual StatusCode commitOutput(const std::string &outputConnectionSpec, bool doCommit)
Commit pending output.
Definition: NtupleCnvSvc.cxx:196
Athena::NtupleCnvSvc::updateServiceState
virtual StatusCode updateServiceState(IOpaqueAddress *pAddress)
IConversionSvc and IConverter interfaces
Definition: NtupleCnvSvc.cxx:91
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Athena::NtupleCnvSvc::createAddress
virtual StatusCode createAddress(long svcType, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)
IAddressCreator interfaces
Definition: NtupleCnvSvc.cxx:217
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
Athena::NtupleCnvSvc::queryInterface
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
Definition: NtupleCnvSvc.cxx:76
Athena::NtupleCnvSvc::convertAddress
virtual StatusCode convertAddress(const IOpaqueAddress *pAddress, std::string &refAddress)
Convert address to string form.
Definition: NtupleCnvSvc.cxx:233
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
Athena::NtupleCnvSvc::initialize
virtual StatusCode initialize()
Gaudi Service Implementation.
Definition: NtupleCnvSvc.cxx:55
Athena::NtupleCnvSvc::NtupleCnvSvc
NtupleCnvSvc()
Default constructor:
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
Athena::NtupleCnvSvc::createConverter
virtual IConverter * createConverter(long typ, const CLID &clid, const ICnvFactory *fac)
Create new Converter using factory (override AthCnvSvc::createConverter)
Definition: NtupleCnvSvc.cxx:285
Athena::NtupleCnvSvc::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject)
Implementation of IConverter: Create the transient representation of an object from persistent state.
Definition: NtupleCnvSvc.cxx:107
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
Athena::LeafCnv
Definition: LeafCnv.h:37
AthCnvSvc::createConverter
virtual IConverter * createConverter(long typ, const CLID &clid, const ICnvFactory *fac)
Create new Converter using factory.
Definition: AthCnvSvc.cxx:491
Athena::NtupleCnvSvc::finalize
virtual StatusCode finalize()
Definition: NtupleCnvSvc.cxx:63
RootBranchAddress.h
Athena::NtupleCnvSvc::createRep
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Implementation of IConverter: Convert the transient object to the requested representation.
Definition: NtupleCnvSvc.cxx:129
AthCnvSvc
Definition: AthCnvSvc.h:67
NtupleCnvSvc.h