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

Last change on this file since 1076 was 1076, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 8.3 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 <TMethod.h>
70#include <TOrdCollection.h>
71
72#include "MLog.h"
73#include "MLogManip.h"
74
75#include "MFilter.h"
76#include "MGGroupFrame.h"
77
78ClassImp(MTask);
79
80MTask::MTask(const char *name, const char *title)
81 : fFilter(NULL), fIsPreprocessed(kFALSE), fNumExecutions(0)
82{
83 fName = name ? name : "MTask";
84 fTitle = title ? title : "Base class for all tasks (dummy task).";
85
86 fListOfBranches = new TOrdCollection;
87 fListOfBranches->SetOwner();
88}
89
90MTask::~MTask()
91{
92 delete fListOfBranches;
93}
94
95// --------------------------------------------------------------------------
96//
97// This adds a branch to the list for the auto enabeling schmeme.
98// This makes it possible for MReadTree to decide which branches
99// are really needed for the eventloop. Only the necessary branches
100// are read from disk which speeds up the calculation enormously.
101//
102// You can use TRegExp expressions like "*.fEnergy", but the
103// recommended method is to call this function for exactly all
104// branches you want to have, eg:
105// AddToBranchList("MMcTrig;1.fNumFirstLevel");
106// AddToBranchList("MMcTrig;2.fNumFirstLevel");
107//
108// We agreed on the convetion, that all branches are stored with
109// a trailing dot '.' so that always the Master Branch name
110// (eg. MMcTrig) is part of the branch name.
111//
112// Remark: The common place to call AddToBranchList is the
113// constructor of the derived classes (tasks)
114//
115void MTask::AddToBranchList(const char *b)
116{
117 TNamed *name = new TNamed(b, "");
118 fListOfBranches->Add(name);
119}
120
121// --------------------------------------------------------------------------
122//
123// Copy constructor.
124//
125MTask::MTask(MTask &t)
126{
127 fFilter = t.fFilter;
128 fListOfBranches->AddAll(t.fListOfBranches);
129}
130
131// --------------------------------------------------------------------------
132//
133// Mapper function for PreProcess.
134// Sets the preprocessed flag dependend on the return value of PreProcess.
135//
136Bool_t MTask::CallPreProcess(MParList *plist)
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//
152Bool_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//
174Bool_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 processed before the eventloop starts
187//
188// It is the job of the PreProcess to connect the tasks
189// with the right container in the parameter list.
190//
191// the virtual implementation returns kTRUE
192//
193Bool_t MTask::PreProcess(MParList *pList)
194{
195 return kTRUE;
196}
197
198// --------------------------------------------------------------------------
199//
200// This is processed for every event in the eventloop
201//
202// the virtual implementation returns kTRUE
203//
204Bool_t MTask::Process()
205{
206 return kTRUE;
207}
208
209// --------------------------------------------------------------------------
210//
211// This is processed after the eventloop starts
212//
213// the virtual implementation returns kTRUE
214//
215Bool_t MTask::PostProcess()
216{
217 return kTRUE;
218}
219
220// --------------------------------------------------------------------------
221//
222// Prints the number of times this task has been processed.
223// For convinience the lvl argument results in a number of spaces at the
224// beginning of the line. So that the structur of a tasklist can be
225// identified.
226//
227void MTask::PrintStatistics(const Int_t lvl) const
228{
229 *fLog << setw(lvl) << " " << GetDescriptor() << "\t";
230 *fLog << dec << fNumExecutions << endl;
231}
232
Note: See TracBrowser for help on using the repository browser.