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