The Gaudi Framework  v36r10 (fc05264c)
RootHistCnv::RFileCnv Class Reference

#include </builds/gaudi/Gaudi/RootHistCnv/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...
 
- 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...
 
- 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...
 
- Public Member Functions inherited from implements< IConverter >
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::stringgetInterfaceNames () 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...
 
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...
 

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 { nullptr }
 Pointer to ROOT file. More...
 
std::string m_compLevel
 Compression setting, property RFileCnv.GlobalCompression. More...
 
- Protected Attributes inherited from implements< IConverter >
std::atomic_ulong m_refCount
 Reference counter
More...
 

Additional Inherited Members

- Public Types inherited from Converter
using Factory = Gaudi::PluginService::Factory< IConverter *(ISvcLocator *)>
 
- Public Types inherited from implements< IConverter >
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...
 
- Protected Member Functions inherited from RootHistCnv::RConverter
 RConverter (const CLID &clid, ISvcLocator *svc)
 Standard constructor. 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
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 Retrieve pointer to message service. More...
 
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 32 of file RFileCnv.h.

Constructor & Destructor Documentation

◆ RFileCnv()

RootHistCnv::RFileCnv::RFileCnv ( ISvcLocator svc)

Standard constructor.

Definition at line 36 of file RFileCnv.cpp.

36 : RDirectoryCnv( svc, classID() ) {}

Member Function Documentation

◆ classID()

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

Inquire class type.

Definition at line 48 of file RFileCnv.h.

48 { return CLID_NTupleFile; }

◆ createObj()

StatusCode RootHistCnv::RFileCnv::createObj ( IOpaqueAddress pAddress,
DataObject *&  refpObject 
)
override

Create the transient representation of an object.

Definition at line 52 of file RFileCnv.cpp.

54 {
55  MsgStream log( msgSvc(), "RFileCnv" );
56  unsigned long* ipar = (unsigned long*)pAddress->ipar();
57  char mode[2] = { char( ipar[1] ), 0 };
58 
59  std::string fname = pAddress->par()[0]; // Container name
60  std::string ooname = pAddress->par()[1]; // Object name
61 
62  const std::string* spar = pAddress->par();
63  // Strip of store name to get the top level RZ directory
64  std::string oname = spar[1].substr( spar[1].find( "/", 1 ) + 1 );
65 
66  // Protect against multiple instances of TROOT
67  if ( !gROOT ) {
68  static TROOT root( "root", "ROOT I/O" );
69  // gDebug = 99;
70  } else {
71  log << MSG::VERBOSE << "ROOT already initialized, debug = " << gDebug << endmsg;
72  }
73 
74  // Determine access mode:
75 
76  if ( mode[0] == 'O' ) {
77 
78  if ( findTFile( ooname, rfile ).isFailure() ) {
79 
80  log << MSG::INFO << "opening Root file \"" << fname << "\" for reading" << endmsg;
81 
82  rfile = TFile::Open( fname.c_str(), "READ" );
83  if ( rfile && rfile->IsOpen() ) {
84  regTFile( ooname, rfile ).ignore();
85 
86  ipar[0] = (unsigned long)rfile;
87  NTuple::File* pFile = new NTuple::File( objType(), fname, oname );
88  pFile->setOpen( true );
89  refpObject = pFile;
90 
91  return StatusCode::SUCCESS;
92 
93  } else {
94  log << MSG::ERROR << "Couldn't open \"" << fname << "\" for reading" << endmsg;
95  return StatusCode::FAILURE;
96  }
97 
98  } else {
99  log << MSG::DEBUG << "Root file \"" << fname << "\" already opened" << endmsg;
100  return StatusCode::SUCCESS;
101  }
102 
103  } else if ( mode[0] == 'U' ) {
104 
105  log << MSG::INFO << "opening Root file \"" << fname << "\" for updating" << endmsg;
106 
107  log << MSG::ERROR << "don't know how to do this yet. Aborting." << endmsg;
108  exit( 1 );
109 
110  } else if ( mode[0] == 'N' ) {
111 
112  log << MSG::INFO << "opening Root file \"" << fname << "\" for writing";
113  if ( !m_compLevel.empty() ) { log << ", CompressionLevel='" << m_compLevel << "'"; }
114  log << endmsg;
115 
116  rfile = TFile::Open( fname.c_str(), "RECREATE", "Gaudi Trees" );
117  if ( !( rfile && rfile->IsOpen() ) ) {
118  log << MSG::ERROR << "Could not open file " << fname << " for writing" << endmsg;
119  return StatusCode::FAILURE;
120  }
121  if ( !m_compLevel.empty() ) {
122  const RootCompressionSettings settings( m_compLevel );
123  rfile->SetCompressionSettings( settings.level() );
124  }
125 
126  regTFile( ooname, rfile ).ignore();
127 
128  log << MSG::DEBUG << "creating ROOT file " << fname << endmsg;
129 
130  ipar[0] = (unsigned long)rfile;
131  NTuple::File* pFile = new NTuple::File( objType(), fname, oname );
132  pFile->setOpen( true );
133  refpObject = pFile;
134  return StatusCode::SUCCESS;
135 
136  } else {
137 
138  log << MSG::ERROR << "Uknown mode to access ROOT file" << endmsg;
139  return StatusCode::FAILURE;
140  }
141 
142  return StatusCode::FAILURE;
143 }

◆ createRep()

StatusCode RootHistCnv::RFileCnv::createRep ( DataObject pObject,
IOpaqueAddress *&  refpAddress 
)
override

Convert the transient object to the requested representation.

Definition at line 146 of file RFileCnv.cpp.

148 {
149  refpAddress = pObject->registry()->address();
150  return RFileCnv::updateRep( refpAddress, pObject );
151 }

◆ initialize()

StatusCode RootHistCnv::RFileCnv::initialize ( )
override

Initialise.

Definition at line 39 of file RFileCnv.cpp.

39  {
40  // Set compression level property ...
41  const auto& optsSvc = serviceLocator()->getOptsSvc();
42  if ( optsSvc.has( "RFileCnv.GlobalCompression" ) ) {
43  auto sc = Gaudi::Parsers::parse( m_compLevel, optsSvc.get( "RFileCnv.GlobalCompression" ) );
44  if ( !sc ) return sc;
45  }
46  // initialise base class
48 }

◆ updateRep()

StatusCode RootHistCnv::RFileCnv::updateRep ( IOpaqueAddress pAddress,
DataObject pObject 
)
override

Convert the transient object to the requested representation.

Definition at line 154 of file RFileCnv.cpp.

156 {
157  MsgStream log( msgSvc(), "RFileCnv" );
158  std::string ooname = pAddress->par()[1];
159 
160  NTuple::File* pFile = dynamic_cast<NTuple::File*>( pObject );
161  if ( pFile && pFile->isOpen() ) {
162 
163  unsigned long* ipar = (unsigned long*)pAddress->ipar();
164  if ( findTFile( ooname, rfile ).isFailure() ) {
165  log << MSG::ERROR << "Problems closing TFile " << ooname << endmsg;
166  return StatusCode::FAILURE;
167  }
168 
169  rfile->Write( nullptr, TObject::kOverwrite );
170  if ( log.level() <= MSG::INFO ) {
171  log << MSG::INFO << "dumping contents of " << ooname << endmsg;
172  rfile->Print();
173  }
174 
175  /*
176  * MetaData
177  * Ana Trisovic
178  * March 2015
179  * */
181  mds = serviceLocator()->service( "Gaudi::MetaDataSvc", false );
182  // auto mds = service<IMetaDataSvc>("MetaDataSvc", false);
183  if ( mds ) {
184  std::map<std::string, std::string> m_metadata = mds->getMetaDataMap();
185  if ( !rfile->WriteObject( &m_metadata, "info" ) ) { return StatusCode::FAILURE; }
186  }
187  /* */
188 
189  rfile->Close();
190  delete rfile;
191 
192  ipar[0] = 0;
193  pFile->setOpen( false );
194  return StatusCode::SUCCESS;
195 
196  } else {
197  log << MSG::ERROR << "TFile " << ooname << " is not open" << endmsg;
198  }
199  return StatusCode::FAILURE;
200 }

Member Data Documentation

◆ m_compLevel

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

Compression setting, property RFileCnv.GlobalCompression.

Definition at line 55 of file RFileCnv.h.

◆ rfile

TFile* RootHistCnv::RFileCnv::rfile { nullptr }
protected

Pointer to ROOT file.

Definition at line 54 of file RFileCnv.h.


The documentation for this class was generated from the following files:
RootHistCnv::RFileCnv::classID
static const CLID & classID()
Inquire class type.
Definition: RFileCnv.h:48
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
RootHistCnv::RFileCnv::updateRep
StatusCode updateRep(IOpaqueAddress *pAddress, DataObject *pObject) override
Convert the transient object to the requested representation.
Definition: RFileCnv.cpp:154
NTuple::File
Small class representing an N tuple file in the transient store.
Definition: NTuple.h:922
std::string
STL class.
IOpaqueAddress::par
virtual const std::string * par() const =0
Retrieve String parameters.
Gaudi.Configuration.log
log
Definition: Configuration.py:28
MSG::INFO
@ INFO
Definition: IMessageSvc.h:25
RootHistCnv::RFileCnv::rfile
TFile * rfile
Pointer to ROOT file.
Definition: RFileCnv.h:54
Properties.long
long
(c) Copyright 1998-2020 CERN for the benefit of the LHCb and ATLAS collaborations # # This software i...
Definition: Properties.py:15
std::find
T find(T... args)
gaudiComponentHelp.root
root
Definition: gaudiComponentHelp.py:43
std::string::c_str
T c_str(T... args)
Converter::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
Definition: Converter.cpp:102
SmartIF
Definition: IConverter.h:25
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
Converter::objType
const CLID & objType() const override
Retrieve the class type of objects the converter produces.
Definition: Converter.cpp:23
std::map< std::string, std::string >
MsgStream
Definition: MsgStream.h:34
RootHistCnv::RFileCnv::m_compLevel
std::string m_compLevel
Compression setting, property RFileCnv.GlobalCompression.
Definition: RFileCnv.h:55
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
RootHistCnv::RConverter::findTFile
StatusCode findTFile(const std::string, TFile *&)
Definition: RConverter.cpp:289
std::string::substr
T substr(T... args)
RootHistCnv::RConverter::regTFile
StatusCode regTFile(const std::string, const TFile *)
Definition: RConverter.cpp:274
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
MSG::VERBOSE
@ VERBOSE
Definition: IMessageSvc.h:25
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
RootHistCnv::RDirectoryCnv::RDirectoryCnv
RDirectoryCnv(ISvcLocator *svc)
Standard constructor.
Definition: RDirectoryCnv.h:39
Gaudi::Parsers::parse
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
Definition: DODBasicMapper.cpp:21
std::string::empty
T empty(T... args)
NTuple::File::setOpen
void setOpen(bool flag)
Set "open" flag.
Definition: NTuple.h:956
NTuple::File::isOpen
bool isOpen() const
Access "open" flag.
Definition: NTuple.h:958
Converter::initialize
StatusCode initialize() override
Initialize the converter.
Definition: Converter.cpp:53
Converter::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:105
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:82
std::exit
T exit(T... args)
IOpaqueAddress::ipar
virtual const unsigned long * ipar() const =0
Access to generic link parameters.