The Gaudi Framework  v30r3 (a5ef0a68)
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

 THistSvc (const std::string &name, ISvcLocator *svc)
 
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...
 
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 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...
 
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. 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
 
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
 
- 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 (Gaudi::Details::PropertyBase &inputfile)
 call-back method to handle input stream property More...
 
void setupOutputFile (Gaudi::Details::PropertyBase &outputfile)
 call-back method to handle output stream property More...
 
void setupCompressionLevel (Gaudi::Details::PropertyBase &cmp)
 
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)
 

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 {this, "CompressionLevel", 1}
 
Gaudi::Property< std::vector< std::string > > m_outputfile {this, "Output", {}}
 
Gaudi::Property< std::vector< std::string > > m_inputfile {this, "Input", {}}
 

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, "[[deprecated]] 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 29 of file THistSvc.h.

Member Typedef Documentation

Definition at line 166 of file THistSvc.h.

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

Definition at line 241 of file THistSvc.h.

Definition at line 245 of file THistSvc.h.

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

Definition at line 246 of file THistSvc.h.

Definition at line 256 of file THistSvc.h.

Definition at line 165 of file THistSvc.h.

Definition at line 243 of file THistSvc.h.

Definition at line 239 of file THistSvc.h.

Member Enumeration Documentation

enum THistSvc::Mode
private

Enumerating all possible file access modes.

Enumerator
READ 
WRITE 
UPDATE 
APPEND 
SHARE 
INVALID 

Definition at line 183 of file THistSvc.h.

Constructor & Destructor Documentation

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

Definition at line 58 of file THistSvc.cpp.

58  : base_class( name, svc )
59 {
60  m_compressionLevel.declareUpdateHandler( &THistSvc::setupCompressionLevel, this );
61  m_outputfile.declareUpdateHandler( &THistSvc::setupOutputFile, this );
62  m_inputfile.declareUpdateHandler( &THistSvc::setupInputFile, this );
63 }
void setupCompressionLevel(Gaudi::Details::PropertyBase &cmp)
Definition: THistSvc.cpp:1802
Gaudi::Property< std::vector< std::string > > m_outputfile
Definition: THistSvc.h:337
Gaudi::Property< std::vector< std::string > > m_inputfile
Definition: THistSvc.h:338
Gaudi::Property< int > m_compressionLevel
Definition: THistSvc.h:336
void setupInputFile(Gaudi::Details::PropertyBase &inputfile)
call-back method to handle input stream property
Definition: THistSvc.cpp:1746
void setupOutputFile(Gaudi::Details::PropertyBase &outputfile)
call-back method to handle output stream property
Definition: THistSvc.cpp:1776

Member Function Documentation

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

Definition at line 1585 of file THistSvc.cpp.

1586 {
1587  std::string uid = hid.id;
1588  TFile* file = hid.file;
1589  std::string stream, fdir, bdir, dir, id;
1590 
1591  if ( file ) {
1592  file->cd( "/" );
1593  } else {
1594  gROOT->cd();
1595  }
1596 
1597  fdir = uid;
1598  bdir = stripDirectoryName( fdir );
1599 
1600  while ( ( dir = stripDirectoryName( fdir ) ) != "" ) {
1601  if ( !gDirectory->GetKey( dir.c_str() ) ) {
1602  gDirectory->mkdir( dir.c_str() );
1603  }
1604  gDirectory->cd( dir.c_str() );
1605  }
1606 
1607  return gDirectory;
1608 }
STL class.
std::string id
Definition: THistSvc.h:187
std::string stripDirectoryName(std::string &dir) const
Definition: THistSvc.cpp:1610
T c_str(T...args)
StatusCode THistSvc::connect ( const std::string ident)
private

Definition at line 1396 of file THistSvc.cpp.

1397 {
1398  auto loc = ident.find( " " );
1399  std::string stream = ident.substr( 0, loc );
1400  char typ( 0 );
1402  std::vector<Prop> props;
1403  std::string filename, db_typ( "ROOT" );
1404  int cl( 1 );
1405 
1406  if ( loc != std::string::npos ) {
1407  using Parser = Gaudi::Utils::AttribStringParser;
1408  for ( auto attrib : Parser( ident.substr( loc + 1 ) ) ) {
1409  auto TAG = boost::algorithm::to_upper_copy( attrib.tag );
1410  auto VAL = boost::algorithm::to_upper_copy( attrib.value );
1411 
1412  if ( TAG == "FILE" || TAG == "DATAFILE" ) {
1413  filename = attrib.value;
1414  removeDoubleSlash( filename );
1415  } else if ( TAG == "OPT" ) {
1416  if ( VAL == "APPEND" || VAL == "UPDATE" ) {
1417  typ = 'A';
1418  } else if ( VAL == "CREATE" || VAL == "NEW" || VAL == "WRITE" ) {
1419  typ = 'N';
1420  } else if ( VAL == "RECREATE" ) {
1421  typ = 'R';
1422  } else if ( VAL == "SHARE" ) {
1423  typ = 'S';
1424  } else if ( VAL == "OLD" || VAL == "READ" ) {
1425  typ = 'O';
1426  } else {
1427  error() << "Unknown OPT: \"" << attrib.value << "\"" << endmsg;
1428  typ = 0;
1429  }
1430  } else if ( TAG == "TYP" ) {
1431  db_typ = std::move( attrib.value );
1432  } else if ( TAG == "CL" ) {
1433  cl = std::stoi( attrib.value );
1434  } else {
1435  props.emplace_back( attrib.tag, attrib.value );
1436  }
1437  }
1438  }
1439 
1440  if ( stream == "temp" ) {
1441  error() << "in JobOption \"" << ident << "\": stream name \"temp\" reserved." << endmsg;
1442  return StatusCode::FAILURE;
1443  }
1444 
1445  if ( db_typ != "ROOT" ) {
1446  error() << "in JobOption \"" << ident << "\": technology type \"" << db_typ << "\" not supported." << endmsg;
1447  return StatusCode::FAILURE;
1448  }
1449 
1450  if ( m_files.find( stream ) != m_files.end() ) {
1451  error() << "in JobOption \"" << ident << "\":\n stream \"" << stream << "\" already connected to file: \""
1452  << m_files[stream].first->GetName() << "\"" << endmsg;
1453  return StatusCode::FAILURE;
1454  }
1455 
1456  Mode newMode;
1457  if ( typ == 'O' ) {
1458  newMode = THistSvc::READ;
1459  } else if ( typ == 'N' ) {
1460  newMode = THistSvc::WRITE;
1461  } else if ( typ == 'A' ) {
1462  newMode = THistSvc::APPEND;
1463  } else if ( typ == 'R' ) {
1464  newMode = THistSvc::UPDATE;
1465  } else if ( typ == 'S' ) {
1466  newMode = THistSvc::SHARE;
1467  } else {
1468  // something else?
1469  error() << "No OPT= specified or unknown access mode in: " << ident << endmsg;
1470  return StatusCode::FAILURE;
1471  }
1472 
1473  // Is this file already connected to another stream?
1474  if ( m_fileStreams.find( filename ) != m_fileStreams.end() ) {
1475  auto fitr = m_fileStreams.equal_range( filename );
1476 
1477  const std::string& oldstream = fitr.first->second;
1478 
1479  const auto& f_info = m_files[oldstream];
1480 
1481  if ( newMode != f_info.second ) {
1482  error() << "in JobOption \"" << ident << "\":\n file \"" << filename << "\" already opened by stream: \""
1483  << oldstream << "\" with different access mode." << endmsg;
1484  return StatusCode::FAILURE;
1485  } else {
1486  TFile* f2 = f_info.first;
1487  m_files[stream] = std::make_pair( f2, newMode );
1488  if ( msgLevel( MSG::DEBUG ) )
1489  debug() << "Connecting stream: \"" << stream << "\" to previously opened TFile: \"" << filename << "\""
1490  << endmsg;
1491  return StatusCode::SUCCESS;
1492  }
1493  }
1494 
1495  IIncidentSvc* pi = nullptr;
1496  if ( service( "IncidentSvc", pi ).isFailure() ) {
1497  error() << "Unable to get the IncidentSvc" << endmsg;
1498  return StatusCode::FAILURE;
1499  }
1500 
1501  void* vf = nullptr;
1502  TFile* f = nullptr;
1503 
1504  if ( newMode == THistSvc::READ ) {
1505  // old file
1506  int r = p_fileMgr->open( Io::ROOT, name(), filename, Io::READ, vf, "HIST" );
1507 
1508  if ( r != 0 ) {
1509  error() << "Unable to open ROOT file " << filename << " for reading" << endmsg;
1510  return StatusCode::FAILURE;
1511  }
1512 
1513  f = (TFile*)vf;
1514 
1515  // FIX ME!
1516  pi->fireIncident( FileIncident( name(), "BeginHistFile", filename ) );
1517 
1518  } else if ( newMode == THistSvc::WRITE ) {
1519  // new file. error if file exists
1520  int r = p_fileMgr->open( Io::ROOT, name(), filename, ( Io::WRITE | Io::CREATE | Io::EXCL ), vf, "HIST" );
1521 
1522  if ( r != 0 ) {
1523  error() << "Unable to open ROOT file " << filename << " for writing" << endmsg;
1524  return StatusCode::FAILURE;
1525  }
1526 
1527  f = (TFile*)vf;
1528 
1529  } else if ( newMode == THistSvc::APPEND ) {
1530  // update file
1531  int r = p_fileMgr->open( Io::ROOT, name(), filename, ( Io::WRITE | Io::APPEND ), vf, "HIST" );
1532  if ( r != 0 ) {
1533  error() << "unable to open file \"" << filename << "\" for appending" << endmsg;
1534  return StatusCode::FAILURE;
1535  }
1536 
1537  f = (TFile*)vf;
1538 
1539  } else if ( newMode == THistSvc::SHARE ) {
1540  // SHARE file type
1541  // For SHARE files, all data will be stored in a temp file and will be
1542  // merged into the target file in writeObjectsToFile() when finalize(),
1543  // this help to solve some confliction. e.g. with storegate
1544  static int ishared = 0;
1545  std::string realfilename = filename;
1546  filename = "tmp_THistSvc_" + std::to_string( ishared++ ) + ".root";
1547 
1548  if ( msgLevel( MSG::DEBUG ) ) {
1549  debug() << "Creating temp file \"" << filename << "\" and realfilename=" << realfilename << endmsg;
1550  }
1551  m_sharedFiles[stream] = realfilename;
1552 
1553  int r = p_fileMgr->open( Io::ROOT, name(), filename, ( Io::WRITE | Io::CREATE | Io::EXCL ), vf, "HIST" );
1554 
1555  if ( r != 0 ) {
1556  error() << "Unable to open ROOT file " << filename << " for writing" << endmsg;
1557  return StatusCode::FAILURE;
1558  }
1559 
1560  f = (TFile*)vf;
1561 
1562  } else if ( newMode == THistSvc::UPDATE ) {
1563  // update file
1564  int r = p_fileMgr->open( Io::ROOT, name(), filename, ( Io::WRITE | Io::CREATE ), vf, "HIST" );
1565 
1566  if ( r != 0 ) {
1567  error() << "Unable to open ROOT file " << filename << " for appending" << endmsg;
1568  return StatusCode::FAILURE;
1569  }
1570 
1571  f = (TFile*)vf;
1572  }
1573 
1574  m_files[stream] = std::make_pair( f, newMode );
1575  m_fileStreams.insert( std::make_pair( filename, stream ) );
1576 
1577  if ( msgLevel( MSG::DEBUG ) ) {
1578  debug() << "Opening TFile \"" << filename << "\" stream: \"" << stream << "\" mode: \"" << typ << "\""
1579  << " comp level: " << cl << endmsg;
1580  }
1581 
1582  return StatusCode::SUCCESS;
1583 }
Parse attribute strings allowing iteration over the various attributes.
constexpr static const auto FAILURE
Definition: StatusCode.h:88
This class is the FileIncident.
Definition: FileIncident.h:17
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
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
T to_string(T...args)
T end(T...args)
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
T make_pair(T...args)
T move(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
Mode
Enumerating all possible file access modes.
Definition: THistSvc.h:183
T insert(T...args)
T find(T...args)
STL class.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:255
IFileMgr * p_fileMgr
Definition: THistSvc.h:343
T substr(T...args)
std::map< std::string, std::string > m_sharedFiles
Definition: THistSvc.h:260
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn&#39;t already exist.
Definition: Service.h:84
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:209
constexpr double pi
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
streamMap m_fileStreams
Definition: THistSvc.h:257
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1627
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
T emplace_back(T...args)
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 1809 of file THistSvc.cpp.

1810 {
1811  if ( msgLevel( MSG::DEBUG ) ) {
1812  debug() << "copyFileLayout() to destination path: " << destination->GetPath() << endmsg;
1813  }
1814 
1815  // strip out URLs
1816  TString path( (char*)strstr( destination->GetPath(), ":" ) );
1817  path.Remove( 0, 2 );
1818 
1819  source->cd( path );
1820  TDirectory* current_source_dir = gDirectory;
1821 
1822  // loop over all keys in this directory
1823  TList* key_list = current_source_dir->GetListOfKeys();
1824  int n = key_list->GetEntries();
1825  for ( int j = 0; j < n; ++j ) {
1826  TKey* k = (TKey*)key_list->At( j );
1827  const std::string source_pathname = current_source_dir->GetPath() + std::string( "/" ) + k->GetName();
1828  TObject* o = source->Get( source_pathname.c_str() );
1829 
1830  if ( o && o->IsA()->InheritsFrom( "TDirectory" ) ) {
1831  if ( msgLevel( MSG::VERBOSE ) ) {
1832  verbose() << " subdir [" << o->GetName() << "]..." << endmsg;
1833  }
1834  destination->cd();
1835  TDirectory* destination_dir = destination->mkdir( o->GetName(), o->GetTitle() );
1836  copyFileLayout( destination_dir, source );
1837  }
1838  } // loop over keys
1839  return;
1840 }
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
void copyFileLayout(TDirectory *, TDirectory *)
helper function to recursively copy the layout of a TFile into a new TFile
Definition: THistSvc.cpp:1809
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:209
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
StatusCode THistSvc::deReg ( const std::string name)
override

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

Definition at line 572 of file THistSvc.cpp.

573 {
574  auto itr = m_uids.find( id );
575  if ( itr == m_uids.end() ) {
576  error() << "Problem deregistering id \"" << id << "\": not found in registry" << endmsg;
577  return StatusCode::FAILURE;
578  }
579 
580  vhid_t* vh = itr->second;
581  debug() << "will deregister " << vh->size() << " elements of id \"" << id << "\"" << endmsg;
583  while ( vh->size() > 0 ) {
584  if ( deReg( vh->back().obj ).isFailure() ) {
585  sc = StatusCode::FAILURE;
586  error() << "Problems deRegistering " << vh->size() << " element of id \"" << id << "\"" << endmsg;
587  break;
588  }
589  }
590 
591  return sc;
592 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
StatusCode deReg(const std::string &name) override
Deregister object with given name and give up ownership (without deletion!)
Definition: THistSvc.cpp:572
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
std::vector< THistID > vhid_t
Definition: THistSvc.h:239
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
uidMap_t m_uids
Definition: THistSvc.h:249
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode THistSvc::deReg ( TObject *  obj)
override

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

Definition at line 594 of file THistSvc.cpp.

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

Definition at line 1888 of file THistSvc.cpp.

1889 {
1890  std::ostringstream ost;
1891 
1892  // list< vector<THistID> >
1893  ost << "m_hlist: size: " << m_hlist.size() << "\n";
1894  for ( auto& vh : m_hlist ) {
1895  ost << " - " << vh->at( 0 ) << " :: [" << vh << "] " << vh->size() << " {";
1896  for ( auto& e : *vh ) {
1897  TObject* o = e.obj;
1898  ost << "[" << o << "]";
1899  }
1900  ost << "}\n";
1901  }
1902 
1903  // map uid -> vector<THistID>*
1904  ost << "\n"
1905  << "m_uids: " << m_uids.size() << "\n";
1906  for ( auto& e : m_uids ) {
1907  ost << " - " << e.first << " [" << e.second << "]" << std::endl;
1908  }
1909 
1910  // multimap id -> vector<THistID>*
1911  ost << "\n"
1912  << "m_ids: " << m_ids.size() << "\n";
1913  for ( auto& e : m_ids ) {
1914  ost << " - " << e.first << " [" << e.second << "]" << std::endl;
1915  }
1916 
1917  // map TObject* -> THistID*
1918  ost << "\n"
1919  << "m_tobjs: " << m_tobjs.size() << "\n";
1920  for ( auto& e : m_tobjs ) {
1921  TObject* o = e.first;
1922  THistID& i = e.second.first->at( e.second.second );
1923  ost << " - " << o << " -> " << i << std::endl;
1924  }
1925 
1926  debug() << "dumping THistSvc contents\n" << ost.str() << endmsg;
1927 }
T endl(T...args)
objMap_t m_tobjs
Definition: THistSvc.h:253
hlist_t m_hlist
Definition: THistSvc.h:248
idMap_t m_ids
Definition: THistSvc.h:250
T size(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
uidMap_t m_uids
Definition: THistSvc.h:249
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
bool THistSvc::exists ( const std::string name) const
override

Check if object with given name is managed by THistSvcMT.

Definition at line 677 of file THistSvc.cpp.

677 { return ( getHist_i<TH1>( name, 0, true ) != nullptr ); }
StatusCode THistSvc::finalize ( )
override

Definition at line 187 of file THistSvc.cpp.

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

Definition at line 1842 of file THistSvc.cpp.

1843 {
1844  GlobalDirectoryRestore restore( m_svcMut );
1845 
1846  std::string idr( id );
1847  removeDoubleSlash( idr );
1848 
1849  hid = 0;
1850 
1851  if ( idr.find( "/" ) == 0 ) {
1852  // fully specified name, starts with "/"
1853  auto itr = m_uids.find( idr );
1854  if ( itr == m_uids.end() ) {
1855  // no matches found
1856  return 0;
1857  } else {
1858  // one or more matches found (clones).
1859  if ( index >= itr->second->size() ) {
1860  error() << "no index " << index << " found for Hist " << idr << endmsg;
1861  return 0;
1862  }
1863  hid = &( itr->second->at( index ) );
1864  return 1;
1865  }
1866  } else {
1867  // name not fully specified.
1868  auto mitr = m_ids.equal_range( idr );
1869  if ( mitr.first == mitr.second ) {
1870  // not found
1871  return 0;
1872  } else if ( distance( mitr.first, mitr.second ) == 1 ) {
1873  // one found
1874  if ( index >= mitr.first->second->size() ) {
1875  error() << "no index " << index << " found for Hist " << idr << endmsg;
1876  return 0;
1877  }
1878  hid = &( mitr.first->second->at( 0 ) );
1879  return 1;
1880  } else {
1881  // multiple matches
1882  hid = &( mitr.first->second->at( 0 ) );
1883  return distance( mitr.first, mitr.second );
1884  }
1885  }
1886 }
T distance(T...args)
STL class.
idMap_t m_ids
Definition: THistSvc.h:250
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T find(T...args)
uidMap_t m_uids
Definition: THistSvc.h:249
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:351
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1627
bool THistSvc::findStream ( const std::string name,
std::string root,
std::string rem,
TFile *&  file 
) const
private

Definition at line 1692 of file THistSvc.cpp.

1693 {
1694  auto pos = id.find( "/" );
1695 
1696  if ( pos == std::string::npos ) {
1697  // no "/" in id
1698  stream = "temp";
1699  rem = id;
1700  } else if ( pos != 0 ) {
1701  // id does not start with "/"
1702  stream = "temp";
1703  rem = id;
1704  } else {
1705  // id starts with "/"
1706 
1707  auto pos2 = id.find( "/", pos + 1 );
1708 
1709  if ( pos2 == std::string::npos ) {
1710  // need at least 2 "/" in format "/STREAM/name" or "/STREAM/dir/name"
1711  error() << "badly formed Hist/Tree id: \"" << id << "\"" << endmsg;
1712  return false;
1713  }
1714  parseString( id, stream, rem );
1715  }
1716 
1717  if ( stream == "temp" ) {
1718  file = nullptr;
1719  return true;
1720  }
1721 
1722  auto itr = m_files.find( stream );
1723  file = ( itr != m_files.end() ? itr->second.first : nullptr );
1724  if ( !file ) {
1725  warning() << "no stream \"" << stream << "\" associated with id: \"" << id << "\"" << endmsg;
1726  }
1727 
1728  return true;
1729 }
T end(T...args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1731
T find(T...args)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:255
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode THistSvc::getGraph ( const std::string name,
TGraph *&  graph 
) const
override

Return TGraph with given name.

Definition at line 482 of file THistSvc.cpp.

483 {
484  graph = getHist_i<TGraph>( id );
485  if ( graph != nullptr ) {
486  return StatusCode::SUCCESS;
487  } else {
488  return StatusCode::FAILURE;
489  }
490 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
std::vector< std::string > THistSvc::getGraphs ( ) const
override

Definition at line 697 of file THistSvc.cpp.

698 {
700  names.reserve( m_uids.size() );
701  transform_if( std::begin( m_uids ), std::end( m_uids ), std::back_inserter( names ), select1st,
702  []( uidMap_t::const_reference i ) { return i.second->at( 0 ).obj->IsA()->InheritsFrom( "TGraph" ); } );
703  return names;
704 }
T end(T...args)
T size(T...args)
T begin(T...args)
T back_inserter(T...args)
uidMap_t m_uids
Definition: THistSvc.h:249
T reserve(T...args)
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 370 of file THistSvc.cpp.

371 {
372  hist = getHist_i<TH1>( id, ind );
373  if ( hist != nullptr ) {
374  return StatusCode::SUCCESS;
375  } else {
376  return StatusCode::FAILURE;
377  }
378 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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 380 of file THistSvc.cpp.

381 {
382  hist = getHist_i<TH2>( id, ind );
383  if ( hist != nullptr ) {
384  return StatusCode::SUCCESS;
385  } else {
386  return StatusCode::FAILURE;
387  }
388 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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 390 of file THistSvc.cpp.

391 {
392  hist = getHist_i<TH3>( id, ind );
393  if ( hist != nullptr ) {
394  return StatusCode::SUCCESS;
395  } else {
396  return StatusCode::FAILURE;
397  }
398 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
template<typename T >
T * THistSvc::getHist_i ( const std::string name,
const size_t &  ind = 0,
bool  quiet = false 
) const
private

Definition at line 172 of file THistSvc.icc.

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

Definition at line 679 of file THistSvc.cpp.

680 {
682  names.reserve( m_uids.size() );
683  transform_if( std::begin( m_uids ), std::end( m_uids ), std::back_inserter( names ), select1st,
684  []( uidMap_t::const_reference i ) { return i.second->at( 0 ).obj->IsA()->InheritsFrom( "TH1" ); } );
685  return names;
686 }
T end(T...args)
T size(T...args)
T begin(T...args)
T back_inserter(T...args)
uidMap_t m_uids
Definition: THistSvc.h:249
T reserve(T...args)
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 532 of file THistSvc.cpp.

533 {
534  lh = getShared_i<TH1>( name );
535  if ( lh ) {
536  return StatusCode::SUCCESS;
537  } else {
538  return StatusCode::FAILURE;
539  }
540 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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 542 of file THistSvc.cpp.

543 {
544  lh = getShared_i<TH2>( name );
545  if ( lh ) {
546  return StatusCode::SUCCESS;
547  } else {
548  return StatusCode::FAILURE;
549  }
550 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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 552 of file THistSvc.cpp.

553 {
554  lh = getShared_i<TH3>( name );
555  if ( lh ) {
556  return StatusCode::SUCCESS;
557  } else {
558  return StatusCode::FAILURE;
559  }
560 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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 562 of file THistSvc.cpp.

563 {
564  lh = getShared_i<TGraph>( name );
565  if ( lh ) {
566  return StatusCode::SUCCESS;
567  } else {
568  return StatusCode::FAILURE;
569  }
570 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
template<typename T >
LockedHandle< T > THistSvc::getShared_i ( const std::string name) const
private

Definition at line 307 of file THistSvc.icc.

308 {
309  GlobalDirectoryRestore restore( m_svcMut );
310 
311  const THistID* hid = nullptr;
312  size_t i = findHistID( name, hid );
313 
314  LockedHandle<T> hist( nullptr, nullptr );
315 
316  if ( i == 1 ) {
317  if ( !hid->shared ) {
318  error() << "getSharedHist: found Hist with id \"" << name << "\", but it's not marked as shared" << endmsg;
319  return hist;
320  }
321  T* h1 = dynamic_cast<T*>( hid->obj );
322  hist = LockedHandle<T>( h1, hid->mutex );
323 
324  debug() << "getSharedHist: found THistID: " << *hid << endmsg;
325  } else if ( i == 0 ) {
326  error() << "no histograms matching id \"" << name << "\" found" << endmsg;
327  } else {
328  info() << "multiple matches for id \"" << name << "\" found [" << i << "], probably from different streams"
329  << endmsg;
330  }
331  return hist;
332 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
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:28
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
size_t findHistID(const std::string &id, const THistID *&hid, const size_t &index=0) const
Definition: THistSvc.cpp:1842
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:351
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode THistSvc::getTHists ( TDirectory *  td,
TList &  tl,
bool  recurse = false 
) const
override

Definition at line 706 of file THistSvc.cpp.

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

Definition at line 752 of file THistSvc.cpp.

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

Definition at line 802 of file THistSvc.cpp.

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

Definition at line 865 of file THistSvc.cpp.

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

Return TTree with given name.

Definition at line 433 of file THistSvc.cpp.

434 {
435  tree = getHist_i<TTree>( id );
436  if ( tree != nullptr ) {
437  return StatusCode::SUCCESS;
438  } else {
439  return StatusCode::FAILURE;
440  }
441 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
std::vector< std::string > THistSvc::getTrees ( ) const
override

Definition at line 688 of file THistSvc.cpp.

689 {
691  names.reserve( m_uids.size() );
692  transform_if( std::begin( m_uids ), std::end( m_uids ), std::back_inserter( names ), select1st,
693  []( uidMap_t::const_reference i ) { return i.second->at( 0 ).obj->IsA()->InheritsFrom( "TTree" ); } );
694  return names;
695 }
T end(T...args)
T size(T...args)
T begin(T...args)
T back_inserter(T...args)
uidMap_t m_uids
Definition: THistSvc.h:249
T reserve(T...args)
StatusCode THistSvc::getTTrees ( TDirectory *  td,
TList &  tl,
bool  recurse = false 
) const
override

Definition at line 917 of file THistSvc.cpp.

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

Definition at line 963 of file THistSvc.cpp.

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

Definition at line 1006 of file THistSvc.cpp.

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

Definition at line 1069 of file THistSvc.cpp.

1070 {
1071  GlobalDirectoryRestore restore( m_svcMut );
1072 
1073  gErrorIgnoreLevel = kBreak;
1074 
1075  StatusCode sc;
1076 
1077  std::string stream, rem, r2;
1078  parseString( dir, stream, rem );
1079 
1080  auto itr = m_files.find( stream );
1081  if ( itr != m_files.end() ) {
1082  r2 = itr->second.first->GetName();
1083  r2 += ":/";
1084  r2 += rem;
1085 
1086  if ( msgLevel( MSG::DEBUG ) ) {
1087  debug() << "getTTrees: \"" << dir << "\" looks like a stream name."
1088  << " associated TFile: \"" << itr->second.first->GetName() << "\"" << endmsg;
1089  }
1090 
1091  if ( gDirectory->cd( r2.c_str() ) ) {
1092  return getTTrees( gDirectory, tl, rcs, reg );
1093  } else {
1094  if ( msgLevel( MSG::DEBUG ) ) {
1095  debug() << "getTTrees: no such TDirectory \"" << r2 << "\"" << endmsg;
1096  }
1097  }
1098  } else {
1099  if ( msgLevel( MSG::DEBUG ) ) {
1100  debug() << "getTTrees: stream \"" << stream << "\" not found" << endmsg;
1101  }
1102  }
1103 
1104  if ( !gDirectory->cd( dir.c_str() ) ) {
1105  error() << "getTTrees: No such TDirectory/stream \"" << dir << "\"" << endmsg;
1106  return StatusCode::FAILURE;
1107  }
1108 
1109  return getTTrees( gDirectory, tl, rcs, reg );
1110 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
T end(T...args)
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1731
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:917
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T c_str(T...args)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:255
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:351
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
void THistSvc::handle ( const Incident )
override

Definition at line 1114 of file THistSvc.cpp.

1115 {
1116  if ( m_signaledStop ) return;
1117 
1118  if ( m_maxFileSize.value() == -1 ) return;
1119 
1120  // convert to bytes.
1121  Long64_t mfs = (Long64_t)m_maxFileSize.value() * (Long64_t)1048576;
1122  Long64_t mfs_warn = mfs * 95 / 100;
1123 
1124  updateFiles();
1125 
1126  std::map<std::string, std::pair<TFile*, Mode>>::const_iterator itr;
1127  for ( const auto& f : m_files ) {
1128  TFile* tf = f.second.first;
1129 
1130 #ifndef NDEBUG
1131  if ( msgLevel( MSG::DEBUG ) ) {
1132  debug() << "stream: " << f.first << " name: " << tf->GetName() << " size: " << tf->GetSize() << endmsg;
1133  }
1134 #endif
1135 
1136  // Signal job to terminate if output file is too large
1137  if ( tf->GetSize() > mfs ) {
1138 
1139  m_signaledStop = true;
1140 
1141  fatal() << "file \"" << tf->GetName() << "\" associated with stream \"" << f.first
1142  << "\" has exceeded the max file size of " << m_maxFileSize.value() << "MB. Terminating Job." << endmsg;
1143 
1144  IEventProcessor* evt = nullptr;
1145  if ( service( "ApplicationMgr", evt, true ).isSuccess() ) {
1146  evt->stopRun();
1147  evt->release();
1148  } else {
1149  abort();
1150  }
1151  } else if ( tf->GetSize() > mfs_warn ) {
1152  warning() << "file \"" << tf->GetName() << "\" associated with stream \"" << f.first
1153  << "\" is at 95% of its maximum allowable file size of " << m_maxFileSize.value() << "MB" << endmsg;
1154  }
1155  }
1156 }
virtual StatusCode stopRun()=0
Schedule a stop of the current event processing.
bool m_signaledStop
Definition: THistSvc.h:345
STL class.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Gaudi::Property< int > m_maxFileSize
Definition: THistSvc.h:334
virtual unsigned long release()=0
Release Interface instance.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:255
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&#39;t already exist.
Definition: Service.h:84
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:209
evt
Definition: IOTest.py:96
void updateFiles()
Handle case where TTree grows beyond TTree::fgMaxTreeSize.
Definition: THistSvc.cpp:1288
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
StatusCode THistSvc::initialize ( )
override

Definition at line 65 of file THistSvc.cpp.

66 {
68 
70 
71  if ( status.isFailure() ) {
72  error() << "initializing service" << endmsg;
73  return status;
74  }
75 
77 
78  try {
80  } catch ( GaudiException& err ) {
81  error() << "Caught: " << err << endmsg;
83  }
84 
85  try {
87  } catch ( GaudiException& err ) {
88  error() << "Caught: " << err << endmsg;
90  }
91 
92  // Protect against multiple instances of TROOT
93  if ( !gROOT ) {
94  static TROOT root( "root", "ROOT I/O" );
95  // gDebug = 99;
96  } else {
97  if ( msgLevel( MSG::VERBOSE ) ) {
98  verbose() << "ROOT already initialized, debug = " << gDebug << endmsg;
99  }
100  }
101 
102  if ( service( "IncidentSvc", p_incSvc, true ).isFailure() ) {
103  error() << "unable to get the IncidentSvc" << endmsg;
104  st = StatusCode::FAILURE;
105  } else {
106  p_incSvc->addListener( this, "EndEvent", 100, true );
107  }
108 
109  if ( service( "FileMgr", p_fileMgr, true ).isFailure() ) {
110  error() << "unable to get the FileMgr" << endmsg;
111  st = StatusCode::FAILURE;
112  } else {
113  debug() << "got the FileMgr" << endmsg;
114  }
115 
116  // Register open/close callback actions
117  using namespace std::placeholders;
118  auto boa = [this]( const Io::FileAttr* fa, const std::string& caller ) { return this->rootOpenAction( fa, caller ); };
119  if ( p_fileMgr->regAction( boa, Io::OPEN, Io::ROOT ).isFailure() ) {
120  error() << "unable to register ROOT file open action with FileMgr" << endmsg;
121  }
122  auto bea = [this]( const Io::FileAttr* fa, const std::string& caller ) {
123  return this->rootOpenErrAction( fa, caller );
124  };
125  if ( p_fileMgr->regAction( bea, Io::OPEN_ERR, Io::ROOT ).isFailure() ) {
126  error() << "unable to register ROOT file open Error action with FileMgr" << endmsg;
127  }
128 
129  m_okToConnect = true;
130  if ( m_delayConnect ) {
131  if ( !m_inputfile.value().empty() ) {
133  }
134  if ( !m_outputfile.value().empty() ) {
136  }
137 
138  m_delayConnect = false;
139  }
142 
143  IIoComponentMgr* iomgr = nullptr;
144  if ( service( "IoComponentMgr", iomgr, true ).isFailure() ) {
145  error() << "unable to get the IoComponentMgr" << endmsg;
146  st = StatusCode::FAILURE;
147  } else {
148  if ( !iomgr->io_register( this ).isSuccess() ) {
149  error() << "could not register with the I/O component manager !" << endmsg;
150  st = StatusCode::FAILURE;
151  } else {
152  bool all_good = true;
153  // register input/output files...
154  for ( const auto& reg : m_files ) {
155  const std::string& fname = reg.second.first->GetName();
156  const IIoComponentMgr::IoMode::Type iomode =
158  if ( !iomgr->io_register( this, iomode, fname ).isSuccess() ) {
159  warning() << "could not register file [" << fname << "] with the I/O component manager..." << endmsg;
160  all_good = false;
161  } else {
162  info() << "registered file [" << fname << "]... [ok]" << endmsg;
163  }
164  }
165  if ( !all_good ) {
166  error() << "problem while registering input/output files with "
167  << "the I/O component manager !" << endmsg;
168  st = StatusCode::FAILURE;
169  }
170  }
171  }
172 
173  if ( st.isFailure() ) {
174  fatal() << "Unable to initialize THistSvc" << endmsg;
175  }
176 
177  return st;
178 }
bool m_delayConnect
Definition: THistSvc.h:346
constexpr static const auto FAILURE
Definition: StatusCode.h:88
StatusCode initialize() override
Definition: Service.cpp:63
Define general base for Gaudi exception.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
IIncidentSvc * p_incSvc
Definition: THistSvc.h:342
bool isSuccess() const
Definition: StatusCode.h:287
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
StatusCode rootOpenAction(FILEMGR_CALLBACK_ARGS)
Definition: THistSvc.cpp:1974
bool isFailure() const
Definition: StatusCode.h:139
Gaudi::Property< std::vector< std::string > > m_outputfile
Definition: THistSvc.h:337
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
STL class.
virtual StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &d="")=0
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Gaudi::Property< std::vector< std::string > > m_inputfile
Definition: THistSvc.h:338
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
bool m_okToConnect
Definition: THistSvc.h:347
StatusCode rootOpenErrAction(FILEMGR_CALLBACK_ARGS)
Definition: THistSvc.cpp:1999
T clear(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
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:255
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:343
std::set< std::string > m_alreadyConnectedOutFiles
list of already connected files.
Definition: THistSvc.h:235
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn&#39;t already exist.
Definition: Service.h:84
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
Definition: THistSvc.h:231
void setupInputFile(Gaudi::Details::PropertyBase &inputfile)
call-back method to handle input stream property
Definition: THistSvc.cpp:1746
void setupOutputFile(Gaudi::Details::PropertyBase &outputfile)
call-back method to handle output stream property
Definition: THistSvc.cpp:1776
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:351
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
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 1161 of file THistSvc.cpp.

1162 {
1163  bool all_good = true;
1164  if ( msgLevel( MSG::DEBUG ) ) {
1165  debug() << "reinitializing I/O..." << endmsg;
1166  }
1167 
1168  // retrieve the I/O component manager...
1169 
1170  IIoComponentMgr* iomgr = nullptr;
1171 
1172  if ( service( "IoComponentMgr", iomgr, true ).isFailure() ) {
1173  error() << "could not retrieve I/O component manager !" << endmsg;
1174  return StatusCode::FAILURE;
1175  }
1176 
1177  GlobalDirectoryRestore restore( m_svcMut );
1178  // to hide the expected errors upon closing the files whose
1179  // file descriptors have been swept under the rug...
1180  gErrorIgnoreLevel = kFatal;
1181 
1182  for ( auto& ifile : m_files ) {
1183  TFile* f = ifile.second.first;
1184  std::string fname = f->GetName();
1185  if ( msgLevel( MSG::DEBUG ) ) {
1186  debug() << "file [" << fname << "] mode: [" << f->GetOption() << "] r:" << f->GetFileBytesRead()
1187  << " w:" << f->GetFileBytesWritten() << " cnt:" << f->GetFileCounter() << endmsg;
1188  }
1189 
1190  if ( ifile.second.second == READ ) {
1191  if ( msgLevel( MSG::DEBUG ) ) {
1192  debug() << " TFile opened in READ mode: not reassigning names" << endmsg;
1193  }
1194  continue;
1195  }
1196 
1197  if ( !iomgr->io_retrieve( this, fname ).isSuccess() ) {
1198  error() << "could not retrieve new name for [" << fname << "] !!" << endmsg;
1199  all_good = false;
1200  continue;
1201  } else {
1202  if ( msgLevel( MSG::DEBUG ) ) {
1203  debug() << "got a new name [" << fname << "]..." << endmsg;
1204  }
1205  }
1206 
1207  void* vf = nullptr;
1208  Option_t* opts = f->GetOption();
1209  int r = p_fileMgr->open( Io::ROOT, name(), fname, Io::WRITE, vf, "HIST" );
1210  if ( r != 0 ) {
1211  error() << "unable to open file \"" << fname << "\" for writing" << endmsg;
1212  return StatusCode::FAILURE;
1213  }
1214  TFile* newfile = (TFile*)vf;
1215  newfile->SetOption( opts );
1216 
1217  if ( ifile.second.second != THistSvc::READ ) {
1218  copyFileLayout( newfile, f );
1219  ifile.second.first = newfile;
1220  }
1221 
1222  // loop over all uids and migrate them to the new file
1223  for ( auto& uid : m_uids ) {
1224  for ( auto& hid : *uid.second ) {
1225  if ( hid.file != f ) continue;
1226  TDirectory* olddir = this->changeDir( hid );
1227  hid.file = newfile;
1228  // side-effect: create needed directories...
1229  TDirectory* newdir = this->changeDir( hid );
1230  TClass* cl = hid.obj->IsA();
1231 
1232  // migrate the objects to the new file.
1233  // thanks to the object model of ROOT, it is super easy.
1234  if ( cl->InheritsFrom( "TTree" ) ) {
1235  dynamic_cast<TTree*>( hid.obj )->SetDirectory( newdir );
1236  dynamic_cast<TTree*>( hid.obj )->Reset();
1237  } else if ( cl->InheritsFrom( "TH1" ) ) {
1238  dynamic_cast<TH1*>( hid.obj )->SetDirectory( newdir );
1239  dynamic_cast<TH1*>( hid.obj )->Reset();
1240  } else if ( cl->InheritsFrom( "TGraph" ) ) {
1241  olddir->Remove( hid.obj );
1242  newdir->Append( hid.obj );
1243  } else {
1244  error() << "id: \"" << hid.id << "\" is not a inheriting from a class "
1245  << "we know how to handle (received [" << cl->GetName() << "], "
1246  << "expected [TTree, TH1 or TGraph]) !" << endmsg << "attaching to current dir [" << newdir->GetPath()
1247  << "] "
1248  << "nonetheless..." << endmsg;
1249  olddir->Remove( hid.obj );
1250  newdir->Append( hid.obj );
1251  }
1252  }
1253  }
1254  f->ReOpen( "READ" );
1255  p_fileMgr->close( f, name() );
1256  f = newfile;
1257  }
1258 
1259  return all_good ? StatusCode::SUCCESS : StatusCode::FAILURE;
1260 }
virtual StatusCode io_retrieve(IIoComponent *iocomponent, std::string &fname)=0
: retrieve the new filename for a given IIoComponent and
constexpr static const auto FAILURE
Definition: StatusCode.h:88
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
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
bool isSuccess() const
Definition: StatusCode.h:287
void copyFileLayout(TDirectory *, TDirectory *)
helper function to recursively copy the layout of a TFile into a new TFile
Definition: THistSvc.cpp:1809
TDirectory * changeDir(const THistSvc::THistID &hid) const
Definition: THistSvc.cpp:1585
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
uidMap_t m_uids
Definition: THistSvc.h:249
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:255
IFileMgr * p_fileMgr
Definition: THistSvc.h:343
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn&#39;t already exist.
Definition: Service.h:84
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:351
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
virtual Io::close_t close(const Io::Fd, const std::string &caller)=0
StatusCode THistSvc::merge ( const std::string id)
override

Merge all clones for object with a given id.

Definition at line 655 of file THistSvc.cpp.

656 {
657  uidMap_t::iterator itr = m_uids.find( name );
658  if ( itr == m_uids.end() ) {
659  error() << "merge: id \"" << name << "\" not found" << endmsg;
660  return StatusCode::FAILURE;
661  }
662 
663  return merge( itr->second );
664 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
StatusCode merge(const std::string &id) override
Merge all clones for object with a given id.
Definition: THistSvc.cpp:655
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T find(T...args)
uidMap_t m_uids
Definition: THistSvc.h:249
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode THistSvc::merge ( TObject *  obj)
override

Merge all clones for given TObject*.

Definition at line 666 of file THistSvc.cpp.

667 {
668  objMap_t::iterator itr = m_tobjs.find( obj );
669  if ( itr != m_tobjs.end() ) {
670  return merge( itr->second.first );
671  } else {
672  error() << "merge: unknown object " << obj << endmsg;
673  return StatusCode::FAILURE;
674  }
675 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
StatusCode merge(const std::string &id) override
Merge all clones for object with a given id.
Definition: THistSvc.cpp:655
objMap_t m_tobjs
Definition: THistSvc.h:253
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T find(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode THistSvc::merge ( const THistID hid)
private

Helper method to merge THistID objects.

Definition at line 1929 of file THistSvc.cpp.

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

Helper method to merge vectors of THistID.

Definition at line 1931 of file THistSvc.cpp.

1932 {
1933  const std::string& name = vh->at( 0 ).id;
1934  if ( vh->size() == 1 ) {
1935  debug() << "merge: id: \"" << name << "\" is size 1. nothing to do" << endmsg;
1936  return StatusCode::SUCCESS;
1937  }
1938 
1939  if ( !vh->at( 0 ).obj->IsA()->InheritsFrom( "TH1" ) ) {
1940  error() << "merge: id \"" << name << "\" is not a THn. Cannot merge" << endmsg;
1941  return StatusCode::FAILURE;
1942  }
1943 
1944  TList* l = new TList();
1945  for ( size_t i = 1; i < vh->size(); ++i ) {
1946  debug() << "merge: id: \"" << name << "\" (" << vh->at( i ).obj << ") adding index " << i << endmsg;
1947  l->Add( vh->at( i ).obj );
1948  }
1949 
1950  TH1* t0 = dynamic_cast<TH1*>( vh->at( 0 ).obj );
1951  if ( t0 == 0 ) {
1952  error() << "merge: could not dcast " << name << "(" << t0 << ") index " << 0 << " to TH1" << endmsg;
1953  return StatusCode::FAILURE;
1954  }
1955 
1956  Long64_t n = t0->Merge( l );
1957 
1958  debug() << "merge: id: \"" << name << "\" merged " << n << " entries" << endmsg;
1959 
1960  for ( size_t i = 1; i < vh->size(); ++i ) {
1961  TH1* th = dynamic_cast<TH1*>( vh->at( i ).obj );
1962  if ( th != 0 ) {
1963  debug() << "clearing index " << i << "(" << th << ")" << endmsg;
1964  th->SetDirectory( nullptr );
1965  th->Reset();
1966  } else {
1967  error() << "merge: could not dcast " << name << " index " << i << " to TH1" << endmsg;
1968  return StatusCode::FAILURE;
1969  }
1970  }
1971  return StatusCode::SUCCESS;
1972 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
STL class.
T at(T...args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
dictionary l
Definition: gaudirun.py:440
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void THistSvc::MergeRootFile ( TDirectory *  target,
TDirectory *  source 
)
private

Definition at line 1634 of file THistSvc.cpp.

1635 {
1636  if ( msgLevel( MSG::DEBUG ) ) {
1637  debug() << "Target path: " << target->GetPath() << endmsg;
1638  }
1639  TString path( (char*)strstr( target->GetPath(), ":" ) );
1640  path.Remove( 0, 2 );
1641 
1642  source->cd( path );
1643  TDirectory* current_sourcedir = gDirectory;
1644 
1645  // loop over all keys in this directory
1646  TList* lkeys = current_sourcedir->GetListOfKeys();
1647  int nkeys = lkeys->GetEntries();
1648  TKey* key = nullptr;
1649  for ( int jj = 0; jj < nkeys; jj++ ) {
1650  key = (TKey*)lkeys->At( jj );
1651  std::string pathnameinsource = current_sourcedir->GetPath() + std::string( "/" ) + key->GetName();
1652  if ( msgLevel( MSG::DEBUG ) ) {
1653  debug() << "Reading Key:" << pathnameinsource << endmsg;
1654  }
1655  TObject* obj = source->Get( pathnameinsource.c_str() );
1656 
1657  if ( obj ) {
1658  if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) {
1659  // it's a subdirectory
1660  if ( msgLevel( MSG::DEBUG ) ) {
1661  debug() << "Found subdirectory " << obj->GetName() << endmsg;
1662  }
1663 
1664  // create a new subdir of same name and title in the target file
1665  target->cd();
1666  TDirectory* newtargetdir = target->mkdir( obj->GetName(), obj->GetTitle() );
1667 
1668  MergeRootFile( newtargetdir, source );
1669 
1670  } else if ( obj->IsA()->InheritsFrom( "TTree" ) ) {
1671  if ( msgLevel( MSG::DEBUG ) ) {
1672  debug() << "Found TTree " << obj->GetName() << endmsg;
1673  }
1674  TTree* mytree = dynamic_cast<TTree*>( obj );
1675  int nentries = (int)mytree->GetEntries();
1676  mytree->SetBranchStatus( "*", 1 );
1677 
1678  if ( msgLevel( MSG::DEBUG ) ) {
1679  debug() << "Dumping TTree " << nentries << " entries" << endmsg;
1680  }
1681  target->cd();
1682  mytree->CloneTree();
1683 
1684  } else {
1685  target->cd();
1686  obj->Write( key->GetName() );
1687  }
1688  }
1689  }
1690 }
void MergeRootFile(TDirectory *, TDirectory *)
Definition: THistSvc.cpp:1634
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:209
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
void THistSvc::parseString ( const std::string id,
std::string root,
std::string rem 
) const
private

Definition at line 1731 of file THistSvc.cpp.

1732 {
1733  auto pos = id.find( "/" );
1734 
1735  if ( pos == std::string::npos ) {
1736  root.clear();
1737  rem = id;
1738  } else if ( pos == 0 ) {
1739  parseString( id.substr( 1 ), root, rem );
1740  } else {
1741  root = id.substr( 0, pos );
1742  rem = id.substr( pos + 1 );
1743  }
1744 }
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1731
T clear(T...args)
T substr(T...args)
template<typename T >
T * THistSvc::readHist ( const std::string name) const
private

Definition at line 1281 of file THistSvc.cpp.

1282 {
1283  return dynamic_cast<T*>( readHist_i<T>( id ) );
1284 }
template<typename T >
T * THistSvc::readHist_i ( const std::string name) const
private

Definition at line 215 of file THistSvc.icc.

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

Definition at line 1286 of file THistSvc.cpp.

1286 { return dynamic_cast<TTree*>( readHist_i<TTree>( id ) ); }
StatusCode THistSvc::regGraph ( const std::string name)
override

Register a new TGraph with a given name.

Definition at line 443 of file THistSvc.cpp.

444 {
445  std::unique_ptr<TGraph> graph = std::make_unique<TGraph>();
446  return regHist_i( std::move( graph ), id, false );
447 }
T move(T...args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:17
STL class.
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 449 of file THistSvc.cpp.

450 {
451  if ( strcmp( graph->GetName(), "Graph" ) == 0 ) {
452  std::string id2( id );
453  std::string::size_type i = id2.rfind( "/" );
454  if ( i != std::string::npos ) {
455  id2.erase( 0, i + 1 );
456  }
457 
458  info() << "setting name of TGraph id: \"" << id << "\" to \"" << id2 << "\" since it is unset" << endmsg;
459  graph->SetName( id2.c_str() );
460  }
461 
462  return regHist_i( std::move( graph ), id, false );
463 }
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:17
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
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 465 of file THistSvc.cpp.

466 {
467  std::unique_ptr<TGraph> graph( graph_ptr );
468  if ( strcmp( graph->GetName(), "Graph" ) == 0 ) {
469  std::string id2( id );
470  std::string::size_type i = id2.rfind( "/" );
471  if ( i != std::string::npos ) {
472  id2.erase( 0, i + 1 );
473  }
474 
475  info() << "setting name of TGraph id: \"" << id << "\" to \"" << id2 << "\" since it is unset" << endmsg;
476  graph->SetName( id2.c_str() );
477  }
478 
479  return regHist_i( std::move( graph ), id, false );
480 }
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:17
STL class.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode THistSvc::regHist ( const std::string name)
override

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

Definition at line 344 of file THistSvc.cpp.

345 {
346  std::unique_ptr<TH1> hist = nullptr;
347  return regHist_i( std::move( hist ), id, false );
348 }
T move(T...args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:17
STL class.
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 350 of file THistSvc.cpp.

351 {
352  return regHist_i( std::move( hist ), id, false );
353 }
T move(T...args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:17
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 355 of file THistSvc.cpp.

356 {
357  // This is only to support a common use case where the histogram is used after its registration
358  if ( hist_ptr != nullptr ) {
359  hist_ptr = hist.get();
360  }
361  return regHist_i( std::move( hist ), id, false );
362 }
T move(T...args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:17
T get(T...args)
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 364 of file THistSvc.cpp.

365 {
366  std::unique_ptr<TH1> hist( hist_ptr );
367  return regHist_i( std::move( hist ), id, false );
368 }
T move(T...args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:17
STL class.
template<typename T >
StatusCode THistSvc::regHist_i ( std::unique_ptr< T >  hist,
const std::string name,
bool  shared 
)
private

Definition at line 17 of file THistSvc.icc.

18 {
19  THistID* hid = nullptr ;
20  return regHist_i( std::move(hist), id, shared, hid );
21 }
T move(T...args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:17
template<typename T >
StatusCode THistSvc::regHist_i ( std::unique_ptr< T >  hist,
const std::string name,
bool  shared,
THistID *&  hid 
)
private

Definition at line 24 of file THistSvc.icc.

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

493 {
494  lh = regShared_i<TH1>( id, std::move( hist ) );
495  if ( lh ) {
496  return StatusCode::SUCCESS;
497  } else {
498  return StatusCode::FAILURE;
499  }
500 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
T move(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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 502 of file THistSvc.cpp.

503 {
504  lh = regShared_i<TH2>( id, std::move( hist ) );
505  if ( lh ) {
506  return StatusCode::SUCCESS;
507  } else {
508  return StatusCode::FAILURE;
509  }
510 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
T move(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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 512 of file THistSvc.cpp.

513 {
514  lh = regShared_i<TH3>( id, std::move( hist ) );
515  if ( lh ) {
516  return StatusCode::SUCCESS;
517  } else {
518  return StatusCode::FAILURE;
519  }
520 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
T move(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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 522 of file THistSvc.cpp.

523 {
524  lh = regShared_i<TGraph>( id, std::move( graph ) );
525  if ( lh ) {
526  return StatusCode::SUCCESS;
527  } else {
528  return StatusCode::FAILURE;
529  }
530 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
T move(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
template<typename T >
LockedHandle< T > THistSvc::regShared_i ( const std::string id,
std::unique_ptr< T >  hist 
)
private

Definition at line 272 of file THistSvc.icc.

273 {
274  LockedHandle<T> lh( nullptr, nullptr );
275  const THistID* hid = nullptr;
276  if ( findHistID( id, hid ) == 0 ) {
277  T* phist = hist.get();
278  THistID* phid = nullptr;
279  if ( regHist_i( std::move(hist), id, true, phid ).isSuccess() ) {
280  lh.set( phist, phid->mutex );
281 
282  } else {
283  error() << "regSharedHist: unable to register shared hist with id \"" << id << "\"" << endmsg;
284  }
285  } else {
286  if ( !hid->shared ) {
287  error() << "regSharedHist: previously register Hist with id \"" << id << "\" was not marked shared" << endmsg;
288  }
289 
290  if ( hist->Compare( hid->obj ) != 0 ) {
291  error() << "regSharedHist: Histogram " << id << " does not compare with " << hid << endmsg;
292  } else {
293  T* phist = dynamic_cast<T*>( hid->obj );
294  if ( phist == 0 ) {
295  error() << "regSharedHist: unable to dcast retrieved shared hist \"" << id << "\" of type "
296  << hid->obj->IsA()->GetName() << " to requested type " << System::typeinfoName( typeid( T ) ) << endmsg;
297  } else {
298  lh.set( phist, hid->mutex );
299  delete hist.release();
300  }
301  }
302  }
303  return lh;
304 }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:332
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:28
T move(T...args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:17
T get(T...args)
size_t findHistID(const std::string &id, const THistID *&hid, const size_t &index=0) const
Definition: THistSvc.cpp:1842
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode THistSvc::regTree ( const std::string name)
override

Register a new TTree with a given name.

Definition at line 400 of file THistSvc.cpp.

401 {
402  std::unique_ptr<TTree> tree = nullptr;
403  return regHist_i( std::move( tree ), id, false );
404 }
T move(T...args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:17
STL class.
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 406 of file THistSvc.cpp.

407 {
408  StatusCode sc = regHist_i( std::move( tree ), id, false );
409  TTree* tr = nullptr;
410  if ( getTree( id, tr ).isSuccess() && sc.isSuccess() ) {
411  if ( m_autoSave != 0 ) {
412  tr->SetAutoSave( m_autoSave );
413  }
414  tr->SetAutoFlush( m_autoFlush );
415  }
416  return sc;
417 }
bool isSuccess() const
Definition: StatusCode.h:287
Gaudi::Property< int > m_autoSave
Definition: THistSvc.h:331
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
StatusCode getTree(const std::string &name, TTree *&) const override
Return TTree with given name.
Definition: THistSvc.cpp:433
T move(T...args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:17
Gaudi::Property< int > m_autoFlush
Definition: THistSvc.h:332
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 419 of file THistSvc.cpp.

420 {
421  std::unique_ptr<TTree> tree( tree_ptr );
422  StatusCode sc = regHist_i( std::move( tree ), id, false );
423  TTree* tr = nullptr;
424  if ( getTree( id, tr ).isSuccess() && sc.isSuccess() ) {
425  if ( m_autoSave != 0 ) {
426  tr->SetAutoSave( m_autoSave );
427  }
428  tr->SetAutoFlush( m_autoFlush );
429  }
430  return sc;
431 }
bool isSuccess() const
Definition: StatusCode.h:287
Gaudi::Property< int > m_autoSave
Definition: THistSvc.h:331
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
StatusCode getTree(const std::string &name, TTree *&) const override
Return TTree with given name.
Definition: THistSvc.cpp:433
T move(T...args)
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared)
Definition: THistSvc.icc:17
STL class.
Gaudi::Property< int > m_autoFlush
Definition: THistSvc.h:332
StatusCode THistSvc::reinitialize ( )
override

Definition at line 180 of file THistSvc.cpp.

181 {
182  GlobalDirectoryRestore restore( m_svcMut );
183  warning() << "reinitialize not implemented" << endmsg;
184  return StatusCode::SUCCESS;
185 }
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
THistSvcMutex_t m_svcMut
Definition: THistSvc.h:351
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void THistSvc::removeDoubleSlash ( std::string id) const
private

Definition at line 1627 of file THistSvc.cpp.

1628 {
1629  while ( id.find( "//" ) != std::string::npos ) {
1630  id.replace( id.find( "//" ), 2, "/" );
1631  }
1632 }
T find(T...args)
StatusCode THistSvc::rootOpenAction ( FILEMGR_CALLBACK_ARGS  )
private

Definition at line 1974 of file THistSvc.cpp.

1975 {
1976  if ( fa->tech() != Io::ROOT ) {
1977  // This should never happen
1978  return StatusCode::SUCCESS;
1979  }
1980 
1981  if ( fa->desc() != "HIST" ) {
1982  return StatusCode::SUCCESS;
1983  }
1984 
1985  p_incSvc->fireIncident( FileIncident( caller, "OpenHistFile", fa->name() ) );
1986 
1987  if ( fa->flags().isRead() ) {
1988  p_incSvc->fireIncident( FileIncident( caller, "BeginHistFile", fa->name() ) );
1989  } else if ( fa->flags().isWrite() ) {
1990  p_incSvc->fireIncident( FileIncident( caller, IncidentType::BeginOutputFile, fa->name() ) );
1991  } else {
1992  // for Io::RW
1993  p_incSvc->fireIncident( FileIncident( caller, IncidentType::BeginOutputFile, fa->name() ) );
1994  }
1995 
1996  return StatusCode::SUCCESS;
1997 }
This class is the FileIncident.
Definition: FileIncident.h:17
IIncidentSvc * p_incSvc
Definition: THistSvc.h:342
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
StatusCode THistSvc::rootOpenErrAction ( FILEMGR_CALLBACK_ARGS  )
private

Definition at line 1999 of file THistSvc.cpp.

2000 {
2001  if ( fa->tech() != Io::ROOT ) {
2002  // This should never happen
2003  return StatusCode::SUCCESS;
2004  }
2005 
2006  if ( fa->desc() != "HIST" ) {
2007  return StatusCode::SUCCESS;
2008  }
2009 
2010  if ( fa->flags().isRead() ) {
2011  p_incSvc->fireIncident( FileIncident( caller, IncidentType::FailInputFile, fa->name() ) );
2012  } else if ( fa->flags().isWrite() ) {
2013  p_incSvc->fireIncident( FileIncident( caller, IncidentType::FailOutputFile, fa->name() ) );
2014  } else {
2015  // for Io::RW
2016  p_incSvc->fireIncident( FileIncident( caller, "FailRWFile", fa->name() ) );
2017  }
2018 
2019  return StatusCode::SUCCESS;
2020 }
This class is the FileIncident.
Definition: FileIncident.h:17
IIncidentSvc * p_incSvc
Definition: THistSvc.h:342
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
void THistSvc::setupCompressionLevel ( Gaudi::Details::PropertyBase cmp)
private

Definition at line 1802 of file THistSvc.cpp.

1804 {
1805  warning() << "\"CompressionLevel\" Property has been deprecated. "
1806  << "Set it via the \"CL=\" parameter in the \"Output\" Property" << endmsg;
1807 }
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void THistSvc::setupInputFile ( Gaudi::Details::PropertyBase inputfile)
private

call-back method to handle input stream property

Definition at line 1746 of file THistSvc.cpp.

1748 {
1750  debug() << "Delaying connection of Input Files until Initialize"
1751  << ". now in " << FSMState() << endmsg;
1752 
1753  m_delayConnect = true;
1754  } else {
1755  debug() << "Now connecting of Input Files" << endmsg;
1756 
1758 
1759  for ( const auto& itr : m_inputfile.value() ) {
1761  continue;
1762  }
1763  if ( connect( itr ).isFailure() ) {
1764  sc = StatusCode::FAILURE;
1765  } else {
1767  }
1768  }
1769 
1770  if ( !sc.isSuccess() ) {
1771  throw GaudiException( "Problem connecting inputfile !!", name(), StatusCode::FAILURE );
1772  }
1773  }
1774 }
bool m_delayConnect
Definition: THistSvc.h:346
constexpr static const auto FAILURE
Definition: StatusCode.h:88
Define general base for Gaudi exception.
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
bool isSuccess() const
Definition: StatusCode.h:287
T end(T...args)
bool isFailure() const
Definition: StatusCode.h:139
Gaudi::Property< std::vector< std::string > > m_inputfile
Definition: THistSvc.h:338
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
bool m_okToConnect
Definition: THistSvc.h:347
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T insert(T...args)
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Gaudi::StateMachine::State FSMState() const override
Definition: Service.h:53
StatusCode connect(const std::string &)
Definition: THistSvc.cpp:1396
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
Definition: THistSvc.h:231
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void THistSvc::setupOutputFile ( Gaudi::Details::PropertyBase outputfile)
private

call-back method to handle output stream property

Definition at line 1776 of file THistSvc.cpp.

1778 {
1780  debug() << "Delaying connection of Input Files until Initialize"
1781  << ". now in " << FSMState() << endmsg;
1782  m_delayConnect = true;
1783  } else {
1785  for ( const auto& itr : m_outputfile.value() ) {
1787  continue;
1788  }
1789  if ( connect( itr ).isFailure() ) {
1790  sc = StatusCode::FAILURE;
1791  } else {
1793  }
1794  }
1795 
1796  if ( !sc.isSuccess() ) {
1797  throw GaudiException( "Problem connecting outputfile !!", name(), StatusCode::FAILURE );
1798  }
1799  }
1800 }
bool m_delayConnect
Definition: THistSvc.h:346
constexpr static const auto FAILURE
Definition: StatusCode.h:88
Define general base for Gaudi exception.
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
bool isSuccess() const
Definition: StatusCode.h:287
T end(T...args)
bool isFailure() const
Definition: StatusCode.h:139
Gaudi::Property< std::vector< std::string > > m_outputfile
Definition: THistSvc.h:337
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
bool m_okToConnect
Definition: THistSvc.h:347
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T insert(T...args)
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Gaudi::StateMachine::State FSMState() const override
Definition: Service.h:53
StatusCode connect(const std::string &)
Definition: THistSvc.cpp:1396
std::set< std::string > m_alreadyConnectedOutFiles
list of already connected files.
Definition: THistSvc.h:235
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
std::string THistSvc::stripDirectoryName ( std::string dir) const
private

Definition at line 1610 of file THistSvc.cpp.

1611 {
1612  std::string::size_type i = dir.find( "/" );
1613 
1614  if ( i == std::string::npos ) return {};
1615 
1616  if ( i == 0 ) {
1617  dir.erase( 0, 1 );
1618  return stripDirectoryName( dir );
1619  }
1620 
1621  std::string root = dir.substr( 0, i );
1622  dir.erase( 0, i );
1623 
1624  return root;
1625 }
STL class.
std::string stripDirectoryName(std::string &dir) const
Definition: THistSvc.cpp:1610
T erase(T...args)
T find(T...args)
T substr(T...args)
void THistSvc::updateFiles ( )
private

Handle case where TTree grows beyond TTree::fgMaxTreeSize.

Definition at line 1288 of file THistSvc.cpp.

1289 {
1290  // If TTrees grow beyond TTree::fgMaxTreeSize, a new file is
1291  // automatically created by root, and the old one closed. We
1292  // need to migrate all the UIDs over to show the correct file
1293  // pointer. This is ugly.
1294 
1295  if ( msgLevel( MSG::DEBUG ) ) debug() << "updateFiles()" << endmsg;
1296 
1297  for ( auto uitr = m_uids.begin(); uitr != m_uids.end(); ++uitr ) {
1298  for ( auto& hid : *( uitr->second ) ) {
1299 #ifndef NDEBUG
1300  if ( msgLevel( MSG::VERBOSE ) )
1301  verbose() << " update: " << uitr->first << " " << hid.id << " " << hid.mode << endmsg;
1302 #endif
1303  TObject* to = hid.obj;
1304  TFile* oldFile = hid.file;
1305  if ( !to ) {
1306  warning() << uitr->first << ": TObject == 0" << endmsg;
1307  } else if ( hid.temp || hid.mode == READ ) {
1308 // do nothing - no need to check how big the file is since we
1309 // are just reading it.
1310 #ifndef NDEBUG
1311  if ( msgLevel( MSG::VERBOSE ) ) verbose() << " skipping" << endmsg;
1312 #endif
1313  } else if ( to->IsA()->InheritsFrom( "TTree" ) ) {
1314  TTree* tr = dynamic_cast<TTree*>( to );
1315  TFile* newFile = tr->GetCurrentFile();
1316 
1317  if ( oldFile != newFile ) {
1318  std::string newFileName = newFile->GetName();
1319  std::string oldFileName, streamName, rem;
1320  TFile* dummy = nullptr;
1321  findStream( hid.id, streamName, rem, dummy );
1322 
1323  for ( auto& itr : m_files ) {
1324  if ( itr.second.first == oldFile ) {
1325  itr.second.first = newFile;
1326  }
1327  }
1328 
1329  for ( auto uitr2 = uitr; uitr2 != m_uids.end(); ++uitr2 ) {
1330  for ( auto& hid2 : *( uitr2->second ) ) {
1331  if ( hid2.file == oldFile ) {
1332  hid2.file = newFile;
1333  }
1334  }
1335  }
1336 
1338  [&]( streamMap::const_reference s ) { return s.second == streamName; } );
1339  if ( sitr != std::end( m_fileStreams ) ) oldFileName = sitr->first;
1340 
1341 #ifndef NDEBUG
1342  if ( msgLevel( MSG::DEBUG ) ) {
1343  debug() << "migrating uid: " << hid.id << " stream: " << streamName << " oldFile: " << oldFileName
1344  << " newFile: " << newFileName << endmsg;
1345  }
1346 #endif
1347 
1348  if ( !oldFileName.empty() ) {
1349  auto i = m_fileStreams.lower_bound( oldFileName );
1350  while ( i != std::end( m_fileStreams ) && i->first == oldFileName ) {
1351 #ifndef NDEBUG
1352  if ( msgLevel( MSG::DEBUG ) ) {
1353  debug() << "changing filename \"" << i->first << "\" to \"" << newFileName << "\" for stream \""
1354  << i->second << "\"" << endmsg;
1355  }
1356 #endif
1357  std::string nm = std::move( i->second );
1358  i = m_fileStreams.erase( i );
1359  m_fileStreams.emplace( newFileName, std::move( nm ) );
1360  }
1361  } else {
1362  error() << "Problems updating fileStreams with new file name" << endmsg;
1363  }
1364  }
1365  }
1366  }
1367  }
1368 }
T empty(T...args)
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
Definition: THistSvc.cpp:1692
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
T lower_bound(T...args)
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
T erase(T...args)
T move(T...args)
constexpr double nm
Definition: SystemOfUnits.h:83
T find_if(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T begin(T...args)
uidMap_t m_uids
Definition: THistSvc.h:249
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:255
T emplace(T...args)
string s
Definition: gaudirun.py:253
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
streamMap m_fileStreams
Definition: THistSvc.h:257
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
StatusCode THistSvc::writeObjectsToFile ( )
private

Definition at line 1370 of file THistSvc.cpp.

1371 {
1372  updateFiles();
1373 
1375  auto mode = i.second.second;
1376  auto file = i.second.first;
1377  if ( mode == WRITE || mode == UPDATE || mode == SHARE ) {
1378  file->Write( "", TObject::kOverwrite );
1379  } else if ( mode == APPEND ) {
1380  file->Write( "" );
1381  }
1382  } );
1383 
1384  if ( msgLevel( MSG::DEBUG ) ) {
1385  debug() << "THistSvc::writeObjectsToFile()::List of Files connected in ROOT " << endmsg;
1386  TSeqCollection* filelist = gROOT->GetListOfFiles();
1387  for ( int ii = 0; ii < filelist->GetEntries(); ii++ ) {
1388  debug() << "THistSvc::writeObjectsToFile()::List of Files connected in ROOT: \"" << filelist->At( ii )->GetName()
1389  << "\"" << endmsg;
1390  }
1391  }
1392 
1393  return StatusCode::SUCCESS;
1394 }
T end(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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:255
T for_each(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void updateFiles()
Handle case where TTree grows beyond TTree::fgMaxTreeSize.
Definition: THistSvc.cpp:1288
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)

Member Data Documentation

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

list of already connected files.

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

Definition at line 231 of file THistSvc.h.

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

list of already connected files.

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

Definition at line 235 of file THistSvc.h.

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

Definition at line 332 of file THistSvc.h.

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

Definition at line 331 of file THistSvc.h.

Gaudi::Property<int> THistSvc::m_compressionLevel {this, "CompressionLevel", 1}
private

Definition at line 336 of file THistSvc.h.

std::string THistSvc::m_curstream
mutableprivate

Definition at line 349 of file THistSvc.h.

bool THistSvc::m_delayConnect = false
private

Definition at line 346 of file THistSvc.h.

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

Definition at line 255 of file THistSvc.h.

streamMap THistSvc::m_fileStreams
private

Definition at line 257 of file THistSvc.h.

hlist_t THistSvc::m_hlist
private

Definition at line 248 of file THistSvc.h.

idMap_t THistSvc::m_ids
private

Definition at line 250 of file THistSvc.h.

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

Definition at line 338 of file THistSvc.h.

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

bool THistSvc::m_okToConnect = false
private

Definition at line 347 of file THistSvc.h.

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

Definition at line 337 of file THistSvc.h.

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

Definition at line 333 of file THistSvc.h.

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

Definition at line 227 of file THistSvc.h.

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

Definition at line 260 of file THistSvc.h.

bool THistSvc::m_signaledStop = false
private

Definition at line 345 of file THistSvc.h.

THistSvcMutex_t THistSvc::m_svcMut
mutableprivate

Definition at line 351 of file THistSvc.h.

objMap_t THistSvc::m_tobjs
private

Definition at line 253 of file THistSvc.h.

uidMap_t THistSvc::m_uids
private

Definition at line 249 of file THistSvc.h.

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

Definition at line 227 of file THistSvc.h.

IFileMgr* THistSvc::p_fileMgr = nullptr
private

Definition at line 343 of file THistSvc.h.

IIncidentSvc* THistSvc::p_incSvc = nullptr
private

Definition at line 342 of file THistSvc.h.


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