source: trunk/MagicSoft/Mars/mbase/MTask.cc@ 992

Last change on this file since 992 was 988, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 6.9 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// 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
74ClassImp(MTask);
75
76MTask::MTask(const char *name, const char *title)
77 : fFilter(NULL), fIsPreprocessed(kFALSE), fNumExecutions()
78{
79 *fName = name ? name : "MTask";
80 *fTitle = title ? title : "Base class for all tasks (dummy task).";
81}
82
83// --------------------------------------------------------------------------
84//
85// Mapper function for PreProcess.
86// Sets the preprocessed flag dependend on the return value of PreProcess.
87//
88Bool_t MTask::CallPreProcess(MParList *plist)
89{
90 if (!PreProcess(plist))
91 return kFALSE;
92
93 fIsPreprocessed = kTRUE;
94 return kTRUE;
95}
96
97// --------------------------------------------------------------------------
98//
99// Mapper function for Process.
100// Executes Process dependent on the existance of a filter and its possible
101// return value.
102// If Process is executed, the execution counter is increased.
103//
104inline Bool_t MTask::CallProcess()
105{
106 //
107 // Check for the existance of a filter. If a filter is existing
108 // check for its value. If the value is kFALSE don't execute
109 // this task.
110 //
111 const Bool_t exec = fFilter ? fFilter->IsExpressionTrue() : kTRUE;
112
113 if (!exec)
114 return kTRUE;
115
116 fNumExecutions++;
117 return Process();
118}
119
120// --------------------------------------------------------------------------
121//
122// Mapper function for PreProcess.
123// Calls Postprocess dependent on the state of the preprocessed flag,
124// resets this flag.
125//
126Bool_t MTask::CallPostProcess()
127{
128 if (!fIsPreprocessed)
129 return kTRUE;
130
131 fIsPreprocessed = kFALSE;
132 return PostProcess();
133}
134
135// --------------------------------------------------------------------------
136//
137// This is processed before the eventloop starts
138//
139// It is the job of the PreProcess to connect the tasks
140// with the right container in the parameter list.
141//
142// the virtual implementation returns kTRUE
143//
144Bool_t MTask::PreProcess(MParList *pList)
145{
146 return kTRUE;
147}
148
149// --------------------------------------------------------------------------
150//
151// This is processed for every event in the eventloop
152//
153// the virtual implementation returns kTRUE
154//
155Bool_t MTask::Process()
156{
157 return kTRUE;
158}
159
160// --------------------------------------------------------------------------
161//
162// This is processed after the eventloop starts
163//
164// the virtual implementation returns kTRUE
165//
166Bool_t MTask::PostProcess()
167{
168 return kTRUE;
169}
170
171// --------------------------------------------------------------------------
172//
173// Prints the number of times this task has been processed.
174// For convinience the lvl argument results in a number of spaces at the
175// beginning of the line. So that the structur of a tasklist can be
176// identified.
177//
178void MTask::PrintStatistics(const Int_t lvl) const
179{
180 *fLog << setw(lvl) << " " << GetName() << " [";
181 *fLog << ClassName() << "] \t" << fNumExecutions;
182 *fLog << endl;
183}
Note: See TracBrowser for help on using the repository browser.