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

Last change on this file since 770 was 752, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 6.4 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 //
138 // create the Iterator over the tasklist
139 //
140 TIter Next(&fTasks);
141
142 MTask *task=NULL;
143
144 //
145 // loop over all tasks for preproccesing
146 //
147 while ( (task=(MTask*)Next()) )
148 {
149 *fLog << task->GetName() << "... " << flush;
150
151 if (!task->PreProcess( pList ))
152 return kFALSE;
153 }
154
155 *fLog << endl;
156
157 return kTRUE;
158}
159
160// --------------------------------------------------------------------------
161//
162// do the event execution of all tasks in the task-list
163//
164Bool_t MTaskList::Process()
165{
166 //
167 // create the Iterator for the TaskList
168 //
169 TIter Next(&fTasks);
170 MTask *task=NULL;
171
172 //
173 // loop over all tasks for processing
174 //
175 while ( (task=(MTask*)Next()) )
176 {
177 //
178 // if the task has the wrong stream id skip it.
179 //
180 if (strcmp(GetStreamId(), task->GetStreamId()) &&
181 strcmp(task->GetStreamId(), "All"))
182 continue;
183
184 //
185 // if it has the right stream id execute the Process() function
186 // and check what the result of it is.
187 //
188 switch (task->Process())
189 {
190 case kTRUE:
191 //
192 // everything was OK: go on
193 //
194 continue;
195
196 case kFALSE:
197 //
198 // an error occured: stop eventloop
199 //
200 return kFALSE;
201
202 case kCONTINUE:
203 //
204 // something occured: skip the rest of the tasks for this event
205 //
206 break;
207 }
208 }
209 return kTRUE;
210}
211
212// --------------------------------------------------------------------------
213//
214// do post processing (before eventloop) of all tasks in the task-list
215//
216Bool_t MTaskList::PostProcess()
217{
218 *fLog << "Postprocessing... " << flush;
219
220 //
221 // create the Iterator for the TaskList
222 //
223 TIter Next(&fTasks);
224
225 MTask *task=NULL;
226
227 //
228 // loop over all tasks for postprocessing
229 //
230 while ( (task=(MTask*)Next()) )
231 {
232 *fLog << task->GetName() << "... " << flush;
233
234 if (!task->PostProcess())
235 return kFALSE;
236 }
237
238 *fLog << endl;
239
240 return kTRUE;
241}
242
243// --------------------------------------------------------------------------
244void MTaskList::Print(Option_t *t)
245{
246 *fLog << "TaskList: " << this->GetName() << " <" << this->GetTitle() << ">" << endl;
247
248 fTasks.Print();
249
250 *fLog << endl;
251}
252
Note: See TracBrowser for help on using the repository browser.