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

Last change on this file since 608 was 608, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 4.7 KB
Line 
1///////////////////////////////////////////////////////////////////////
2// //
3// MTaskList //
4// //
5// Collection of tasks to 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
43void MTaskList::SetLogStream(MLog *log)
44{
45 //
46 // create the Iterator over the tasklist
47 //
48 TIter Next(&fTasks);
49
50 MTask *task=NULL;
51
52 //
53 // loop over all tasks for preproccesing
54 //
55 while ( (task=(MTask*)Next()) )
56 task->SetLogStream(log);
57
58// SetLogStream(log);
59}
60
61
62Bool_t MTaskList::AddToList(MTask *task, const char *type, MTask *where)
63{
64 // schedule task for execution, whether as first task, or after
65 // 'where'. 'tType' is the event type which should be processed
66 if (!task)
67 return kTRUE;
68
69 const char *name = task->GetName();
70
71 // FIXME: We agreed to put the task into list in an ordered way.
72
73 if (fTasks.FindObject(task))
74 {
75 cout << "WARNING: MTaskList::AddToList: Task already existing." << endl;
76 return kTRUE;
77 }
78
79 if (fTasks.FindObject(name))
80 {
81 cout << "WARNING: MTaskList::AddToList: '" << name << "' exists in List already." << endl;
82 return kTRUE;
83 }
84
85 if (where)
86 {
87 if (!fTasks.FindObject(where))
88 {
89 printf("ERROR: MTaskList::AddToList: Cannot find task after which the new task should be scheduled!\n");
90 return kFALSE;
91 }
92 }
93
94 cout << "Adding " << name << " to " << GetName() << " for " << type << "... " << flush;
95
96 task->SetStreamId(type);
97 fTasks.Add(task);
98
99 cout << "Done." << endl;
100
101 return kTRUE;
102}
103
104
105Bool_t MTaskList::PreProcess( MParList *pList )
106{
107 //
108 // do pre processing (before eventloop) of all tasks in the task-list
109 //
110 cout << "Preprocessing... " << flush;
111
112 //
113 // create the Iterator over the tasklist
114 //
115 TIter Next(&fTasks);
116
117 MTask *task=NULL;
118
119 //
120 // loop over all tasks for preproccesing
121 //
122 while ( (task=(MTask*)Next()) )
123 {
124 cout << task->GetName() << "... " << flush;
125
126 if (!task->PreProcess( pList ))
127 return kFALSE;
128 }
129
130 cout << endl;
131
132 return kTRUE;
133}
134
135Bool_t MTaskList::Process()
136{
137 //
138 // do the event execution of all tasks in the task-list
139 //
140
141 //
142 // create the Iterator for the TaskList
143 //
144 TIter Next(&fTasks);
145 MTask *task=NULL;
146
147 //
148 // loop over all tasks for processing
149 //
150 while ( (task=(MTask*)Next()) )
151 {
152 if (!strcmp(GetStreamId(), task->GetStreamId()) ||
153 !strcmp(task->GetStreamId(), "All"))
154 {
155 switch (task->Process())
156 {
157 case kTRUE:
158 //
159 // everything was OK: go on
160 //
161 continue;
162
163 case kFALSE:
164 //
165 // an error occured: stop eventloop
166 //
167 return kFALSE;
168
169 case kCONTINUE:
170 //
171 // something occured: skip the rest of the tasks for this event
172 //
173 break;
174 }
175 }
176 }
177 return kTRUE;
178}
179
180Bool_t MTaskList::PostProcess()
181{
182 //
183 // do post processing (before eventloop) of all tasks in the task-list
184 //
185
186 cout << "Postprocessing... " << flush;
187
188 //
189 // create the Iterator for the TaskList
190 //
191 TIter Next(&fTasks);
192
193 MTask *task=NULL;
194
195 //
196 // loop over all tasks for postprocessing
197 //
198 while ( (task=(MTask*)Next()) )
199 {
200 cout << task->GetName() << "... " << flush;
201
202 if (!task->PostProcess())
203 return kFALSE;
204 }
205
206 cout << endl;
207
208 return kTRUE;
209}
210
211
212
213void MTaskList::Print(Option_t *t)
214{
215 cout << "TaskList: " << this->GetName() << " <" << this->GetTitle() << ">" << endl;
216
217 fTasks.Print();
218
219 cout << endl;
220}
221
Note: See TracBrowser for help on using the repository browser.