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@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MTaskList
|
---|
28 | //
|
---|
29 | // Collection of tasks.
|
---|
30 | //
|
---|
31 | // A tasklist is necessary to run the eventloop. It contains the scheduled
|
---|
32 | // tasks, which should be executed in your program.
|
---|
33 | //
|
---|
34 | // To add a task use AddToList.
|
---|
35 | //
|
---|
36 | // The tasklist itself is a task, too. You can add a tasklist to another
|
---|
37 | // tasklist. This makes sense, if you want to filter the execution of
|
---|
38 | // more than one task of your tasklist using the same filter.
|
---|
39 | //
|
---|
40 | // The tasks in the list are idetified by their names. If more than one
|
---|
41 | // task has the same name, the tasklist will still work correctly, but
|
---|
42 | // you might run into trouble trying to get a pointer to a task by name
|
---|
43 | // from the list.
|
---|
44 | //
|
---|
45 | // Warning:
|
---|
46 | // Be carefull if you are writing your tasklist
|
---|
47 | // (eg. MWriteRootFile("file.root", "MTaskList")) to a file. You may
|
---|
48 | // not be able to initialize a new working tasklist from a file if
|
---|
49 | // a) Two Paramerer containers with the same names are existing in the
|
---|
50 | // MParList.
|
---|
51 | // b) You used a container somewhere which is not part of MParList.
|
---|
52 | // (eg. You specified a pointer to a MH container in MFillH which is
|
---|
53 | // not added to the parameter list.
|
---|
54 | //
|
---|
55 | /////////////////////////////////////////////////////////////////////////////
|
---|
56 | #include "MTaskList.h"
|
---|
57 |
|
---|
58 | #include <fstream> // ofstream, SavePrimitive
|
---|
59 |
|
---|
60 | #include <TSystem.h> // gSystem
|
---|
61 | #include <TOrdCollection.h> // TOrdCollection
|
---|
62 |
|
---|
63 | #include "MLog.h"
|
---|
64 | #include "MLogManip.h"
|
---|
65 |
|
---|
66 | #include "MIter.h"
|
---|
67 | #include "MFilter.h"
|
---|
68 | #include "MParList.h"
|
---|
69 | #include "MInputStreamID.h"
|
---|
70 |
|
---|
71 | #include "MStatusDisplay.h"
|
---|
72 |
|
---|
73 | ClassImp(MTaskList);
|
---|
74 |
|
---|
75 | using namespace std;
|
---|
76 |
|
---|
77 | const TString MTaskList::gsDefName = "MTaskList";
|
---|
78 | const TString MTaskList::gsDefTitle = "A list for tasks to be executed";
|
---|
79 |
|
---|
80 | // --------------------------------------------------------------------------
|
---|
81 | //
|
---|
82 | // the name for the task list must be the same for all task lists
|
---|
83 | // because the task list (at the moment) is identified by exactly
|
---|
84 | // this name in the parameter list (by MEvtLoop::SetParList)
|
---|
85 | //
|
---|
86 | MTaskList::MTaskList(const char *name, const char *title)
|
---|
87 | {
|
---|
88 | fName = name ? name : gsDefName.Data();
|
---|
89 | fTitle = title ? title : gsDefTitle.Data();
|
---|
90 |
|
---|
91 | fTasks = new TList;
|
---|
92 |
|
---|
93 | gROOT->GetListOfCleanups()->Add(fTasks);
|
---|
94 | gROOT->GetListOfCleanups()->Add(&fTasksProcess);
|
---|
95 | fTasks->SetBit(kMustCleanup);
|
---|
96 | fTasksProcess.SetBit(kMustCleanup);
|
---|
97 | }
|
---|
98 |
|
---|
99 | // --------------------------------------------------------------------------
|
---|
100 | //
|
---|
101 | // CopyConstructor
|
---|
102 | // creates a new TaskList and put the contents of an existing
|
---|
103 | // TaskList in the new TaskList.
|
---|
104 | //
|
---|
105 | MTaskList::MTaskList(MTaskList &ts)
|
---|
106 | {
|
---|
107 | fTasks->AddAll(ts.fTasks);
|
---|
108 | }
|
---|
109 |
|
---|
110 | // --------------------------------------------------------------------------
|
---|
111 | //
|
---|
112 | // If the 'IsOwner' bit is set (via SetOwner()) all tasks are deleted
|
---|
113 | // by the destructor
|
---|
114 | //
|
---|
115 | MTaskList::~MTaskList()
|
---|
116 | {
|
---|
117 | if (TestBit(kIsOwner))
|
---|
118 | fTasks->SetOwner();
|
---|
119 |
|
---|
120 | delete fTasks;
|
---|
121 | }
|
---|
122 |
|
---|
123 | // --------------------------------------------------------------------------
|
---|
124 | //
|
---|
125 | // If the 'IsOwner' bit is set (via SetOwner()) all containers are deleted
|
---|
126 | // by the destructor
|
---|
127 | //
|
---|
128 | void MTaskList::SetOwner(Bool_t enable)
|
---|
129 | {
|
---|
130 | enable ? SetBit(kIsOwner) : ResetBit(kIsOwner);
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 | // --------------------------------------------------------------------------
|
---|
135 | //
|
---|
136 | // Set the logging stream for the all tasks in the list and the tasklist
|
---|
137 | // itself.
|
---|
138 | //
|
---|
139 | void MTaskList::SetLogStream(MLog *log)
|
---|
140 | {
|
---|
141 | fTasks->ForEach(MTask, SetLogStream)(log);
|
---|
142 | MTask::SetLogStream(log);
|
---|
143 | }
|
---|
144 |
|
---|
145 | // --------------------------------------------------------------------------
|
---|
146 | //
|
---|
147 | // Set the display for the all tasks in the list and the tasklist itself.
|
---|
148 | //
|
---|
149 | void MTaskList::SetDisplay(MStatusDisplay *d)
|
---|
150 | {
|
---|
151 | fTasks->ForEach(MTask, SetDisplay)(d);
|
---|
152 | MTask::SetDisplay(d);
|
---|
153 | }
|
---|
154 |
|
---|
155 | // --------------------------------------------------------------------------
|
---|
156 | //
|
---|
157 | // Set the serial number for the all tasks in the list and the tasklist
|
---|
158 | // itself.
|
---|
159 | //
|
---|
160 | void MTaskList::SetSerialNumber(Byte_t num)
|
---|
161 | {
|
---|
162 | fTasks->ForEach(MTask, SetSerialNumber)(num);
|
---|
163 | MTask::SetSerialNumber(num);
|
---|
164 | }
|
---|
165 |
|
---|
166 | Bool_t MTaskList::CheckAddToList(MTask *task, const char *type, const MTask *where) const
|
---|
167 | {
|
---|
168 | //
|
---|
169 | // Sanity check
|
---|
170 | //
|
---|
171 | if (!task)
|
---|
172 | {
|
---|
173 | *fLog << err << "ERROR - task argument=NULL." << endl;
|
---|
174 | return kFALSE;
|
---|
175 | }
|
---|
176 |
|
---|
177 | //
|
---|
178 | // Get Name of new task
|
---|
179 | //
|
---|
180 | const char *name = task->GetName();
|
---|
181 |
|
---|
182 | //
|
---|
183 | // Check if the new task is already existing in the list
|
---|
184 | //
|
---|
185 | const TObject *objn = fTasks->FindObject(name);
|
---|
186 | const TObject *objt = fTasks->FindObject(task);
|
---|
187 |
|
---|
188 | if (objn || objt)
|
---|
189 | {
|
---|
190 | //
|
---|
191 | // If the task is already in the list ignore it.
|
---|
192 | //
|
---|
193 | if (objt || objn==task)
|
---|
194 | {
|
---|
195 | *fLog << warn << dbginf << "Warning: Task '" << task->GetName() << ", 0x" << (void*)task;
|
---|
196 | *fLog << "' already existing in '" << GetName() << "'... ignoring." << endl;
|
---|
197 | return kTRUE;
|
---|
198 | }
|
---|
199 |
|
---|
200 | //
|
---|
201 | // Otherwise add it to the list, but print a warning message
|
---|
202 | //
|
---|
203 | *fLog << warn << dbginf << "Warning: Task '" << task->GetName();
|
---|
204 | *fLog << "' already existing in '" << GetName() << "'." << endl;
|
---|
205 | *fLog << "You may not be able to get a pointer to this task by name." << endl;
|
---|
206 | }
|
---|
207 |
|
---|
208 | if (!where)
|
---|
209 | return kTRUE;
|
---|
210 |
|
---|
211 | if (fTasks->FindObject(where))
|
---|
212 | return kTRUE;
|
---|
213 |
|
---|
214 | *fLog << err << dbginf << "Error: Cannot find task after which the new task should be scheduled!" << endl;
|
---|
215 | return kFALSE;
|
---|
216 | }
|
---|
217 |
|
---|
218 |
|
---|
219 | // --------------------------------------------------------------------------
|
---|
220 | //
|
---|
221 | // schedule task for execution, before 'where'.
|
---|
222 | // 'type' is the event type which should be processed
|
---|
223 | //
|
---|
224 | Bool_t MTaskList::AddToListBefore(MTask *task, const MTask *where, const char *type)
|
---|
225 | {
|
---|
226 | // FIXME: We agreed to put the task into list in an ordered way.
|
---|
227 | if (!CheckAddToList(task, type, where))
|
---|
228 | return kFALSE;
|
---|
229 |
|
---|
230 | *fLog << inf << "Adding " << task->GetName() << " to " << GetName() << " for " << type << "... " << flush;
|
---|
231 | task->SetStreamId(type);
|
---|
232 | task->SetBit(kMustCleanup);
|
---|
233 | fTasks->AddBefore((TObject*)where, task);
|
---|
234 | *fLog << "Done." << endl;
|
---|
235 |
|
---|
236 | return kTRUE;
|
---|
237 | }
|
---|
238 |
|
---|
239 | // --------------------------------------------------------------------------
|
---|
240 | //
|
---|
241 | // schedule task for execution, after 'where'.
|
---|
242 | // 'type' is the event type which should be processed
|
---|
243 | //
|
---|
244 | Bool_t MTaskList::AddToListAfter(MTask *task, const MTask *where, const char *type)
|
---|
245 | {
|
---|
246 | // FIXME: We agreed to put the task into list in an ordered way.
|
---|
247 |
|
---|
248 | if (!CheckAddToList(task, type, where))
|
---|
249 | return kFALSE;
|
---|
250 |
|
---|
251 | *fLog << inf << "Adding " << task->GetName() << " to " << GetName() << " for " << type << "... " << flush;
|
---|
252 | task->SetStreamId(type);
|
---|
253 | task->SetBit(kMustCleanup);
|
---|
254 | fTasks->AddAfter((TObject*)where, task);
|
---|
255 | *fLog << "Done." << endl;
|
---|
256 |
|
---|
257 | return kTRUE;
|
---|
258 | }
|
---|
259 |
|
---|
260 | // --------------------------------------------------------------------------
|
---|
261 | //
|
---|
262 | // schedule task for execution, 'type' is the event type which should
|
---|
263 | // be processed
|
---|
264 | //
|
---|
265 | Bool_t MTaskList::AddToList(MTask *task, const char *type)
|
---|
266 | {
|
---|
267 | // FIXME: We agreed to put the task into list in an ordered way.
|
---|
268 |
|
---|
269 | if (!CheckAddToList(task, type))
|
---|
270 | return kFALSE;
|
---|
271 |
|
---|
272 | *fLog << inf << "Adding " << task->GetName() << " to " << GetName() << " for " << type << "... " << flush;
|
---|
273 | task->SetStreamId(type);
|
---|
274 | task->SetBit(kMustCleanup);
|
---|
275 | fTasks->Add(task);
|
---|
276 | *fLog << "Done." << endl;
|
---|
277 |
|
---|
278 | return kTRUE;
|
---|
279 | }
|
---|
280 |
|
---|
281 | // --------------------------------------------------------------------------
|
---|
282 | //
|
---|
283 | // Find an object in the list.
|
---|
284 | // 'name' is the name of the object you are searching for.
|
---|
285 | //
|
---|
286 | TObject *MTaskList::FindObject(const char *name) const
|
---|
287 | {
|
---|
288 | return fTasks->FindObject(name);
|
---|
289 | }
|
---|
290 |
|
---|
291 | // --------------------------------------------------------------------------
|
---|
292 | //
|
---|
293 | // check if the object is in the list or not
|
---|
294 | //
|
---|
295 | TObject *MTaskList::FindObject(const TObject *obj) const
|
---|
296 | {
|
---|
297 | return fTasks->FindObject(obj);
|
---|
298 | }
|
---|
299 |
|
---|
300 | // --------------------------------------------------------------------------
|
---|
301 | //
|
---|
302 | // do reinit of all tasks in the task-list
|
---|
303 | //
|
---|
304 | Bool_t MTaskList::ReInit(MParList *pList)
|
---|
305 | {
|
---|
306 | *fLog << all << "Reinit... " << flush;
|
---|
307 |
|
---|
308 | if (!pList)
|
---|
309 | pList = fParList;
|
---|
310 |
|
---|
311 | //
|
---|
312 | // Make sure, that the ReadyToSave flag is not reset from a tasklist
|
---|
313 | // running as a task in another tasklist.
|
---|
314 | //
|
---|
315 | const Bool_t noreset = pList->TestBit(MParList::kDoNotReset);
|
---|
316 | if (!noreset)
|
---|
317 | pList->SetBit(MParList::kDoNotReset);
|
---|
318 |
|
---|
319 | //
|
---|
320 | // create the Iterator over the tasklist
|
---|
321 | //
|
---|
322 | TIter Next(fTasks);
|
---|
323 |
|
---|
324 | MTask *task=NULL;
|
---|
325 |
|
---|
326 | //
|
---|
327 | // loop over all tasks for reinitialization
|
---|
328 | //
|
---|
329 | while ((task=(MTask*)Next()))
|
---|
330 | {
|
---|
331 | *fLog << all << task->GetName() << "... " << flush;
|
---|
332 |
|
---|
333 | if (!task->ReInit(pList/*?pList:fParList*/))
|
---|
334 | {
|
---|
335 | *fLog << err << "ERROR - ReInit of Task '" << task->GetDescriptor() << "' failed." << endl;
|
---|
336 | return kFALSE;
|
---|
337 | }
|
---|
338 | }
|
---|
339 |
|
---|
340 | *fLog << all << endl;
|
---|
341 |
|
---|
342 | //
|
---|
343 | // Reset the ReadyToSave flag.
|
---|
344 | //
|
---|
345 | if (!noreset)
|
---|
346 | {
|
---|
347 | pList->SetReadyToSave(kFALSE);
|
---|
348 | pList->ResetBit(MParList::kDoNotReset);
|
---|
349 | }
|
---|
350 |
|
---|
351 | return kTRUE;
|
---|
352 | }
|
---|
353 |
|
---|
354 | // --------------------------------------------------------------------------
|
---|
355 | //
|
---|
356 | // removes a task from the list (used in PreProcess).
|
---|
357 | // if kIsOwner is set the task is deleted. (see SetOwner())
|
---|
358 | //
|
---|
359 | void MTaskList::Remove(MTask *task)
|
---|
360 | {
|
---|
361 | TObject *obj = fTasks->Remove(task);
|
---|
362 |
|
---|
363 | if (TestBit(kIsOwner))
|
---|
364 | delete obj;
|
---|
365 | }
|
---|
366 |
|
---|
367 | // --------------------------------------------------------------------------
|
---|
368 | //
|
---|
369 | // do pre processing (before eventloop) of all tasks in the task-list
|
---|
370 | // Only if a task overwrites the Process function the task is
|
---|
371 | // added to the fTaskProcess-List. This makes the execution of the
|
---|
372 | // tasklist a little bit (only a little bit) faster, bacause tasks
|
---|
373 | // doing no Processing are not Processed.
|
---|
374 | //
|
---|
375 | Int_t MTaskList::PreProcess(MParList *pList)
|
---|
376 | {
|
---|
377 | *fLog << all << "Preprocessing... " << flush;
|
---|
378 | if (fDisplay)
|
---|
379 | {
|
---|
380 | // Set status lines
|
---|
381 | fDisplay->SetStatusLine1("PreProcessing...");
|
---|
382 | fDisplay->SetStatusLine2("");
|
---|
383 | }
|
---|
384 |
|
---|
385 | fParList = pList;
|
---|
386 |
|
---|
387 | //
|
---|
388 | // Make sure, that the ReadyToSave flag is not reset from a tasklist
|
---|
389 | // running as a task in another tasklist.
|
---|
390 | //
|
---|
391 | const Bool_t noreset = fParList->TestBit(MParList::kDoNotReset);
|
---|
392 | if (!noreset)
|
---|
393 | fParList->SetBit(MParList::kDoNotReset);
|
---|
394 |
|
---|
395 | //
|
---|
396 | // create the Iterator over the tasklist
|
---|
397 | //
|
---|
398 | TIter Next(fTasks);
|
---|
399 |
|
---|
400 | MTask *task=NULL;
|
---|
401 |
|
---|
402 | //
|
---|
403 | // loop over all tasks for preproccesing
|
---|
404 | //
|
---|
405 | while ((task=(MTask*)Next()))
|
---|
406 | {
|
---|
407 | //
|
---|
408 | // PreProcess the task and check for it's return value.
|
---|
409 | //
|
---|
410 | switch (task->CallPreProcess(fParList))
|
---|
411 | {
|
---|
412 | case kFALSE:
|
---|
413 | return kFALSE;
|
---|
414 |
|
---|
415 | case kTRUE:
|
---|
416 | // Handle GUI events (display changes, mouse clicks)
|
---|
417 | if (fDisplay)
|
---|
418 | gSystem->ProcessEvents();
|
---|
419 | continue;
|
---|
420 |
|
---|
421 | case kSKIP:
|
---|
422 | Remove(task);
|
---|
423 | continue;
|
---|
424 | }
|
---|
425 |
|
---|
426 | *fLog << err << dbginf << "PreProcess of " << task->GetDescriptor();
|
---|
427 | *fLog << " returned an unknown value... aborting." << endl;
|
---|
428 | return kFALSE;
|
---|
429 | }
|
---|
430 |
|
---|
431 | *fLog << all << endl;
|
---|
432 |
|
---|
433 | //
|
---|
434 | // Reset the ReadyToSave flag.
|
---|
435 | //
|
---|
436 | if (!noreset)
|
---|
437 | {
|
---|
438 | fParList->SetReadyToSave(kFALSE);
|
---|
439 | fParList->ResetBit(MParList::kDoNotReset);
|
---|
440 | }
|
---|
441 |
|
---|
442 | //
|
---|
443 | // loop over all tasks to fill fTasksProcess
|
---|
444 | //
|
---|
445 | Next.Reset();
|
---|
446 | fTasksProcess.Clear();
|
---|
447 | while ((task=(MTask*)Next()))
|
---|
448 | if (task->OverwritesProcess())
|
---|
449 | fTasksProcess.Add(task);
|
---|
450 |
|
---|
451 | return kTRUE;
|
---|
452 | }
|
---|
453 |
|
---|
454 | // --------------------------------------------------------------------------
|
---|
455 | //
|
---|
456 | // do the event execution of all tasks in the task-list
|
---|
457 | //
|
---|
458 | Int_t MTaskList::Process()
|
---|
459 | {
|
---|
460 | //
|
---|
461 | // Check whether there is something which can be processed, otherwise
|
---|
462 | // stop the eventloop.
|
---|
463 | //
|
---|
464 | if (fTasksProcess.GetSize()==0)
|
---|
465 | {
|
---|
466 | *fLog << warn << "Warning: No entries in " << GetDescriptor() << " for Processing." << endl;
|
---|
467 | return kFALSE;
|
---|
468 | }
|
---|
469 |
|
---|
470 | //
|
---|
471 | // Reset the ReadyToSave flag.
|
---|
472 | // Reset all containers.
|
---|
473 | //
|
---|
474 | // Make sure, that the parameter list is not reset from a tasklist
|
---|
475 | // running as a task in another tasklist.
|
---|
476 | //
|
---|
477 | const Bool_t noreset = fParList->TestBit(MParList::kIsProcessing);
|
---|
478 | if (!noreset)
|
---|
479 | {
|
---|
480 | fParList->SetBit(MParList::kIsProcessing);
|
---|
481 | fParList->Reset();
|
---|
482 | }
|
---|
483 |
|
---|
484 | //
|
---|
485 | // create the Iterator for the TaskList
|
---|
486 | //
|
---|
487 | TIter Next(&fTasksProcess);
|
---|
488 | MTask *task=NULL;
|
---|
489 |
|
---|
490 | //
|
---|
491 | // loop over all tasks for processing
|
---|
492 | //
|
---|
493 | Bool_t rc = kTRUE;
|
---|
494 | while ( (task=(MTask*)Next()) )
|
---|
495 | {
|
---|
496 | //
|
---|
497 | // if the task has the wrong stream id skip it.
|
---|
498 | //
|
---|
499 | if (GetStreamId() != task->GetStreamId() &&
|
---|
500 | task->GetStreamId() != "All")
|
---|
501 | continue;
|
---|
502 |
|
---|
503 | //
|
---|
504 | // if it has the right stream id execute the CallProcess() function
|
---|
505 | // and check what the result of it is.
|
---|
506 | // The CallProcess() function increases the execution counter and
|
---|
507 | // calls the Process() function dependent on the existance and
|
---|
508 | // return value of a filter.
|
---|
509 | //
|
---|
510 | switch (task->CallProcess())
|
---|
511 | {
|
---|
512 | case kTRUE:
|
---|
513 | //
|
---|
514 | // everything was OK: go on with the next task
|
---|
515 | //
|
---|
516 | continue;
|
---|
517 |
|
---|
518 | case kFALSE:
|
---|
519 | //
|
---|
520 | // an error occured: stop eventloop
|
---|
521 | //
|
---|
522 | rc = kFALSE;
|
---|
523 | *fLog << inf << task->GetDescriptor() << " has stopped execution of " << GetDescriptor() << "." << endl;
|
---|
524 | break;
|
---|
525 |
|
---|
526 | case kERROR:
|
---|
527 | //
|
---|
528 | // an error occured: stop eventloop and return: failed
|
---|
529 | //
|
---|
530 | *fLog << err << dbginf << "Fatal error occured... stopped." << endl;
|
---|
531 | rc = kERROR;
|
---|
532 | break;
|
---|
533 |
|
---|
534 | case kCONTINUE:
|
---|
535 | //
|
---|
536 | // something occured: skip the rest of the tasks for this event
|
---|
537 | //
|
---|
538 | rc = kTRUE;
|
---|
539 | break;
|
---|
540 |
|
---|
541 | default:
|
---|
542 | *fLog << warn << dbginf << "Unknown return value from MTask::Process()... ignored." << endl;
|
---|
543 | continue;
|
---|
544 | }
|
---|
545 | break;
|
---|
546 | }
|
---|
547 |
|
---|
548 | if (!noreset)
|
---|
549 | {
|
---|
550 | fParList->SetReadyToSave(kFALSE);
|
---|
551 | fParList->ResetBit(MParList::kIsProcessing);
|
---|
552 | }
|
---|
553 |
|
---|
554 | return rc;
|
---|
555 | }
|
---|
556 |
|
---|
557 | // --------------------------------------------------------------------------
|
---|
558 | //
|
---|
559 | // do post processing (before eventloop) of all tasks in the task-list
|
---|
560 | // only tasks which have successfully been preprocessed are postprocessed.
|
---|
561 | //
|
---|
562 | Int_t MTaskList::PostProcess()
|
---|
563 | {
|
---|
564 | *fLog << all << "Postprocessing... " << flush;
|
---|
565 | if (fDisplay)
|
---|
566 | {
|
---|
567 | // Set status lines
|
---|
568 | fDisplay->SetStatusLine1("PostProcessing...");
|
---|
569 | fDisplay->SetStatusLine2("");
|
---|
570 | }
|
---|
571 |
|
---|
572 | //
|
---|
573 | // Make sure, that the ReadyToSave flag is not reset from a tasklist
|
---|
574 | // running as a task in another tasklist.
|
---|
575 | //
|
---|
576 | const Bool_t noreset = fParList->TestBit(MParList::kDoNotReset);
|
---|
577 | if (!noreset)
|
---|
578 | {
|
---|
579 | fParList->SetBit(MParList::kDoNotReset);
|
---|
580 | fParList->Reset();
|
---|
581 | }
|
---|
582 |
|
---|
583 | //
|
---|
584 | // create the Iterator for the TaskList
|
---|
585 | //
|
---|
586 | TIter Next(fTasks);
|
---|
587 |
|
---|
588 | MTask *task=NULL;
|
---|
589 |
|
---|
590 | //
|
---|
591 | // loop over all tasks for postprocessing
|
---|
592 | // only tasks which have successfully been preprocessed are postprocessed.
|
---|
593 | //
|
---|
594 | while ( (task=(MTask*)Next()) )
|
---|
595 | {
|
---|
596 | if (!task->CallPostProcess())
|
---|
597 | return kFALSE;
|
---|
598 |
|
---|
599 | // Handle GUI events (display changes, mouse clicks)
|
---|
600 | if (fDisplay)
|
---|
601 | gSystem->ProcessEvents();
|
---|
602 | }
|
---|
603 |
|
---|
604 | *fLog << all << endl;
|
---|
605 |
|
---|
606 | //
|
---|
607 | // Reset the ReadyToSave flag.
|
---|
608 | //
|
---|
609 | if (!noreset)
|
---|
610 | {
|
---|
611 | fParList->SetReadyToSave(kFALSE);
|
---|
612 | fParList->ResetBit(MParList::kDoNotReset);
|
---|
613 | }
|
---|
614 |
|
---|
615 | return kTRUE;
|
---|
616 | }
|
---|
617 |
|
---|
618 | // --------------------------------------------------------------------------
|
---|
619 | //
|
---|
620 | // Prints the number of times all the tasks in the list has been.
|
---|
621 | // For convinience the lvl argument results in a number of spaces at the
|
---|
622 | // beginning of the line. So that the structur of a tasklist can be
|
---|
623 | // identified. If a Tasklist or task has filter applied the name of the
|
---|
624 | // filter is printer in <>-brackets behind the number of executions.
|
---|
625 | // Use MTaskList::PrintStatistics without an argument.
|
---|
626 | //
|
---|
627 | void MTaskList::PrintStatistics(const Int_t lvl, Bool_t title, Double_t time) const
|
---|
628 | {
|
---|
629 | if (lvl==0)
|
---|
630 | {
|
---|
631 | *fLog << all << underline << "Process execution Statistics:" << endl;
|
---|
632 | *fLog << GetDescriptor();
|
---|
633 | if (GetFilter())
|
---|
634 | *fLog << " <" << GetFilter()->GetName() << ">";
|
---|
635 | if (title)
|
---|
636 | *fLog << "\t" << fTitle;
|
---|
637 | if (time>=0)
|
---|
638 | *fLog << Form(" %5.1f", GetCpuTime()/time*100) << "%";
|
---|
639 | else
|
---|
640 | *fLog << " 100.0%";
|
---|
641 | *fLog << endl;
|
---|
642 | }
|
---|
643 | else
|
---|
644 | MTask::PrintStatistics(lvl, title, time);
|
---|
645 |
|
---|
646 | //
|
---|
647 | // create the Iterator for the TaskList
|
---|
648 | //
|
---|
649 | fTasks->ForEach(MTask, PrintStatistics)(lvl+1, title, GetCpuTime());
|
---|
650 |
|
---|
651 | if (lvl==0)
|
---|
652 | *fLog << endl;
|
---|
653 | }
|
---|
654 |
|
---|
655 | // --------------------------------------------------------------------------
|
---|
656 | //
|
---|
657 | // Call 'Print()' of all tasks
|
---|
658 | //
|
---|
659 | void MTaskList::Print(Option_t *t) const
|
---|
660 | {
|
---|
661 | *fLog << all << underline << GetDescriptor() << ":" << endl;
|
---|
662 |
|
---|
663 | fTasks->Print();
|
---|
664 |
|
---|
665 | *fLog << endl;
|
---|
666 | }
|
---|
667 |
|
---|
668 | // --------------------------------------------------------------------------
|
---|
669 | //
|
---|
670 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
671 | // to a macro. In the original root implementation it is used to write
|
---|
672 | // gui elements to a macro-file.
|
---|
673 | //
|
---|
674 | void MTaskList::StreamPrimitive(ofstream &out) const
|
---|
675 | {
|
---|
676 | out << " MTaskList " << GetUniqueName();
|
---|
677 | if (fName!=gsDefName || fTitle!=gsDefTitle)
|
---|
678 | {
|
---|
679 | out << "(\"" << fName << "\"";
|
---|
680 | if (fTitle!=gsDefTitle)
|
---|
681 | out << ", \"" << fTitle << "\"";
|
---|
682 | out <<")";
|
---|
683 | }
|
---|
684 | out << ";" << endl << endl;
|
---|
685 |
|
---|
686 | MIter Next(fTasks);
|
---|
687 |
|
---|
688 | MParContainer *cont = NULL;
|
---|
689 | while ((cont=Next()))
|
---|
690 | {
|
---|
691 | cont->SavePrimitive(out, "");
|
---|
692 | out << " " << GetUniqueName() << ".AddToList(&";
|
---|
693 | out << cont->GetUniqueName() << ");" << endl << endl;
|
---|
694 | }
|
---|
695 | }
|
---|
696 |
|
---|
697 | void MTaskList::GetNames(TObjArray &arr) const
|
---|
698 | {
|
---|
699 | MParContainer::GetNames(arr);
|
---|
700 | fTasks->ForEach(MParContainer, GetNames)(arr);
|
---|
701 | }
|
---|
702 |
|
---|
703 | void MTaskList::SetNames(TObjArray &arr)
|
---|
704 | {
|
---|
705 | MParContainer::SetNames(arr);
|
---|
706 | fTasks->ForEach(MParContainer, SetNames)(arr);
|
---|
707 | }
|
---|
708 |
|
---|
709 | // --------------------------------------------------------------------------
|
---|
710 | //
|
---|
711 | // Read the contents/setup of a parameter container/task from a TEnv
|
---|
712 | // instance (steering card/setup file).
|
---|
713 | // The key to search for in the file should be of the syntax:
|
---|
714 | // prefix.vname
|
---|
715 | // While vname is a name which is specific for a single setup date
|
---|
716 | // (variable) of this container and prefix is something like:
|
---|
717 | // evtloopname.name
|
---|
718 | // While name is the name of the containers/tasks in the parlist/tasklist
|
---|
719 | //
|
---|
720 | // eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
|
---|
721 | // Job4.MImgCleanStd.CleaningLevel2: 2.5
|
---|
722 | //
|
---|
723 | // If this cannot be found the next step is to search for
|
---|
724 | // MImgCleanStd.CleaningLevel1: 3.0
|
---|
725 | // And if this doesn't exist, too, we should search for:
|
---|
726 | // CleaningLevel1: 3.0
|
---|
727 | //
|
---|
728 | // Warning: The programmer is responsible for the names to be unique in
|
---|
729 | // all Mars classes.
|
---|
730 | //
|
---|
731 | Bool_t MTaskList::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
732 | {
|
---|
733 | if (print)
|
---|
734 | *fLog << all << "MTaskList::ReadEnv: " << prefix << " (" << (int)print << ")" << endl;
|
---|
735 |
|
---|
736 | MParContainer *cont = NULL;
|
---|
737 |
|
---|
738 | MIter Next(fTasks);
|
---|
739 | while ((cont=Next()))
|
---|
740 | {
|
---|
741 | if (cont->InheritsFrom("MTaskList"))
|
---|
742 | {
|
---|
743 | if (cont->ReadEnv(env, prefix, print)==kERROR)
|
---|
744 | return kERROR;
|
---|
745 | continue;
|
---|
746 | }
|
---|
747 |
|
---|
748 | // Check For: Job4.ContainerName.Varname
|
---|
749 | if (print)
|
---|
750 | *fLog << all << "Testing: " << prefix+cont->GetName() << endl;
|
---|
751 | Bool_t rc = cont->ReadEnv(env, prefix+cont->GetName(), print);
|
---|
752 | if (rc==kERROR)
|
---|
753 | return kERROR;
|
---|
754 | if (rc==kTRUE)
|
---|
755 | continue;
|
---|
756 |
|
---|
757 | // Check For: Job4.MClassName.Varname
|
---|
758 | if (print)
|
---|
759 | *fLog << all << "Testing: " << prefix+cont->ClassName() << endl;
|
---|
760 | rc = cont->ReadEnv(env, prefix+cont->ClassName(), print);
|
---|
761 | if (rc==kERROR)
|
---|
762 | return kERROR;
|
---|
763 | if (rc==kTRUE)
|
---|
764 | continue;
|
---|
765 |
|
---|
766 | // Check For: ContainerName.Varname
|
---|
767 | if (print)
|
---|
768 | *fLog << all << "Testing: " << cont->GetName() << endl;
|
---|
769 | rc = cont->ReadEnv(env, cont->GetName(), print);
|
---|
770 | if (rc==kERROR)
|
---|
771 | return kERROR;
|
---|
772 | if (rc==kTRUE)
|
---|
773 | continue;
|
---|
774 |
|
---|
775 | // Check For: MClassName.Varname
|
---|
776 | if (print)
|
---|
777 | *fLog << all << "Testing: " << cont->ClassName() << endl;
|
---|
778 | rc = cont->ReadEnv(env, cont->ClassName(), print);
|
---|
779 | if (rc==kERROR)
|
---|
780 | return kERROR;
|
---|
781 | if (rc==kTRUE)
|
---|
782 | continue;
|
---|
783 | }
|
---|
784 |
|
---|
785 | return kTRUE;
|
---|
786 | }
|
---|
787 |
|
---|
788 | // --------------------------------------------------------------------------
|
---|
789 | //
|
---|
790 | // Write the contents/setup of a parameter container/task to a TEnv
|
---|
791 | // instance (steering card/setup file).
|
---|
792 | // The key to search for in the file should be of the syntax:
|
---|
793 | // prefix.vname
|
---|
794 | // While vname is a name which is specific for a single setup date
|
---|
795 | // (variable) of this container and prefix is something like:
|
---|
796 | // evtloopname.name
|
---|
797 | // While name is the name of the containers/tasks in the parlist/tasklist
|
---|
798 | //
|
---|
799 | // eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
|
---|
800 | // Job4.MImgCleanStd.CleaningLevel2: 2.5
|
---|
801 | //
|
---|
802 | // If this cannot be found the next step is to search for
|
---|
803 | // MImgCleanStd.CleaningLevel1: 3.0
|
---|
804 | // And if this doesn't exist, too, we should search for:
|
---|
805 | // CleaningLevel1: 3.0
|
---|
806 | //
|
---|
807 | // Warning: The programmer is responsible for the names to be unique in
|
---|
808 | // all Mars classes.
|
---|
809 | //
|
---|
810 | Bool_t MTaskList::WriteEnv(TEnv &env, TString prefix, Bool_t print) const
|
---|
811 | {
|
---|
812 | MParContainer *cont = NULL;
|
---|
813 |
|
---|
814 | MIter Next(fTasks);
|
---|
815 | while ((cont=Next()))
|
---|
816 | if (!cont->WriteEnv(env, prefix, print))
|
---|
817 | return kFALSE;
|
---|
818 | return kTRUE;
|
---|
819 | }
|
---|
820 |
|
---|
821 | // --------------------------------------------------------------------------
|
---|
822 | //
|
---|
823 | // Removes a task from the tasklist. Returns kFALSE if the object was not
|
---|
824 | // found in the list.
|
---|
825 | //
|
---|
826 | Bool_t MTaskList::RemoveFromList(MTask *task)
|
---|
827 | {
|
---|
828 | TObject *obj = fTasks->Remove(task);
|
---|
829 |
|
---|
830 | //
|
---|
831 | // If the task was found in the list try to remove it from the second
|
---|
832 | // list, too.
|
---|
833 | //
|
---|
834 | if (obj)
|
---|
835 | fTasksProcess.Remove(task);
|
---|
836 |
|
---|
837 | return obj ? kTRUE : kFALSE;
|
---|
838 |
|
---|
839 | }
|
---|