| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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"
5 #include "GaudiKernel/IIncidentListener.h"
6 #include "GaudiKernel/IIoComponent.h"
7 #include "GaudiKernel/ITHistSvc.h"
8 #include "GaudiKernel/MsgStream.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:
82 class GlobalDirectoryRestore
83 {
84 public:
85 GlobalDirectoryRestore();
86 ~GlobalDirectoryRestore();
87
88 private:
89 TDirectory* m_gd;
90 TFile* m_gf;
91 int m_ge;
92 };
93
94 enum Mode { READ, WRITE, UPDATE, APPEND, SHARE, INVALID };
95
96 struct THistID {
97 std::string id;
98 bool temp;
99 TObject* obj;
100 TFile* file;
101 Mode mode;
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
148 void setupCompressionLevel( Gaudi::Details::PropertyBase& cmp );
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};
160 Gaudi::Property<std::vector<std::string>> m_outputfile{this, "Output", {}};
161 Gaudi::Property<std::vector<std::string>> m_inputfile{this, "Input", {}};
162
163 std::vector<std::string> m_Rstream, m_Wstream;
164
167 std::set<std::string> m_alreadyConnectedInFiles;
168
171 std::set<std::string> m_alreadyConnectedOutFiles;
172
173 typedef std::map<std::string, THistID> uidMap;
174 typedef std::multimap<std::string, THistID> idMap;
175 typedef std::map<TObject*, THistID> objMap;
176 typedef std::multimap<std::string, std::string> streamMap;
177
178 uidMap m_uids;
179 idMap m_ids;
180 objMap m_tobjs;
181
182 std::map<std::string, std::pair<TFile*, Mode>> m_files; // stream->file
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
190 mutable std::string m_curstream;
191
192 IIncidentSvc* p_incSvc = nullptr;
193 IFileMgr* p_fileMgr = nullptr;
194
195 StatusCode rootOpenAction( FILEMGR_CALLBACK_ARGS );
196 StatusCode rootOpenErrAction( FILEMGR_CALLBACK_ARGS );
197 };
198
199 #ifndef GAUDISVC_THISTSVC_ICC
200 #include "THistSvc.icc"
201 #endif
202
203 #endif
THistSvc::THistID
Definition: THistSvc.h:96
THistSvc::m_delayConnect
bool m_delayConnect
Definition: THistSvc.h:188
THistSvc::getGraph
StatusCode getGraph(const std::string &name, TGraph *&) const override
Definition: THistSvc.cpp:954
THistSvc::initialize
StatusCode initialize() override
Definition: THistSvc.cpp:70
THistSvc::THistID::THistID
THistID(std::string &i, bool &t, TObject *o, TFile *f, Mode m)
Definition: THistSvc.h:110
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
THistSvc::INVALID
Definition: THistSvc.h:94
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
THistSvc::THistID::THistID
THistID(const THistID &rhs)
Definition: THistSvc.h:104
IFileMgr
Definition: IFileMgr.h:316
THistSvc::m_curstream
std::string m_curstream
Definition: THistSvc.h:190
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:314
MsgStream.h
THistSvc::THistID::file
TFile * file
Definition: THistSvc.h:100
THistSvc::getGraphs
std::vector< std::string > getGraphs() const override
Definition: THistSvc.cpp:958
THistSvc::exists
bool exists(const std::string &name) const override
Definition: THistSvc.cpp:1552
THistSvc::p_incSvc
IIncidentSvc * p_incSvc
Definition: THistSvc.h:192
THistSvc::findStream
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
Definition: THistSvc.cpp:985
THistSvc::getTHists
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:393
THistSvc::browseTDir
bool browseTDir(TDirectory *dir) const
Definition: THistSvc.cpp:344
THistSvc::APPEND
Definition: THistSvc.h:94
THistSvc::signaledStop
bool signaledStop
Definition: THistSvc.h:187
THistSvc::rootOpenAction
StatusCode rootOpenAction(FILEMGR_CALLBACK_ARGS)
Definition: THistSvc.cpp:1743
THistSvc::copyFileLayout
void copyFileLayout(TDirectory *, TDirectory *)
helper function to recursively copy the layout of a TFile into a new TFile
Definition: THistSvc.cpp:1609
THistSvc::changeDir
TDirectory * changeDir(const THistSvc::THistID &hid) const
Definition: THistSvc.cpp:1411
THistSvc::UPDATE
Definition: THistSvc.h:94
THistSvc::setupCompressionLevel
void setupCompressionLevel(Gaudi::Details::PropertyBase &cmp)
Definition: THistSvc.cpp:1041
std::map< std::string, THistID >
THistSvc::m_tobjs
objMap m_tobjs
Definition: THistSvc.h:180
THistSvc::m_outputfile
Gaudi::Property< std::vector< std::string > > m_outputfile
Definition: THistSvc.h:160
THistSvc::idMap
std::multimap< std::string, THistID > idMap
Definition: THistSvc.h:174
THistSvc::getHists
std::vector< std::string > getHists() const override
Definition: THistSvc.cpp:928
THistSvc::GlobalDirectoryRestore::m_gd
TDirectory * m_gd
Definition: THistSvc.h:89
THistSvc::write
StatusCode write()
Definition: THistSvc.cpp:1188
THistSvc::SHARE
Definition: THistSvc.h:94
THistSvc::m_Wstream
std::vector< std::string > m_Wstream
Definition: THistSvc.h:163
std::string
STL class.
FILEMGR_CALLBACK_ARGS
#define FILEMGR_CALLBACK_ARGS
Definition: IFileMgr.h:308
THistSvc::GlobalDirectoryRestore::m_ge
int m_ge
Definition: THistSvc.h:91
Service.h
THistSvc.icc
THistSvc::m_autoSave
Gaudi::Property< int > m_autoSave
Definition: THistSvc.h:154
THistSvc::THistID::id
std::string id
Definition: THistSvc.h:97
THistSvc::~THistSvc
~THistSvc() override=default
THistSvc::m_inputfile
Gaudi::Property< std::vector< std::string > > m_inputfile
Definition: THistSvc.h:161
THistSvc::dirname
std::string dirname(std::string &dir) const
Definition: THistSvc.cpp:1439
THistSvc::readTree
StatusCode readTree(const std::string &name, TTree *&) const
Definition: THistSvc.cpp:981
THistSvc::m_Rstream
std::vector< std::string > m_Rstream
Definition: THistSvc.h:163
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
THistSvc::GlobalDirectoryRestore::GlobalDirectoryRestore
GlobalDirectoryRestore()
Definition: THistSvc.cpp:1459
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:93
THistSvc::m_okToConnect
bool m_okToConnect
Definition: THistSvc.h:188
THistSvc::m_print
Gaudi::Property< bool > m_print
Definition: THistSvc.h:156
THistSvc::handle
void handle(const Incident &) override
Definition: THistSvc.cpp:1561
THistSvc::m_maxFileSize
Gaudi::Property< int > m_maxFileSize
Definition: THistSvc.h:157
THistSvc::streamMap
std::multimap< std::string, std::string > streamMap
Definition: THistSvc.h:176
IIoComponent.h
THistSvc::getTree
StatusCode getTree(const std::string &name, TTree *&) const override
Definition: THistSvc.cpp:939
THistSvc::GlobalDirectoryRestore::~GlobalDirectoryRestore
~GlobalDirectoryRestore()
Definition: THistSvc.cpp:1466
THistSvc::rootOpenErrAction
StatusCode rootOpenErrAction(FILEMGR_CALLBACK_ARGS)
Definition: THistSvc.cpp:1771
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
THistSvc::m_compressionLevel
Gaudi::Property< int > m_compressionLevel
Definition: THistSvc.h:159
THistSvc::parseString
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1024
THistSvc::getHist_i
StatusCode getHist_i(const std::string &name, T *&hist, bool quiet=false) const
Definition: THistSvc.icc:142
THistSvc::THistID::THistID
THistID(std::string &i, bool &t, TObject *o, TFile *f)
Definition: THistSvc.h:107
THistSvc::finalize
StatusCode finalize() override
Definition: THistSvc.cpp:199
THistSvc::GlobalDirectoryRestore::m_gf
TFile * m_gf
Definition: THistSvc.h:90
THistSvc::THistID::operator<
bool operator<(THistID const &rhs) const
Definition: THistSvc.h:115
THistSvc::regHist
StatusCode regHist(const std::string &name) override
Definition: THistSvc.cpp:848
THistSvc::Mode
Mode
Definition: THistSvc.h:94
std::multimap< std::string, THistID >
THistSvc::getTTrees
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:486
std::set< std::string >
THistSvc::THistID::obj
TObject * obj
Definition: THistSvc.h:99
std::vector< std::string >
THistSvc::reinitialize
StatusCode reinitialize() override
Definition: THistSvc.cpp:189
THistSvc::regHist_i
StatusCode regHist_i(T *hist, const std::string &name)
Definition: THistSvc.icc:17
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
THistSvc::m_uids
uidMap m_uids
Definition: THistSvc.h:178
THistSvc::readHist_i
StatusCode readHist_i(const std::string &name, T *&hist) const
Definition: THistSvc.icc:242
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
THistSvc::objMap
std::map< TObject *, THistID > objMap
Definition: THistSvc.h:175
THistSvc::m_files
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:182
THistSvc::READ
Definition: THistSvc.h:94
THistSvc::connect
StatusCode connect(const std::string &)
Definition: THistSvc.cpp:1217
THistSvc::readHist
StatusCode readHist(const std::string &name, TH1 *&) const
Definition: THistSvc.cpp:969
THistSvc::m_ids
idMap m_ids
Definition: THistSvc.h:179
THistSvc::p_fileMgr
IFileMgr * p_fileMgr
Definition: THistSvc.h:193
THistSvc::m_alreadyConnectedOutFiles
std::set< std::string > m_alreadyConnectedOutFiles
list of already connected files.
Definition: THistSvc.h:171
gaudiComponentHelp.root
root
Definition: gaudiComponentHelp.py:14
IFileMgr.h
THistSvc::deReg
StatusCode deReg(TObject *obj) override
Definition: THistSvc.cpp:795
IIncidentListener.h
THistSvc::regTree
StatusCode regTree(const std::string &name) override
Definition: THistSvc.cpp:869
THistSvc::getHist
StatusCode getHist(const std::string &name, TH1 *&) const override
Definition: THistSvc.cpp:916
THistSvc::m_sharedFiles
std::map< std::string, std::string > m_sharedFiles
Definition: THistSvc.h:185
THistSvc::THistID::temp
bool temp
Definition: THistSvc.h:98
THistSvc::getTrees
std::vector< std::string > getTrees() const override
Definition: THistSvc.cpp:943
THistSvc::uidMap
std::map< std::string, THistID > uidMap
Definition: THistSvc.h:173
THistSvc::WRITE
Definition: THistSvc.h:94
THistSvc::THistID::mode
Mode mode
Definition: THistSvc.h:101
THistSvc::m_alreadyConnectedInFiles
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
Definition: THistSvc.h:167
THistSvc::setupInputFile
void setupInputFile(Gaudi::Details::PropertyBase &inputfile)
call-back method to handle input stream property
Definition: THistSvc.cpp:1050
THistSvc::setupOutputFile
void setupOutputFile(Gaudi::Details::PropertyBase &outputfile)
call-back method to handle output stream property
Definition: THistSvc.cpp:1082
THistSvc::regGraph
StatusCode regGraph(const std::string &name) override
Definition: THistSvc.cpp:889
THistSvc::m_autoFlush
Gaudi::Property< int > m_autoFlush
Definition: THistSvc.h:155
THistSvc::THistSvc
THistSvc(const std::string &name, ISvcLocator *svc)
Definition: THistSvc.cpp:61
THistSvc::io_reinit
StatusCode io_reinit() override
callback method to reinitialize the internal state of the component for I/O purposes (e...
Definition: THistSvc.cpp:1643
THistSvc::THistID::THistID
THistID()
Definition: THistSvc.h:103
THistSvc::GlobalDirectoryRestore
Definition: THistSvc.h:82
IIncidentSvc
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
THistSvc::m_fileStreams
streamMap m_fileStreams
Definition: THistSvc.h:183
THistSvc::MergeRootFile
void MergeRootFile(TDirectory *target, TDirectory *source)
Definition: THistSvc.cpp:1485
ITHistSvc.h
THistSvc::removeDoubleSlash
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1475
THistSvc
Definition: THistSvc.h:25
THistSvc::updateFiles
void updateFiles()
Definition: THistSvc.cpp:1108