1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | // //
|
---|
27 | // MTask //
|
---|
28 | // //
|
---|
29 | // Base class for all tasks which can perfomed in a tasklist //
|
---|
30 | // For each event processed in the eventloop all the different //
|
---|
31 | // tasks in the tasklist will be processed. //
|
---|
32 | // //
|
---|
33 | // So all tasks must inherit from this baseclass. //
|
---|
34 | // //
|
---|
35 | // The inheritance from MInputStreamID is used to indicate the //
|
---|
36 | // type of event that this task is for. If it is "All" it is executed //
|
---|
37 | // independantly of the actual ID of the task list. //
|
---|
38 | // //
|
---|
39 | // Inside this abstract class, there are three fundamental function: //
|
---|
40 | // //
|
---|
41 | // - PreProcess(): executed before the eventloop starts. Here you //
|
---|
42 | // can initiate different things, open files, etc. //
|
---|
43 | // As an argument this function gets a pointer to the //
|
---|
44 | // parameter list. You can stop the execution by //
|
---|
45 | // returning kFALSE instead of kTRUE. If an error //
|
---|
46 | // occured and you return kFALSE make sure, that //
|
---|
47 | // any action is closed correctly and all newly //
|
---|
48 | // created object are deleted. The PostProcess in //
|
---|
49 | // such a case won't be executed by the Tasklist or //
|
---|
50 | // Eventloop. //
|
---|
51 | // //
|
---|
52 | // - Process(): executed for each event in the eventloop. Do it //
|
---|
53 | // one task after the other (as they occur in the //
|
---|
54 | // tasklist). Only the tasks with a Stream ID //
|
---|
55 | // which matches the actual ID of the tasklist //
|
---|
56 | // are executed. A task can return kFALSE to //
|
---|
57 | // stop the execuition of the tasklist or //
|
---|
58 | // kCONTINUE to skip the pending tasks. //
|
---|
59 | // //
|
---|
60 | // - PostProcess(): executed after the eventloop. Here you can close //
|
---|
61 | // output files, start display of the run parameter, //
|
---|
62 | // etc. PostProcess should be executed only if //
|
---|
63 | // PreProcess was successfull (returned kTRUE) //
|
---|
64 | // //
|
---|
65 | /////////////////////////////////////////////////////////////////////////////
|
---|
66 |
|
---|
67 | #include "MTask.h"
|
---|
68 |
|
---|
69 | #include "MLog.h"
|
---|
70 | #include "MLogManip.h"
|
---|
71 |
|
---|
72 | #include "MFilter.h"
|
---|
73 | #include "MGGroupFrame.h"
|
---|
74 |
|
---|
75 | ClassImp(MTask);
|
---|
76 |
|
---|
77 | MTask::MTask(const char *name, const char *title)
|
---|
78 | : fFilter(NULL), fIsPreprocessed(kFALSE), fNumExecutions(0)
|
---|
79 | {
|
---|
80 | fName = name ? name : "MTask";
|
---|
81 | fTitle = title ? title : "Base class for all tasks (dummy task).";
|
---|
82 |
|
---|
83 | fListOfBranches = new TList;
|
---|
84 | fListOfBranches->SetOwner();
|
---|
85 | }
|
---|
86 |
|
---|
87 | MTask::~MTask()
|
---|
88 | {
|
---|
89 | delete fListOfBranches;
|
---|
90 | }
|
---|
91 |
|
---|
92 | // --------------------------------------------------------------------------
|
---|
93 | //
|
---|
94 | // This adds a branch to the list for the auto enabeling schmeme.
|
---|
95 | // This makes it possible for MReadTree to decide which branches
|
---|
96 | // are really needed for the eventloop. Only the necessary branches
|
---|
97 | // are read from disk which speeds up the calculation enormously.
|
---|
98 | //
|
---|
99 | // You can use TRegExp expressions like "*.fEnergy", but the
|
---|
100 | // recommended method is to call this function for exactly all
|
---|
101 | // branches you want to have, eg:
|
---|
102 | // AddToBranchList("MMcTrig.fNumFirstLevel");
|
---|
103 | // AddToBranchList("MMcTrig;1.fNumFirstLevel");
|
---|
104 | // AddToBranchList("MMcTrig;2.fNumFirstLevel");
|
---|
105 | //
|
---|
106 | // We agreed on the convetion, that all branches are stored with
|
---|
107 | // a trailing dot '.' so that always the Master Branch name
|
---|
108 | // (eg. MMcTrig) is part of the branch name.
|
---|
109 | //
|
---|
110 | // Remark: The common place to call AddToBranchList is the
|
---|
111 | // constructor of the derived classes (tasks)
|
---|
112 | //
|
---|
113 | void MTask::AddToBranchList(const char *b)
|
---|
114 | {
|
---|
115 | TNamed *name = new TNamed(b, "");
|
---|
116 | fListOfBranches->Add(name);
|
---|
117 | }
|
---|
118 |
|
---|
119 | // --------------------------------------------------------------------------
|
---|
120 | //
|
---|
121 | // Copy constructor.
|
---|
122 | //
|
---|
123 | MTask::MTask(MTask &t)
|
---|
124 | {
|
---|
125 | fFilter = t.fFilter;
|
---|
126 | fListOfBranches->AddAll(t.fListOfBranches);
|
---|
127 | }
|
---|
128 |
|
---|
129 | // --------------------------------------------------------------------------
|
---|
130 | //
|
---|
131 | // Mapper function for PreProcess.
|
---|
132 | // Sets the preprocessed flag dependend on the return value of PreProcess.
|
---|
133 | //
|
---|
134 | Bool_t MTask::CallPreProcess(MParList *plist)
|
---|
135 | {
|
---|
136 | fNumExecutions = 0;
|
---|
137 |
|
---|
138 | if (!PreProcess(plist))
|
---|
139 | return kFALSE;
|
---|
140 |
|
---|
141 | fIsPreprocessed = kTRUE;
|
---|
142 | return kTRUE;
|
---|
143 | }
|
---|
144 |
|
---|
145 | // --------------------------------------------------------------------------
|
---|
146 | //
|
---|
147 | // Mapper function for Process.
|
---|
148 | // Executes Process dependent on the existance of a filter and its possible
|
---|
149 | // return value.
|
---|
150 | // If Process is executed, the execution counter is increased.
|
---|
151 | //
|
---|
152 | Bool_t MTask::CallProcess()
|
---|
153 | {
|
---|
154 | //
|
---|
155 | // Check for the existance of a filter. If a filter is existing
|
---|
156 | // check for its value. If the value is kFALSE don't execute
|
---|
157 | // this task.
|
---|
158 | //
|
---|
159 | const Bool_t exec = fFilter ? fFilter->IsExpressionTrue() : kTRUE;
|
---|
160 |
|
---|
161 | if (!exec)
|
---|
162 | return kTRUE;
|
---|
163 |
|
---|
164 | fNumExecutions++;
|
---|
165 | return Process();
|
---|
166 | }
|
---|
167 |
|
---|
168 | // --------------------------------------------------------------------------
|
---|
169 | //
|
---|
170 | // Mapper function for PreProcess.
|
---|
171 | // Calls Postprocess dependent on the state of the preprocessed flag,
|
---|
172 | // resets this flag.
|
---|
173 | //
|
---|
174 | Bool_t MTask::CallPostProcess()
|
---|
175 | {
|
---|
176 | if (!fIsPreprocessed)
|
---|
177 | return kTRUE;
|
---|
178 |
|
---|
179 | fIsPreprocessed = kFALSE;
|
---|
180 |
|
---|
181 | return PostProcess();
|
---|
182 | }
|
---|
183 |
|
---|
184 | // --------------------------------------------------------------------------
|
---|
185 | //
|
---|
186 | // This is reinit function
|
---|
187 | //
|
---|
188 | // This function is called asynchronously if the tasks in the tasklist need
|
---|
189 | // reinitialization. This for example happens when the eventloop switches
|
---|
190 | // from one group of events to another one (eg. switching between events
|
---|
191 | // of different runs means reading a new run header and a new run header
|
---|
192 | // may mean that some value must be reinitialized)
|
---|
193 | //
|
---|
194 | // the virtual implementation returns kTRUE
|
---|
195 | //
|
---|
196 | Bool_t MTask::ReInit(MParList *pList)
|
---|
197 | {
|
---|
198 | return kTRUE;
|
---|
199 | }
|
---|
200 |
|
---|
201 | // --------------------------------------------------------------------------
|
---|
202 | //
|
---|
203 | // This is processed before the eventloop starts
|
---|
204 | //
|
---|
205 | // It is the job of the PreProcess to connect the tasks
|
---|
206 | // with the right container in the parameter list.
|
---|
207 | //
|
---|
208 | // the virtual implementation returns kTRUE
|
---|
209 | //
|
---|
210 | Bool_t MTask::PreProcess(MParList *pList)
|
---|
211 | {
|
---|
212 | return kTRUE;
|
---|
213 | }
|
---|
214 |
|
---|
215 | // --------------------------------------------------------------------------
|
---|
216 | //
|
---|
217 | // This is processed for every event in the eventloop
|
---|
218 | //
|
---|
219 | // the virtual implementation returns kTRUE
|
---|
220 | //
|
---|
221 | Bool_t MTask::Process()
|
---|
222 | {
|
---|
223 | return kTRUE;
|
---|
224 | }
|
---|
225 |
|
---|
226 | // --------------------------------------------------------------------------
|
---|
227 | //
|
---|
228 | // This is processed after the eventloop starts
|
---|
229 | //
|
---|
230 | // the virtual implementation returns kTRUE
|
---|
231 | //
|
---|
232 | Bool_t MTask::PostProcess()
|
---|
233 | {
|
---|
234 | return kTRUE;
|
---|
235 | }
|
---|
236 |
|
---|
237 | // --------------------------------------------------------------------------
|
---|
238 | //
|
---|
239 | // Prints the number of times this task has been processed.
|
---|
240 | // For convinience the lvl argument results in a number of spaces at the
|
---|
241 | // beginning of the line. So that the structur of a tasklist can be
|
---|
242 | // identified.
|
---|
243 | //
|
---|
244 | void MTask::PrintStatistics(const Int_t lvl) const
|
---|
245 | {
|
---|
246 | *fLog << all << setw(lvl) << " " << GetDescriptor() << "\t";
|
---|
247 | *fLog << dec << fNumExecutions << endl;
|
---|
248 | }
|
---|
249 |
|
---|