Fork me on GitHub

source: git/external/ExRootAnalysis/ExRootTask.cc@ 9cd3a4d

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 9cd3a4d was cab38f6, checked in by Pavel Demin <pavel.demin@…>, 10 years ago

remove svn tags and fix formatting

  • Property mode set to 100644
File size: 6.7 KB
Line 
1
2/** \class ExRootTask
3 *
4 * Class handling output ROOT tree
5 *
6 * \author P. Demin - UCL, Louvain-la-Neuve
7 *
8 */
9
10#include "ExRootAnalysis/ExRootTask.h"
11#include "ExRootAnalysis/ExRootConfReader.h"
12
13#include "TROOT.h"
14#include "TClass.h"
15#include "TFolder.h"
16#include "TString.h"
17
18#include <iostream>
19#include <iomanip>
20#include <stdexcept>
21#include <sstream>
22
23static const char *const kINIT = "0";
24static const char *const kPROCESS = "1";
25static const char *const kFINISH = "2";
26
27using namespace std;
28
29ExRootTask::ExRootTask() :
30 TTask("", ""), fFolder(0), fConfReader(0)
31{
32}
33
34//------------------------------------------------------------------------------
35
36ExRootTask::~ExRootTask()
37{
38}
39
40//------------------------------------------------------------------------------
41
42void ExRootTask::Init()
43{
44}
45
46//------------------------------------------------------------------------------
47
48void ExRootTask::Process()
49{
50}
51
52//------------------------------------------------------------------------------
53
54void ExRootTask::Finish()
55{
56}
57
58//------------------------------------------------------------------------------
59
60void ExRootTask::Exec(Option_t *option)
61{
62 if(option == kINIT)
63 {
64 cout << left;
65 cout << setw(30) << "** INFO: initializing module";
66 cout << setw(25) << GetName() << endl;
67 Init();
68 }
69 else if(option == kPROCESS)
70 {
71 Process();
72 }
73 else if(option == kFINISH)
74 {
75 Finish();
76 }
77}
78
79//------------------------------------------------------------------------------
80
81void ExRootTask::InitTask()
82{
83 ExecuteTask(kINIT);
84}
85
86//------------------------------------------------------------------------------
87
88void ExRootTask::ProcessTask()
89{
90 ExecuteTask(kPROCESS);
91}
92
93//------------------------------------------------------------------------------
94
95void ExRootTask::FinishTask()
96{
97 ExecuteTask(kFINISH);
98}
99
100//------------------------------------------------------------------------------
101
102void ExRootTask::InitSubTasks()
103{
104 ExecuteTasks(kINIT);
105}
106
107//------------------------------------------------------------------------------
108
109void ExRootTask::ProcessSubTasks()
110{
111 ExecuteTasks(kPROCESS);
112}
113
114//------------------------------------------------------------------------------
115
116void ExRootTask::FinishSubTasks()
117{
118 ExecuteTasks(kFINISH);
119}
120
121//------------------------------------------------------------------------------
122
123void ExRootTask::Add(TTask *task)
124{
125 stringstream message;
126
127 if(!task) return;
128
129 if(!task->IsA()->InheritsFrom(ExRootTask::Class()))
130 {
131 message << "task '" << task->IsA()->GetName();
132 message << "' does not inherit from ExRootTask";
133 throw runtime_error(message.str());
134 }
135
136 TTask::Add(task);
137}
138
139//------------------------------------------------------------------------------
140
141ExRootTask *ExRootTask::NewTask(TClass *cl, const char *taskName)
142{
143 stringstream message;
144
145 if(!cl) return 0;
146
147 if(!cl->InheritsFrom(ExRootTask::Class()))
148 {
149 message << "task '" << cl->GetName();
150 message << "' does not inherit from ExRootTask";
151 throw runtime_error(message.str());
152 }
153
154 ExRootTask *task = static_cast<ExRootTask *>(cl->New());
155 task->SetName(taskName);
156 task->SetFolder(fFolder);
157 task->SetConfReader(fConfReader);
158
159 return task;
160}
161
162//------------------------------------------------------------------------------
163
164ExRootTask *ExRootTask::NewTask(const char *className, const char *taskName)
165{
166 stringstream message;
167 TClass *cl = gROOT->GetClass(className);
168 if(!cl)
169 {
170 message << "can't find class '" << className << "'";
171 throw runtime_error(message.str());
172 }
173
174 return NewTask(cl, taskName);
175}
176
177//------------------------------------------------------------------------------
178
179const ExRootConfReader::ExRootTaskMap *ExRootTask::GetModules()
180{
181 if(fConfReader)
182 {
183 return fConfReader->GetModules();
184 }
185 else
186 {
187 return 0;
188 }
189}
190
191//------------------------------------------------------------------------------
192
193ExRootConfParam ExRootTask::GetParam(const char *name)
194{
195 if(fConfReader)
196 {
197 return fConfReader->GetParam(TString(GetName()) + "::" + name);
198 }
199 else
200 {
201 return ExRootConfParam(TString(GetName()) + "::" + name, 0, 0);
202 }
203}
204
205//------------------------------------------------------------------------------
206
207int ExRootTask::GetInt(const char *name, int defaultValue, int index)
208{
209 if(fConfReader)
210 {
211 return fConfReader->GetInt(TString(GetName()) + "::" + name, defaultValue, index);
212 }
213 else
214 {
215 return defaultValue;
216 }
217}
218
219//------------------------------------------------------------------------------
220
221long ExRootTask::GetLong(const char *name, long defaultValue, int index)
222{
223 if(fConfReader)
224 {
225 return fConfReader->GetLong(TString(GetName()) + "::" + name, defaultValue, index);
226 }
227 else
228 {
229 return defaultValue;
230 }
231}
232
233//------------------------------------------------------------------------------
234
235double ExRootTask::GetDouble(const char *name, double defaultValue, int index)
236{
237 if(fConfReader)
238 {
239 return fConfReader->GetDouble(TString(GetName()) + "::" + name, defaultValue, index);
240 }
241 else
242 {
243 return defaultValue;
244 }
245}
246
247//------------------------------------------------------------------------------
248
249bool ExRootTask::GetBool(const char *name, bool defaultValue, int index)
250{
251 if(fConfReader)
252 {
253 return fConfReader->GetBool(TString(GetName()) + "::" + name, defaultValue, index);
254 }
255 else
256 {
257 return defaultValue;
258 }
259}
260
261//------------------------------------------------------------------------------
262
263const char *ExRootTask::GetString(const char *name, const char *defaultValue, int index)
264{
265 if(fConfReader)
266 {
267 return fConfReader->GetString(TString(GetName()) + "::" + name, defaultValue, index);
268 }
269 else
270 {
271 return defaultValue;
272 }
273}
274
275//------------------------------------------------------------------------------
276
277TFolder *ExRootTask::NewFolder(const char *name)
278{
279 stringstream message;
280 TFolder *folder;
281 folder = static_cast<TFolder *>(GetObject(name, TFolder::Class()));
282 if(!folder) folder = GetFolder()->AddFolder(name, "");
283 if(!folder)
284 {
285 message << "can't create folder '" << name << "'";
286 throw runtime_error(message.str());
287 }
288 folder = folder->AddFolder(GetName(), GetTitle());
289 if(!folder)
290 {
291 message << "can't create folder '";
292 message << name << "/" << GetName() << "'";
293 throw runtime_error(message.str());
294 }
295 return folder;
296}
297
298//------------------------------------------------------------------------------
299
300TObject *ExRootTask::GetObject(const char *name, TClass *cl)
301{
302 stringstream message;
303 TObject *object = GetFolder()->FindObject(name);
304 if(object && object->IsA() != cl)
305 {
306 message << "object '" << name;
307 message << "' is not of class '" << cl->GetName() << "'";
308 throw runtime_error(message.str());
309 }
310 return object;
311}
312
Note: See TracBrowser for help on using the repository browser.