| The Gaudi Framework v27r1

- 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/Service.h"
5 #include "GaudiKernel/ITHistSvc.h"
6 #include "GaudiKernel/IFileMgr.h"
7 #include "GaudiKernel/IIncidentListener.h"
8 #include "GaudiKernel/IIoComponent.h"
9 #include "GaudiKernel/MsgStream.h"
10
11 #include "TObject.h"
12 #include "TH1.h"
13 #include "TH2.h"
14 #include "TH3.h"
15 #include "TTree.h"
16 #include "TGraph.h"
17 #include "TList.h"
18
19
20 #include <vector>
21 #include <string>
22 #include <set>
23 #include <map>
24
25 class IIncidentSvc;
26 class THistSvc: public extends<Service,
27 ITHistSvc,
28 IIncidentListener,
29 IIoComponent> {
30
31 public:
32
33 StatusCode initialize() override;
34 StatusCode reinitialize() override;
35 StatusCode finalize() override;
36
37 StatusCode regHist(const std::string& name) override;
38 StatusCode regHist(const std::string& name, TH1*) override;
39 StatusCode regHist(const std::string& name, TH2*) override;
40 StatusCode regHist(const std::string& name, TH3*) override;
41
42 StatusCode getHist(const std::string& name, TH1*&) const override;
43 StatusCode getHist(const std::string& name, TH2*&) const override;
44 StatusCode getHist(const std::string& name, TH3*&) const override;
45
46 StatusCode regTree(const std::string& name) override;
47 StatusCode regTree(const std::string& name, TTree*) override;
48 StatusCode getTree(const std::string& name, TTree*&) const override;
49
50 StatusCode regGraph(const std::string& name) override;
51 StatusCode regGraph(const std::string& name, TGraph*) override;
52 StatusCode getGraph(const std::string& name, TGraph*&) const override;
53
54 StatusCode deReg(TObject* obj) override;
55 StatusCode deReg(const std::string& name) override;
56
57 std::vector<std::string> getHists() const override;
58 std::vector<std::string> getTrees() const override;
59 std::vector<std::string> getGraphs() const override;
60
61 StatusCode getTHists(TDirectory *td, TList &,
62 bool recurse=false) const override;
63 StatusCode getTHists(const std::string& name, TList &,
64 bool recurse=false) const override;
65
66 StatusCode getTHists(TDirectory *td, TList &tl,
67 bool recurse=false, bool reg=false) override;
68 StatusCode getTHists(const std::string& name, TList &tl,
69 bool recurse=false, bool reg=false) override;
70
71 StatusCode getTTrees(TDirectory *td, TList &,
72 bool recurse=false) const override;
73 StatusCode getTTrees(const std::string& name, TList &,
74 bool recurse=false) const override;
75
76 StatusCode getTTrees(TDirectory *td, TList & tl,
77 bool recurse=false, bool reg=false) override;
78 StatusCode getTTrees(const std::string& name, TList & tl,
79 bool recurse=false, bool reg=false) override;
80
81 bool exists(const std::string& name) const override;
82
83 THistSvc(const std::string& name, ISvcLocator *svc );
84
85 void handle(const Incident&) override;
86
87 // From IIoComponent
88 StatusCode io_reinit () override;
89
90
91 protected:
92
93 ~THistSvc() override = default;
94
95 private:
96
97 class GlobalDirectoryRestore {
98 public:
99 GlobalDirectoryRestore();
100 ~GlobalDirectoryRestore();
101 private:
102 TDirectory* m_gd;
103 TFile* m_gf;
104 int m_ge;
105 };
106
107 enum Mode {
108 READ,
109 WRITE,
110 UPDATE,
111 APPEND,
112 SHARE,
113 INVALID
114 };
115
116 struct THistID {
117 std::string id;
118 bool temp;
119 TObject* obj;
120 TFile* file;
121 Mode mode;
122
123 THistID():id(""),temp(true),obj(0),file(0),mode(INVALID) {}
124 THistID(const THistID& rhs):id(rhs.id), temp(rhs.temp),
125 obj(rhs.obj), file(rhs.file), mode(rhs.mode) {}
126 THistID(std::string& i, bool& t, TObject* o, TFile* f)
127 : id(i), temp(t), obj(o), file(f), mode(INVALID){
128 }
129 THistID(std::string& i, bool& t, TObject* o, TFile* f, Mode m)
130 : id(i), temp(t), obj(o), file(f), mode(m){
131 }
132
133 bool operator < (THistID const &rhs) const {
134 return (obj < rhs.obj);
135 }
136 };
137
138
139 template <typename T>
140 StatusCode regHist_i(T* hist, const std::string& name);
141 template <typename T>
142 StatusCode getHist_i(const std::string& name, T*& hist, bool quiet=false) const;
143 template <typename T>
144 StatusCode readHist_i(const std::string& name, T*& hist) const;
145
146
147 StatusCode readHist(const std::string& name, TH1*&) const;
148 StatusCode readHist(const std::string& name, TH2*&) const;
149 StatusCode readHist(const std::string& name, TH3*&) const;
150 StatusCode readTree(const std::string& name, TTree*&) const;
151
152 void updateFiles();
153 StatusCode write();
154 StatusCode connect(const std::string&);
155 TDirectory* changeDir(const THistSvc::THistID& hid) const;
156 std::string dirname(std::string& dir) const;
157 void removeDoubleSlash(std::string&) const;
158
159 bool browseTDir(TDirectory* dir) const;
160
161 bool findStream(const std::string& name, std::string& root,
162 std::string& rem, TFile*& file) const;
163 void parseString(const std::string& id, std::string& root, std::string& rem)
164 const;
165
167 void setupInputFile( Property& inputfile );
168
170 void setupOutputFile( Property& outputfile );
171
172 void setupCompressionLevel( Property& cmp );
173
174 void copyFileLayout(TDirectory*, TDirectory*);
175
176 void MergeRootFile( TDirectory *target, TDirectory *source);
177
179
180 mutable MsgStream m_log;
181
182 StringArrayProperty m_inputfile, m_outputfile;
183 std::vector<std::string> m_Rstream, m_Wstream;
184 IntegerProperty m_autoSave, m_autoFlush, m_compressionLevel, m_maxFileSize;
185 BooleanProperty m_print;
186
189 std::set<std::string> m_alreadyConnectedInFiles;
190
193 std::set<std::string> m_alreadyConnectedOutFiles;
194
195
196 typedef std::map<std::string, THistID> uidMap;
197 typedef std::multimap<std::string, THistID> idMap;
198 typedef std::map<TObject*, THistID> objMap;
199 typedef std::multimap<std::string, std::string> streamMap;
200
201 uidMap m_uids;
202 idMap m_ids;
203 objMap m_tobjs;
204
205 std::map<std::string, std::pair<TFile*,Mode> > m_files; // stream->file
206 streamMap m_fileStreams; // fileName->streams
207
208 std::map<std::string, std::string > m_sharedFiles; // stream->filename of shared files
209
210 bool signaledStop = false;
211 bool m_delayConnect = false, m_okToConnect = false;
212
213 mutable std::string m_curstream;
214
215 IIncidentSvc* p_incSvc = nullptr;
216 IFileMgr* p_fileMgr = nullptr;
217
218 StatusCode rootOpenAction( FILEMGR_CALLBACK_ARGS );
219 StatusCode rootOpenErrAction( FILEMGR_CALLBACK_ARGS );
220
221 };
222
223 #ifndef GAUDISVC_THISTSVC_ICC
224 #include "THistSvc.icc"
225 #endif
226
227
228 #endif
THistSvc::THistID
Definition: THistSvc.h:116
THistSvc::m_delayConnect
bool m_delayConnect
Definition: THistSvc.h:211
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
THistSvc::getTrees
std::vector< std::string > getTrees() const override
Definition: THistSvc.cpp:1095
THistSvc::initialize
StatusCode initialize() override
Definition: THistSvc.cpp:78
THistSvc::THistID::THistID
THistID(std::string &i, bool &t, TObject *o, TFile *f, Mode m)
Definition: THistSvc.h:129
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:113
THistSvc::THistID::THistID
THistID(const THistID &rhs)
Definition: THistSvc.h:124
IFileMgr
Definition: IFileMgr.h:316
THistSvc::m_curstream
std::string m_curstream
Definition: THistSvc.h:213
THistSvc::m_autoFlush
IntegerProperty m_autoFlush
Definition: THistSvc.h:184
MsgStream.h
THistSvc::THistID::file
TFile * file
Definition: THistSvc.h:120
THistSvc::m_autoSave
IntegerProperty m_autoSave
Definition: THistSvc.h:184
THistSvc::p_incSvc
IIncidentSvc * p_incSvc
Definition: THistSvc.h:215
THistSvc::findStream
bool findStream(const std::string &name, std::string &root, std::string &rem, TFile *&file) const
Definition: THistSvc.cpp:1161
THistSvc::browseTDir
bool browseTDir(TDirectory *dir) const
Definition: THistSvc.cpp:405
THistSvc::APPEND
Definition: THistSvc.h:111
THistSvc::getTTrees
StatusCode getTTrees(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:559
THistSvc::getGraph
StatusCode getGraph(const std::string &name, TGraph *&) const override
Definition: THistSvc.cpp:1111
THistSvc::signaledStop
bool signaledStop
Definition: THistSvc.h:210
THistSvc::setupCompressionLevel
void setupCompressionLevel(Property &cmp)
Definition: THistSvc.cpp:1223
THistSvc::rootOpenAction
StatusCode rootOpenAction(FILEMGR_CALLBACK_ARGS)
Definition: THistSvc.cpp:2030
THistSvc::copyFileLayout
void copyFileLayout(TDirectory *, TDirectory *)
helper function to recursively copy the layout of a TFile into a new TFile
Definition: THistSvc.cpp:1872
THistSvc::changeDir
TDirectory * changeDir(const THistSvc::THistID &hid) const
Definition: THistSvc.cpp:1655
THistSvc::UPDATE
Definition: THistSvc.h:110
std::map< std::string, THistID >
THistSvc::m_tobjs
objMap m_tobjs
Definition: THistSvc.h:203
THistSvc::idMap
std::multimap< std::string, THistID > idMap
Definition: THistSvc.h:197
THistSvc::getTHists
StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
Definition: THistSvc.cpp:451
THistSvc::GlobalDirectoryRestore::m_gd
TDirectory * m_gd
Definition: THistSvc.h:102
THistSvc::write
StatusCode write()
Definition: THistSvc.cpp:1399
THistSvc::SHARE
Definition: THistSvc.h:112
THistSvc::m_Wstream
std::vector< std::string > m_Wstream
Definition: THistSvc.h:183
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:104
SimpleProperty< std::vector< std::string > >
THistSvc::m_inputfile
StringArrayProperty m_inputfile
Definition: THistSvc.h:182
Service.h
THistSvc::m_print
BooleanProperty m_print
Definition: THistSvc.h:185
THistSvc.icc
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
THistSvc::m_outputfile
StringArrayProperty m_outputfile
Definition: THistSvc.h:182
THistSvc::THistID::id
std::string id
Definition: THistSvc.h:117
THistSvc::~THistSvc
~THistSvc() override=default
THistSvc::setupOutputFile
void setupOutputFile(Property &outputfile)
call-back method to handle output stream property
Definition: THistSvc.cpp:1275
THistSvc::dirname
std::string dirname(std::string &dir) const
Definition: THistSvc.cpp:1684
THistSvc::readTree
StatusCode readTree(const std::string &name, TTree *&) const
Definition: THistSvc.cpp:1154
THistSvc::getTree
StatusCode getTree(const std::string &name, TTree *&) const override
Definition: THistSvc.cpp:1088
THistSvc::m_Rstream
std::vector< std::string > m_Rstream
Definition: THistSvc.h:183
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
THistSvc::GlobalDirectoryRestore::GlobalDirectoryRestore
GlobalDirectoryRestore()
Definition: THistSvc.cpp:1705
THistSvc::m_files
std::map< std::string, std::pair< TFile *, Mode > > m_files
Definition: THistSvc.h:205
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:93
THistSvc::m_okToConnect
bool m_okToConnect
Definition: THistSvc.h:211
THistSvc::handle
void handle(const Incident &) override
Definition: THistSvc.cpp:1816
THistSvc::m_maxFileSize
IntegerProperty m_maxFileSize
Definition: THistSvc.h:184
THistSvc::getHists
std::vector< std::string > getHists() const override
Definition: THistSvc.cpp:1073
THistSvc::streamMap
std::multimap< std::string, std::string > streamMap
Definition: THistSvc.h:199
IIoComponent.h
THistSvc::GlobalDirectoryRestore::~GlobalDirectoryRestore
~GlobalDirectoryRestore()
Definition: THistSvc.cpp:1711
THistSvc::rootOpenErrAction
StatusCode rootOpenErrAction(FILEMGR_CALLBACK_ARGS)
Definition: THistSvc.cpp:2062
THistSvc::parseString
void parseString(const std::string &id, std::string &root, std::string &rem) const
Definition: THistSvc.cpp:1205
ana.file
list file
Definition: ana.py:160
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:126
THistSvc::finalize
StatusCode finalize() override
Definition: THistSvc.cpp:241
THistSvc::m_compressionLevel
IntegerProperty m_compressionLevel
Definition: THistSvc.h:184
THistSvc::GlobalDirectoryRestore::m_gf
TFile * m_gf
Definition: THistSvc.h:103
THistSvc::THistID::operator<
bool operator<(THistID const &rhs) const
Definition: THistSvc.h:133
THistSvc::regHist
StatusCode regHist(const std::string &name) override
Definition: THistSvc.cpp:974
THistSvc::Mode
Mode
Definition: THistSvc.h:107
std::multimap< std::string, THistID >
THistSvc::m_sharedFiles
std::map< std::string, std::string > m_sharedFiles
Definition: THistSvc.h:208
std::set< std::string >
THistSvc::THistID::obj
TObject * obj
Definition: THistSvc.h:119
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
std::vector< std::string >
THistSvc::reinitialize
StatusCode reinitialize() override
Definition: THistSvc.cpp:230
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:201
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:198
THistSvc::READ
Definition: THistSvc.h:108
THistSvc::connect
StatusCode connect(const std::string &)
Definition: THistSvc.cpp:1431
THistSvc::readHist
StatusCode readHist(const std::string &name, TH1 *&) const
Definition: THistSvc.cpp:1133
THistSvc::m_ids
idMap m_ids
Definition: THistSvc.h:202
THistSvc::p_fileMgr
IFileMgr * p_fileMgr
Definition: THistSvc.h:216
IOTest.root
tuple root
Definition: IOTest.py:42
THistSvc::m_alreadyConnectedOutFiles
std::set< std::string > m_alreadyConnectedOutFiles
list of already connected files.
Definition: THistSvc.h:193
IFileMgr.h
THistSvc::deReg
StatusCode deReg(TObject *obj) override
Definition: THistSvc.cpp:913
IIncidentListener.h
THistSvc::regTree
StatusCode regTree(const std::string &name) override
Definition: THistSvc.cpp:1004
THistSvc::exists
bool exists(const std::string &name) const override
Definition: THistSvc.cpp:1806
THistSvc::THistID::temp
bool temp
Definition: THistSvc.h:118
THistSvc::uidMap
std::map< std::string, THistID > uidMap
Definition: THistSvc.h:196
THistSvc::m_log
MsgStream m_log
Definition: THistSvc.h:180
THistSvc::WRITE
Definition: THistSvc.h:109
THistSvc::THistID::mode
Mode mode
Definition: THistSvc.h:121
THistSvc::m_alreadyConnectedInFiles
std::set< std::string > m_alreadyConnectedInFiles
list of already connected files.
Definition: THistSvc.h:189
THistSvc::regGraph
StatusCode regGraph(const std::string &name) override
Definition: THistSvc.cpp:1024
THistSvc::THistSvc
THistSvc(const std::string &name, ISvcLocator *svc)
Definition: THistSvc.cpp:62
THistSvc::setupInputFile
void setupInputFile(Property &inputfile)
call-back method to handle input stream property
Definition: THistSvc.cpp:1236
ana.i
list i
Definition: ana.py:128
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:1912
THistSvc::getHist
StatusCode getHist(const std::string &name, TH1 *&) const override
Definition: THistSvc.cpp:1052
THistSvc::THistID::THistID
THistID()
Definition: THistSvc.h:123
THistSvc::GlobalDirectoryRestore
Definition: THistSvc.h:97
IIncidentSvc
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:21
THistSvc::m_fileStreams
streamMap m_fileStreams
Definition: THistSvc.h:206
THistSvc::MergeRootFile
void MergeRootFile(TDirectory *target, TDirectory *source)
Definition: THistSvc.cpp:1730
ITHistSvc.h
THistSvc::removeDoubleSlash
void removeDoubleSlash(std::string &) const
Definition: THistSvc.cpp:1720
THistSvc
Definition: THistSvc.h:26
THistSvc::updateFiles
void updateFiles()
Definition: THistSvc.cpp:1305
THistSvc::getGraphs
std::vector< std::string > getGraphs() const override
Definition: THistSvc.cpp:1118