GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4AnalysisStepManager.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
15
16#include "TObjArray.h"
17
18#include "TGo4Log.h"
19#include "TGo4MainTree.h"
20#include "TGo4AnalysisStep.h"
21
23#include "TGo4AnalysisStatus.h"
24#include "TGo4AnalysisImp.h"
25#include "TGo4EventProcessor.h"
26
28 TNamed(name,"The Go4 Analysis Step Manager"),
32 fbStepCheckingMode(kTRUE),
33 fxCurrentStep(nullptr),
34 fxOutputEvent(nullptr)
35{
36 fxStepList = new TObjArray;
37 fxStepIterator = fxStepList->MakeIterator();
38}
39
45
47{
48 GO4TRACE((14,"TGo4AnalysisStepManager::CloseAnalysis()",__LINE__, __FILE__));
49 //
50 TGo4Log::Debug("Analysis Step Manager -- closing analysis steps...");
51 TGo4AnalysisStep *step = nullptr;
52 fxStepIterator->Reset();
53 while((step= dynamic_cast<TGo4AnalysisStep *>( fxStepIterator->Next() ) ) != nullptr)
54 {
55 step->Close();
56 }
57 TGo4Log::Debug("Analysis Step Manager -- analysis steps were closed.");
58}
59
61{
62 GO4TRACE((14,"TGo4AnalysisStepManager::InitEventClasses()",__LINE__, __FILE__));
63 //
64 Bool_t rev = kTRUE;
65 Bool_t firststepfound = kFALSE;
66 Bool_t laststepfound = kFALSE;
67 TGo4Log::Debug("Analysis StepManager -- Initializing EventClasses...");
68 TGo4AnalysisStep *step = nullptr;
69 fxStepIterator->Reset();
71 while((step = dynamic_cast<TGo4AnalysisStep *>(fxStepIterator->Next())) != nullptr)
72 {
73 step->InitEventClasses();
74 // last enabled step:
75 // for step checking off, take last step in list
76 if(firststepfound)
77 {
78 if((IsStepChecking() && step->IsProcessEnabled())
79 || !IsStepChecking())
80 {
82 laststepfound=kTRUE;
83 }
84 }
85 // first enabled step is first step of chain:
86 // except for step checking is off, then take first
87 if(!firststepfound)
88 {
89 if((IsStepChecking() && step->IsProcessEnabled())
90 || !IsStepChecking())
91 {
93 firststepfound=kTRUE;
94 }
95 }
97 }
98 if(!laststepfound) fiLastStepIndex=fiFirstStepIndex; // for single step analysis
99
100 if(IsStepChecking())
101 {
102 // Test for steps valid:
103 fxStepIterator->Reset();
105 while((step = dynamic_cast<TGo4AnalysisStep *>(fxStepIterator->Next())) != nullptr)
106 {
107 if(! step->IsMatchingPrevious() )
108 {
109 rev = kFALSE;
110 TGo4Analysis::Instance()->Message(3,"!!! AnalysisStepManager -- ERROR: step %s is not matching previous !!!",
111 step->GetName() );
112 break;
113 }
114 else
115 {
116 rev = kTRUE;
117 }
118 } // while
119 }//if(IsStepChecking())
120
121 TGo4Log::Debug("AnalysisStepManager -- Initializing EventClasses done.");
122 return rev;
123}
124
126{
127 GO4TRACE((12,"TGo4AnalysisStepManager::SetFirstStep(const char *)",__LINE__, __FILE__));
128 //
129 Bool_t result = kFALSE;
130 if (!name) {
131 // reset to defaults:
132 fiFirstStepIndex = 0; // beginning of steplist
133 TGo4Analysis::Instance()->Message(0, "Analysis: Setting first step to beginning of steplist");
134 result = kTRUE;
135 } else {
136 TObject *obj = fxStepList->FindObject(name);
137 if (!obj) {
138 result = kFALSE;
139 TGo4Analysis::Instance()->Message(3, "!!! Analysis: SetFirstStep ERROR - no such step %s", name);
140 } else {
141 Int_t ix = fxStepList->IndexOf(obj);
142 if (ix <= fiLastStepIndex) {
143 fiFirstStepIndex = ix;
144 TGo4Analysis::Instance()->Message(0, "Analysis: Setting first step to %s", name);
145 } else {
147 TGo4Analysis::Instance()->Message(0, "Analysis: Range WARNING - Setting first step to last step");
148 }
149
150 result = kTRUE;
151 }
152 }
153 return result;
154}
155
157{
158 GO4TRACE((12,"TGo4AnalysisStepManager::SetLastStep(const char *)",__LINE__, __FILE__));
159 //
160 Bool_t result=kTRUE;
161 if(!name) {
162 // reset to defaults:
163 fiLastStepIndex = fxStepList->GetLast(); // end of steplist
164 if(fiLastStepIndex < 0)
165 fiLastStepIndex = 0; // case of empty steplist
166 TGo4Analysis::Instance()->Message(0,"Analysis: Setting last step to end of steplist");
167
168 result = kTRUE;
169 } else {
170 TObject *obj = fxStepList->FindObject(name);
171 if(!obj) {
172 result=kFALSE;
173 TGo4Analysis::Instance()->Message(3,"!!! Analysis: SetLastStep ERROR - no such step %s",
174 name);
175
176 } else {
177 Int_t ix=fxStepList->IndexOf(obj);
178 if(ix >= fiFirstStepIndex) {
180 TGo4Analysis::Instance()->Message(0,"Analysis: Setting last step to %s",
181 name);
182 } else {
184 TGo4Analysis::Instance()->Message(0," Analysis: Range WARNING - Setting last step to first step");
185
186 }
187
188 result=kTRUE;
189 }
190
191
192 }
193 return result;
194}
195
196Bool_t TGo4AnalysisStepManager::SetStepStorage(const char *name, Bool_t on)
197{
198 GO4TRACE((12,"TGo4AnalysisStepManager::SetStepStorage(const char *, Bool_t)",__LINE__, __FILE__));
199 Bool_t result = kFALSE;
200 TGo4AnalysisStep *step = GetAnalysisStep(name);
201 if (step) {
202 step->SetStoreEnabled(on);
203 result = kTRUE;
204 } else {
205 result = kFALSE;
206 }
207
208 return result;
209}
210
212{
213 GO4TRACE((12,"TGo4AnalysisStepManager::NewStepStore(const char *, TGo4EventStoreParameter *)",__LINE__, __FILE__));
214 Bool_t result=kFALSE;
215 TGo4AnalysisStep *step = nullptr;
216
217 if(!name) {
218 // zero name: use last step
219 step = dynamic_cast<TGo4AnalysisStep *> (fxStepList->At(fiLastStepIndex));
220 } else {
221 // step specified by name:
222 step=GetAnalysisStep(name);
223 }
224
225 if(step) {
226 //step->SetEventStore(par); // remember parameter for next init
227 step->NewEventStore(par); // create new store now
228 result=kTRUE;
229 } else {
230 result=kFALSE;
231 }
232
233 return result;
234}
235
237{
238 GO4TRACE((12,"TGo4AnalysisStepManager::NewStepSource(const char *, TGo4EventSourceParameter *)",__LINE__, __FILE__));
239 Bool_t result=kFALSE;
240 TGo4AnalysisStep *step = nullptr;
241 if(!name) {
242 // zero name: use first step
243 step = dynamic_cast<TGo4AnalysisStep *> (fxStepList->At(fiFirstStepIndex));
244 } else {
245 // step specified by name:
246 step = GetAnalysisStep(name);
247 }
248
249 if(step) {
250 //step->SetEventSource(par); // remember parameter for next init
251 step->NewEventSource(par); // delete old, and create the new source now
252 result = kTRUE;
253 } else {
254 result = kFALSE;
255 }
256 return result;
257}
258
260{
261 GO4TRACE((12,"TGo4AnalysisStepManager::NewStepProcessor(const char *, TGo4EventProcessorParameter *)",__LINE__, __FILE__));
262 Bool_t result = kFALSE;
263 TGo4AnalysisStep *step = GetAnalysisStep(name);
264 if(step) {
265 //step->SetEventProcessor(par); // remember parameter for next init
266 step->NewEventProcessor(par); // create processor now
267 result=kTRUE;
268 } else {
269 result=kFALSE;
270 }
271 return result;
272}
273
275{
277 return step ? step->Store(par) : 1;
278}
279
281{
283 return step ? step->Store(con) : 1;
284}
285
286Int_t TGo4AnalysisStepManager::Store(const char *name, TGo4Fitter *fit)
287{
289 return step ? step->Store(fit) : 1;
290}
291
292Int_t TGo4AnalysisStepManager::Store(const char *name, TFolder *folder)
293{
294 TGo4AnalysisStep *step = GetAnalysisStep(name);
295 return step ? step->Store(folder) : 1;
296}
297
299{
300 GO4TRACE((11,"TGo4AnalysisStepManager::GetInputEvent(Int_t)",__LINE__, __FILE__));
301 TGo4EventElement *rev = nullptr;
302 TGo4AnalysisStep *step = GetAnalysisStep(stepname);
303 if(step) {
305 if(pro) rev = pro->GetInputEvent(); // get true input event
306 } else {
307 rev = nullptr;
308 }
309 return rev;
310}
311
313{
314 GO4TRACE((11,"TGo4AnalysisStepManager::GetInputEvent(Int_t)",__LINE__, __FILE__));
315 TGo4EventElement *rev = nullptr;
316 TGo4AnalysisStep *step = dynamic_cast<TGo4AnalysisStep *> (fxStepList->At(stepindex));
317 if(step) {
319 if(pro) rev = pro->GetInputEvent(); // get true input event
320 //rev=step->GetInputEvent();
321 } else {
322 rev = nullptr;
323 }
324 return rev;
325}
326
328{
329 GO4TRACE((11,"TGo4AnalysisStepManager::GetOutputEvent(const char *)",__LINE__, __FILE__));
330 TGo4EventElement *rev = nullptr;
331 TGo4AnalysisStep *step=GetAnalysisStep(stepname);
332 if(step) {
333 rev = step->GetOutputEvent();
334 } else {
335 rev = nullptr;
336 }
337 return rev;
338}
339
341{
342 GO4TRACE((11,"TGo4AnalysisStepManager::GetOutputEvent(Int_t)",__LINE__, __FILE__));
343 TGo4EventElement *rev = nullptr;
344 TGo4AnalysisStep *step = nullptr;
345 step= dynamic_cast<TGo4AnalysisStep *> ( fxStepList->At(stepindex) );
346 if(step) {
347 rev=step->GetOutputEvent();
348 } else {
349 rev = nullptr;
350 }
351 return rev;
352}
353
355{
356 GO4TRACE((14,"TGo4AnalysisStepManager::AddAnalysisStep(TGo4AnalysisStep *)",__LINE__, __FILE__));
357 //
358 Bool_t rev = kFALSE;
359 if (next) {
360 if(!fxStepList->FindObject(next))
361 // is object already in list?
362 {
363 //no, add the new object
364 GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Adding new analysis step",__LINE__, __FILE__));
365 fxStepList->AddLast(next);
366 // set previous step:
367 Int_t ix=fxStepList->IndexOf(next);
368 if(ix>0)
369 {
370 TGo4AnalysisStep *previous= dynamic_cast<TGo4AnalysisStep *> ( fxStepList->At(ix-1) );
371 next->SetPreviousStep(previous);
372 }
373 else
374 {
375 next->SetPreviousStep(nullptr);
376 }
377 fiLastStepIndex = ix;
378 rev = kTRUE;
379 TGo4Analysis::Instance()->Message(1,"Analysis: Added analysis step %s",
380 next->GetName());
381 }
382 else
383 {
384 // yes, do nothing
385 GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Analysis step was already there",__LINE__, __FILE__));
386 rev=kFALSE;
387 TGo4Analysis::Instance()->Message(2,"Analysis: WARNING - analysis step %s was already in steplist",
388 next->GetName() );
389 }
390 } // if(next)
391 else
392 {
393 GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Zero Analysis step pointer",__LINE__, __FILE__));
394 rev=kFALSE;
395 TGo4Analysis::Instance()->Message(2,"Analysis: WARNING - did not add zero analysis step pointer to steplist");
396 }
397 return rev;
398}
399
401{
402 GO4TRACE((11,"TGo4AnalysisStepManager::GetAnalysisStep(const char *)",__LINE__, __FILE__));
403 TGo4AnalysisStep *step = nullptr;
404 if(!name)
405 step = dynamic_cast<TGo4AnalysisStep *>(fxStepList->At(fiFirstStepIndex));
406 else
407 step = dynamic_cast<TGo4AnalysisStep *>(fxStepList->FindObject(name));
408 return step;
409}
410
412{
413 return fxStepList ? fxStepList->GetLast() + 1 : 0;
414}
415
417{
418 GO4TRACE((11,"TGo4AnalysisStepManager::GetAnalysisStepNum(Int_t)",__LINE__, __FILE__));
419 if ((number < 0) || (number > fxStepList->GetLast())) return nullptr;
420 return dynamic_cast<TGo4AnalysisStep *>(fxStepList->At(number));
421}
422
423
425{
426 GO4TRACE((11,"TGo4AnalysisStepManager::ProcessAnalysisSteps()",__LINE__, __FILE__));
427 //
428 fxCurrentStep = nullptr;
430 Bool_t isfirststep = kTRUE;
431 // first evaluate actual beginning index for "keep input event" mode:
432 Int_t repeatinputstart=-1;
435 if(fxCurrentStep->IsKeepInputEvent()) {
436 repeatinputstart = fiCurrentStepIndex;
437 break;
438 }
439 }
440
441 SetOutputEvent(nullptr); // make sure that first step wont take output of last one
444 if(!fxCurrentStep) break;
445 if(IsStepChecking() && isfirststep ) {
446 // check first step source:
447 isfirststep = kFALSE;
448 if(fxCurrentStep->IsSourceImplemented())
449 fxCurrentStep->SetSourceEnabled();
450 else {
451 fxCurrentStep->SetStatusMessage("!!! No Event Source for first analysis step !!!");
453 }
454 }
455 if(fiCurrentStepIndex<repeatinputstart) continue; // skip steps before a step which is reprocessing same input event
456
457 fxCurrentStep->Process();
458
459 if(fxCurrentStep->IsKeepOutputEvent()) break; // skip all steps after incomplete output event
460 } // for(...)
461 // finally, we update maintree header if the steps use treesource/store instances:
463 return 0;
464}
465
467{
468 GO4TRACE((11,"TGo4AnalysisStepManager::UpdateStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
469 if(state) {
473 fxCurrentStep = nullptr;
474 fxStepIterator->Reset();
475 state->ClearStepStatus();
476 while((fxCurrentStep = dynamic_cast<TGo4AnalysisStep *>(fxStepIterator->Next())) != nullptr) {
477 TGo4AnalysisStepStatus* stepstate = fxCurrentStep->CreateStatus();
478 state->AddStepStatus(stepstate);
479 }
480 }
481}
482
484{
485 GO4TRACE((11,"TGo4AnalysisStepManager::SetStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
486 if(state) {
490 // note: the step indices are not used for
491 // initialization of analysis any more!
492 // update internal states of steps:
493 fxCurrentStep = nullptr;
494 fxStepIterator->Reset();
495 while((fxCurrentStep = dynamic_cast<TGo4AnalysisStep *>(fxStepIterator->Next())) != nullptr) {
496 const char *name = fxCurrentStep->GetName();
497 TGo4AnalysisStepStatus *stepstate = state->GetStepStatus(name);
498 fxCurrentStep->SetStatus(stepstate);
499 }
500 }
501}
502
504{
505 GO4TRACE((12,"TGo4AnalysisStepManager::AutoSave()",__LINE__, __FILE__));
506 //
507 //TGo4LockGuard autoguard(fxAutoSaveMutex);
508 TGo4Analysis::Instance()->Message(0,"Analysis Step Manager -- AutoSaving....");
509 TGo4AnalysisStep *step = nullptr;
510 fxStepIterator->Reset();
511 while((step = dynamic_cast<TGo4AnalysisStep *>(fxStepIterator->Next())) != nullptr) {
512 step->StoreCalibration();
513 }
514
515 // write maintree to file if existing...
518 }
519}
520
522{
523 return kTRUE; // FIXME: workaround, to be removed later!!! JA
524
525 // return fxCurrentStep ? fxCurrentStep->IsErrorStopEnabled() : kTRUE;
526}
#define GO4TRACE(X)
Definition TGo4Log.h:25
Status of the analysis instance.
void SetFirstStepIndex(Int_t i)
void SetLastStepIndex(Int_t i)
Int_t IsStepChecking() const
Int_t GetFirstStepIndex() const
void SetStepChecking(Int_t on)
Bool_t AddStepStatus(TGo4AnalysisStepStatus *next)
Add new step status object to analysis status.
Int_t GetLastStepIndex() const
void ClearStepStatus()
Clear all existing step status objects.
TGo4AnalysisStepStatus * GetStepStatus(const char *name)
Access to certain analysis step status by name.
Int_t GetNumberOfAnalysisSteps() const
Returns number of analysis steps.
TGo4EventElement * GetInputEvent(const char *stepname) const
Returns the input event structure of analysis step.
TObjArray * fxStepList
Array containing all analysis steps.
TGo4AnalysisStep * GetAnalysisStepNum(Int_t number) const
Access to certain analysis step by number.
void AutoSave()
Save step specific parts.
Bool_t SetStepStorage(const char *name, Bool_t on)
Enables analysis step of name to write its output event into its event store.
Bool_t fbStepCheckingMode
True if chain of steps is checked for consistency of input and output events.
TIterator * fxStepIterator
Iterator used for analysis step list.
Int_t fiLastStepIndex
Index describing the last analysis step from the steplist to be processed.
void SetOutputEvent(TGo4EventElement *event)
Int_t Store(const char *name, TGo4Parameter *obj)
Write object obj into eventstore of the step specified by name.
Bool_t NewStepProcessor(const char *name, TGo4EventProcessorParameter *par)
Shuts down the old analysis step processor and creates a new one specified by parameter par.
TGo4AnalysisStep * GetAnalysisStep(const char *name) const
Access to certain analysis step by name.
void SetStatus(TGo4AnalysisStatus *state)
Set step specific part of analysis status object to steplist.
Bool_t SetLastStep(const char *name)
Sets analysis step name as last one to be processed in the chain of steps.
TGo4AnalysisStepManager(const char *name)
Bool_t AddAnalysisStep(TGo4AnalysisStep *next)
Method for user analysis constructor to setup the list of analysis steps.
void UpdateStatus(TGo4AnalysisStatus *state)
Update step specific part of analysis status object.
TGo4AnalysisStep * fxCurrentStep
Points to the currently active analysis step.
Bool_t SetFirstStep(const char *name)
Sets analysis step name as first one to be processed in the chain of steps.
Int_t fiFirstStepIndex
Index describing the first analysis step from the steplist to be processed.
virtual Bool_t InitEventClasses()
Initialization of the event class plugins which are delivered from the user defined event factory.
Int_t ProcessAnalysisSteps()
Uses the chain of analysis steps to process the first input event into an output event which then is ...
TGo4EventElement * GetOutputEvent() const
Returns the output event (detector) structure of analysis step.
Int_t fiCurrentStepIndex
Index describing the current analysis step.
void CloseAnalysis()
Finish the analysis run and close all event sources/storages.
Bool_t NewStepStore(const char *name, TGo4EventStoreParameter *par)
Shuts down the old analysis step storage and creates a new one specified by parameter par.
Bool_t NewStepSource(const char *name, TGo4EventSourceParameter *par)
Shuts down the old analysis step event source and creates a new one specified by parameter par.
TGo4EventElement * fxOutputEvent
Link to the last output event produced by the event analysis steps.
Status object of one analysis step.
Contains a single step of the analysis.
Int_t Store(TGo4Parameter *cali)
Saves a parameter correlated with the current event into the storage.
void SetStoreEnabled(Bool_t on=kTRUE)
Enables or disables the event store.
void Close()
Closes the analysis 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.
void NewEventProcessor(TGo4EventProcessorParameter *kind)
For lazy initialization of event processor.
void NewEventSource(TGo4EventSourceParameter *kind)
For lazy initialization of event source.
void SetPreviousStep(TGo4AnalysisStep *pre)
Sets reference to previous analysis step.
Bool_t IsProcessEnabled() const
TGo4EventProcessor * GetEventProcessor() const
Access to the event processor.
TGo4EventElement * GetOutputEvent() const
Access to the output event which has been filled last.
void NewEventStore(TGo4EventStoreParameter *kind)
For lazy initialization of event store.
Bool_t IsMatchingPrevious() const
Check if an analysis step is matching as a previous step to this step.
static TGo4Analysis * Instance()
return analysis instance
void Message(Int_t prio, const char *text,...)
Display a user message.
Go4 condition class.
The abstract base class for the data elements of which the unpacked events (or detector structure dat...
Basic type for all classes containing information to parametrize the event processor.
Abstract event processor.
TGo4EventElement * GetInputEvent()
Access to external raw event which is set as association member.
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
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Definition TGo4Log.cxx:281
Int_t Write(const char *dummy=nullptr, Int_t option=0, Int_t bufsize=0) override
Write tree content to file.
static TGo4MainTree * Instance()
static Bool_t Exists()
True if instance of tree already exists.
void Update()
Update the tree entry information without processing any branch.
Base class for all parameter aggregations, e.g.