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