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 (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 <TOrdCollection.h>
|
---|
70 |
|
---|
71 | #include "MLog.h"
|
---|
72 | #include "MLogManip.h"
|
---|
73 |
|
---|
74 | #include "MFilter.h"
|
---|
75 |
|
---|
76 | ClassImp(MTask);
|
---|
77 |
|
---|
78 | MTask::MTask(const char *name, const char *title)
|
---|
79 | : fFilter(NULL), fIsPreprocessed(kFALSE), fNumExecutions(0)
|
---|
80 | {
|
---|
81 | fName = name ? name : "MTask";
|
---|
82 | fTitle = title ? title : "Base class for all tasks (dummy task).";
|
---|
83 |
|
---|
84 | fListOfBranches = new TOrdCollection;
|
---|
85 | fListOfBranches->SetOwner();
|
---|
86 | }
|
---|
87 |
|
---|
88 | MTask::~MTask()
|
---|
89 | {
|
---|
90 | delete fListOfBranches;
|
---|
91 | }
|
---|
92 |
|
---|
93 | // --------------------------------------------------------------------------
|
---|
94 | //
|
---|
95 | // This adds a branch to the list for the auto enabeling schmeme.
|
---|
96 | // This makes it possible for MReadTree to decide which branches
|
---|
97 | // are really needed for the eventloop. Only the necessary branches
|
---|
98 | // are read from disk which speeds up the calculation enormously.
|
---|
99 | //
|
---|
100 | // You can use TRegExp expressions like "*.fEnergy", but the
|
---|
101 | // recommended method is to call this function for exactly all
|
---|
102 | // branches you want to have, eg:
|
---|
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 | if (!PreProcess(plist))
|
---|
137 | return kFALSE;
|
---|
138 |
|
---|
139 | fIsPreprocessed = kTRUE;
|
---|
140 | return kTRUE;
|
---|
141 | }
|
---|
142 |
|
---|
143 | // --------------------------------------------------------------------------
|
---|
144 | //
|
---|
145 | // Mapper function for Process.
|
---|
146 | // Executes Process dependent on the existance of a filter and its possible
|
---|
147 | // return value.
|
---|
148 | // If Process is executed, the execution counter is increased.
|
---|
149 | //
|
---|
150 | Bool_t MTask::CallProcess()
|
---|
151 | {
|
---|
152 | //
|
---|
153 | // Check for the existance of a filter. If a filter is existing
|
---|
154 | // check for its value. If the value is kFALSE don't execute
|
---|
155 | // this task.
|
---|
156 | //
|
---|
157 | const Bool_t exec = fFilter ? fFilter->IsExpressionTrue() : kTRUE;
|
---|
158 |
|
---|
159 | if (!exec)
|
---|
160 | return kTRUE;
|
---|
161 |
|
---|
162 | fNumExecutions++;
|
---|
163 | return Process();
|
---|
164 | }
|
---|
165 |
|
---|
166 | // --------------------------------------------------------------------------
|
---|
167 | //
|
---|
168 | // Mapper function for PreProcess.
|
---|
169 | // Calls Postprocess dependent on the state of the preprocessed flag,
|
---|
170 | // resets this flag.
|
---|
171 | //
|
---|
172 | Bool_t MTask::CallPostProcess()
|
---|
173 | {
|
---|
174 | if (!fIsPreprocessed)
|
---|
175 | return kTRUE;
|
---|
176 |
|
---|
177 | fIsPreprocessed = kFALSE;
|
---|
178 | return PostProcess();
|
---|
179 | }
|
---|
180 |
|
---|
181 | // --------------------------------------------------------------------------
|
---|
182 | //
|
---|
183 | // This is processed before the eventloop starts
|
---|
184 | //
|
---|
185 | // It is the job of the PreProcess to connect the tasks
|
---|
186 | // with the right container in the parameter list.
|
---|
187 | //
|
---|
188 | // the virtual implementation returns kTRUE
|
---|
189 | //
|
---|
190 | Bool_t MTask::PreProcess(MParList *pList)
|
---|
191 | {
|
---|
192 | return kTRUE;
|
---|
193 | }
|
---|
194 |
|
---|
195 | // --------------------------------------------------------------------------
|
---|
196 | //
|
---|
197 | // This is processed for every event in the eventloop
|
---|
198 | //
|
---|
199 | // the virtual implementation returns kTRUE
|
---|
200 | //
|
---|
201 | Bool_t MTask::Process()
|
---|
202 | {
|
---|
203 | return kTRUE;
|
---|
204 | }
|
---|
205 |
|
---|
206 | // --------------------------------------------------------------------------
|
---|
207 | //
|
---|
208 | // This is processed after the eventloop starts
|
---|
209 | //
|
---|
210 | // the virtual implementation returns kTRUE
|
---|
211 | //
|
---|
212 | Bool_t MTask::PostProcess()
|
---|
213 | {
|
---|
214 | return kTRUE;
|
---|
215 | }
|
---|
216 |
|
---|
217 | // --------------------------------------------------------------------------
|
---|
218 | //
|
---|
219 | // Prints the number of times this task has been processed.
|
---|
220 | // For convinience the lvl argument results in a number of spaces at the
|
---|
221 | // beginning of the line. So that the structur of a tasklist can be
|
---|
222 | // identified.
|
---|
223 | //
|
---|
224 | void MTask::PrintStatistics(const Int_t lvl) const
|
---|
225 | {
|
---|
226 | *fLog << setw(lvl) << " " << GetName() << " [";
|
---|
227 | *fLog << ClassName() << "] \t" << fNumExecutions;
|
---|
228 | *fLog << endl;
|
---|
229 | }
|
---|