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

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