GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4AnalysisStep.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 
14 #include "TGo4AnalysisStep.h"
15 
16 #include "TROOT.h"
17 
18 #include "TGo4Log.h"
19 #include "TGo4AnalysisImp.h"
20 #include "TGo4AnalysisStepStatus.h"
22 
26 
27 #include "TGo4EventCalibration.h"
29 #include "TGo4FileStoreParameter.h"
30 
31 #include "TGo4EventElement.h"
32 #include "TGo4EventFactory.h"
33 #include "TGo4EventStore.h"
34 
36 :TNamed(name,"This is a Go4 analysis step"),
37  fxPrevious(nullptr), fxEventStore(nullptr), fxEventSource(nullptr), fxEventProcessor(nullptr),
38  fxInputEvent(nullptr), fxOutputEvent(nullptr),
39  fxSourceType(sourcetype), fxStoreType(storetype), fxProcessorType(processortype),
40  fbSourceEnabled(kFALSE), fbSourceImplemented(kFALSE),
41  fbStoreEnabled(kFALSE), fbStoreImplemented(kFALSE),
42  fbProcessEnabled(kTRUE),
43  fbErrorStopEnabled(kFALSE), fbErrorStopped(kFALSE)
44 
45 {
46  GO4TRACE((15,"TGo4AnalysisStep::TGo4AnalysisStep(const char *, TGo4EventFactory *)",__LINE__, __FILE__));
47  fxOwner = TGo4Analysis::Instance(); // note: we always have the analysis framework!
48  fxEventFactory = eventfactory;
49  if(fxStoreType)
50  fxStoreType->SetTitle(GetName()); // set title of eventstore parameter to analysis step name
51  // this might be used to indicate tree name
52  SetStatusMessage(" Analysis Step is created ");
53 }
54 
55 
57 :TNamed("Default Analysis Step","This is a Go4 analysis step"),
58  fxPrevious(nullptr), fxEventStore(nullptr), fxEventSource(nullptr), fxEventProcessor(nullptr),
59  fxInputEvent(nullptr), fxOutputEvent(nullptr),
60  fxSourceType(nullptr), fxStoreType(nullptr), fxProcessorType(nullptr),
61  fbSourceEnabled(kFALSE), fbSourceImplemented(kFALSE),
62  fbStoreEnabled(kFALSE), fbStoreImplemented(kFALSE),
63  fbProcessEnabled(kTRUE),
64  fbErrorStopEnabled(kFALSE), fbErrorStopped(kFALSE)
65 {
66  GO4TRACE((15,"TGo4AnalysisStep::TGo4AnalysisStep()",__LINE__, __FILE__));
67 
68  fxOwner = nullptr;
69  fxEventFactory = nullptr;
70 }
71 
73 {
74  GO4TRACE((15,"TGo4AnalysisStep::~TGo4AnalysisStep()",__LINE__, __FILE__));
75  if(fxOwner) {
76  Close();
77  delete fxEventFactory;
78  delete fxSourceType;
79  delete fxStoreType;
80  delete fxProcessorType;
81  }
82 }
83 
85 {
86  GO4TRACE((15,"TGo4AnalysisStep::InitEventClasses()",__LINE__, __FILE__));
87  // note: the order is important here, from source to drain...
88  if(fbProcessEnabled) {
90  NewInputEvent();
94  }
95 }
96 
98 {
99  GO4TRACE((12,"TGo4AnalysisStep::Process()",__LINE__, __FILE__));
100  if(!fbProcessEnabled) return;
101  if(!fxEventProcessor) {
102  SetStatusMessage("! AnalysisStep -- Process Error: no event processor !");
103  throw TGo4AnalysisStepException(this);
104  }
105 
106  TGo4EventElement *input = nullptr;
107  fiProcessStatus = 0;
110  // fill input event from own source
113  fxInputEvent->Fill(); // do not overwrite current input event contents
114  input = fxInputEvent;
115  } else
116  // get input event structure from previous step
117  input = fxOwner->GetOutputEvent();
118 
119 
122  fxEventProcessor->SetInputEvent(input); // do not change current input event reference
123 
124  //fxEventProcessor->SetKeepInputEvent(kFALSE); // automatic reset of keep input flags before processor execution
125 
126  if(fxOutputEvent) {
128  if(fxEventProcessor->IsKeepOutputEvent()) fxOutputEvent->SetKeepContents(kTRUE); // suppress inplicit Clear()
129  //fxEventProcessor->SetKeepOutputEvent(kFALSE); // automatic reset of keep output flags before processor execution
130 
131  fxOutputEvent->Fill(); // this calls processor build event
132 
136  } else {
137  SetStatusMessage("! AnalysisStep -- Process Error: no output event !");
138  throw TGo4AnalysisStepException(this);
139  }
140 }
141 
143 {
144  GO4TRACE((14,"TGo4AnalysisStep::Close()",__LINE__, __FILE__));
145  CloseEventStore();
150 }
151 
153 {
154  GO4TRACE((14,"TGo4AnalysisStep::CloseEventStore()",__LINE__, __FILE__));
155  if(fxEventStore) {
156  TTree *atree = fxEventStore->GetTree();
157  fxOwner->RemoveTree(atree);
159  delete fxEventStore;
160  fxEventStore = nullptr;
161  fbStoreImplemented=kFALSE;
162  }
163 }
164 
165 
167 {
168  GO4TRACE((14,"TGo4AnalysisStep::CloseEventSource()",__LINE__, __FILE__));
169  if(fxEventSource) {
171  delete fxEventSource;
172  fxEventSource = nullptr;
173  fbSourceImplemented=kFALSE;
174  }
175 }
176 
178 {
179  GO4TRACE((14,"TGo4AnalysisStep::CloseEventProcessor()",__LINE__, __FILE__));
180  if(fxEventProcessor) {
182  delete fxEventProcessor;
183  fxEventProcessor = nullptr;
184  }
185 }
186 
188 {
189  GO4TRACE((14,"TGo4AnalysisStep::DeleteInputEvent()",__LINE__, __FILE__));
190  if(fxInputEvent) {
192  delete fxInputEvent;
193  fxInputEvent = nullptr;
194  }
195 }
196 
198 {
199  GO4TRACE((14,"TGo4AnalysisStep::DeleteOutputEvent()",__LINE__, __FILE__));
200  if(fxOutputEvent) {
202  delete fxOutputEvent;
203  fxOutputEvent = nullptr;
204  }
205 }
206 
208 {
209  GO4TRACE((14,"TGo4AnalysisStep::StoreCalibration()",__LINE__, __FILE__));
210  TGo4EventCalibration* cali = nullptr;
211  if(fxEventProcessor)
214  fxEventStore->Store(cali);
215 }
216 
218 {
220  return fxEventStore->Store(cali);
221  return -1;
222 }
223 
225 {
227  return fxEventStore->Store(conny);
228  return -1;
229 }
230 
232 {
234  return fxEventStore->Store(fitter);
235  return -1;
236 }
237 
238 Int_t TGo4AnalysisStep::Store(TFolder *fold)
239 {
241  return fxEventStore->Store(fold);
242  return -1;
243 }
244 
245 
247 {
248  GO4TRACE((14,"TGo4AnalysisStep::IsMatchingPrevious(TGo4AnalysisStep *)",__LINE__, __FILE__));
249  if(!IsProcessEnabled()) return kTRUE;
250  // only check if this step is active, otherwise no event classes are initialized!
251 
252  auto prevevent = fxPrevious ? fxPrevious->GetOutputEvent() : nullptr;
253  if (!prevevent) return kTRUE;
254 
255  return !strcmp(prevevent->ClassName(), fxInputEvent->ClassName()) &&
256  !strcmp(prevevent->GetName(), fxInputEvent->GetName());
257 }
258 
260 {
261  return !fxEventStore ? nullptr : fxEventStore->GetName();
262 }
263 
265 {
266  return !fxEventSource ? nullptr : fxEventSource->GetActiveName();
267 }
268 
270 {
271  GO4TRACE((12,"TGo4AnalysisStep::NewEventSource(Int_t)",__LINE__, __FILE__));
272  const char *sourcename = "";
273  if (kind) sourcename = kind->GetName();
274 
276  if(fxEventFactory) {
277  gROOT->cd(); // make sure that any histograms of source are not assigned
278  // to a file possibly opened before...
279  if(fbSourceEnabled) {
280  if(kind && kind->InheritsFrom("TGo4TreeSourceParameter")) {
281  SetStatusMessage("Did not init TGo4TreeSource, please use TGo4FileSource instead !");
282  throw TGo4AnalysisStepException(this);
283  }
284  if(fxPrevious) {
285  // check if previous step would overwrite our event source:
286  const char *evstorename=fxPrevious->GetEventStoreName();
287  if(evstorename && !strcmp(evstorename, sourcename) && fxPrevious->IsStoreEnabled()) {
288  TGo4Analysis::Instance()->Message(2,"AnalysisStep %s: Event source %s not created: previous store of same name !",
289  GetName(), sourcename);
290  fxEventSource = nullptr;
291  } else {
293  } // if(evstorename!= ... )
294  } else {
296  } // if(fxPrevious)
297  gROOT->cd(); // back to global directory; rootfile as eventsource would be cd here!
298  } else {
299  fxEventSource = nullptr;// if not enabled, do not open files or connect...
300  } // if(fbSourceEnabled)
301 
302  if(fxEventSource) {
303  fbSourceImplemented=kTRUE;
304  fxOwner->AddEventSource(fxEventSource); // reference to eventsource class
305  // we have to set reference to new source in input event:
306  if(fxInputEvent) {
308  fxInputEvent->Init(); // this should check if source is correct
309  }
310  } else {
311  TGo4Analysis::Instance()->Message(0,"AnalysisStep %s : No EventSource instance created by EventFactory",
312  GetName());
313  fbSourceImplemented=kFALSE;
314  } // if(fxEventSource)
315  } else {
316  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventSource Error: no event factory ");
317  } // if(fxEventFactory)
318  // for InitEventClasses we must store the source type:
319  SetEventSource(kind);
320 }
321 
323 {
324  GO4TRACE((12,"TGo4AnalysisStep::NewEventStore(Int_t)",__LINE__, __FILE__));
325  CloseEventStore();
326  if(fxEventFactory) {
327  gROOT->cd(); // make sure that store is not assigned
328  // to a file possibly opened before...
329  if(fbStoreEnabled) {
330  if(kind && kind->InheritsFrom("TGo4TreeStoreParameter"))
331  {
332  SetStatusMessage("! Did not init TGo4TreeStore, please use TGo4FileStore instead !");
333  throw TGo4AnalysisStepException(this);
334  }
335 
337  //kind->Print();
338  }
339 
340  if(fxEventStore) {
341  fbStoreImplemented=kTRUE;
342  TTree *atree= fxEventStore->GetTree();
343  fxOwner->AddTree(atree); // reference to tree
344  fxOwner->AddEventStore(fxEventStore); // reference to storage class
345  } else {
346  TGo4Analysis::Instance()->Message(0,"AnalysisStep %s : No EventStore instance created by EventFactory",
347  GetName() );
348  fbStoreImplemented=kFALSE;
349  }
350  } else {
351  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventStore Error: no event factory !");
352  }
353  gROOT->cd(); // make sure that objects assigned after us are in global dir!
354  // for InitEventClasses :
355  SetEventStore(kind);
356 }
357 
359 {
360  GO4TRACE((12,"TGo4AnalysisStep::NewEventProcessor(Int_t)",__LINE__, __FILE__));
362  if(fxEventFactory) {
363  gROOT->cd(); // make sure that any histograms of processor are not assigned
364  // to a file possibly opened before...
367  if(fxEventProcessor)
369  // method of processor might init the types here...
370  if(fxOutputEvent) {
372  fxOutputEvent->Init(); // should check event source
373  }
374  } else {
375  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventProcessor Error: no event factory !");
376  }
377  // for InitEventClasses :
378  SetEventProcessor(kind);
379 }
381 {
382  GO4TRACE((11,"TGo4AnalysisStep::CreateStatus()",__LINE__, __FILE__));
383  TGo4AnalysisStepStatus* state= new TGo4AnalysisStepStatus( GetName() );
385  if(!fxSourceType) {
386  // if user has defined the source as null, we provide dummy for gui
387  fxSourceType= new TGo4FileSourceParameter("NoInputDefined");
388  fbSourceEnabled=kFALSE;
389  }
390  state->SetSourcePar(fxSourceType);
392  if(!fxStoreType) {
393  fxStoreType = new TGo4FileStoreParameter("NoOutputDefined");
394  fbStoreEnabled=kFALSE;
395  }
396  state->SetStorePar(fxStoreType);
402  return state;
403 }
404 
406 {
407  GO4TRACE((12,"TGo4AnalysisStep::NewInputEvent()",__LINE__, __FILE__));
409  if(fxEventFactory) {
412  if(fxInputEvent) {
414  fxInputEvent->Init(); // this should check if source is correct
415  }
416  } else {
417  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewInputEvent Error: no event factory !");
418  }
419 }
420 
422 {
423  GO4TRACE((12,"TGo4AnalysisStep::NewOutputEvent()",__LINE__, __FILE__));
425  if(fxEventFactory) {
428  if(fxOutputEvent) {
430  fxOutputEvent->Init(); // should check event source
431  }
432  } else {
433  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewOutputEvent Error: no event factory !");
434  }
435 }
436 
437 
439 {
440  GO4TRACE((11,"TGo4AnalysisStep::SetStatus(TGo4AnalysisStepStatus*)",__LINE__, __FILE__));
441  if(state) {
443  SetEventSource(state->GetSourcePar());
444  SetEventStore(state->GetStorePar());
449  fbErrorStopped=kFALSE; // reset run status parameters to default
450  fiProcessStatus = 0; // dito
451  }
452 }
453 
455 {
456  if(kind==fxProcessorType) return; // avoid deleting valid parameter
457  if(fxProcessorType) delete fxProcessorType;
458  if(kind)
459  fxProcessorType = dynamic_cast<TGo4EventProcessorParameter*>(kind->Clone());
460  else
461  fxProcessorType = nullptr;
462 }
463 
465 {
466  if(kind==fxSourceType) return; // avoid deleting valid parameter
467  if(fxSourceType) delete fxSourceType;
468  if(kind)
469  fxSourceType = dynamic_cast<TGo4EventSourceParameter*>(kind->Clone());
470  else
471  fxSourceType = nullptr;
472 }
473 
475 {
476  return fxSourceType != nullptr;
477 }
478 
480 {
481  if(kind == fxStoreType) return; // avoid deleting valid parameter
482  if (fxStoreType)
483  delete fxStoreType;
484  if (kind)
485  fxStoreType = dynamic_cast<TGo4EventStoreParameter *>(kind->Clone());
486  else
487  fxStoreType = nullptr;
488  if (fxStoreType)
489  fxStoreType->SetTitle(GetName());
490  // set title of eventstore parameter to analysis step name
491  // this might be used to indicate tree name
492 }
493 
495 {
496  return fxStoreType != nullptr;
497 }
void SetProcessEnabled(Bool_t on=kTRUE)
void SetStoreEnabled(Bool_t on=kTRUE)
Bool_t IsKeepInputEvent() const
void SetOutputEvent(TGo4EventElement *event)
TGo4EventElement * fxInputEvent
virtual Int_t Store(TGo4EventElement *event)=0
Int_t Store(TGo4Parameter *cali)
void NewEventStore(TGo4EventStoreParameter *kind)
void SetEventStore(TGo4EventStoreParameter *kind)
void NewEventSource(TGo4EventSourceParameter *kind)
void SetStatus(TGo4AnalysisStepStatus *state)
TGo4EventFactory * fxEventFactory
Bool_t IsEventSourceParam() const
void SetSourceEnabled(Bool_t on=kTRUE)
Bool_t RemoveEventSource(TGo4EventSource *source)
virtual const char * GetActiveName() const
TGo4EventElement * GetOutputEvent() const
TGo4EventSourceParameter * GetSourcePar() const
TGo4EventElement * fxOutputEvent
Bool_t IsValid() const
Bool_t RemoveTree(TTree *tree, const char *stepname=nullptr)
Bool_t IsStoreEnabled() const
TGo4EventCalibration * GetCalibration() const
Bool_t RemoveEventStructure(TGo4EventElement *ev)
void SetStorePar(TGo4EventStoreParameter *kind)
Bool_t AddTree(TTree *tree, const char *subfolder=nullptr)
TGo4EventStoreParameter * fxStoreType
void SetSourcePar(TGo4EventSourceParameter *kind)
Bool_t IsProcessEnabled() const
void SetSourceEnabled(Bool_t on=kTRUE)
TGo4EventSource * fxEventSource
TGo4EventProcessor * fxEventProcessor
virtual Int_t Fill()
Bool_t RemoveEventStore(TGo4EventStore *store)
void SetStatusMessage(const char *txt)
virtual TGo4EventElement * CreateOutputEvent()=0
Bool_t AddEventStructure(TGo4EventElement *ev)
void Message(Int_t prio, const char *text,...)
Bool_t AddEventSource(TGo4EventSource *source)
TGo4AnalysisStepStatus * CreateStatus()
Bool_t AddEventProcessor(TGo4EventProcessor *pro)
void SetInputEvent(TGo4EventElement *raw)
void SetProcessorPar(TGo4EventProcessorParameter *kind)
Bool_t RemoveEventProcessor(TGo4EventProcessor *pro)
Bool_t IsKeepOutputEvent() const
Bool_t IsMatchingPrevious() const
TGo4EventStore * fxEventStore
TGo4Analysis * fxOwner
const char * GetEventSourceName() const
TGo4AnalysisStep * fxPrevious
void SetStoreEnabled(Bool_t on=kTRUE)
void SetErrorStopEnabled(Bool_t on=kTRUE)
virtual Int_t Init()
TGo4EventProcessorParameter * GetProcessorPar() const
void SetProcessEnabled(Bool_t on=kTRUE)
void SetEventSource(TGo4EventSourceParameter *kind)
#define GO4TRACE(X)
Definition: TGo4Log.h:25
virtual void InitEventClasses()
void SetEventProcessor(TGo4EventProcessorParameter *kind)
const char * GetEventStoreName() const
TGo4EventSourceParameter * fxSourceType
TGo4EventStoreParameter * GetStorePar() const
virtual ~TGo4AnalysisStep()
void SetEventSource(TGo4EventSource *src)
void SetErrorStopEnabled(Bool_t on)
virtual TGo4EventProcessor * CreateEventProcessor(TGo4EventProcessorParameter *par)=0
virtual TGo4EventStore * CreateEventStore(TGo4EventStoreParameter *par)=0
void NewEventProcessor(TGo4EventProcessorParameter *kind)
TGo4EventElement * GetOutputEvent(const char *stepname) const
TGo4EventProcessorParameter * fxProcessorType
Bool_t AddEventStore(TGo4EventStore *store)
static TGo4Analysis * Instance()
virtual TTree * GetTree()
virtual TGo4EventElement * CreateInputEvent()=0
Bool_t IsEventStoreParam() const
virtual TGo4EventSource * CreateEventSource(TGo4EventSourceParameter *par)=0
void SetKeepContents(Bool_t on=kTRUE)