The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
RootHistCnv::RFileCnv Class Reference

NTuple converter class definition. More...

#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.
 
StatusCode createObj (IOpaqueAddress *pAddress, DataObject *&refpObject) override
 Create the transient representation of an object.
 
StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress) override
 Convert the transient object to the requested representation.
 
StatusCode updateRep (IOpaqueAddress *pAddress, DataObject *pObject) override
 Convert the transient object to the requested representation.
 
 RFileCnv (ISvcLocator *svc)
 Standard constructor.
 
- Public Member Functions inherited from RootHistCnv::RDirectoryCnv
StatusCode createObj (IOpaqueAddress *pAddr, DataObject *&refpObj) override
 Create the transient representation of an object.
 
StatusCode fillObjRefs (IOpaqueAddress *pAddr, DataObject *refpObj) override
 Update the transient object from the other representation.
 
StatusCode createRep (DataObject *pObj, IOpaqueAddress *&refpAddr) override
 Convert the transient object to the requested representation.
 
StatusCode updateRep (IOpaqueAddress *pAddr, DataObject *pObject) override
 Convert the transient object to the requested representation.
 
 RDirectoryCnv (ISvcLocator *svc)
 Standard constructor.
 
 RDirectoryCnv (ISvcLocator *svc, const CLID &clid)
 Standard constructor.
 
- Public Member Functions inherited from RootHistCnv::RConverter
StatusCode createRep (DataObject *pObj, IOpaqueAddress *&refpAddr) override
 Convert the transient object to the requested representation.
 
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.
 
StatusCode finalize () override
 Initialize the converter.
 
StatusCode setDataProvider (IDataProviderSvc *svc) override
 Set Data provider service.
 
SmartIF< IDataProviderSvc > & dataProvider () const override
 Get Data provider service.
 
StatusCode setConversionSvc (IConversionSvc *svc) override
 Set conversion service the converter is connected to.
 
SmartIF< IConversionSvc > & conversionSvc () const override
 Get conversion service the converter is connected to.
 
StatusCode setAddressCreator (IAddressCreator *creator) override
 Set address creator facility.
 
SmartIF< IAddressCreator > & addressCreator () const override
 Retrieve address creator facility.
 
const CLIDobjType () const override
 Retrieve the class type of objects the converter produces.
 
virtual long i_repSvcType () const
 Retrieve the class type of the data store the converter uses.
 
StatusCode createObj (IOpaqueAddress *pAddress, DataObject *&refpObject) override
 Create the transient representation of an object.
 
StatusCode fillObjRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Resolve the references of the created transient object.
 
StatusCode updateObj (IOpaqueAddress *pAddress, DataObject *refpObject) override
 Update the transient object from the other representation.
 
StatusCode updateObjRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the references of an updated transient object.
 
StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress) override
 Convert the transient object to the requested representation.
 
StatusCode fillRepRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Resolve the references of the converted object.
 
StatusCode updateRep (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the converted representation of a transient object.
 
StatusCode updateRepRefs (IOpaqueAddress *pAddress, DataObject *pObject) override
 Update the references of an already converted object.
 
 Converter (long storage_type, const CLID &class_type, ISvcLocator *svc=0)
 Standard Constructor.
 
SmartIF< IServiceservice (const std::string &name, const bool createIf=true) const
 Return a pointer to the service identified by name (or "type/name")
 
- Public Member Functions inherited from implements< IConverter >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
 
 implements ()=default
 Default constructor.
 
 implements (const implements &)
 Copy constructor (zero the reference count)
 
implementsoperator= (const implements &)
 Assignment operator (do not touch the reference count).
 
unsigned long addRef () const override
 Reference Interface instance.
 
unsigned long release () const override
 Release Interface instance.
 
unsigned long refCount () const override
 Current reference count.
 

Static Public Member Functions

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

Protected Attributes

TFile * rfile { nullptr }
 Pointer to ROOT file.
 
std::string m_compLevel
 Compression setting, property RFileCnv.GlobalCompression.
 
SmartIF< IIncidentSvcm_incSvc
 
- Protected Attributes inherited from implements< IConverter >
std::atomic_ulong m_refCount
 Reference counter.
 

Additional Inherited Members

- Public Types inherited from Converter
using Factory = Gaudi::PluginService::Factory<IConverter*( ISvcLocator* )>
 
- Public Types inherited from implements< IConverter >
using base_class
 Typedef to this class.
 
using extend_interfaces_base
 Typedef to the base of this class.
 
using iids
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
 
- Protected Member Functions inherited from RootHistCnv::RConverter
 RConverter (const CLID &clid, ISvcLocator *svc)
 Standard constructor.
 
virtual StatusCode readObject (IOpaqueAddress *pAddr, DataObject *&refpObj)
 Create the transient representation of an object.
 
virtual TObject * createPersistent (DataObject *pObj)
 Create the persistent representation of an object.
 
StatusCode createAddress (DataObject *pObject, TDirectory *pDir, TObject *pTObject, IOpaqueAddress *&refpAddr)
 Create address of the transient object according to the requested representation.
 
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)
 
- Protected Member Functions inherited from Converter
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator.
 
SmartIF< IMessageSvc > & msgSvc () const
 Retrieve pointer to message service.
 
SmartIF< IDataManagerSvc > & dataManager () const
 Get Data Manager service.
 
- Protected Member Functions inherited from implements< IConverter >
unsigned long decRef () const override
 

Detailed Description

NTuple converter class definition.

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

Constructor & Destructor Documentation

◆ RFileCnv()

RootHistCnv::RFileCnv::RFileCnv ( ISvcLocator * svc)

Standard constructor.

Definition at line 37 of file RFileCnv.cpp.

37: RDirectoryCnv( svc, classID() ) {}
RDirectoryCnv(ISvcLocator *svc)
Standard constructor.
static const CLID & classID()
Inquire class type.
Definition RFileCnv.h:48

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 60 of file RFileCnv.cpp.

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

◆ createRep()

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

Convert the transient object to the requested representation.

Definition at line 155 of file RFileCnv.cpp.

157{
158 refpAddress = pObject->registry()->address();
159 return RFileCnv::updateRep( refpAddress, pObject );
160}
IRegistry * registry() const
Get pointer to Registry.
Definition DataObject.h:79
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
StatusCode updateRep(IOpaqueAddress *pAddress, DataObject *pObject) override
Convert the transient object to the requested representation.
Definition RFileCnv.cpp:163

◆ initialize()

StatusCode RootHistCnv::RFileCnv::initialize ( )
override

Initialise.

Definition at line 40 of file RFileCnv.cpp.

40 {
41 // Set compression level property ...
42 const auto& optsSvc = serviceLocator()->getOptsSvc();
43 if ( optsSvc.has( "RFileCnv.GlobalCompression" ) ) {
44 auto sc = Gaudi::Parsers::parse( m_compLevel, optsSvc.get( "RFileCnv.GlobalCompression" ) );
45 if ( !sc ) return sc;
46 }
47 // initialise base class
48 return RDirectoryCnv::initialize().andThen( [&]() {
49 m_incSvc = service( "IncidentSvc" );
50 if ( !m_incSvc ) {
51 MsgStream( msgSvc() ) << MSG::ERROR << "Cannot access IncidentSvc" << endmsg;
53 }
55 } );
56}
StatusCode initialize() override
Initialize the converter.
Definition Converter.cpp:52
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
SmartIF< IService > service(const std::string &name, const bool createIf=true) const
Return a pointer to the service identified by name (or "type/name")
Gaudi::Interfaces::IOptionsSvc & getOptsSvc()
Direct access to Gaudi::Interfaces::IOptionsSvc implementation.
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition StatusCode.h:163
StatusCode parse(GaudiUtils::HashMap< K, V > &result, std::string_view input)
Basic parser for the types of HashMap used in DODBasicMapper.

◆ updateRep()

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

Convert the transient object to the requested representation.

Definition at line 163 of file RFileCnv.cpp.

165{
166 MsgStream log( msgSvc(), "RFileCnv" );
167 std::string ooname = pAddress->par()[1];
168
169 NTuple::File* pFile = dynamic_cast<NTuple::File*>( pObject );
170 if ( pFile && pFile->isOpen() ) {
171
172 unsigned long* ipar = (unsigned long*)pAddress->ipar();
173 if ( findTFile( ooname, rfile ).isFailure() ) {
174 log << MSG::ERROR << "Problems closing TFile " << ooname << endmsg;
175 return StatusCode::FAILURE;
176 }
177
178 rfile->Write( nullptr, TObject::kOverwrite );
179 if ( log.level() <= MSG::INFO ) {
180 log << MSG::INFO << "dumping contents of " << ooname << endmsg;
181 rfile->Print();
182 }
183
184 /*
185 * MetaData
186 * Ana Trisovic
187 * March 2015
188 * */
189 SmartIF<IMetaDataSvc> mds;
190 mds = serviceLocator()->service( "Gaudi::MetaDataSvc", false );
191 // auto mds = service<IMetaDataSvc>("MetaDataSvc", false);
192 if ( mds ) {
193 std::map<std::string, std::string> m_metadata = mds->getMetaDataMap();
194 if ( !rfile->WriteObject( &m_metadata, "info" ) ) { return StatusCode::FAILURE; }
195 }
196 /* */
197
198 rfile->Close();
199 delete rfile;
200
201 ipar[0] = 0;
202 pFile->setOpen( false );
203 return StatusCode::SUCCESS;
204
205 } else {
206 log << MSG::ERROR << "TFile " << ooname << " is not open" << endmsg;
207 }
208 return StatusCode::FAILURE;
209}
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
bool isOpen() const
Access "open" flag.
Definition NTuple.h:951

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.

◆ m_incSvc

SmartIF<IIncidentSvc> RootHistCnv::RFileCnv::m_incSvc
protected

Definition at line 56 of file RFileCnv.h.

◆ rfile

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

Pointer to ROOT file.

Definition at line 54 of file RFileCnv.h.

54{ nullptr };

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