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

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