All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

virtual StatusCode initialize ()
 Initialise. More...
 
virtual StatusCode createObj (IOpaqueAddress *pAddress, DataObject *&refpObject)
 Create the transient representation of an object. More...
 
virtual StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress)
 Convert the transient object to the requested representation. More...
 
virtual StatusCode updateRep (IOpaqueAddress *pAddress, DataObject *pObject)
 Convert the transient object to the requested representation. More...
 
 RFileCnv (ISvcLocator *svc)
 Standard constructor. More...
 
virtual ~RFileCnv ()
 Standard destructor. More...
 
- Public Member Functions inherited from RootHistCnv::RDirectoryCnv
virtual StatusCode fillObjRefs (IOpaqueAddress *pAddr, DataObject *refpObj)
 Update the transient object from the other representation. More...
 
 RDirectoryCnv (ISvcLocator *svc)
 Standard constructor. More...
 
 RDirectoryCnv (ISvcLocator *svc, const CLID &clid)
 Standard constructor. More...
 
virtual ~RDirectoryCnv ()
 Standard destructor. More...
 
- Public Member Functions inherited from RootHistCnv::RConverter
long repSvcType () const
 Retrieve the class type of the data store the converter uses. More...
 
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
virtual StatusCode finalize ()
 Initialize the converter. More...
 
virtual StatusCode setDataProvider (IDataProviderSvc *svc)
 Set Data provider service. More...
 
virtual SmartIF
< IDataProviderSvc > & 
dataProvider () const
 Get Data provider service. More...
 
virtual StatusCode setConversionSvc (IConversionSvc *svc)
 Set conversion service the converter is connected to. More...
 
virtual SmartIF< IConversionSvc > & conversionSvc () const
 Get conversion service the converter is connected to. More...
 
virtual StatusCode setAddressCreator (IAddressCreator *creator)
 Set address creator facility. More...
 
virtual SmartIF
< IAddressCreator > & 
addressCreator () const
 Retrieve address creator facility. More...
 
virtual const CLIDobjType () const
 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...
 
virtual StatusCode updateObj (IOpaqueAddress *pAddress, DataObject *refpObject)
 Update the transient object from the other representation. More...
 
virtual StatusCode updateObjRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Update the references of an updated transient object. More...
 
virtual StatusCode fillRepRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Resolve the references of the converted object. More...
 
virtual StatusCode updateRepRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 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 extend_interfaces1< IConverter >
virtual ~extend_interfaces1 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IConverter
 DeclareInterfaceID (IConverter, 3, 0)
 InterfaceID. More...
 
virtual ~IConverter ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IInterface
virtual void * i_cast (const InterfaceID &) const =0
 main cast function More...
 
virtual std::vector< std::string > getInterfaceNames () const =0
 Returns a vector of strings containing the names of all the implemented interfaces. More...
 
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long release ()=0
 Release Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)=0
 Set the void** to the pointer to the requested interface of the instance. More...
 
virtual ~IInterface ()
 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...
 
- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 

Protected Attributes

TFile * rfile
 Pointer to ROOT file. More...
 
std::string m_compLevel
 Compression setting. More...
 

Additional Inherited Members

- Public Types inherited from Converter
typedef
Gaudi::PluginService::Factory
< IConverter *, ISvcLocator * > 
Factory
 
- Public Types inherited from implements1< IConverter >
typedef implements1 base_class
 Typedef to this class. More...
 
typedef extend_interfaces1
< IConverter
extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from extend_interfaces1< IConverter >
typedef IConverter::iid::iids::type ext_iids
 MPL set of interfaces extended by this one. More...
 
- Public Types inherited from IConverter
enum  Status {
  INVALID_ADDRESS = IInterface::LAST_ERROR+1, INVALID_OBJECT, NO_MEMORY, BAD_STORAGE_TYPE,
  NO_SOURCE_OBJECT, ICONVERSIONSVC_LAST_ERROR
}
 Status code. More...
 
- Public Types inherited from IInterface
enum  Status { SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR }
 Return status. More...
 
typedef Gaudi::InterfaceId
< IInterface, 0, 0 > 
iid
 Interface ID. More...
 
typedef mpl::set1< iidext_iids
 Extra interfaces. More...
 
- Protected Member Functions inherited from RootHistCnv::RConverter
 RConverter (const CLID &clid, ISvcLocator *svc)
 Standard constructor. More...
 
virtual ~RConverter ()
 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
virtual ~Converter ()
 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 23 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  m_compLevel ( "" )
25 { }
static const CLID & classID()
Inquire class type.
Definition: RFileCnv.h:43
std::string m_compLevel
Compression setting.
Definition: RFileCnv.h:56
RDirectoryCnv(ISvcLocator *svc)
Standard constructor.
Definition: RDirectoryCnv.h:30
RootHistCnv::RFileCnv::~RFileCnv ( )
virtual

Standard destructor.

Definition at line 194 of file RFileCnv.cpp.

196 {
197 }

Member Function Documentation

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

Inquire class type.

Definition at line 43 of file RFileCnv.h.

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

Create the transient representation of an object.

Reimplemented from RootHistCnv::RDirectoryCnv.

Definition at line 45 of file RFileCnv.cpp.

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

Convert the transient object to the requested representation.

Reimplemented from RootHistCnv::RDirectoryCnv.

Definition at line 150 of file RFileCnv.cpp.

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

Initialise.

Reimplemented from Converter.

Definition at line 28 of file RFileCnv.cpp.

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

Convert the transient object to the requested representation.

Reimplemented from RootHistCnv::RDirectoryCnv.

Definition at line 159 of file RFileCnv.cpp.

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

Member Data Documentation

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

Compression setting.

Definition at line 56 of file RFileCnv.h.

TFile* RootHistCnv::RFileCnv::rfile
protected

Pointer to ROOT file.

Definition at line 55 of file RFileCnv.h.


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