| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 extends3<Service, ITHistSvc, IIncidentListener,
27 IIoComponent> {
28
29 public:
30
31 virtual StatusCode initialize();
32 virtual StatusCode reinitialize();
33 virtual StatusCode finalize();
34
35 virtual StatusCode regHist(const std::string& name);
36 virtual StatusCode regHist(const std::string& name, TH1*);
37 virtual StatusCode regHist(const std::string& name, TH2*);
38 virtual StatusCode regHist(const std::string& name, TH3*);
39
40 virtual StatusCode getHist(const std::string& name, TH1*&) const;
41 virtual StatusCode getHist(const std::string& name, TH2*&) const;
42 virtual StatusCode getHist(const std::string& name, TH3*&) const;
43
44 virtual StatusCode regTree(const std::string& name);
45 virtual StatusCode regTree(const std::string& name, TTree*);
46 virtual StatusCode getTree(const std::string& name, TTree*&) const;
47
48 virtual StatusCode regGraph(const std::string& name);
49 virtual StatusCode regGraph(const std::string& name, TGraph*);
50 virtual StatusCode getGraph(const std::string& name, TGraph*&) const;
51
52 virtual StatusCode deReg(TObject* obj);
53 virtual StatusCode deReg(const std::string& name);
54
55 virtual std::vector<std::string> getHists() const;
56 virtual std::vector<std::string> getTrees() const;
57 virtual std::vector<std::string> getGraphs() const;
58
59 virtual StatusCode getTHists(TDirectory *td, TList &,
60 bool recurse=false) const;
61 virtual StatusCode getTHists(const std::string& name, TList &,
62 bool recurse=false) const;
63
64 virtual StatusCode getTHists(TDirectory *td, TList &tl,
65 bool recurse=false, bool reg=false);
66 virtual StatusCode getTHists(const std::string& name, TList &tl,
67 bool recurse=false, bool reg=false);
68
69 virtual StatusCode getTTrees(TDirectory *td, TList &,
70 bool recurse=false) const;
71 virtual StatusCode getTTrees(const std::string& name, TList &,
72 bool recurse=false) const;
73
74 virtual StatusCode getTTrees(TDirectory *td, TList & tl,
75 bool recurse=false, bool reg=false);
76 virtual StatusCode getTTrees(const std::string& name, TList & tl,
77 bool recurse=false, bool reg=false);
78
79 virtual bool exists(const std::string& name) const;
80
81 THistSvc(const std::string& name, ISvcLocator *svc );
82
83 void handle(const Incident&);
84
85 // From IIoComponent
86 virtual StatusCode io_reinit ();
87
88
89 protected:
90
91 virtual ~THistSvc();
92
93 private:
94
95 class GlobalDirectoryRestore {
96 public:
97 GlobalDirectoryRestore();
98 ~GlobalDirectoryRestore();
99 private:
100 TDirectory* m_gd;
101 TFile* m_gf;
102 int m_ge;
103 };
104
105 enum Mode {
106 READ,
107 WRITE,
108 UPDATE,
109 APPEND,
110 SHARE,
111 INVALID
112 };
113
114 struct THistID {
115 std::string id;
116 bool temp;
117 TObject* obj;
118 TFile* file;
119 Mode mode;
120
121 THistID():id(""),temp(true),obj(0),file(0),mode(INVALID) {}
122 THistID(const THistID& rhs):id(rhs.id), temp(rhs.temp),
123 obj(rhs.obj), file(rhs.file), mode(rhs.mode) {}
124 THistID(std::string& i, bool& t, TObject* o, TFile* f)
125 : id(i), temp(t), obj(o), file(f), mode(INVALID){
126 }
127 THistID(std::string& i, bool& t, TObject* o, TFile* f, Mode m)
128 : id(i), temp(t), obj(o), file(f), mode(m){
129 }
130
131 bool operator < (THistID const &rhs) const {
132 return (obj < rhs.obj);
133 }
134 };
135
136
137 template <typename T>
138 StatusCode regHist_i(T* hist, const std::string& name);
139 template <typename T>
140 StatusCode getHist_i(const std::string& name, T*& hist, bool quiet=false) const;
141 template <typename T>
142 StatusCode readHist_i(const std::string& name, T*& hist) const;
143
144
145 StatusCode readHist(const std::string& name, TH1*&) const;
146 StatusCode readHist(const std::string& name, TH2*&) const;
147 StatusCode readHist(const std::string& name, TH3*&) const;
148 StatusCode readTree(const std::string& name, TTree*&) const;
149
150 void updateFiles();
151 StatusCode write();
152 StatusCode connect(const std::string&);
153 TDirectory* changeDir(const THistSvc::THistID& hid) const;
154 std::string dirname(std::string& dir) const;
155 void removeDoubleSlash(std::string&) const;
156
157 bool browseTDir(TDirectory* dir) const;
158
159 bool findStream(const std::string& name, std::string& root,
160 std::string& rem, TFile*& file) const;
161 void parseString(const std::string& id, std::string& root, std::string& rem)
162 const;
163
165 void setupInputFile( Property& inputfile );
166
168 void setupOutputFile( Property& outputfile );
169
170 void setupCompressionLevel( Property& cmp );
171
172 void copyFileLayout(TDirectory*, TDirectory*);
173
174 void MergeRootFile( TDirectory *target, TDirectory *source);
175
177
178 mutable MsgStream m_log;
179
180 StringArrayProperty m_inputfile, m_outputfile;
181 std::vector<std::string> m_Rstream, m_Wstream;
182 IntegerProperty m_autoSave, m_autoFlush, m_compressionLevel, m_maxFileSize;
183 BooleanProperty m_print;
184
187 std::set<std::string> m_alreadyConnectedInFiles;
188
191 std::set<std::string> m_alreadyConnectedOutFiles;
192
193
194 typedef std::map<std::string, THistID> uidMap;
195 typedef std::multimap<std::string, THistID> idMap;
196 typedef std::map<TObject*, THistID> objMap;
197 typedef std::multimap<std::string, std::string> streamMap;
198
199 uidMap m_uids;
200 idMap m_ids;
201 objMap m_tobjs;
202
203 std::map<std::string, std::pair<TFile*,Mode> > m_files; // stream->file
204 streamMap m_fileStreams; // fileName->streams
205
206 std::map<std::string, std::string > m_sharedFiles; // stream->filename of shared files
207
208 bool signaledStop;
209 bool m_delayConnect, m_okToConnect;
210
211 mutable std::string m_curstream;
212
213 IIncidentSvc* p_incSvc;
214 IFileMgr* p_fileMgr;
215
216 StatusCode rootOpenAction( FILEMGR_CALLBACK_ARGS );
217 StatusCode rootOpenErrAction( FILEMGR_CALLBACK_ARGS );
218
219 };
220
221 #ifndef GAUDISVC_THISTSVC_ICC
222 #include "THistSvc.icc"
223 #endif
224
225
226 #endif