source: trunk/MagicSoft/Mars/mbase/MTaskList.cc@ 858

Last change on this file since 858 was 858, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 7.5 KB
Line 
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// MTaskList //
28// //
29// Collection of tasks to be processed in the eventloop //
30// //
31/////////////////////////////////////////////////////////////////////////////
32
33#include "MTaskList.h"
34
35#include "MLog.h"
36#include "MLogManip.h"
37#include "MFilter.h"
38#include "MParList.h"
39#include "MInputStreamID.h"
40
41ClassImp(MTaskList);
42
43// --------------------------------------------------------------------------
44//
45// the name for the task list must be the same for all task lists
46// because the task list (at the moment) is identified by exactly
47// this name in the parameter list (by MEvtLoop::SetParList)
48//
49MTaskList::MTaskList(const char *title)
50{
51 *fName = "MTaskList";
52 *fTitle = title ? title : "List for Tasks";
53}
54
55// --------------------------------------------------------------------------
56//
57// CopyConstructor
58// creates a new TaskList and put the contents of an existing
59// TaskList in the new TaskList.
60//
61MTaskList::MTaskList(MTaskList &ts)
62{
63 fTasks.AddAll(&ts.fTasks);
64}
65
66// --------------------------------------------------------------------------
67//
68// Set the logging stream for the all tasks in the list and the tasklist
69// itself.
70//
71void MTaskList::SetLogStream(MLog *log)
72{
73 //
74 // create the Iterator over the tasklist
75 //
76 TIter Next(&fTasks);
77
78 MTask *task=NULL;
79
80 //
81 // loop over all tasks for preproccesing
82 //
83 while ((task=(MTask*)Next()))
84 task->SetLogStream(log);
85
86 MParContainer::SetLogStream(log);
87}
88
89
90// --------------------------------------------------------------------------
91//
92// schedule task for execution, whether as first task, or after
93// 'where'. 'tType' is the event type which should be processed
94//
95Bool_t MTaskList::AddToList(MTask *task, const char *type, MTask *where)
96{
97 if (!task)
98 return kTRUE;
99
100 const char *name = task->GetName();
101
102 // FIXME: We agreed to put the task into list in an ordered way.
103
104 if (fTasks.FindObject(task))
105 {
106 *fLog << dbginf << "Task already existing." << endl;
107 return kTRUE;
108 }
109
110 if (fTasks.FindObject(name))
111 {
112 *fLog << dbginf << "'" << name << "' exists in List already." << endl;
113 return kTRUE;
114 }
115
116 if (where)
117 {
118 if (!fTasks.FindObject(where))
119 {
120 *fLog << dbginf << "Cannot find task after which the new task should be scheduled!" << endl;
121 return kFALSE;
122 }
123 }
124
125 *fLog << "Adding " << name << " to " << GetName() << " for " << type << "... " << flush;
126
127 task->SetStreamId(type);
128 fTasks.Add(task);
129
130 *fLog << "Done." << endl;
131
132 return kTRUE;
133}
134
135// --------------------------------------------------------------------------
136//
137// do pre processing (before eventloop) of all tasks in the task-list
138//
139Bool_t MTaskList::PreProcess(MParList *pList)
140{
141 *fLog << "Preprocessing... " << flush;
142
143 fParList = pList;
144
145 //
146 // create the Iterator over the tasklist
147 //
148 TIter Next(&fTasks);
149
150 MTask *task=NULL;
151
152 //
153 // loop over all tasks for preproccesing
154 //
155 while ( (task=(MTask*)Next()) )
156 {
157 *fLog << task->GetName() << "... " << flush;
158
159 if (!task->PreProcess(fParList))
160 return kFALSE;
161 }
162
163 *fLog << endl;
164
165 return kTRUE;
166}
167
168// --------------------------------------------------------------------------
169//
170// do the event execution of all tasks in the task-list
171//
172Bool_t MTaskList::Process()
173{
174 //
175 // Reset the ReadyToSave flag.
176 // Reset all containers.
177 //
178 // FIXME: To run a tasklist as a single task in another tasklist we
179 // have to make sure, that the Parameter list isn't reset.
180 //
181 fParList->SetReadyToSave(kFALSE);
182 fParList->Reset();
183
184 //
185 // create the Iterator for the TaskList
186 //
187 TIter Next(&fTasks);
188 MTask *task=NULL;
189
190 //
191 // loop over all tasks for processing
192 //
193 while ( (task=(MTask*)Next()) )
194 {
195 //
196 // if the task has the wrong stream id skip it.
197 //
198 if (strcmp(GetStreamId(), task->GetStreamId()) &&
199 strcmp(task->GetStreamId(), "All"))
200 continue;
201
202 //
203 // Check for the existance of a filter. If a filter is existing
204 // check for its value. If the value is kFALSE don't execute
205 // this task.
206 //
207 const MFilter *filter = task->GetFilter();
208
209 const Bool_t rc = filter ? filter->IsExpressionTrue() : kTRUE;
210
211 if (!rc)
212 continue;
213
214 //
215 // if it has the right stream id execute the Process() function
216 // and check what the result of it is.
217 //
218 switch (task->Process())
219 {
220 case kTRUE:
221 //
222 // everything was OK: go on
223 //
224 continue;
225
226 case kFALSE:
227 //
228 // an error occured: stop eventloop
229 //
230 return kFALSE;
231
232 case kCONTINUE:
233 //
234 // something occured: skip the rest of the tasks for this event
235 //
236 break;
237 }
238 }
239 return kTRUE;
240}
241
242// --------------------------------------------------------------------------
243//
244// do post processing (before eventloop) of all tasks in the task-list
245//
246Bool_t MTaskList::PostProcess()
247{
248 *fLog << "Postprocessing... " << flush;
249
250 // FIXME: At the moment all tasks are post processed independ of
251 // whether it was preprocessed or not.
252
253 //
254 // Reset the ReadyToSave flag.
255 // Reset all containers.
256 //
257 // FIXME: To run a tasklist as a single task in another tasklist we
258 // have to make sure, that the Parameter list isn't reset.
259 //
260 fParList->SetReadyToSave(kFALSE);
261 fParList->Reset();
262
263 //
264 // create the Iterator for the TaskList
265 //
266 TIter Next(&fTasks);
267
268 MTask *task=NULL;
269
270 //
271 // loop over all tasks for postprocessing
272 //
273 while ( (task=(MTask*)Next()) )
274 {
275 *fLog << task->GetName() << "... " << flush;
276
277 if (!task->PostProcess())
278 return kFALSE;
279 }
280
281 *fLog << endl;
282
283 return kTRUE;
284}
285
286// --------------------------------------------------------------------------
287void MTaskList::Print(Option_t *t)
288{
289 *fLog << "TaskList: " << this->GetName() << " <" << this->GetTitle() << ">" << endl;
290
291 fTasks.Print();
292
293 *fLog << endl;
294}
295
Note: See TracBrowser for help on using the repository browser.