The Gaudi Framework  v29r0 (ff2e7097)
THistSvc.h
Go to the documentation of this file.
1 #ifndef GAUDISVC_THISTSVC_H
2 #define GAUDISVC_THISTSVC_H
3 
4 #include "GaudiKernel/IFileMgr.h"
9 #include "GaudiKernel/Service.h"
10 
11 #include "TGraph.h"
12 #include "TH1.h"
13 #include "TH2.h"
14 #include "TH3.h"
15 #include "TList.h"
16 #include "TObject.h"
17 #include "TTree.h"
18 
19 #include <map>
20 #include <set>
21 #include <string>
22 #include <vector>
23 
24 class IIncidentSvc;
25 class THistSvc : public extends<Service, ITHistSvc, IIncidentListener, IIoComponent>
26 {
27 
28 public:
29  StatusCode initialize() override;
30  StatusCode reinitialize() override;
31  StatusCode finalize() override;
32 
33  StatusCode regHist( const std::string& name ) override;
34  StatusCode regHist( const std::string& name, TH1* ) override;
35  StatusCode regHist( const std::string& name, TH2* ) override;
36  StatusCode regHist( const std::string& name, TH3* ) override;
37 
38  StatusCode getHist( const std::string& name, TH1*& ) const override;
39  StatusCode getHist( const std::string& name, TH2*& ) const override;
40  StatusCode getHist( const std::string& name, TH3*& ) const override;
41 
42  StatusCode regTree( const std::string& name ) override;
43  StatusCode regTree( const std::string& name, TTree* ) override;
44  StatusCode getTree( const std::string& name, TTree*& ) const override;
45 
46  StatusCode regGraph( const std::string& name ) override;
47  StatusCode regGraph( const std::string& name, TGraph* ) override;
48  StatusCode getGraph( const std::string& name, TGraph*& ) const override;
49 
50  StatusCode deReg( TObject* obj ) override;
51  StatusCode deReg( const std::string& name ) override;
52 
53  std::vector<std::string> getHists() const override;
54  std::vector<std::string> getTrees() const override;
55  std::vector<std::string> getGraphs() const override;
56 
57  StatusCode getTHists( TDirectory* td, TList&, bool recurse = false ) const override;
58  StatusCode getTHists( const std::string& name, TList&, bool recurse = false ) const override;
59 
60  StatusCode getTHists( TDirectory* td, TList& tl, bool recurse = false, bool reg = false ) override;
61  StatusCode getTHists( const std::string& name, TList& tl, bool recurse = false, bool reg = false ) override;
62 
63  StatusCode getTTrees( TDirectory* td, TList&, bool recurse = false ) const override;
64  StatusCode getTTrees( const std::string& name, TList&, bool recurse = false ) const override;
65 
66  StatusCode getTTrees( TDirectory* td, TList& tl, bool recurse = false, bool reg = false ) override;
67  StatusCode getTTrees( const std::string& name, TList& tl, bool recurse = false, bool reg = false ) override;
68 
69  bool exists( const std::string& name ) const override;
70 
71  THistSvc( const std::string& name, ISvcLocator* svc );
72 
73  void handle( const Incident& ) override;
74 
75  // From IIoComponent
76  StatusCode io_reinit() override;
77 
78 protected:
79  ~THistSvc() override = default;
80 
81 private:
83  {
84  public:
87 
88  private:
89  TDirectory* m_gd;
90  TFile* m_gf;
91  int m_ge;
92  };
93 
95 
96  struct THistID {
98  bool temp;
99  TObject* obj;
100  TFile* file;
102 
103  THistID() : id( "" ), temp( true ), obj( 0 ), file( 0 ), mode( INVALID ) {}
104  THistID( const THistID& rhs ) : id( rhs.id ), temp( rhs.temp ), obj( rhs.obj ), file( rhs.file ), mode( rhs.mode )
105  {
106  }
107  THistID( std::string& i, bool& t, TObject* o, TFile* f ) : id( i ), temp( t ), obj( o ), file( f ), mode( INVALID )
108  {
109  }
110  THistID( std::string& i, bool& t, TObject* o, TFile* f, Mode m )
111  : id( i ), temp( t ), obj( o ), file( f ), mode( m )
112  {
113  }
114 
115  bool operator<( THistID const& rhs ) const { return ( obj < rhs.obj ); }
116  };
117 
118  template <typename T>
119  StatusCode regHist_i( T* hist, const std::string& name );
120  template <typename T>
121  StatusCode getHist_i( const std::string& name, T*& hist, bool quiet = false ) const;
122  template <typename T>
123  StatusCode readHist_i( const std::string& name, T*& hist ) const;
124 
125  StatusCode readHist( const std::string& name, TH1*& ) const;
126  StatusCode readHist( const std::string& name, TH2*& ) const;
127  StatusCode readHist( const std::string& name, TH3*& ) const;
128  StatusCode readTree( const std::string& name, TTree*& ) const;
129 
130  void updateFiles();
131  StatusCode write();
132  StatusCode connect( const std::string& );
133  TDirectory* changeDir( const THistSvc::THistID& hid ) const;
134  std::string dirname( std::string& dir ) const;
135  void removeDoubleSlash( std::string& ) const;
136 
137  bool browseTDir( TDirectory* dir ) const;
138 
139  bool findStream( const std::string& name, std::string& root, std::string& rem, TFile*& file ) const;
140  void parseString( const std::string& id, std::string& root, std::string& rem ) const;
141 
143  void setupInputFile( Gaudi::Details::PropertyBase& inputfile );
144 
146  void setupOutputFile( Gaudi::Details::PropertyBase& outputfile );
147 
149 
150  void copyFileLayout( TDirectory*, TDirectory* );
151 
152  void MergeRootFile( TDirectory* target, TDirectory* source );
153 
154  Gaudi::Property<int> m_autoSave{this, "AutoSave", 0};
155  Gaudi::Property<int> m_autoFlush{this, "AutoFlush", 0};
156  Gaudi::Property<bool> m_print{this, "PrintAll", false};
157  Gaudi::Property<int> m_maxFileSize{this, "MaxFileSize", 10240,
158  "maximum file size in MB. if exceeded, will cause an abort. -1 to never check."};
159  Gaudi::Property<int> m_compressionLevel{this, "CompressionLevel", 1};
162 
164 
168 
172 
177 
178  uidMap m_uids;
179  idMap m_ids;
180  objMap m_tobjs;
181 
183  streamMap m_fileStreams; // fileName->streams
184 
185  std::map<std::string, std::string> m_sharedFiles; // stream->filename of shared files
186 
187  bool signaledStop = false;
188  bool m_delayConnect = false, m_okToConnect = false;
189 
191 
192  IIncidentSvc* p_incSvc = nullptr;
193  IFileMgr* p_fileMgr = nullptr;
194 
197 };
198 
199 #ifndef GAUDISVC_THISTSVC_ICC
200 #include "THistSvc.icc"
201 #endif
202 
203 #endif
bool m_delayConnect
Definition: THistSvc.h:188
StatusCode getGraph(const std::string &name, TGraph *&) const override
Definition: THistSvc.cpp:954
StatusCode initialize() override
Definition: THistSvc.cpp:70
THistID(std::string &i, bool &t, TObject *o, TFile *f, Mode m)
Definition: THistSvc.h:110
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
THistID(const THistID &rhs)
Definition: THistSvc.h:104
std::string m_curstream
Definition: THistSvc.h:190
Implementation of property with value of concrete type.
Definition: Property.h:319
std::vector< std::string > getGraphs() const override
Definition: THistSvc.cpp:958
bool exists(const std::string &name) const override
Definition: THistSvc.cpp:1552
IIncidentSvc * p_incSvc
Definition: THistSvc.h:192
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
Definition: THistSvc.cpp:985
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:393
bool browseTDir(TDirectory *dir) const
Definition: THistSvc.cpp:344
bool signaledStop
Definition: THistSvc.h:187
StatusCode rootOpenAction(FILEMGR_CALLBACK_ARGS)
Definition: THistSvc.cpp:1741
void copyFileLayout(TDirectory *, TDirectory *)
helper function to recursively copy the layout of a TFile into a new TFile
Definition: THistSvc.cpp:1609
TDirectory * changeDir(const THistSvc::THistID &hid) const
Definition: THistSvc.cpp:1411
void setupCompressionLevel(Gaudi::Details::PropertyBase &cmp)
Definition: THistSvc.cpp:1041
objMap m_tobjs
Definition: THistSvc.h:180
Gaudi::Property< std::vector< std::string > > m_outputfile
Definition: THistSvc.h:160
std::multimap< std::string, THistID > idMap
Definition: THistSvc.h:174
std::vector< std::string > getHists() const override
Definition: THistSvc.cpp:928
StatusCode write()
Definition: THistSvc.cpp:1188
std::vector< std::string > m_Wstream
Definition: THistSvc.h:163
STL class.
#define FILEMGR_CALLBACK_ARGS
Definition: IFileMgr.h:293
Gaudi::Property< int > m_autoSave
Definition: THistSvc.h:154
std::string id
Definition: THistSvc.h:97
~THistSvc() override=default
Gaudi::Property< std::vector< std::string > > m_inputfile
Definition: THistSvc.h:161
std::string dirname(std::string &dir) const
Definition: THistSvc.cpp:1439
StatusCode readTree(const std::string &name, TTree *&) const
Definition: THistSvc.cpp:981
std::vector< std::string > m_Rstream
Definition: THistSvc.h:163
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
constexpr double m
Definition: SystemOfUnits.h:94
bool m_okToConnect
Definition: THistSvc.h:188
Gaudi::Property< bool > m_print
Definition: THistSvc.h:156
void handle(const Incident &) override
Definition: THistSvc.cpp:1561
Gaudi::Property< int > m_maxFileSize
Definition: THistSvc.h:157
std::multimap< std::string, std::string > streamMap
Definition: THistSvc.h:176
StatusCode getTree(const std::string &name, TTree *&) const override
Definition: THistSvc.cpp:939
StatusCode rootOpenErrAction(FILEMGR_CALLBACK_ARGS)
Definition: THistSvc.cpp:1769
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Property< int > m_compressionLevel
Definition: THistSvc.h:159
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1024
StatusCode getHist_i(const std::string &name, T *&hist, bool quiet=false) const
Definition: THistSvc.icc:142
THistID(std::string &i, bool &t, TObject *o, TFile *f)
Definition: THistSvc.h:107
StatusCode finalize() override
Definition: THistSvc.cpp:199
bool operator<(THistID const &rhs) const
Definition: THistSvc.h:115
StatusCode regHist(const std::string &name) override
Definition: THistSvc.cpp:848
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:486
TObject * obj
Definition: THistSvc.h:99
StatusCode reinitialize() override
Definition: THistSvc.cpp:189
StatusCode regHist_i(T *hist, const std::string &name)
Definition: THistSvc.icc:17
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
uidMap m_uids
Definition: THistSvc.h:178
StatusCode readHist_i(const std::string &name, T *&hist) const
Definition: THistSvc.icc:242
Base class for all Incidents (computing events).
Definition: Incident.h:17
std::map< TObject *, THistID > objMap
Definition: THistSvc.h:175
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:182
StatusCode connect(const std::string &)
Definition: THistSvc.cpp:1217
StatusCode readHist(const std::string &name, TH1 *&) const
Definition: THistSvc.cpp:969
idMap m_ids
Definition: THistSvc.h:179
IFileMgr * p_fileMgr
Definition: THistSvc.h:193
std::set< std::string > m_alreadyConnectedOutFiles
list of already connected files.
Definition: THistSvc.h:171
StatusCode deReg(TObject *obj) override
Definition: THistSvc.cpp:795
StatusCode regTree(const std::string &name) override
Definition: THistSvc.cpp:869
StatusCode getHist(const std::string &name, TH1 *&) const override
Definition: THistSvc.cpp:916
std::map< std::string, std::string > m_sharedFiles
Definition: THistSvc.h:185
std::vector< std::string > getTrees() const override
Definition: THistSvc.cpp:943
std::map< std::string, THistID > uidMap
Definition: THistSvc.h:173
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
Definition: THistSvc.h:167
void setupInputFile(Gaudi::Details::PropertyBase &inputfile)
call-back method to handle input stream property
Definition: THistSvc.cpp:1050
void setupOutputFile(Gaudi::Details::PropertyBase &outputfile)
call-back method to handle output stream property
Definition: THistSvc.cpp:1082
StatusCode regGraph(const std::string &name) override
Definition: THistSvc.cpp:889
Gaudi::Property< int > m_autoFlush
Definition: THistSvc.h:155
THistSvc(const std::string &name, ISvcLocator *svc)
Definition: THistSvc.cpp:61
StatusCode io_reinit() override
callback method to reinitialize the internal state of the component for I/O purposes (e...
Definition: THistSvc.cpp:1643
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
streamMap m_fileStreams
Definition: THistSvc.h:183
void MergeRootFile(TDirectory *target, TDirectory *source)
Definition: THistSvc.cpp:1485
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1475
void updateFiles()
Definition: THistSvc.cpp:1108