source: trunk/Mars/mbase/MTask.h@ 19159

Last change on this file since 19159 was 14447, checked in by tbretz, 12 years ago
Added some missing std::
File size: 4.7 KB
Line 
1#ifndef MARS_MTask
2#define MARS_MTask
3
4/////////////////////////////////////////////////////////////////////////////
5// //
6// MTask //
7// //
8// Abstract base class for a task //
9// //
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef MARS_MInputStreamID
13#include "MInputStreamID.h"
14#endif
15
16class TList;
17class TStopwatch;
18
19class MFilter;
20class MParList;
21
22class MTask : public MInputStreamID
23{
24public:
25 enum {
26 kAccStandard = 0,
27 kAccDontTime = BIT(1),
28 kAccDontReset = BIT(2)
29 };
30
31private:
32 TList *fListOfBranches; //! List of Branch names for auto enabeling scheme
33
34 MFilter *fFilter; // Filter for conditional task execution
35 Byte_t fSerialNumber; // Serial number having more than one detector of the same type
36
37 Bool_t fIsPreprocessed; //! Indicates the success of the PreProcessing (set by MTaskList)
38
39 TStopwatch *fStopwatch; //! Count the execution time and number of executions
40 UInt_t fNumExecutions; //! Number of executions (also counted by fStopwatch, but faster)
41 UInt_t fNumExec0; //! Total number of executions at PreProcess
42 Byte_t fAccelerator; //!
43
44 virtual Int_t PreProcess(MParList *pList);
45 virtual Int_t Process();
46 virtual Int_t PostProcess();
47
48protected:
49 void AddToBranchList(const char *b);
50 void AddToBranchList(const TString &str);
51 void AddToBranchList(const char *master, const char *sub, const UInt_t first, const UInt_t last)
52 {
53 if (first==0 && last==0)
54 {
55 AddToBranchList(sub);
56 return;
57 }
58
59 for (unsigned int i=first; i<last+1; i++)
60 AddToBranchList(Form("%s;%d.%s", master, i, sub));
61 }
62 void AddToBranchList(TString &master, TString &sub, const UInt_t first, const UInt_t last)
63 {
64 AddToBranchList((const char*)master, (const char*)sub, first, last);
65 }
66 void AddToBranchList(const char *master, const char *sub, const UInt_t num)
67 {
68 AddToBranchList(master, sub, 0, num);
69 }
70 void AddToBranchList(TString &master, TString &sub, const UInt_t num)
71 {
72 AddToBranchList(master, sub, 0, num);
73 }
74
75public:
76 MTask(const char *name=NULL, const char *title=NULL);
77 MTask(MTask &t);
78 virtual ~MTask();
79
80 const TList *GetListOfBranches() const { return fListOfBranches; }
81 Bool_t Overwrites(const char *name, TClass *cls=NULL) const { return MParContainer::Overwrites(MTask::Class(), *this, name, cls); }
82
83 // Filter functions
84 virtual void SetFilter(MFilter *filter);
85 const MFilter *GetFilter() const { return fFilter; }
86 MFilter *GetFilter() { return fFilter; } // for MContinue only
87
88 // Display functions
89 void SetDisplay(MStatusDisplay *d);
90
91 // Acceleration Control
92 virtual void SetAccelerator(Byte_t acc=kAccStandard) { fAccelerator=acc; }
93 Byte_t GetAccelerator() const { return fAccelerator; }
94 Bool_t HasAccelerator(Byte_t acc) const { return fAccelerator&acc; }
95
96 // Function for parallel executions
97 static TString AddSerialNumber(const char *str, UInt_t num) { TString s(str); if (num==0) return s; s += ";"; s += num; return s; }
98 static TString AddSerialNumber(const TString &str, UInt_t num) { return AddSerialNumber((const char*)str, num); }
99 TString AddSerialNumber(const char *str) const { return AddSerialNumber(str, fSerialNumber); }
100 TString AddSerialNumber(const TString &str) const { return AddSerialNumber(str, fSerialNumber); }
101
102 virtual void SetSerialNumber(Byte_t num) { fSerialNumber = num; }
103 Byte_t GetSerialNumber() const { return fSerialNumber; }
104
105 const TString GetDescriptor() const;
106
107 // Task execution statistics
108 UInt_t GetNumExecutions() const;
109 UInt_t GetNumExecutionsTotal() const;
110 Double_t GetCpuTime() const;
111 Double_t GetRealTime() const;
112 virtual void PrintStatistics(const Int_t lvl=0, Bool_t title=kFALSE, Double_t time=0) const;
113 virtual void PrintSkipped(UInt_t n, const char *str);
114
115 // Task overwrite functions
116 virtual Bool_t ReInit(MParList *pList);
117
118 virtual Int_t CallPreProcess(MParList *plist);
119 virtual Int_t CallProcess();
120 virtual Int_t CallPostProcess();
121
122 void SavePrimitive(std::ostream &out, Option_t *o="");
123 void SavePrimitive(std::ofstream &out, Option_t *o="");
124
125 // TObject
126 void RecursiveRemove(TObject *obj);
127
128 ClassDef(MTask, 2) //Abstract base class for a task
129};
130
131#endif
Note: See TracBrowser for help on using the repository browser.