THistSvc Class Reference

#include <src/THistSvc/THistSvc.h>

Inheritance diagram for THistSvc:
Collaboration diagram for THistSvc:

Classes

class  GlobalDirectoryRestore
 
struct  THistID
 

Public Member Functions

virtual StatusCode initialize ()
 Initialization (from CONFIGURED to INITIALIZED). More...
 
virtual StatusCode reinitialize ()
 Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED). More...
 
virtual StatusCode finalize ()
 Finalize (from INITIALIZED to CONFIGURED). More...
 
virtual StatusCode regHist (const std::string &name)
 
virtual StatusCode regHist (const std::string &name, TH1 *)
 
virtual StatusCode regHist (const std::string &name, TH2 *)
 
virtual StatusCode regHist (const std::string &name, TH3 *)
 
virtual StatusCode getHist (const std::string &name, TH1 *&) const
 
virtual StatusCode getHist (const std::string &name, TH2 *&) const
 
virtual StatusCode getHist (const std::string &name, TH3 *&) const
 
virtual StatusCode regTree (const std::string &name)
 
virtual StatusCode regTree (const std::string &name, TTree *)
 
virtual StatusCode getTree (const std::string &name, TTree *&) const
 
virtual StatusCode regGraph (const std::string &name)
 
virtual StatusCode regGraph (const std::string &name, TGraph *)
 
virtual StatusCode getGraph (const std::string &name, TGraph *&) const
 
virtual StatusCode deReg (TObject *obj)
 
virtual StatusCode deReg (const std::string &name)
 
virtual std::vector< std::string > getHists () const
 
virtual std::vector< std::string > getTrees () const
 
virtual std::vector< std::string > getGraphs () const
 
virtual StatusCode getTHists (TDirectory *td, TList &, bool recurse=false) const
 
virtual StatusCode getTHists (const std::string &name, TList &, bool recurse=false) const
 
virtual StatusCode getTHists (TDirectory *td, TList &tl, bool recurse=false, bool reg=false)
 
virtual StatusCode getTHists (const std::string &name, TList &tl, bool recurse=false, bool reg=false)
 
virtual StatusCode getTTrees (TDirectory *td, TList &, bool recurse=false) const
 
virtual StatusCode getTTrees (const std::string &name, TList &, bool recurse=false) const
 
virtual StatusCode getTTrees (TDirectory *td, TList &tl, bool recurse=false, bool reg=false)
 
virtual StatusCode getTTrees (const std::string &name, TList &tl, bool recurse=false, bool reg=false)
 
virtual bool exists (const std::string &name) const
 
 THistSvc (const std::string &name, ISvcLocator *svc)
 
void handle (const Incident &)
 Inform that a new incident has occurred. More...
 
virtual StatusCode io_reinit ()
 callback method to reinitialize the internal state of the component for I/O purposes (e.g. More...
 
- Public Member Functions inherited from extends3< Service, ITHistSvc, IIncidentListener, IIoComponent >
 extends3 (A1 a1, A2 a2, A3 a3)
 Templated constructor with 3 arguments. More...
 
 extends3 (A1 a1, A2 a2)
 Templated constructor with 2 arguments. More...
 
 extends3 (A1 a1)
 Templated constructor with 1 argument. More...
 
 extends3 ()
 Default constructor. More...
 
 extends3 (A1 a1, A2 a2, A3 a3)
 Templated constructor with 3 arguments. More...
 
 extends3 (A1 a1, A2 a2)
 Templated constructor with 2 arguments. More...
 
 extends3 (A1 a1)
 Templated constructor with 1 argument. More...
 
 extends3 ()
 Default constructor. More...
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast. More...
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface. More...
 
virtual std::vector< std::string > getInterfaceNames () const
 Implementation of IInterface::getInterfaceNames. More...
 
virtual std::vector< std::string > getInterfaceNames () const
 Implementation of IInterface::getInterfaceNames. More...
 
virtual ~extends3 ()
 Virtual destructor. More...
 
virtual ~extends3 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from Service
virtual unsigned long release ()
 Release Interface instance. More...
 
virtual const std::string & name () const
 Retrieve name of the service. More...
 
virtual StatusCode configure ()
 Configuration (from OFFLINE to CONFIGURED). More...
 
virtual StatusCode start ()
 Start (from INITIALIZED to RUNNING). More...
 
virtual StatusCode stop ()
 Stop (from RUNNING to INITIALIZED). More...
 
virtual StatusCode terminate ()
 Initialization (from CONFIGURED to OFFLINE). More...
 
virtual Gaudi::StateMachine::State FSMState () const
 Get the current state. More...
 
virtual Gaudi::StateMachine::State targetFSMState () const
 When we are in the middle of a transition, get the state where the transition is leading us. More...
 
virtual StatusCode restart ()
 Initialization (from RUNNING to RUNNING, via INITIALIZED). More...
 
virtual StatusCode sysInitialize ()
 Initialize Service. More...
 
virtual StatusCode sysStart ()
 Initialize Service. More...
 
virtual StatusCode sysStop ()
 Initialize Service. More...
 
virtual StatusCode sysFinalize ()
 Finalize Service. More...
 
virtual StatusCode sysReinitialize ()
 Re-initialize the Service. More...
 
virtual StatusCode sysRestart ()
 Re-initialize the Service. More...
 
virtual StatusCode setProperty (const Property &p)
 Set the property by property. More...
 
virtual StatusCode setProperty (const std::string &s)
 Set the property by string. More...
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 Set the property by std::string. More...
 
virtual StatusCode getProperty (Property *p) const
 Get the property by property. More...
 
virtual const PropertygetProperty (const std::string &name) const
 Get the property by name. More...
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 Get the property by std::string. More...
 
virtual const std::vector< Property * > & getProperties () const
 Get list of properties. More...
 
virtual bool hasProperty (const std::string &name) const
 Return true if we have a property with the given name. More...
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
virtual unsigned long release ()
 Release Interface instance. More...
 
virtual const std::string & name () const
 Retrieve name of the service. More...
 
virtual StatusCode configure ()
 Configuration (from OFFLINE to CONFIGURED). More...
 
virtual StatusCode start ()
 Start (from INITIALIZED to RUNNING). More...
 
virtual StatusCode stop ()
 Stop (from RUNNING to INITIALIZED). More...
 
virtual StatusCode terminate ()
 Initialization (from CONFIGURED to OFFLINE). More...
 
virtual Gaudi::StateMachine::State FSMState () const
 Get the current state. More...
 
virtual Gaudi::StateMachine::State targetFSMState () const
 When we are in the middle of a transition, get the state where the transition is leading us. More...
 
virtual StatusCode restart ()
 Initialization (from RUNNING to RUNNING, via INITIALIZED). More...
 
virtual StatusCode sysInitialize ()
 Initialize Service. More...
 
virtual StatusCode sysStart ()
 Initialize Service. More...
 
virtual StatusCode sysStop ()
 Initialize Service. More...
 
virtual StatusCode sysFinalize ()
 Finalize Service. More...
 
virtual StatusCode sysReinitialize ()
 Re-initialize the Service. More...
 
virtual StatusCode sysRestart ()
 Re-initialize the Service. More...
 
virtual StatusCode setProperty (const Property &p)
 Set the property by property. More...
 
virtual StatusCode setProperty (const std::string &s)
 Set the property by string. More...
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 Set the property by std::string. More...
 
virtual StatusCode getProperty (Property *p) const
 Get the property by property. More...
 
virtual const PropertygetProperty (const std::string &name) const
 Get the property by name. More...
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 Get the property by std::string. More...
 
virtual const std::vector< Property * > & getProperties () const
 Get list of properties. More...
 
virtual bool hasProperty (const std::string &name) const
 Return true if we have a property with the given name. More...
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
 CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
 Templated constructor with 3 arguments. More...
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments. More...
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument. More...
 
 CommonMessaging ()
 Default constructor. More...
 
 CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
 Templated constructor with 3 arguments. More...
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments. More...
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument. More...
 
 CommonMessaging ()
 Default constructor. More...
 
virtual ~CommonMessaging ()
 Virtual destructor. More...
 
virtual ~CommonMessaging ()
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces3< IService, IProperty, IStateful >
virtual ~extend_interfaces3 ()
 Virtual destructor. More...
 
virtual ~extend_interfaces3 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IService
 DeclareInterfaceID (IService, 3, 0)
 InterfaceID. More...
 
virtual ~IService ()
 virtual destructor More...
 
 DeclareInterfaceID (IService, 3, 0)
 InterfaceID. More...
 
virtual ~IService ()
 virtual destructor More...
 
- Public Member Functions inherited from INamedInterface
 DeclareInterfaceID (INamedInterface, 1, 0)
 InterfaceID. More...
 
virtual ~INamedInterface ()
 Virtual destructor (always needed for abstract classes). More...
 
 DeclareInterfaceID (INamedInterface, 1, 0)
 InterfaceID. More...
 
virtual ~INamedInterface ()
 Virtual destructor (always needed for abstract classes). More...
 
- Public Member Functions inherited from IInterface
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual ~IInterface ()
 Virtual destructor. More...
 
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual ~IInterface ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IProperty
 DeclareInterfaceID (IProperty, 2, 1)
 InterfaceID. More...
 
 DeclareInterfaceID (IProperty, 2, 1)
 InterfaceID. More...
 
- Public Member Functions inherited from IStateful
 DeclareInterfaceID (IStateful, 1, 0)
 InterfaceID. More...
 
virtual ~IStateful ()
 
 DeclareInterfaceID (IStateful, 1, 0)
 InterfaceID. More...
 
virtual ~IStateful ()
 
- Public Member Functions inherited from extend_interfaces3< ITHistSvc, IIncidentListener, IIoComponent >
virtual ~extend_interfaces3 ()
 Virtual destructor. More...
 
virtual ~extend_interfaces3 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from ITHistSvc
 DeclareInterfaceID (ITHistSvc, 2, 0)
 InterfaceID. More...
 
virtual ~ITHistSvc ()
 virtual destructor More...
 
 DeclareInterfaceID (ITHistSvc, 2, 0)
 InterfaceID. More...
 
virtual ~ITHistSvc ()
 virtual destructor More...
 
- Public Member Functions inherited from IIncidentListener
 DeclareInterfaceID (IIncidentListener, 2, 0)
 InterfaceID. More...
 
 DeclareInterfaceID (IIncidentListener, 2, 0)
 InterfaceID. More...
 
- Public Member Functions inherited from IIoComponent
 DeclareInterfaceID (IIoComponent, 1, 0)
 
virtual ~IIoComponent ()
 Destructor: More...
 
virtual StatusCode io_finalize ()
 
 DeclareInterfaceID (IIoComponent, 1, 0)
 
virtual ~IIoComponent ()
 Destructor: More...
 
virtual StatusCode io_finalize ()
 

Protected Member Functions

virtual ~THistSvc ()
 
- Protected Member Functions inherited from Service
virtual ~Service ()
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
virtual ~Service ()
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 

Private Types

enum  Mode {
  READ, WRITE, UPDATE, APPEND,
  SHARE, INVALID
}
 
typedef std::map< std::string, THistIDuidMap
 
typedef std::multimap< std::string, THistIDidMap
 
typedef std::map< TObject *, THistIDobjMap
 
typedef std::multimap< std::string, std::string > streamMap
 

Private Member Functions

template<typename T >
StatusCode regHist_i (T *hist, const std::string &name)
 
template<typename T >
StatusCode getHist_i (const std::string &name, T *&hist, bool quiet=false) const
 
template<typename T >
StatusCode readHist_i (const std::string &name, T *&hist) const
 
StatusCode readHist (const std::string &name, TH1 *&) const
 
StatusCode readHist (const std::string &name, TH2 *&) const
 
StatusCode readHist (const std::string &name, TH3 *&) const
 
StatusCode readTree (const std::string &name, TTree *&) const
 
void updateFiles ()
 
StatusCode write ()
 
StatusCode connect (const std::string &)
 
TDirectory * changeDir (const THistSvc::THistID &hid) const
 
std::string dirname (std::string &dir) const
 
void removeDoubleSlash (std::string &) const
 
bool browseTDir (TDirectory *dir) const
 
bool findStream (const std::string &name, std::string &root, std::string &rem, TFile *&file) const
 
void parseString (const std::string &id, std::string &root, std::string &rem) const
 
void setupInputFile (Property &inputfile)
 call-back method to handle input stream property More...
 
void setupOutputFile (Property &outputfile)
 call-back method to handle output stream property More...
 
void setupCompressionLevel (Property &cmp)
 
void copyFileLayout (TDirectory *, TDirectory *)
 helper function to recursively copy the layout of a TFile into a new TFile More...
 
void MergeRootFile (TDirectory *target, TDirectory *source)
 
StatusCode rootOpenAction (FILEMGR_CALLBACK_ARGS)
 
StatusCode rootOpenErrAction (FILEMGR_CALLBACK_ARGS)
 

Private Attributes

MsgStream m_log
 
StringArrayProperty m_inputfile
 
StringArrayProperty m_outputfile
 
std::vector< std::string > m_Rstream
 
std::vector< std::string > m_Wstream
 
IntegerProperty m_autoSave
 
IntegerProperty m_autoFlush
 
IntegerProperty m_compressionLevel
 
IntegerProperty m_maxFileSize
 
BooleanProperty m_print
 
std::set< std::string > m_alreadyConnectedInFiles
 list of already connected files. More...
 
std::set< std::string > m_alreadyConnectedOutFiles
 list of already connected files. More...
 
uidMap m_uids
 
idMap m_ids
 
objMap m_tobjs
 
std::map< std::string, std::pair< TFile *, Mode > > m_files
 
streamMap m_fileStreams
 
std::map< std::string, std::string > m_sharedFiles
 
bool signaledStop
 
bool m_delayConnect
 
bool m_okToConnect
 
std::string m_curstream
 
IIncidentSvcp_incSvc
 
IFileMgrp_fileMgr
 

Additional Inherited Members

- Public Types inherited from extends3< Service, ITHistSvc, IIncidentListener, IIoComponent >
typedef extends3 base_class
 Typedef to this class. More...
 
typedef extends3 base_class
 Typedef to this class. More...
 
typedef extend_interfaces3< ITHistSvc, IIncidentListener, IIoComponentextend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extend_interfaces3< ITHistSvc, IIncidentListener, IIoComponentextend_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...
 
typedef extend_interfaces_base::ext_iids interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from Service
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
 
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
 
- Public Types inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
typedef CommonMessaging base_class
 
typedef CommonMessaging base_class
 
- Public Types inherited from implements3< IService, IProperty, IStateful >
typedef implements3 base_class
 Typedef to this class. More...
 
typedef implements3 base_class
 Typedef to this class. More...
 
typedef extend_interfaces3< IService, IProperty, IStatefulextend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extend_interfaces3< IService, IProperty, IStatefulextend_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...
 
typedef extend_interfaces_base::ext_iids interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from extend_interfaces3< IService, IProperty, IStateful >
typedef mpl::fold< typename IService::iid::iids::type, typename mpl::fold< typename IProperty::iid::iids::type, typename IStateful::iid::iids::type, mpl::insert< mpl::_1, mpl::_2 > >::type, mpl::insert< mpl::_1, mpl::_2 > >::type ext_iids
 MPL set of interfaces extended by this one. More...
 
typedef mpl::fold< typename IService::iid::iids::type, typename mpl::fold< typename IProperty::iid::iids::type, typename IStateful::iid::iids::type, mpl::insert< mpl::_1, mpl::_2 > >::type, mpl::insert< mpl::_1, mpl::_2 > >::type ext_iids
 MPL set of interfaces extended by this one. More...
 
- Public Types inherited from IInterface
enum  Status {
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR,
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR
}
 Return status. More...
 
enum  Status {
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR,
  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...
 
typedef Gaudi::InterfaceId< IInterface, 0, 0 > iid
 Interface ID. More...
 
typedef mpl::set1< iidext_iids
 Extra interfaces. More...
 
- Public Types inherited from extend_interfaces3< ITHistSvc, IIncidentListener, IIoComponent >
typedef mpl::fold< typename ITHistSvc::iid::iids::type, typename mpl::fold< typename IIncidentListener::iid::iids::type, typename IIoComponent::iid::iids::type, mpl::insert< mpl::_1, mpl::_2 > >::type, mpl::insert< mpl::_1, mpl::_2 > >::type ext_iids
 MPL set of interfaces extended by this one. More...
 
typedef mpl::fold< typename ITHistSvc::iid::iids::type, typename mpl::fold< typename IIncidentListener::iid::iids::type, typename IIoComponent::iid::iids::type, mpl::insert< mpl::_1, mpl::_2 > >::type, mpl::insert< mpl::_1, mpl::_2 > >::type ext_iids
 MPL set of interfaces extended by this one. More...
 
- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel
 Service output level. More...
 
Gaudi::StateMachine::State m_state
 Service state. More...
 
Gaudi::StateMachine::State m_targetState
 Service state. More...
 
- Protected Attributes inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
SmartIF< IMessageSvcm_msgsvc
 Pointer to the message service;. More...
 
std::auto_ptr< MsgStreamm_msgStream
 The predefined message stream. More...
 
bool m_streamWithService
 Flag to create a new MsgStream if it was created without the message service. More...
 

Detailed Description

Definition at line 26 of file THistSvc.h.

Member Typedef Documentation

typedef std::multimap<std::string, THistID> THistSvc::idMap
private

Definition at line 195 of file THistSvc.h.

typedef std::map<TObject*, THistID> THistSvc::objMap
private

Definition at line 196 of file THistSvc.h.

typedef std::multimap<std::string, std::string> THistSvc::streamMap
private

Definition at line 197 of file THistSvc.h.

typedef std::map<std::string, THistID> THistSvc::uidMap
private

Definition at line 194 of file THistSvc.h.

Member Enumeration Documentation

enum THistSvc::Mode
private
Enumerator
READ 
WRITE 
UPDATE 
APPEND 
SHARE 
INVALID 

Definition at line 105 of file THistSvc.h.

105  {
106  READ,
107  WRITE,
108  UPDATE,
109  APPEND,
110  SHARE,
111  INVALID
112  };

Constructor & Destructor Documentation

THistSvc::THistSvc ( const std::string &  name,
ISvcLocator svc 
)

Definition at line 48 of file THistSvc.cpp.

49  : base_class(name, svc), m_log(msgSvc(), name ), signaledStop(false),
50  m_delayConnect(false),m_okToConnect(false),
51  p_incSvc(0), p_fileMgr(0) {
52 
53  declareProperty ("AutoSave", m_autoSave=0 );
54  declareProperty ("AutoFlush", m_autoFlush=0 );
55  declareProperty ("PrintAll", m_print=false);
56  declareProperty ("MaxFileSize", m_maxFileSize=10240,
57  "maximum file size in MB. if exceeded, will cause an abort. -1 to never check.");
61 
62 
63 }
bool m_delayConnect
Definition: THistSvc.h:209
IntegerProperty m_autoFlush
Definition: THistSvc.h:182
IntegerProperty m_autoSave
Definition: THistSvc.h:182
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
IIncidentSvc * p_incSvc
Definition: THistSvc.h:213
bool signaledStop
Definition: THistSvc.h:208
void setupCompressionLevel(Property &cmp)
Definition: THistSvc.cpp:1278
StringArrayProperty m_inputfile
Definition: THistSvc.h:180
BooleanProperty m_print
Definition: THistSvc.h:183
virtual void declareUpdateHandler(PropertyCallbackFunctor *pf)
set new callback for update
Definition: Property.cpp:141
StringArrayProperty m_outputfile
Definition: THistSvc.h:180
void setupOutputFile(Property &outputfile)
call-back method to handle output stream property
Definition: THistSvc.cpp:1337
bool m_okToConnect
Definition: THistSvc.h:209
IntegerProperty m_maxFileSize
Definition: THistSvc.h:182
IntegerProperty m_compressionLevel
Definition: THistSvc.h:182
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
IFileMgr * p_fileMgr
Definition: THistSvc.h:214
MsgStream m_log
Definition: THistSvc.h:178
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:212
void setupInputFile(Property &inputfile)
call-back method to handle input stream property
Definition: THistSvc.cpp:1291
THistSvc::~THistSvc ( )
protectedvirtual

Definition at line 67 of file THistSvc.cpp.

67  {
68 
69 }

Member Function Documentation

bool THistSvc::browseTDir ( TDirectory *  dir) const
private

Definition at line 413 of file THistSvc.cpp.

413  {
414 
415  if (dir == 0) {
416  std::cerr << "TDirectory == 0" << std::endl;
417  return false;
418  }
419 
420  GlobalDirectoryRestore restore;
421 
422  dir->cd();
423 
424 
425  cout << "-> " << dir->GetPath() << " "
426  << dir->GetListOfKeys()->GetSize() << endl;
427 
428  // TIter nextkey(dir->GetListOfKeys());
429  TIter nextkey(dir->GetList());
430  while (TKey *key = (TKey*)nextkey()) {
431 
432  TObject *obj = key->ReadObj();
433  if (obj == 0) { cout << key->GetName() << " obj==0"<< endl; continue; }
434  // if (obj->IsA()->InheritsFrom("TDirectory")) {
435  cout << " Key: " << key->GetName() << " "
436  << " tit: " << obj->GetTitle() << " "
437  << " (" << key->GetClassName() << ")" << endl;
438  // }
439  }
440 
441  nextkey = dir->GetListOfKeys();
442  while (TKey *key = (TKey*)nextkey()) {
443 
444  TObject *obj = key->ReadObj();
445  if (obj == 0) { cout << key->GetName() << " obj==0"<< endl; continue; }
446  if (obj->IsA()->InheritsFrom("TDirectory")) {
447  TDirectory *tt = dynamic_cast<TDirectory*>(obj);
448  browseTDir(tt);
449  }
450  }
451 
452  return true;
453 }
bool browseTDir(TDirectory *dir) const
Definition: THistSvc.cpp:413
TDirectory * THistSvc::changeDir ( const THistSvc::THistID hid) const
private

Definition at line 1743 of file THistSvc.cpp.

1743  {
1744 
1745  string uid = hid.id;
1746  TFile* file = hid.file;
1747  string stream, fdir, bdir, dir, id;
1748 
1749  if (file != 0) {
1750  file->cd("/");
1751  } else {
1752  gROOT->cd();
1753  }
1754 
1755  fdir = uid;
1756  bdir = dirname(fdir);
1757 
1758  while ( (dir = dirname(fdir)) != "") {
1759  if (! gDirectory->GetKey(dir.c_str())) {
1760  gDirectory->mkdir(dir.c_str());
1761  }
1762  gDirectory->cd(dir.c_str());
1763  }
1764 
1765  return gDirectory;
1766 
1767 }
std::string id
Definition: THistSvc.h:115
std::string dirname(std::string &dir) const
Definition: THistSvc.cpp:1772
list file
Definition: ana.py:160
StatusCode THistSvc::connect ( const std::string &  ident)
private

Definition at line 1512 of file THistSvc.cpp.

1512  {
1513 
1514  string::size_type loc = ident.find(" ");
1515  string stream = ident.substr(0,loc);
1516  char typ(0);
1517  typedef std::pair<std::string,std::string> Prop;
1518  std::vector<Prop> props;
1519  string filename, db_typ("ROOT");
1520  int cl(1);
1521 
1522  if (loc != string::npos) {
1523  using Parser = Gaudi::Utils::AttribStringParser;
1524  for (auto attrib: Parser(ident.substr(loc + 1))) {
1525  auto TAG = attrib.tag;
1526  toupper(TAG);
1527 
1528  auto VAL = attrib.value;
1529  toupper(VAL);
1530 
1531  if (TAG == "FILE" || TAG == "DATAFILE") {
1532  filename = attrib.value;
1533  removeDoubleSlash( filename );
1534  } else if ( TAG == "OPT" ) {
1535  if ( VAL == "APPEND" || VAL == "UPDATE" ) {
1536  typ = 'A';
1537  } else if ( VAL == "CREATE" || VAL == "NEW" || VAL == "WRITE" ) {
1538  typ = 'N';
1539  } else if ( VAL == "RECREATE" ) {
1540  typ = 'R';
1541  } else if (VAL == "SHARE") {
1542  typ = 'S';
1543  } else if ( VAL == "OLD" || VAL == "READ" ) {
1544  typ = 'O';
1545  } else {
1546  m_log << MSG::ERROR << "Unknown OPT: \"" << attrib.value << "\""
1547  << endmsg;
1548  typ = 0;
1549  }
1550  } else if (TAG == "TYP") {
1551  db_typ = std::move(attrib.value);
1552  } else if (TAG == "CL") {
1553  cl = atoi(attrib.value.c_str());
1554  } else {
1555  props.push_back( Prop(attrib.tag, attrib.value));
1556  }
1557 
1558  }
1559  }
1560 
1561  if (stream == "temp") {
1562  m_log << MSG::ERROR << "in JobOption \"" << ident
1563  << "\": stream name \"temp\" reserved."
1564  << endmsg;
1565  return StatusCode::FAILURE;
1566  }
1567 
1568  if (db_typ != "ROOT") {
1569  m_log << MSG::ERROR << "in JobOption \"" << ident
1570  << "\": technology type \"" << db_typ << "\" not supported."
1571  << endmsg;
1572  return StatusCode::FAILURE;
1573  }
1574 
1575 
1576  if (m_files.find(stream) != m_files.end()) {
1577  m_log << MSG::ERROR << "in JobOption \"" << ident
1578  << "\":\n stream \"" << stream << "\" already connected to file: \""
1579  << m_files[stream].first->GetName() << "\""
1580  << endmsg;
1581  return StatusCode::FAILURE;
1582  }
1583 
1584  Mode newMode;
1585  if (typ == 'O') {
1586  newMode = THistSvc::READ;
1587  } else if (typ == 'N') {
1588  newMode = THistSvc::WRITE;
1589  } else if (typ == 'A') {
1590  newMode = THistSvc::APPEND;
1591  } else if (typ == 'R') {
1592  newMode = THistSvc::UPDATE;
1593  } else if (typ == 'S') {
1594  newMode = THistSvc::SHARE;
1595  } else {
1596  // something else?
1597  m_log << MSG::ERROR << "No OPT= specified or unknown access mode in: "
1598  << ident << endmsg;
1599  return StatusCode::FAILURE;
1600  }
1601 
1602  // Is this file already connected to another stream?
1603  if (m_fileStreams.find(filename) != m_fileStreams.end()) {
1604  std::pair<streamMap::iterator, streamMap::iterator> fitr =
1605  m_fileStreams.equal_range(filename);
1606 
1607  std::string oldstream = (fitr.first)->second;
1608 
1609  std::pair<TFile*,Mode> f_info = m_files[oldstream];
1610 
1611  if (newMode != f_info.second) {
1612  m_log << MSG::ERROR << "in JobOption \"" << ident
1613  << "\":\n file \"" << filename << "\" already opened by stream: \""
1614  << oldstream << "\" with different access mode."
1615  << endmsg;
1616  return StatusCode::FAILURE;
1617  } else {
1618  TFile *f2 = f_info.first;
1619  m_files[stream] = make_pair(f2,newMode);
1620  if (m_log.level() <= MSG::DEBUG)
1621  m_log << MSG::DEBUG << "Connecting stream: \"" << stream
1622  << "\" to previously opened TFile: \"" << filename << "\""
1623  << endmsg;
1624  return StatusCode::SUCCESS;
1625  }
1626  }
1627 
1628 
1629  IIncidentSvc *pi(0);
1630  if (service("IncidentSvc",pi).isFailure()) {
1631  m_log << MSG::ERROR << "Unable to get the IncidentSvc" << endmsg;
1632  return StatusCode::FAILURE;
1633  }
1634 
1635  void* vf(0);
1636  TFile *f(0);
1637 
1638  if (newMode == THistSvc::READ) {
1639  // old file
1640 
1641  int r = p_fileMgr->open(Io::ROOT,name(), filename,Io::READ,vf,"HIST");
1642 
1643  if (r != 0) {
1644  m_log << "Unable to open ROOT file " << filename << " for reading"
1645  << endmsg;
1646  return StatusCode::FAILURE;
1647  }
1648 
1649 
1650  f = (TFile*) vf;
1651 
1652  // FIX ME!
1653  pi->fireIncident(FileIncident(name(), "BeginHistFile",
1654  filename));
1655 
1656 
1657  } else if (newMode == THistSvc::WRITE) {
1658  // new file. error if file exists
1659 
1660  int r = p_fileMgr->open(Io::ROOT,name(),filename, (Io::WRITE|Io::CREATE|Io::EXCL),
1661  vf,"HIST");
1662 
1663  if (r != 0) {
1664  m_log << "Unable to open ROOT file " << filename << " for writing"
1665  << endmsg;
1666  return StatusCode::FAILURE;
1667  }
1668 
1669  f = (TFile*)vf;
1670 
1671  } else if (newMode == THistSvc::APPEND) {
1672  // update file
1673 
1674  int r = p_fileMgr->open(Io::ROOT,name(),filename, (Io::WRITE | Io::APPEND),
1675  vf,"HIST");
1676  if (r != 0) {
1677  m_log << MSG::ERROR << "unable to open file \"" << filename
1678  << "\" for appending" << endmsg;
1679  return StatusCode::FAILURE;
1680  }
1681 
1682  f = (TFile*) vf;
1683 
1684 
1685  } else if (newMode == THistSvc::SHARE) {
1686  // SHARE file type
1687  //For SHARE files, all data will be stored in a temp file and will be merged into the target file
1688  //in write() when finalize(), this help to solve some confliction. e.g. with storegate
1689 
1690  static int ishared = 0;
1691  stringstream out;
1692  string realfilename=filename;
1693  out << ishared++;
1694  filename = string("tmp_THistSvc_")+out.str()+string(".root");
1695 
1696  if (m_log.level() <= MSG::DEBUG)
1697  m_log << MSG::DEBUG << "Creating temp file \"" << filename
1698  << "\" and realfilename="<<realfilename << endmsg;
1699  m_sharedFiles[stream]=realfilename;
1700 
1701 
1702  int r = p_fileMgr->open(Io::ROOT,name(), filename, (Io::WRITE|Io::CREATE|Io::EXCL),
1703  vf,"HIST");
1704 
1705  if (r != 0) {
1706  m_log << "Unable to open ROOT file " << filename << " for writing"
1707  << endmsg;
1708  return StatusCode::FAILURE;
1709  }
1710 
1711  f = (TFile*)vf;
1712 
1713  } else if (newMode == THistSvc::UPDATE) {
1714  // update file
1715 
1716  int r = p_fileMgr->open(Io::ROOT,name(), filename, (Io::WRITE|Io::CREATE),
1717  vf, "HIST");
1718 
1719  if (r != 0) {
1720  m_log << "Unable to open ROOT file " << filename << " for appending"
1721  << endmsg;
1722  return StatusCode::FAILURE;
1723  }
1724 
1725  f = (TFile*)vf;
1726 
1727  }
1728 
1729  m_files[stream] = make_pair(f,newMode);
1730  m_fileStreams.insert(make_pair(filename,stream));
1731 
1732  if (m_log.level() <= MSG::DEBUG)
1733  m_log << MSG::DEBUG << "Opening TFile \"" << filename << "\" stream: \""
1734  << stream << "\" mode: \"" << typ << "\"" << " comp level: " << cl
1735  << endmsg;
1736 
1737  return StatusCode::SUCCESS;
1738 }
This class is the FileIncident.
Definition: FileIncident.h:18
virtual Io::open_t open(const Io::IoTech &, const std::string &caller, const std::string &fname, const Io::IoFlags &, Io::Fd &, void *&, const std::string &desc, const bool shared=false)=0
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
constexpr double second
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
std::map< std::string, std::string > m_sharedFiles
Definition: THistSvc.h:206
void toupper(std::string &s)
Definition: THistSvc.cpp:39
IFileMgr * p_fileMgr
Definition: THistSvc.h:214
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:143
MsgStream m_log
Definition: THistSvc.h:178
constexpr double pi
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:22
streamMap m_fileStreams
Definition: THistSvc.h:204
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1810
void THistSvc::copyFileLayout ( TDirectory *  dst,
TDirectory *  src 
)
private

helper function to recursively copy the layout of a TFile into a new TFile

Definition at line 1966 of file THistSvc.cpp.

1966  {
1967 
1968  if (m_log.level() <= MSG::DEBUG)
1969  m_log << MSG::DEBUG
1970  << "copyFileLayout() to dst path: " << dst->GetPath () << endmsg;
1971 
1972  // strip out URLs
1973  TString path ((char*)strstr (dst->GetPath(), ":"));
1974  path.Remove (0, 2);
1975 
1976  src->cd (path);
1977  TDirectory *cur_src_dir = gDirectory;
1978 
1979  // loop over all keys in this directory
1980  TList *key_list = cur_src_dir->GetListOfKeys ();
1981  int n = key_list->GetEntries ();
1982  for ( int j = 0; j < n; ++j ) {
1983  TKey *k = (TKey*)key_list->At (j);
1984  const std::string src_pathname = cur_src_dir->GetPath()
1985  + std::string("/")
1986  + k->GetName();
1987  TObject *o=src->Get (src_pathname.c_str());
1988 
1989  if (o != NULL && o->IsA()->InheritsFrom ("TDirectory")) {
1990  if (m_log.level() <= MSG::VERBOSE)
1991  m_log << MSG::VERBOSE << " subdir [" << o->GetName() << "]..."
1992  << endmsg;
1993  dst->cd ();
1994  TDirectory * dst_dir = dst->mkdir (o->GetName(), o->GetTitle());
1995  copyFileLayout (dst_dir, src);
1996  }
1997  } // loop over keys
1998  return;
1999 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
list path
Definition: __init__.py:15
void copyFileLayout(TDirectory *, TDirectory *)
helper function to recursively copy the layout of a TFile into a new TFile
Definition: THistSvc.cpp:1966
MsgStream m_log
Definition: THistSvc.h:178
StatusCode THistSvc::deReg ( TObject *  obj)
virtual

Implements ITHistSvc.

Definition at line 929 of file THistSvc.cpp.

929  {
930 
931  objMap::iterator itr = m_tobjs.find(obj);
932  if (itr != m_tobjs.end()) {
933  THistID hid = itr->second;
934 
935  uidMap::iterator itr2 = m_uids.find(hid.id);
936  if (itr2 == m_uids.end()) {
937  m_log << MSG::ERROR << "Problems deregistering TObject \""
938  << obj->GetName()
939  << "\" with id \"" << hid.id << "\"" << endmsg;
940  return StatusCode::FAILURE;
941  }
942 
943  std::string id,root,rem;
944  parseString(hid.id, root, rem);
945 
946  idMap::iterator itr3;
947  bool found(false);
948 
949  std::pair<idMap::iterator, idMap::iterator> mitr = m_ids.equal_range(rem);
950  if (mitr.first == mitr.second) {
951  m_log << MSG::ERROR << "Problems deregistering TObject \""
952  << obj->GetName()
953  << "\" with id \"" << hid.id << "\"" << endmsg;
954  return StatusCode::FAILURE;
955  } else {
956  for (itr3 = mitr.first; itr3 != mitr.second; ++itr3) {
957  if (itr3->second.obj == obj) {
958  found = true;
959  break;
960  }
961  }
962  if (!found) {
963  m_log << MSG::ERROR << "Problems deregistering TObject \""
964  << obj->GetName()
965  << "\" with id \"" << hid.id << "\"" << endmsg;
966  }
967  }
968 
969  m_tobjs.erase(itr);
970  m_uids.erase(itr2);
971  m_ids.erase(itr3);
972 
973  return StatusCode::SUCCESS;
974 
975  } else {
976  m_log << MSG::ERROR << "Cannot unregister TObject \"" << obj->GetName()
977  << "\": not known to THistSvc" << endmsg;
978  return StatusCode::FAILURE;
979  }
980 
981 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
objMap m_tobjs
Definition: THistSvc.h:201
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1257
uidMap m_uids
Definition: THistSvc.h:199
idMap m_ids
Definition: THistSvc.h:200
tuple root
Definition: IOTest.py:42
MsgStream m_log
Definition: THistSvc.h:178
StatusCode THistSvc::deReg ( const std::string &  name)
virtual

Implements ITHistSvc.

Definition at line 987 of file THistSvc.cpp.

987  {
988 
989  uidMap::iterator itr = m_uids.find(id);
990  if (itr == m_uids.end()) {
991  m_log << MSG::ERROR << "Problems deregistering id \""
992  << id << "\"" << endmsg;
993  return StatusCode::FAILURE;
994  }
995 
996  TObject* obj = itr->second.obj;
997 
998  return deReg(obj);
999 }
virtual StatusCode deReg(TObject *obj)
Definition: THistSvc.cpp:929
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
uidMap m_uids
Definition: THistSvc.h:199
MsgStream m_log
Definition: THistSvc.h:178
std::string THistSvc::dirname ( std::string &  dir) const
private

Definition at line 1772 of file THistSvc.cpp.

1772  {
1773 
1774 
1775  string::size_type i = dir.find("/");
1776 
1777  if (i == string::npos) {
1778  return "";
1779  }
1780 
1781  if ( i == 0 ) {
1782  dir.erase(0,1);
1783  return dirname(dir);
1784  }
1785 
1786  string root = dir.substr(0,i);
1787  dir.erase(0,i);
1788 
1789  return root;
1790 
1791 }
std::string dirname(std::string &dir) const
Definition: THistSvc.cpp:1772
tuple root
Definition: IOTest.py:42
list i
Definition: ana.py:128
bool THistSvc::exists ( const std::string &  name) const
virtual

Implements ITHistSvc.

Definition at line 1896 of file THistSvc.cpp.

1896  {
1897 
1898  TH1* h;
1899 
1900  return getHist_i(name,h,true).isSuccess();
1901 
1902 
1903 }
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
StatusCode getHist_i(const std::string &name, T *&hist, bool quiet=false) const
Definition: THistSvc.icc:142
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
StatusCode THistSvc::finalize ( )
virtual

Finalize (from INITIALIZED to CONFIGURED).

Reimplemented from Service.

Definition at line 247 of file THistSvc.cpp.

247  {
248 
249  GlobalDirectoryRestore restore;
250 
251  if (m_log.level() <= MSG::DEBUG)
252  m_log << MSG::DEBUG << "THistSvc::finalize" << endmsg;
253 
254 #ifndef NDEBUG
255  if (m_log.level() <= MSG::DEBUG) {
256  uidMap::const_iterator uitr;
257  for (uitr=m_uids.begin(); uitr != m_uids.end(); ++uitr) {
258 
259  TObject* to = uitr->second.obj;
260 
261  string dirname("none");
262  if (to && to->IsA()->InheritsFrom("TTree")) {
263  TTree* tr = dynamic_cast<TTree*>(to);
264  if (tr->GetDirectory() != 0) {
265  dirname = tr->GetDirectory()->GetPath();
266  }
267  } else if (to && to->IsA()->InheritsFrom("TGraph")) {
268  if (!uitr->second.temp) {
269  dirname = uitr->second.file->GetPath();
270  string id2(uitr->second.id);
271  id2.erase(0,id2.find("/",1));
272  id2.erase(id2.rfind("/"), id2.length());
273  if (id2.find("/") == 0) {
274  id2.erase(0,1);
275  }
276  dirname += id2;
277  } else {
278  dirname = "/tmp";
279  }
280  } else if (to && to->IsA()->InheritsFrom("TH1")) {
281  TH1* th = dynamic_cast<TH1*>(to);
282  if (th == 0) {
283  m_log << MSG::ERROR << "Couldn't dcast: " << uitr->first << endmsg;
284  } else {
285  if (th->GetDirectory() != 0) {
286  dirname = th->GetDirectory()->GetPath();
287  }
288  }
289  } else if (! to ) {
290  m_log << MSG::WARNING << uitr->first << " has NULL TObject ptr"
291  << endmsg;
292  }
293 
294  m_log << MSG::DEBUG << "uid: \"" << uitr->first << "\" temp: "
295  << uitr->second.temp << " dir: " << dirname
296  << endmsg;
297  }
298  }
299 #endif
300 
301  StatusCode sc = write();
302  if (sc.isFailure()) {
303  m_log << MSG::ERROR << "problems writing histograms" << endmsg;
304  }
305 
306  if (m_print) {
307  m_log << MSG::INFO << "Listing contents of ROOT files: " << endmsg;
308  }
309  vector<TFile*> deleted_files;
310  map<string, pair<TFile*,Mode> >::const_iterator itr;
311  for (itr = m_files.begin(); itr != m_files.end(); ++itr) {
312 
313  if (find(deleted_files.begin(), deleted_files.end(), itr->second.first) ==
314  deleted_files.end()) {
315  deleted_files.push_back(itr->second.first);
316 
317 #ifndef NDEBUG
318  if (m_log.level() <= MSG::DEBUG)
319  m_log << MSG::DEBUG << "finalizing stream/file " << itr->first << ":"
320  << itr->second.first->GetName()
321  << endmsg;
322 #endif
323  } else {
324 #ifndef NDEBUG
325  if (m_log.level() <= MSG::DEBUG)
326  m_log << MSG::DEBUG << "already finalized stream " << itr->first << endmsg;
327 #endif
328  continue;
329  }
330 
331 
332  if (m_print && m_log.level() <= MSG::INFO) {
333 
334  m_log << MSG::INFO;
335  m_log << "==> File: " << itr->second.first->GetName()
336  << " stream: " << itr->first << endmsg;
337 
338  itr->second.first->Print("base");
339  }
340 
341  string tmpfn=itr->second.first->GetName();
342 
343  p_fileMgr->close(itr->second.first, name());
344 
345  IIncidentSvc *pi(0);
346  if (service("IncidentSvc",pi).isFailure()) {
347  m_log << MSG::ERROR << "Unable to get the IncidentSvc" << endmsg;
348  return StatusCode::FAILURE;
349  }
350 
351  if (itr->second.second==SHARE) {
352 
353  //Merge File
354  void* vf(0);
355  int r = p_fileMgr->open(Io::ROOT,name(), m_sharedFiles[itr->first],
356  Io::WRITE|Io::APPEND,vf,"HIST");
357 
358  if (r != 0 ) {
359  m_log << MSG::ERROR << "unable to open Final Output File: \""
360  << m_sharedFiles[itr->first] << "\" for merging"
361  << endmsg;
362  return StatusCode::FAILURE;
363  }
364 
365  TFile *outputfile = (TFile*) vf;
367  m_sharedFiles[itr->first]));
368 
369  if (m_log.level() <= MSG::DEBUG)
370  m_log << MSG::DEBUG << "THistSvc::write()::Merging Rootfile "<<endmsg;
371 
372  vf = 0;
373  r = p_fileMgr->open(Io::ROOT,name(),tmpfn,Io::READ,vf,"HIST");
374 
375  if (r != 0) {
376  m_log << MSG::ERROR << "unable to open temporary file: \""
377  << tmpfn << endmsg;
378  return StatusCode::FAILURE;
379  }
380 
381  TFile *inputfile = (TFile*) vf;
382 
383  outputfile->SetCompressionLevel( inputfile->GetCompressionLevel() );
384 
385  MergeRootFile(outputfile, inputfile);
386 
387  outputfile->Write();
388  p_fileMgr->close(outputfile,name());
389  p_fileMgr->close(inputfile,name());
390 
391  if (m_log.level() <= MSG::DEBUG)
392  m_log << MSG::DEBUG << "Trying to remove temporary file \"" << tmpfn
393  << "\""<<endmsg;
394 
395  std::remove(tmpfn.c_str());
396  }
397  delete itr->second.first;
398  }
399 
400  m_sharedFiles.clear();
401  m_fileStreams.clear();
402  m_files.clear();
403  m_uids.clear();
404  m_ids.clear();
405  m_tobjs.clear();
406 
407  return Service::finalize();
408 }
This class is the FileIncident.
Definition: FileIncident.h:18
virtual Io::open_t open(const Io::IoTech &, const std::string &caller, const std::string &fname, const Io::IoFlags &, Io::Fd &, void *&, const std::string &desc, const bool shared=false)=0
def remove(file, logdir)
Definition: install.py:153
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
objMap m_tobjs
Definition: THistSvc.h:201
StatusCode write()
Definition: THistSvc.cpp:1478
BooleanProperty m_print
Definition: THistSvc.h:183
std::string dirname(std::string &dir) const
Definition: THistSvc.cpp:1772
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
std::map< std::string, std::string > m_sharedFiles
Definition: THistSvc.h:206
uidMap m_uids
Definition: THistSvc.h:199
idMap m_ids
Definition: THistSvc.h:200
IFileMgr * p_fileMgr
Definition: THistSvc.h:214
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:143
const std::string WroteToOutputFile
the output file was written to in this event
Definition: Incident.h:74
MsgStream m_log
Definition: THistSvc.h:178
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
Definition: Service.cpp:197
constexpr double pi
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:22
streamMap m_fileStreams
Definition: THistSvc.h:204
void MergeRootFile(TDirectory *target, TDirectory *source)
Definition: THistSvc.cpp:1820
virtual Io::close_t close(const Io::Fd, const std::string &caller)=0
bool THistSvc::findStream ( const std::string &  name,
std::string &  root,
std::string &  rem,
TFile *&  file 
) const
private

Definition at line 1210 of file THistSvc.cpp.

1211  {
1212 
1213  string::size_type pos = id.find("/");
1214 
1215  if (pos == string::npos) {
1216  stream = "temp";
1217  rem = id;
1218  } else if (pos != 0) {
1219  stream = "temp";
1220  rem = id;
1221  } else {
1222 
1223  string::size_type pos2 = id.find("/",pos+1);
1224 
1225  if (pos2 == string::npos) {
1226  m_log << MSG::ERROR << "badly formed Hist/Tree id: \"" << id << "\""
1227  << endmsg;
1228  return false;
1229  }
1230 
1231  parseString(id,stream,rem);
1232 
1233  }
1234 
1235  if (stream == "temp") {
1236  file = 0;
1237  return true;
1238  }
1239 
1240  map< string,pair<TFile*,Mode> >::const_iterator itr = m_files.find(stream);
1241  if (itr != m_files.end()) {
1242  file = itr->second.first;
1243  } else {
1244  file = 0;
1245  m_log << MSG::WARNING << "no stream \"" << stream
1246  << "\" associated with id: \"" << id << "\""
1247  << endmsg;
1248  }
1249 
1250  return true;
1251 
1252 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1257
list file
Definition: ana.py:160
MsgStream m_log
Definition: THistSvc.h:178
StatusCode THistSvc::getGraph ( const std::string &  name,
TGraph *&  hist 
) const
virtual

Implements ITHistSvc.

Definition at line 1154 of file THistSvc.cpp.

1154  {
1155  return getHist_i(id, hist);
1156 }
StatusCode getHist_i(const std::string &name, T *&hist, bool quiet=false) const
Definition: THistSvc.icc:142
std::vector< std::string > THistSvc::getGraphs ( ) const
virtual

Implements ITHistSvc.

Definition at line 1161 of file THistSvc.cpp.

1161  {
1162 
1163  std::vector<std::string> names;
1164  names.reserve(m_uids.size());
1165 
1166  uidMap::const_iterator itr;
1167  for (itr = m_uids.begin(); itr != m_uids.end(); ++itr) {
1168  THistID tid = itr->second;
1169 
1170  if (tid.obj->IsA()->InheritsFrom("TGraph")) {
1171  names.push_back(itr->first);
1172  }
1173 
1174  }
1175 
1176  return names;
1177 
1178 }
std::string names[100]
Definition: Node.cpp:19
uidMap m_uids
Definition: THistSvc.h:199
StatusCode THistSvc::getHist ( const std::string &  name,
TH1 *&  hist 
) const
virtual

Implements ITHistSvc.

Definition at line 1084 of file THistSvc.cpp.

1084  {
1085  return getHist_i(id, hist);
1086 }
StatusCode getHist_i(const std::string &name, T *&hist, bool quiet=false) const
Definition: THistSvc.icc:142
StatusCode THistSvc::getHist ( const std::string &  name,
TH2 *&  hist 
) const
virtual

Implements ITHistSvc.

Definition at line 1091 of file THistSvc.cpp.

1091  {
1092  return getHist_i(id, hist);
1093 }
StatusCode getHist_i(const std::string &name, T *&hist, bool quiet=false) const
Definition: THistSvc.icc:142
StatusCode THistSvc::getHist ( const std::string &  name,
TH3 *&  hist 
) const
virtual

Implements ITHistSvc.

Definition at line 1098 of file THistSvc.cpp.

1098  {
1099  return getHist_i(id, hist);
1100 }
StatusCode getHist_i(const std::string &name, T *&hist, bool quiet=false) const
Definition: THistSvc.icc:142
template<typename T >
StatusCode THistSvc::getHist_i ( const std::string &  name,
T *&  hist,
bool  quiet = false 
) const
private

Definition at line 142 of file THistSvc.icc.

142  {
143  // id starts with "/": unique
144 
145  GlobalDirectoryRestore restore;
146 
147  std::string idr(id);
148  removeDoubleSlash( idr );
149 
150  if (idr.find("/") == 0) {
151  std::map<std::string, THistID>::const_iterator itr = m_uids.find(id);
152  if (itr == m_uids.end()) {
153  if (!quiet) {
154  m_log << MSG::ERROR << "Could not locate Hist with id \"" << idr << "\""
155  << endmsg;
156  }
157  hist = 0;
158  return StatusCode::FAILURE;
159  }
160 
161  THistID hid = itr->second;
162  if (!quiet) {
163  hist = dynamic_cast<T*>(hid.obj);
164  if (hist == 0) {
165  m_log << MSG::ERROR << "dcast failed, Hist id: \"" << idr << "\""
166  << endmsg;
167  return StatusCode::FAILURE;
168  }
169  if (m_log.level() <= MSG::VERBOSE) {
170  m_log << MSG::VERBOSE << "found unique Hist title: \""
171  << hist->GetTitle()
172  << "\" id: \"" << idr << "\"" << endmsg;
173  }
174  } else {
175  if (m_log.level() <= MSG::VERBOSE) {
176  m_log << MSG::VERBOSE << "found unique Hist id: \"" << idr
177  << "\" type: \"" << hid.obj->IsA()->GetName() << "\""
178  << endmsg;
179  }
180  }
181 
182  return StatusCode::SUCCESS;
183 
184 
185  // not necessarily unique
186  } else {
187 
188  std::pair< std::multimap<std::string,THistID>::const_iterator,
189  std::multimap<std::string,THistID>::const_iterator > mitr = m_ids.equal_range(idr);
190 
191 
192  if (mitr.first == mitr.second) {
193  m_log << MSG::ERROR << "Could not locate Hist with id \"" << idr << "\""
194  << endmsg;
195  hist = 0;
196  return StatusCode::FAILURE;
197  } else {
198 
199  if (distance(mitr.first,mitr.second) == 1) {
200  THistID hid = mitr.first->second;
201  if (!quiet) {
202  hist = dynamic_cast<T*>(hid.obj);
203  if (hist == 0) {
204  m_log << MSG::ERROR << "dcast failed" << endmsg;
205  return StatusCode::FAILURE;
206  }
207  if (m_log.level() <= MSG::VERBOSE) {
208  m_log << MSG::VERBOSE << "found Hist title: \"" << hist->GetTitle()
209  << "\" id: \"" << idr << "\"" << endmsg;
210  }
211  } else {
212  if (m_log.level() <= MSG::VERBOSE) {
213  m_log << MSG::VERBOSE << "found Hist id: \"" << idr << "\" type: \""
214  << hid.obj->IsA()->GetName() << "\""
215  << endmsg;
216  }
217  }
218  return StatusCode::SUCCESS;
219  } else {
220  if (!quiet) {
221  // return failure if trying to GET a single hist
222  m_log << MSG::ERROR << "Multiple matches with id \"" << idr << "\"."
223  << " Further specifications required."
224  << endmsg;
225  hist = 0;
226  return StatusCode::FAILURE;
227  } else {
228  // return a SUCCESS if just INQUIRING
229  m_log << MSG::INFO << "Found multiple matches with id \"" << idr
230  << "\"" << endmsg;
231  hist = 0;
232  return StatusCode::SUCCESS;
233  }
234  }
235  }
236  }
237 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
uidMap m_uids
Definition: THistSvc.h:199
idMap m_ids
Definition: THistSvc.h:200
MsgStream m_log
Definition: THistSvc.h:178
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1810
std::vector< std::string > THistSvc::getHists ( ) const
virtual

Implements ITHistSvc.

Definition at line 1105 of file THistSvc.cpp.

1105  {
1106 
1107  std::vector<std::string> names;
1108  names.reserve(m_uids.size());
1109 
1110  uidMap::const_iterator itr;
1111  for (itr = m_uids.begin(); itr != m_uids.end(); ++itr) {
1112  THistID tid = itr->second;
1113 
1114  if (tid.obj->IsA()->InheritsFrom("TH1")) {
1115  names.push_back(itr->first);
1116  }
1117 
1118  }
1119 
1120  return names;
1121 
1122 }
std::string names[100]
Definition: Node.cpp:19
uidMap m_uids
Definition: THistSvc.h:199
StatusCode THistSvc::getTHists ( TDirectory *  td,
TList &  tl,
bool  recurse = false 
) const
virtual

Implements ITHistSvc.

Definition at line 459 of file THistSvc.cpp.

459  {
460  GlobalDirectoryRestore restore;
461 
462  gErrorIgnoreLevel = kBreak;
463 
464  if (!td->cd()) {
465  m_log << MSG::ERROR << "getTHists: No such TDirectory \"" << td->GetPath()
466  << "\"" << endmsg;
467  return StatusCode::FAILURE;
468  }
469 
470  if (m_log.level() <= MSG::DEBUG)
471  m_log << MSG::DEBUG << "getTHists: \"" << td->GetPath() << "\": found "
472  << td->GetListOfKeys()->GetSize() << " keys" << endmsg;
473 
474  TIter nextkey(td->GetListOfKeys());
475  while (TKey *key = (TKey*)nextkey()) {
476  if (m_log.level() <= MSG::DEBUG)
477  m_log << MSG::DEBUG << " key: " << key->GetName();
478  TObject *obj = key->ReadObj();
479  if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
480  if (m_log.level() <= MSG::DEBUG)
481  m_log << " (" << obj->IsA()->GetName() << ")";
482  } else if (obj != 0 && obj->IsA()->InheritsFrom("TH1")) {
483  if (m_log.level() <= MSG::DEBUG)
484  m_log << " (" << obj->IsA()->GetName() << ")";
485  tl.Add(obj);
486  } else if (obj != 0) {
487  if (m_log.level() <= MSG::DEBUG)
488  m_log << " [" << obj->IsA()->GetName() << "]";
489  }
490  if (m_log.level() <= MSG::DEBUG)
491  m_log << endmsg;
492  }
493 
494  // operate recursively
495  if (rcs) {
496  nextkey = td->GetListOfKeys();
497  while (TKey *key = (TKey*)nextkey()) {
498  TObject *obj = key->ReadObj();
499  if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
500  TDirectory *tt = dynamic_cast<TDirectory*>(obj);
501  getTHists(tt, tl, rcs);
502  }
503  }
504  }
505 
506  return StatusCode::SUCCESS;
507 
508 
509 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const
Definition: THistSvc.cpp:459
MsgStream m_log
Definition: THistSvc.h:178
StatusCode THistSvc::getTHists ( const std::string &  name,
TList &  tl,
bool  recurse = false 
) const
virtual

Implements ITHistSvc.

Definition at line 514 of file THistSvc.cpp.

514  {
515 
516  GlobalDirectoryRestore restore;
517 
518  gErrorIgnoreLevel = kBreak;
519 
520  StatusCode sc;
521 
522  std::string stream,rem,r2;
523  parseString(dir,stream,rem);
524 
525  map< string,pair<TFile*,Mode> >::const_iterator itr = m_files.find(stream);
526  if (itr != m_files.end()) {
527  r2 = itr->second.first->GetName();
528  r2 += ":/";
529  r2 += rem;
530 
531  if (m_log.level() <= MSG::DEBUG)
532  m_log << MSG::DEBUG << "getTHists: \"" << dir
533  << "\" looks like a stream name." << " associated TFile: \""
534  << itr->second.first->GetName() << "\"" << endmsg;
535 
536  if (gDirectory->cd(r2.c_str())) {
537  m_curstream = stream;
538  sc = getTHists(gDirectory,tl,rcs);
539  m_curstream = "";
540  return sc;
541  } else {
542  if (m_log.level() <= MSG::DEBUG)
543  m_log << MSG::DEBUG << "getTHists: no such TDirectory \""
544  << r2 << "\"" << endmsg;
545  }
546 
547  } else {
548  if (m_log.level() <= MSG::DEBUG)
549  m_log << MSG::DEBUG << "getTHists: stream \"" << stream << "\" not found"
550  << endmsg;
551  }
552 
553  if (!gDirectory->cd(dir.c_str())) {
554  m_log << MSG::ERROR << "getTHists: No such TDirectory/stream \"" << dir
555  << "\"" << endmsg;
556  sc = StatusCode::FAILURE;
557  } else {
558  sc = getTHists(gDirectory,tl,rcs);
559  }
560 
561  return sc;
562 
563 }
std::string m_curstream
Definition: THistSvc.h:211
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
virtual StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const
Definition: THistSvc.cpp:459
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1257
MsgStream m_log
Definition: THistSvc.h:178
StatusCode THistSvc::getTHists ( TDirectory *  td,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
virtual

Implements ITHistSvc.

Definition at line 672 of file THistSvc.cpp.

672  {
673 
674  GlobalDirectoryRestore restore;
675 
676  gErrorIgnoreLevel = kBreak;
677 
678  if (!td->cd()) {
679  m_log << MSG::ERROR << "getTHists: No such TDirectory \"" << td->GetPath()
680  << "\"" << endmsg;
681  return StatusCode::FAILURE;
682  }
683 
684  if (m_log.level() <= MSG::DEBUG)
685  m_log << MSG::DEBUG << "getTHists: \"" << td->GetPath() << "\": found "
686  << td->GetListOfKeys()->GetSize() << " keys" << endmsg;
687 
688  TIter nextkey(td->GetListOfKeys());
689  while (TKey *key = (TKey*)nextkey()) {
690  if (m_log.level() <= MSG::DEBUG)
691  m_log << MSG::DEBUG << " key: " << key->GetName();
692  TObject *obj = key->ReadObj();
693  if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
694  if (m_log.level() <= MSG::DEBUG)
695  m_log << " (" << obj->IsA()->GetName() << ")";
696  } else if (obj != 0 && obj->IsA()->InheritsFrom("TH1")) {
697  if (m_log.level() <= MSG::DEBUG)
698  m_log << " (" << obj->IsA()->GetName() << ")";
699  tl.Add(obj);
700  if (reg && m_curstream != "") {
701  string dir = td->GetPath();
702  string fil = td->GetFile()->GetName();
703  dir.erase(0,fil.length()+1);
704  string id = "/" + m_curstream;
705  if ( dir == "/" ) {
706  id = id + "/" + key->GetName();
707  } else {
708  id = id + dir + "/" + key->GetName();
709  }
710  if (!exists(id)) {
711  if (m_log.level() <= MSG::DEBUG)
712  m_log << " reg as \"" << id << "\"";
713  regHist(id).ignore();
714  } else {
715  if (m_log.level() <= MSG::DEBUG)
716  m_log << " already registered";
717  }
718  }
719  } else if (obj != 0) {
720  if (m_log.level() <= MSG::DEBUG)
721  m_log << " [" << obj->IsA()->GetName() << "]";
722  }
723  if (m_log.level() <= MSG::DEBUG)
724  m_log << endmsg;
725  }
726 
727  // operate recursively
728  if (rcs) {
729  nextkey = td->GetListOfKeys();
730  while (TKey *key = (TKey*)nextkey()) {
731  TObject *obj = key->ReadObj();
732  if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
733  TDirectory *tt = dynamic_cast<TDirectory*>(obj);
734  getTHists(tt, tl, rcs, reg);
735  }
736  }
737  }
738 
739  return StatusCode::SUCCESS;
740 
741 }
std::string m_curstream
Definition: THistSvc.h:211
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StatusCode regHist(const std::string &name)
Definition: THistSvc.cpp:1004
virtual StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const
Definition: THistSvc.cpp:459
virtual bool exists(const std::string &name) const
Definition: THistSvc.cpp:1896
MsgStream m_log
Definition: THistSvc.h:178
void ignore() const
Definition: StatusCode.h:107
StatusCode THistSvc::getTHists ( const std::string &  name,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
virtual

Implements ITHistSvc.

Definition at line 746 of file THistSvc.cpp.

746  {
747 
748  GlobalDirectoryRestore restore;
749 
750  gErrorIgnoreLevel = kBreak;
751 
752  StatusCode sc;
753 
754  std::string stream,rem,r2;
755  parseString(dir,stream,rem);
756 
757  map< string,pair<TFile*,Mode> >::const_iterator itr = m_files.find(stream);
758  if (itr != m_files.end()) {
759  r2 = itr->second.first->GetName();
760  r2 += ":/";
761  r2 += rem;
762 
763  if (m_log.level() <= MSG::DEBUG)
764  m_log << MSG::DEBUG << "getTHists: \"" << dir
765  << "\" looks like a stream name." << " associated TFile: \""
766  << itr->second.first->GetName() << "\"" << endmsg;
767 
768  if (gDirectory->cd(r2.c_str())) {
769  m_curstream = stream;
770  sc = getTHists(gDirectory,tl,rcs,reg);
771  m_curstream = "";
772  return sc;
773  } else {
774  if (m_log.level() <= MSG::DEBUG)
775  m_log << MSG::DEBUG << "getTHists: no such TDirectory \""
776  << r2 << "\"" << endmsg;
777  }
778 
779  } else {
780  if (m_log.level() <= MSG::DEBUG)
781  m_log << MSG::DEBUG << "getTHists: stream \"" << stream << "\" not found"
782  << endmsg;
783  }
784 
785  if (!gDirectory->cd(dir.c_str())) {
786  m_log << MSG::ERROR << "getTHists: No such TDirectory/stream \"" << dir
787  << "\"" << endmsg;
788  sc = StatusCode::FAILURE;
789  } else {
790  if (reg) {
791  m_log << MSG::WARNING << "Unable to register histograms automatically "
792  << "without a valid stream name" << endmsg;
793  reg = false;
794  }
795  sc = getTHists(gDirectory,tl,rcs,reg);
796  }
797 
798  return sc;
799 
800 }
std::string m_curstream
Definition: THistSvc.h:211
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
virtual StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const
Definition: THistSvc.cpp:459
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1257
MsgStream m_log
Definition: THistSvc.h:178
StatusCode THistSvc::getTree ( const std::string &  name,
TTree *&  hist 
) const
virtual

Implements ITHistSvc.

Definition at line 1126 of file THistSvc.cpp.

1126  {
1127  return getHist_i(id, hist);
1128 }
StatusCode getHist_i(const std::string &name, T *&hist, bool quiet=false) const
Definition: THistSvc.icc:142
std::vector< std::string > THistSvc::getTrees ( ) const
virtual

Implements ITHistSvc.

Definition at line 1133 of file THistSvc.cpp.

1133  {
1134 
1135  std::vector<std::string> names;
1136  names.reserve(m_uids.size());
1137 
1138  uidMap::const_iterator itr;
1139  for (itr = m_uids.begin(); itr != m_uids.end(); ++itr) {
1140  THistID tid = itr->second;
1141 
1142  if (tid.obj->IsA()->InheritsFrom("TTree")) {
1143  names.push_back(itr->first);
1144  }
1145 
1146  }
1147 
1148  return names;
1149 
1150 }
std::string names[100]
Definition: Node.cpp:19
uidMap m_uids
Definition: THistSvc.h:199
StatusCode THistSvc::getTTrees ( TDirectory *  td,
TList &  tl,
bool  recurse = false 
) const
virtual

Implements ITHistSvc.

Definition at line 567 of file THistSvc.cpp.

567  {
568  GlobalDirectoryRestore restore;
569 
570  gErrorIgnoreLevel = kBreak;
571 
572  if (!td->cd()) {
573  m_log << MSG::ERROR << "getTTrees: No such TDirectory \""
574  << td->GetPath() << "\"" << endmsg;
575  return StatusCode::FAILURE;
576  }
577 
578  if (m_log.level() <= MSG::DEBUG)
579  m_log << MSG::DEBUG << "getTHists: \"" << td->GetPath() << "\": found "
580  << td->GetListOfKeys()->GetSize() << " keys" << endmsg;
581 
582  TIter nextkey(td->GetListOfKeys());
583  while (TKey *key = (TKey*)nextkey()) {
584  if (m_log.level() <= MSG::DEBUG)
585  m_log << MSG::DEBUG << " key: " << key->GetName();
586  TObject *obj = key->ReadObj();
587  if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
588  if (m_log.level() <= MSG::DEBUG)
589  m_log << " (" << obj->IsA()->GetName() << ")";
590  } else if (obj != 0 && obj->IsA()->InheritsFrom("TTree")) {
591  if (m_log.level() <= MSG::DEBUG)
592  m_log << " (" << obj->IsA()->GetName() << ")";
593  tl.Add(obj);
594  } else if (obj != 0) {
595  if (m_log.level() <= MSG::DEBUG)
596  m_log << " [" << obj->IsA()->GetName() << "]";
597  }
598  m_log << endmsg;
599  }
600 
601  // operate recursively
602  if (rcs) {
603  nextkey = td->GetListOfKeys();
604  while (TKey *key = (TKey*)nextkey()) {
605  TObject *obj = key->ReadObj();
606  if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
607  TDirectory *tt = dynamic_cast<TDirectory*>(obj);
608  getTTrees(tt, tl, rcs);
609  }
610  }
611  }
612 
613  return StatusCode::SUCCESS;
614 
615 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MsgStream m_log
Definition: THistSvc.h:178
virtual StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const
Definition: THistSvc.cpp:567
StatusCode THistSvc::getTTrees ( const std::string &  name,
TList &  tl,
bool  recurse = false 
) const
virtual

Implements ITHistSvc.

Definition at line 620 of file THistSvc.cpp.

620  {
621  GlobalDirectoryRestore restore;
622 
623  gErrorIgnoreLevel = kBreak;
624 
625  StatusCode sc;
626 
627  std::string stream,rem,r2;
628  parseString(dir,stream,rem);
629 
630  map< string,pair<TFile*,Mode> >::const_iterator itr = m_files.find(stream);
631  if (itr != m_files.end()) {
632  r2 = itr->second.first->GetName();
633  r2 += ":/";
634  r2 += rem;
635 
636  if (m_log.level() <= MSG::DEBUG)
637  m_log << MSG::DEBUG << "getTTrees: \"" << dir
638  << "\" looks like a stream name." << " associated TFile: \""
639  << itr->second.first->GetName() << "\"" << endmsg;
640 
641  if (gDirectory->cd(r2.c_str())) {
642  return getTTrees(gDirectory,tl,rcs);
643  } else {
644  if (m_log.level() <= MSG::DEBUG)
645  m_log << MSG::DEBUG << "getTTrees: no such TDirectory \""
646  << r2 << "\"" << endmsg;
647  }
648 
649  } else {
650  if (m_log.level() <= MSG::DEBUG)
651  m_log << MSG::DEBUG << "getTTrees: stream \"" << stream << "\" not found"
652  << endmsg;
653  }
654 
655  if (!gDirectory->cd(dir.c_str())) {
656  m_log << MSG::ERROR << "getTTrees: No such TDirectory/stream \"" << dir
657  << "\"" << endmsg;
658  sc = StatusCode::FAILURE;
659  } else {
660  sc = getTTrees(gDirectory,tl,rcs);
661  }
662 
663  return sc;
664 
665 
666 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1257
MsgStream m_log
Definition: THistSvc.h:178
virtual StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const
Definition: THistSvc.cpp:567
StatusCode THistSvc::getTTrees ( TDirectory *  td,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
virtual

Implements ITHistSvc.

Definition at line 804 of file THistSvc.cpp.

804  {
805 
806  GlobalDirectoryRestore restore;
807 
808  gErrorIgnoreLevel = kBreak;
809 
810  if (!td->cd()) {
811  m_log << MSG::ERROR << "getTTrees: No such TDirectory \""
812  << td->GetPath() << "\"" << endmsg;
813  return StatusCode::FAILURE;
814  }
815 
816  if (m_log.level() <= MSG::DEBUG)
817  m_log << MSG::DEBUG << "getTHists: \"" << td->GetPath() << "\": found "
818  << td->GetListOfKeys()->GetSize() << " keys" << endmsg;
819 
820  TIter nextkey(td->GetListOfKeys());
821  while (TKey *key = (TKey*)nextkey()) {
822  if (m_log.level() <= MSG::DEBUG)
823  m_log << MSG::DEBUG << " key: " << key->GetName();
824  TObject *obj = key->ReadObj();
825  if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
826  if (m_log.level() <= MSG::DEBUG)
827  m_log << " (" << obj->IsA()->GetName() << ")";
828  } else if (obj != 0 && obj->IsA()->InheritsFrom("TTree")) {
829  if (m_log.level() <= MSG::DEBUG)
830  m_log << " (" << obj->IsA()->GetName() << ")";
831  tl.Add(obj);
832  if (reg && m_curstream != "") {
833  string dir = td->GetPath();
834  string fil = td->GetFile()->GetName();
835  dir.erase(0,fil.length()+1);
836  string id = "/" + m_curstream;
837  if ( dir == "/" ) {
838  id = id + "/" + key->GetName();
839  } else {
840  id = id + dir + "/" + key->GetName();
841  }
842  if (!exists(id)) {
843  if (m_log.level() <= MSG::DEBUG)
844  m_log << " reg as \"" << id << "\"";
845  regHist(id).ignore();
846  } else {
847  if (m_log.level() <= MSG::DEBUG)
848  m_log << " already registered";
849  }
850  }
851  } else if (obj != 0) {
852  if (m_log.level() <= MSG::DEBUG)
853  m_log << " [" << obj->IsA()->GetName() << "]";
854  }
855  if (m_log.level() <= MSG::DEBUG)
856  m_log << endmsg;
857  }
858 
859  // operate recursively
860  if (rcs) {
861  nextkey = td->GetListOfKeys();
862  while (TKey *key = (TKey*)nextkey()) {
863  TObject *obj = key->ReadObj();
864  if (obj != 0 && obj->IsA()->InheritsFrom("TDirectory")) {
865  TDirectory *tt = dynamic_cast<TDirectory*>(obj);
866  getTTrees(tt, tl, rcs, reg);
867  }
868  }
869  }
870 
871  return StatusCode::SUCCESS;
872 
873 }
std::string m_curstream
Definition: THistSvc.h:211
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StatusCode regHist(const std::string &name)
Definition: THistSvc.cpp:1004
virtual bool exists(const std::string &name) const
Definition: THistSvc.cpp:1896
MsgStream m_log
Definition: THistSvc.h:178
void ignore() const
Definition: StatusCode.h:107
virtual StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const
Definition: THistSvc.cpp:567
StatusCode THistSvc::getTTrees ( const std::string &  name,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
virtual

Implements ITHistSvc.

Definition at line 878 of file THistSvc.cpp.

878  {
879 
880  GlobalDirectoryRestore restore;
881 
882  gErrorIgnoreLevel = kBreak;
883 
884  StatusCode sc;
885 
886  std::string stream,rem,r2;
887  parseString(dir,stream,rem);
888 
889  map< string,pair<TFile*,Mode> >::const_iterator itr = m_files.find(stream);
890  if (itr != m_files.end()) {
891  r2 = itr->second.first->GetName();
892  r2 += ":/";
893  r2 += rem;
894 
895  if (m_log.level() <= MSG::DEBUG)
896  m_log << MSG::DEBUG << "getTTrees: \"" << dir
897  << "\" looks like a stream name." << " associated TFile: \""
898  << itr->second.first->GetName() << "\"" << endmsg;
899 
900  if (gDirectory->cd(r2.c_str())) {
901  return getTTrees(gDirectory,tl,rcs,reg);
902  } else {
903  if (m_log.level() <= MSG::DEBUG)
904  m_log << MSG::DEBUG << "getTTrees: no such TDirectory \""
905  << r2 << "\"" << endmsg;
906  }
907 
908  } else {
909  if (m_log.level() <= MSG::DEBUG)
910  m_log << MSG::DEBUG << "getTTrees: stream \"" << stream << "\" not found"
911  << endmsg;
912  }
913 
914  if (!gDirectory->cd(dir.c_str())) {
915  m_log << MSG::ERROR << "getTTrees: No such TDirectory/stream \"" << dir
916  << "\"" << endmsg;
917  sc = StatusCode::FAILURE;
918  } else {
919  sc = getTTrees(gDirectory,tl,rcs,reg);
920  }
921 
922  return sc;
923 
924 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1257
MsgStream m_log
Definition: THistSvc.h:178
virtual StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const
Definition: THistSvc.cpp:567
void THistSvc::handle ( const Incident )
virtual

Inform that a new incident has occurred.

Implements IIncidentListener.

Definition at line 1908 of file THistSvc.cpp.

1908  {
1909 
1910  if (signaledStop) return ;
1911 
1912  if (m_maxFileSize.value() == -1) {
1913  return;
1914  }
1915 
1916  // convert to bytes.
1917  Long64_t mfs = (Long64_t)m_maxFileSize.value() * (Long64_t)1048576;
1918  Long64_t mfs_warn = mfs * 95 / 100;
1919 
1920  updateFiles();
1921 
1922  map<string, pair<TFile*,Mode> >::const_iterator itr;
1923  for (itr=m_files.begin(); itr!= m_files.end(); ++itr) {
1924  TFile* tf = itr->second.first;
1925 
1926 #ifndef NDEBUG
1927  if (m_log.level() <= MSG::DEBUG)
1928  m_log << MSG::DEBUG << "stream: " << itr->first << " name: "
1929  << tf->GetName() << " size: " << tf->GetSize()
1930  << endmsg;
1931 #endif
1932 
1933  // Signal job to terminate if output file is too large
1934  if (tf->GetSize() > mfs) {
1935 
1936  signaledStop = true;
1937 
1938  m_log << MSG::FATAL << "file \"" << tf->GetName()
1939  << "\" associated with stream \"" << itr->first
1940  << "\" has exceeded the max file size of "
1941  << m_maxFileSize.value() << "MB. Terminating Job."
1942  << endmsg;
1943 
1944  IEventProcessor* evt(0);
1945  if (service("ApplicationMgr", evt, true).isSuccess()) {
1946  evt->stopRun();
1947  evt->release();
1948  } else {
1949  abort();
1950  }
1951  } else if (tf->GetSize() > mfs_warn) {
1952  m_log << MSG::WARNING << "file \"" << tf->GetName()
1953  << "\" associated with stream \"" << itr->first
1954  << "\" is at 95% of its maximum allowable file size of "
1955  << m_maxFileSize.value() << "MB"
1956  << endmsg;
1957  }
1958  }
1959 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool signaledStop
Definition: THistSvc.h:208
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
IntegerProperty m_maxFileSize
Definition: THistSvc.h:182
const TYPE & value() const
explicit conversion
Definition: Property.h:355
The IEventProcessor is the interface to process events.
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:143
MsgStream m_log
Definition: THistSvc.h:178
void updateFiles()
Definition: THistSvc.cpp:1375
StatusCode THistSvc::initialize ( )
virtual

Initialization (from CONFIGURED to INITIALIZED).

Reimplemented from Service.

Definition at line 74 of file THistSvc.cpp.

74  {
75  GlobalDirectoryRestore restore;
76 
77  // Super ugly hack to make sure we have the OutputLevel set first, so we
78  // can see DEBUG printouts in update handlers.
79  IJobOptionsSvc* jos(0);
80  if( serviceLocator()->service( "JobOptionsSvc", jos, true ).isSuccess() ) {
81  const std::vector<const Property*> *props = jos->getProperties( name() );
82 
83  if (props != NULL) {
84  for ( std::vector<const Property*>::const_iterator cur = props->begin();
85  cur != props->end(); cur++) {
86  if ( (*cur)->name() == "OutputLevel" ) {
87  setProperty( **cur ).ignore();
89  break;
90  }
91  }
92  }
93  }
94 
95 
98 
99  if (status.isFailure()) {
100  m_log << MSG::ERROR << "initializing service" << endmsg;
101  return status;
102  }
103 
104  vector<string>::const_iterator itr;
106 
107  try {
109  } catch ( GaudiException& err ) {
110  m_log << MSG::ERROR
111  << "Caught: " << err << endmsg;
112  st = StatusCode::FAILURE;
113  }
114 
115  try {
117  } catch ( GaudiException& err ) {
118  m_log << MSG::ERROR
119  << "Caught: " << err << endmsg;
120  st = StatusCode::FAILURE;
121  }
122 
123  // Protect against multiple instances of TROOT
124  if ( 0 == gROOT ) {
125  static TROOT root("root","ROOT I/O");
126  // gDebug = 99;
127  } else {
128  if (m_log.level() <= MSG::VERBOSE)
129  m_log << MSG::VERBOSE << "ROOT already initialized, debug = "
130  << gDebug<< endmsg;
131  }
132 
133  if (service("IncidentSvc", p_incSvc, true).isFailure()) {
134  m_log << MSG::ERROR << "unable to get the IncidentSvc" << endmsg;
135  st = StatusCode::FAILURE;
136  } else {
137  p_incSvc->addListener( this, "EndEvent", 100, true);
138  }
139 
140  if (service("FileMgr",p_fileMgr,true).isFailure()) {
141  m_log << MSG::ERROR << "unable to get the FileMgr" << endmsg;
142  st = StatusCode::FAILURE;
143  } else {
144  m_log << MSG::DEBUG << "got the FileMgr" << endmsg;
145  }
146 
147 
148  // Register open/close callback actions
149 
150  Io::bfcn_action_t boa = boost::bind(&THistSvc::rootOpenAction, this, _1,_2);
152  m_log << MSG::ERROR
153  << "unable to register ROOT file open action with FileMgr"
154  << endmsg;
155  }
156  Io::bfcn_action_t bea = boost::bind(&THistSvc::rootOpenErrAction, this, _1,_2);
158  m_log << MSG::ERROR
159  << "unable to register ROOT file open Error action with FileMgr"
160  << endmsg;
161  }
162 
163 
164  m_okToConnect = true;
165 
166  if (m_delayConnect == true) {
167  if (m_inputfile.value().size() > 0) { setupInputFile(m_inputfile); }
168  if (m_outputfile.value().size() > 0) { setupOutputFile(m_outputfile); }
169 
170  m_delayConnect = false;
171 
172  }
175 
176 
177  IIoComponentMgr* iomgr(0);
178 
179  if (service("IoComponentMgr", iomgr, true).isFailure()) {
180  m_log << MSG::ERROR << "unable to get the IoComponentMgr" << endmsg;
181  st = StatusCode::FAILURE;
182  } else {
183 
184  if ( !iomgr->io_register (this).isSuccess() ) {
185  m_log << MSG::ERROR
186  << "could not register with the I/O component manager !"
187  << endmsg;
188  st = StatusCode::FAILURE;
189  } else {
190  bool all_good = true;
191  typedef std::map<std::string, std::pair<TFile*,Mode> > Registry_t;
192  // register input/output files...
193  for ( Registry_t::const_iterator
194  ireg = m_files.begin(),
195  iend = m_files.end();
196  ireg != iend;
197  ++ireg ) {
198  const std::string fname = ireg->second.first->GetName();
199  const IIoComponentMgr::IoMode::Type iomode =
200  ( ireg->second.second==THistSvc::READ
203  if ( !iomgr->io_register (this, iomode, fname).isSuccess () ) {
204  m_log << MSG::WARNING << "could not register file ["
205  << fname << "] with the I/O component manager..." << endmsg;
206  all_good = false;
207  } else {
208  m_log << MSG::INFO << "registered file [" << fname << "]... [ok]"
209  << endmsg;
210  }
211  }
212  if (!all_good) {
213  m_log << MSG::ERROR
214  << "problem while registering input/output files with "
215  << "the I/O component manager !" << endmsg;
216  st = StatusCode::FAILURE;
217  }
218  }
219 
220  }
221 
222  if (st.isFailure()) {
223  m_log << MSG::FATAL << "Unable to initialize THistSvc" << endmsg;
224  }
225 
226  return st;
227 
228 }
bool m_delayConnect
Definition: THistSvc.h:209
IntegerProperty m_outputLevel
Service output level.
Definition: Service.h:244
Define general base for Gaudi exception.
std::function< StatusCode(FILEMGR_CALLBACK_ARGS) > bfcn_action_t
Definition: IFileMgr.h:340
virtual StatusCode setProperty(const Property &p)
Set the property by property.
Definition: Service.cpp:340
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
IIncidentSvc * p_incSvc
Definition: THistSvc.h:213
StatusCode rootOpenAction(FILEMGR_CALLBACK_ARGS)
Definition: THistSvc.cpp:2129
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
virtual StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &d="")=0
StringArrayProperty m_inputfile
Definition: THistSvc.h:180
StringArrayProperty m_outputfile
Definition: THistSvc.h:180
void setupOutputFile(Property &outputfile)
call-back method to handle output stream property
Definition: THistSvc.cpp:1337
Main interface for the JobOptions service.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
bool m_okToConnect
Definition: THistSvc.h:209
StatusCode rootOpenErrAction(FILEMGR_CALLBACK_ARGS)
Definition: THistSvc.cpp:2161
const TYPE & value() const
explicit conversion
Definition: Property.h:355
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Definition: Service.cpp:72
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
void setLevel(int level)
Update outputlevel.
Definition: MsgStream.h:106
IFileMgr * p_fileMgr
Definition: THistSvc.h:214
tuple root
Definition: IOTest.py:42
std::set< std::string > m_alreadyConnectedOutFiles
list of already connected files.
Definition: THistSvc.h:191
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:143
MsgStream m_log
Definition: THistSvc.h:178
void ignore() const
Definition: StatusCode.h:107
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
Definition: THistSvc.h:187
void setupInputFile(Property &inputfile)
call-back method to handle input stream property
Definition: THistSvc.cpp:1291
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
Definition: Service.cpp:334
StatusCode THistSvc::io_reinit ( )
virtual

callback method to reinitialize the internal state of the component for I/O purposes (e.g.

upon fork(2))

Implements IIoComponent.

Definition at line 2006 of file THistSvc.cpp.

2007 {
2008  bool all_good = true;
2009  if (m_log.level() <= MSG::DEBUG)
2010  m_log << MSG::DEBUG << "reinitializing I/O..." << endmsg;
2011 
2012  // retrieve the I/O component manager...
2013 
2014  IIoComponentMgr* iomgr(0);
2015 
2016  if (service("IoComponentMgr", iomgr, true).isFailure()) {
2017  m_log << MSG::ERROR << "could not retrieve I/O component manager !"
2018  << endmsg;
2019  return StatusCode::FAILURE;
2020  }
2021 
2022  GlobalDirectoryRestore restore;
2023  // to hide the expected errors upon closing the files whose
2024  // file descriptors have been swept under the rug...
2025  gErrorIgnoreLevel = kFatal;
2026 
2027  typedef std::map<std::string, std::pair<TFile*,Mode> > FileReg_t;
2028 
2029  for (FileReg_t::iterator ifile = m_files.begin(), iend=m_files.end();
2030  ifile != iend; ++ifile) {
2031  TFile *f = ifile->second.first;
2032  std::string fname = f->GetName();
2033  if (m_log.level() <= MSG::DEBUG)
2034  m_log << MSG::DEBUG << "file [" << fname << "] mode: ["
2035  << f->GetOption() << "] r:"
2036  << f->GetFileBytesRead()
2037  << " w:" << f->GetFileBytesWritten()
2038  << " cnt:" << f->GetFileCounter()
2039  << endmsg;
2040 
2041  if ( ifile->second.second == READ ) {
2042  if (m_log.level() <= MSG::DEBUG)
2043  m_log << MSG::DEBUG
2044  << " TFile opened in READ mode: not reassigning names" << endmsg;
2045  continue;
2046  }
2047 
2048  if ( !iomgr->io_retrieve (this, fname).isSuccess () ) {
2049  m_log << MSG::ERROR << "could not retrieve new name for [" << fname
2050  << "] !!" << endmsg;
2051  all_good = false;
2052  continue;
2053  } else {
2054  if (m_log.level() <= MSG::DEBUG)
2055  m_log << MSG::DEBUG << "got a new name [" << fname << "]..." << endmsg;
2056  }
2057  // create a new TFile
2058  // TFile *newfile = TFile::Open (fname.c_str(), f->GetOption());
2059 
2060  void* vf;
2061  Option_t *opts = f->GetOption();
2062  int r = p_fileMgr->open(Io::ROOT,name(),fname,Io::WRITE,vf,"HIST");
2063  if (r != 0) {
2064  m_log << MSG::ERROR << "unable to open file \"" << fname
2065  << "\" for writing" << endmsg;
2066  return StatusCode::FAILURE;
2067  }
2068  TFile *newfile = (TFile*) vf;
2069  newfile->SetOption(opts);
2070 
2071 
2072  if (ifile->second.second != THistSvc::READ) {
2073  copyFileLayout (newfile, f);
2074  ifile->second.first = newfile;
2075  }
2076 
2077  // loop over all uids and migrate them to the new file
2078  // XXX FIXME: this double loop sucks...
2079  for ( uidMap::iterator uid = m_uids.begin(), uid_end = m_uids.end();
2080  uid != uid_end;
2081  ++uid ) {
2082  THistID& hid = uid->second;
2083  if ( hid.file != f ) {
2084  continue;
2085  }
2086  TDirectory *olddir = this->changeDir (hid);
2087  hid.file = newfile;
2088  // side-effect: create needed directories...
2089  TDirectory *newdir = this->changeDir (hid);
2090  TClass *cl = hid.obj->IsA();
2091 
2092  // migrate the objects to the new file.
2093  // thanks to the object model of ROOT, it is super easy.
2094  if (cl->InheritsFrom ("TTree")) {
2095  dynamic_cast<TTree*> (hid.obj)->SetDirectory (newdir);
2096  dynamic_cast<TTree*> (hid.obj)->Reset();
2097  }
2098  else if (cl->InheritsFrom ("TH1")) {
2099  dynamic_cast<TH1*> (hid.obj)->SetDirectory (newdir);
2100  dynamic_cast<TH1*> (hid.obj)->Reset();
2101  }
2102  else if (cl->InheritsFrom ("TGraph")) {
2103  olddir->Remove (hid.obj);
2104  newdir->Append (hid.obj);
2105  } else {
2106  m_log << MSG::ERROR
2107  << "id: \"" << hid.id << "\" is not a inheriting from a class "
2108  << "we know how to handle (received [" << cl->GetName()
2109  << "], " << "expected [TTree, TH1 or TGraph]) !"
2110  << endmsg
2111  << "attaching to current dir [" << newdir->GetPath() << "] "
2112  << "nonetheless..." << endmsg;
2113  olddir->Remove (hid.obj);
2114  newdir->Append (hid.obj);
2115  }
2116  }
2117  f->ReOpen ("READ");
2118  p_fileMgr->close(f,name());
2119  f = newfile;
2120  }
2121 
2122  return all_good ? StatusCode::SUCCESS : StatusCode::FAILURE;
2123 }
virtual Io::open_t open(const Io::IoTech &, const std::string &caller, const std::string &fname, const Io::IoFlags &, Io::Fd &, void *&, const std::string &desc, const bool shared=false)=0
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void copyFileLayout(TDirectory *, TDirectory *)
helper function to recursively copy the layout of a TFile into a new TFile
Definition: THistSvc.cpp:1966
TDirectory * changeDir(const THistSvc::THistID &hid) const
Definition: THistSvc.cpp:1743
dictionary opts
Definition: ana.py:111
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
uidMap m_uids
Definition: THistSvc.h:199
IFileMgr * p_fileMgr
Definition: THistSvc.h:214
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:143
MsgStream m_log
Definition: THistSvc.h:178
virtual Io::close_t close(const Io::Fd, const std::string &caller)=0
void THistSvc::MergeRootFile ( TDirectory *  target,
TDirectory *  source 
)
private

Definition at line 1820 of file THistSvc.cpp.

1820  {
1821 
1822  if (m_log.level() <= MSG::DEBUG)
1823  m_log <<MSG::DEBUG << "Target path: " << target->GetPath() << endmsg;
1824  TString path( (char*)strstr(target->GetPath(), ":") );
1825  path.Remove( 0, 2);
1826 
1827  source->cd(path);
1828  TDirectory *current_sourcedir = gDirectory;
1829 
1830  // loop over all keys in this directory
1831  TList *lkeys=current_sourcedir->GetListOfKeys();
1832  int nkeys=lkeys->GetEntries();
1833  TKey *key;
1834  for (int jj=0; jj<nkeys; jj++) {
1835  key=(TKey*) lkeys->At(jj);
1836  string pathnameinsource=current_sourcedir->GetPath()+string("/")+key->GetName();
1837  if (m_log.level() <= MSG::DEBUG)
1838  m_log <<MSG::DEBUG << "Reading Key:" << pathnameinsource << endmsg;
1839  //key->Dump();
1840  //TObject *obj=key->ReadObj();
1841  TObject *obj=source->Get(pathnameinsource.c_str());
1842 
1843  if (obj) {
1844  if (obj->IsA()->InheritsFrom("TDirectory") ) {
1845  // it's a subdirectory
1846 
1847  if (m_log.level() <= MSG::DEBUG)
1848  m_log <<MSG::DEBUG << "Found subdirectory " << obj->GetName()
1849  << endmsg;
1850 
1851  // create a new subdir of same name and title in the target file
1852  target->cd();
1853  TDirectory *newtargetdir =
1854  target->mkdir(obj->GetName(), obj->GetTitle() );
1855 
1856  MergeRootFile(newtargetdir, source);
1857 
1858  } else if (obj->IsA()->InheritsFrom("TTree")) {
1859  if (m_log.level() <= MSG::DEBUG)
1860  m_log <<MSG::DEBUG << "Found TTree " << obj->GetName() << endmsg;
1861  TTree *mytree=dynamic_cast<TTree*>(obj);
1862  int nentries=(int) mytree->GetEntries();
1863  mytree->SetBranchStatus("*",1);
1864 
1865  if (m_log.level() <= MSG::DEBUG)
1866  m_log <<MSG::DEBUG << "Dumping TTree " << nentries <<" entries"
1867  << endmsg;
1868  //mytree->Print();
1869  //for (int ij=0; ij<nentries; ij++) {
1870  //m_log <<MSG::DEBUG << "Dumping TTree Show( " << ij <<" )"
1871  //<< endmsg;
1872  //mytree->Show(ij);
1873  //}
1874  target->cd();
1875  mytree->CloneTree();
1876 
1877  //m_log <<MSG::DEBUG << "Writing TTree to target file: ( "
1878  //<< mycopiedtree->Write(key->GetName()) <<" ) bytes written"
1879  //<< endmsg;
1880 
1881  } else {
1882  target->cd();
1883  obj->Write(key->GetName() );
1884  }
1885  }
1886 
1887  } // while ( ( TKey *key = (TKey*)nextkey() ) )
1888 
1889  // save modifications to target file
1890 
1891 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
list path
Definition: __init__.py:15
MsgStream m_log
Definition: THistSvc.h:178
void MergeRootFile(TDirectory *target, TDirectory *source)
Definition: THistSvc.cpp:1820
void THistSvc::parseString ( const std::string &  id,
std::string &  root,
std::string &  rem 
) const
private

Definition at line 1257 of file THistSvc.cpp.

1257  {
1258  string::size_type pos = id.find("/");
1259 
1260  if (pos == string::npos) {
1261  root = "";
1262  rem = id;
1263  return;
1264  }
1265 
1266  if (pos == 0) {
1267  parseString(id.substr(1,id.length()),root,rem);
1268  } else {
1269  root = id.substr(0,pos);
1270  rem = id.substr(pos+1,id.length());
1271  }
1272 
1273 }
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1257
tuple root
Definition: IOTest.py:42
StatusCode THistSvc::readHist ( const std::string &  name,
TH1 *&  hist 
) const
private

Definition at line 1182 of file THistSvc.cpp.

1182  {
1183  return readHist_i(id, hist);
1184 }
StatusCode readHist_i(const std::string &name, T *&hist) const
Definition: THistSvc.icc:243
StatusCode THistSvc::readHist ( const std::string &  name,
TH2 *&  hist 
) const
private

Definition at line 1189 of file THistSvc.cpp.

1189  {
1190  return readHist_i(id, hist);
1191 }
StatusCode readHist_i(const std::string &name, T *&hist) const
Definition: THistSvc.icc:243
StatusCode THistSvc::readHist ( const std::string &  name,
TH3 *&  hist 
) const
private

Definition at line 1196 of file THistSvc.cpp.

1196  {
1197  return readHist_i(id, hist);
1198 }
StatusCode readHist_i(const std::string &name, T *&hist) const
Definition: THistSvc.icc:243
template<typename T >
StatusCode THistSvc::readHist_i ( const std::string &  name,
T *&  hist 
) const
private

Definition at line 243 of file THistSvc.icc.

243  {
244 
245  GlobalDirectoryRestore restore;
246 
247  std::string idr(id);
248  removeDoubleSlash( idr );
249 
250  std::string stream, rem, dir, fdir, bdir, fdir2;
251  TFile *file;
252 
253  if (!findStream(idr, stream, rem, file) ) {
254  return StatusCode::FAILURE;
255  }
256 
257  if (file == 0) {
258  m_log << MSG::ERROR << "no associated file found" << endmsg;
259  return StatusCode::FAILURE;
260  }
261 
262  file->cd("/");
263 
264  fdir = idr;
265  bdir = dirname(fdir);
266  fdir2 = fdir;
267  while ( (dir=dirname(fdir)) != "" ) {
268  if (! gDirectory->GetKey(dir.c_str())) {
269  m_log << MSG::ERROR << "Directory \"" << fdir2 << "\" doesnt exist in "
270  << file->GetName() << endmsg;
271  return StatusCode::FAILURE;
272  }
273  gDirectory->cd(dir.c_str());
274  }
275 
276  TObject *to;
277  gDirectory->GetObject(fdir.c_str(), to);
278 
279  if (to == 0) {
280  m_log << MSG::ERROR << "Could not get obj \"" << fdir << "\" in "
281  << gDirectory->GetPath() << endmsg;
282  return StatusCode::FAILURE;
283  }
284 
285 
286 
287  hist = dynamic_cast<T*>(to);
288  if (hist == 0) {
289  m_log << MSG::ERROR << "Could not convert \"" << idr << "\" to a "
290  << System::typeinfoName(typeid(*hist)) << " as is a "
291  << to->IsA()->GetName()
292  << endmsg;
293  return StatusCode::FAILURE;
294  }
295 
296 
297  if (m_log.level() <= MSG::DEBUG) {
298  m_log << MSG::DEBUG << "Read in " << hist->IsA()->GetName() << " \""
299  << hist->GetName() << "\" from file "
300  << file->GetName() << endmsg;
301  hist->Print();
302  }
303 
304  return StatusCode::SUCCESS;
305 
306 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:299
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
Definition: THistSvc.cpp:1210
std::string dirname(std::string &dir) const
Definition: THistSvc.cpp:1772
list file
Definition: ana.py:160
MsgStream m_log
Definition: THistSvc.h:178
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1810
StatusCode THistSvc::readTree ( const std::string &  name,
TTree *&  hist 
) const
private

Definition at line 1203 of file THistSvc.cpp.

1203  {
1204  return readHist_i(id, hist);
1205 }
StatusCode readHist_i(const std::string &name, T *&hist) const
Definition: THistSvc.icc:243
StatusCode THistSvc::regGraph ( const std::string &  name)
virtual

Implements ITHistSvc.

Definition at line 1056 of file THistSvc.cpp.

1056  {
1057  TGraph *hist(0);
1058  return regHist_i(hist, id);
1059 }
StatusCode regHist_i(T *hist, const std::string &name)
Definition: THistSvc.icc:17
StatusCode THistSvc::regGraph ( const std::string &  name,
TGraph *  hist 
)
virtual

Implements ITHistSvc.

Definition at line 1064 of file THistSvc.cpp.

1064  {
1065  if ( strcmp(hist->GetName(),"Graph") == 0 ) {
1066 
1067  std::string id2(id);
1068  string::size_type i = id2.rfind("/");
1069  if (i != string::npos) {
1070  id2.erase(0,i+1);
1071  }
1072 
1073  m_log << MSG::INFO << "setting name of TGraph id: \"" << id << "\" to \""
1074  << id2 << "\" since it is unset" << endmsg;
1075  hist->SetName(id2.c_str());
1076  }
1077 
1078  return regHist_i(hist, id);
1079 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode regHist_i(T *hist, const std::string &name)
Definition: THistSvc.icc:17
MsgStream m_log
Definition: THistSvc.h:178
list i
Definition: ana.py:128
StatusCode THistSvc::regHist ( const std::string &  name)
virtual

Implements ITHistSvc.

Definition at line 1004 of file THistSvc.cpp.

1004  {
1005 
1006  TH1 *hist(0);
1007 
1008  return regHist_i(hist, id);
1009 }
StatusCode regHist_i(T *hist, const std::string &name)
Definition: THistSvc.icc:17
StatusCode THistSvc::regHist ( const std::string &  name,
TH1 *  hist 
)
virtual

Implements ITHistSvc.

Definition at line 1014 of file THistSvc.cpp.

1014  {
1015  return regHist_i(hist, id);
1016 }
StatusCode regHist_i(T *hist, const std::string &name)
Definition: THistSvc.icc:17
StatusCode THistSvc::regHist ( const std::string &  name,
TH2 *  hist 
)
virtual

Implements ITHistSvc.

Definition at line 1021 of file THistSvc.cpp.

1021  {
1022  return regHist_i(hist, id);
1023 }
StatusCode regHist_i(T *hist, const std::string &name)
Definition: THistSvc.icc:17
StatusCode THistSvc::regHist ( const std::string &  name,
TH3 *  hist 
)
virtual

Implements ITHistSvc.

Definition at line 1028 of file THistSvc.cpp.

1028  {
1029  return regHist_i(hist, id);
1030 }
StatusCode regHist_i(T *hist, const std::string &name)
Definition: THistSvc.icc:17
template<typename T >
StatusCode THistSvc::regHist_i ( T *  hist,
const std::string &  name 
)
private

Definition at line 17 of file THistSvc.icc.

17  {
18 
19  GlobalDirectoryRestore restore;
20 
21  std::string idr(id);
22  removeDoubleSlash( idr );
23 
24  if (idr.find("/") == idr.length()) {
25  m_log << MSG::ERROR << "Badly formed identifier \"" << idr << "\": "
26  << "Must not end with a /" << endmsg;
27  return StatusCode::FAILURE;
28  }
29 
30 
31  TFile *f(0);
32  std::string stream,rem;
33  if (!findStream(idr, stream, rem, f)) {
34  m_log << MSG::ERROR << "Could not register id: \"" << idr << "\""
35  << endmsg;
36  return StatusCode::FAILURE;
37  }
38 
39  std::string uid = "/" + stream + "/" + rem;
40  uidMap::const_iterator itr = m_uids.find(uid);
41  if (itr != m_uids.end()) {
42  m_log << MSG::ERROR << "already registered an object with identifier \""
43  << idr << "\"" << endmsg;
44  return StatusCode::FAILURE;
45  }
46 
47 
48  bool temp = false;
49  if (f == 0) {
50  temp = true;
51  if (m_log.level() <= MSG::DEBUG)
52  m_log << MSG::DEBUG << "Historgram with id \"" << idr << "\" is temporary"
53  << endmsg;
54  }
55 
56 
57  TObject *to;
58  THistID hid;
59 
60  // check to see if this hist is to be read in;
61  if (!temp && m_files.find(stream)->second.second == READ) {
62 
63  if (hist != 0) {
64  m_log << MSG::WARNING << "Registering id: \"" << idr
65  << "\" with non zero pointer!" << endmsg;
66  }
67 
68  if (readHist_i(idr,hist).isFailure()) {
69  m_log << MSG::ERROR << "Unable to read in hist" << endmsg;
70  return StatusCode::FAILURE;
71  }
72  to = dynamic_cast<TObject*>(hist);
73  hid = THistID(uid,temp,to,f,m_files.find(stream)->second.second);
74 
75  } else if (hist == 0) {
76  m_log << MSG::ERROR << "Unable to read in hist with id: \""
77  << idr << "\"" << endmsg;
78  return StatusCode::FAILURE;
79 
80  } else {
81 
82  to = dynamic_cast<TObject*>(hist);
83  if (to == 0) {
84  m_log << MSG::ERROR << "Could not dcast to TObject. id: \"" << idr
85  << "\"" << endmsg;
86  return StatusCode::FAILURE;
87  }
88 
89  objMap::const_iterator oitr = m_tobjs.find(to);
90  if (oitr != m_tobjs.end()) {
91  m_log << MSG::ERROR << "already registered id: \"" << idr
92  << "\" with identifier \"" << oitr->second.id << "\"" << endmsg;
93  return StatusCode::FAILURE;
94  }
95 
96  hid = THistID(uid,temp,to,f,m_files.find(stream)->second.second);
97  TDirectory* dir = changeDir(hid);
98 
99  if ( dynamic_cast<TTree*>(hist) != 0 ) {
100  dynamic_cast<TTree*>(hist)->SetDirectory(dir);
101  } else if ( dynamic_cast<TH1*>(hist) != 0 ) {
102  dynamic_cast<TH1*>(hist)->SetDirectory(dir);
103  } else if ( dynamic_cast<TGraph*>(hist) != 0 ) {
104  dir->Append(hist);
105  } else {
106  m_log << MSG::ERROR << "id: \"" << idr
107  << "\" is not a TH, TTree, or TGraph. Attaching it to current dir."
108  << endmsg;
109  dir->Append(hist);
110  }
111 
112  }
113 
114  std::string fname;
115  if (f == 0) {
116  fname = "none";
117  } else {
118  fname = f->GetName();
119  }
120 
121  if (m_log.level() <= MSG::DEBUG)
122  m_log << MSG::DEBUG << "Registering " << System::typeinfoName(typeid(*hist))
123  << " title: \"" << hist->GetTitle()
124  << "\" id: \"" << uid << "\" dir: "
125  // << hist->GetDirectory()->GetPath() << " "
126  << changeDir(hid)->GetPath()
127  << " file: " << fname
128  << endmsg;
129 
130  m_ids.insert(std::pair<std::string,THistID>(rem, hid));
131  m_uids[uid] = hid;
132  m_tobjs[to] = hid;
133 
134  return StatusCode::SUCCESS;
135 
136 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:299
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
Definition: THistSvc.cpp:1210
TDirectory * changeDir(const THistSvc::THistID &hid) const
Definition: THistSvc.cpp:1743
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
objMap m_tobjs
Definition: THistSvc.h:201
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
uidMap m_uids
Definition: THistSvc.h:199
StatusCode readHist_i(const std::string &name, T *&hist) const
Definition: THistSvc.icc:243
idMap m_ids
Definition: THistSvc.h:200
MsgStream m_log
Definition: THistSvc.h:178
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1810
StatusCode THistSvc::regTree ( const std::string &  name)
virtual

Implements ITHistSvc.

Definition at line 1035 of file THistSvc.cpp.

1035  {
1036  TTree *hist(0);
1037  return regHist_i(hist, id);
1038 }
StatusCode regHist_i(T *hist, const std::string &name)
Definition: THistSvc.icc:17
StatusCode THistSvc::regTree ( const std::string &  name,
TTree *  hist 
)
virtual

Implements ITHistSvc.

Definition at line 1043 of file THistSvc.cpp.

1043  {
1044  StatusCode sc = regHist_i(hist, id);
1045  if (hist != 0 && sc.isSuccess()) {
1046  if (m_autoSave != 0)
1047  hist->SetAutoSave(m_autoSave);
1048  hist->SetAutoFlush(m_autoFlush);
1049  }
1050  return sc;
1051 }
IntegerProperty m_autoFlush
Definition: THistSvc.h:182
IntegerProperty m_autoSave
Definition: THistSvc.h:182
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
StatusCode regHist_i(T *hist, const std::string &name)
Definition: THistSvc.icc:17
StatusCode THistSvc::reinitialize ( )
virtual

Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).

Reimplemented from Service.

Definition at line 233 of file THistSvc.cpp.

233  {
234 
235  GlobalDirectoryRestore restore;
236 
237  m_log << MSG::WARNING << "reinitialize not implemented" << endmsg;
238 
239 
240  return StatusCode::SUCCESS;
241 
242 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MsgStream m_log
Definition: THistSvc.h:178
void THistSvc::removeDoubleSlash ( std::string &  id) const
private

Definition at line 1810 of file THistSvc.cpp.

1810  {
1811 
1812  while (id.find("//") != std::string::npos) {
1813  id.replace(id.find("//"),2,"/");
1814  }
1815 
1816 }
StatusCode THistSvc::rootOpenAction ( FILEMGR_CALLBACK_ARGS  )
private

Definition at line 2129 of file THistSvc.cpp.

2129  {
2130 
2131  if (fa->tech() != Io::ROOT) {
2132  // This should never happen
2133  return StatusCode::SUCCESS;
2134  }
2135 
2136  if (fa->desc() != "HIST") {
2137  return StatusCode::SUCCESS;
2138  }
2139 
2140  p_incSvc->fireIncident(FileIncident(caller, "OpenHistFile", fa->name()));
2141 
2142  if ( fa->flags().isRead() ) {
2143  p_incSvc->fireIncident(FileIncident(caller, "BeginHistFile", fa->name()));
2144  } else if ( fa->flags().isWrite() ) {
2146  fa->name()));
2147  } else {
2148  // for Io::RW
2150  fa->name()));
2151  }
2152 
2153  return StatusCode::SUCCESS;
2154 
2155 
2156 }
This class is the FileIncident.
Definition: FileIncident.h:18
IIncidentSvc * p_incSvc
Definition: THistSvc.h:213
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
const std::string BeginOutputFile
a new output file has been created
Definition: Incident.h:72
StatusCode THistSvc::rootOpenErrAction ( FILEMGR_CALLBACK_ARGS  )
private

Definition at line 2161 of file THistSvc.cpp.

2161  {
2162 
2163  if (fa->tech() != Io::ROOT) {
2164  // This should never happen
2165  return StatusCode::SUCCESS;
2166  }
2167 
2168  if (fa->desc() != "HIST") {
2169  return StatusCode::SUCCESS;
2170  }
2171 
2172  if ( fa->flags().isRead() ) {
2174  fa->name()));
2175  } else if ( fa->flags().isWrite() ) {
2177  fa->name()));
2178  } else {
2179  // for Io::RW
2180  p_incSvc->fireIncident(FileIncident(caller, "FailRWFile", fa->name()));
2181  }
2182 
2183 
2184  return StatusCode::SUCCESS;
2185 
2186 
2187 }
This class is the FileIncident.
Definition: FileIncident.h:18
IIncidentSvc * p_incSvc
Definition: THistSvc.h:213
const std::string FailInputFile
could not open or read from this file
Definition: Incident.h:78
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
const std::string FailOutputFile
could not create or write to this file
Definition: Incident.h:73
void THistSvc::setupCompressionLevel ( Property cmp)
private

Definition at line 1278 of file THistSvc.cpp.

1279 {
1280 
1281  m_log << MSG::WARNING << "\"CompressionLevel\" Property has been deprecated. "
1282  << "Set it via the \"CL=\" parameter in the \"Output\" Property"
1283  << endmsg;
1284 
1285 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MsgStream m_log
Definition: THistSvc.h:178
void THistSvc::setupInputFile ( Property inputfile)
private

call-back method to handle input stream property

Definition at line 1291 of file THistSvc.cpp.

1292 {
1293 
1295 
1296  m_log <<MSG::DEBUG << "Delaying connection of Input Files until Initialize"
1297  << ". now in " << FSMState()
1298  << endmsg;
1299 
1300  m_delayConnect = true;
1301  } else {
1302 
1303  m_log <<MSG::DEBUG << "Now connecting of Input Files"
1304  << endmsg;
1305 
1307 
1308  typedef std::vector<std::string> Strings_t;
1309  for ( Strings_t::const_iterator
1310  itr = m_inputfile.value().begin(),
1311  iEnd = m_inputfile.value().end();
1312  itr != iEnd;
1313  ++itr ) {
1314  if ( m_alreadyConnectedInFiles.end() ==
1315  m_alreadyConnectedInFiles.find( *itr ) ) {
1316  if ( connect(*itr).isFailure() ) {
1317  sc = StatusCode::FAILURE;
1318  } else {
1319  m_alreadyConnectedInFiles.insert( *itr );
1320  }
1321  }
1322  }
1323 
1324  if ( !sc.isSuccess() ) {
1325  throw GaudiException( "Problem connecting inputfile !!", name(),
1327  }
1328 
1329  }
1330 
1331  return;
1332 }
bool m_delayConnect
Definition: THistSvc.h:209
Define general base for Gaudi exception.
std::vector< std::string > Strings_t
Definition: genconf.cpp:88
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
StringArrayProperty m_inputfile
Definition: THistSvc.h:180
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
bool m_okToConnect
Definition: THistSvc.h:209
virtual Gaudi::StateMachine::State FSMState() const
Get the current state.
Definition: Service.h:56
const TYPE & value() const
explicit conversion
Definition: Property.h:355
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
StatusCode connect(const std::string &)
Definition: THistSvc.cpp:1512
MsgStream m_log
Definition: THistSvc.h:178
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
Definition: THistSvc.h:187
void THistSvc::setupOutputFile ( Property outputfile)
private

call-back method to handle output stream property

Definition at line 1337 of file THistSvc.cpp.

1338 {
1340  m_log <<MSG::DEBUG << "Delaying connection of Input Files until Initialize"
1341  << ". now in " << FSMState()
1342  << endmsg;
1343  m_delayConnect = true;
1344  } else {
1345 
1347 
1348  typedef std::vector<std::string> Strings_t;
1349  for ( Strings_t::const_iterator
1350  itr = m_outputfile.value().begin(),
1351  iEnd = m_outputfile.value().end();
1352  itr != iEnd;
1353  ++itr ) {
1354  if ( m_alreadyConnectedOutFiles.end() ==
1355  m_alreadyConnectedOutFiles.find( *itr ) ) {
1356  if ( connect(*itr).isFailure() ) {
1357  sc = StatusCode::FAILURE;
1358  } else {
1359  m_alreadyConnectedOutFiles.insert( *itr );
1360  }
1361  }
1362  }
1363 
1364  if ( !sc.isSuccess() ) {
1365  throw GaudiException( "Problem connecting outputfile !!", name(),
1367  }
1368  return;
1369  }
1370 }
bool m_delayConnect
Definition: THistSvc.h:209
Define general base for Gaudi exception.
std::vector< std::string > Strings_t
Definition: genconf.cpp:88
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
StringArrayProperty m_outputfile
Definition: THistSvc.h:180
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
bool m_okToConnect
Definition: THistSvc.h:209
virtual Gaudi::StateMachine::State FSMState() const
Get the current state.
Definition: Service.h:56
const TYPE & value() const
explicit conversion
Definition: Property.h:355
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
StatusCode connect(const std::string &)
Definition: THistSvc.cpp:1512
std::set< std::string > m_alreadyConnectedOutFiles
list of already connected files.
Definition: THistSvc.h:191
MsgStream m_log
Definition: THistSvc.h:178
void THistSvc::updateFiles ( )
private

Definition at line 1375 of file THistSvc.cpp.

1375  {
1376 
1377  // If TTrees grow beyond TTree::fgMaxTreeSize, a new file is
1378  // automatically created by root, and the old one closed. We
1379  // need to migrate all the UIDs over to show the correct file
1380  // pointer. This is ugly.
1381 
1382  if (m_log.level() <= MSG::DEBUG)
1383  m_log << MSG::DEBUG << "updateFiles()" << endmsg;
1384 
1385 
1386  uidMap::iterator uitr, uitr2;
1387  for (uitr=m_uids.begin(); uitr != m_uids.end(); ++uitr) {
1388 #ifndef NDEBUG
1389  if (m_log.level() <= MSG::VERBOSE)
1390  m_log << MSG::VERBOSE << " update: " << uitr->first << " "
1391  << uitr->second.id << " " << uitr->second.mode << endmsg;
1392 #endif
1393  TObject* to = uitr->second.obj;
1394  TFile* oldFile = uitr->second.file;
1395  if (!to) {
1396  m_log << MSG::WARNING << uitr->first << ": TObject == 0" << endmsg;
1397  } else if ( uitr->second.temp || uitr->second.mode == READ ) {
1398  // do nothing - no need to check how big the file is since we
1399  // are just reading it.
1400 #ifndef NDEBUG
1401  if (m_log.level() <= MSG::VERBOSE)
1402  m_log << MSG::VERBOSE << " skipping" << endmsg;
1403 #endif
1404 
1405  } else if (to->IsA()->InheritsFrom("TTree")) {
1406  TTree* tr = dynamic_cast<TTree*>(to);
1407  TFile* newFile = tr->GetCurrentFile();
1408 
1409  if (oldFile != newFile) {
1410  std::string newFileName = newFile->GetName();
1411  std::string oldFileName(""), streamName, rem;
1412  TFile* dummy;
1413  findStream(uitr->second.id, streamName, rem, dummy);
1414 
1415  map<string, pair<TFile*,Mode> >::iterator itr;
1416  for (itr=m_files.begin(); itr!= m_files.end(); ++itr) {
1417  if (itr->second.first == oldFile) {
1418  itr->second.first = newFile;
1419 
1420  }
1421  }
1422 
1423  uitr2 = uitr;
1424  for (; uitr2 != m_uids.end(); ++uitr2) {
1425  if (uitr2->second.file == oldFile) {
1426  uitr2->second.file = newFile;
1427  }
1428  }
1429 
1430  streamMap::iterator sitr;
1431  for (sitr = m_fileStreams.begin(); sitr!=m_fileStreams.end(); ++sitr) {
1432  if (sitr->second == streamName) {
1433  oldFileName = sitr->first;
1434  break;
1435  }
1436  }
1437 
1438 
1439 #ifndef NDEBUG
1440  if (m_log.level() <= MSG::DEBUG)
1441  m_log << MSG::DEBUG << "migrating uid: " << uitr->second.id
1442  << " stream: " << streamName
1443  << " oldFile: " << oldFileName
1444  << " newFile: " << newFileName
1445  << endmsg;
1446 #endif
1447 
1448 
1449  if (oldFileName != "") {
1450  while ( (sitr=m_fileStreams.find(oldFileName)) != m_fileStreams.end() ) {
1451 
1452 #ifndef NDEBUG
1453  if (m_log.level() <= MSG::DEBUG)
1454  m_log << MSG::DEBUG << "changing filename \"" << oldFileName
1455  << "\" to \"" << newFileName << "\" for stream \""
1456  << sitr->second << "\"" << endmsg;
1457 #endif
1458  m_fileStreams.erase(sitr);
1459  m_fileStreams.insert( make_pair(newFileName,streamName) );
1460  }
1461 
1462 
1463  } else {
1464  m_log << MSG::ERROR
1465  << "Problems updating fileStreams with new file name" << endmsg;
1466  }
1467 
1468  }
1469 
1470  }
1471  }
1472 
1473 }
if(ep)
Definition: Bootstrap.cpp:337
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
Definition: THistSvc.cpp:1210
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
uidMap m_uids
Definition: THistSvc.h:199
MsgStream m_log
Definition: THistSvc.h:178
streamMap m_fileStreams
Definition: THistSvc.h:204
StatusCode THistSvc::write ( )
private

Definition at line 1478 of file THistSvc.cpp.

1478  {
1479 
1480  updateFiles();
1481 
1482  map<string, pair<TFile*,Mode> >::const_iterator itr;
1483  for (itr=m_files.begin(); itr!= m_files.end(); ++itr) {
1484  if (itr->second.second == WRITE || itr->second.second == UPDATE
1485  ||itr->second.second==SHARE) {
1486  itr->second.first->Write("",TObject::kOverwrite);
1487  } else if (itr->second.second == APPEND) {
1488  itr->second.first->Write("");
1489  }
1490  }
1491 
1492 
1493  if (m_log.level() <= MSG::DEBUG)
1494  m_log << MSG::DEBUG << "THistSvc::write()::List of Files connected in ROOT "
1495  << endmsg;
1496 
1497  TSeqCollection *filelist=gROOT->GetListOfFiles();
1498  for (int ii=0; ii<filelist->GetEntries(); ii++) {
1499  if (m_log.level() <= MSG::DEBUG)
1500  m_log << MSG::DEBUG
1501  << "THistSvc::write()::List of Files connected in ROOT: \""
1502  << filelist->At(ii)->GetName()<<"\""<<endmsg;
1503  }
1504 
1505  return StatusCode::SUCCESS;
1506 
1507 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:203
MsgStream m_log
Definition: THistSvc.h:178
void updateFiles()
Definition: THistSvc.cpp:1375

Member Data Documentation

std::set<std::string> THistSvc::m_alreadyConnectedInFiles
private

list of already connected files.

This is to keep track of files registered by the setupInputFile callback method

Definition at line 187 of file THistSvc.h.

std::set<std::string> THistSvc::m_alreadyConnectedOutFiles
private

list of already connected files.

This is to keep track of files registered by the setupOutputFile callback method

Definition at line 191 of file THistSvc.h.

IntegerProperty THistSvc::m_autoFlush
private

Definition at line 182 of file THistSvc.h.

IntegerProperty THistSvc::m_autoSave
private

Definition at line 182 of file THistSvc.h.

IntegerProperty THistSvc::m_compressionLevel
private

Definition at line 182 of file THistSvc.h.

std::string THistSvc::m_curstream
mutableprivate

Definition at line 211 of file THistSvc.h.

bool THistSvc::m_delayConnect
private

Definition at line 209 of file THistSvc.h.

std::map<std::string, std::pair<TFile*,Mode> > THistSvc::m_files
private

Definition at line 203 of file THistSvc.h.

streamMap THistSvc::m_fileStreams
private

Definition at line 204 of file THistSvc.h.

idMap THistSvc::m_ids
private

Definition at line 200 of file THistSvc.h.

StringArrayProperty THistSvc::m_inputfile
private

Definition at line 180 of file THistSvc.h.

MsgStream THistSvc::m_log
mutableprivate

Definition at line 178 of file THistSvc.h.

IntegerProperty THistSvc::m_maxFileSize
private

Definition at line 182 of file THistSvc.h.

bool THistSvc::m_okToConnect
private

Definition at line 209 of file THistSvc.h.

StringArrayProperty THistSvc::m_outputfile
private

Definition at line 180 of file THistSvc.h.

BooleanProperty THistSvc::m_print
private

Definition at line 183 of file THistSvc.h.

std::vector<std::string> THistSvc::m_Rstream
private

Definition at line 181 of file THistSvc.h.

std::map<std::string, std::string > THistSvc::m_sharedFiles
private

Definition at line 206 of file THistSvc.h.

objMap THistSvc::m_tobjs
private

Definition at line 201 of file THistSvc.h.

uidMap THistSvc::m_uids
private

Definition at line 199 of file THistSvc.h.

std::vector<std::string> THistSvc::m_Wstream
private

Definition at line 181 of file THistSvc.h.

IFileMgr* THistSvc::p_fileMgr
private

Definition at line 214 of file THistSvc.h.

IIncidentSvc* THistSvc::p_incSvc
private

Definition at line 213 of file THistSvc.h.

bool THistSvc::signaledStop
private

Definition at line 208 of file THistSvc.h.


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