GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4AnalysisStepManager.cxx
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
15 
16 #include "TObjArray.h"
17 
18 #include "TGo4Log.h"
19 #include "TGo4MainTree.h"
20 #include "TGo4AnalysisStep.h"
21 
23 #include "TGo4AnalysisStatus.h"
24 #include "TGo4AnalysisImp.h"
25 #include "TGo4EventProcessor.h"
26 
28  TNamed(name,"The Go4 Analysis Step Manager"),
29  fiFirstStepIndex(0),
30  fiLastStepIndex(0),
31  fiCurrentStepIndex(0),
32  fbStepCheckingMode(kTRUE),
33  fxCurrentStep(nullptr),
34  fxOutputEvent(nullptr)
35 {
36  fxStepList = new TObjArray;
37  fxStepIterator = fxStepList->MakeIterator();
38 }
39 
41 {
42  delete fxStepIterator;
43  delete fxStepList;
44 }
45 
47 {
48  GO4TRACE((14,"TGo4AnalysisStepManager::CloseAnalysis()",__LINE__, __FILE__));
49  //
50  TGo4Log::Debug("Analysis Step Manager -- closing analysis steps...");
51  TGo4AnalysisStep *step = nullptr;
52  fxStepIterator->Reset();
53  while((step= dynamic_cast<TGo4AnalysisStep *>( fxStepIterator->Next() ) ) != nullptr)
54  {
55  step->Close();
56  }
57  TGo4Log::Debug("Analysis Step Manager -- analysis steps were closed.");
58 }
59 
61 {
62  GO4TRACE((14,"TGo4AnalysisStepManager::InitEventClasses()",__LINE__, __FILE__));
63  //
64  Bool_t rev = kTRUE;
65  Bool_t firststepfound = kFALSE;
66  Bool_t laststepfound = kFALSE;
67  TGo4Log::Debug("Analysis StepManager -- Initializing EventClasses...");
68  TGo4AnalysisStep *step = nullptr;
69  fxStepIterator->Reset();
71  while((step = dynamic_cast<TGo4AnalysisStep *>(fxStepIterator->Next())) != nullptr)
72  {
73  step->InitEventClasses();
74  // last enabled step:
75  // for step checking off, take last step in list
76  if(firststepfound)
77  {
78  if((IsStepChecking() && step->IsProcessEnabled())
79  || !IsStepChecking())
80  {
82  laststepfound=kTRUE;
83  }
84  }
85  // first enabled step is first step of chain:
86  // except for step checking is off, then take first
87  if(!firststepfound)
88  {
89  if((IsStepChecking() && step->IsProcessEnabled())
90  || !IsStepChecking())
91  {
93  firststepfound=kTRUE;
94  }
95  }
97  }
98  if(!laststepfound) fiLastStepIndex=fiFirstStepIndex; // for single step analysis
99 
100  if(IsStepChecking())
101  {
102  // Test for steps valid:
103  fxStepIterator->Reset();
104  fiCurrentStepIndex = 0;
105  while((step = dynamic_cast<TGo4AnalysisStep *>(fxStepIterator->Next())) != nullptr)
106  {
107  if(! step->IsMatchingPrevious() )
108  {
109  rev = kFALSE;
110  TGo4Analysis::Instance()->Message(3,"!!! AnalysisStepManager -- ERROR: step %s is not matching previous !!!",
111  step->GetName() );
112  break;
113  }
114  else
115  {
116  rev = kTRUE;
117  }
118  } // while
119  }//if(IsStepChecking())
120 
121  TGo4Log::Debug("AnalysisStepManager -- Initializing EventClasses done.");
122  return rev;
123 }
124 
126 {
127  GO4TRACE((12,"TGo4AnalysisStepManager::SetFirstStep(const char *)",__LINE__, __FILE__));
128  //
129  Bool_t result = kFALSE;
130  if (!name) {
131  // reset to defaults:
132  fiFirstStepIndex = 0; // beginning of steplist
133  TGo4Analysis::Instance()->Message(0, "Analysis: Setting first step to beginning of steplist");
134  result = kTRUE;
135  } else {
136  TObject *obj = fxStepList->FindObject(name);
137  if (!obj) {
138  result = kFALSE;
139  TGo4Analysis::Instance()->Message(3, "!!! Analysis: SetFirstStep ERROR - no such step %s", name);
140  } else {
141  Int_t ix = fxStepList->IndexOf(obj);
142  if (ix <= fiLastStepIndex) {
143  fiFirstStepIndex = ix;
144  TGo4Analysis::Instance()->Message(0, "Analysis: Setting first step to %s", name);
145  } else {
147  TGo4Analysis::Instance()->Message(0, "Analysis: Range WARNING - Setting first step to last step");
148  }
149 
150  result = kTRUE;
151  }
152  }
153  return result;
154 }
155 
156 Bool_t TGo4AnalysisStepManager::SetLastStep(const char *name)
157 {
158  GO4TRACE((12,"TGo4AnalysisStepManager::SetLastStep(const char *)",__LINE__, __FILE__));
159  //
160  Bool_t result=kTRUE;
161  if(!name) {
162  // reset to defaults:
163  fiLastStepIndex = fxStepList->GetLast(); // end of steplist
164  if(fiLastStepIndex < 0)
165  fiLastStepIndex = 0; // case of empty steplist
166  TGo4Analysis::Instance()->Message(0,"Analysis: Setting last step to end of steplist");
167 
168  result = kTRUE;
169  } else {
170  TObject *obj = fxStepList->FindObject(name);
171  if(!obj) {
172  result=kFALSE;
173  TGo4Analysis::Instance()->Message(3,"!!! Analysis: SetLastStep ERROR - no such step %s",
174  name);
175 
176  } else {
177  Int_t ix=fxStepList->IndexOf(obj);
178  if(ix >= fiFirstStepIndex) {
179  fiLastStepIndex=ix;
180  TGo4Analysis::Instance()->Message(0,"Analysis: Setting last step to %s",
181  name);
182  } else {
184  TGo4Analysis::Instance()->Message(0," Analysis: Range WARNING - Setting last step to first step");
185 
186  }
187 
188  result=kTRUE;
189  }
190 
191 
192  }
193  return result;
194 }
195 
196 Bool_t TGo4AnalysisStepManager::SetStepStorage(const char *name, Bool_t on)
197 {
198  GO4TRACE((12,"TGo4AnalysisStepManager::SetStepStorage(const char *, Bool_t)",__LINE__, __FILE__));
199  Bool_t result = kFALSE;
200  TGo4AnalysisStep *step = GetAnalysisStep(name);
201  if (step) {
202  step->SetStoreEnabled(on);
203  result = kTRUE;
204  } else {
205  result = kFALSE;
206  }
207 
208  return result;
209 }
210 
212 {
213  GO4TRACE((12,"TGo4AnalysisStepManager::NewStepStore(const char *, TGo4EventStoreParameter *)",__LINE__, __FILE__));
214  Bool_t result=kFALSE;
215  TGo4AnalysisStep *step = nullptr;
216 
217  if(!name) {
218  // zero name: use last step
219  step = dynamic_cast<TGo4AnalysisStep *> (fxStepList->At(fiLastStepIndex));
220  } else {
221  // step specified by name:
222  step=GetAnalysisStep(name);
223  }
224 
225  if(step) {
226  //step->SetEventStore(par); // remember parameter for next init
227  step->NewEventStore(par); // create new store now
228  result=kTRUE;
229  } else {
230  result=kFALSE;
231  }
232 
233  return result;
234 }
235 
237 {
238  GO4TRACE((12,"TGo4AnalysisStepManager::NewStepSource(const char *, TGo4EventSourceParameter *)",__LINE__, __FILE__));
239  Bool_t result=kFALSE;
240  TGo4AnalysisStep *step = nullptr;
241  if(!name) {
242  // zero name: use first step
243  step = dynamic_cast<TGo4AnalysisStep *> (fxStepList->At(fiFirstStepIndex));
244  } else {
245  // step specified by name:
246  step = GetAnalysisStep(name);
247  }
248 
249  if(step) {
250  //step->SetEventSource(par); // remember parameter for next init
251  step->NewEventSource(par); // delete old, and create the new source now
252  result = kTRUE;
253  } else {
254  result = kFALSE;
255  }
256  return result;
257 }
258 
260 {
261  GO4TRACE((12,"TGo4AnalysisStepManager::NewStepProcessor(const char *, TGo4EventProcessorParameter *)",__LINE__, __FILE__));
262  Bool_t result = kFALSE;
263  TGo4AnalysisStep *step = GetAnalysisStep(name);
264  if(step) {
265  //step->SetEventProcessor(par); // remember parameter for next init
266  step->NewEventProcessor(par); // create processor now
267  result=kTRUE;
268  } else {
269  result=kFALSE;
270  }
271  return result;
272 }
273 
274 Int_t TGo4AnalysisStepManager::Store(const char *name, TGo4Parameter *par)
275 {
276  TGo4AnalysisStep *step=GetAnalysisStep(name);
277  return step ? step->Store(par) : 1;
278 }
279 
280 Int_t TGo4AnalysisStepManager::Store(const char *name, TGo4Condition *con)
281 {
282  TGo4AnalysisStep *step=GetAnalysisStep(name);
283  return step ? step->Store(con) : 1;
284 }
285 
286 Int_t TGo4AnalysisStepManager::Store(const char *name, TGo4Fitter *fit)
287 {
288  TGo4AnalysisStep *step=GetAnalysisStep(name);
289  return step ? step->Store(fit) : 1;
290 }
291 
292 Int_t TGo4AnalysisStepManager::Store(const char *name, TFolder *folder)
293 {
294  TGo4AnalysisStep *step = GetAnalysisStep(name);
295  return step ? step->Store(folder) : 1;
296 }
297 
299 {
300  GO4TRACE((11,"TGo4AnalysisStepManager::GetInputEvent(Int_t)",__LINE__, __FILE__));
301  TGo4EventElement *rev = nullptr;
302  TGo4AnalysisStep *step = GetAnalysisStep(stepname);
303  if(step) {
304  TGo4EventProcessor *pro = step->GetEventProcessor();
305  if(pro) rev = pro->GetInputEvent(); // get true input event
306  } else {
307  rev = nullptr;
308  }
309  return rev;
310 }
311 
313 {
314  GO4TRACE((11,"TGo4AnalysisStepManager::GetInputEvent(Int_t)",__LINE__, __FILE__));
315  TGo4EventElement *rev = nullptr;
316  TGo4AnalysisStep *step = dynamic_cast<TGo4AnalysisStep *> (fxStepList->At(stepindex));
317  if(step) {
318  TGo4EventProcessor *pro = step->GetEventProcessor();
319  if(pro) rev = pro->GetInputEvent(); // get true input event
320  //rev=step->GetInputEvent();
321  } else {
322  rev = nullptr;
323  }
324  return rev;
325 }
326 
328 {
329  GO4TRACE((11,"TGo4AnalysisStepManager::GetOutputEvent(const char *)",__LINE__, __FILE__));
330  TGo4EventElement *rev = nullptr;
331  TGo4AnalysisStep *step=GetAnalysisStep(stepname);
332  if(step) {
333  rev = step->GetOutputEvent();
334  } else {
335  rev = nullptr;
336  }
337  return rev;
338 }
339 
341 {
342  GO4TRACE((11,"TGo4AnalysisStepManager::GetOutputEvent(Int_t)",__LINE__, __FILE__));
343  TGo4EventElement *rev = nullptr;
344  TGo4AnalysisStep *step = nullptr;
345  step= dynamic_cast<TGo4AnalysisStep *> ( fxStepList->At(stepindex) );
346  if(step) {
347  rev=step->GetOutputEvent();
348  } else {
349  rev = nullptr;
350  }
351  return rev;
352 }
353 
355 {
356  GO4TRACE((14,"TGo4AnalysisStepManager::AddAnalysisStep(TGo4AnalysisStep *)",__LINE__, __FILE__));
357  //
358  Bool_t rev = kFALSE;
359  if (next) {
360  if(!fxStepList->FindObject(next))
361  // is object already in list?
362  {
363  //no, add the new object
364  GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Adding new analysis step",__LINE__, __FILE__));
365  fxStepList->AddLast(next);
366  // set previous step:
367  Int_t ix=fxStepList->IndexOf(next);
368  if(ix>0)
369  {
370  TGo4AnalysisStep *previous= dynamic_cast<TGo4AnalysisStep *> ( fxStepList->At(ix-1) );
371  next->SetPreviousStep(previous);
372  }
373  else
374  {
375  next->SetPreviousStep(nullptr);
376  }
377  fiLastStepIndex = ix;
378  rev = kTRUE;
379  TGo4Analysis::Instance()->Message(1,"Analysis: Added analysis step %s",
380  next->GetName());
381  }
382  else
383  {
384  // yes, do nothing
385  GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Analysis step was already there",__LINE__, __FILE__));
386  rev=kFALSE;
387  TGo4Analysis::Instance()->Message(2,"Analysis: WARNING - analysis step %s was already in steplist",
388  next->GetName() );
389  }
390  } // if(next)
391  else
392  {
393  GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Zero Analysis step pointer",__LINE__, __FILE__));
394  rev=kFALSE;
395  TGo4Analysis::Instance()->Message(2,"Analysis: WARNING - did not add zero analysis step pointer to steplist");
396  }
397  return rev;
398 }
399 
401 {
402  GO4TRACE((11,"TGo4AnalysisStepManager::GetAnalysisStep(const char *)",__LINE__, __FILE__));
403  TGo4AnalysisStep *step = nullptr;
404  if(!name)
405  step = dynamic_cast<TGo4AnalysisStep *>(fxStepList->At(fiFirstStepIndex));
406  else
407  step = dynamic_cast<TGo4AnalysisStep *>(fxStepList->FindObject(name));
408  return step;
409 }
410 
412 {
413  return fxStepList ? fxStepList->GetLast() + 1 : 0;
414 }
415 
417 {
418  GO4TRACE((11,"TGo4AnalysisStepManager::GetAnalysisStepNum(Int_t)",__LINE__, __FILE__));
419  if ((number < 0) || (number > fxStepList->GetLast())) return nullptr;
420  return dynamic_cast<TGo4AnalysisStep *>(fxStepList->At(number));
421 }
422 
423 
425 {
426  GO4TRACE((11,"TGo4AnalysisStepManager::ProcessAnalysisSteps()",__LINE__, __FILE__));
427  //
428  fxCurrentStep = nullptr;
429  fiCurrentStepIndex = 0;
430  Bool_t isfirststep = kTRUE;
431  // first evaluate actual beginning index for "keep input event" mode:
432  Int_t repeatinputstart=-1;
436  repeatinputstart = fiCurrentStepIndex;
437  break;
438  }
439  }
440 
441  SetOutputEvent(nullptr); // make sure that first step wont take output of last one
444  if(!fxCurrentStep) break;
445  if(IsStepChecking() && isfirststep ) {
446  // check first step source:
447  isfirststep = kFALSE;
450  else {
451  fxCurrentStep->SetStatusMessage("!!! No Event Source for first analysis step !!!");
453  }
454  }
455  if(fiCurrentStepIndex<repeatinputstart) continue; // skip steps before a step which is reprocessing same input event
456 
458 
459  if(fxCurrentStep->IsKeepOutputEvent()) break; // skip all steps after incomplete output event
460  } // for(...)
461  // finally, we update maintree header if the steps use treesource/store instances:
463  return 0;
464 }
465 
467 {
468  GO4TRACE((11,"TGo4AnalysisStepManager::UpdateStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
469  if(state) {
473  fxCurrentStep = nullptr;
474  fxStepIterator->Reset();
475  state->ClearStepStatus();
476  while((fxCurrentStep = dynamic_cast<TGo4AnalysisStep *>(fxStepIterator->Next())) != nullptr) {
478  state->AddStepStatus(stepstate);
479  }
480  }
481 }
482 
484 {
485  GO4TRACE((11,"TGo4AnalysisStepManager::SetStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
486  if(state) {
490  // note: the step indices are not used for
491  // initialization of analysis any more!
492  // update internal states of steps:
493  fxCurrentStep = nullptr;
494  fxStepIterator->Reset();
495  while((fxCurrentStep = dynamic_cast<TGo4AnalysisStep *>(fxStepIterator->Next())) != nullptr) {
496  const char *name = fxCurrentStep->GetName();
497  TGo4AnalysisStepStatus *stepstate = state->GetStepStatus(name);
498  fxCurrentStep->SetStatus(stepstate);
499  }
500  }
501 }
502 
504 {
505  GO4TRACE((12,"TGo4AnalysisStepManager::AutoSave()",__LINE__, __FILE__));
506  //
507  //TGo4LockGuard autoguard(fxAutoSaveMutex);
508  TGo4Analysis::Instance()->Message(0,"Analysis Step Manager -- AutoSaving....");
509  TGo4AnalysisStep *step = nullptr;
510  fxStepIterator->Reset();
511  while((step = dynamic_cast<TGo4AnalysisStep *>(fxStepIterator->Next())) != nullptr) {
512  step->StoreCalibration();
513  }
514 
515  // write maintree to file if existing...
516  if(TGo4MainTree::Exists()) {
518  }
519 }
520 
522 {
523  return kTRUE; // FIXME: workaround, to be removed later!!! JA
524 
525  // return fxCurrentStep ? fxCurrentStep->IsErrorStopEnabled() : kTRUE;
526 }
Int_t Store(const char *name, TGo4Parameter *obj)
static TGo4MainTree * Instance()
void SetOutputEvent(TGo4EventElement *event)
Bool_t NewStepProcessor(const char *name, TGo4EventProcessorParameter *par)
Int_t GetFirstStepIndex() const
Bool_t NewStepSource(const char *name, TGo4EventSourceParameter *par)
void UpdateStatus(TGo4AnalysisStatus *state)
void SetStatus(TGo4AnalysisStatus *state)
TGo4AnalysisStepManager(const char *name)
void SetPreviousStep(TGo4AnalysisStep *pre)
Bool_t IsSourceImplemented() const
Int_t Store(TGo4Parameter *cali)
void NewEventStore(TGo4EventStoreParameter *kind)
void NewEventSource(TGo4EventSourceParameter *kind)
void SetStatus(TGo4AnalysisStepStatus *state)
TGo4EventElement * GetOutputEvent() const
TGo4AnalysisStep * GetAnalysisStep(const char *name) const
Int_t IsStepChecking() const
TGo4EventElement * GetOutputEvent() const
static Bool_t Exists()
Definition: TGo4MainTree.h:64
Int_t Write(const char *dummy=nullptr, Int_t option=0, Int_t bufsize=0) override
Bool_t IsKeepInputEvent() const
void SetFirstStepIndex(Int_t i)
Bool_t IsProcessEnabled() const
void SetSourceEnabled(Bool_t on=kTRUE)
Bool_t SetStepStorage(const char *name, Bool_t on)
static void Debug(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:281
TGo4AnalysisStep * GetAnalysisStepNum(Int_t number) const
void SetStatusMessage(const char *txt)
void SetStepChecking(Int_t on)
void Message(Int_t prio, const char *text,...)
TGo4AnalysisStepStatus * CreateStatus()
Bool_t AddStepStatus(TGo4AnalysisStepStatus *next)
Bool_t NewStepStore(const char *name, TGo4EventStoreParameter *par)
Bool_t AddAnalysisStep(TGo4AnalysisStep *next)
Bool_t IsMatchingPrevious() const
TGo4AnalysisStepStatus * GetStepStatus(const char *name)
Bool_t IsKeepOutputEvent() const
void SetStoreEnabled(Bool_t on=kTRUE)
TGo4EventElement * GetInputEvent()
TGo4EventProcessor * GetEventProcessor() const
#define GO4TRACE(X)
Definition: TGo4Log.h:25
Int_t GetLastStepIndex() const
virtual void InitEventClasses()
void SetLastStepIndex(Int_t i)
void NewEventProcessor(TGo4EventProcessorParameter *kind)
static TGo4Analysis * Instance()
TGo4EventElement * GetInputEvent(const char *stepname) const
Bool_t SetFirstStep(const char *name)
Bool_t SetLastStep(const char *name)