GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4AnalysisStep.cxx
Go to the documentation of this file.
1 // $Id: TGo4AnalysisStep.cxx 2742 2020-04-16 07:35: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 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(0), fxEventStore(0), fxEventSource(0), fxEventProcessor(0),
38  fxInputEvent(0), fxOutputEvent(0),
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(0), fxEventStore(0), fxEventSource(0), fxEventProcessor(0),
59  fxInputEvent(0), fxOutputEvent(0),
60  fxSourceType(0), fxStoreType(0), fxProcessorType(0),
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=0;
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==0) {
102  SetStatusMessage("! AnalysisStep -- Process Error: no event processor !");
103  throw TGo4AnalysisStepException(this);
104  }
105 
106  TGo4EventElement* input(0);
107  fiProcessStatus = 0;
109  if (fbSourceEnabled && (fxEventSource!=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!=0) {
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  } // end if(fxOutputEvent!=0)
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=0;
161  fbStoreImplemented=kFALSE;
162  }
163 }
164 
165 
167 {
168  GO4TRACE((14,"TGo4AnalysisStep::CloseEventSource()",__LINE__, __FILE__));
169  if(fxEventSource) {
171  delete fxEventSource;
172  fxEventSource=0;
173  fbSourceImplemented=kFALSE;
174  }
175 }
176 
178 {
179  GO4TRACE((14,"TGo4AnalysisStep::CloseEventProcessor()",__LINE__, __FILE__));
180  if(fxEventProcessor) {
182  delete fxEventProcessor;
184  }
185 }
186 
188 {
189  GO4TRACE((14,"TGo4AnalysisStep::DeleteInputEvent()",__LINE__, __FILE__));
190  if(fxInputEvent) {
192  delete fxInputEvent;
193  fxInputEvent=0;
194  }
195 }
196 
198 {
199  GO4TRACE((14,"TGo4AnalysisStep::DeleteOutputEvent()",__LINE__, __FILE__));
200  if(fxOutputEvent) {
202  delete fxOutputEvent;
203  fxOutputEvent=0;
204  }
205 }
206 
207 
208 
210 {
211  GO4TRACE((14,"TGo4AnalysisStep::StoreCalibration()",__LINE__, __FILE__));
212  TGo4EventCalibration* cali=0;
213  if(fxEventProcessor)
216  fxEventStore->Store(cali);
217 }
218 
220 {
222  return fxEventStore->Store(cali);
223  return -1;
224 }
225 
227 {
229  return fxEventStore->Store(conny);
230  return -1;
231 }
232 
234 {
236  return fxEventStore->Store(fitter);
237  return -1;
238 }
239 
240 Int_t TGo4AnalysisStep::Store(TFolder* fold)
241 {
243  return fxEventStore->Store(fold);
244  return -1;
245 }
246 
247 
249 {
250  GO4TRACE((14,"TGo4AnalysisStep::IsMatchingPrevious(TGo4AnalysisStep*)",__LINE__, __FILE__));
251  if(!IsProcessEnabled()) return kTRUE;
252  // only check if this step is active, otherwise no event classes are initialized!
253 
254  if (fxPrevious==0) return kTRUE;
255 
257  if (prevevent==0) return kTRUE;
258 
259  return !strcmp(prevevent->ClassName(),fxInputEvent->ClassName()) &&
260  !strcmp(prevevent->GetName(),fxInputEvent->GetName());
261 }
262 
264 {
265  GO4TRACE((12,"TGo4AnalysisStep::GetEventStoreName()",__LINE__, __FILE__));
266 
267  return (fxEventStore==0) ? 0 : fxEventStore->GetName();
268 }
269 
271 {
272  return (fxEventSource==0) ? 0 : fxEventSource->GetActiveName();
273 }
274 
276 {
277  GO4TRACE((12,"TGo4AnalysisStep::NewEventSource(Int_t)",__LINE__, __FILE__));
278  const char* sourcename = "";
279  if (kind) sourcename = kind->GetName();
280 
282  if(fxEventFactory) {
283  gROOT->cd(); // make sure that any histograms of source are not assigned
284  // to a file possibly opened before...
285  if(fbSourceEnabled) {
286  if(kind && kind->InheritsFrom("TGo4TreeSourceParameter")) {
287  SetStatusMessage("Did not init TGo4TreeSource, please use TGo4FileSource instead !");
288  throw TGo4AnalysisStepException(this);
289  }
290  if(fxPrevious) {
291  // check if previous step would overwrite our event source:
292  const char* evstorename=fxPrevious->GetEventStoreName();
293  if(evstorename!=0 && !strcmp(evstorename, sourcename) && fxPrevious->IsStoreEnabled()) {
294  TGo4Analysis::Instance()->Message(2,"AnalysisStep %s: Event source %s not created: previous store of same name !",
295  GetName(), sourcename);
296  fxEventSource=0;
297  } else {
299  } // if(evstorename!= ... )
300  } else {
302  } // if(fxPrevious)
303  gROOT->cd(); // back to global directory; rootfile as eventsource would be cd here!
304  } else {
305  fxEventSource=0;// if not enabled, do not open files or connect...
306  } // if(fbSourceEnabled)
307 
308  if(fxEventSource) {
309  fbSourceImplemented=kTRUE;
310  fxOwner->AddEventSource(fxEventSource); // reference to eventsource class
311  // we have to set reference to new source in input event:
312  if(fxInputEvent) {
314  fxInputEvent->Init(); // this should check if source is correct
315  }
316  } else {
317  TGo4Analysis::Instance()->Message(0,"AnalysisStep %s : No EventSource instance created by EventFactory",
318  GetName());
319  fbSourceImplemented=kFALSE;
320  } // if(fxEventSource)
321  } else {
322  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventSource Error: no event factory ");
323  } // if(fxEventFactory)
324  // for InitEventClasses we must store the source type:
325  SetEventSource(kind);
326 }
327 
329 {
330  GO4TRACE((12,"TGo4AnalysisStep::NewEventStore(Int_t)",__LINE__, __FILE__));
331  CloseEventStore();
332  if(fxEventFactory) {
333  gROOT->cd(); // make sure that store is not assigned
334  // to a file possibly opened before...
335  if(fbStoreEnabled) {
336  if(kind && kind->InheritsFrom("TGo4TreeStoreParameter"))
337  {
338  SetStatusMessage("! Did not init TGo4TreeStore, please use TGo4FileStore instead !");
339  throw TGo4AnalysisStepException(this);
340  }
341 
343  //kind->PrintParameter();
344  }
345 
346  if(fxEventStore) {
347  fbStoreImplemented=kTRUE;
348  TTree* atree= fxEventStore->GetTree();
349  fxOwner->AddTree(atree); // reference to tree
350  fxOwner->AddEventStore(fxEventStore); // reference to storage class
351  } else {
352  TGo4Analysis::Instance()->Message(0,"AnalysisStep %s : No EventStore instance created by EventFactory",
353  GetName() );
354  fbStoreImplemented=kFALSE;
355  }
356  } else {
357  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventStore Error: no event factory !");
358  }
359  gROOT->cd(); // make sure that objects assigned after us are in global dir!
360  // for InitEventClasses :
361  SetEventStore(kind);
362 }
363 
365 {
366  GO4TRACE((12,"TGo4AnalysisStep::NewEventProcessor(Int_t)",__LINE__, __FILE__));
368  if(fxEventFactory) {
369  gROOT->cd(); // make sure that any histograms of processor are not assigned
370  // to a file possibly opened before...
373  if(fxEventProcessor)
375  // method of processor might init the types here...
376  if(fxOutputEvent) {
378  fxOutputEvent->Init(); // should check event source
379  }
380  } else {
381  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventProcessor Error: no event factory !");
382  }
383  // for InitEventClasses :
384  SetEventProcessor(kind);
385 }
387 {
388  GO4TRACE((11,"TGo4AnalysisStep::CreateStatus()",__LINE__, __FILE__));
389  TGo4AnalysisStepStatus* state= new TGo4AnalysisStepStatus( GetName() );
391  if(fxSourceType==0) {
392  // if user has defined the source as null, we provide dummy for gui
393  fxSourceType= new TGo4FileSourceParameter("NoInputDefined");
394  fbSourceEnabled=kFALSE;
395  }
396  state->SetSourcePar(fxSourceType);
398  if(fxStoreType==0) {
399  fxStoreType = new TGo4FileStoreParameter("NoOutputDefined");
400  fbStoreEnabled=kFALSE;
401  }
402  state->SetStorePar(fxStoreType);
408  return state;
409 }
410 
412 {
413  GO4TRACE((12,"TGo4AnalysisStep::NewInputEvent()",__LINE__, __FILE__));
415  if(fxEventFactory) {
418  if(fxInputEvent) {
420  fxInputEvent->Init(); // this should check if source is correct
421  }
422  } else {
423  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewInputEvent Error: no event factory !");
424  }
425 }
426 
428 {
429  GO4TRACE((12,"TGo4AnalysisStep::NewOutputEvent()",__LINE__, __FILE__));
431  if(fxEventFactory) {
434  if(fxOutputEvent) {
436  fxOutputEvent->Init(); // should check event source
437  }
438  } else {
439  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewOutputEvent Error: no event factory !");
440  }
441 }
442 
443 
445 {
446  GO4TRACE((11,"TGo4AnalysisStep::SetStatus(TGo4AnalysisStepStatus*)",__LINE__, __FILE__));
447  if(state!=0) {
449  SetEventSource(state->GetSourcePar());
450  SetEventStore(state->GetStorePar());
455  fbErrorStopped=kFALSE; // reset run status parameters to default
456  fiProcessStatus=0; // dito
457  }
458 }
459 
461 {
462  if(kind==fxProcessorType) return; // avoid deleting valid parameter
463  if(fxProcessorType) delete fxProcessorType;
464  if(kind)
465  fxProcessorType=dynamic_cast<TGo4EventProcessorParameter*>(kind->Clone());
466  else
467  fxProcessorType=0;
468 }
469 
471 {
472  if(kind==fxSourceType) return; // avoid deleting valid parameter
473  if(fxSourceType) delete fxSourceType;
474  if(kind)
475  fxSourceType=dynamic_cast<TGo4EventSourceParameter*>(kind->Clone());
476  else
477  fxSourceType=0;
478 }
479 
481 {
482  return fxSourceType!=0;
483 }
484 
486 {
487  if(kind==fxStoreType) return; // avoid deleting valid parameter
488  if(fxStoreType) delete fxStoreType;
489  if(kind)
490  fxStoreType=dynamic_cast<TGo4EventStoreParameter*>(kind->Clone());
491  else
492  fxStoreType=0;
493  if(fxStoreType)
494  fxStoreType->SetTitle(GetName());
495  // set title of eventstore parameter to analysis step name
496  // this might be used to indicate tree name
497 }
498 
500 {
501  return fxStoreType!=0;
502 }
void SetProcessEnabled(Bool_t on=kTRUE)
Bool_t IsErrorStopEnabled() const
void SetStoreEnabled(Bool_t on=kTRUE)
TGo4EventStoreParameter * GetStorePar() const
void SetOutputEvent(TGo4EventElement *event)
Bool_t IsEventSourceParam() const
TGo4EventElement * fxInputEvent
TGo4EventElement * GetOutputEvent(const char *stepname)
virtual Int_t Store(TGo4EventElement *event)=0
Bool_t IsStoreEnabled() const
TGo4EventProcessorParameter * GetProcessorPar() const
Int_t Store(TGo4Parameter *cali)
void NewEventStore(TGo4EventStoreParameter *kind)
void SetEventStore(TGo4EventStoreParameter *kind)
TGo4EventElement * GetOutputEvent() const
void NewEventSource(TGo4EventSourceParameter *kind)
void SetStatus(TGo4AnalysisStepStatus *state)
TGo4EventFactory * fxEventFactory
Bool_t IsValid() const
void SetSourceEnabled(Bool_t on=kTRUE)
Bool_t RemoveEventSource(TGo4EventSource *source)
TGo4EventElement * fxOutputEvent
Bool_t RemoveEventStructure(TGo4EventElement *ev)
void SetStorePar(TGo4EventStoreParameter *kind)
TGo4EventStoreParameter * fxStoreType
void SetSourcePar(TGo4EventSourceParameter *kind)
void SetSourceEnabled(Bool_t on=kTRUE)
TGo4EventSourceParameter * GetSourcePar() const
TGo4EventSource * fxEventSource
TGo4EventProcessor * fxEventProcessor
Bool_t IsProcessEnabled() const
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)
TGo4EventStore * fxEventStore
TGo4Analysis * fxOwner
virtual const char * GetActiveName()
TGo4AnalysisStep * fxPrevious
void SetStoreEnabled(Bool_t on=kTRUE)
Bool_t AddTree(TTree *tree, const char *subfolder=0)
Bool_t RemoveTree(TTree *tree, const char *stepname=0)
void SetErrorStopEnabled(Bool_t on=kTRUE)
virtual Int_t Init()
void SetProcessEnabled(Bool_t on=kTRUE)
void SetEventSource(TGo4EventSourceParameter *kind)
#define GO4TRACE(X)
Definition: TGo4Log.h:26
virtual void InitEventClasses()
void SetEventProcessor(TGo4EventProcessorParameter *kind)
TGo4EventSourceParameter * fxSourceType
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)
TGo4EventProcessorParameter * fxProcessorType
Bool_t AddEventStore(TGo4EventStore *store)
static TGo4Analysis * Instance()
const char * GetEventSourceName()
Bool_t IsEventStoreParam() const
virtual TTree * GetTree()
virtual TGo4EventElement * CreateInputEvent()=0
virtual TGo4EventSource * CreateEventSource(TGo4EventSourceParameter *par)=0
TGo4EventCalibration * GetCalibration()
void SetKeepContents(Bool_t on=kTRUE)
const char * GetEventStoreName()