The Gaudi Framework  v33r0 (d5ea422b)
THistSvc Class Reference

#include <src/THistSvc/THistSvc.h>

Inheritance diagram for THistSvc:
Collaboration diagram for THistSvc:

Classes

class  GlobalDirectoryRestore
 Helper class that manages ROOts global directory and file. More...
 
struct  THistID
 Helper struct that bundles the histogram ID with a mutex, TFile and TObject*. More...
 

Public Member Functions

StatusCode initialize () override
 
StatusCode reinitialize () override
 
StatusCode finalize () override
 
void handle (const Incident &) override
 
StatusCode io_reinit () override
 callback method to reinitialize the internal state of the component for I/O purposes (e.g. More...
 
Functions to manage ROOT histograms of any kind
StatusCode regHist (const std::string &name) override
 Register a new ROOT histogram TH*X with a name. More...
 
StatusCode regHist (const std::string &name, std::unique_ptr< TH1 > hist) override
 Register an existing ROOT histogram TH*X with name and moved unique_ptr. More...
 
StatusCode regHist (const std::string &name, std::unique_ptr< TH1 > hist, TH1 *hist_ptr) override
 Register an existing ROOT histogram TH*X with name and moved unique_ptr. More...
 
StatusCode regHist (const std::string &name, TH1 *) override
 
StatusCode getHist (const std::string &name, TH1 *&, size_t index=0) const override
 Return histogram with given name as TH1*, THistSvcMT still owns object. More...
 
StatusCode getHist (const std::string &name, TH2 *&, size_t index=0) const override
 Return histogram with given name as TH2*, THistSvcMT still owns object. More...
 
StatusCode getHist (const std::string &name, TH3 *&, size_t index=0) const override
 Return histogram with given name as TH3*, THistSvcMT still owns object. More...
 
Functions to manage TTrees
StatusCode regTree (const std::string &name) override
 Register a new TTree with a given name. More...
 
StatusCode regTree (const std::string &name, std::unique_ptr< TTree >) override
 Register an existing TTree with a given name and moved unique_ptr. More...
 
StatusCode regTree (const std::string &name, TTree *) override
 
StatusCode getTree (const std::string &name, TTree *&) const override
 Return TTree with given name. More...
 
Functions to manage TGraphs
StatusCode regGraph (const std::string &name) override
 Register a new TGraph with a given name. More...
 
StatusCode regGraph (const std::string &name, std::unique_ptr< TGraph >) override
 Register an existing TGraph with a given name and moved unique_ptr. More...
 
virtual StatusCode regGraph (const std::string &name, TGraph *) override
 
StatusCode getGraph (const std::string &name, TGraph *&) const override
 Return TGraph with given name. More...
 
StatusCode regEfficiency (const std::string &name) override
 Register a new TEfficiency with a given name. More...
 
StatusCode regEfficiency (const std::string &name, std::unique_ptr< TEfficiency >) override
 Register an existing TEfficiency with a given name and moved unique_ptr. More...
 
virtual StatusCode regEfficiency (const std::string &name, TEfficiency *) override
 
StatusCode getEfficiency (const std::string &name, TEfficiency *&) const override
 Return TEfficiency with given name. More...
 
Functions managing shared objects
StatusCode regShared (const std::string &name, std::unique_ptr< TH1 >, LockedHandle< TH1 > &) override
 Register shared object of type TH1 and return LockedHandle for that object. More...
 
StatusCode regShared (const std::string &name, std::unique_ptr< TH2 >, LockedHandle< TH2 > &) override
 Register shared object of type TH2 and return LockedHandle for that object. More...
 
StatusCode regShared (const std::string &name, std::unique_ptr< TH3 >, LockedHandle< TH3 > &) override
 Register shared object of type TH3 and return LockedHandle for that object. More...
 
StatusCode regShared (const std::string &name, std::unique_ptr< TGraph >, LockedHandle< TGraph > &) override
 Register shared object of type TGraph and return LockedHandle for that object. More...
 
StatusCode regShared (const std::string &name, std::unique_ptr< TEfficiency >, LockedHandle< TEfficiency > &) override
 Register shared object of type TEfficiency and return LockedHandle for that object. More...
 
StatusCode getShared (const std::string &name, LockedHandle< TH1 > &) const override
 Retrieve shared object with given name as TH1 through LockedHandle. More...
 
StatusCode getShared (const std::string &name, LockedHandle< TH2 > &) const override
 Retrieve shared object with given name as TH2 through LockedHandle. More...
 
StatusCode getShared (const std::string &name, LockedHandle< TH3 > &) const override
 Retrieve shared object with given name as TH3 through LockedHandle. More...
 
StatusCode getShared (const std::string &name, LockedHandle< TGraph > &) const override
 Retrieve shared object with given name as TGraph through LockedHandle. More...
 
StatusCode getShared (const std::string &name, LockedHandle< TEfficiency > &) const override
 Retrieve shared object with given name as TEfficiency through LockedHandle. More...
 
Functions that work on any TObject in the THistSvcMT
StatusCode deReg (const std::string &name) override
 Deregister object with given name and give up ownership (without deletion!) More...
 
StatusCode deReg (TObject *obj) override
 Deregister obejct identified by TObject* and give up ownership (without deletion!) More...
 
StatusCode merge (const std::string &id) override
 Merge all clones for object with a given id. More...
 
StatusCode merge (TObject *) override
 Merge all clones for given TObject*. More...
 
bool exists (const std::string &name) const override
 Check if object with given name is managed by THistSvcMT exists calls existsHist and only works for TH1-descendants. More...
 
bool existsHist (const std::string &name) const override
 Check if histogram with given name is managed by THistSvcMT. More...
 
bool existsTree (const std::string &name) const override
 Check if tree with given name is managed by THistSvcMT. More...
 
bool existsGraph (const std::string &name) const override
 Check if graph with given name is managed by THistSvcMT. More...
 
bool existsEfficiency (const std::string &name) const override
 Check if TEfficiency with given name is managed by THistSvcMT. More...
 
Functions returning lists of all histograms, trees and graphs
std::vector< std::stringgetHists () const override
 
std::vector< std::stringgetTrees () const override
 
std::vector< std::stringgetGraphs () const override
 
std::vector< std::stringgetEfficiencies () const override
 
StatusCode getTHists (TDirectory *td, TList &, bool recurse=false) const override
 
StatusCode getTHists (const std::string &name, TList &, bool recurse=false) const override
 
StatusCode getTHists (TDirectory *td, TList &tl, bool recurse=false, bool reg=false) override
 
StatusCode getTHists (const std::string &name, TList &tl, bool recurse=false, bool reg=false) override
 
StatusCode getTTrees (TDirectory *td, TList &, bool recurse=false) const override
 
StatusCode getTTrees (const std::string &name, TList &, bool recurse=false) const override
 
StatusCode getTTrees (TDirectory *td, TList &tl, bool recurse=false, bool reg=false) override
 
StatusCode getTTrees (const std::string &name, TList &tl, bool recurse=false, bool reg=false) override
 
StatusCode getTEfficiencies (TDirectory *td, TList &, bool recurse=false) const override
 
StatusCode getTEfficiencies (const std::string &name, TList &, bool recurse=false) const override
 
StatusCode getTEfficiencies (TDirectory *td, TList &tl, bool recurse=false, bool reg=false) override
 
StatusCode getTEfficiencies (const std::string &name, TList &tl, bool recurse=false, bool reg=false) override
 
- Public Member Functions inherited from extends< Service, ITHistSvc, IIncidentListener, IIoComponent >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service. More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service. More...
 
StatusCode sysStart () override
 Initialize Service. More...
 
StatusCode sysStop () override
 Initialize Service. More...
 
StatusCode sysFinalize () override
 Finalize Service. More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 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<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, 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 >
StatusCode declareTool (ToolHandle< T > &handle, std::string toolTypeAndName, bool createIf=true)
 Declare used tool. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p) override
 set the property form another property More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 set the property from name and the value More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (const std::string &name) const override
 get the property by name More...
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (const std::string &name) const override
 Return true if we have a property with the given name. More...
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const
 Backward compatibility function for getting the output level. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
const 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...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () 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...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 

Private Types

enum  Mode {
  READ, WRITE, UPDATE, APPEND,
  SHARE, INVALID
}
 Enumerating all possible file access modes. More...
 
typedef std::recursive_mutex THistSvcMutex_t
 
typedef std::mutex histMut_t
 

Private Member Functions

Templated helper functions to register and retrieve Histograms and TObjects
template<typename T >
StatusCode regHist_i (std::unique_ptr< T > hist, const std::string &name, bool shared)
 
template<typename T >
StatusCode regHist_i (std::unique_ptr< T > hist, const std::string &name, bool shared, THistID *&hid)
 
template<typename T >
T * getHist_i (const std::string &name, const size_t &ind=0, bool quiet=false) const
 
template<typename T >
T * readHist_i (const std::string &name) const
 
template<typename T >
LockedHandle< T > regShared_i (const std::string &id, std::unique_ptr< T > hist)
 
template<typename T >
LockedHandle< T > getShared_i (const std::string &name) const
 
Collection of private helper methods
template<typename T >
T * readHist (const std::string &name) const
 
TTree * readTree (const std::string &name) const
 
void updateFiles ()
 Handle case where TTree grows beyond TTree::fgMaxTreeSize. More...
 
StatusCode writeObjectsToFile ()
 
StatusCode connect (const std::string &)
 
TDirectory * changeDir (const THistSvc::THistID &hid) const
 
std::string stripDirectoryName (std::string &dir) const
 
void removeDoubleSlash (std::string &) const
 
void MergeRootFile (TDirectory *, TDirectory *)
 
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 ()
 call-back method to handle input stream property More...
 
void setupOutputFile ()
 call-back method to handle output stream property More...
 
void copyFileLayout (TDirectory *, TDirectory *)
 helper function to recursively copy the layout of a TFile into a new TFile More...
 
size_t findHistID (const std::string &id, const THistID *&hid, const size_t &index=0) const
 
void dump () const
 
StatusCode merge (const THistID &)
 Helper method to merge THistID objects. More...
 
StatusCode merge (vhid_t *)
 Helper method to merge vectors of THistID. More...
 
StatusCode rootOpenAction (FILEMGR_CALLBACK_ARGS)
 
StatusCode rootOpenErrAction (FILEMGR_CALLBACK_ARGS)
 

Static Private Member Functions

static Mode charToMode (const char typ)
 Convert a char to a Mode enum. More...
 

Private Attributes

IIncidentSvcp_incSvc = nullptr
 
IFileMgrp_fileMgr = nullptr
 
bool m_signaledStop = false
 
bool m_delayConnect = false
 
bool m_okToConnect = false
 
std::string m_curstream
 
THistSvcMutex_t m_svcMut
 
Gaudi properties
Gaudi::Property< int > m_autoSave {this, "AutoSave", 0}
 
Gaudi::Property< int > m_autoFlush {this, "AutoFlush", 0}
 
Gaudi::Property< bool > m_print {this, "PrintAll", false}
 
Gaudi::Property< int > m_maxFileSize
 
Gaudi::Property< int > m_compressionLevel
 
Gaudi::Property< std::vector< std::string > > m_outputfile {this, "Output", {}, &THistSvc::setupOutputFile}
 
Gaudi::Property< std::vector< std::string > > m_inputfile {this, "Input", {}, &THistSvc::setupInputFile}
 

Container definitions

typedef std::vector< THistIDvhid_t
 
typedef std::list< vhid_t * > hlist_t
 
typedef std::unordered_map< std::string, vhid_t * > uidMap_t
 
typedef std::unordered_multimap< std::string, vhid_t * > idMap_t
 
typedef std::unordered_map< TObject *, std::pair< vhid_t *, size_t > > objMap_t
 
typedef std::multimap< std::string, std::stringstreamMap
 
std::vector< std::stringm_Rstream
 
std::vector< std::stringm_Wstream
 
std::set< std::stringm_alreadyConnectedInFiles
 list of already connected files. More...
 
std::set< std::stringm_alreadyConnectedOutFiles
 list of already connected files. More...
 
hlist_t m_hlist
 
uidMap_t m_uids
 
idMap_t m_ids
 
objMap_t m_tobjs
 
std::map< std::string, std::pair< TFile *, Mode > > m_files
 
streamMap m_fileStreams
 
std::map< std::string, std::stringm_sharedFiles
 

Additional Inherited Members

- Public Types inherited from extends< Service, ITHistSvc, IIncidentListener, IIoComponent >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
- Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory< IService *(const std::string &, ISvcLocator *)>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl = PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Member Functions inherited from Service
 ~Service () override
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
Gaudi::Details::PropertyBaseproperty (const std::string &name) const
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches. More...
 
MSG::Level resetMessaging ()
 Reinitialize internal states. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::Property< int > m_outputLevel {this, "OutputLevel", MSG::NIL, "output level"}
 
Gaudi::Property< bool > m_auditInit {this, "AuditServices", false, " unused"}
 
Gaudi::Property< bool > m_auditorInitialize {this, "AuditInitialize", false, "trigger auditor on initialize()"}
 
Gaudi::Property< bool > m_auditorStart {this, "AuditStart", false, "trigger auditor on start()"}
 
Gaudi::Property< bool > m_auditorStop {this, "AuditStop", false, "trigger auditor on stop()"}
 
Gaudi::Property< bool > m_auditorFinalize {this, "AuditFinalize", false, "trigger auditor on finalize()"}
 
Gaudi::Property< bool > m_auditorReinitialize {this, "AuditReinitialize", false, "trigger auditor on reinitialize()"}
 
Gaudi::Property< bool > m_auditorRestart {this, "AuditRestart", false, "trigger auditor on restart()"}
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service. More...
 

Detailed Description

Definition at line 40 of file THistSvc.h.

Member Typedef Documentation

◆ histMut_t

Definition at line 205 of file THistSvc.h.

◆ hlist_t

typedef std::list<vhid_t*> THistSvc::hlist_t
private

Definition at line 291 of file THistSvc.h.

◆ idMap_t

Definition at line 295 of file THistSvc.h.

◆ objMap_t

typedef std::unordered_map<TObject*, std::pair<vhid_t*, size_t> > THistSvc::objMap_t
private

Definition at line 296 of file THistSvc.h.

◆ streamMap

Definition at line 306 of file THistSvc.h.

◆ THistSvcMutex_t

Definition at line 204 of file THistSvc.h.

◆ uidMap_t

Definition at line 293 of file THistSvc.h.

◆ vhid_t

Definition at line 289 of file THistSvc.h.

Member Enumeration Documentation

◆ Mode

enum THistSvc::Mode
private

Enumerating all possible file access modes.

Enumerator
READ 
WRITE 
UPDATE 
APPEND 
SHARE 
INVALID 

Definition at line 221 of file THistSvc.h.

Member Function Documentation

◆ changeDir()

TDirectory * THistSvc::changeDir ( const THistSvc::THistID hid) const
private

Definition at line 1745 of file THistSvc.cpp.

1745  {
1746  std::string uid = hid.id;
1747  TFile* file = hid.file;
1748  std::string stream, fdir, bdir, dir, id;
1749 
1750  if ( file ) {
1751  file->cd( "/" );
1752  } else {
1753  gROOT->cd();
1754  }
1755 
1756  fdir = uid;
1757  bdir = stripDirectoryName( fdir );
1758 
1759  while ( ( dir = stripDirectoryName( fdir ) ) != "" ) {
1760  if ( !gDirectory->GetKey( dir.c_str() ) ) { gDirectory->mkdir( dir.c_str() ); }
1761  gDirectory->cd( dir.c_str() );
1762  }
1763 
1764  return gDirectory;
1765 }
std::string stripDirectoryName(std::string &dir) const
Definition: THistSvc.cpp:1767
STL class.
std::string id
Definition: THistSvc.h:241
T c_str(T... args)

◆ charToMode()

static Mode THistSvc::charToMode ( const char  typ)
inlinestaticprivate

Convert a char to a Mode enum.

Definition at line 224 of file THistSvc.h.

224  {
225  switch ( typ ) {
226  case 'O':
227  return READ;
228  case 'A':
229  return APPEND;
230  case 'R':
231  return UPDATE;
232  case 'S':
233  return SHARE;
234  default:
235  return INVALID;
236  }
237  }

◆ connect()

StatusCode THistSvc::connect ( const std::string ident)
private

Definition at line 1568 of file THistSvc.cpp.

1568  {
1569  auto loc = ident.find( " " );
1570  std::string stream = ident.substr( 0, loc );
1571  char typ( 0 );
1573  std::vector<Prop> props;
1574  std::string filename, db_typ( "ROOT" );
1575  int cl( 1 );
1576 
1577  if ( loc != std::string::npos ) {
1578  using Parser = Gaudi::Utils::AttribStringParser;
1579  for ( auto attrib : Parser( ident.substr( loc + 1 ) ) ) {
1580  auto TAG = boost::algorithm::to_upper_copy( attrib.tag );
1581  auto VAL = boost::algorithm::to_upper_copy( attrib.value );
1582 
1583  if ( TAG == "FILE" || TAG == "DATAFILE" ) {
1584  filename = attrib.value;
1586  } else if ( TAG == "OPT" ) {
1587  if ( VAL == "APPEND" || VAL == "UPDATE" ) {
1588  typ = 'A';
1589  } else if ( VAL == "CREATE" || VAL == "NEW" || VAL == "WRITE" ) {
1590  typ = 'N';
1591  } else if ( VAL == "RECREATE" ) {
1592  typ = 'R';
1593  } else if ( VAL == "SHARE" ) {
1594  typ = 'S';
1595  } else if ( VAL == "OLD" || VAL == "READ" ) {
1596  typ = 'O';
1597  } else {
1598  error() << "Unknown OPT: \"" << attrib.value << "\"" << endmsg;
1599  typ = 0;
1600  }
1601  } else if ( TAG == "TYP" ) {
1602  db_typ = std::move( attrib.value );
1603  } else if ( TAG == "CL" ) {
1604  cl = std::stoi( attrib.value );
1605  } else {
1606  props.emplace_back( attrib.tag, attrib.value );
1607  }
1608  }
1609  }
1610 
1611  if ( stream == "temp" ) {
1612  error() << "in JobOption \"" << ident << "\": stream name \"temp\" reserved." << endmsg;
1613  return StatusCode::FAILURE;
1614  }
1615 
1616  if ( db_typ != "ROOT" ) {
1617  error() << "in JobOption \"" << ident << "\": technology type \"" << db_typ << "\" not supported." << endmsg;
1618  return StatusCode::FAILURE;
1619  }
1620 
1621  if ( m_files.find( stream ) != m_files.end() ) {
1622  error() << "in JobOption \"" << ident << "\":\n stream \"" << stream << "\" already connected to file: \""
1623  << m_files[stream].first->GetName() << "\"" << endmsg;
1624  return StatusCode::FAILURE;
1625  }
1626 
1627  const auto newMode = charToMode( typ );
1628  if ( newMode == THistSvc::INVALID ) {
1629  error() << "No OPT= specified or unknown access mode in: " << ident << endmsg;
1630  return StatusCode::FAILURE;
1631  }
1632 
1633  // Is this file already connected to another stream?
1634  if ( m_fileStreams.find( filename ) != m_fileStreams.end() ) {
1635  auto fitr = m_fileStreams.equal_range( filename );
1636 
1637  const std::string& oldstream = fitr.first->second;
1638 
1639  const auto& f_info = m_files[oldstream];
1640 
1641  if ( newMode != f_info.second ) {
1642  error() << "in JobOption \"" << ident << "\":\n file \"" << filename << "\" already opened by stream: \""
1643  << oldstream << "\" with different access mode." << endmsg;
1644  return StatusCode::FAILURE;
1645  } else {
1646  TFile* f2 = f_info.first;
1647  m_files[stream] = std::make_pair( f2, newMode );
1648  if ( msgLevel( MSG::DEBUG ) )
1649  debug() << "Connecting stream: \"" << stream << "\" to previously opened TFile: \"" << filename << "\""
1650  << endmsg;
1651  return StatusCode::SUCCESS;
1652  }
1653  }
1654 
1655  IIncidentSvc* pi = nullptr;
1656  if ( service( "IncidentSvc", pi ).isFailure() ) {
1657  error() << "Unable to get the IncidentSvc" << endmsg;
1658  return StatusCode::FAILURE;
1659  }
1660 
1661  void* vf = nullptr;
1662  TFile* f = nullptr;
1663 
1664  if ( newMode == THistSvc::READ ) {
1665  // old file
1666  int r = p_fileMgr->open( Io::ROOT, name(), filename, Io::READ, vf, "HIST" );
1667 
1668  if ( r != 0 ) {
1669  error() << "Unable to open ROOT file " << filename << " for reading" << endmsg;
1670  return StatusCode::FAILURE;
1671  }
1672 
1673  f = (TFile*)vf;
1674 
1675  // FIX ME!
1676  pi->fireIncident( FileIncident( name(), "BeginHistFile", filename ) );
1677 
1678  } else if ( newMode == THistSvc::WRITE ) {
1679  // new file. error if file exists
1680  int r = p_fileMgr->open( Io::ROOT, name(), filename, ( Io::WRITE | Io::CREATE | Io::EXCL ), vf, "HIST" );
1681 
1682  if ( r != 0 ) {
1683  error() << "Unable to open ROOT file " << filename << " for writing" << endmsg;
1684  return StatusCode::FAILURE;
1685  }
1686 
1687  f = (TFile*)vf;
1688 
1689  } else if ( newMode == THistSvc::APPEND ) {
1690  // update file
1691  int r = p_fileMgr->open( Io::ROOT, name(), filename, ( Io::WRITE | Io::APPEND ), vf, "HIST" );
1692  if ( r != 0 ) {
1693  error() << "unable to open file \"" << filename << "\" for appending" << endmsg;
1694  return StatusCode::FAILURE;
1695  }
1696 
1697  f = (TFile*)vf;
1698 
1699  } else if ( newMode == THistSvc::SHARE ) {
1700  // SHARE file type
1701  // For SHARE files, all data will be stored in a temp file and will be
1702  // merged into the target file in writeObjectsToFile() when finalize(),
1703  // this help to solve some confliction. e.g. with storegate
1704  static int ishared = 0;
1705  std::string realfilename = filename;
1706  filename = "tmp_THistSvc_" + std::to_string( ishared++ ) + ".root";
1707 
1708  if ( msgLevel( MSG::DEBUG ) ) {
1709  debug() << "Creating temp file \"" << filename << "\" and realfilename=" << realfilename << endmsg;
1710  }
1711  m_sharedFiles[stream] = realfilename;
1712 
1713  int r = p_fileMgr->open( Io::ROOT, name(), filename, ( Io::WRITE | Io::CREATE | Io::EXCL ), vf, "HIST" );
1714 
1715  if ( r != 0 ) {
1716  error() << "Unable to open ROOT file " << filename << " for writing" << endmsg;
1717  return StatusCode::FAILURE;
1718  }
1719 
1720  f = (TFile*)vf;
1721 
1722  } else if ( newMode == THistSvc::UPDATE ) {
1723  // update file
1724  int r = p_fileMgr->open( Io::ROOT, name(), filename, ( Io::WRITE | Io::CREATE ), vf, "HIST" );
1725 
1726  if ( r != 0 ) {
1727  error() << "Unable to open ROOT file " << filename << " for appending" << endmsg;
1728  return StatusCode::FAILURE;
1729  }
1730 
1731  f = (TFile*)vf;
1732  }
1733 
1734  m_files[stream] = std::make_pair( f, newMode );
1736 
1737  if ( msgLevel( MSG::DEBUG ) ) {
1738  debug() << "Opening TFile \"" << filename << "\" stream: \"" << stream << "\" mode: \"" << typ << "\""
1739  << " comp level: " << cl << endmsg;
1740  }
1741 
1742  return StatusCode::SUCCESS;
1743 }
Parse attribute strings allowing iteration over the various attributes.
This class is the FileIncident.
Definition: FileIncident.h:27
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
T to_string(T... args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T end(T... args)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
static Mode charToMode(const char typ)
Convert a char to a Mode enum.
Definition: THistSvc.h:224
T make_pair(T... args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T move(T... args)
T insert(T... args)
T find(T... args)
STL class.
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1783
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
constexpr static const auto FAILURE
Definition: StatusCode.h:97
IFileMgr * p_fileMgr
Definition: THistSvc.h:397
T substr(T... args)
std::map< std::string, std::string > m_sharedFiles
Definition: THistSvc.h:310
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:93
T stoi(T... args)
T equal_range(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
constexpr double pi
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:33
streamMap m_fileStreams
Definition: THistSvc.h:307
T emplace_back(T... args)

◆ copyFileLayout()

void THistSvc::copyFileLayout ( TDirectory *  destination,
TDirectory *  source 
)
private

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

Definition at line 1928 of file THistSvc.cpp.

1928  {
1929  if ( msgLevel( MSG::DEBUG ) ) {
1930  debug() << "copyFileLayout() to destination path: " << destination->GetPath() << endmsg;
1931  }
1932 
1933  // strip out URLs
1934  TString path( (char*)strstr( destination->GetPath(), ":" ) );
1935  path.Remove( 0, 2 );
1936 
1937  source->cd( path );
1938  TDirectory* current_source_dir = gDirectory;
1939 
1940  // loop over all keys in this directory
1941  TList* key_list = current_source_dir->GetListOfKeys();
1942  int n = key_list->GetEntries();
1943  for ( int j = 0; j < n; ++j ) {
1944  TKey* k = (TKey*)key_list->At( j );
1945  const std::string source_pathname = current_source_dir->GetPath() + std::string( "/" ) + k->GetName();
1946  TObject* o = source->Get( source_pathname.c_str() );
1947 
1948  if ( o && o->IsA()->InheritsFrom( "TDirectory" ) ) {
1949  if ( msgLevel( MSG::VERBOSE ) ) { verbose() << " subdir [" << o->GetName() << "]..." << endmsg; }
1950  destination->cd();
1951  // Create directory if it does not exist yet
1952  TDirectory* destination_dir = destination->mkdir( o->GetName(), o->GetTitle() );
1953  if ( destination_dir == nullptr ) destination_dir = destination->GetDirectory( o->GetName() );
1954  copyFileLayout( destination_dir, source );
1955  }
1956  } // loop over keys
1957  return;
1958 }
void copyFileLayout(TDirectory *, TDirectory *)
helper function to recursively copy the layout of a TFile into a new TFile
Definition: THistSvc.cpp:1928
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T c_str(T... args)
T strstr(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ deReg() [1/2]

StatusCode THistSvc::deReg ( const std::string name)
override

Deregister object with given name and give up ownership (without deletion!)

Definition at line 566 of file THistSvc.cpp.

566  {
567  auto itr = m_uids.find( id );
568  if ( itr == m_uids.end() ) {
569  error() << "Problem deregistering id \"" << id << "\": not found in registry" << endmsg;
570  return StatusCode::FAILURE;
571  }
572 
573  vhid_t* vh = itr->second;
574  debug() << "will deregister " << vh->size() << " elements of id \"" << id << "\"" << endmsg;
576  // vh will get deleted in deReg once empty, so we cannot query the list size in the loop
577  size_t vh_size = vh->size();
578  while ( vh_size-- ) {
579  if ( deReg( vh->back().obj ).isFailure() ) {
580  sc = StatusCode::FAILURE;
581  error() << "Problems deRegistering " << vh->size() << " element of id \"" << id << "\"" << endmsg;
582  break;
583  }
584  }
585 
586  return sc;
587 }
StatusCode deReg(const std::string &name) override
Deregister object with given name and give up ownership (without deletion!)
Definition: THistSvc.cpp:566
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T end(T... args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
std::vector< THistID > vhid_t
Definition: THistSvc.h:289
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T find(T... args)
uidMap_t m_uids
Definition: THistSvc.h:299
constexpr static const auto FAILURE
Definition: StatusCode.h:97
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ deReg() [2/2]

StatusCode THistSvc::deReg ( TObject *  obj)
override

Deregister obejct identified by TObject* and give up ownership (without deletion!)

Definition at line 589 of file THistSvc.cpp.

589  {
590  objMap_t::iterator obj_itr = m_tobjs.find( obj );
591  if ( obj_itr != m_tobjs.end() ) {
592  vhid_t* vhid = obj_itr->second.first;
593  THistID hid = obj_itr->second.first->at( obj_itr->second.second );
594 
595  auto uid_itr = m_uids.find( hid.id );
596  if ( uid_itr == m_uids.end() ) {
597  error() << "Problems deregistering TObject \"" << obj->GetName() << "\" with id \"" << hid.id
598  << "\": not in uidMap" << endmsg;
599  return StatusCode::FAILURE;
600  }
601 
602  if ( vhid->size() == 1 ) {
603  // We are the last object, so we have to delete vhid properly
604  debug() << "vhid for " << hid.id << " is empty. deleting" << endmsg;
605 
606  std::string root, rem;
607  parseString( hid.id, root, rem );
608 
609  auto mitr = m_ids.equal_range( rem );
610  auto id_itr = std::find_if( mitr.first, mitr.second,
611  [&]( idMap_t::const_reference i ) { return i.second->at( 0 ).obj == obj; } );
612  if ( id_itr == mitr.second ) {
613  error() << "Problems deregistering TObject \"" << obj->GetName() << "\" with id \"" << hid.id
614  << "\": not in idMap" << endmsg;
615  return StatusCode::FAILURE;
616  }
617 
618  auto hlist_itr = std::find( m_hlist.begin(), m_hlist.end(), vhid );
619  if ( hlist_itr == m_hlist.end() ) {
620  error() << "Problems deregistering TObject \"" << obj->GetName() << "\" with id \"" << hid.id
621  << "\": not in hlist" << endmsg;
622  return StatusCode::FAILURE;
623  }
624 
625  vhid->erase( vhid->begin() + obj_itr->second.second );
626  m_tobjs.erase( obj_itr );
627 
628  m_uids.erase( uid_itr );
629  m_ids.erase( id_itr );
630  m_hlist.erase( hlist_itr );
631 
632  delete vhid;
633 
634  } else if ( vhid->size() > 1 ) {
635  m_tobjs.erase( obj_itr );
636  vhid->erase( vhid->begin() + obj_itr->second.second );
637 
638  // vector of THistID is still not empty (i.e. other instances with same name registered)
639  } else {
640  error() << "Deregistration failed unexpectedly. (bug in THistSvc?)" << endmsg;
641  }
642  return StatusCode::SUCCESS;
643  } else {
644  error() << "Cannot unregister TObject \"" << obj->GetName() << "\": not known to THistSvc" << endmsg;
645  return StatusCode::FAILURE;
646  }
647 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T end(T... args)
objMap_t m_tobjs
Definition: THistSvc.h:303
STL class.
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1870
hlist_t m_hlist
Definition: THistSvc.h:298
idMap_t m_ids
Definition: THistSvc.h:300
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T erase(T... args)
std::vector< THistID > vhid_t
Definition: THistSvc.h:289
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T find(T... args)
T begin(T... args)
uidMap_t m_uids
Definition: THistSvc.h:299
constexpr static const auto FAILURE
Definition: StatusCode.h:97
T equal_range(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ dump()

void THistSvc::dump ( ) const
private

Definition at line 2005 of file THistSvc.cpp.

2005  {
2006  std::ostringstream ost;
2007 
2008  // list< vector<THistID> >
2009  ost << "m_hlist: size: " << m_hlist.size() << "\n";
2010  for ( auto& vh : m_hlist ) {
2011  ost << " - " << vh->at( 0 ) << " :: [" << vh << "] " << vh->size() << " {";
2012  for ( auto& e : *vh ) {
2013  TObject* o = e.obj;
2014  ost << "[" << o << "]";
2015  }
2016  ost << "}\n";
2017  }
2018 
2019  // map uid -> vector<THistID>*
2020  ost << "\n"
2021  << "m_uids: " << m_uids.size() << "\n";
2022  for ( auto& e : m_uids ) { ost << " - " << e.first << " [" << e.second << "]" << std::endl; }
2023 
2024  // multimap id -> vector<THistID>*
2025  ost << "\n"
2026  << "m_ids: " << m_ids.size() << "\n";
2027  for ( auto& e : m_ids ) { ost << " - " << e.first << " [" << e.second << "]" << std::endl; }
2028 
2029  // map TObject* -> THistID*
2030  ost << "\n"
2031  << "m_tobjs: " << m_tobjs.size() << "\n";
2032  for ( auto& e : m_tobjs ) {
2033  TObject* o = e.first;
2034  THistID& i = e.second.first->at( e.second.second );
2035  ost << " - " << o << " -> " << i << std::endl;
2036  }
2037 
2038  debug() << "dumping THistSvc contents\n" << ost.str() << endmsg;
2039 }
T endl(T... args)
objMap_t m_tobjs
Definition: THistSvc.h:303
hlist_t m_hlist
Definition: THistSvc.h:298
idMap_t m_ids
Definition: THistSvc.h:300
T str(T... args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T size(T... args)
uidMap_t m_uids
Definition: THistSvc.h:299
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ exists()

bool THistSvc::exists ( const std::string name) const
override

Check if object with given name is managed by THistSvcMT exists calls existsHist and only works for TH1-descendants.

Definition at line 669 of file THistSvc.cpp.

669 { return existsHist( name ); }
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
bool existsHist(const std::string &name) const override
Check if histogram with given name is managed by THistSvcMT.
Definition: THistSvc.cpp:671

◆ existsEfficiency()

bool THistSvc::existsEfficiency ( const std::string name) const
override

Check if TEfficiency with given name is managed by THistSvcMT.

Definition at line 673 of file THistSvc.cpp.

673  {
674  return ( getHist_i<TEfficiency>( name, 0, true ) != nullptr );
675 }
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284

◆ existsGraph()

bool THistSvc::existsGraph ( const std::string name) const
override

Check if graph with given name is managed by THistSvcMT.

Definition at line 677 of file THistSvc.cpp.

677  {
678  return ( getHist_i<TGraph>( name, 0, true ) != nullptr );
679 }
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284

◆ existsHist()

bool THistSvc::existsHist ( const std::string name) const
override

Check if histogram with given name is managed by THistSvcMT.

Definition at line 671 of file THistSvc.cpp.

671 { return ( getHist_i<TH1>( name, 0, true ) != nullptr ); }
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284

◆ existsTree()

bool THistSvc::existsTree ( const std::string name) const
override

Check if tree with given name is managed by THistSvcMT.

Definition at line 681 of file THistSvc.cpp.

681 { return ( getHist_i<TTree>( name, 0, true ) != nullptr ); }
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284

◆ finalize()

StatusCode THistSvc::finalize ( )
override

Definition at line 189 of file THistSvc.cpp.

189  {
190  GlobalDirectoryRestore restore( m_svcMut );
191 
192  if ( msgLevel( MSG::DEBUG ) ) {
193  dump();
194  debug() << "THistSvc::finalize" << endmsg;
195  }
196 
197 #ifndef NDEBUG
198  if ( msgLevel( MSG::DEBUG ) ) {
200  for ( const auto& itr : sorted_uids ) {
201  THistID& thid = itr.second->at( 0 );
202  TObject* tobj = thid.obj;
203 
204  std::string dirname( "none" );
205  if ( tobj && tobj->IsA()->InheritsFrom( "TTree" ) ) {
206  TTree* tree = dynamic_cast<TTree*>( tobj );
207  if ( tree->GetDirectory() != 0 ) { dirname = tree->GetDirectory()->GetPath(); }
208  } else if ( tobj && tobj->IsA()->InheritsFrom( "TGraph" ) ) {
209  if ( !thid.temp ) {
210  dirname = thid.file->GetPath();
211  std::string id2( thid.id );
212  id2.erase( 0, id2.find( "/", 1 ) );
213  id2.erase( id2.rfind( "/" ), id2.length() );
214  if ( id2.find( "/" ) == 0 ) { id2.erase( 0, 1 ); }
215  dirname += id2;
216  } else {
217  dirname = "/tmp";
218  }
219  } else if ( tobj && tobj->IsA()->InheritsFrom( "TH1" ) ) {
220  TH1* th = dynamic_cast<TH1*>( tobj );
221  if ( th == nullptr ) {
222  error() << "Couldn't dcast: " << itr.first << endmsg;
223  } else {
224  if ( th->GetDirectory() != 0 ) { dirname = th->GetDirectory()->GetPath(); }
225  }
226  } else if ( !tobj ) {
227  warning() << itr.first << " has NULL TObject ptr" << endmsg;
228  }
229  debug() << "finalize: " << thid << endmsg;
230  }
231  }
232 #endif
233 
234  if ( writeObjectsToFile().isFailure() ) { error() << "problems writing histograms" << endmsg; }
235 
236  if ( m_print ) { info() << "Listing contents of ROOT files: " << endmsg; }
237  std::vector<TFile*> deleted_files;
238  for ( auto& itr : m_files ) {
239  if ( std::find( deleted_files.begin(), deleted_files.end(), itr.second.first ) == deleted_files.end() ) {
240  deleted_files.push_back( itr.second.first );
241 
242 #ifndef NDEBUG
243  if ( msgLevel( MSG::DEBUG ) ) {
244  debug() << "finalizing stream/file " << itr.first << ":" << itr.second.first->GetName() << endmsg;
245  }
246 #endif
247  } else {
248 #ifndef NDEBUG
249  if ( msgLevel( MSG::DEBUG ) ) { debug() << "already finalized stream " << itr.first << endmsg; }
250 #endif
251  continue;
252  }
253 
254  if ( m_print && msgLevel( MSG::INFO ) ) {
255  info() << "==> File: " << itr.second.first->GetName() << " stream: " << itr.first << endmsg;
256 
257  itr.second.first->Print( "base" );
258  }
259 
260  std::string tmpfn = itr.second.first->GetName();
261 
262  p_fileMgr->close( itr.second.first, name() );
263 
264  IIncidentSvc* pIncidentSvc = nullptr;
265  if ( service( "IncidentSvc", pIncidentSvc ).isFailure() ) {
266  error() << "Unable to get the IncidentSvc" << endmsg;
267  return StatusCode::FAILURE;
268  }
269 
270  if ( itr.second.second == SHARE ) {
271  // Merge File
272  void* vfile = nullptr;
273  int returncode =
274  p_fileMgr->open( Io::ROOT, name(), m_sharedFiles[itr.first], Io::WRITE | Io::APPEND, vfile, "HIST" );
275 
276  if ( returncode ) {
277  error() << "unable to open Final Output File: \"" << m_sharedFiles[itr.first] << "\" for merging" << endmsg;
278  return StatusCode::FAILURE;
279  }
280 
281  TFile* outputfile = (TFile*)vfile;
282  pIncidentSvc->fireIncident( FileIncident( name(), IncidentType::WroteToOutputFile, m_sharedFiles[itr.first] ) );
283 
284  if ( msgLevel( MSG::DEBUG ) ) { debug() << "THistSvc::writeObjectsToFile()::Merging Rootfile " << endmsg; }
285 
286  vfile = nullptr;
287  returncode = p_fileMgr->open( Io::ROOT, name(), tmpfn, Io::READ, vfile, "HIST" );
288 
289  if ( returncode ) {
290  error() << "unable to open temporary file: \"" << tmpfn << endmsg;
291  return StatusCode::FAILURE;
292  }
293 
294  TFile* inputfile = (TFile*)vfile;
295 
296  outputfile->SetCompressionLevel( inputfile->GetCompressionLevel() );
297 
298  MergeRootFile( outputfile, inputfile );
299 
300  outputfile->Write();
301  p_fileMgr->close( outputfile, name() );
302  p_fileMgr->close( inputfile, name() );
303 
304  if ( msgLevel( MSG::DEBUG ) ) { debug() << "Trying to remove temporary file \"" << tmpfn << "\"" << endmsg; }
305 
306  std::remove( tmpfn.c_str() );
307  }
308  delete itr.second.first;
309  }
310 
311  m_files.clear();
314  m_hlist.clear(); // vhid* is deleted in m_tobjs
315  m_uids.clear(); // vhid* is deleted in m_tobjs
316  m_ids.clear(); // vhid* is deleted in m_tobjs
317 
318  for ( auto& obj : m_tobjs ) {
319  // TObject*'s are already dealt with through root file i/o
320  delete obj.second.first; // delete vhid*
321  }
322  m_tobjs.clear();
323 
324  return Service::finalize();
325 }
void dump() const
Definition: THistSvc.cpp:2005
void MergeRootFile(TDirectory *, TDirectory *)
Definition: THistSvc.cpp:1787
This class is the FileIncident.
Definition: FileIncident.h:27
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
StatusCode finalize() override
Definition: Service.cpp:174
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
StatusCode writeObjectsToFile()
Definition: THistSvc.cpp:1543
T end(T... args)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
T remove(T... args)
STL class.
objMap_t m_tobjs
Definition: THistSvc.h:303
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
hlist_t m_hlist
Definition: THistSvc.h:298
idMap_t m_ids
Definition: THistSvc.h:300
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
T push_back(T... args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
Gaudi::Property< bool > m_print
Definition: THistSvc.h:381
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
def end
Definition: IOTest.py:123
T clear(T... args)
T find(T... args)
STL class.
T begin(T... args)
T c_str(T... args)
uidMap_t m_uids
Definition: THistSvc.h:299
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
constexpr static const auto FAILURE
Definition: StatusCode.h:97
IFileMgr * p_fileMgr
Definition: THistSvc.h:397
std::map< std::string, std::string > m_sharedFiles
Definition: THistSvc.h:310
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:93
AttribStringParser::Iterator begin(const AttribStringParser &parser)
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:33
streamMap m_fileStreams
Definition: THistSvc.h:307
virtual Io::close_t close(const Io::Fd, const std::string &caller)=0

◆ findHistID()

size_t THistSvc::findHistID ( const std::string id,
const THistID *&  hid,
const size_t &  index = 0 
) const
private

Definition at line 1960 of file THistSvc.cpp.

1960  {
1961  GlobalDirectoryRestore restore( m_svcMut );
1962 
1963  std::string idr( id );
1964  removeDoubleSlash( idr );
1965 
1966  hid = 0;
1967 
1968  if ( idr.find( "/" ) == 0 ) {
1969  // fully specified name, starts with "/"
1970  auto itr = m_uids.find( idr );
1971  if ( itr == m_uids.end() ) {
1972  // no matches found
1973  return 0;
1974  } else {
1975  // one or more matches found (clones).
1976  if ( index >= itr->second->size() ) {
1977  error() << "no index " << index << " found for Hist " << idr << endmsg;
1978  return 0;
1979  }
1980  hid = &( itr->second->at( index ) );
1981  return 1;
1982  }
1983  } else {
1984  // name not fully specified.
1985  auto mitr = m_ids.equal_range( idr );
1986  if ( mitr.first == mitr.second ) {
1987  // not found
1988  return 0;
1989  } else if ( distance( mitr.first, mitr.second ) == 1 ) {
1990  // one found
1991  if ( index >= mitr.first->second->size() ) {
1992  error() << "no index " << index << " found for Hist " << idr << endmsg;
1993  return 0;
1994  }
1995  hid = &( mitr.first->second->at( 0 ) );
1996  return 1;
1997  } else {
1998  // multiple matches
1999  hid = &( mitr.first->second->at( 0 ) );
2000  return distance( mitr.first, mitr.second );
2001  }
2002  }
2003 }
T distance(T... args)
T end(T... args)
STL class.
idMap_t m_ids
Definition: THistSvc.h:300
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T find(T... args)
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1783
uidMap_t m_uids
Definition: THistSvc.h:299
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
T equal_range(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ findStream()

bool THistSvc::findStream ( const std::string name,
std::string root,
std::string rem,
TFile *&  file 
) const
private

Definition at line 1834 of file THistSvc.cpp.

1834  {
1835  auto pos = id.find( "/" );
1836 
1837  if ( pos == std::string::npos ) {
1838  // no "/" in id
1839  stream = "temp";
1840  rem = id;
1841  } else if ( pos != 0 ) {
1842  // id does not start with "/"
1843  stream = "temp";
1844  rem = id;
1845  } else {
1846  // id starts with "/"
1847 
1848  auto pos2 = id.find( "/", pos + 1 );
1849 
1850  if ( pos2 == std::string::npos ) {
1851  // need at least 2 "/" in format "/STREAM/name" or "/STREAM/dir/name"
1852  error() << "badly formed Hist/Tree id: \"" << id << "\"" << endmsg;
1853  return false;
1854  }
1855  parseString( id, stream, rem );
1856  }
1857 
1858  if ( stream == "temp" ) {
1859  file = nullptr;
1860  return true;
1861  }
1862 
1863  auto itr = m_files.find( stream );
1864  file = ( itr != m_files.end() ? itr->second.first : nullptr );
1865  if ( !file ) { warning() << "no stream \"" << stream << "\" associated with id: \"" << id << "\"" << endmsg; }
1866 
1867  return true;
1868 }
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
T end(T... args)
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1870
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T find(T... args)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getEfficiencies()

std::vector< std::string > THistSvc::getEfficiencies ( ) const
override

Definition at line 707 of file THistSvc.cpp.

707  {
709  names.reserve( m_uids.size() );
710  transform_if(
711  std::begin( m_uids ), std::end( m_uids ), std::back_inserter( names ), select1st,
712  []( uidMap_t::const_reference i ) { return i.second->at( 0 ).obj->IsA()->InheritsFrom( "TEfficiency" ); } );
713  return names;
714 }
T end(T... args)
T size(T... args)
T begin(T... args)
T back_inserter(T... args)
uidMap_t m_uids
Definition: THistSvc.h:299
T reserve(T... args)

◆ getEfficiency()

StatusCode THistSvc::getEfficiency ( const std::string name,
TEfficiency *&  eff 
) const
override

Return TEfficiency with given name.

Definition at line 466 of file THistSvc.cpp.

466  {
467  eff = getHist_i<TEfficiency>( id );
468  if ( eff != nullptr ) {
469  return StatusCode::SUCCESS;
470  } else {
471  return StatusCode::FAILURE;
472  }
473 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getGraph()

StatusCode THistSvc::getGraph ( const std::string name,
TGraph *&  graph 
) const
override

Return TGraph with given name.

Definition at line 443 of file THistSvc.cpp.

443  {
444  graph = getHist_i<TGraph>( id );
445  if ( graph != nullptr ) {
446  return StatusCode::SUCCESS;
447  } else {
448  return StatusCode::FAILURE;
449  }
450 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getGraphs()

std::vector< std::string > THistSvc::getGraphs ( ) const
override

Definition at line 699 of file THistSvc.cpp.

699  {
701  names.reserve( m_uids.size() );
702  transform_if( std::begin( m_uids ), std::end( m_uids ), std::back_inserter( names ), select1st,
703  []( uidMap_t::const_reference i ) { return i.second->at( 0 ).obj->IsA()->InheritsFrom( "TGraph" ); } );
704  return names;
705 }
T end(T... args)
T size(T... args)
T begin(T... args)
T back_inserter(T... args)
uidMap_t m_uids
Definition: THistSvc.h:299
T reserve(T... args)

◆ getHist() [1/3]

StatusCode THistSvc::getHist ( const std::string name,
TH1 *&  hist,
size_t  index = 0 
) const
override

Return histogram with given name as TH1*, THistSvcMT still owns object.

Definition at line 349 of file THistSvc.cpp.

349  {
350  hist = getHist_i<TH1>( id, ind );
351  if ( hist != nullptr ) {
352  return StatusCode::SUCCESS;
353  } else {
354  return StatusCode::FAILURE;
355  }
356 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getHist() [2/3]

StatusCode THistSvc::getHist ( const std::string name,
TH2 *&  hist,
size_t  index = 0 
) const
override

Return histogram with given name as TH2*, THistSvcMT still owns object.

Definition at line 358 of file THistSvc.cpp.

358  {
359  hist = getHist_i<TH2>( id, ind );
360  if ( hist != nullptr ) {
361  return StatusCode::SUCCESS;
362  } else {
363  return StatusCode::FAILURE;
364  }
365 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getHist() [3/3]

StatusCode THistSvc::getHist ( const std::string name,
TH3 *&  hist,
size_t  index = 0 
) const
override

Return histogram with given name as TH3*, THistSvcMT still owns object.

Definition at line 367 of file THistSvc.cpp.

367  {
368  hist = getHist_i<TH3>( id, ind );
369  if ( hist != nullptr ) {
370  return StatusCode::SUCCESS;
371  } else {
372  return StatusCode::FAILURE;
373  }
374 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getHist_i()

template<typename T >
T * THistSvc::getHist_i ( const std::string name,
const size_t &  ind = 0,
bool  quiet = false 
) const
private

Definition at line 177 of file THistSvc.icc.

177  {
178  // id starts with "/": unique
179 
180  GlobalDirectoryRestore restore( m_svcMut );
181 
182  T* hist = nullptr;
183  const THistID* hid = nullptr;
184  size_t num = findHistID( id, hid, ind );
185  if ( num == 0 ) {
186  // no matches found
187  if ( !quiet ) { error() << "could not locate Hist with id \"" << id << "\"" << endmsg; }
188  return nullptr;
189  } else if ( num > 1 ) {
190  if ( !quiet ) {
191  // return failure if trying to GET a single hist
192  error() << "Multiple matches with id \"" << id << "\"."
193  << " Further specifications required." << endmsg;
194  return nullptr;
195  } else {
196  info() << "Found multiple matches with id \"" << id << "\"" << endmsg;
197  // return first match if just INQUIRING (i.e. != nullptr)
198  hist = dynamic_cast<T*>( hid->obj );
199  if ( hist == nullptr ) {
200  error() << "dcast failed, Hist id: \"" << id << "\"" << endmsg;
201  return nullptr;
202  }
203  }
204  } else {
205  hist = dynamic_cast<T*>( hid->obj );
206  if ( hist == nullptr ) {
207  error() << "dcast failed, Hist id: \"" << id << "\"" << endmsg;
208  return nullptr;
209  }
210  verbose() << "found unique Hist title: \"" << hist->GetTitle() << "\" id: \"" << id << "\"" << endmsg;
211  }
212 
213  return hist;
214 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
size_t findHistID(const std::string &id, const THistID *&hid, const size_t &index=0) const
Definition: THistSvc.cpp:1960
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getHists()

std::vector< std::string > THistSvc::getHists ( ) const
override

Definition at line 683 of file THistSvc.cpp.

683  {
685  names.reserve( m_uids.size() );
686  transform_if( std::begin( m_uids ), std::end( m_uids ), std::back_inserter( names ), select1st,
687  []( uidMap_t::const_reference i ) { return i.second->at( 0 ).obj->IsA()->InheritsFrom( "TH1" ); } );
688  return names;
689 }
T end(T... args)
T size(T... args)
T begin(T... args)
T back_inserter(T... args)
uidMap_t m_uids
Definition: THistSvc.h:299
T reserve(T... args)

◆ getShared() [1/5]

StatusCode THistSvc::getShared ( const std::string name,
LockedHandle< TH1 > &  lh 
) const
override

Retrieve shared object with given name as TH1 through LockedHandle.

Definition at line 521 of file THistSvc.cpp.

521  {
522  lh = getShared_i<TH1>( name );
523  if ( lh ) {
524  return StatusCode::SUCCESS;
525  } else {
526  return StatusCode::FAILURE;
527  }
528 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getShared() [2/5]

StatusCode THistSvc::getShared ( const std::string name,
LockedHandle< TH2 > &  lh 
) const
override

Retrieve shared object with given name as TH2 through LockedHandle.

Definition at line 530 of file THistSvc.cpp.

530  {
531  lh = getShared_i<TH2>( name );
532  if ( lh ) {
533  return StatusCode::SUCCESS;
534  } else {
535  return StatusCode::FAILURE;
536  }
537 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getShared() [3/5]

StatusCode THistSvc::getShared ( const std::string name,
LockedHandle< TH3 > &  lh 
) const
override

Retrieve shared object with given name as TH3 through LockedHandle.

Definition at line 539 of file THistSvc.cpp.

539  {
540  lh = getShared_i<TH3>( name );
541  if ( lh ) {
542  return StatusCode::SUCCESS;
543  } else {
544  return StatusCode::FAILURE;
545  }
546 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getShared() [4/5]

StatusCode THistSvc::getShared ( const std::string name,
LockedHandle< TGraph > &  lh 
) const
override

Retrieve shared object with given name as TGraph through LockedHandle.

Definition at line 548 of file THistSvc.cpp.

548  {
549  lh = getShared_i<TGraph>( name );
550  if ( lh ) {
551  return StatusCode::SUCCESS;
552  } else {
553  return StatusCode::FAILURE;
554  }
555 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getShared() [5/5]

StatusCode THistSvc::getShared ( const std::string name,
LockedHandle< TEfficiency > &  lh 
) const
override

Retrieve shared object with given name as TEfficiency through LockedHandle.

Definition at line 557 of file THistSvc.cpp.

557  {
558  lh = getShared_i<TEfficiency>( name );
559  if ( lh ) {
560  return StatusCode::SUCCESS;
561  } else {
562  return StatusCode::FAILURE;
563  }
564 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getShared_i()

template<typename T >
LockedHandle< T > THistSvc::getShared_i ( const std::string name) const
private

Definition at line 305 of file THistSvc.icc.

305  {
306  GlobalDirectoryRestore restore( m_svcMut );
307 
308  const THistID* hid = nullptr;
309  size_t i = findHistID( name, hid );
310 
311  LockedHandle<T> hist( nullptr, nullptr );
312 
313  if ( i == 1 ) {
314  if ( !hid->shared ) {
315  error() << "getSharedHist: found Hist with id \"" << name << "\", but it's not marked as shared" << endmsg;
316  return hist;
317  }
318  T* h1 = dynamic_cast<T*>( hid->obj );
319  hist = LockedHandle<T>( h1, hid->mutex );
320 
321  debug() << "getSharedHist: found THistID: " << *hid << endmsg;
322  } else if ( i == 0 ) {
323  error() << "no histograms matching id \"" << name << "\" found" << endmsg;
324  } else {
325  info() << "multiple matches for id \"" << name << "\" found [" << i << "], probably from different streams"
326  << endmsg;
327  }
328  return hist;
329 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Provides automatic lock/unlock access to a class upon deref of ptr.
Definition: LockedHandle.h:38
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
size_t findHistID(const std::string &id, const THistID *&hid, const size_t &index=0) const
Definition: THistSvc.cpp:1960
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getTEfficiencies() [1/4]

StatusCode THistSvc::getTEfficiencies ( TDirectory *  td,
TList &  tl,
bool  recurse = false 
) const
override

Definition at line 1096 of file THistSvc.cpp.

1096  {
1097  GlobalDirectoryRestore restore( m_svcMut );
1098 
1099  gErrorIgnoreLevel = kBreak;
1100 
1101  if ( !td->cd() ) {
1102  error() << "getTEfficiencies: No such TDirectory \"" << td->GetPath() << "\"" << endmsg;
1103  return StatusCode::FAILURE;
1104  }
1105 
1106  if ( msgLevel( MSG::DEBUG ) ) {
1107  debug() << "getTEfficiencies: \"" << td->GetPath() << "\": found " << td->GetListOfKeys()->GetSize() << " keys"
1108  << endmsg;
1109  }
1110 
1111  TIter nextkey( td->GetListOfKeys() );
1112  while ( TKey* key = (TKey*)nextkey() ) {
1113  auto& log = debug();
1114  if ( msgLevel( MSG::DEBUG ) ) log << " key: " << key->GetName();
1115  TObject* obj = key->ReadObj();
1116  if ( obj != 0 && obj->IsA()->InheritsFrom( "TDirectory" ) ) {
1117  if ( msgLevel( MSG::DEBUG ) ) log << " (" << obj->IsA()->GetName() << ")";
1118  } else if ( obj != 0 && obj->IsA()->InheritsFrom( "TEfficiency" ) ) {
1119  if ( msgLevel( MSG::DEBUG ) ) log << " (" << obj->IsA()->GetName() << ")";
1120  tl.Add( obj );
1121  } else if ( obj != 0 ) {
1122  if ( msgLevel( MSG::DEBUG ) ) log << " [" << obj->IsA()->GetName() << "]";
1123  }
1124  if ( msgLevel( MSG::DEBUG ) ) log << endmsg;
1125  }
1126 
1127  // operate recursively
1128  if ( rcs ) {
1129  nextkey = td->GetListOfKeys();
1130  while ( TKey* key = (TKey*)nextkey() ) {
1131  TObject* obj = key->ReadObj();
1132  if ( obj && obj->IsA()->InheritsFrom( "TDirectory" ) ) {
1133  TDirectory* tt = dynamic_cast<TDirectory*>( obj );
1134  getTHists( tt, tl, rcs );
1135  }
1136  }
1137  }
1138 
1139  return StatusCode::SUCCESS;
1140 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:716
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
constexpr static const auto FAILURE
Definition: StatusCode.h:97
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getTEfficiencies() [2/4]

StatusCode THistSvc::getTEfficiencies ( const std::string name,
TList &  tl,
bool  recurse = false 
) const
override

Definition at line 1142 of file THistSvc.cpp.

1142  {
1143 
1144  GlobalDirectoryRestore restore( m_svcMut );
1145 
1146  gErrorIgnoreLevel = kBreak;
1147 
1148  StatusCode sc;
1149 
1150  std::string stream, rem, r2;
1151  parseString( dir, stream, rem );
1152 
1153  auto itr = m_files.find( stream );
1154  if ( itr != m_files.end() ) {
1155  r2 = itr->second.first->GetName();
1156  r2 += ":/";
1157  r2 += rem;
1158 
1159  if ( msgLevel( MSG::DEBUG ) ) {
1160  debug() << "getTEfficiencies: \"" << dir << "\" looks like a stream name."
1161  << " associated TFile: \"" << itr->second.first->GetName() << "\"" << endmsg;
1162  }
1163 
1164  if ( gDirectory->cd( r2.c_str() ) ) {
1165  m_curstream = stream;
1166  sc = getTEfficiencies( gDirectory, tl, rcs );
1167  m_curstream = "";
1168  return sc;
1169  } else {
1170  if ( msgLevel( MSG::DEBUG ) ) { debug() << "getTEfficiencies: no such TDirectory \"" << r2 << "\"" << endmsg; }
1171  }
1172 
1173  } else {
1174  if ( msgLevel( MSG::DEBUG ) ) { debug() << "getTEfficiencies: stream \"" << stream << "\" not found" << endmsg; }
1175  }
1176 
1177  if ( !gDirectory->cd( dir.c_str() ) ) {
1178  error() << "getTEfficiencies: No such TDirectory/stream \"" << dir << "\"" << endmsg;
1179  sc = StatusCode::FAILURE;
1180  } else {
1181  sc = getTHists( gDirectory, tl, rcs );
1182  }
1183 
1184  return sc;
1185 }
std::string m_curstream
Definition: THistSvc.h:403
StatusCode getTEfficiencies(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:1096
T end(T... args)
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:716
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1870
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T find(T... args)
T c_str(T... args)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
constexpr static const auto FAILURE
Definition: StatusCode.h:97
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getTEfficiencies() [3/4]

StatusCode THistSvc::getTEfficiencies ( TDirectory *  td,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
override

Definition at line 1187 of file THistSvc.cpp.

1187  {
1188  GlobalDirectoryRestore restore( m_svcMut );
1189 
1190  gErrorIgnoreLevel = kBreak;
1191 
1192  if ( !td->cd() ) {
1193  error() << "getTEfficiencies: No such TDirectory \"" << td->GetPath() << "\"" << endmsg;
1194  return StatusCode::FAILURE;
1195  }
1196 
1197  if ( msgLevel( MSG::DEBUG ) ) {
1198  debug() << "getTEfficiencies: \"" << td->GetPath() << "\": found " << td->GetListOfKeys()->GetSize() << " keys"
1199  << endmsg;
1200  }
1201 
1202  TIter nextkey( td->GetListOfKeys() );
1203  while ( TKey* key = (TKey*)nextkey() ) {
1204  auto& log = debug();
1205  if ( msgLevel( MSG::DEBUG ) ) log << " key: " << key->GetName();
1206  TObject* obj = key->ReadObj();
1207  if ( obj && obj->IsA()->InheritsFrom( "TDirectory" ) ) {
1208  if ( msgLevel( MSG::DEBUG ) ) log << " (" << obj->IsA()->GetName() << ")";
1209  } else if ( obj && obj->IsA()->InheritsFrom( "TEfficiency" ) ) {
1210  if ( msgLevel( MSG::DEBUG ) ) log << " (" << obj->IsA()->GetName() << ")";
1211  tl.Add( obj );
1212  if ( reg && m_curstream != "" ) {
1213  std::string dir = td->GetPath();
1214  std::string fil = td->GetFile()->GetName();
1215  dir.erase( 0, fil.length() + 1 );
1216  std::string id = "/" + m_curstream;
1217  if ( dir == "/" ) {
1218  id = id + "/" + key->GetName();
1219  } else {
1220  id = id + dir + "/" + key->GetName();
1221  }
1222  if ( !exists( id ) ) {
1223  if ( msgLevel( MSG::DEBUG ) ) log << " reg as \"" << id << "\"";
1224  regHist( id ).ignore();
1225  } else {
1226  if ( msgLevel( MSG::DEBUG ) ) log << " already registered";
1227  }
1228  }
1229  } else if ( obj ) {
1230  if ( msgLevel( MSG::DEBUG ) ) log << " [" << obj->IsA()->GetName() << "]";
1231  }
1232  if ( msgLevel( MSG::DEBUG ) ) log << endmsg;
1233  }
1234 
1235  // operate recursively
1236  if ( rcs ) {
1237  nextkey = td->GetListOfKeys();
1238  while ( TKey* key = (TKey*)nextkey() ) {
1239  TObject* obj = key->ReadObj();
1240  if ( obj && obj->IsA()->InheritsFrom( "TDirectory" ) ) {
1241  TDirectory* tt = dynamic_cast<TDirectory*>( obj );
1242  getTEfficiencies( tt, tl, rcs, reg );
1243  }
1244  }
1245  }
1246 
1247  return StatusCode::SUCCESS;
1248 }
std::string m_curstream
Definition: THistSvc.h:403
StatusCode getTEfficiencies(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:1096
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T erase(T... args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode regHist(const std::string &name) override
Register a new ROOT histogram TH*X with a name.
Definition: THistSvc.cpp:329
T length(T... args)
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:164
constexpr static const auto FAILURE
Definition: StatusCode.h:97
bool exists(const std::string &name) const override
Check if object with given name is managed by THistSvcMT exists calls existsHist and only works for T...
Definition: THistSvc.cpp:669
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getTEfficiencies() [4/4]

StatusCode THistSvc::getTEfficiencies ( const std::string name,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
override

Definition at line 1250 of file THistSvc.cpp.

1250  {
1251  GlobalDirectoryRestore restore( m_svcMut );
1252 
1253  gErrorIgnoreLevel = kBreak;
1254 
1255  StatusCode sc;
1256 
1257  std::string stream, rem, r2;
1258  parseString( dir, stream, rem );
1259 
1260  auto itr = m_files.find( stream );
1261  if ( itr != m_files.end() ) {
1262  r2 = itr->second.first->GetName();
1263  r2 += ":/";
1264  r2 += rem;
1265 
1266  if ( msgLevel( MSG::DEBUG ) ) {
1267  debug() << "getTEfficiencies: \"" << dir << "\" looks like a stream name."
1268  << " associated TFile: \"" << itr->second.first->GetName() << "\"" << endmsg;
1269  }
1270 
1271  if ( gDirectory->cd( r2.c_str() ) ) {
1272  m_curstream = stream;
1273  sc = getTEfficiencies( gDirectory, tl, rcs, reg );
1274  m_curstream.clear();
1275  return sc;
1276  }
1277  if ( msgLevel( MSG::DEBUG ) ) { debug() << "getTEfficiencies: no such TDirectory \"" << r2 << "\"" << endmsg; }
1278  } else {
1279  if ( msgLevel( MSG::DEBUG ) ) { debug() << "getTEfficiencies: stream \"" << stream << "\" not found" << endmsg; }
1280  }
1281 
1282  if ( !gDirectory->cd( dir.c_str() ) ) {
1283  error() << "getTEfficiencies: No such TDirectory/stream \"" << dir << "\"" << endmsg;
1284  sc = StatusCode::FAILURE;
1285  } else {
1286  if ( reg ) {
1287  warning() << "Unable to register histograms automatically "
1288  << "without a valid stream name" << endmsg;
1289  reg = false;
1290  }
1291  sc = getTEfficiencies( gDirectory, tl, rcs, reg );
1292  }
1293 
1294  return sc;
1295 }
std::string m_curstream
Definition: THistSvc.h:403
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
StatusCode getTEfficiencies(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:1096
T end(T... args)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1870
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T clear(T... args)
T find(T... args)
T c_str(T... args)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
constexpr static const auto FAILURE
Definition: StatusCode.h:97
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getTHists() [1/4]

StatusCode THistSvc::getTHists ( TDirectory *  td,
TList &  tl,
bool  recurse = false 
) const
override

Definition at line 716 of file THistSvc.cpp.

716  {
717  GlobalDirectoryRestore restore( m_svcMut );
718 
719  gErrorIgnoreLevel = kBreak;
720 
721  if ( !td->cd() ) {
722  error() << "getTHists: No such TDirectory \"" << td->GetPath() << "\"" << endmsg;
723  return StatusCode::FAILURE;
724  }
725 
726  if ( msgLevel( MSG::DEBUG ) ) {
727  debug() << "getTHists: \"" << td->GetPath() << "\": found " << td->GetListOfKeys()->GetSize() << " keys" << endmsg;
728  }
729 
730  TIter nextkey( td->GetListOfKeys() );
731  while ( TKey* key = (TKey*)nextkey() ) {
732  auto& log = debug();
733  if ( msgLevel( MSG::DEBUG ) ) log << " key: " << key->GetName();
734  TObject* obj = key->ReadObj();
735  if ( obj != 0 && obj->IsA()->InheritsFrom( "TDirectory" ) ) {
736  if ( msgLevel( MSG::DEBUG ) ) log << " (" << obj->IsA()->GetName() << ")";
737  } else if ( obj != 0 && obj->IsA()->InheritsFrom( "TH1" ) ) {
738  if ( msgLevel( MSG::DEBUG ) ) log << " (" << obj->IsA()->GetName() << ")";
739  tl.Add( obj );
740  } else if ( obj != 0 ) {
741  if ( msgLevel( MSG::DEBUG ) ) log << " [" << obj->IsA()->GetName() << "]";
742  }
743  if ( msgLevel( MSG::DEBUG ) ) log << endmsg;
744  }
745 
746  // operate recursively
747  if ( rcs ) {
748  nextkey = td->GetListOfKeys();
749  while ( TKey* key = (TKey*)nextkey() ) {
750  TObject* obj = key->ReadObj();
751  if ( obj && obj->IsA()->InheritsFrom( "TDirectory" ) ) {
752  TDirectory* tt = dynamic_cast<TDirectory*>( obj );
753  getTHists( tt, tl, rcs );
754  }
755  }
756  }
757 
758  return StatusCode::SUCCESS;
759 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:716
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
constexpr static const auto FAILURE
Definition: StatusCode.h:97
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getTHists() [2/4]

StatusCode THistSvc::getTHists ( const std::string name,
TList &  tl,
bool  recurse = false 
) const
override

Definition at line 761 of file THistSvc.cpp.

761  {
762 
763  GlobalDirectoryRestore restore( m_svcMut );
764 
765  gErrorIgnoreLevel = kBreak;
766 
767  StatusCode sc;
768 
769  std::string stream, rem, r2;
770  parseString( dir, stream, rem );
771 
772  auto itr = m_files.find( stream );
773  if ( itr != m_files.end() ) {
774  r2 = itr->second.first->GetName();
775  r2 += ":/";
776  r2 += rem;
777 
778  if ( msgLevel( MSG::DEBUG ) ) {
779  debug() << "getTHists: \"" << dir << "\" looks like a stream name."
780  << " associated TFile: \"" << itr->second.first->GetName() << "\"" << endmsg;
781  }
782 
783  if ( gDirectory->cd( r2.c_str() ) ) {
784  m_curstream = stream;
785  sc = getTHists( gDirectory, tl, rcs );
786  m_curstream = "";
787  return sc;
788  } else {
789  if ( msgLevel( MSG::DEBUG ) ) { debug() << "getTHists: no such TDirectory \"" << r2 << "\"" << endmsg; }
790  }
791 
792  } else {
793  if ( msgLevel( MSG::DEBUG ) ) { debug() << "getTHists: stream \"" << stream << "\" not found" << endmsg; }
794  }
795 
796  if ( !gDirectory->cd( dir.c_str() ) ) {
797  error() << "getTHists: No such TDirectory/stream \"" << dir << "\"" << endmsg;
798  sc = StatusCode::FAILURE;
799  } else {
800  sc = getTHists( gDirectory, tl, rcs );
801  }
802 
803  return sc;
804 }
std::string m_curstream
Definition: THistSvc.h:403
T end(T... args)
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:716
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1870
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T find(T... args)
T c_str(T... args)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
constexpr static const auto FAILURE
Definition: StatusCode.h:97
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getTHists() [3/4]

StatusCode THistSvc::getTHists ( TDirectory *  td,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
override

Definition at line 806 of file THistSvc.cpp.

806  {
807  GlobalDirectoryRestore restore( m_svcMut );
808 
809  gErrorIgnoreLevel = kBreak;
810 
811  if ( !td->cd() ) {
812  error() << "getTHists: No such TDirectory \"" << td->GetPath() << "\"" << endmsg;
813  return StatusCode::FAILURE;
814  }
815 
816  if ( msgLevel( MSG::DEBUG ) ) {
817  debug() << "getTHists: \"" << td->GetPath() << "\": found " << td->GetListOfKeys()->GetSize() << " keys" << endmsg;
818  }
819 
820  TIter nextkey( td->GetListOfKeys() );
821  while ( TKey* key = (TKey*)nextkey() ) {
822  auto& log = debug();
823  if ( msgLevel( MSG::DEBUG ) ) log << " key: " << key->GetName();
824  TObject* obj = key->ReadObj();
825  if ( obj && obj->IsA()->InheritsFrom( "TDirectory" ) ) {
826  if ( msgLevel( MSG::DEBUG ) ) log << " (" << obj->IsA()->GetName() << ")";
827  } else if ( obj && obj->IsA()->InheritsFrom( "TH1" ) ) {
828  if ( msgLevel( MSG::DEBUG ) ) log << " (" << obj->IsA()->GetName() << ")";
829  tl.Add( obj );
830  if ( reg && m_curstream != "" ) {
831  std::string dir = td->GetPath();
832  std::string fil = td->GetFile()->GetName();
833  dir.erase( 0, fil.length() + 1 );
834  std::string id = "/" + m_curstream;
835  if ( dir == "/" ) {
836  id = id + "/" + key->GetName();
837  } else {
838  id = id + dir + "/" + key->GetName();
839  }
840  if ( !exists( id ) ) {
841  if ( msgLevel( MSG::DEBUG ) ) log << " reg as \"" << id << "\"";
842  regHist( id ).ignore();
843  } else {
844  if ( msgLevel( MSG::DEBUG ) ) log << " already registered";
845  }
846  }
847  } else if ( obj ) {
848  if ( msgLevel( MSG::DEBUG ) ) log << " [" << obj->IsA()->GetName() << "]";
849  }
850  if ( msgLevel( MSG::DEBUG ) ) log << endmsg;
851  }
852 
853  // operate recursively
854  if ( rcs ) {
855  nextkey = td->GetListOfKeys();
856  while ( TKey* key = (TKey*)nextkey() ) {
857  TObject* obj = key->ReadObj();
858  if ( obj && obj->IsA()->InheritsFrom( "TDirectory" ) ) {
859  TDirectory* tt = dynamic_cast<TDirectory*>( obj );
860  getTHists( tt, tl, rcs, reg );
861  }
862  }
863  }
864 
865  return StatusCode::SUCCESS;
866 }
std::string m_curstream
Definition: THistSvc.h:403
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:716
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T erase(T... args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode regHist(const std::string &name) override
Register a new ROOT histogram TH*X with a name.
Definition: THistSvc.cpp:329
T length(T... args)
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:164
constexpr static const auto FAILURE
Definition: StatusCode.h:97
bool exists(const std::string &name) const override
Check if object with given name is managed by THistSvcMT exists calls existsHist and only works for T...
Definition: THistSvc.cpp:669
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getTHists() [4/4]

StatusCode THistSvc::getTHists ( const std::string name,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
override

Definition at line 868 of file THistSvc.cpp.

868  {
869  GlobalDirectoryRestore restore( m_svcMut );
870 
871  gErrorIgnoreLevel = kBreak;
872 
873  StatusCode sc;
874 
875  std::string stream, rem, r2;
876  parseString( dir, stream, rem );
877 
878  auto itr = m_files.find( stream );
879  if ( itr != m_files.end() ) {
880  r2 = itr->second.first->GetName();
881  r2 += ":/";
882  r2 += rem;
883 
884  if ( msgLevel( MSG::DEBUG ) ) {
885  debug() << "getTHists: \"" << dir << "\" looks like a stream name."
886  << " associated TFile: \"" << itr->second.first->GetName() << "\"" << endmsg;
887  }
888 
889  if ( gDirectory->cd( r2.c_str() ) ) {
890  m_curstream = stream;
891  sc = getTHists( gDirectory, tl, rcs, reg );
892  m_curstream.clear();
893  return sc;
894  }
895  if ( msgLevel( MSG::DEBUG ) ) { debug() << "getTHists: no such TDirectory \"" << r2 << "\"" << endmsg; }
896  } else {
897  if ( msgLevel( MSG::DEBUG ) ) { debug() << "getTHists: stream \"" << stream << "\" not found" << endmsg; }
898  }
899 
900  if ( !gDirectory->cd( dir.c_str() ) ) {
901  error() << "getTHists: No such TDirectory/stream \"" << dir << "\"" << endmsg;
902  sc = StatusCode::FAILURE;
903  } else {
904  if ( reg ) {
905  warning() << "Unable to register histograms automatically "
906  << "without a valid stream name" << endmsg;
907  reg = false;
908  }
909  sc = getTHists( gDirectory, tl, rcs, reg );
910  }
911 
912  return sc;
913 }
std::string m_curstream
Definition: THistSvc.h:403
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
T end(T... args)
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:716
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1870
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T clear(T... args)
T find(T... args)
T c_str(T... args)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
constexpr static const auto FAILURE
Definition: StatusCode.h:97
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getTree()

StatusCode THistSvc::getTree ( const std::string name,
TTree *&  tree 
) const
override

Return TTree with given name.

Definition at line 402 of file THistSvc.cpp.

402  {
403  tree = getHist_i<TTree>( id );
404  if ( tree != nullptr ) {
405  return StatusCode::SUCCESS;
406  } else {
407  return StatusCode::FAILURE;
408  }
409 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getTrees()

std::vector< std::string > THistSvc::getTrees ( ) const
override

Definition at line 691 of file THistSvc.cpp.

691  {
693  names.reserve( m_uids.size() );
694  transform_if( std::begin( m_uids ), std::end( m_uids ), std::back_inserter( names ), select1st,
695  []( uidMap_t::const_reference i ) { return i.second->at( 0 ).obj->IsA()->InheritsFrom( "TTree" ); } );
696  return names;
697 }
T end(T... args)
T size(T... args)
T begin(T... args)
T back_inserter(T... args)
uidMap_t m_uids
Definition: THistSvc.h:299
T reserve(T... args)

◆ getTTrees() [1/4]

StatusCode THistSvc::getTTrees ( TDirectory *  td,
TList &  tl,
bool  recurse = false 
) const
override

Definition at line 915 of file THistSvc.cpp.

915  {
916  GlobalDirectoryRestore restore( m_svcMut );
917 
918  gErrorIgnoreLevel = kBreak;
919 
920  if ( !td->cd() ) {
921  error() << "getTTrees: No such TDirectory \"" << td->GetPath() << "\"" << endmsg;
922  return StatusCode::FAILURE;
923  }
924 
925  if ( msgLevel( MSG::DEBUG ) ) {
926  debug() << "getTHists: \"" << td->GetPath() << "\": found " << td->GetListOfKeys()->GetSize() << " keys" << endmsg;
927  }
928 
929  TIter nextkey( td->GetListOfKeys() );
930  while ( TKey* key = (TKey*)nextkey() ) {
931  auto& log = debug();
932  if ( msgLevel( MSG::DEBUG ) ) log << " key: " << key->GetName();
933  TObject* obj = key->ReadObj();
934  if ( obj != 0 && obj->IsA()->InheritsFrom( "TDirectory" ) ) {
935  if ( msgLevel( MSG::DEBUG ) ) log << " (" << obj->IsA()->GetName() << ")";
936  } else if ( obj != 0 && obj->IsA()->InheritsFrom( "TTree" ) ) {
937  if ( msgLevel( MSG::DEBUG ) ) log << " (" << obj->IsA()->GetName() << ")";
938  tl.Add( obj );
939  } else if ( obj != 0 ) {
940  if ( msgLevel( MSG::DEBUG ) ) log << " [" << obj->IsA()->GetName() << "]";
941  }
942  log << endmsg;
943  }
944 
945  // operate recursively
946  if ( rcs ) {
947  nextkey = td->GetListOfKeys();
948  while ( TKey* key = (TKey*)nextkey() ) {
949  TObject* obj = key->ReadObj();
950  if ( obj && obj->IsA()->InheritsFrom( "TDirectory" ) ) {
951  TDirectory* tt = dynamic_cast<TDirectory*>( obj );
952  getTTrees( tt, tl, rcs );
953  }
954  }
955  }
956 
957  return StatusCode::SUCCESS;
958 }
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:915
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
constexpr static const auto FAILURE
Definition: StatusCode.h:97
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getTTrees() [2/4]

StatusCode THistSvc::getTTrees ( const std::string name,
TList &  tl,
bool  recurse = false 
) const
override

Definition at line 960 of file THistSvc.cpp.

960  {
961  GlobalDirectoryRestore restore( m_svcMut );
962 
963  gErrorIgnoreLevel = kBreak;
964 
965  StatusCode sc;
966 
967  std::string stream, rem, r2;
968  parseString( dir, stream, rem );
969 
970  auto itr = m_files.find( stream );
971  if ( itr != m_files.end() ) {
972  r2 = itr->second.first->GetName();
973  r2 += ":/";
974  r2 += rem;
975 
976  if ( msgLevel( MSG::DEBUG ) ) {
977  debug() << "getTTrees: \"" << dir << "\" looks like a stream name."
978  << " associated TFile: \"" << itr->second.first->GetName() << "\"" << endmsg;
979  }
980 
981  if ( gDirectory->cd( r2.c_str() ) ) { return getTTrees( gDirectory, tl, rcs ); }
982  if ( msgLevel( MSG::DEBUG ) ) { debug() << "getTTrees: no such TDirectory \"" << r2 << "\"" << endmsg; }
983  } else {
984  if ( msgLevel( MSG::DEBUG ) ) { debug() << "getTTrees: stream \"" << stream << "\" not found" << endmsg; }
985  }
986 
987  if ( !gDirectory->cd( dir.c_str() ) ) {
988  error() << "getTTrees: No such TDirectory/stream \"" << dir << "\"" << endmsg;
989  sc = StatusCode::FAILURE;
990  } else {
991  sc = getTTrees( gDirectory, tl, rcs );
992  }
993  return sc;
994 }
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:915
T end(T... args)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1870
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T find(T... args)
T c_str(T... args)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
constexpr static const auto FAILURE
Definition: StatusCode.h:97
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getTTrees() [3/4]

StatusCode THistSvc::getTTrees ( TDirectory *  td,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
override

Definition at line 996 of file THistSvc.cpp.

996  {
997  GlobalDirectoryRestore restore( m_svcMut );
998 
999  gErrorIgnoreLevel = kBreak;
1000 
1001  if ( !td->cd() ) {
1002  error() << "getTTrees: No such TDirectory \"" << td->GetPath() << "\"" << endmsg;
1003  return StatusCode::FAILURE;
1004  }
1005 
1006  if ( msgLevel( MSG::DEBUG ) ) {
1007  debug() << "getTHists: \"" << td->GetPath() << "\": found " << td->GetListOfKeys()->GetSize() << " keys" << endmsg;
1008  }
1009 
1010  TIter nextkey( td->GetListOfKeys() );
1011  while ( TKey* key = (TKey*)nextkey() ) {
1012  auto& log = debug();
1013  if ( msgLevel( MSG::DEBUG ) ) log << " key: " << key->GetName();
1014  TObject* obj = key->ReadObj();
1015  if ( obj && obj->IsA()->InheritsFrom( "TDirectory" ) ) {
1016  if ( msgLevel( MSG::DEBUG ) ) log << " (" << obj->IsA()->GetName() << ")";
1017  } else if ( obj && obj->IsA()->InheritsFrom( "TTree" ) ) {
1018  if ( msgLevel( MSG::DEBUG ) ) log << " (" << obj->IsA()->GetName() << ")";
1019  tl.Add( obj );
1020  if ( reg && m_curstream != "" ) {
1021  std::string dir = td->GetPath();
1022  std::string fil = td->GetFile()->GetName();
1023  dir.erase( 0, fil.length() + 1 );
1024  std::string id = "/" + m_curstream;
1025  if ( dir == "/" ) {
1026  id = id + "/" + key->GetName();
1027  } else {
1028  id = id + dir + "/" + key->GetName();
1029  }
1030  if ( !exists( id ) ) {
1031  if ( msgLevel( MSG::DEBUG ) ) log << " reg as \"" << id << "\"";
1032  regHist( id ).ignore();
1033  } else {
1034  if ( msgLevel( MSG::DEBUG ) ) log << " already registered";
1035  }
1036  }
1037  } else if ( obj != 0 ) {
1038  if ( msgLevel( MSG::DEBUG ) ) log << " [" << obj->IsA()->GetName() << "]";
1039  }
1040  if ( msgLevel( MSG::DEBUG ) ) log << endmsg;
1041  }
1042 
1043  // operate recursively
1044  if ( rcs ) {
1045  nextkey = td->GetListOfKeys();
1046  while ( TKey* key = (TKey*)nextkey() ) {
1047  TObject* obj = key->ReadObj();
1048  if ( obj && obj->IsA()->InheritsFrom( "TDirectory" ) ) {
1049  TDirectory* tt = dynamic_cast<TDirectory*>( obj );
1050  getTTrees( tt, tl, rcs, reg );
1051  }
1052  }
1053  }
1054 
1055  return StatusCode::SUCCESS;
1056 }
std::string m_curstream
Definition: THistSvc.h:403
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:915
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T erase(T... args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode regHist(const std::string &name) override
Register a new ROOT histogram TH*X with a name.
Definition: THistSvc.cpp:329
T length(T... args)
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:164
constexpr static const auto FAILURE
Definition: StatusCode.h:97
bool exists(const std::string &name) const override
Check if object with given name is managed by THistSvcMT exists calls existsHist and only works for T...
Definition: THistSvc.cpp:669
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getTTrees() [4/4]

StatusCode THistSvc::getTTrees ( const std::string name,
TList &  tl,
bool  recurse = false,
bool  reg = false 
)
override

Definition at line 1058 of file THistSvc.cpp.

1058  {
1059  GlobalDirectoryRestore restore( m_svcMut );
1060 
1061  gErrorIgnoreLevel = kBreak;
1062 
1063  StatusCode sc;
1064 
1065  std::string stream, rem, r2;
1066  parseString( dir, stream, rem );
1067 
1068  auto itr = m_files.find( stream );
1069  if ( itr != m_files.end() ) {
1070  r2 = itr->second.first->GetName();
1071  r2 += ":/";
1072  r2 += rem;
1073 
1074  if ( msgLevel( MSG::DEBUG ) ) {
1075  debug() << "getTTrees: \"" << dir << "\" looks like a stream name."
1076  << " associated TFile: \"" << itr->second.first->GetName() << "\"" << endmsg;
1077  }
1078 
1079  if ( gDirectory->cd( r2.c_str() ) ) {
1080  return getTTrees( gDirectory, tl, rcs, reg );
1081  } else {
1082  if ( msgLevel( MSG::DEBUG ) ) { debug() << "getTTrees: no such TDirectory \"" << r2 << "\"" << endmsg; }
1083  }
1084  } else {
1085  if ( msgLevel( MSG::DEBUG ) ) { debug() << "getTTrees: stream \"" << stream << "\" not found" << endmsg; }
1086  }
1087 
1088  if ( !gDirectory->cd( dir.c_str() ) ) {
1089  error() << "getTTrees: No such TDirectory/stream \"" << dir << "\"" << endmsg;
1090  return StatusCode::FAILURE;
1091  }
1092 
1093  return getTTrees( gDirectory, tl, rcs, reg );
1094 }
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:915
T end(T... args)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1870
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T find(T... args)
T c_str(T... args)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
constexpr static const auto FAILURE
Definition: StatusCode.h:97
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ handle()

void THistSvc::handle ( const Incident )
override

Definition at line 1299 of file THistSvc.cpp.

1299  {
1300  if ( m_signaledStop ) return;
1301 
1302  if ( m_maxFileSize.value() == -1 ) return;
1303 
1304  // convert to bytes.
1305  Long64_t mfs = (Long64_t)m_maxFileSize.value() * (Long64_t)1048576;
1306  Long64_t mfs_warn = mfs * 95 / 100;
1307 
1308  updateFiles();
1309 
1310  for ( const auto& f : m_files ) {
1311  TFile* tf = f.second.first;
1312 
1313 #ifndef NDEBUG
1314  if ( msgLevel( MSG::DEBUG ) ) {
1315  debug() << "stream: " << f.first << " name: " << tf->GetName() << " size: " << tf->GetSize() << endmsg;
1316  }
1317 #endif
1318 
1319  // Signal job to terminate if output file is too large
1320  if ( tf->GetSize() > mfs ) {
1321 
1322  m_signaledStop = true;
1323 
1324  fatal() << "file \"" << tf->GetName() << "\" associated with stream \"" << f.first
1325  << "\" has exceeded the max file size of " << m_maxFileSize.value() << "MB. Terminating Job." << endmsg;
1326 
1327  IEventProcessor* evt = nullptr;
1328  if ( service( "ApplicationMgr", evt, true ).isSuccess() ) {
1329  evt->stopRun();
1330  evt->release();
1331  } else {
1332  abort();
1333  }
1334  } else if ( tf->GetSize() > mfs_warn ) {
1335  warning() << "file \"" << tf->GetName() << "\" associated with stream \"" << f.first
1336  << "\" is at 95% of its maximum allowable file size of " << m_maxFileSize.value() << "MB" << endmsg;
1337  }
1338  }
1339 }
bool m_signaledStop
Definition: THistSvc.h:399
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Gaudi::Property< int > m_maxFileSize
Definition: THistSvc.h:382
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
The IEventProcessor is the interface to process events.
T abort(T... args)
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:93
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
void updateFiles()
Handle case where TTree grows beyond TTree::fgMaxTreeSize.
Definition: THistSvc.cpp:1466

◆ initialize()

StatusCode THistSvc::initialize ( )
override

Definition at line 78 of file THistSvc.cpp.

78  {
80 
82 
83  if ( status.isFailure() ) {
84  error() << "initializing service" << endmsg;
85  return status;
86  }
87 
89 
90  try {
92  } catch ( GaudiException& err ) {
93  error() << "Caught: " << err << endmsg;
95  }
96 
97  try {
99  } catch ( GaudiException& err ) {
100  error() << "Caught: " << err << endmsg;
101  st = StatusCode::FAILURE;
102  }
103 
104  // Protect against multiple instances of TROOT
105  if ( !gROOT ) {
106  static TROOT root( "root", "ROOT I/O" );
107  // gDebug = 99;
108  } else {
109  if ( msgLevel( MSG::VERBOSE ) ) { verbose() << "ROOT already initialized, debug = " << gDebug << endmsg; }
110  }
111 
112  if ( service( "IncidentSvc", p_incSvc, true ).isFailure() ) {
113  error() << "unable to get the IncidentSvc" << endmsg;
114  st = StatusCode::FAILURE;
115  } else {
116  p_incSvc->addListener( this, "EndEvent", 100, true );
117  }
118 
119  if ( service( "FileMgr", p_fileMgr, true ).isFailure() ) {
120  error() << "unable to get the FileMgr" << endmsg;
121  st = StatusCode::FAILURE;
122  } else {
123  debug() << "got the FileMgr" << endmsg;
124  }
125 
126  // Register open/close callback actions
127  using namespace std::placeholders;
128  auto boa = [this]( const Io::FileAttr* fa, const std::string& caller ) { return this->rootOpenAction( fa, caller ); };
129  if ( p_fileMgr->regAction( boa, Io::OPEN, Io::ROOT ).isFailure() ) {
130  error() << "unable to register ROOT file open action with FileMgr" << endmsg;
131  }
132  auto bea = [this]( const Io::FileAttr* fa, const std::string& caller ) {
133  return this->rootOpenErrAction( fa, caller );
134  };
135  if ( p_fileMgr->regAction( bea, Io::OPEN_ERR, Io::ROOT ).isFailure() ) {
136  error() << "unable to register ROOT file open Error action with FileMgr" << endmsg;
137  }
138 
139  m_okToConnect = true;
140  if ( m_delayConnect ) {
141  if ( !m_inputfile.value().empty() ) setupInputFile();
142  if ( !m_outputfile.value().empty() ) setupOutputFile();
143  m_delayConnect = false;
144  }
147 
148  IIoComponentMgr* iomgr = nullptr;
149  if ( service( "IoComponentMgr", iomgr, true ).isFailure() ) {
150  error() << "unable to get the IoComponentMgr" << endmsg;
151  st = StatusCode::FAILURE;
152  } else {
153  if ( !iomgr->io_register( this ).isSuccess() ) {
154  error() << "could not register with the I/O component manager !" << endmsg;
155  st = StatusCode::FAILURE;
156  } else {
157  bool all_good = true;
158  // register input/output files...
159  for ( const auto& reg : m_files ) {
160  const std::string& fname = reg.second.first->GetName();
161  const IIoComponentMgr::IoMode::Type iomode =
163  if ( !iomgr->io_register( this, iomode, fname ).isSuccess() ) {
164  warning() << "could not register file [" << fname << "] with the I/O component manager..." << endmsg;
165  all_good = false;
166  } else {
167  info() << "registered file [" << fname << "]... [ok]" << endmsg;
168  }
169  }
170  if ( !all_good ) {
171  error() << "problem while registering input/output files with "
172  << "the I/O component manager !" << endmsg;
173  st = StatusCode::FAILURE;
174  }
175  }
176  }
177 
178  if ( st.isFailure() ) { fatal() << "Unable to initialize THistSvc" << endmsg; }
179 
180  return st;
181 }
bool m_delayConnect
Definition: THistSvc.h:400
StatusCode initialize() override
Definition: Service.cpp:70
Define general base for Gaudi exception.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
IIncidentSvc * p_incSvc
Definition: THistSvc.h:396
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
StatusCode rootOpenAction(FILEMGR_CALLBACK_ARGS)
Definition: THistSvc.cpp:2085
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Gaudi::Property< std::vector< std::string > > m_outputfile
Definition: THistSvc.h:391
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
virtual StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &d="")=0
void setupOutputFile()
call-back method to handle output stream property
Definition: THistSvc.cpp:1908
void setupInputFile()
call-back method to handle input stream property
Definition: THistSvc.cpp:1884
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Gaudi::Property< std::vector< std::string > > m_inputfile
Definition: THistSvc.h:392
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
bool m_okToConnect
Definition: THistSvc.h:401
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode rootOpenErrAction(FILEMGR_CALLBACK_ARGS)
Definition: THistSvc.cpp:2107
T clear(T... args)
bool isSuccess() const
Definition: StatusCode.h:361
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
constexpr static const auto FAILURE
Definition: StatusCode.h:97
virtual StatusCode io_register(IIoComponent *iocomponent)=0
: allow a IIoComponent to register itself with this manager so appropriate actions can be taken when ...
IFileMgr * p_fileMgr
Definition: THistSvc.h:397
std::set< std::string > m_alreadyConnectedOutFiles
list of already connected files.
Definition: THistSvc.h:285
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:93
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
bool isFailure() const
Definition: StatusCode.h:141
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
Definition: THistSvc.h:281
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ io_reinit()

StatusCode THistSvc::io_reinit ( )
override

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

upon fork(2))

Definition at line 1344 of file THistSvc.cpp.

1344  {
1345  bool all_good = true;
1346  if ( msgLevel( MSG::DEBUG ) ) { debug() << "reinitializing I/O..." << endmsg; }
1347 
1348  // retrieve the I/O component manager...
1349 
1350  IIoComponentMgr* iomgr = nullptr;
1351 
1352  if ( service( "IoComponentMgr", iomgr, true ).isFailure() ) {
1353  error() << "could not retrieve I/O component manager !" << endmsg;
1354  return StatusCode::FAILURE;
1355  }
1356 
1357  GlobalDirectoryRestore restore( m_svcMut );
1358  // to hide the expected errors upon closing the files whose
1359  // file descriptors have been swept under the rug...
1360  gErrorIgnoreLevel = kFatal;
1361 
1362  for ( auto& ifile : m_files ) {
1363  TFile* f = ifile.second.first;
1364  std::string fname = f->GetName();
1365  if ( msgLevel( MSG::DEBUG ) ) {
1366  debug() << "file [" << fname << "] mode: [" << f->GetOption() << "] r:" << f->GetFileBytesRead()
1367  << " w:" << f->GetFileBytesWritten() << " cnt:" << f->GetFileCounter() << endmsg;
1368  }
1369 
1370  if ( ifile.second.second == READ ) {
1371  if ( msgLevel( MSG::DEBUG ) ) { debug() << " TFile opened in READ mode: not reassigning names" << endmsg; }
1372  continue;
1373  }
1374 
1375  if ( !iomgr->io_retrieve( this, fname ).isSuccess() ) {
1376  error() << "could not retrieve new name for [" << fname << "] !!" << endmsg;
1377  all_good = false;
1378  continue;
1379  } else if ( fname.empty() ) {
1380  if ( msgLevel( MSG::DEBUG ) ) { debug() << "empty new name for [" << fname << "], skipping..." << endmsg; }
1381  continue;
1382  } else {
1383  if ( msgLevel( MSG::DEBUG ) ) { debug() << "got a new name [" << fname << "]..." << endmsg; }
1384  }
1385 
1386  void* vf = nullptr;
1387  Option_t* opts = f->GetOption();
1388  int r = p_fileMgr->open( Io::ROOT, name(), fname, Io::WRITE, vf, "HIST" );
1389  if ( r != 0 ) {
1390  error() << "unable to open file \"" << fname << "\" for writing" << endmsg;
1391  return StatusCode::FAILURE;
1392  }
1393  TFile* newfile = (TFile*)vf;
1394  newfile->SetOption( opts );
1395 
1396  if ( ifile.second.second != THistSvc::READ ) {
1397  copyFileLayout( newfile, f );
1398  ifile.second.first = newfile;
1399  }
1400 
1401  // loop over all uids and migrate them to the new file
1402  for ( auto& uid : m_uids ) {
1403  for ( auto& hid : *uid.second ) {
1404  if ( hid.file != f ) continue;
1405  TDirectory* olddir = this->changeDir( hid );
1406  hid.file = newfile;
1407  // side-effect: create needed directories...
1408  TDirectory* newdir = this->changeDir( hid );
1409  TClass* cl = hid.obj->IsA();
1410 
1411  // migrate the objects to the new file.
1412  // thanks to the object model of ROOT, it is super easy.
1413  if ( cl->InheritsFrom( "TTree" ) ) {
1414  dynamic_cast<TTree*>( hid.obj )->SetDirectory( newdir );
1415  dynamic_cast<TTree*>( hid.obj )->Reset();
1416  } else if ( cl->InheritsFrom( "TH1" ) ) {
1417  dynamic_cast<TH1*>( hid.obj )->SetDirectory( newdir );
1418  dynamic_cast<TH1*>( hid.obj )->Reset();
1419  } else if ( cl->InheritsFrom( "TEfficiency" ) ) {
1420  dynamic_cast<TEfficiency*>( hid.obj )->SetDirectory( newdir );
1421  } else if ( cl->InheritsFrom( "TGraph" ) ) {
1422  olddir->Remove( hid.obj );
1423  newdir->Append( hid.obj );
1424  } else {
1425  error() << "id: \"" << hid.id << "\" is not a inheriting from a class "
1426  << "we know how to handle (received [" << cl->GetName() << "], "
1427  << "expected [TTree, TH1, TGraph or TEfficiency]) !" << endmsg << "attaching to current dir ["
1428  << newdir->GetPath() << "] "
1429  << "nonetheless..." << endmsg;
1430  olddir->Remove( hid.obj );
1431  newdir->Append( hid.obj );
1432  }
1433  }
1434  }
1435  f->ReOpen( "READ" );
1436  p_fileMgr->close( f, name() );
1437  f = newfile;
1438  }
1439 
1440  return all_good ? StatusCode::SUCCESS : StatusCode::FAILURE;
1441 }
T empty(T... args)
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
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
void copyFileLayout(TDirectory *, TDirectory *)
helper function to recursively copy the layout of a TFile into a new TFile
Definition: THistSvc.cpp:1928
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
TDirectory * changeDir(const THistSvc::THistID &hid) const
Definition: THistSvc.cpp:1745
virtual std::vector< std::string > io_retrieve(IIoComponent *iocomponent)=0
: retrieve all registered filenames for a given IIoComponent
uidMap_t m_uids
Definition: THistSvc.h:299
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
constexpr static const auto FAILURE
Definition: StatusCode.h:97
IFileMgr * p_fileMgr
Definition: THistSvc.h:397
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:93
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
virtual Io::close_t close(const Io::Fd, const std::string &caller)=0

◆ merge() [1/4]

StatusCode THistSvc::merge ( const std::string id)
override

Merge all clones for object with a given id.

Definition at line 649 of file THistSvc.cpp.

649  {
650  uidMap_t::iterator itr = m_uids.find( name );
651  if ( itr == m_uids.end() ) {
652  error() << "merge: id \"" << name << "\" not found" << endmsg;
653  return StatusCode::FAILURE;
654  }
655 
656  return merge( itr->second );
657 }
StatusCode merge(const std::string &id) override
Merge all clones for object with a given id.
Definition: THistSvc.cpp:649
T end(T... args)
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T find(T... args)
uidMap_t m_uids
Definition: THistSvc.h:299
constexpr static const auto FAILURE
Definition: StatusCode.h:97
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ merge() [2/4]

StatusCode THistSvc::merge ( TObject *  obj)
override

Merge all clones for given TObject*.

Definition at line 659 of file THistSvc.cpp.

659  {
660  objMap_t::iterator itr = m_tobjs.find( obj );
661  if ( itr != m_tobjs.end() ) {
662  return merge( itr->second.first );
663  } else {
664  error() << "merge: unknown object " << obj << endmsg;
665  return StatusCode::FAILURE;
666  }
667 }
StatusCode merge(const std::string &id) override
Merge all clones for object with a given id.
Definition: THistSvc.cpp:649
T end(T... args)
objMap_t m_tobjs
Definition: THistSvc.h:303
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T find(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ merge() [3/4]

StatusCode THistSvc::merge ( const THistID hid)
private

Helper method to merge THistID objects.

Definition at line 2041 of file THistSvc.cpp.

2041 { return merge( hid.id ); }
StatusCode merge(const std::string &id) override
Merge all clones for object with a given id.
Definition: THistSvc.cpp:649

◆ merge() [4/4]

StatusCode THistSvc::merge ( vhid_t vh)
private

Helper method to merge vectors of THistID.

Definition at line 2043 of file THistSvc.cpp.

2043  {
2044  const std::string& name = vh->at( 0 ).id;
2045  if ( vh->size() == 1 ) {
2046  debug() << "merge: id: \"" << name << "\" is size 1. nothing to do" << endmsg;
2047  return StatusCode::SUCCESS;
2048  }
2049 
2050  if ( !vh->at( 0 ).obj->IsA()->InheritsFrom( "TH1" ) ) {
2051  error() << "merge: id \"" << name << "\" is not a THn. Cannot merge" << endmsg;
2052  return StatusCode::FAILURE;
2053  }
2054 
2055  TList* l = new TList();
2056  for ( size_t i = 1; i < vh->size(); ++i ) {
2057  debug() << "merge: id: \"" << name << "\" (" << vh->at( i ).obj << ") adding index " << i << endmsg;
2058  l->Add( vh->at( i ).obj );
2059  }
2060 
2061  TH1* t0 = dynamic_cast<TH1*>( vh->at( 0 ).obj );
2062  if ( t0 == 0 ) {
2063  error() << "merge: could not dcast " << name << "(" << t0 << ") index " << 0 << " to TH1" << endmsg;
2064  return StatusCode::FAILURE;
2065  }
2066 
2067  Long64_t n = t0->Merge( l );
2068 
2069  debug() << "merge: id: \"" << name << "\" merged " << n << " entries" << endmsg;
2070 
2071  for ( size_t i = 1; i < vh->size(); ++i ) {
2072  TH1* th = dynamic_cast<TH1*>( vh->at( i ).obj );
2073  if ( th != 0 ) {
2074  debug() << "clearing index " << i << "(" << th << ")" << endmsg;
2075  th->SetDirectory( nullptr );
2076  th->Reset();
2077  } else {
2078  error() << "merge: could not dcast " << name << " index " << i << " to TH1" << endmsg;
2079  return StatusCode::FAILURE;
2080  }
2081  }
2082  return StatusCode::SUCCESS;
2083 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
STL class.
T at(T... args)
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
dictionary l
Definition: gaudirun.py:543
constexpr static const auto FAILURE
Definition: StatusCode.h:97
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ MergeRootFile()

void THistSvc::MergeRootFile ( TDirectory *  target,
TDirectory *  source 
)
private

Definition at line 1787 of file THistSvc.cpp.

1787  {
1788  if ( msgLevel( MSG::DEBUG ) ) { debug() << "Target path: " << target->GetPath() << endmsg; }
1789  TString path( (char*)strstr( target->GetPath(), ":" ) );
1790  path.Remove( 0, 2 );
1791 
1792  source->cd( path );
1793  TDirectory* current_sourcedir = gDirectory;
1794 
1795  // loop over all keys in this directory
1796  TList* lkeys = current_sourcedir->GetListOfKeys();
1797  int nkeys = lkeys->GetEntries();
1798  TKey* key = nullptr;
1799  for ( int jj = 0; jj < nkeys; jj++ ) {
1800  key = (TKey*)lkeys->At( jj );
1801  std::string pathnameinsource = current_sourcedir->GetPath() + std::string( "/" ) + key->GetName();
1802  if ( msgLevel( MSG::DEBUG ) ) { debug() << "Reading Key:" << pathnameinsource << endmsg; }
1803  TObject* obj = source->Get( pathnameinsource.c_str() );
1804 
1805  if ( obj ) {
1806  if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) {
1807  // it's a subdirectory
1808  if ( msgLevel( MSG::DEBUG ) ) { debug() << "Found subdirectory " << obj->GetName() << endmsg; }
1809 
1810  // create a new subdir of same name and title in the target file
1811  target->cd();
1812  TDirectory* newtargetdir = target->mkdir( obj->GetName(), obj->GetTitle() );
1813 
1814  MergeRootFile( newtargetdir, source );
1815 
1816  } else if ( obj->IsA()->InheritsFrom( "TTree" ) ) {
1817  if ( msgLevel( MSG::DEBUG ) ) { debug() << "Found TTree " << obj->GetName() << endmsg; }
1818  TTree* mytree = dynamic_cast<TTree*>( obj );
1819  int nentries = (int)mytree->GetEntries();
1820  mytree->SetBranchStatus( "*", 1 );
1821 
1822  if ( msgLevel( MSG::DEBUG ) ) { debug() << "Dumping TTree " << nentries << " entries" << endmsg; }
1823  target->cd();
1824  mytree->CloneTree();
1825 
1826  } else {
1827  target->cd();
1828  obj->Write( key->GetName() );
1829  }
1830  }
1831  }
1832 }
void MergeRootFile(TDirectory *, TDirectory *)
Definition: THistSvc.cpp:1787
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T c_str(T... args)
T strstr(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ parseString()

void THistSvc::parseString ( const std::string id,
std::string root,
std::string rem 
) const
private

Definition at line 1870 of file THistSvc.cpp.

1870  {
1871  auto pos = id.find( "/" );
1872 
1873  if ( pos == std::string::npos ) {
1874  root.clear();
1875  rem = id;
1876  } else if ( pos == 0 ) {
1877  parseString( id.substr( 1 ), root, rem );
1878  } else {
1879  root = id.substr( 0, pos );
1880  rem = id.substr( pos + 1 );
1881  }
1882 }
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1870
T substr(T... args)

◆ readHist()

template<typename T >
T * THistSvc::readHist ( const std::string name) const
private

Definition at line 1460 of file THistSvc.cpp.

1460  {
1461  return dynamic_cast<T*>( readHist_i<T>( id ) );
1462 }

◆ readHist_i()

template<typename T >
T * THistSvc::readHist_i ( const std::string name) const
private

Definition at line 217 of file THistSvc.icc.

217  {
218  GlobalDirectoryRestore restore( m_svcMut );
219 
220  std::string idr( id );
221  removeDoubleSlash( idr );
222 
223  std::string stream, rem, dir, fdir, bdir, fdir2;
224  TFile* file = nullptr;
225 
226  if ( !findStream( idr, stream, rem, file ) ) { return nullptr; }
227 
228  if ( !file ) {
229  error() << "no associated file found" << endmsg;
230  return nullptr;
231  }
232 
233  file->cd( "/" );
234 
235  fdir = idr;
236  bdir = stripDirectoryName( fdir );
237  fdir2 = fdir;
238  while ( ( dir = stripDirectoryName( fdir ) ) != "" ) {
239  if ( !gDirectory->GetKey( dir.c_str() ) ) {
240  error() << "Directory \"" << fdir2 << "\" doesnt exist in " << file->GetName() << endmsg;
241  return nullptr;
242  }
243  gDirectory->cd( dir.c_str() );
244  }
245 
246  TObject* to = nullptr;
247  gDirectory->GetObject( fdir.c_str(), to );
248 
249  if ( !to ) {
250  error() << "Could not get obj \"" << fdir << "\" in " << gDirectory->GetPath() << endmsg;
251  return nullptr;
252  }
253 
254  T* hist = dynamic_cast<T*>( to );
255  if ( hist == nullptr ) {
256  error() << "Could not convert \"" << idr << "\" to a " << System::typeinfoName( typeid( *hist ) ) << " as is a "
257  << to->IsA()->GetName() << endmsg;
258  return nullptr;
259  }
260 
261  if ( msgLevel( MSG::DEBUG ) ) {
262  debug() << "Read in " << hist->IsA()->GetName() << " \"" << hist->GetName() << "\" from file " << file->GetName()
263  << endmsg;
264  hist->Print();
265  }
266 
267  return hist;
268 }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:308
std::string stripDirectoryName(std::string &dir) const
Definition: THistSvc.cpp:1767
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
Definition: THistSvc.cpp:1834
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1783
T c_str(T... args)
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ readTree()

TTree * THistSvc::readTree ( const std::string name) const
private

Definition at line 1464 of file THistSvc.cpp.

1464 { return dynamic_cast<TTree*>( readHist_i<TTree>( id ) ); }

◆ regEfficiency() [1/3]

StatusCode THistSvc::regEfficiency ( const std::string name)
override

Register a new TEfficiency with a given name.

Definition at line 452 of file THistSvc.cpp.

452  {
453  std::unique_ptr<TEfficiency> eff = nullptr;
454  return regHist_i( std::move( eff ), id, false );
455 }
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27
STL class.

◆ regEfficiency() [2/3]

StatusCode THistSvc::regEfficiency ( const std::string name,
std::unique_ptr< TEfficiency >  eff 
)
override

Register an existing TEfficiency with a given name and moved unique_ptr.

Definition at line 457 of file THistSvc.cpp.

457  {
458  return regHist_i( std::move( eff ), id, false );
459 }
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27

◆ regEfficiency() [3/3]

StatusCode THistSvc::regEfficiency ( const std::string name,
TEfficiency *  eff_ptr 
)
overridevirtual
Deprecated:
{Just kept for compatibiltiy to current ATLAS code.

Pleas use std::unique_ptrs instead!} Register a new TEfficiency with a given name and a raw pointer

Definition at line 461 of file THistSvc.cpp.

461  {
462  std::unique_ptr<TEfficiency> eff( eff_ptr );
463  return regHist_i( std::move( eff ), id, false );
464 }
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27
STL class.

◆ regGraph() [1/3]

StatusCode THistSvc::regGraph ( const std::string name)
override

Register a new TGraph with a given name.

Definition at line 411 of file THistSvc.cpp.

411  {
412  std::unique_ptr<TGraph> graph = std::make_unique<TGraph>();
413  return regHist_i( std::move( graph ), id, false );
414 }
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27
STL class.

◆ regGraph() [2/3]

StatusCode THistSvc::regGraph ( const std::string name,
std::unique_ptr< TGraph >  graph 
)
override

Register an existing TGraph with a given name and moved unique_ptr.

Definition at line 416 of file THistSvc.cpp.

416  {
417  if ( strcmp( graph->GetName(), "Graph" ) == 0 ) {
418  std::string id2( id );
419  std::string::size_type i = id2.rfind( "/" );
420  if ( i != std::string::npos ) { id2.erase( 0, i + 1 ); }
421 
422  info() << "setting name of TGraph id: \"" << id << "\" to \"" << id2 << "\" since it is unset" << endmsg;
423  graph->SetName( id2.c_str() );
424  }
425 
426  return regHist_i( std::move( graph ), id, false );
427 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
STL class.
T strcmp(T... args)
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ regGraph() [3/3]

StatusCode THistSvc::regGraph ( const std::string name,
TGraph *  graph_ptr 
)
overridevirtual
Deprecated:
{Just kept for compatibiltiy to current ATLAS code.

Pleas use std::unique_ptrs instead!} Register a new TGraph with a given name and a raw pointer

Definition at line 429 of file THistSvc.cpp.

429  {
430  std::unique_ptr<TGraph> graph( graph_ptr );
431  if ( strcmp( graph->GetName(), "Graph" ) == 0 ) {
432  std::string id2( id );
433  std::string::size_type i = id2.rfind( "/" );
434  if ( i != std::string::npos ) { id2.erase( 0, i + 1 ); }
435 
436  info() << "setting name of TGraph id: \"" << id << "\" to \"" << id2 << "\" since it is unset" << endmsg;
437  graph->SetName( id2.c_str() );
438  }
439 
440  return regHist_i( std::move( graph ), id, false );
441 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
STL class.
T strcmp(T... args)
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27
STL class.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ regHist() [1/4]

StatusCode THistSvc::regHist ( const std::string name)
override

Register a new ROOT histogram TH*X with a name.

Definition at line 329 of file THistSvc.cpp.

329  {
330  std::unique_ptr<TH1> hist = nullptr;
331  return regHist_i( std::move( hist ), id, false );
332 }
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27
STL class.

◆ regHist() [2/4]

StatusCode THistSvc::regHist ( const std::string name,
std::unique_ptr< TH1 >  hist 
)
override

Register an existing ROOT histogram TH*X with name and moved unique_ptr.

Parameters
[in]namedefines the histogram id/name under which it is recorded
[in]histtransfers ownership of the histogram to the THistSvc

Definition at line 334 of file THistSvc.cpp.

334  {
335  return regHist_i( std::move( hist ), id, false );
336 }
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27

◆ regHist() [3/4]

StatusCode THistSvc::regHist ( const std::string name,
std::unique_ptr< TH1 >  hist,
TH1 *  hist_ptr 
)
override

Register an existing ROOT histogram TH*X with name and moved unique_ptr.

Parameters
[in]namedefines the histogram id/name under which it is recorded
[in]histtransfers ownership of the histogram to the THistSvc
[out]hist_ptrfor compatibility: return raw pointer to managed object to support common usage in Athena

Definition at line 338 of file THistSvc.cpp.

338  {
339  // This is only to support a common use case where the histogram is used after its registration
340  if ( hist_ptr != nullptr ) { hist_ptr = hist.get(); }
341  return regHist_i( std::move( hist ), id, false );
342 }
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27
T get(T... args)

◆ regHist() [4/4]

StatusCode THistSvc::regHist ( const std::string name,
TH1 *  hist_ptr 
)
override
Deprecated:
{Just for compatibility purposes.

Ownership should be clearly managed.} Register an existing ROOT histogram TH*X with name and pointer

Definition at line 344 of file THistSvc.cpp.

344  {
345  std::unique_ptr<TH1> hist( hist_ptr );
346  return regHist_i( std::move( hist ), id, false );
347 }
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27
STL class.

◆ regHist_i() [1/2]

template<typename T >
StatusCode THistSvc::regHist_i ( std::unique_ptr< T >  hist,
const std::string name,
bool  shared 
)
private

Definition at line 27 of file THistSvc.icc.

27  {
28  THistID* hid = nullptr;
29  return regHist_i( std::move( hist ), id, shared, hid );
30 }
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27

◆ regHist_i() [2/2]

template<typename T >
StatusCode THistSvc::regHist_i ( std::unique_ptr< T >  hist,
const std::string name,
bool  shared,
THistID *&  hid 
)
private

Definition at line 33 of file THistSvc.icc.

33  {
35  phid = nullptr;
36 
37  // It is sad that we lose propper memory management here
38  T* hist = nullptr;
39  if ( hist_unique.get() != nullptr ) { hist = hist_unique.release(); }
40  debug() << "regHist_i obj: " << hist << " id: " << id << " s: " << shared << endmsg;
41 
42  std::string idr( id );
43  removeDoubleSlash( idr );
44 
45  if ( idr.find( "/" ) == idr.length() ) {
46  error() << "Badly formed identifier \"" << idr << "\": "
47  << "Must not end with a /" << endmsg;
48  delete hist;
49  return StatusCode::FAILURE;
50  }
51 
52  TFile* f = nullptr;
53  std::string stream, name;
54  if ( !findStream( idr, stream, name, f ) ) {
55  error() << "Could not register id: \"" << idr << "\"" << endmsg;
56  delete hist;
57  return StatusCode::FAILURE;
58  }
59 
60  std::string uid = "/" + stream + "/" + name;
61 
62  uidMap_t::iterator uitr = m_uids.find( uid );
63  bool exists( false );
64  if ( uitr != m_uids.end() ) {
65  exists = true;
66  TObject* t1 = uitr->second->at( 0 ).obj;
67  if ( hist->Compare( t1 ) != 0 ) {
68  error() << "previously registered object with identifier \"" << uid << "\" does not compare to this one"
69  << endmsg;
70  delete hist;
71  return StatusCode::FAILURE;
72  } else {
73  debug() << "previously registered id \"" << uid << "\": num " << uitr->second->size() << endmsg;
74  }
75  }
76 
77  bool temp = false;
78  if ( !f ) {
79  temp = true;
80  if ( msgLevel( MSG::DEBUG ) ) { debug() << "Historgram with id \"" << idr << "\" is temporary" << endmsg; }
81  }
82 
83  TObject* to = nullptr;
84  THistID hid;
85  // check to see if this hist is to be read in;
86  if ( !temp && m_files.find( stream )->second.second == READ ) {
87  if ( hist != 0 ) { warning() << "Registering id: \"" << idr << "\" with non zero pointer!" << endmsg; }
88 
89  hist = readHist_i<T>( idr );
90  if ( hist == nullptr ) {
91  error() << "Unable to read in hist" << endmsg;
92  delete hist;
93  return StatusCode::FAILURE;
94  }
95  to = dynamic_cast<TObject*>( hist );
96  hid = THistID( uid, temp, to, f, m_files.find( stream )->second.second );
97  } else if ( !hist ) {
98  error() << "Unable to read in hist with id: \"" << idr << "\"" << endmsg;
99  delete hist;
100  return StatusCode::FAILURE;
101  } else {
102  to = dynamic_cast<TObject*>( hist );
103  if ( to == nullptr ) {
104  error() << "Could not dcast to TObject. id: \"" << idr << "\"" << endmsg;
105  delete hist;
106  return StatusCode::FAILURE;
107  }
108 
109  auto oitr = m_tobjs.find( to );
110  if ( oitr != m_tobjs.end() ) {
111  error() << "already registered id: \"" << idr << "\" with identifier \""
112  << oitr->second.first->at( oitr->second.second ).id << "\"" << endmsg;
113  delete hist;
114  return StatusCode::FAILURE;
115  }
116 
117  const auto findF = m_files.find( stream );
118  hid = ( findF != m_files.end() ? THistID( uid, temp, to, f, findF->second.second ) : THistID( uid, temp, to, f ) );
119 
120  hid.shared = shared;
121  TDirectory* dir = changeDir( hid );
122 
123  if ( dynamic_cast<TTree*>( hist ) ) {
124  dynamic_cast<TTree*>( hist )->SetDirectory( dir );
125  } else if ( dynamic_cast<TH1*>( hist ) ) {
126  dynamic_cast<TH1*>( hist )->SetDirectory( dir );
127  } else if ( dynamic_cast<TEfficiency*>( hist ) ) {
128  dynamic_cast<TEfficiency*>( hist )->SetDirectory( dir );
129  } else if ( dynamic_cast<TGraph*>( hist ) ) {
130  dir->Append( hist );
131  } else {
132  error() << "id: \"" << idr << "\" is not a TH, TTree, TGraph, or TEfficiency. Attaching it to current dir."
133  << endmsg;
134  dir->Append( hist );
135  }
136  }
137 
138  std::string fname;
139  if ( !f ) {
140  fname = "none";
141  } else {
142  fname = f->GetName();
143  }
144 
145  debug() << "Registering" << ( shared ? " shared " : " " ) << System::typeinfoName( typeid( *hist ) ) << " title: \""
146  << hist->GetTitle() << "\" id: \"" << uid
147  << "\" dir: "
148  // << hist->GetDirectory()->GetPath() << " "
149  << changeDir( hid )->GetPath() << " file: " << fname << endmsg;
150 
151  // create a mutex for all shared histograms
152  if ( shared ) { hid.mutex = new histMut_t; }
153 
154  if ( exists ) {
155  vhid_t* vi = uitr->second;
156  vi->push_back( hid );
157  phid = &( vi->back() );
158 
159  m_tobjs.emplace( to, std::pair<vhid_t*, size_t>( vi, vi->size() - 1 ) );
160  } else {
161  vhid_t* vi = new vhid_t{hid};
162  m_hlist.emplace( m_hlist.end(), vi );
163 
164  phid = &( vi->back() );
165  m_uids.emplace( uid, vi );
166  m_ids.emplace( name, vi );
167 
169  }
170 
171  debug() << "regHist_i THistID: " << hid << endmsg;
172 
173  return StatusCode::SUCCESS;
174 }
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:308
std::mutex histMut_t
Definition: THistSvc.h:205
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T end(T... args)
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
Definition: THistSvc.cpp:1834
objMap_t m_tobjs
Definition: THistSvc.h:303
T release(T... args)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
hlist_t m_hlist
Definition: THistSvc.h:298
idMap_t m_ids
Definition: THistSvc.h:300
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
std::vector< THistID > vhid_t
Definition: THistSvc.h:289
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
TDirectory * changeDir(const THistSvc::THistID &hid) const
Definition: THistSvc.cpp:1745
T find(T... args)
T size(T... args)
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1783
uidMap_t m_uids
Definition: THistSvc.h:299
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
T emplace(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97
bool exists(const std::string &name) const override
Check if object with given name is managed by THistSvcMT exists calls existsHist and only works for T...
Definition: THistSvc.cpp:669
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ regShared() [1/5]

StatusCode THistSvc::regShared ( const std::string name,
std::unique_ptr< TH1 >  hist,
LockedHandle< TH1 > &  lh 
)
override

Register shared object of type TH1 and return LockedHandle for that object.

Definition at line 475 of file THistSvc.cpp.

475  {
476  lh = regShared_i<TH1>( id, std::move( hist ) );
477  if ( lh ) {
478  return StatusCode::SUCCESS;
479  } else {
480  return StatusCode::FAILURE;
481  }
482 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T move(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ regShared() [2/5]

StatusCode THistSvc::regShared ( const std::string name,
std::unique_ptr< TH2 >  hist,
LockedHandle< TH2 > &  lh 
)
override

Register shared object of type TH2 and return LockedHandle for that object.

Definition at line 484 of file THistSvc.cpp.

484  {
485  lh = regShared_i<TH2>( id, std::move( hist ) );
486  if ( lh ) {
487  return StatusCode::SUCCESS;
488  } else {
489  return StatusCode::FAILURE;
490  }
491 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T move(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ regShared() [3/5]

StatusCode THistSvc::regShared ( const std::string name,
std::unique_ptr< TH3 >  hist,
LockedHandle< TH3 > &  lh 
)
override

Register shared object of type TH3 and return LockedHandle for that object.

Definition at line 493 of file THistSvc.cpp.

493  {
494  lh = regShared_i<TH3>( id, std::move( hist ) );
495  if ( lh ) {
496  return StatusCode::SUCCESS;
497  } else {
498  return StatusCode::FAILURE;
499  }
500 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T move(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ regShared() [4/5]

StatusCode THistSvc::regShared ( const std::string name,
std::unique_ptr< TGraph >  graph,
LockedHandle< TGraph > &  lh 
)
override

Register shared object of type TGraph and return LockedHandle for that object.

Definition at line 502 of file THistSvc.cpp.

502  {
503  lh = regShared_i<TGraph>( id, std::move( graph ) );
504  if ( lh ) {
505  return StatusCode::SUCCESS;
506  } else {
507  return StatusCode::FAILURE;
508  }
509 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T move(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ regShared() [5/5]

StatusCode THistSvc::regShared ( const std::string name,
std::unique_ptr< TEfficiency >  eff,
LockedHandle< TEfficiency > &  lh 
)
override

Register shared object of type TEfficiency and return LockedHandle for that object.

Definition at line 511 of file THistSvc.cpp.

512  {
513  lh = regShared_i<TEfficiency>( id, std::move( eff ) );
514  if ( lh ) {
515  return StatusCode::SUCCESS;
516  } else {
517  return StatusCode::FAILURE;
518  }
519 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T move(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ regShared_i()

template<typename T >
LockedHandle< T > THistSvc::regShared_i ( const std::string id,
std::unique_ptr< T >  hist 
)
private

Definition at line 271 of file THistSvc.icc.

271  {
272  LockedHandle<T> lh( nullptr, nullptr );
273  const THistID* hid = nullptr;
274  if ( findHistID( id, hid ) == 0 ) {
275  T* phist = hist.get();
276  THistID* phid = nullptr;
277  if ( regHist_i( std::move( hist ), id, true, phid ).isSuccess() ) {
278  lh.set( phist, phid->mutex );
279 
280  } else {
281  error() << "regSharedHist: unable to register shared hist with id \"" << id << "\"" << endmsg;
282  }
283  } else {
284  if ( !hid->shared ) {
285  error() << "regSharedHist: previously register Hist with id \"" << id << "\" was not marked shared" << endmsg;
286  }
287 
288  if ( hist->Compare( hid->obj ) != 0 ) {
289  error() << "regSharedHist: Histogram " << id << " does not compare with " << hid << endmsg;
290  } else {
291  T* phist = dynamic_cast<T*>( hid->obj );
292  if ( phist == 0 ) {
293  error() << "regSharedHist: unable to dcast retrieved shared hist \"" << id << "\" of type "
294  << hid->obj->IsA()->GetName() << " to requested type " << System::typeinfoName( typeid( T ) ) << endmsg;
295  } else {
296  lh.set( phist, hid->mutex );
297  delete hist.release();
298  }
299  }
300  }
301  return lh;
302 }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:308
T release(T... args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Provides automatic lock/unlock access to a class upon deref of ptr.
Definition: LockedHandle.h:38
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27
T get(T... args)
size_t findHistID(const std::string &id, const THistID *&hid, const size_t &index=0) const
Definition: THistSvc.cpp:1960
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ regTree() [1/3]

StatusCode THistSvc::regTree ( const std::string name)
override

Register a new TTree with a given name.

Definition at line 376 of file THistSvc.cpp.

376  {
377  std::unique_ptr<TTree> tree = nullptr;
378  return regHist_i( std::move( tree ), id, false );
379 }
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27
STL class.

◆ regTree() [2/3]

StatusCode THistSvc::regTree ( const std::string name,
std::unique_ptr< TTree >  tree 
)
override

Register an existing TTree with a given name and moved unique_ptr.

Definition at line 381 of file THistSvc.cpp.

381  {
382  StatusCode sc = regHist_i( std::move( tree ), id, false );
383  TTree* tr = nullptr;
384  if ( getTree( id, tr ).isSuccess() && sc.isSuccess() ) {
385  if ( m_autoSave != 0 ) { tr->SetAutoSave( m_autoSave ); }
386  tr->SetAutoFlush( m_autoFlush );
387  }
388  return sc;
389 }
Gaudi::Property< int > m_autoSave
Definition: THistSvc.h:379
StatusCode getTree(const std::string &name, TTree *&) const override
Return TTree with given name.
Definition: THistSvc.cpp:402
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
bool isSuccess() const
Definition: StatusCode.h:361
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27
Gaudi::Property< int > m_autoFlush
Definition: THistSvc.h:380

◆ regTree() [3/3]

StatusCode THistSvc::regTree ( const std::string name,
TTree *  tree_ptr 
)
override
Deprecated:
{Just kept for compatibiltiy to current ATLAS code.

Pleas use std::unique_ptrs instead!} Register a new TTree with a given name and a raw pointer

Definition at line 391 of file THistSvc.cpp.

391  {
392  std::unique_ptr<TTree> tree( tree_ptr );
393  StatusCode sc = regHist_i( std::move( tree ), id, false );
394  TTree* tr = nullptr;
395  if ( getTree( id, tr ).isSuccess() && sc.isSuccess() ) {
396  if ( m_autoSave != 0 ) { tr->SetAutoSave( m_autoSave ); }
397  tr->SetAutoFlush( m_autoFlush );
398  }
399  return sc;
400 }
Gaudi::Property< int > m_autoSave
Definition: THistSvc.h:379
StatusCode getTree(const std::string &name, TTree *&) const override
Return TTree with given name.
Definition: THistSvc.cpp:402
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
bool isSuccess() const
Definition: StatusCode.h:361
T move(T... args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:27
STL class.
Gaudi::Property< int > m_autoFlush
Definition: THistSvc.h:380

◆ reinitialize()

StatusCode THistSvc::reinitialize ( )
override

Definition at line 183 of file THistSvc.cpp.

183  {
184  GlobalDirectoryRestore restore( m_svcMut );
185  warning() << "reinitialize not implemented" << endmsg;
186  return StatusCode::SUCCESS;
187 }
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:405
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ removeDoubleSlash()

void THistSvc::removeDoubleSlash ( std::string id) const
private

Definition at line 1783 of file THistSvc.cpp.

1783  {
1784  while ( id.find( "//" ) != std::string::npos ) { id.replace( id.find( "//" ), 2, "/" ); }
1785 }
T find(T... args)

◆ rootOpenAction()

StatusCode THistSvc::rootOpenAction ( FILEMGR_CALLBACK_ARGS  )
private

Definition at line 2085 of file THistSvc.cpp.

2085  {
2086  if ( fa->tech() != Io::ROOT ) {
2087  // This should never happen
2088  return StatusCode::SUCCESS;
2089  }
2090 
2091  if ( fa->desc() != "HIST" ) { return StatusCode::SUCCESS; }
2092 
2093  p_incSvc->fireIncident( FileIncident( caller, "OpenHistFile", fa->name() ) );
2094 
2095  if ( fa->flags().isRead() ) {
2096  p_incSvc->fireIncident( FileIncident( caller, "BeginHistFile", fa->name() ) );
2097  } else if ( fa->flags().isWrite() ) {
2098  p_incSvc->fireIncident( FileIncident( caller, IncidentType::BeginOutputFile, fa->name() ) );
2099  } else {
2100  // for Io::RW
2101  p_incSvc->fireIncident( FileIncident( caller, IncidentType::BeginOutputFile, fa->name() ) );
2102  }
2103 
2104  return StatusCode::SUCCESS;
2105 }
This class is the FileIncident.
Definition: FileIncident.h:27
IIncidentSvc * p_incSvc
Definition: THistSvc.h:396
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.

◆ rootOpenErrAction()

StatusCode THistSvc::rootOpenErrAction ( FILEMGR_CALLBACK_ARGS  )
private

Definition at line 2107 of file THistSvc.cpp.

2107  {
2108  if ( fa->tech() != Io::ROOT ) {
2109  // This should never happen
2110  return StatusCode::SUCCESS;
2111  }
2112 
2113  if ( fa->desc() != "HIST" ) { return StatusCode::SUCCESS; }
2114 
2115  if ( fa->flags().isRead() ) {
2116  p_incSvc->fireIncident( FileIncident( caller, IncidentType::FailInputFile, fa->name() ) );
2117  } else if ( fa->flags().isWrite() ) {
2118  p_incSvc->fireIncident( FileIncident( caller, IncidentType::FailOutputFile, fa->name() ) );
2119  } else {
2120  // for Io::RW
2121  p_incSvc->fireIncident( FileIncident( caller, "FailRWFile", fa->name() ) );
2122  }
2123 
2124  return StatusCode::SUCCESS;
2125 }
This class is the FileIncident.
Definition: FileIncident.h:27
IIncidentSvc * p_incSvc
Definition: THistSvc.h:396
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.

◆ setupInputFile()

void THistSvc::setupInputFile ( )
private

call-back method to handle input stream property

Definition at line 1884 of file THistSvc.cpp.

1884  {
1886  debug() << "Delaying connection of Input Files until Initialize"
1887  << ". now in " << FSMState() << endmsg;
1888 
1889  m_delayConnect = true;
1890  } else {
1891  debug() << "Now connecting of Input Files" << endmsg;
1892 
1894 
1895  for ( const auto& itr : m_inputfile.value() ) {
1896  if ( m_alreadyConnectedInFiles.end() != m_alreadyConnectedInFiles.find( itr ) ) { continue; }
1897  if ( connect( itr ).isFailure() ) {
1898  sc = StatusCode::FAILURE;
1899  } else {
1901  }
1902  }
1903 
1904  if ( !sc.isSuccess() ) { throw GaudiException( "Problem connecting inputfile !!", name(), StatusCode::FAILURE ); }
1905  }
1906 }
bool m_delayConnect
Definition: THistSvc.h:400
Define general base for Gaudi exception.
Gaudi::StateMachine::State FSMState() const override
Definition: Service.h:62
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T end(T... args)
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
Gaudi::Property< std::vector< std::string > > m_inputfile
Definition: THistSvc.h:392
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
bool m_okToConnect
Definition: THistSvc.h:401
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
bool isSuccess() const
Definition: StatusCode.h:361
T insert(T... args)
T find(T... args)
StatusCode connect(const std::string &)
Definition: THistSvc.cpp:1568
constexpr static const auto FAILURE
Definition: StatusCode.h:97
bool isFailure() const
Definition: StatusCode.h:141
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
Definition: THistSvc.h:281
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ setupOutputFile()

void THistSvc::setupOutputFile ( )
private

call-back method to handle output stream property

Definition at line 1908 of file THistSvc.cpp.

1908  {
1910  debug() << "Delaying connection of Input Files until Initialize"
1911  << ". now in " << FSMState() << endmsg;
1912  m_delayConnect = true;
1913  } else {
1915  for ( const auto& itr : m_outputfile.value() ) {
1916  if ( m_alreadyConnectedOutFiles.end() != m_alreadyConnectedOutFiles.find( itr ) ) { continue; }
1917  if ( connect( itr ).isFailure() ) {
1918  sc = StatusCode::FAILURE;
1919  } else {
1921  }
1922  }
1923 
1924  if ( !sc.isSuccess() ) { throw GaudiException( "Problem connecting outputfile !!", name(), StatusCode::FAILURE ); }
1925  }
1926 }
bool m_delayConnect
Definition: THistSvc.h:400
Define general base for Gaudi exception.
Gaudi::StateMachine::State FSMState() const override
Definition: Service.h:62
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T end(T... args)
Gaudi::Property< std::vector< std::string > > m_outputfile
Definition: THistSvc.h:391
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
bool m_okToConnect
Definition: THistSvc.h:401
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
bool isSuccess() const
Definition: StatusCode.h:361
T insert(T... args)
T find(T... args)
StatusCode connect(const std::string &)
Definition: THistSvc.cpp:1568
constexpr static const auto FAILURE
Definition: StatusCode.h:97
std::set< std::string > m_alreadyConnectedOutFiles
list of already connected files.
Definition: THistSvc.h:285
bool isFailure() const
Definition: StatusCode.h:141
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ stripDirectoryName()

std::string THistSvc::stripDirectoryName ( std::string dir) const
private

Definition at line 1767 of file THistSvc.cpp.

1767  {
1768  std::string::size_type i = dir.find( "/" );
1769 
1770  if ( i == std::string::npos ) return {};
1771 
1772  if ( i == 0 ) {
1773  dir.erase( 0, 1 );
1774  return stripDirectoryName( dir );
1775  }
1776 
1777  std::string root = dir.substr( 0, i );
1778  dir.erase( 0, i );
1779 
1780  return root;
1781 }
std::string stripDirectoryName(std::string &dir) const
Definition: THistSvc.cpp:1767
STL class.
T erase(T... args)
T find(T... args)
T substr(T... args)

◆ updateFiles()

void THistSvc::updateFiles ( )
private

Handle case where TTree grows beyond TTree::fgMaxTreeSize.

Definition at line 1466 of file THistSvc.cpp.

1466  {
1467  // If TTrees grow beyond TTree::fgMaxTreeSize, a new file is
1468  // automatically created by root, and the old one closed. We
1469  // need to migrate all the UIDs over to show the correct file
1470  // pointer. This is ugly.
1471 
1472  if ( msgLevel( MSG::DEBUG ) ) debug() << "updateFiles()" << endmsg;
1473 
1474  for ( auto uitr = m_uids.begin(); uitr != m_uids.end(); ++uitr ) {
1475  for ( auto& hid : *( uitr->second ) ) {
1476 #ifndef NDEBUG
1477  if ( msgLevel( MSG::VERBOSE ) )
1478  verbose() << " update: " << uitr->first << " " << hid.id << " " << hid.mode << endmsg;
1479 #endif
1480  TObject* to = hid.obj;
1481  TFile* oldFile = hid.file;
1482  if ( !to ) {
1483  warning() << uitr->first << ": TObject == 0" << endmsg;
1484  } else if ( hid.temp || hid.mode == READ ) {
1485 // do nothing - no need to check how big the file is since we
1486 // are just reading it.
1487 #ifndef NDEBUG
1488  if ( msgLevel( MSG::VERBOSE ) ) verbose() << " skipping" << endmsg;
1489 #endif
1490  } else if ( to->IsA()->InheritsFrom( "TTree" ) ) {
1491  TTree* tr = dynamic_cast<TTree*>( to );
1492  TFile* newFile = tr->GetCurrentFile();
1493 
1494  if ( oldFile != newFile ) {
1495  std::string newFileName = newFile->GetName();
1496  std::string oldFileName, streamName, rem;
1497  TFile* dummy = nullptr;
1498  findStream( hid.id, streamName, rem, dummy );
1499 
1500  for ( auto& itr : m_files ) {
1501  if ( itr.second.first == oldFile ) { itr.second.first = newFile; }
1502  }
1503 
1504  for ( auto uitr2 = uitr; uitr2 != m_uids.end(); ++uitr2 ) {
1505  for ( auto& hid2 : *( uitr2->second ) ) {
1506  if ( hid2.file == oldFile ) { hid2.file = newFile; }
1507  }
1508  }
1509 
1511  [&]( streamMap::const_reference s ) { return s.second == streamName; } );
1512  if ( sitr != std::end( m_fileStreams ) ) oldFileName = sitr->first;
1513 
1514 #ifndef NDEBUG
1515  if ( msgLevel( MSG::DEBUG ) ) {
1516  debug() << "migrating uid: " << hid.id << " stream: " << streamName << " oldFile: " << oldFileName
1517  << " newFile: " << newFileName << endmsg;
1518  }
1519 #endif
1520 
1521  if ( !oldFileName.empty() ) {
1522  auto i = m_fileStreams.lower_bound( oldFileName );
1523  while ( i != std::end( m_fileStreams ) && i->first == oldFileName ) {
1524 #ifndef NDEBUG
1525  if ( msgLevel( MSG::DEBUG ) ) {
1526  debug() << "changing filename \"" << i->first << "\" to \"" << newFileName << "\" for stream \""
1527  << i->second << "\"" << endmsg;
1528  }
1529 #endif
1530  std::string nm = std::move( i->second );
1531  i = m_fileStreams.erase( i );
1532  m_fileStreams.emplace( newFileName, std::move( nm ) );
1533  }
1534  } else {
1535  error() << "Problems updating fileStreams with new file name" << endmsg;
1536  }
1537  }
1538  }
1539  }
1540  }
1541 }
T empty(T... args)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
T end(T... args)
T lower_bound(T... args)
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
Definition: THistSvc.cpp:1834
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T erase(T... args)
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T move(T... args)
constexpr double nm
Definition: SystemOfUnits.h:91
T find_if(T... args)
T begin(T... args)
uidMap_t m_uids
Definition: THistSvc.h:299
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
T emplace(T... args)
string s
Definition: gaudirun.py:328
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
streamMap m_fileStreams
Definition: THistSvc.h:307

◆ writeObjectsToFile()

StatusCode THistSvc::writeObjectsToFile ( )
private

Definition at line 1543 of file THistSvc.cpp.

1543  {
1544  updateFiles();
1545 
1547  auto mode = i.second.second;
1548  auto file = i.second.first;
1549  if ( mode == WRITE || mode == UPDATE || mode == SHARE ) {
1550  file->Write( "", TObject::kOverwrite );
1551  } else if ( mode == APPEND ) {
1552  file->Write( "" );
1553  }
1554  } );
1555 
1556  if ( msgLevel( MSG::DEBUG ) ) {
1557  debug() << "THistSvc::writeObjectsToFile()::List of Files connected in ROOT " << endmsg;
1558  TSeqCollection* filelist = gROOT->GetListOfFiles();
1559  for ( int ii = 0; ii < filelist->GetEntries(); ii++ ) {
1560  debug() << "THistSvc::writeObjectsToFile()::List of Files connected in ROOT: \"" << filelist->At( ii )->GetName()
1561  << "\"" << endmsg;
1562  }
1563  }
1564 
1565  return StatusCode::SUCCESS;
1566 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T end(T... args)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T begin(T... args)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:305
T for_each(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
void updateFiles()
Handle case where TTree grows beyond TTree::fgMaxTreeSize.
Definition: THistSvc.cpp:1466

Member Data Documentation

◆ m_alreadyConnectedInFiles

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 281 of file THistSvc.h.

◆ m_alreadyConnectedOutFiles

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 285 of file THistSvc.h.

◆ m_autoFlush

Gaudi::Property<int> THistSvc::m_autoFlush {this, "AutoFlush", 0}
private

Definition at line 380 of file THistSvc.h.

◆ m_autoSave

Gaudi::Property<int> THistSvc::m_autoSave {this, "AutoSave", 0}
private

Definition at line 379 of file THistSvc.h.

◆ m_compressionLevel

Gaudi::Property<int> THistSvc::m_compressionLevel
private
Initial value:
{this, "CompressionLevel", 1, [this]( auto& ) {
this->warning()
<< "\"CompressionLevel\" Property has been deprecated. "
<< "Set it via the \"CL=\" parameter in the \"Output\" Property"
<< endmsg;
}}

Definition at line 385 of file THistSvc.h.

◆ m_curstream

std::string THistSvc::m_curstream
mutableprivate

Definition at line 403 of file THistSvc.h.

◆ m_delayConnect

bool THistSvc::m_delayConnect = false
private

Definition at line 400 of file THistSvc.h.

◆ m_files

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

Definition at line 305 of file THistSvc.h.

◆ m_fileStreams

streamMap THistSvc::m_fileStreams
private

Definition at line 307 of file THistSvc.h.

◆ m_hlist

hlist_t THistSvc::m_hlist
private

Definition at line 298 of file THistSvc.h.

◆ m_ids

idMap_t THistSvc::m_ids
private

Definition at line 300 of file THistSvc.h.

◆ m_inputfile

Gaudi::Property<std::vector<std::string> > THistSvc::m_inputfile {this, "Input", {}, &THistSvc::setupInputFile}
private

Definition at line 392 of file THistSvc.h.

◆ m_maxFileSize

Gaudi::Property<int> THistSvc::m_maxFileSize
private
Initial value:
{this, "MaxFileSize", 10240,
"maximum file size in MB. if exceeded,"
" will cause an abort. -1 to never check."}

Definition at line 382 of file THistSvc.h.

◆ m_okToConnect

bool THistSvc::m_okToConnect = false
private

Definition at line 401 of file THistSvc.h.

◆ m_outputfile

Gaudi::Property<std::vector<std::string> > THistSvc::m_outputfile {this, "Output", {}, &THistSvc::setupOutputFile}
private

Definition at line 391 of file THistSvc.h.

◆ m_print

Gaudi::Property<bool> THistSvc::m_print {this, "PrintAll", false}
private

Definition at line 381 of file THistSvc.h.

◆ m_Rstream

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

Definition at line 277 of file THistSvc.h.

◆ m_sharedFiles

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

Definition at line 310 of file THistSvc.h.

◆ m_signaledStop

bool THistSvc::m_signaledStop = false
private

Definition at line 399 of file THistSvc.h.

◆ m_svcMut

THistSvcMutex_t THistSvc::m_svcMut
mutableprivate

Definition at line 405 of file THistSvc.h.

◆ m_tobjs

objMap_t THistSvc::m_tobjs
private

Definition at line 303 of file THistSvc.h.

◆ m_uids

uidMap_t THistSvc::m_uids
private

Definition at line 299 of file THistSvc.h.

◆ m_Wstream

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

Definition at line 277 of file THistSvc.h.

◆ p_fileMgr

IFileMgr* THistSvc::p_fileMgr = nullptr
private

Definition at line 397 of file THistSvc.h.

◆ p_incSvc

IIncidentSvc* THistSvc::p_incSvc = nullptr
private

Definition at line 396 of file THistSvc.h.


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