Fork me on GitHub

source: git/external/ExRootAnalysis/ExRootTask.cc@ 5babc8b

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 5babc8b was d7d2da3, checked in by pavel <pavel@…>, 12 years ago

move branches/ModularDelphes to trunk

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