GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
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"
22
26
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...
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
111 fxInputEvent->SetEventSource(fxEventSource);
112 if(!fxEventProcessor->IsKeepInputEvent())
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
121 if(!fxEventProcessor->IsKeepInputEvent())
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) {
127 fxOutputEvent->SetEventSource(fxEventProcessor);
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
133 fxOwner->SetOutputEvent(fxOutputEvent);
134 if(fbStoreEnabled && fxEventStore && fxOutputEvent->IsValid() && !fxEventProcessor->IsKeepOutputEvent())
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__));
150}
151
153{
154 GO4TRACE((14,"TGo4AnalysisStep::CloseEventStore()",__LINE__, __FILE__));
155 if(fxEventStore) {
156 TTree *atree = fxEventStore->GetTree();
157 fxOwner->RemoveTree(atree);
158 fxOwner->RemoveEventStore(fxEventStore);
159 delete fxEventStore;
160 fxEventStore = nullptr;
161 fbStoreImplemented=kFALSE;
162 }
163}
164
165
167{
168 GO4TRACE((14,"TGo4AnalysisStep::CloseEventSource()",__LINE__, __FILE__));
169 if(fxEventSource) {
170 fxOwner->RemoveEventSource(fxEventSource);
171 delete fxEventSource;
172 fxEventSource = nullptr;
173 fbSourceImplemented=kFALSE;
174 }
175}
176
178{
179 GO4TRACE((14,"TGo4AnalysisStep::CloseEventProcessor()",__LINE__, __FILE__));
180 if(fxEventProcessor) {
181 fxOwner->RemoveEventProcessor(fxEventProcessor);
182 delete fxEventProcessor;
183 fxEventProcessor = nullptr;
184 }
185}
186
188{
189 GO4TRACE((14,"TGo4AnalysisStep::DeleteInputEvent()",__LINE__, __FILE__));
190 if(fxInputEvent) {
191 fxOwner->RemoveEventStructure(fxInputEvent);
192 delete fxInputEvent;
193 fxInputEvent = nullptr;
194 }
195}
196
198{
199 GO4TRACE((14,"TGo4AnalysisStep::DeleteOutputEvent()",__LINE__, __FILE__));
200 if(fxOutputEvent) {
201 fxOwner->RemoveEventStructure(fxOutputEvent);
202 delete fxOutputEvent;
203 fxOutputEvent = nullptr;
204 }
205}
206
208{
209 GO4TRACE((14,"TGo4AnalysisStep::StoreCalibration()",__LINE__, __FILE__));
210 TGo4EventCalibration* cali = nullptr;
212 cali = fxEventProcessor->GetCalibration();
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
238Int_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 {
292 fxEventSource = fxEventFactory->CreateEventSource(kind);
293 } // if(evstorename!= ... )
294 } else {
295 fxEventSource=fxEventFactory->CreateEventSource(kind);
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) {
304 fxOwner->AddEventSource(fxEventSource); // reference to eventsource class
305 // we have to set reference to new source in input event:
306 if(fxInputEvent) {
307 fxInputEvent->SetEventSource(fxEventSource);
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__));
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
336 fxEventStore = fxEventFactory->CreateEventStore(kind);
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...
365 fxEventProcessor=fxEventFactory->CreateEventProcessor(kind);
366 fxOwner->AddEventProcessor(fxEventProcessor);
368 fxEventProcessor->SetInputEvent(fxInputEvent);
369 // method of processor might init the types here...
370 if(fxOutputEvent) {
371 fxOutputEvent->SetEventSource(fxEventProcessor);
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 }
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) {
410 fxInputEvent = fxEventFactory->CreateInputEvent();
411 fxOwner->AddEventStructure(fxInputEvent);
412 if(fxInputEvent) {
413 fxInputEvent->SetEventSource(fxEventSource);
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) {
426 fxOutputEvent=fxEventFactory->CreateOutputEvent();
427 fxOwner->AddEventStructure(fxOutputEvent);
428 if(fxOutputEvent) {
429 fxOutputEvent->SetEventSource(fxEventProcessor);
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) {
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
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}
#define GO4TRACE(X)
Definition TGo4Log.h:25
Status object of one analysis step.
void SetErrorStopEnabled(Bool_t on=kTRUE)
Enables or disables the stop-on-error mode.
void SetProcessStatus(Int_t val)
Sets status value of processor, user defined.
void SetSourceEnabled(Bool_t on=kTRUE)
Enables or disables the event source.
void SetErrorStopped(Bool_t on)
Enables or disables the stop-on-error mode.
TGo4EventSourceParameter * GetSourcePar() const
Returns the event source parameter which was put into this status object.
TGo4EventProcessorParameter * GetProcessorPar() const
Returns the event processor parameter which was put into this status object.
Bool_t IsErrorStopEnabled() const
True if analysis step shall stop on error.
void SetStorePar(TGo4EventStoreParameter *kind)
Sets the event store parameter which is used on intitialization of this step.
void SetProcessorPar(TGo4EventProcessorParameter *kind)
Sets the event processor parameter which is used on intitialization of this step.
TGo4EventStoreParameter * GetStorePar() const
Returns the event store parameter which was put into this status object.
void SetStoreEnabled(Bool_t on=kTRUE)
Enables or disables the event store.
void SetProcessEnabled(Bool_t on=kTRUE)
Enables or disables the event processing.
void SetSourcePar(TGo4EventSourceParameter *kind)
Sets the event source parameter which is used on intitialization of this step.
void SetErrorStopEnabled(Bool_t on)
Enables or disables the stop-on-error mode.
void NewInputEvent()
create input event object
Bool_t fbErrorStopEnabled
Operation mode switch.
void SetStatusMessage(const char *txt)
Set Status message of last Process() call.
Int_t Store(TGo4Parameter *cali)
Saves a parameter correlated with the current event into the storage.
void SetProcessEnabled(Bool_t on=kTRUE)
Enables or disables the event processing.
TGo4EventElement * fxOutputEvent
The unpacked event (detector) structure that has been filled by the analysis step .
void SetStoreEnabled(Bool_t on=kTRUE)
Enables or disables the event store.
void Close()
Closes the analysis step.
TGo4Analysis * fxOwner
Points back to the analysis which keeps this step.
void StoreCalibration()
Store the current calibration object of the event processor into the event store instance.
virtual void InitEventClasses()
Initialization of the event class plugins which are delivered from the user defined event factory.
TGo4EventStore * fxEventStore
The storage instance for the unpacked events (detector) structures.
Bool_t fbSourceImplemented
Flag for the previous analysis step.
void DeleteOutputEvent()
Delete input event object.
Bool_t fbProcessEnabled
Enables processing of the input event.
void NewEventProcessor(TGo4EventProcessorParameter *kind)
For lazy initialization of event processor.
void NewEventSource(TGo4EventSourceParameter *kind)
For lazy initialization of event source.
void CloseEventStore()
Unregister and close eventstore, if existing.
void DeleteInputEvent()
Delete input event object.
TGo4AnalysisStepStatus * CreateStatus()
Create a copy of the analysis step internal state.
void SetEventProcessor(TGo4EventProcessorParameter *kind)
Sets the event processor parameter which is used on initialization of this step.
TGo4EventElement * fxInputEvent
points to the last input event delivered from the event source 1 aggregation
void CloseEventProcessor()
Unregister and close eventprocessor, if existing.
TGo4EventStoreParameter * fxStoreType
Parameter object of next event storage to be activated.
Bool_t IsProcessEnabled() const
void Process()
The main analysis action which is invoked by the external go4 analysis.
Bool_t IsEventStoreParam() const
Return kTRUE, if event store parameter specified.
void CloseEventSource()
Unregister and close eventsource, if existing.
Int_t fiProcessStatus
Contains current analysis step status value.
void NewOutputEvent()
create input event object
TGo4EventProcessor * fxEventProcessor
The processing class which works on the input event and fills the output event.
TGo4EventProcessorParameter * fxProcessorType
Parameter object of next event processor to be activated.
TGo4AnalysisStep * fxPrevious
Points to the previous analysis step.
void SetEventSource(TGo4EventSourceParameter *kind)
Sets the event source parameter which is used on initialization of this step.
const char * GetEventStoreName() const
Access to name of currently active event store.
void SetStatus(TGo4AnalysisStepStatus *state)
Set all analysis step parameters to that of given status object.
TGo4EventSourceParameter * fxSourceType
Parameter object of next event source to be activated.
const char * GetEventSourceName() const
Access to name of currently active event source.
Bool_t fbSourceEnabled
Enables event source.If true, the event source is used to get the input event; otherwise we use the o...
Bool_t IsEventSourceParam() const
Return kTRUE, if event source parameter specified.
void NewEventStore(TGo4EventStoreParameter *kind)
For lazy initialization of event store.
Bool_t fbErrorStopped
True if the analysis step has been stopped after input error.
Bool_t fbStoreEnabled
Enables event store.
Bool_t IsMatchingPrevious() const
Check if an analysis step is matching as a previous step to this step.
TGo4EventFactory * fxEventFactory
The abstract factory implementation which provides the event classes.
void SetSourceEnabled(Bool_t on=kTRUE)
Enables or disables the event source.
void SetEventStore(TGo4EventStoreParameter *kind)
Sets the event store parameter which is used on initialization of this step.
TGo4AnalysisStep()
default ctor for streamer.
Bool_t fbStoreImplemented
Flag for the subsequent analysis step.
TGo4EventSource * fxEventSource
The source of the input events.
static TGo4Analysis * Instance()
return analysis instance
void Message(Int_t prio, const char *text,...)
Display a user message.
Go4 condition class.
Data object for calibration of the input event.
The abstract base class for the data elements of which the unpacked events (or detector structure dat...
Abstract factory for the event related classes.
Basic type for all classes containing information to parametrize the event processor.
Basic type for all classes containing information to parameterize the event source.
Basic type for all classes containing information to parametrize the event store.
Central class of Go4Fit package.
Definition TGo4Fitter.h:38
Base class for all parameter aggregations, e.g.