GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4AnalysisStep.cxx
Go to the documentation of this file.
1 // $Id: TGo4AnalysisStep.cxx 999 2013-07-25 11:58:59Z 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 
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 "TGo4EventProcessor.h"
34 #include "TGo4EventStore.h"
35 #include "TGo4EventSource.h"
36 
38 :TNamed(name,"This is a Go4 analysis step"),
39  fxPrevious(0), fxEventStore(0), fxEventSource(0), fxEventProcessor(0),
40  fxInputEvent(0), fxOutputEvent(0),
41  fxSourceType(sourcetype), fxStoreType(storetype), fxProcessorType(processortype),
42  fbSourceEnabled(kFALSE), fbSourceImplemented(kFALSE),
43  fbStoreEnabled(kFALSE), fbStoreImplemented(kFALSE),
44  fbProcessEnabled(kTRUE),
45  fbErrorStopEnabled(kFALSE), fbErrorStopped(kFALSE)
46 
47 {
48 GO4TRACE((15,"TGo4AnalysisStep::TGo4AnalysisStep(const char*, TGo4EventFactory*)",__LINE__, __FILE__));
49  fxOwner=TGo4Analysis::Instance(); // note: we always have the analysis framework!
50  fxEventFactory=eventfactory;
51  if(fxStoreType)
52  fxStoreType->SetTitle(GetName()); // set title of eventstore parameter to analysis step name
53  // this might be used to indicate tree name
54  SetStatusMessage(" Analysis Step is created ");
55 }
56 
57 
59 :TNamed("Default Analysis Step","This is a Go4 analysis step"),
60  fxPrevious(0), fxEventStore(0), fxEventSource(0), fxEventProcessor(0),
61  fxInputEvent(0), fxOutputEvent(0),
62  fxSourceType(0), fxStoreType(0), fxProcessorType(0),
63  fbSourceEnabled(kFALSE), fbSourceImplemented(kFALSE),
64  fbStoreEnabled(kFALSE), fbStoreImplemented(kFALSE),
65  fbProcessEnabled(kTRUE),
66  fbErrorStopEnabled(kFALSE), fbErrorStopped(kFALSE)
67 {
68  GO4TRACE((15,"TGo4AnalysisStep::TGo4AnalysisStep()",__LINE__, __FILE__));
69 
70  fxOwner=0;
72 }
73 
75 {
76  GO4TRACE((15,"TGo4AnalysisStep::~TGo4AnalysisStep()",__LINE__, __FILE__));
77  if(fxOwner) {
78  Close();
79  delete fxEventFactory;
80  delete fxSourceType;
81  delete fxStoreType;
82  delete fxProcessorType;
83  }
84 }
85 
87 {
88  GO4TRACE((15,"TGo4AnalysisStep::InitEventClasses()",__LINE__, __FILE__));
89  // note: the order is important here, from source to drain...
90  if(fbProcessEnabled) {
92  NewInputEvent();
96  }
97 }
98 
100 {
101  GO4TRACE((12,"TGo4AnalysisStep::Process()",__LINE__, __FILE__));
102  if(!fbProcessEnabled) return;
103  if(fxEventProcessor==0) {
104  SetStatusMessage("! AnalysisStep -- Process Error: no event processor !");
105  throw TGo4AnalysisStepException(this);
106  }
107 
108  TGo4EventElement* input(0);
109  fiProcessStatus = 0;
111  if (fbSourceEnabled && (fxEventSource!=0)) {
112  // fill input event from own source
115  fxInputEvent->Fill(); // do not overwrite current input event contents
116  input = fxInputEvent;
117  } else
118  // get input event structure from previous step
119  input = fxOwner->GetOutputEvent();
120 
121 
124  fxEventProcessor->SetInputEvent(input); // do not change current input event reference
125 
126  //fxEventProcessor->SetKeepInputEvent(kFALSE); // automatic reset of keep input flags before processor execution
127 
128  if(fxOutputEvent!=0) {
130  if(fxEventProcessor->IsKeepOutputEvent()) fxOutputEvent->SetKeepContents(kTRUE); // suppress inplicit Clear()
131  //fxEventProcessor->SetKeepOutputEvent(kFALSE); // automatic reset of keep output flags before processor execution
132 
133  fxOutputEvent->Fill(); // this calls processor build event
134 
138  } else {
139  SetStatusMessage("! AnalysisStep -- Process Error: no output event !");
140  throw TGo4AnalysisStepException(this);
141  } // end if(fxOutputEvent!=0)
142 }
143 
145 {
146  GO4TRACE((14,"TGo4AnalysisStep::Close()",__LINE__, __FILE__));
147  CloseEventStore();
152 }
153 
155 {
156  GO4TRACE((14,"TGo4AnalysisStep::CloseEventStore()",__LINE__, __FILE__));
157  if(fxEventStore) {
158  TTree* atree= fxEventStore->GetTree();
159  fxOwner->RemoveTree(atree);
161  delete fxEventStore;
162  fxEventStore=0;
163  fbStoreImplemented=kFALSE;
164  }
165 }
166 
167 
169 {
170  GO4TRACE((14,"TGo4AnalysisStep::CloseEventSource()",__LINE__, __FILE__));
171  if(fxEventSource) {
173  delete fxEventSource;
174  fxEventSource=0;
175  fbSourceImplemented=kFALSE;
176  }
177 }
178 
180 {
181  GO4TRACE((14,"TGo4AnalysisStep::CloseEventProcessor()",__LINE__, __FILE__));
182  if(fxEventProcessor) {
184  delete fxEventProcessor;
186  }
187 }
188 
190 {
191  GO4TRACE((14,"TGo4AnalysisStep::DeleteInputEvent()",__LINE__, __FILE__));
192  if(fxInputEvent) {
194  delete fxInputEvent;
195  fxInputEvent=0;
196  }
197 }
198 
200 {
201  GO4TRACE((14,"TGo4AnalysisStep::DeleteOutputEvent()",__LINE__, __FILE__));
202  if(fxOutputEvent) {
204  delete fxOutputEvent;
205  fxOutputEvent=0;
206  }
207 }
208 
209 
210 
212 {
213  GO4TRACE((14,"TGo4AnalysisStep::StoreCalibration()",__LINE__, __FILE__));
214  TGo4EventCalibration* cali=0;
215  if(fxEventProcessor)
218  fxEventStore->Store(cali);
219 }
220 
222 {
224  return fxEventStore->Store(cali);
225  return -1;
226 }
227 
229 {
231  return fxEventStore->Store(conny);
232  return -1;
233 }
234 
236 {
238  return fxEventStore->Store(fitter);
239  return -1;
240 }
241 
242 Int_t TGo4AnalysisStep::Store(TFolder* fold)
243 {
245  return fxEventStore->Store(fold);
246  return -1;
247 }
248 
249 
251 {
252  GO4TRACE((14,"TGo4AnalysisStep::IsMatchingPrevious(TGo4AnalysisStep*)",__LINE__, __FILE__));
253  if(!IsProcessEnabled()) return kTRUE;
254  // only check if this step is active, otherwise no event classes are initialized!
255 
256  if (fxPrevious==0) return kTRUE;
257 
259  if (prevevent==0) return kTRUE;
260 
261  return !strcmp(prevevent->ClassName(),fxInputEvent->ClassName()) &&
262  !strcmp(prevevent->GetName(),fxInputEvent->GetName());
263 }
264 
266 {
267  GO4TRACE((12,"TGo4AnalysisStep::GetEventStoreName()",__LINE__, __FILE__));
268 
269  return (fxEventStore==0) ? 0 : fxEventStore->GetName();
270 }
271 
273 {
274  return (fxEventSource==0) ? 0 : fxEventSource->GetActiveName();
275 }
276 
278 {
279  GO4TRACE((12,"TGo4AnalysisStep::NewEventSource(Int_t)",__LINE__, __FILE__));
280  const char* sourcename = "";
281  if (kind) sourcename = kind->GetName();
282 
284  if(fxEventFactory) {
285  gROOT->cd(); // make sure that any histograms of source are not assigned
286  // to a file possibly opened before...
287  if(fbSourceEnabled) {
288  if(kind && kind->InheritsFrom("TGo4TreeSourceParameter")) {
289  SetStatusMessage("Did not init TGo4TreeSource, please use TGo4FileSource instead !");
290  throw TGo4AnalysisStepException(this);
291  }
292  if(fxPrevious) {
293  // check if previous step would overwrite our event source:
294  const char* evstorename=fxPrevious->GetEventStoreName();
295  if(evstorename!=0 && !strcmp(evstorename, sourcename) && fxPrevious->IsStoreEnabled()) {
296  TGo4Analysis::Instance()->Message(2,"AnalysisStep %s: Event source %s not created: previous store of same name !",
297  GetName(), sourcename);
298  fxEventSource=0;
299  } else {
301  } // if(evstorename!= ... )
302  } else {
304  } // if(fxPrevious)
305  gROOT->cd(); // back to global directory; rootfile as eventsource would be cd here!
306  } else {
307  fxEventSource=0;// if not enabled, do not open files or connect...
308  } // if(fbSourceEnabled)
309 
310  if(fxEventSource) {
311  fbSourceImplemented=kTRUE;
312  fxOwner->AddEventSource(fxEventSource); // reference to eventsource class
313  // we have to set reference to new source in input event:
314  if(fxInputEvent) {
316  fxInputEvent->Init(); // this should check if source is correct
317  }
318  } else {
319  TGo4Analysis::Instance()->Message(0,"AnalysisStep %s : No EventSource instance created by EventFactory",
320  GetName());
321  fbSourceImplemented=kFALSE;
322  } // if(fxEventSource)
323  } else {
324  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventSource Error: no event factory ");
325  } // if(fxEventFactory)
326  // for InitEventClasses we must store the source type:
327  SetEventSource(kind);
328 }
329 
331 {
332  GO4TRACE((12,"TGo4AnalysisStep::NewEventStore(Int_t)",__LINE__, __FILE__));
333  CloseEventStore();
334  if(fxEventFactory) {
335  gROOT->cd(); // make sure that store is not assigned
336  // to a file possibly opened before...
337  if(fbStoreEnabled) {
338  if(kind && kind->InheritsFrom("TGo4TreeStoreParameter"))
339  {
340  SetStatusMessage("! Did not init TGo4TreeStore, please use TGo4FileStore instead !");
341  throw TGo4AnalysisStepException(this);
342  }
343 
345  //kind->PrintParameter();
346  }
347 
348  if(fxEventStore) {
349  fbStoreImplemented=kTRUE;
350  TTree* atree= fxEventStore->GetTree();
351  fxOwner->AddTree(atree); // reference to tree
352  fxOwner->AddEventStore(fxEventStore); // reference to storage class
353  } else {
354  TGo4Analysis::Instance()->Message(0,"AnalysisStep %s : No EventStore instance created by EventFactory",
355  GetName() );
356  fbStoreImplemented=kFALSE;
357  }
358  } else {
359  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventStore Error: no event factory !");
360  }
361  gROOT->cd(); // make sure that objects assigned after us are in global dir!
362  // for InitEventClasses :
363  SetEventStore(kind);
364 }
365 
367 {
368  GO4TRACE((12,"TGo4AnalysisStep::NewEventProcessor(Int_t)",__LINE__, __FILE__));
370  if(fxEventFactory) {
371  gROOT->cd(); // make sure that any histograms of processor are not assigned
372  // to a file possibly opened before...
375  if(fxEventProcessor)
377  // method of processor might init the types here...
378  if(fxOutputEvent) {
380  fxOutputEvent->Init(); // should check event source
381  }
382  } else {
383  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventProcessor Error: no event factory !");
384  }
385  // for InitEventClasses :
386  SetEventProcessor(kind);
387 }
389 {
390  GO4TRACE((11,"TGo4AnalysisStep::CreateStatus()",__LINE__, __FILE__));
391  TGo4AnalysisStepStatus* state= new TGo4AnalysisStepStatus( GetName() );
393  if(fxSourceType==0) {
394  // if user has defined the source as null, we provide dummy for gui
395  fxSourceType= new TGo4FileSourceParameter("NoInputDefined");
396  fbSourceEnabled=kFALSE;
397  }
398  state->SetSourcePar(fxSourceType);
400  if(fxStoreType==0) {
401  fxStoreType = new TGo4FileStoreParameter("NoOutputDefined");
402  fbStoreEnabled=kFALSE;
403  }
404  state->SetStorePar(fxStoreType);
410  return state;
411 }
412 
414 {
415  GO4TRACE((12,"TGo4AnalysisStep::NewInputEvent()",__LINE__, __FILE__));
417  if(fxEventFactory) {
420  if(fxInputEvent) {
422  fxInputEvent->Init(); // this should check if source is correct
423  }
424  } else {
425  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewInputEvent Error: no event factory !");
426  }
427 }
428 
430 {
431  GO4TRACE((12,"TGo4AnalysisStep::NewOutputEvent()",__LINE__, __FILE__));
433  if(fxEventFactory) {
436  if(fxOutputEvent) {
438  fxOutputEvent->Init(); // should check event source
439  }
440  } else {
441  TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewOutputEvent Error: no event factory !");
442  }
443 }
444 
445 
447 {
448  GO4TRACE((11,"TGo4AnalysisStep::SetStatus(TGo4AnalysisStepStatus*)",__LINE__, __FILE__));
449  if(state!=0) {
451  SetEventSource(state->GetSourcePar());
452  SetEventStore(state->GetStorePar());
457  fbErrorStopped=kFALSE; // reset run status parameters to default
458  fiProcessStatus=0; // dito
459  }
460 }
461 
463 {
464  if(kind==fxProcessorType) return; // avoid deleting valid parameter
465  if(fxProcessorType) delete fxProcessorType;
466  if(kind)
467  fxProcessorType=dynamic_cast<TGo4EventProcessorParameter*>(kind->Clone());
468  else
469  fxProcessorType=0;
470 }
471 
473 {
474  if(kind==fxSourceType) return; // avoid deleting valid parameter
475  if(fxSourceType) delete fxSourceType;
476  if(kind)
477  fxSourceType=dynamic_cast<TGo4EventSourceParameter*>(kind->Clone());
478  else
479  fxSourceType=0;
480 }
481 
483 {
484  return fxSourceType!=0;
485 }
486 
488 {
489  if(kind==fxStoreType) return; // avoid deleting valid parameter
490  if(fxStoreType) delete fxStoreType;
491  if(kind)
492  fxStoreType=dynamic_cast<TGo4EventStoreParameter*>(kind->Clone());
493  else
494  fxStoreType=0;
495  if(fxStoreType)
496  fxStoreType->SetTitle(GetName());
497  // set title of eventstore parameter to analysis step name
498  // this might be used to indicate tree name
499 }
500 
502 {
503  return fxStoreType!=0;
504 }
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()