source: trunk/src/ExRootTask.cc@ 22

Last change on this file since 22 was 2, checked in by Pavel Demin, 16 years ago

first commit

File size: 5.4 KB
RevLine 
[2]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 "TString.h"
20
21#include <iostream>
22
23const char *const kINIT = "0";
24const char *const kPROCESS = "1";
25const 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 Init();
65 }
66 else if(option == kPROCESS)
67 {
68 Process();
69 }
70 else if(option == kFINISH)
71 {
72 Finish();
73 }
74}
75
76//------------------------------------------------------------------------------
77
78void ExRootTask::InitTask()
79{
80 ExecuteTask(kINIT);
81}
82
83//------------------------------------------------------------------------------
84
85void ExRootTask::ProcessTask()
86{
87 ExecuteTask(kPROCESS);
88}
89
90//------------------------------------------------------------------------------
91
92void ExRootTask::FinishTask()
93{
94 ExecuteTask(kFINISH);
95}
96
97//------------------------------------------------------------------------------
98
99void ExRootTask::InitSubTasks()
100{
101 ExecuteTasks(kINIT);
102}
103
104//------------------------------------------------------------------------------
105
106void ExRootTask::ProcessSubTasks()
107{
108 ExecuteTasks(kPROCESS);
109}
110
111//------------------------------------------------------------------------------
112
113void ExRootTask::FinishSubTasks()
114{
115 ExecuteTasks(kFINISH);
116}
117
118//------------------------------------------------------------------------------
119
120void ExRootTask::Add(TTask *task)
121{
122 if(!task) return;
123
124 if(!task->IsA()->InheritsFrom(ExRootTask::Class()))
125 {
126 cout << "** ERROR: task '" << task->IsA()->GetName();
127 cout << "' does not inherit from ExRootTask" << endl;
128 return;
129 }
130
131 TTask::Add(task);
132}
133
134//------------------------------------------------------------------------------
135
136ExRootTask *ExRootTask::NewTask(TClass *cl, const char *taskName)
137{
138 if(!cl) return 0;
139
140 if(!cl->InheritsFrom(ExRootTask::Class()))
141 {
142 cout << "** ERROR: task '" << cl->GetName();
143 cout << "' does not inherit from ExRootTask" << endl;
144 return 0;
145 }
146
147 ExRootTask *task = static_cast<ExRootTask *>(cl->New());
148 task->SetName(taskName);
149 task->SetFolder(fFolder);
150 task->SetConfReader(fConfReader);
151
152 return task;
153}
154
155//------------------------------------------------------------------------------
156
157ExRootTask *ExRootTask::NewTask(const char *className, const char *taskName)
158{
159 TClass *cl = gROOT->GetClass(className);
160 if(!cl)
161 {
162 cout << "** ERROR: cannot find class '" << className << "'" << endl;
163 return 0;
164 }
165
166 return NewTask(cl, taskName);
167}
168
169//------------------------------------------------------------------------------
170
171const ExRootConfReader::ExRootTaskMap *ExRootTask::GetModules()
172{
173 if(fConfReader)
174 {
175 return fConfReader->GetModules();
176 }
177 else
178 {
179 return 0;
180 }
181}
182
183//------------------------------------------------------------------------------
184
185ExRootConfParam ExRootTask::GetParam(const char *name)
186{
187 if(fConfReader)
188 {
189 return fConfReader->GetParam(TString(GetName()) + "::" + name);
190 }
191 else
192 {
193 return ExRootConfParam(TString(GetName()) + "::" + name, 0, 0);
194 }
195}
196
197//------------------------------------------------------------------------------
198
199int ExRootTask::GetInt(const char *name, int defaultValue, int index)
200{
201 if(fConfReader)
202 {
203 return fConfReader->GetInt(TString(GetName()) + "::" + name, defaultValue, index);
204 }
205 else
206 {
207 return defaultValue;
208 }
209}
210
211//------------------------------------------------------------------------------
212
213long ExRootTask::GetLong(const char *name, long defaultValue, int index)
214{
215 if(fConfReader)
216 {
217 return fConfReader->GetLong(TString(GetName()) + "::" + name, defaultValue, index);
218 }
219 else
220 {
221 return defaultValue;
222 }
223}
224
225//------------------------------------------------------------------------------
226
227double ExRootTask::GetDouble(const char *name, double defaultValue, int index)
228{
229 if(fConfReader)
230 {
231 return fConfReader->GetDouble(TString(GetName()) + "::" + name, defaultValue, index);
232 }
233 else
234 {
235 return defaultValue;
236 }
237}
238
239//------------------------------------------------------------------------------
240
241bool ExRootTask::GetBool(const char *name, bool defaultValue, int index)
242{
243 if(fConfReader)
244 {
245 return fConfReader->GetBool(TString(GetName()) + "::" + name, defaultValue, index);
246 }
247 else
248 {
249 return defaultValue;
250 }
251}
252
253//------------------------------------------------------------------------------
254
255const char *ExRootTask::GetString(const char *name, const char *defaultValue, int index)
256{
257 if(fConfReader)
258 {
259 return fConfReader->GetString(TString(GetName()) + "::" + name, defaultValue, index);
260 }
261 else
262 {
263 return defaultValue;
264 }
265}
266
267
Note: See TracBrowser for help on using the repository browser.