HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
htaskset.cc
Go to the documentation of this file.
1 using namespace std;
2 #include "htaskset.h"
3 #include "hdebug.h"
4 #include "hmessagemgr.h"
5 #include "hades.h"
6 #include "TROOT.h"
7 #include "TClass.h"
8 #include "haddef.h"
9 #include "TBrowser.h"
10 
11 #include <iostream>
12 #include <iomanip>
13 
14 //*-- Author : Manuel Sanchez
15 //*-- Modified: 13/02/2004 by R. Holzmann
16 //*-- Modified: 19/11/2001 by D. Magestro
17 //*-- Modified: 09/03/2000 by R. Holzmann
18 //*-- Modified: 26/5/1999 by D.Bertini
19 //*-- Modified: 9/11/1998
20 
21 //_HADES_CLASS_DESCRIPTION
22 ///////////////////////////////////////////////////////////////////////////////
23 // HTaskSet
24 //
25 // This HTask is in fact a set of tasks arbitrarily connected among themselves.
26 //
27 // The tasks are connected such that when a task is finished a pointer to
28 // the next task is retrieved; note that the tasks must not necessarily be
29 // connected in a linear fashion.
30 ///////////////////////////////////////////////////////////////////////////////
31 
32 HTaskSet::HTaskSet(const Text_t name[],const Text_t title[]) : HTask(name,title) {
33  // Constructor
34  fFirstTask=0;
35  fNextTask=0;
36  fIsTimed=kFALSE;
37  owner=0;
38  for (Int_t i=0;i<8;i++) ids[i] = -1;
39 }
40 
41 
43  // Default constructor
44  fIsTimed=kFALSE;
45  owner=0;
46  for (Int_t i=0;i<8;i++) ids[i] = -1;
47 }
48 
49 /*
50 // old code .... its not a copy and and not used ... so don"t allow it
51  HTaskSet::HTaskSet(HTaskSet &ts) {
52  // Copy constructor.
53  fFirstTask=ts.fFirstTask;
54  fNextTask=ts.fNextTask;
55  fTasks.AddAll(&ts.fTasks);
56  fIsTimed=ts.fIsTimed;
57  owner=ts.owner;
58  for (Int_t i=0;i<8;i++) ids[i] = ts.ids[i];
59 }
60 */
61 
63  // Destructor.
64  fTasks.Delete();
65 }
66 
67 
68 HTask* HTaskSet::getTask(const Char_t *name) {
69  // return pointer to first task of given name found
70  if (strcmp(GetName(),name)==0) return this;
71 
72  HTask* task=NULL;
73  HTask* found=NULL;
74  TIterator *iter=fTasks.MakeIterator();
75  while ( (task=(HTask*)iter->Next()) ) {
76  if ( (found=task->getTask(name)) ) return found;
77  }
78  return NULL;
79 }
80 
81 
82 Bool_t HTaskSet::add( HTask* task ){
83  // For the moment only elementary task are added
84 
85  if ( fTasks.IsEmpty() ) {
86  fTasks.Add( task );
87  fFirstTask=task;
88  task->setOwner(this);
89  return kTRUE;
90  } else {
91  HTask* pTask = (HTask*) fTasks.Last();
92  pTask->connectTask(task,0);
93  if (!(fTasks.FindObject(task))) fTasks.Add( task );
94  task->setOwner(this);
95  return kTRUE;
96  }
97 }
98 
99 Bool_t HTaskSet::connect(HTask *task) {
100  // Connects "task" as the first task to be performed in the set.
101  if (!fTasks.FindObject(task)) fTasks.Add(task);
102  fFirstTask=task;
103  task->setOwner(this);
104  return kTRUE;
105 }
106 
107 
108 Bool_t HTaskSet::connect(HTask *task,HTask *where,Int_t n) {
109  // connects task "task" to the task "where" with parameter "n"
110  if(!task) return kTRUE;
111  if (where) {
112  if (fTasks.FindObject(where)) {
113  where->connectTask(task,n);
114  if (!(fTasks.FindObject(task))) fTasks.Add(task);
115  } else return kFALSE;
116  } else {
117  fTasks.Add(task);
118  fFirstTask=task;
119  }
120  task->setOwner(this);
121  return kTRUE;
122 }
123 
124 
125 Bool_t HTaskSet::connect(HTask *task,const Text_t *where,Int_t n) {
126  // Connects task "task" to the task with name "where" using "n" as parameter.
127  if(!task) return kTRUE;
128  if(where) {
129  HTask *wh=NULL;
130  wh=(HTask *)fTasks.FindObject(where);
131  if (wh) {
132  if(wh->connectTask(task,n)) {
133  if (!(fTasks.FindObject(task))) fTasks.Add(task);
134  } else {
135  WARNING_msg(10,HMessageMgr::DET_ALL,"Problem in connecting task!\n");
136  return kFALSE;
137  }
138  } else return kFALSE;
139  task->setOwner(this);
140  return kTRUE;
141  }
142  return kFALSE;
143 }
144 
145 
146 Bool_t HTaskSet::connect(const Text_t task[],const Text_t where[],Int_t n) {
147  // Connects the task named "task" to the one named "where" using "n" as
148  // parameter.
149  HTask *ta=NULL,*wh=NULL;
150  wh=(HTask *)fTasks.FindObject(where);
151  ta=(HTask *)fTasks.FindObject(task);
152  if (ta && wh) {
153  wh->connectTask(ta,n);
154  if (!(fTasks.FindObject(task))) fTasks.Add(ta);
155  } else return kFALSE;
156  ta->setOwner(this);
157  return kTRUE;
158 }
159 
160 
161 void HTaskSet::Clear(Option_t *opt) {
162 
163 //FIXME: "HTaskSet::Clear should clear not delete..."
164  fTasks.Delete();
165  fFirstTask=NULL;
166  fNextTask=NULL;
167 }
168 
169 
170 Bool_t HTaskSet::init(void) {
171  // Calls the init function for each of the tasks in the task set.
172  TIter next(&fTasks);
173  HTask *task=NULL;
174  if(fIsTimed) resetTimer();
175  while ( (task=(HTask *)next())!=NULL) {
176  if (!task->init()) {
177  Error("init","%s initialization failed!",task->GetName());
178  return kFALSE;
179  }
180  }
181  return kTRUE;
182 }
183 
184 
185 Bool_t HTaskSet::reinit(void) {
186  // Calls the init function for each of the tasks in the task set.
187  TIter next(&fTasks);
188  HTask *task=NULL;
189  while ( (task=(HTask *)next())!=NULL) {
190  if (!(task->reinit())) { Error("reinit()","Error returned from %s",task->GetName()); return kFALSE; }
191  }
192  return kTRUE;
193 }
194 
195 
196 Bool_t HTaskSet::finalize(void) {
197  // Calls the finalize function for each of the tasks in the set
198  TIter next(&fTasks);
199  HTask *task=NULL;
200  while ( (task=(HTask *)next())!=NULL) {
201  if (!task->finalize()) return kFALSE;
202  }
203  return kTRUE;
204 }
205 
206 
207 void HTaskSet::print(void) {
208  // Dumps dependencies for each of the tasks in the set
209  TIter next(&fTasks);
210  HTask *task=NULL;
211 
212  if(owner==NULL) {
213  gHades->getMsg()->info(10,HMessageMgr::DET_ALL,GetName(),"=== TASK SET: %-15s ========================\n",
214  GetName());
215  }
216  else if(owner->getOwner()==NULL) {
217  gHades->getMsg()->info(10,HMessageMgr::DET_ALL,GetName(),"--- Task Set: %-15s -------------------\n",
218  GetName());
219  }
220  else {
221  gHades->getMsg()->info(10,HMessageMgr::DET_ALL,GetName(),"- - Task set: %-15s - - - - - - - -\n",
222  GetName());
223  }
224  while ( (task=(HTask *)next())!=NULL) {
225  if(strcmp((task->IsA())->GetName(),"HTaskSet")==0) {
226  ((HTaskSet*) task)->print();
227  SEPERATOR_msg("-",63);
228  //printf("\n");
229  }
230  else { task->getConnections(); }
231  }
232 
233  if(owner==NULL) { SEPERATOR_msg("=",63); }
234  //printf("================================================================\n\n");
235 // else
236 // printf("-----------------------------------------------------------\n");
237 }
238 
239 
240 void HTaskSet::setIds(Int_t i0, Int_t i1, Int_t i2, Int_t i3, Int_t i4,
241  Int_t i5, Int_t i6, Int_t i7) {
242  // set event ids for which this task set should execute
243  //
244  ids[0] = i0;
245  ids[1] = i1;
246  ids[2] = i2;
247  ids[3] = i3;
248  ids[4] = i4;
249  ids[5] = i5;
250  ids[6] = i6;
251  ids[7] = i7;
252 
253 }
254 
255 HTask* HTaskSet::next(Int_t &errCode, Int_t evtId) {
256  // do tasks only if evtId matches with one of the 8 tabulated ids
257  //
258  if (fFirstTask) {
259  for (Int_t i=0;i<8; i++) if (evtId==ids[i]) return next(errCode);
260  }
261  return NULL;
262 }
263 
264 HTask *HTaskSet::next(Int_t &errCode) {
265  // Iterates throught the task set. When the iteration is finished it
266  // returns a pointer to the next task as set by connectTask()
267  HTask *task;
268  if (fFirstTask==NULL) return fNextTask; // task set is empty
269  Int_t err=0;
270 
271  //loop over task in the list
272  task=fFirstTask;
273  while (task) {
274  task=task->next(err);
275  }
276  errCode=err;
277  // check the errcode value stop and skipevent
278  // (when skipping an event in a multi-tasklist
279  // layout, the next tasklist is correctly skipped
280 
281  if (errCode == kSTOP || errCode == kSkipEvent) return NULL;
282  return fNextTask;
283 }
284 
285 
286 Bool_t HTaskSet::connectTask(HTask *task,Int_t) {
287  // Connects "task" as the next task to be performed; n is ignored.
288  fNextTask=task;
289  return kTRUE;
290 }
291 
292 
293 Bool_t HTaskSet::IsFolder(void) const {
294  // Returns true. This tells the Root browser to show HTaskSet as a folder
295  // holding other objects
296  return kTRUE;
297 }
298 
299 
300 void HTaskSet::Browse(TBrowser *b) {
301  // Adds the tasks in the this taskset to the current ROOT browser.
302  //
303  // This function is called by Root when browsing gHades with the Root browser
304  //
305 
306  TIterator *next=fTasks.MakeIterator();
307  TObject *task=0;
308 
309  while ( (task=(HTask *)next->Next()) != 0) {
310  b->Add(task);
311  }
312  delete next;
313 }
314 
315 
316 void HTaskSet::isTimed(Bool_t flag) {
317  // Set timing flag for all tasks in set
318  TIter next(&fTasks);
319  HTask *task=NULL;
320  while ( (task=(HTask *)next()) != NULL ) task->isTimed(flag);
321  fIsTimed = flag;
322 }
323 
324 
326  // Calls the reset function for each of the task timers in the task set.
327  if(fIsTimed) {
328  TIter next(&fTasks);
329  HTask *task=NULL;
330  while ( (task=(HTask *)next()) != NULL ) task->resetTimer();
331  }
332 }
333 
334 
336  // Calls the print function for each of the task timers in the task set.
337  if(fIsTimed) {
338  TIter next(&fTasks);
339  HTask *task=NULL;
340  gHades->getMsg()->infoB(10,HMessageMgr::DET_ALL,"Timing information for taskset %s:\n",this->GetName());
341  while ( (task=(HTask *)next()) != NULL ) task->printTimer();
342  }
343  else gHades->getMsg()->infoB(10,HMessageMgr::DET_ALL,"No timing information has been collected for taskset %s!\n",
344  this->GetName());
345 }
346 
347 void HTaskSet::Streamer(TBuffer &R__b)
348 {
349  // Stream an object of class HTaskSet.
350 
351  UInt_t R__s, R__c;
352  if (R__b.IsReading()) {
353  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
354  HTask::Streamer(R__b);
355  fTasks.Streamer(R__b);
356  R__b >> fNextTask;
357  R__b >> fFirstTask;
358  if (R__v > 1 )R__b.ReadStaticArray(ids);
359  else for (Int_t i=0; i<8; i++) ids[i] = 0;
360  R__b.CheckByteCount(R__s, R__c, HTaskSet::IsA());
361  } else {
362  R__c = R__b.WriteVersion(HTaskSet::IsA(), kTRUE);
363  HTask::Streamer(R__b);
364  fTasks.Streamer(R__b);
365  R__b << fNextTask;
366  R__b << fFirstTask;
367  R__b.WriteArray(ids, 8);
368  R__b.SetByteCount(R__c, kTRUE);
369  }
370 }
371 
373 
374 
375 
376 
377 
378 
379 
380 
381 
382 
383 
384 
385 
386 
387 
388 
389 
390 
391 
392 
393 
394 
395 
396 
397 
398 
399 
400 
401 
402 
403 
404 
void resetTimer(void)
Definition: htaskset.cc:325
void Browse(TBrowser *b)
Definition: htaskset.cc:300
virtual Bool_t init(void)=0
#define WARNING_msg(level, det, text)
Definition: hmessagemgr.h:45
void printTimer(void)
Definition: htaskset.cc:335
HTaskSet(void)
Definition: htaskset.cc:42
virtual Bool_t reinit(void)
Definition: htask.h:33
HTask * fFirstTask
Definition: htaskset.h:13
HTask * fNextTask
Definition: htaskset.h:12
const Int_t kSkipEvent
Definition: haddef.h:30
virtual HTask * next(Int_t &errCode)=0
Bool_t fIsTimed
Definition: htask.h:20
void Clear(Option_t *opt="")
Definition: htaskset.cc:161
Int_t n
Bool_t connect(HTask *)
Definition: htaskset.cc:99
ClassImp(HDbColumn) HDbColumn
Definition: hdbcolumn.cc:18
void print()
Definition: htaskset.cc:207
virtual void isTimed(Bool_t)=0
void info(Char_t level, Int_t det, const Char_t *className, const Char_t *text)
Definition: hmessagemgr.cc:473
HTask * owner
Definition: htask.h:16
void infoB(Char_t level, Int_t det, const Char_t *text,...)
Definition: hmessagemgr.cc:719
Bool_t finalize(void)
Definition: htaskset.cc:196
virtual Bool_t connectTask(HTask *task, Int_t n)=0
Bool_t reinit(void)
Definition: htaskset.cc:185
virtual void resetTimer()=0
const TaskControl kSTOP
Definition: htask.h:8
virtual HTask * getOwner()
Definition: htask.h:38
Hades * gHades
Definition: hades.cc:1213
TOrdCollection fTasks
Definition: htaskset.h:11
virtual void getConnections()
Definition: htask.h:36
void isTimed(Bool_t flag=kTRUE)
Definition: htaskset.cc:316
Bool_t IsFolder(void) const
Definition: htaskset.cc:293
Int_t ids[8]
Definition: htaskset.h:14
HTask * getTask(const Char_t *name)
Definition: htaskset.cc:68
virtual void setOwner(HTask *atask)
Definition: htask.h:39
Bool_t add(HTask *)
Definition: htaskset.cc:82
Definition: htask.h:14
#define SEPERATOR_msg(sep, num)
Definition: hmessagemgr.h:63
virtual Bool_t finalize(void)=0
void setIds(Int_t i0, Int_t i1=-1, Int_t i2=-1, Int_t i3=-1, Int_t i4=-1, Int_t i5=-1, Int_t i6=-1, Int_t i7=-1)
Definition: htaskset.cc:240
~HTaskSet(void)
Definition: htaskset.cc:62
virtual HTask * getTask(const Char_t *name)=0
HTask * next(Int_t &errCode)
Definition: htaskset.cc:264
Bool_t init(void)
Definition: htaskset.cc:170
HMessageMgr * getMsg(void)
Definition: hades.h:113
Bool_t connectTask(HTask *, Int_t n)
Definition: htaskset.cc:286
virtual void printTimer()=0