RootHistCnv::RFileCnv Class Reference

NTuple converter class definition. More...

#include <src/RFileCnv.h>

Inheritance diagram for RootHistCnv::RFileCnv:
Collaboration diagram for RootHistCnv::RFileCnv:

Public Member Functions

StatusCode initialize () override
 Initialise. More...
 
StatusCode createObj (IOpaqueAddress *pAddress, DataObject *&refpObject) override
 Create the transient representation of an object. More...
 
StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress) override
 Convert the transient object to the requested representation. More...
 
StatusCode updateRep (IOpaqueAddress *pAddress, DataObject *pObject) override
 Convert the transient object to the requested representation. More...
 
 RFileCnv (ISvcLocator *svc)
 Standard constructor. More...
 
 ~RFileCnv () override=default
 Standard destructor. More...
 
- Public Member Functions inherited from RootHistCnv::RDirectoryCnv
StatusCode createObj (IOpaqueAddress *pAddr, DataObject *&refpObj) override
 Create the transient representation of an object. More...
 
StatusCode fillObjRefs (IOpaqueAddress *pAddr, DataObject *refpObj) override
 Update the transient object from the other representation. More...
 
StatusCode createRep (DataObject *pObj, IOpaqueAddress *&refpAddr) override
 Convert the transient object to the requested representation. More...
 
StatusCode updateRep (IOpaqueAddress *pAddr, DataObject *pObject) override
 Convert the transient object to the requested representation. More...
 
 RDirectoryCnv (ISvcLocator *svc)
 Standard constructor. More...
 
 RDirectoryCnv (ISvcLocator *svc, const CLID &clid)
 Standard constructor. More...
 
 ~RDirectoryCnv () override=default
 Standard destructor. More...
 
- Public Member Functions inherited from RootHistCnv::RConverter
StatusCode createRep (DataObject *pObj, IOpaqueAddress *&refpAddr) override
 Convert the transient object to the requested representation. More...
 
long repSvcType () const override
 
StatusCode error (const std::string &msg)
 
StatusCode regTFile (const std::string, const TFile *)
 
StatusCode findTFile (const std::string, TFile *&)
 
std::string diskDirectory (const std::string &loc)
 
std::string directory (const std::string &loc)
 
void setDirectory (const std::string &loc)
 
void setDiskDirectory (const std::string &loc)
 
StatusCode createDirectory (const std::string &loc)
 
StatusCode createDiskDirectory (const std::string &loc)
 
std::string getDirectory ()
 
std::string convertId (const std::string &) const
 
- Public Member Functions inherited from Converter
StatusCode initialize () override
 Initialize the converter. More...
 
StatusCode finalize () override
 Initialize the converter. More...
 
StatusCode setDataProvider (IDataProviderSvc *svc) override
 Set Data provider service. More...
 
SmartIF< IDataProviderSvc > & dataProvider () const override
 Get Data provider service. More...
 
StatusCode setConversionSvc (IConversionSvc *svc) override
 Set conversion service the converter is connected to. More...
 
SmartIF< IConversionSvc > & conversionSvc () const override
 Get conversion service the converter is connected to. More...
 
StatusCode setAddressCreator (IAddressCreator *creator) override
 Set address creator facility. More...
 
SmartIF< IAddressCreator > & addressCreator () const override
 Retrieve address creator facility. More...
 
const CLIDobjType () const override
 Retrieve the class type of objects the converter produces. More...
 
virtual long i_repSvcType () const
 Retrieve the class type of the data store the converter uses. More...
 
StatusCode createObj (IOpaqueAddress *pAddress, DataObject *&refpObject) override
 Create the transient representation of an object. More...
 
StatusCode fillObjRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Resolve the references of the created transient object. More...
 
StatusCode updateObj (IOpaqueAddress *pAddress, DataObject *refpObject) override
 Update the transient object from the other representation. More...
 
StatusCode updateObjRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the references of an updated transient object. More...
 
StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress) override
 Convert the transient object to the requested representation. More...
 
StatusCode fillRepRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Resolve the references of the converted object. More...
 
StatusCode updateRep (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the converted representation of a transient object. More...
 
StatusCode updateRepRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the references of an already converted object. More...
 
 Converter (long storage_type, const CLID &class_type, ISvcLocator *svc=0)
 Standard Constructor. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=false) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &type, const std::string &name, T *&psvc) const
 Access a service by name, type creating it if it doesn't already exist. More...
 
SmartIF< IServiceservice (const std::string &name, const bool createIf=true) const
 Return a pointer to the service identified by name (or "type/name") More...
 
StatusCode initialize () override
 Initialize the converter. More...
 
StatusCode finalize () override
 Initialize the converter. More...
 
StatusCode setDataProvider (IDataProviderSvc *svc) override
 Set Data provider service. More...
 
SmartIF< IDataProviderSvc > & dataProvider () const override
 Get Data provider service. More...
 
StatusCode setConversionSvc (IConversionSvc *svc) override
 Set conversion service the converter is connected to. More...
 
SmartIF< IConversionSvc > & conversionSvc () const override
 Get conversion service the converter is connected to. More...
 
StatusCode setAddressCreator (IAddressCreator *creator) override
 Set address creator facility. More...
 
SmartIF< IAddressCreator > & addressCreator () const override
 Retrieve address creator facility. More...
 
const CLIDobjType () const override
 Retrieve the class type of objects the converter produces. More...
 
virtual long i_repSvcType () const
 Retrieve the class type of the data store the converter uses. More...
 
StatusCode createObj (IOpaqueAddress *pAddress, DataObject *&refpObject) override
 Create the transient representation of an object. More...
 
StatusCode fillObjRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Resolve the references of the created transient object. More...
 
StatusCode updateObj (IOpaqueAddress *pAddress, DataObject *refpObject) override
 Update the transient object from the other representation. More...
 
StatusCode updateObjRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the references of an updated transient object. More...
 
StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress) override
 Convert the transient object to the requested representation. More...
 
StatusCode fillRepRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Resolve the references of the converted object. More...
 
StatusCode updateRep (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the converted representation of a transient object. More...
 
StatusCode updateRepRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the references of an already converted object. More...
 
 Converter (long storage_type, const CLID &class_type, ISvcLocator *svc=0)
 Standard Constructor. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=false) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &type, const std::string &name, T *&psvc) const
 Access a service by name, type creating it if it doesn't already exist. More...
 
SmartIF< IServiceservice (const std::string &name, const bool createIf=true) const
 Return a pointer to the service identified by name (or "type/name") More...
 
- Public Member Functions inherited from implements< Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 implements ()=default
 Default constructor. More...
 
 implements (const implements &)
 Copy constructor (zero the reference count) More...
 
implementsoperator= (const implements &)
 Assignment operator (do not touch the reference count). More...
 
 ~implements () override=default
 Virtual destructor. More...
 
unsigned long addRef () override
 Reference Interface instance. More...
 
unsigned long release () override
 Release Interface instance. More...
 
unsigned long refCount () const override
 Current reference count. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 implements ()=default
 Default constructor. More...
 
 implements (const implements &)
 Copy constructor (zero the reference count) More...
 
implementsoperator= (const implements &)
 Assignment operator (do not touch the reference count). More...
 
 ~implements () override=default
 Virtual destructor. More...
 
unsigned long addRef () override
 Reference Interface instance. More...
 
unsigned long release () override
 Release Interface instance. More...
 
unsigned long refCount () const override
 Current reference count. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Static Public Member Functions

static const CLIDclassID ()
 Inquire class type. More...
 
- Static Public Member Functions inherited from RootHistCnv::RDirectoryCnv
static const CLIDclassID ()
 Inquire class type. More...
 
- Static Public Member Functions inherited from RootHistCnv::RConverter
static long storageType ()
 Inquire storage type. More...
 

Protected Attributes

TFile * rfile
 Pointer to ROOT file. More...
 
std::string m_compLevel
 Compression setting. More...
 
- Protected Attributes inherited from implements< Interfaces >
std::atomic_ulong m_refCount = {0}
 Reference counter. More...
 

Additional Inherited Members

- Public Types inherited from Converter
typedef Gaudi::PluginService::Factory< IConverter *, ISvcLocator * > Factory
 
typedef Gaudi::PluginService::Factory< IConverter *, ISvcLocator * > Factory
 
- Public Types inherited from implements< Interfaces >
using base_class = implements< Interfaces...>
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using iids = typename extend_interfaces_base::ext_iids
 
using base_class = implements< Interfaces...>
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using iids = typename extend_interfaces_base::ext_iids
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Member Functions inherited from RootHistCnv::RConverter
 RConverter (const CLID &clid, ISvcLocator *svc)
 Standard constructor. More...
 
 ~RConverter () override=default
 Standard destructor. More...
 
virtual StatusCode readObject (IOpaqueAddress *pAddr, DataObject *&refpObj)
 Create the transient representation of an object. More...
 
virtual TObject * createPersistent (DataObject *pObj)
 Create the persistent representation of an object. More...
 
StatusCode createAddress (DataObject *pObject, TDirectory *pDir, TObject *pTObject, IOpaqueAddress *&refpAddr)
 Create address of the transient object according to the requested representation. More...
 
StatusCode createAddress (const std::string &rzdir, const CLID &clid, long id, TObject *pTobj, IOpaqueAddress *&refpAddress)
 
StatusCode createAddress (const std::string &rzdir, const CLID &clid, const std::string &title, TObject *pTobj, IOpaqueAddress *&refpAddress)
 
TDirectory * changeDirectory (DataObject *pObject)
 Switch to object directory (=Parent directory) More...
 
- Protected Member Functions inherited from Converter
 ~Converter () override=default
 Standard Destructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 Retrieve pointer to message service. More...
 
SmartIF< IMessageSvc > & messageService () const
 
SmartIF< IDataManagerSvc > & dataManager () const
 Get Data Manager service. More...
 
 ~Converter () override=default
 Standard Destructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 Retrieve pointer to message service. More...
 
SmartIF< IMessageSvc > & messageService () const
 
SmartIF< IDataManagerSvc > & dataManager () const
 Get Data Manager service. More...
 

Detailed Description

NTuple converter class definition.

  • Major cleanup and debugging for Gaudi v9
  • Removal of all static storage
Author
Charles Leggett
Markus Frank

Definition at line 22 of file RFileCnv.h.

Constructor & Destructor Documentation

RootHistCnv::RFileCnv::RFileCnv ( ISvcLocator svc)

Standard constructor.

Definition at line 22 of file RFileCnv.cpp.

23 : RDirectoryCnv ( svc, classID() )
24 { }
static const CLID & classID()
Inquire class type.
Definition: RFileCnv.h:42
RDirectoryCnv(ISvcLocator *svc)
Standard constructor.
Definition: RDirectoryCnv.h:29
RootHistCnv::RFileCnv::~RFileCnv ( )
overridedefault

Standard destructor.

Member Function Documentation

static const CLID& RootHistCnv::RFileCnv::classID ( )
inlinestatic

Inquire class type.

Definition at line 42 of file RFileCnv.h.

42  {
43  return CLID_NTupleFile;
44  }
StatusCode RootHistCnv::RFileCnv::createObj ( IOpaqueAddress pAddress,
DataObject *&  refpObject 
)
override

Create the transient representation of an object.

Definition at line 43 of file RFileCnv.cpp.

46 {
47  MsgStream log(msgSvc(), "RFileCnv");
48  unsigned long* ipar = (unsigned long*)pAddress->ipar();
49  char mode[2] = { char(ipar[1]), 0 };
50 
51  std::string fname = pAddress->par()[0]; // Container name
52  std::string ooname = pAddress->par()[1]; // Object name
53 
54  const std::string* spar = pAddress->par();
55  // Strip of store name to get the top level RZ directory
56  std::string oname = spar[1].substr(spar[1].find("/",1)+1);
57 
58  // Protect against multiple instances of TROOT
59  if ( !gROOT ) {
60  static TROOT root("root","ROOT I/O");
61  // gDebug = 99;
62  } else {
63  log << MSG::VERBOSE << "ROOT already initialized, debug = "
64  << gDebug<< endmsg;
65  }
66 
67  // Determine access mode:
68 
69  if ( mode[0] == 'O' ) {
70 
71  if (findTFile(ooname,rfile).isFailure()) {
72 
73  log << MSG::INFO << "opening Root file \"" << fname << "\" for reading"
74  << endmsg;
75 
76  rfile = TFile::Open(fname.c_str(),"READ");
77  if ( rfile && rfile->IsOpen() ) {
78  regTFile(ooname,rfile).ignore();
79 
80  ipar[0] = (unsigned long)rfile;
81  NTuple::File* pFile = new NTuple::File(objType(), fname, oname);
82  pFile->setOpen(true);
83  refpObject = pFile;
84 
85  return StatusCode::SUCCESS;
86 
87  } else {
88  log << MSG::ERROR << "Couldn't open \"" << fname << "\" for reading"
89  << endmsg;
90  return StatusCode::FAILURE;
91  }
92 
93  } else {
94  log << MSG::DEBUG << "Root file \"" << fname << "\" already opened"
95  << endmsg;
96  return StatusCode::SUCCESS;
97  }
98 
99 
100  } else if ( mode[0] == 'U' ) {
101 
102  log << MSG::INFO << "opening Root file \"" << fname << "\" for updating"
103  << endmsg;
104 
105  log << MSG::ERROR << "don't know how to do this yet. Aborting." << endmsg;
106  exit(1);
107 
108  } else if ( mode[0] == 'N' ) {
109 
110  log << MSG::INFO << "opening Root file \"" << fname << "\" for writing";
111  if ( !m_compLevel.empty() )
112  { log << ", CompressionLevel='" << m_compLevel << "'"; }
113  log << endmsg;
114 
115  rfile = TFile::Open( fname.c_str(), "RECREATE", "Gaudi Trees" );
116  if ( ! ( rfile && rfile->IsOpen() ) ) {
117  log << MSG::ERROR << "Could not open file " << fname << " for writing"
118  << endmsg;
119  return StatusCode::FAILURE;
120  }
121  if ( !m_compLevel.empty() )
122  {
123  const RootCompressionSettings settings(m_compLevel);
124  rfile->SetCompressionSettings(settings.level());
125  }
126 
127  regTFile(ooname,rfile).ignore();
128 
129  log << MSG::DEBUG << "creating ROOT file " << fname << endmsg;
130 
131  ipar[0] = (unsigned long)rfile;
132  NTuple::File* pFile = new NTuple::File(objType(), fname, oname);
133  pFile->setOpen(true);
134  refpObject = pFile;
135  return StatusCode::SUCCESS;
136 
137  } else {
138 
139  log << MSG::ERROR << "Uknown mode to access ROOT file" << endmsg;
140  return StatusCode::FAILURE;
141 
142  }
143 
144  return StatusCode::FAILURE;
145 }
virtual const std::string * par() const =0
Retrieve String parameters.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
void setOpen(bool flag)
Set "open" flag.
Definition: NTuple.h:1140
TFile * rfile
Pointer to ROOT file.
Definition: RFileCnv.h:54
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:129
StatusCode regTFile(const std::string, const TFile *)
Definition: RConverter.cpp:299
StatusCode findTFile(const std::string, TFile *&)
Definition: RConverter.cpp:316
std::string m_compLevel
Compression setting.
Definition: RFileCnv.h:55
tuple root
Definition: IOTest.py:42
void ignore() const
Definition: StatusCode.h:108
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
const CLID & objType() const override
Retrieve the class type of objects the converter produces.
Definition: Converter.cpp:14
Small class representing an N tuple file in the transient store.
Definition: NTuple.h:1088
StatusCode RootHistCnv::RFileCnv::createRep ( DataObject pObject,
IOpaqueAddress *&  refpAddress 
)
override

Convert the transient object to the requested representation.

Definition at line 148 of file RFileCnv.cpp.

151 {
152  refpAddress = pObject->registry()->address();
153  return RFileCnv::updateRep( refpAddress, pObject );
154 }
StatusCode updateRep(IOpaqueAddress *pAddress, DataObject *pObject) override
Convert the transient object to the requested representation.
Definition: RFileCnv.cpp:157
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:74
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
StatusCode RootHistCnv::RFileCnv::initialize ( )
override

Initialise.

Definition at line 27 of file RFileCnv.cpp.

28 {
29  // Set compression level property ...
30  std::unique_ptr<PropertyMgr> pmgr ( new PropertyMgr() );
31  pmgr->declareProperty( "GlobalCompression", m_compLevel );
32  ISvcLocator * svcLoc = Gaudi::svcLocator();
33  auto jobSvc = svcLoc->service<IJobOptionsSvc>("JobOptionsSvc");
34  const StatusCode sc = ( jobSvc &&
35  jobSvc->setMyProperties("RFileCnv",pmgr.get()) );
36 
37  // initialise base class
38  return ( sc && RDirectoryCnv::initialize() );
39 }
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
StatusCode initialize() override
Initialize the converter.
Definition: Converter.cpp:65
Property manager helper class.
Definition: PropertyMgr.h:35
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
Main interface for the JobOptions service.
GAUDI_API ISvcLocator * svcLocator()
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::string m_compLevel
Compression setting.
Definition: RFileCnv.h:55
StatusCode RootHistCnv::RFileCnv::updateRep ( IOpaqueAddress pAddress,
DataObject pObject 
)
override

Convert the transient object to the requested representation.

Definition at line 157 of file RFileCnv.cpp.

160 {
161  MsgStream log(msgSvc(), "RFileCnv");
162  std::string ooname = pAddress->par()[1];
163 
164  NTuple::File* pFile = dynamic_cast<NTuple::File*>(pObject);
165  if ( pFile && pFile->isOpen() ) {
166 
167  unsigned long* ipar = (unsigned long*)pAddress->ipar();
168  if (findTFile(ooname,rfile).isFailure()) {
169  log << MSG::ERROR << "Problems closing TFile " << ooname << endmsg;
170  return StatusCode::FAILURE;
171  }
172 
173  rfile->Write(nullptr,TObject::kOverwrite);
174  if ( log.level() <= MSG::INFO ) {
175  log << MSG::INFO << "dumping contents of " << ooname << endmsg;
176  rfile->Print();
177  }
178  rfile->Close();
179  delete rfile;
180 
181  ipar[0] = 0;
182  pFile->setOpen(false);
183  return StatusCode::SUCCESS;
184 
185  } else {
186  log << MSG::ERROR << "TFile " << ooname << " is not open" << endmsg;
187  }
188  return StatusCode::FAILURE;
189 }
virtual const std::string * par() const =0
Retrieve String parameters.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
void setOpen(bool flag)
Set "open" flag.
Definition: NTuple.h:1140
TFile * rfile
Pointer to ROOT file.
Definition: RFileCnv.h:54
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:129
StatusCode findTFile(const std::string, TFile *&)
Definition: RConverter.cpp:316
bool isOpen() const
Access "open" flag.
Definition: NTuple.h:1144
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
Small class representing an N tuple file in the transient store.
Definition: NTuple.h:1088

Member Data Documentation

std::string RootHistCnv::RFileCnv::m_compLevel
protected

Compression setting.

Definition at line 55 of file RFileCnv.h.

TFile* RootHistCnv::RFileCnv::rfile
protected

Pointer to ROOT file.

Definition at line 54 of file RFileCnv.h.


The documentation for this class was generated from the following files: