source: trunk/MagicSoft/MarsOctober/mbase/MTaskList.cc@ 5138

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