GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4AnalysisStepManager.cxx
Go to the documentation of this file.
1 // $Id: TGo4AnalysisStepManager.cxx 2130 2018-08-14 10:13:11Z 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 f�r 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 #include "TFolder.h"
18 #include "TList.h"
19 #include "TThread.h"
20 #include "TH1.h"
21 #include "TTree.h"
22 
23 #include "TGo4Log.h"
24 #include "TGo4LockGuard.h"
25 #include "TGo4Condition.h"
26 #include "TGo4MainTree.h"
27 #include "TGo4AnalysisStep.h"
28 #include "TGo4TreeStructure.h"
29 
31 #include "TGo4AnalysisStatus.h"
32 #include "TGo4AnalysisImp.h"
34 #include "TGo4EventProcessor.h"
36 #include "TGo4BackStore.h"
37 
39  TNamed(name,"The Go4 Analysis Step Manager"),
40  fiFirstStepIndex(0),
41  fiLastStepIndex(0),
42  fiCurrentStepIndex(0),
43  fbStepCheckingMode(kTRUE),
44  fxCurrentStep(0),
45  fxOutputEvent(0)
46 {
47  fxStepList = new TObjArray;
48  fxStepIterator = fxStepList->MakeIterator();
49 }
50 
52 {
53  delete fxStepIterator;
54  delete fxStepList;
55 }
56 
58 {
59  GO4TRACE((14,"TGo4AnalysisStepManager::CloseAnalysis()",__LINE__, __FILE__));
60  //
61  TGo4Log::Debug("Analysis Step Manager -- closing analysis steps...");
62  TGo4AnalysisStep* step=0;
63  fxStepIterator->Reset();
64  while((step= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
65  {
66  step->Close();
67  }
68  TGo4Log::Debug("Analysis Step Manager -- analysis steps were closed.");
69 }
70 
72 {
73  GO4TRACE((14,"TGo4AnalysisStepManager::InitEventClasses()",__LINE__, __FILE__));
74  //
75  Bool_t rev=kTRUE;
76  Bool_t firststepfound=kFALSE;
77  Bool_t laststepfound=kFALSE;
78  TGo4Log::Debug("Analysis StepManager -- Initializing EventClasses...");
79  TGo4AnalysisStep* step=0;
80  fxStepIterator->Reset();
82  //std::cout <<"IIIIIIII InitEventClasses with checking: "<<IsStepChecking() << std::endl;
83  while((step= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
84  {
85  step->InitEventClasses();
86  // last enabled step:
87  // for step checking off, take last step in list
88  if(firststepfound)
89  {
90  if((IsStepChecking() && step->IsProcessEnabled())
91  || !IsStepChecking())
92  {
94  laststepfound=kTRUE;
95  }
96  }
97  // first enabled step is first step of chain:
98  // except for step checking is off, then take first
99  if(!firststepfound)
100  {
101  if((IsStepChecking() && step->IsProcessEnabled())
102  || !IsStepChecking())
103  {
105  firststepfound=kTRUE;
106  }
107  }
109  }
110  if(!laststepfound) fiLastStepIndex=fiFirstStepIndex; // for single step analysis
111 
112  if(IsStepChecking())
113  {
114  // Test for steps valid:
115  fxStepIterator->Reset();
117  while((step= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
118  {
119  //std::cout << "match testing of analysis step " << step->GetName() << std::endl;
120  if(! step->IsMatchingPrevious() )
121  {
122  rev=kFALSE;
123  TGo4Analysis::Instance()->Message(3,"!!! AnalysisStepManager -- ERROR: step %s is not matching previous !!!",
124  step->GetName() );
125  break;
126  }
127  else
128  {
129  rev=kTRUE;
130  }
131  } // while
132  }//if(IsStepChecking())
133 
134  TGo4Log::Debug("AnalysisStepManager -- Initializing EventClasses done.");
135  return rev;
136 }
137 
139 {
140  GO4TRACE((12,"TGo4AnalysisStepManager::SetFirstStep(const char*)",__LINE__, __FILE__));
141  //
142  Bool_t result=kFALSE;
143  if(name==0) {
144  // reset to defaults:
145  fiFirstStepIndex=0; // beginning of steplist
146  TGo4Analysis::Instance()->Message(0,"Analysis: Setting first step to beginning of steplist");
147  result=kTRUE;
148  } else {
149  TObject* obj=fxStepList->FindObject(name);
150  if(obj==0) {
151  result=kFALSE;
152  TGo4Analysis::Instance()->Message(3,"!!! Analysis: SetFirstStep ERROR - no such step %s",
153  name);
154  } else {
155  Int_t ix=fxStepList->IndexOf(obj);
156  if(ix <= fiLastStepIndex)
157  {
158  fiFirstStepIndex=ix;
159  TGo4Analysis::Instance()->Message(0,"Analysis: Setting first step to %s",
160  name);
161  }
162  else
163  {
165  TGo4Analysis::Instance()->Message(0,"Analysis: Range WARNING - Setting first step to last step");
166  }
167 
168  result=kTRUE;
169  }
170 
171  }
172  return result;
173 }
174 
175 Bool_t TGo4AnalysisStepManager::SetLastStep(const char* name)
176 {
177  GO4TRACE((12,"TGo4AnalysisStepManager::SetLastStep(const char*)",__LINE__, __FILE__));
178  //
179  Bool_t result=kTRUE;
180  if(name==0) {
181  // reset to defaults:
182  fiLastStepIndex=fxStepList->GetLast() ; // end of steplist
183  if(fiLastStepIndex<0)
184  fiLastStepIndex=0; // case of empty steplist
185  TGo4Analysis::Instance()->Message(0,"Analysis: Setting last step to end of steplist");
186 
187  result=kTRUE;
188  } else {
189  TObject* obj=fxStepList->FindObject(name);
190  if(obj==0) {
191  result=kFALSE;
192  TGo4Analysis::Instance()->Message(3,"!!! Analysis: SetLastStep ERROR - no such step %s",
193  name);
194 
195  } else {
196  Int_t ix=fxStepList->IndexOf(obj);
197  if(ix >= fiFirstStepIndex) {
198  fiLastStepIndex=ix;
199  TGo4Analysis::Instance()->Message(0,"Analysis: Setting last step to %s",
200  name);
201  } else {
203  TGo4Analysis::Instance()->Message(0," Analysis: Range WARNING - Setting last step to first step");
204 
205  }
206 
207  result=kTRUE;
208  }
209 
210 
211  }
212  return result;
213 }
214 
215 Bool_t TGo4AnalysisStepManager::SetStepStorage(const char* name, Bool_t on)
216 {
217 GO4TRACE((12,"TGo4AnalysisStepManager::SetStepStorage(const char*,Bool_t)",__LINE__, __FILE__));
218  Bool_t result=kFALSE;
219  TGo4AnalysisStep* step=GetAnalysisStep(name);
220  if(step)
221  {
222  step->SetStoreEnabled(on);
223  result=kTRUE;
224  }
225  else
226  {
227  result=kFALSE;
228  }
229 
230  return result;
231 
232 }
233 
235 {
236  GO4TRACE((12,"TGo4AnalysisStepManager::NewStepStore(const char *, TGo4EventStoreParameter*)",__LINE__, __FILE__));
237  Bool_t result=kFALSE;
238  TGo4AnalysisStep* step=0;
239  if(name==0) {
240  // zero name: use last step
241  step=dynamic_cast<TGo4AnalysisStep*> (fxStepList->At(fiLastStepIndex));
242  } else {
243  // step specified by name:
244  step=GetAnalysisStep(name);
245  }
246 
247  if(step) {
248  //step->SetEventStore(par); // remember parameter for next init
249  step->NewEventStore(par); // create new store now
250  result=kTRUE;
251  } else {
252  result=kFALSE;
253  }
254 
255  return result;
256 }
257 
259 {
260  GO4TRACE((12,"TGo4AnalysisStepManager::NewStepSource(const char *, TGo4EventSourceParameter *)",__LINE__, __FILE__));
261  Bool_t result=kFALSE;
262  TGo4AnalysisStep* step=0;
263  if(name==0) {
264  // zero name: use first step
265  step=dynamic_cast<TGo4AnalysisStep*> (fxStepList->At(fiFirstStepIndex));
266  //std::cout << "new step source: zero name"<< std::endl;
267  } else {
268  // step specified by name:
269  step=GetAnalysisStep(name);
270  //std::cout << "new step source: name="<< name << std::endl;
271  }
272 
273  if(step) {
274  //step->SetEventSource(par); // remember parameter for next init
275  step->NewEventSource(par); // delete old, and create the new source now
276  result=kTRUE;
277  //std::cout << "new step source: step found"<< std::endl;
278  } else {
279  result=kFALSE;
280  //std::cout << "new step source: step not found"<< std::endl;
281  }
282  return result;
283 }
284 
286 {
287  GO4TRACE((12,"TGo4AnalysisStepManager::NewStepProcessor(const char *, TGo4EventProcessorParameter *)",__LINE__, __FILE__));
288  Bool_t result=kFALSE;
289  TGo4AnalysisStep* step=GetAnalysisStep(name);
290  if(step) {
291  //step->SetEventProcessor(par); // remember parameter for next init
292  step->NewEventProcessor(par); // create processor now
293  result=kTRUE;
294  } else {
295  result=kFALSE;
296  }
297  return result;
298 }
299 
300 Int_t TGo4AnalysisStepManager::Store(const char * name, TGo4Parameter* par)
301 {
302  TGo4AnalysisStep* step=GetAnalysisStep(name);
303  return (step!=0) ? step->Store(par) : 1;
304 }
305 
306 Int_t TGo4AnalysisStepManager::Store(const char * name, TGo4Condition* con)
307 {
308  TGo4AnalysisStep* step=GetAnalysisStep(name);
309  return (step!=0) ? step->Store(con) : 1;
310 }
311 
312 Int_t TGo4AnalysisStepManager::Store(const char * name, TGo4Fitter* fit)
313 {
314  TGo4AnalysisStep* step=GetAnalysisStep(name);
315  return (step!=0) ? step->Store(fit) : 1;
316 }
317 
318 Int_t TGo4AnalysisStepManager::Store(const char * name, TFolder* folder)
319 {
320  TGo4AnalysisStep* step=GetAnalysisStep(name);
321  return (step!=0) ? step->Store(folder) : 1;
322 }
323 
324 
326 {
327  GO4TRACE((11,"TGo4AnalysisStepManager::GetInputEvent(Int_t)",__LINE__, __FILE__));
328  TGo4EventElement* rev=0;
329  TGo4AnalysisStep* step=GetAnalysisStep(stepname);
330  if(step) {
332  if(pro)
333  rev=pro->GetInputEvent(); // get true input event
334  } else {
335  rev=0;
336  }
337  return rev;
338 }
339 
341 {
342  GO4TRACE((11,"TGo4AnalysisStepManager::GetInputEvent(Int_t)",__LINE__, __FILE__));
343  TGo4EventElement* rev = 0;
344  TGo4AnalysisStep* step = dynamic_cast<TGo4AnalysisStep*> (fxStepList->At(stepindex) );
345  if(step) {
346  TGo4EventProcessor* pro = step->GetEventProcessor();
347  if(pro) rev=pro->GetInputEvent(); // get true input event
348  //rev=step->GetInputEvent();
349  } else {
350  rev=0;
351  }
352  return rev;
353 }
354 
356 {
357  GO4TRACE((11,"TGo4AnalysisStepManager::GetOutputEvent(const char*)",__LINE__, __FILE__));
358  TGo4EventElement* rev=0;
359  TGo4AnalysisStep* step=GetAnalysisStep(stepname);
360  if(step) {
361  rev = step->GetOutputEvent();
362  } else {
363  rev=0;
364  }
365  return rev;
366 }
367 
369 {
370  GO4TRACE((11,"TGo4AnalysisStepManager::GetOutputEvent(Int_t)",__LINE__, __FILE__));
371  TGo4EventElement* rev=0;
372  TGo4AnalysisStep* step=0;
373  step= dynamic_cast<TGo4AnalysisStep*> ( fxStepList->At(stepindex) );
374  if(step) {
375  rev=step->GetOutputEvent();
376  } else {
377  rev=0;
378  }
379  return rev;
380 }
381 
383 {
384  GO4TRACE((14,"TGo4AnalysisStepManager::AddAnalysisStep(TGo4AnalysisStep*)",__LINE__, __FILE__));
385  //
386  Bool_t rev=kFALSE;
387  if (next) {
388  if(fxStepList->FindObject(next)==0)
389  // is object already in list?
390  {
391  //no, add the new object
392  GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Adding new analysis step",__LINE__, __FILE__));
393  fxStepList->AddLast(next);
394  // set previous step:
395  Int_t ix=fxStepList->IndexOf(next);
396  if(ix>0)
397  {
398  TGo4AnalysisStep* previous= dynamic_cast<TGo4AnalysisStep*> ( fxStepList->At(ix-1) );
399  next->SetPreviousStep(previous);
400  }
401  else
402  {
403  next->SetPreviousStep(0);
404  }
405  fiLastStepIndex=ix;
406  rev=kTRUE;
407  TGo4Analysis::Instance()->Message(1,"Analysis: Added analysis step %s",
408  next->GetName());
409  }
410  else
411  {
412  // yes, do nothing
413  GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Analysis step was already there",__LINE__, __FILE__));
414  rev=kFALSE;
415  TGo4Analysis::Instance()->Message(2,"Analysis: WARNING - analysis step %s was already in steplist",
416  next->GetName() );
417  }
418  } // if(next)
419  else
420  {
421  GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Zero Analysis step pointer",__LINE__, __FILE__));
422  rev=kFALSE;
423  TGo4Analysis::Instance()->Message(2,"Analysis: WARNING - did not add zero analysis step pointer to steplist");
424  }
425  return rev;
426 }
427 
429 {
430  GO4TRACE((11,"TGo4AnalysisStepManager::GetAnalysisStep(const char *)",__LINE__, __FILE__));
431  TGo4AnalysisStep* step=0;
432  if(name==0)
433  step=dynamic_cast<TGo4AnalysisStep*>( fxStepList->At(fiFirstStepIndex));
434  else
435  step = dynamic_cast<TGo4AnalysisStep*>( fxStepList->FindObject(name) );
436  return step;
437 }
438 
440 {
441  return fxStepList ? fxStepList->GetLast() + 1 : 0;
442 }
443 
445 {
446  GO4TRACE((11,"TGo4AnalysisStepManager::GetAnalysisStepNum(Int_t)",__LINE__, __FILE__));
447  if ((number<0) || (number>fxStepList->GetLast())) return 0;
448  return dynamic_cast<TGo4AnalysisStep*>(fxStepList->At(number));
449 }
450 
451 
453 {
454  GO4TRACE((11,"TGo4AnalysisStepManager::ProcessAnalysisSteps()",__LINE__, __FILE__));
455  //
456  fxCurrentStep = 0;
457  fiCurrentStepIndex = 0;
458  Bool_t isfirststep = kTRUE;
459  // first evaluate actual beginning index for "keep input event" mode:
460  Int_t repeatinputstart=-1;
464  repeatinputstart=fiCurrentStepIndex;
465  break;
466  }
467  }
468 
469  SetOutputEvent(0); // make sure that first step wont take output of last one
472  if(fxCurrentStep==0) break;
473  if(IsStepChecking() && isfirststep ) {
474  // check first step source:
475  isfirststep = kFALSE;
478  else {
479  fxCurrentStep->SetStatusMessage("!!! No Event Source for first analysis step !!!");
481  }
482  }
483  if(fiCurrentStepIndex<repeatinputstart) continue; // skip steps before a step which is reprocessing same input event
484 
486 
487  if(fxCurrentStep->IsKeepOutputEvent()) break; // skip all steps after incomplete output event
488  } // for(...)
489  // finally, we update maintree header if the steps use treesource/store instances:
491  return 0;
492 }
493 
495 {
496  GO4TRACE((11,"TGo4AnalysisStepManager::UpdateStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
497  if(state!=0) {
501  fxCurrentStep=0;
502  fxStepIterator->Reset();
503  state->ClearStepStatus();
504  while((fxCurrentStep= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
505  {
507  state->AddStepStatus(stepstate);
508  } // while(fxCurrentStep..)
509  } // if(state!=0)
510 }
511 
513 {
514  GO4TRACE((11,"TGo4AnalysisStepManager::SetStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
515  if(state!=0) {
519  // note: the step indices are not used for
520  // initialization of analysis any more!
521  // update internal states of steps:
522  fxCurrentStep=0;
523  fxStepIterator->Reset();
524  while((fxCurrentStep= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
525  {
526  const char* name= fxCurrentStep->GetName();
527  TGo4AnalysisStepStatus* stepstate= state->GetStepStatus(name);
528  fxCurrentStep->SetStatus(stepstate);
529 
530  } // while(fxCurrentStep..)
531  } // if(state!=0)
532 }
533 
535 {
536  GO4TRACE((12,"TGo4AnalysisStepManager::AutoSave()",__LINE__, __FILE__));
537  //
538  //TGo4LockGuard autoguard(fxAutoSaveMutex);
539  TGo4Analysis::Instance()->Message(0,"Analysis Step Manager -- AutoSaving....");
540  TGo4AnalysisStep* step=0;
541  fxStepIterator->Reset();
542  while((step= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
543  {
544  step->StoreCalibration();
545  }
546 
547  // write maintree to file if existing...
548  if(TGo4MainTree::Exists()) {
550  }
551 }
552 
554 {
555  return kTRUE; // FIXME: workaround, to be removed later!!! JA
556 
557  return (fxCurrentStep!=0) ? fxCurrentStep->IsErrorStopEnabled() : kTRUE;
558 }
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)
Bool_t IsErrorStopEnabled() const
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:270