GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4AnalysisStepManager.cxx
Go to the documentation of this file.
1 // $Id: TGo4AnalysisStepManager.cxx 3063 2021-03-12 15:27:09Z linev $
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(0),
34  fxOutputEvent(0)
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=0;
52  fxStepIterator->Reset();
53  while((step= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
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=0;
69  fxStepIterator->Reset();
71  //std::cout <<"IIIIIIII InitEventClasses with checking: "<<IsStepChecking() << std::endl;
72  while((step= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
73  {
74  step->InitEventClasses();
75  // last enabled step:
76  // for step checking off, take last step in list
77  if(firststepfound)
78  {
79  if((IsStepChecking() && step->IsProcessEnabled())
80  || !IsStepChecking())
81  {
83  laststepfound=kTRUE;
84  }
85  }
86  // first enabled step is first step of chain:
87  // except for step checking is off, then take first
88  if(!firststepfound)
89  {
90  if((IsStepChecking() && step->IsProcessEnabled())
91  || !IsStepChecking())
92  {
94  firststepfound=kTRUE;
95  }
96  }
98  }
99  if(!laststepfound) fiLastStepIndex=fiFirstStepIndex; // for single step analysis
100 
101  if(IsStepChecking())
102  {
103  // Test for steps valid:
104  fxStepIterator->Reset();
106  while((step= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
107  {
108  //std::cout << "match testing of analysis step " << step->GetName() << std::endl;
109  if(! step->IsMatchingPrevious() )
110  {
111  rev=kFALSE;
112  TGo4Analysis::Instance()->Message(3,"!!! AnalysisStepManager -- ERROR: step %s is not matching previous !!!",
113  step->GetName() );
114  break;
115  }
116  else
117  {
118  rev=kTRUE;
119  }
120  } // while
121  }//if(IsStepChecking())
122 
123  TGo4Log::Debug("AnalysisStepManager -- Initializing EventClasses done.");
124  return rev;
125 }
126 
128 {
129  GO4TRACE((12,"TGo4AnalysisStepManager::SetFirstStep(const char*)",__LINE__, __FILE__));
130  //
131  Bool_t result=kFALSE;
132  if(name==0) {
133  // reset to defaults:
134  fiFirstStepIndex=0; // beginning of steplist
135  TGo4Analysis::Instance()->Message(0,"Analysis: Setting first step to beginning of steplist");
136  result=kTRUE;
137  } else {
138  TObject* obj=fxStepList->FindObject(name);
139  if(obj==0) {
140  result=kFALSE;
141  TGo4Analysis::Instance()->Message(3,"!!! Analysis: SetFirstStep ERROR - no such step %s",
142  name);
143  } else {
144  Int_t ix=fxStepList->IndexOf(obj);
145  if(ix <= fiLastStepIndex)
146  {
147  fiFirstStepIndex=ix;
148  TGo4Analysis::Instance()->Message(0,"Analysis: Setting first step to %s",
149  name);
150  }
151  else
152  {
154  TGo4Analysis::Instance()->Message(0,"Analysis: Range WARNING - Setting first step to last step");
155  }
156 
157  result=kTRUE;
158  }
159 
160  }
161  return result;
162 }
163 
164 Bool_t TGo4AnalysisStepManager::SetLastStep(const char* name)
165 {
166  GO4TRACE((12,"TGo4AnalysisStepManager::SetLastStep(const char*)",__LINE__, __FILE__));
167  //
168  Bool_t result=kTRUE;
169  if(name==0) {
170  // reset to defaults:
171  fiLastStepIndex=fxStepList->GetLast() ; // end of steplist
172  if(fiLastStepIndex<0)
173  fiLastStepIndex=0; // case of empty steplist
174  TGo4Analysis::Instance()->Message(0,"Analysis: Setting last step to end of steplist");
175 
176  result=kTRUE;
177  } else {
178  TObject* obj=fxStepList->FindObject(name);
179  if(obj==0) {
180  result=kFALSE;
181  TGo4Analysis::Instance()->Message(3,"!!! Analysis: SetLastStep ERROR - no such step %s",
182  name);
183 
184  } else {
185  Int_t ix=fxStepList->IndexOf(obj);
186  if(ix >= fiFirstStepIndex) {
187  fiLastStepIndex=ix;
188  TGo4Analysis::Instance()->Message(0,"Analysis: Setting last step to %s",
189  name);
190  } else {
192  TGo4Analysis::Instance()->Message(0," Analysis: Range WARNING - Setting last step to first step");
193 
194  }
195 
196  result=kTRUE;
197  }
198 
199 
200  }
201  return result;
202 }
203 
204 Bool_t TGo4AnalysisStepManager::SetStepStorage(const char* name, Bool_t on)
205 {
206 GO4TRACE((12,"TGo4AnalysisStepManager::SetStepStorage(const char*,Bool_t)",__LINE__, __FILE__));
207  Bool_t result=kFALSE;
208  TGo4AnalysisStep* step=GetAnalysisStep(name);
209  if(step)
210  {
211  step->SetStoreEnabled(on);
212  result=kTRUE;
213  }
214  else
215  {
216  result=kFALSE;
217  }
218 
219  return result;
220 
221 }
222 
224 {
225  GO4TRACE((12,"TGo4AnalysisStepManager::NewStepStore(const char *, TGo4EventStoreParameter*)",__LINE__, __FILE__));
226  Bool_t result=kFALSE;
227  TGo4AnalysisStep* step=0;
228  if(name==0) {
229  // zero name: use last step
230  step=dynamic_cast<TGo4AnalysisStep*> (fxStepList->At(fiLastStepIndex));
231  } else {
232  // step specified by name:
233  step=GetAnalysisStep(name);
234  }
235 
236  if(step) {
237  //step->SetEventStore(par); // remember parameter for next init
238  step->NewEventStore(par); // create new store now
239  result=kTRUE;
240  } else {
241  result=kFALSE;
242  }
243 
244  return result;
245 }
246 
248 {
249  GO4TRACE((12,"TGo4AnalysisStepManager::NewStepSource(const char *, TGo4EventSourceParameter *)",__LINE__, __FILE__));
250  Bool_t result=kFALSE;
251  TGo4AnalysisStep* step=0;
252  if(name==0) {
253  // zero name: use first step
254  step=dynamic_cast<TGo4AnalysisStep*> (fxStepList->At(fiFirstStepIndex));
255  //std::cout << "new step source: zero name"<< std::endl;
256  } else {
257  // step specified by name:
258  step=GetAnalysisStep(name);
259  //std::cout << "new step source: name="<< name << std::endl;
260  }
261 
262  if(step) {
263  //step->SetEventSource(par); // remember parameter for next init
264  step->NewEventSource(par); // delete old, and create the new source now
265  result=kTRUE;
266  //std::cout << "new step source: step found"<< std::endl;
267  } else {
268  result=kFALSE;
269  //std::cout << "new step source: step not found"<< std::endl;
270  }
271  return result;
272 }
273 
275 {
276  GO4TRACE((12,"TGo4AnalysisStepManager::NewStepProcessor(const char *, TGo4EventProcessorParameter *)",__LINE__, __FILE__));
277  Bool_t result=kFALSE;
278  TGo4AnalysisStep* step=GetAnalysisStep(name);
279  if(step) {
280  //step->SetEventProcessor(par); // remember parameter for next init
281  step->NewEventProcessor(par); // create processor now
282  result=kTRUE;
283  } else {
284  result=kFALSE;
285  }
286  return result;
287 }
288 
289 Int_t TGo4AnalysisStepManager::Store(const char * name, TGo4Parameter* par)
290 {
291  TGo4AnalysisStep* step=GetAnalysisStep(name);
292  return (step!=0) ? step->Store(par) : 1;
293 }
294 
295 Int_t TGo4AnalysisStepManager::Store(const char * name, TGo4Condition* con)
296 {
297  TGo4AnalysisStep* step=GetAnalysisStep(name);
298  return (step!=0) ? step->Store(con) : 1;
299 }
300 
301 Int_t TGo4AnalysisStepManager::Store(const char * name, TGo4Fitter* fit)
302 {
303  TGo4AnalysisStep* step=GetAnalysisStep(name);
304  return (step!=0) ? step->Store(fit) : 1;
305 }
306 
307 Int_t TGo4AnalysisStepManager::Store(const char * name, TFolder* folder)
308 {
309  TGo4AnalysisStep* step=GetAnalysisStep(name);
310  return (step!=0) ? step->Store(folder) : 1;
311 }
312 
314 {
315  GO4TRACE((11,"TGo4AnalysisStepManager::GetInputEvent(Int_t)",__LINE__, __FILE__));
316  TGo4EventElement* rev=0;
317  TGo4AnalysisStep* step=GetAnalysisStep(stepname);
318  if(step) {
320  if(pro) rev = pro->GetInputEvent(); // get true input event
321  } else {
322  rev=0;
323  }
324  return rev;
325 }
326 
328 {
329  GO4TRACE((11,"TGo4AnalysisStepManager::GetInputEvent(Int_t)",__LINE__, __FILE__));
330  TGo4EventElement* rev = 0;
331  TGo4AnalysisStep* step = dynamic_cast<TGo4AnalysisStep*> (fxStepList->At(stepindex) );
332  if(step) {
333  TGo4EventProcessor* pro = step->GetEventProcessor();
334  if(pro) rev = pro->GetInputEvent(); // get true input event
335  //rev=step->GetInputEvent();
336  } else {
337  rev=0;
338  }
339  return rev;
340 }
341 
343 {
344  GO4TRACE((11,"TGo4AnalysisStepManager::GetOutputEvent(const char*)",__LINE__, __FILE__));
345  TGo4EventElement* rev=0;
346  TGo4AnalysisStep* step=GetAnalysisStep(stepname);
347  if(step) {
348  rev = step->GetOutputEvent();
349  } else {
350  rev=0;
351  }
352  return rev;
353 }
354 
356 {
357  GO4TRACE((11,"TGo4AnalysisStepManager::GetOutputEvent(Int_t)",__LINE__, __FILE__));
358  TGo4EventElement* rev=0;
359  TGo4AnalysisStep* step=0;
360  step= dynamic_cast<TGo4AnalysisStep*> ( fxStepList->At(stepindex) );
361  if(step) {
362  rev=step->GetOutputEvent();
363  } else {
364  rev=0;
365  }
366  return rev;
367 }
368 
370 {
371  GO4TRACE((14,"TGo4AnalysisStepManager::AddAnalysisStep(TGo4AnalysisStep*)",__LINE__, __FILE__));
372  //
373  Bool_t rev=kFALSE;
374  if (next) {
375  if(fxStepList->FindObject(next)==0)
376  // is object already in list?
377  {
378  //no, add the new object
379  GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Adding new analysis step",__LINE__, __FILE__));
380  fxStepList->AddLast(next);
381  // set previous step:
382  Int_t ix=fxStepList->IndexOf(next);
383  if(ix>0)
384  {
385  TGo4AnalysisStep* previous= dynamic_cast<TGo4AnalysisStep*> ( fxStepList->At(ix-1) );
386  next->SetPreviousStep(previous);
387  }
388  else
389  {
390  next->SetPreviousStep(0);
391  }
392  fiLastStepIndex=ix;
393  rev=kTRUE;
394  TGo4Analysis::Instance()->Message(1,"Analysis: Added analysis step %s",
395  next->GetName());
396  }
397  else
398  {
399  // yes, do nothing
400  GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Analysis step was already there",__LINE__, __FILE__));
401  rev=kFALSE;
402  TGo4Analysis::Instance()->Message(2,"Analysis: WARNING - analysis step %s was already in steplist",
403  next->GetName() );
404  }
405  } // if(next)
406  else
407  {
408  GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Zero Analysis step pointer",__LINE__, __FILE__));
409  rev=kFALSE;
410  TGo4Analysis::Instance()->Message(2,"Analysis: WARNING - did not add zero analysis step pointer to steplist");
411  }
412  return rev;
413 }
414 
416 {
417  GO4TRACE((11,"TGo4AnalysisStepManager::GetAnalysisStep(const char *)",__LINE__, __FILE__));
418  TGo4AnalysisStep* step=0;
419  if(name==0)
420  step=dynamic_cast<TGo4AnalysisStep*>( fxStepList->At(fiFirstStepIndex));
421  else
422  step = dynamic_cast<TGo4AnalysisStep*>( fxStepList->FindObject(name) );
423  return step;
424 }
425 
427 {
428  return fxStepList ? fxStepList->GetLast() + 1 : 0;
429 }
430 
432 {
433  GO4TRACE((11,"TGo4AnalysisStepManager::GetAnalysisStepNum(Int_t)",__LINE__, __FILE__));
434  if ((number<0) || (number>fxStepList->GetLast())) return 0;
435  return dynamic_cast<TGo4AnalysisStep*>(fxStepList->At(number));
436 }
437 
438 
440 {
441  GO4TRACE((11,"TGo4AnalysisStepManager::ProcessAnalysisSteps()",__LINE__, __FILE__));
442  //
443  fxCurrentStep = 0;
444  fiCurrentStepIndex = 0;
445  Bool_t isfirststep = kTRUE;
446  // first evaluate actual beginning index for "keep input event" mode:
447  Int_t repeatinputstart=-1;
451  repeatinputstart=fiCurrentStepIndex;
452  break;
453  }
454  }
455 
456  SetOutputEvent(0); // make sure that first step wont take output of last one
459  if(fxCurrentStep==0) break;
460  if(IsStepChecking() && isfirststep ) {
461  // check first step source:
462  isfirststep = kFALSE;
465  else {
466  fxCurrentStep->SetStatusMessage("!!! No Event Source for first analysis step !!!");
468  }
469  }
470  if(fiCurrentStepIndex<repeatinputstart) continue; // skip steps before a step which is reprocessing same input event
471 
473 
474  if(fxCurrentStep->IsKeepOutputEvent()) break; // skip all steps after incomplete output event
475  } // for(...)
476  // finally, we update maintree header if the steps use treesource/store instances:
478  return 0;
479 }
480 
482 {
483  GO4TRACE((11,"TGo4AnalysisStepManager::UpdateStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
484  if(state!=0) {
488  fxCurrentStep=0;
489  fxStepIterator->Reset();
490  state->ClearStepStatus();
491  while((fxCurrentStep= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
492  {
494  state->AddStepStatus(stepstate);
495  } // while(fxCurrentStep..)
496  } // if(state!=0)
497 }
498 
500 {
501  GO4TRACE((11,"TGo4AnalysisStepManager::SetStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
502  if(state!=0) {
506  // note: the step indices are not used for
507  // initialization of analysis any more!
508  // update internal states of steps:
509  fxCurrentStep=0;
510  fxStepIterator->Reset();
511  while((fxCurrentStep= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
512  {
513  const char* name= fxCurrentStep->GetName();
514  TGo4AnalysisStepStatus* stepstate= state->GetStepStatus(name);
515  fxCurrentStep->SetStatus(stepstate);
516 
517  } // while(fxCurrentStep..)
518  } // if(state!=0)
519 }
520 
522 {
523  GO4TRACE((12,"TGo4AnalysisStepManager::AutoSave()",__LINE__, __FILE__));
524  //
525  //TGo4LockGuard autoguard(fxAutoSaveMutex);
526  TGo4Analysis::Instance()->Message(0,"Analysis Step Manager -- AutoSaving....");
527  TGo4AnalysisStep* step = 0;
528  fxStepIterator->Reset();
529  while((step= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0) {
530  step->StoreCalibration();
531  }
532 
533  // write maintree to file if existing...
534  if(TGo4MainTree::Exists()) {
536  }
537 }
538 
540 {
541  return kTRUE; // FIXME: workaround, to be removed later!!! JA
542 
543  // return (fxCurrentStep!=0) ? fxCurrentStep->IsErrorStopEnabled() : kTRUE;
544 }
Int_t Store(const char *name, TGo4Parameter *obj)
static TGo4MainTree * Instance()
void SetOutputEvent(TGo4EventElement *event)
Bool_t NewStepProcessor(const char *name, TGo4EventProcessorParameter *par)
Bool_t NewStepSource(const char *name, TGo4EventSourceParameter *par)
void UpdateStatus(TGo4AnalysisStatus *state)
void SetStatus(TGo4AnalysisStatus *state)
TGo4AnalysisStepManager(const char *name)
void SetPreviousStep(TGo4AnalysisStep *pre)
Int_t Store(TGo4Parameter *cali)
void NewEventStore(TGo4EventStoreParameter *kind)
TGo4EventElement * GetOutputEvent() const
void NewEventSource(TGo4EventSourceParameter *kind)
void SetStatus(TGo4AnalysisStepStatus *state)
Bool_t IsKeepOutputEvent()
static Bool_t Exists()
Definition: TGo4MainTree.h:64
void SetFirstStepIndex(Int_t i)
void SetSourceEnabled(Bool_t on=kTRUE)
Bool_t SetStepStorage(const char *name, Bool_t on)
Bool_t IsProcessEnabled() const
Bool_t IsSourceImplemented() const
void SetStatusMessage(const char *txt)
void SetStepChecking(Int_t on)
void Message(Int_t prio, const char *text,...)
Int_t IsStepChecking() const
TGo4AnalysisStepStatus * CreateStatus()
Bool_t AddStepStatus(TGo4AnalysisStepStatus *next)
Bool_t NewStepStore(const char *name, TGo4EventStoreParameter *par)
Int_t GetLastStepIndex() const
Bool_t AddAnalysisStep(TGo4AnalysisStep *next)
TGo4EventElement * GetInputEvent(const char *stepname)
TGo4AnalysisStepStatus * GetStepStatus(const char *name)
void SetStoreEnabled(Bool_t on=kTRUE)
TGo4EventElement * GetInputEvent()
virtual Int_t Write(const char *dummy=0, Int_t option=0, Int_t bufsize=0)
#define GO4TRACE(X)
Definition: TGo4Log.h:26
TGo4EventElement * GetOutputEvent()
virtual void InitEventClasses()
TGo4AnalysisStep * GetAnalysisStep(const char *name)
void SetLastStepIndex(Int_t i)
TGo4AnalysisStep * GetAnalysisStepNum(Int_t number)
void NewEventProcessor(TGo4EventProcessorParameter *kind)
static TGo4Analysis * Instance()
Bool_t SetFirstStep(const char *name)
TGo4EventProcessor * GetEventProcessor() const
Bool_t SetLastStep(const char *name)
Int_t GetFirstStepIndex() const
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:284