source: branches/start/MagicSoft/Mars/mbase/MTaskList.cc@ 9223

Last change on this file since 9223 was 454, checked in by harald, 24 years ago
Import the first sources of the MAGIC Analysis and Reconstruction Software. T. Bretz and H. Kornmayer 20.December 2000
File size: 4.4 KB
Line 
1///////////////////////////////////////////////////////////////////////
2// //
3// MTaskList //
4// //
5// Collection of tasks which should be processed in the eventloop //
6// //
7///////////////////////////////////////////////////////////////////////
8
9#include "MTaskList.h"
10
11#include <iostream.h>
12
13#include "MParList.h"
14#include "MInputStreamID.h"
15
16ClassImp(MTaskList)
17
18MTaskList::MTaskList(const char *title)
19{
20 //
21 // the name for the task list must be the same for all task lists
22 // because the task list (at the moment) is identified by exactly
23 // this name in the parameter list (by MEvtLoop::SetParList)
24 //
25 *fName = "MTaskList";
26 *fTitle = title ? title : "List for Tasks";
27
28 //
29 // default constructor: create empty task list
30 //
31}
32
33MTaskList::MTaskList(MTaskList &ts)
34{
35 //
36 // CopyConstructor
37 // creates a new TaskList and put the contents of an existing
38 // TaskList in the new TaskList.
39 //
40 fTasks.AddAll(&ts.fTasks);
41}
42
43Bool_t MTaskList::AddToList(MTask *task, const char *type, MTask *where)
44{
45 // schedule task for execution, whether as first task, or after
46 // 'where'. 'tType' is the event type which should be processed
47 if (!task)
48 return kTRUE;
49
50 const char *name = task->GetName();
51
52 // FIXME: We agreed to put the task into list in an ordered way.
53
54 if (fTasks.FindObject(task))
55 {
56 cout << "WARNING: MTaskList::AddToList: Task already existing." << endl;
57 return kTRUE;
58 }
59
60 if (fTasks.FindObject(name))
61 {
62 cout << "WARNING: MTaskList::AddToList: '" << name << "' exists in List already." << endl;
63 return kTRUE;
64 }
65
66 if (where)
67 {
68 if (!fTasks.FindObject(where))
69 {
70 printf("ERROR: MTaskList::AddToList: Cannot find task after which the new task should be scheduled!\n");
71 return kFALSE;
72 }
73 }
74
75 cout << "Adding " << name << " to " << GetName() << " for " << type << "... " << flush;
76
77 task->SetStreamId(type);
78 fTasks.Add(task);
79
80 cout << "Done." << endl;
81
82 return kTRUE;
83}
84
85
86Bool_t MTaskList::PreProcess( MParList *pList )
87{
88 //
89 // do pre processing (before eventloop) of all tasks in the task-list
90 //
91 cout << "Preprocessing... " << flush;
92
93 //
94 // create the Iterator over the tasklist
95 //
96 TIter next(&fTasks);
97
98 MTask *task=NULL;
99
100 //
101 // loop over all tasks for preproccesing
102 //
103 while ( (task=(MTask*)next()) )
104 {
105 cout << task->GetName() << "... " << flush;
106
107 if (!task->PreProcess( pList ))
108 return kFALSE;
109 }
110
111 cout << endl;
112
113 return kTRUE;
114}
115
116Bool_t MTaskList::Process()
117{
118 //
119 // do the event execution of all tasks in the task-list
120 //
121
122 //
123 // create the Iterator for the TaskList
124 //
125 TIter next(&fTasks);
126 MTask *task=NULL;
127
128 //
129 // loop over all tasks for processing
130 //
131 while ( (task=(MTask*)next()) )
132 {
133 if (!strcmp(GetStreamId(), task->GetStreamId()) ||
134 !strcmp(task->GetStreamId(), "All"))
135 {
136 switch (task->Process())
137 {
138 case kTRUE:
139 //
140 // everything was OK: go on
141 //
142 continue;
143
144 case kFALSE:
145 //
146 // an error occured: stop eventloop
147 //
148 return kFALSE;
149
150 case kCONTINUE:
151 //
152 // something occured: skip the rest of the tasks for this event
153 //
154 break;
155 }
156 }
157 }
158 return kTRUE;
159}
160
161Bool_t MTaskList::PostProcess()
162{
163 //
164 // do post processing (before eventloop) of all tasks in the task-list
165 //
166
167 cout << "Postprocessing... " << flush;
168
169 //
170 // create the Iterator for the TaskList
171 //
172 TIter next(&fTasks);
173
174 MTask *task=NULL;
175
176 //
177 // loop over all tasks for postprocessing
178 //
179 while ( (task=(MTask*)next()) )
180 {
181 cout << task->GetName() << "... " << flush;
182
183 if (!task->PostProcess())
184 return kFALSE;
185 }
186
187 cout << endl;
188
189 return kTRUE;
190}
191
192
193
194void MTaskList::Print(Option_t *t)
195{
196 cout << "TaskList: " << this->GetName() << " <" << this->GetTitle() << ">" << endl;
197
198 fTasks.Print();
199
200 cout << endl;
201}
202
Note: See TracBrowser for help on using the repository browser.