Project
Loading...
Searching...
No Matches
FairTask.cxx
Go to the documentation of this file.
1/********************************************************************************
2 * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3 * *
4 * This software is distributed under the terms of the *
5 * GNU Lesser General Public Licence (LGPL) version 3, *
6 * copied verbatim in the file "LICENSE" *
7 ********************************************************************************/
8// ----- FairTask source file -----
9// ----- Created 12/01/04 by M. Al-Turany / D. Bertini -----
10
11#include "FairTask.h"
12
13#include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN
14#include "FairMonitor.h" // for FairMonitor
15
16#include <TCollection.h> // for TIter
17#include <TList.h> // for TList
18#include <TObject.h> // for TObject
19#include <cstdio> // printf
20#include <utility> // pair
21
23 : TTask()
24 , fVerbose(0)
25 , fInputPersistance(-1)
26 , fLogger(FairLogger::GetLogger())
27 , fStreamProcessing(kFALSE)
28 , fOutputPersistance()
29{}
30
31FairTask::FairTask(const char* name, Int_t iVerbose)
32 : TTask(name, "FairTask")
33 , fVerbose(iVerbose)
34 , fInputPersistance(-1)
35 , fLogger(FairLogger::GetLogger())
36 , fOutputPersistance()
37{}
38
40
42{
44 if (!fActive) {
45 return;
46 }
47 InitStatus tStat = Init();
48 if (tStat == kFATAL) {
49 LOG(fatal) << "Initialization of Task " << fName.Data() << " failed fatally";
50 }
51 if (tStat == kERROR) {
52 fActive = kFALSE;
53 }
55 InitTasks();
56}
57
59{
60 if (!fActive) {
61 return;
62 }
63 InitStatus tStat = ReInit();
64 if (tStat == kFATAL) {
65 LOG(fatal) << "Reinitialization of Task " << fName.Data() << " failed fatally";
66 }
67 if (tStat == kERROR) {
68 fActive = kFALSE;
69 }
71}
72
74{
75 if (!fActive) {
76 return;
77 }
80}
81
83{
84 if (!fActive) {
85 return;
86 }
88}
89
91{
92 if (!fActive) {
93 return;
94 }
95 Finish();
97}
98
99void FairTask::SetVerbose(Int_t iVerbose)
100{
101 fVerbose = iVerbose;
102 TIter next(GetListOfTasks());
103 FairTask* task;
104 while ((task = dynamic_cast<FairTask*>(next()))) {
105 task->SetVerbose(iVerbose);
106 }
107}
108
110{
111 TIter next(GetListOfTasks());
112 FairTask* task;
113 while ((task = dynamic_cast<FairTask*>(next()))) {
114 task->InitTask();
115 }
116}
117
118void FairTask::ExecuteTask(Option_t* option)
119{
120 // Execute main task and its subtasks.
121 // When calling this function, the Exec function of the corresponding class
122 // is invoked, then the list of its subtasks is executed calling recursively
123 // all the subtasks, etc.
124 //
125 // The option parameter may be used to select different execution steps
126 // within a task. This parameter is passed also to all the subtasks.
127
128 if (fgBeginTask) {
129 Error("ExecuteTask", "Cannot execute task:%s, already running task: %s", GetName(), fgBeginTask->GetName());
130 return;
131 }
132 if (!IsActive())
133 return;
134
135 fOption = option;
136 fgBeginTask = this;
137 fgBreakPoint = 0;
138
139 if (fBreakin)
140 return;
141 if (gDebug > 1) {
142 LOG(info) << "Execute task:" << GetName() << " : " << GetTitle();
143 }
145 Exec(option);
147
148 fHasExecuted = kTRUE;
149 ExecuteTasks(option);
150
151 if (fBreakout)
152 return;
153
154 if (!fgBreakPoint) {
155 fgBeginTask->CleanTasks();
156 fgBeginTask = 0;
157 }
158}
159
160void FairTask::ExecuteTasks(Option_t* option)
161{
162 // Execute all the subtasks of a task.
163
164 TIter next(fTasks);
165 FairTask* task;
166 while ((task = static_cast<FairTask*>(next()))) {
167 if (fgBreakPoint)
168 return;
169 if (!task->IsActive())
170 continue;
171 if (task->fHasExecuted) {
172 task->ExecuteTasks(option);
173 continue;
174 }
175 if (task->fBreakin == 1) {
176 printf("Break at entry of task: %s\n", task->GetName());
177 fgBreakPoint = this;
178 task->fBreakin++;
179 return;
180 }
181
182 if (gDebug > 1) {
183 LOG(info) << "Execute task:" << task->GetName() << " : " << task->GetTitle();
184 }
186 task->Exec(option);
188
189 task->fHasExecuted = kTRUE;
190 task->ExecuteTasks(option);
191 if (task->fBreakout == 1) {
192 printf("Break at exit of task: %s\n", task->GetName());
193 fgBreakPoint = this;
194 task->fBreakout++;
195 return;
196 }
197 }
198}
199
201{
202 TIter next(GetListOfTasks());
203 FairTask* task;
204 while ((task = dynamic_cast<FairTask*>(next()))) {
205 task->ReInitTask();
206 }
207}
208
210{
211 TIter next(GetListOfTasks());
212 FairTask* task;
213 while ((task = dynamic_cast<FairTask*>(next()))) {
214 task->SetParTask();
215 }
216}
217
219{
220 TIter next(GetListOfTasks());
221 FairTask* task;
222 while ((task = dynamic_cast<FairTask*>(next()))) {
223 task->FinishTask();
224 }
225}
226
228{
229 TIter next(GetListOfTasks());
230 FairTask* task;
231 while ((task = dynamic_cast<FairTask*>(next()))) {
232 task->FinishEvent();
233 }
234}
235
236void FairTask::SetOutputBranchPersistent(TString branchName, Bool_t persistence)
237{
238 fOutputPersistance.insert(std::pair<TString, Bool_t>(branchName, persistence));
239}
240
241Bool_t FairTask::IsOutputBranchPersistent(TString branchName)
242{
243 std::map<TString, Bool_t>::iterator it = fOutputPersistance.find(branchName);
244 if (it != fOutputPersistance.end()) {
245 return it->second;
246 } else {
247 return kTRUE;
248 }
249}
250
ClassImp(FairTask)
InitStatus
Definition FairTask.h:34
@ kFATAL
Definition FairTask.h:37
@ kERROR
Definition FairTask.h:36
void StartMonitoring(const TTask *tTask, const char *identStr)
Definition FairMonitor.h:42
void StopMonitoring(const TTask *tTask, const char *identStr)
Definition FairMonitor.h:47
static FairMonitor * GetMonitor()
void SetCurrentTask(TTask *tTask)
Definition FairMonitor.h:64
void FinishTasks()
Definition FairTask.cxx:218
void SetOutputBranchPersistent(TString, Bool_t)
Definition FairTask.cxx:236
void SetParTasks()
Definition FairTask.cxx:209
virtual void Finish()
Definition FairTask.h:123
virtual void ExecuteTasks(Option_t *option)
Definition FairTask.cxx:160
virtual InitStatus ReInit()
Definition FairTask.h:113
void SetVerbose(Int_t iVerbose)
Definition FairTask.cxx:99
void InitTasks()
Definition FairTask.cxx:109
virtual void ExecuteTask(Option_t *option="0")
Definition FairTask.cxx:118
void FinishEvents()
Definition FairTask.cxx:227
virtual void FinishTask()
Definition FairTask.cxx:90
virtual InitStatus Init()
Definition FairTask.h:108
void SetParTask()
Definition FairTask.cxx:73
void ReInitTasks()
Definition FairTask.cxx:200
void InitTask()
Definition FairTask.cxx:41
Int_t fVerbose
Definition FairTask.h:100
Bool_t IsOutputBranchPersistent(TString)
Definition FairTask.cxx:241
virtual void SetParContainers()
Definition FairTask.h:118
void ReInitTask()
Definition FairTask.cxx:58
virtual ~FairTask()
Definition FairTask.cxx:39
virtual void FinishEvent()
Definition FairTask.cxx:82
GLuint const GLchar * name
Definition glcorearb.h:781
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"