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

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