00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4AnalysisStepManager.h"
00015
00016 #include "TObjArray.h"
00017 #include "TFolder.h"
00018 #include "TList.h"
00019 #include "TThread.h"
00020 #include "TH1.h"
00021 #include "TTree.h"
00022
00023 #include "TGo4Log.h"
00024 #include "TGo4LockGuard.h"
00025 #include "TGo4Condition.h"
00026 #include "TGo4MainTree.h"
00027 #include "TGo4AnalysisStep.h"
00028 #include "TGo4TreeStructure.h"
00029
00030 #include "TGo4AnalysisStepException.h"
00031 #include "TGo4AnalysisStatus.h"
00032 #include "TGo4AnalysisImp.h"
00033 #include "TGo4EventErrorException.h"
00034 #include "TGo4EventProcessor.h"
00035 #include "TGo4EventTimeoutException.h"
00036 #include "TGo4CompositeEvent.h"
00037 #include "TGo4BackStore.h"
00038
00039 TGo4AnalysisStepManager::TGo4AnalysisStepManager(const char* name) :
00040 TNamed(name,"The Go4 Analysis Step Manager"),
00041 fiFirstStepIndex(0),
00042 fiLastStepIndex(0),
00043 fiCurrentStepIndex(0),
00044 fbStepCheckingMode(kTRUE),
00045 fxCurrentStep(0),
00046 fxOutputEvent(0)
00047 {
00048 fxStepList = new TObjArray;
00049 fxStepIterator = fxStepList->MakeIterator();
00050 }
00051
00052 TGo4AnalysisStepManager::~TGo4AnalysisStepManager()
00053 {
00054 delete fxStepIterator;
00055 delete fxStepList;
00056 }
00057
00058 void TGo4AnalysisStepManager::CloseAnalysis()
00059 {
00060 GO4TRACE((14,"TGo4AnalysisStepManager::CloseAnalysis()",__LINE__, __FILE__));
00061
00062 TGo4Log::Debug("Analysis Step Manager -- closing analysis steps...");
00063 TGo4AnalysisStep* step=0;
00064 fxStepIterator->Reset();
00065 while((step= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
00066 {
00067 step->Close();
00068 }
00069 TGo4Log::Debug("Analysis Step Manager -- analysis steps were closed.");
00070 }
00071
00072 Bool_t TGo4AnalysisStepManager::InitEventClasses()
00073 {
00074 GO4TRACE((14,"TGo4AnalysisStepManager::InitEventClasses()",__LINE__, __FILE__));
00075
00076 Bool_t rev=kTRUE;
00077 Bool_t firststepfound=kFALSE;
00078 Bool_t laststepfound=kFALSE;
00079 TGo4Log::Debug("Analysis StepManager -- Initializing EventClasses...");
00080 TGo4AnalysisStep* step=0;
00081 fxStepIterator->Reset();
00082 fiCurrentStepIndex=0;
00083
00084 while((step= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
00085 {
00086 step->InitEventClasses();
00087
00088
00089 if(firststepfound)
00090 {
00091 if((IsStepChecking() && step->IsProcessEnabled())
00092 || !IsStepChecking())
00093 {
00094 fiLastStepIndex=fiCurrentStepIndex;
00095 laststepfound=kTRUE;
00096 }
00097 }
00098
00099
00100 if(!firststepfound)
00101 {
00102 if((IsStepChecking() && step->IsProcessEnabled())
00103 || !IsStepChecking())
00104 {
00105 fiFirstStepIndex=fiCurrentStepIndex;
00106 firststepfound=kTRUE;
00107 }
00108 }
00109 fiCurrentStepIndex++;
00110 }
00111 if(!laststepfound) fiLastStepIndex=fiFirstStepIndex;
00112
00113 if(IsStepChecking())
00114 {
00115
00116 fxStepIterator->Reset();
00117 fiCurrentStepIndex=0;
00118 while((step= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
00119 {
00120
00121 if(! step->IsMatchingPrevious() )
00122 {
00123 rev=kFALSE;
00124 TGo4Analysis::Instance()->Message(3,"!!! AnalysisStepManager -- ERROR: step %s is not matching previous !!!",
00125 step->GetName() );
00126 break;
00127 }
00128 else
00129 {
00130 rev=kTRUE;
00131 }
00132 }
00133 }
00134
00135 TGo4Log::Debug("AnalysisStepManager -- Initializing EventClasses done.");
00136 return rev;
00137 }
00138
00139 Bool_t TGo4AnalysisStepManager::SetFirstStep(const char* name)
00140 {
00141 GO4TRACE((12,"TGo4AnalysisStepManager::SetFirstStep(const char*)",__LINE__, __FILE__));
00142
00143 Bool_t result=kFALSE;
00144 if(name==0) {
00145
00146 fiFirstStepIndex=0;
00147 TGo4Analysis::Instance()->Message(0,"Analysis: Setting first step to beginning of steplist");
00148 result=kTRUE;
00149 } else {
00150 TObject* obj=fxStepList->FindObject(name);
00151 if(obj==0) {
00152 result=kFALSE;
00153 TGo4Analysis::Instance()->Message(3,"!!! Analysis: SetFirstStep ERROR - no such step %s",
00154 name);
00155 } else {
00156 Int_t ix=fxStepList->IndexOf(obj);
00157 if(ix <= fiLastStepIndex)
00158 {
00159 fiFirstStepIndex=ix;
00160 TGo4Analysis::Instance()->Message(0,"Analysis: Setting first step to %s",
00161 name);
00162 }
00163 else
00164 {
00165 fiFirstStepIndex=fiLastStepIndex;
00166 TGo4Analysis::Instance()->Message(0,"Analysis: Range WARNING - Setting first step to last step");
00167 }
00168
00169 result=kTRUE;
00170 }
00171
00172 }
00173 return result;
00174 }
00175
00176 Bool_t TGo4AnalysisStepManager::SetLastStep(const char* name)
00177 {
00178 GO4TRACE((12,"TGo4AnalysisStepManager::SetLastStep(const char*)",__LINE__, __FILE__));
00179
00180 Bool_t result=kTRUE;
00181 if(name==0) {
00182
00183 fiLastStepIndex=fxStepList->GetLast() ;
00184 if(fiLastStepIndex<0)
00185 fiLastStepIndex=0;
00186 TGo4Analysis::Instance()->Message(0,"Analysis: Setting last step to end of steplist");
00187
00188 result=kTRUE;
00189 } else {
00190 TObject* obj=fxStepList->FindObject(name);
00191 if(obj==0) {
00192 result=kFALSE;
00193 TGo4Analysis::Instance()->Message(3,"!!! Analysis: SetLastStep ERROR - no such step %s",
00194 name);
00195
00196 } else {
00197 Int_t ix=fxStepList->IndexOf(obj);
00198 if(ix >= fiFirstStepIndex) {
00199 fiLastStepIndex=ix;
00200 TGo4Analysis::Instance()->Message(0,"Analysis: Setting last step to %s",
00201 name);
00202 } else {
00203 fiLastStepIndex=fiFirstStepIndex;
00204 TGo4Analysis::Instance()->Message(0," Analysis: Range WARNING - Setting last step to first step");
00205
00206 }
00207
00208 result=kTRUE;
00209 }
00210
00211
00212 }
00213 return result;
00214 }
00215
00216 Bool_t TGo4AnalysisStepManager::SetStepStorage(const char* name, Bool_t on)
00217 {
00218 GO4TRACE((12,"TGo4AnalysisStepManager::SetStepStorage(const char*,Bool_t)",__LINE__, __FILE__));
00219 Bool_t result=kFALSE;
00220 TGo4AnalysisStep* step=GetAnalysisStep(name);
00221 if(step)
00222 {
00223 step->SetStoreEnabled(on);
00224 result=kTRUE;
00225 }
00226 else
00227 {
00228 result=kFALSE;
00229 }
00230
00231 return result;
00232
00233 }
00234
00235 Bool_t TGo4AnalysisStepManager::NewStepStore(const char * name, TGo4EventStoreParameter* par)
00236 {
00237 GO4TRACE((12,"TGo4AnalysisStepManager::NewStepStore(const char *, TGo4EventStoreParameter*)",__LINE__, __FILE__));
00238 Bool_t result=kFALSE;
00239 TGo4AnalysisStep* step=0;
00240 if(name==0) {
00241
00242 step=dynamic_cast<TGo4AnalysisStep*> (fxStepList->At(fiLastStepIndex));
00243 } else {
00244
00245 step=GetAnalysisStep(name);
00246 }
00247
00248 if(step) {
00249
00250 step->NewEventStore(par);
00251 result=kTRUE;
00252 } else {
00253 result=kFALSE;
00254 }
00255
00256 return result;
00257 }
00258
00259 Bool_t TGo4AnalysisStepManager::NewStepSource(const char * name, TGo4EventSourceParameter * par)
00260 {
00261 GO4TRACE((12,"TGo4AnalysisStepManager::NewStepSource(const char *, TGo4EventSourceParameter *)",__LINE__, __FILE__));
00262 Bool_t result=kFALSE;
00263 TGo4AnalysisStep* step=0;
00264 if(name==0) {
00265
00266 step=dynamic_cast<TGo4AnalysisStep*> (fxStepList->At(fiFirstStepIndex));
00267
00268 } else {
00269
00270 step=GetAnalysisStep(name);
00271
00272 }
00273
00274 if(step) {
00275
00276 step->NewEventSource(par);
00277 result=kTRUE;
00278
00279 } else {
00280 result=kFALSE;
00281
00282 }
00283 return result;
00284 }
00285
00286 Bool_t TGo4AnalysisStepManager::NewStepProcessor(const char * name, TGo4EventProcessorParameter * par)
00287 {
00288 GO4TRACE((12,"TGo4AnalysisStepManager::NewStepProcessor(const char *, TGo4EventProcessorParameter *)",__LINE__, __FILE__));
00289 Bool_t result=kFALSE;
00290 TGo4AnalysisStep* step=GetAnalysisStep(name);
00291 if(step) {
00292
00293 step->NewEventProcessor(par);
00294 result=kTRUE;
00295 } else {
00296 result=kFALSE;
00297 }
00298 return result;
00299 }
00300
00301 Int_t TGo4AnalysisStepManager::Store(const char * name, TGo4Parameter* par)
00302 {
00303 TGo4AnalysisStep* step=GetAnalysisStep(name);
00304 return (step!=0) ? step->Store(par) : 1;
00305 }
00306
00307 Int_t TGo4AnalysisStepManager::Store(const char * name, TGo4Condition* con)
00308 {
00309 TGo4AnalysisStep* step=GetAnalysisStep(name);
00310 return (step!=0) ? step->Store(con) : 1;
00311 }
00312
00313 Int_t TGo4AnalysisStepManager::Store(const char * name, TGo4Fitter* fit)
00314 {
00315 TGo4AnalysisStep* step=GetAnalysisStep(name);
00316 return (step!=0) ? step->Store(fit) : 1;
00317 }
00318
00319 Int_t TGo4AnalysisStepManager::Store(const char * name, TFolder* folder)
00320 {
00321 TGo4AnalysisStep* step=GetAnalysisStep(name);
00322 return (step!=0) ? step->Store(folder) : 1;
00323 }
00324
00325
00326 TGo4EventElement* TGo4AnalysisStepManager::GetInputEvent(const char* stepname)
00327 {
00328 GO4TRACE((11,"TGo4AnalysisStepManager::GetInputEvent(Int_t)",__LINE__, __FILE__));
00329 TGo4EventElement* rev=0;
00330 TGo4AnalysisStep* step=GetAnalysisStep(stepname);
00331 if(step) {
00332 TGo4EventProcessor* pro=step->GetEventProcessor();
00333 if(pro)
00334 rev=pro->GetInputEvent();
00335 } else {
00336 rev=0;
00337 }
00338 return rev;
00339 }
00340
00341 TGo4EventElement* TGo4AnalysisStepManager::GetInputEvent(Int_t stepindex)
00342 {
00343 GO4TRACE((11,"TGo4AnalysisStepManager::GetInputEvent(Int_t)",__LINE__, __FILE__));
00344 TGo4EventElement* rev = 0;
00345 TGo4AnalysisStep* step = dynamic_cast<TGo4AnalysisStep*> (fxStepList->At(stepindex) );
00346 if(step) {
00347 TGo4EventProcessor* pro = step->GetEventProcessor();
00348 if(pro) rev=pro->GetInputEvent();
00349
00350 } else {
00351 rev=0;
00352 }
00353 return rev;
00354 }
00355
00356 TGo4EventElement* TGo4AnalysisStepManager::GetOutputEvent(const char* stepname)
00357 {
00358 GO4TRACE((11,"TGo4AnalysisStepManager::GetOutputEvent(const char*)",__LINE__, __FILE__));
00359 TGo4EventElement* rev=0;
00360 TGo4AnalysisStep* step=GetAnalysisStep(stepname);
00361 if(step) {
00362 rev = step->GetOutputEvent();
00363 } else {
00364 rev=0;
00365 }
00366 return rev;
00367 }
00368
00369 TGo4EventElement* TGo4AnalysisStepManager::GetOutputEvent(Int_t stepindex)
00370 {
00371 GO4TRACE((11,"TGo4AnalysisStepManager::GetOutputEvent(Int_t)",__LINE__, __FILE__));
00372 TGo4EventElement* rev=0;
00373 TGo4AnalysisStep* step=0;
00374 step= dynamic_cast<TGo4AnalysisStep*> ( fxStepList->At(stepindex) );
00375 if(step) {
00376 rev=step->GetOutputEvent();
00377 } else {
00378 rev=0;
00379 }
00380 return rev;
00381 }
00382
00383 Bool_t TGo4AnalysisStepManager::AddAnalysisStep(TGo4AnalysisStep* next)
00384 {
00385 GO4TRACE((14,"TGo4AnalysisStepManager::AddAnalysisStep(TGo4AnalysisStep*)",__LINE__, __FILE__));
00386
00387 Bool_t rev=kFALSE;
00388 if (next) {
00389 if(fxStepList->FindObject(next)==0)
00390
00391 {
00392
00393 GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Adding new analysis step",__LINE__, __FILE__));
00394 fxStepList->AddLast(next);
00395
00396 Int_t ix=fxStepList->IndexOf(next);
00397 if(ix>0)
00398 {
00399 TGo4AnalysisStep* previous= dynamic_cast<TGo4AnalysisStep*> ( fxStepList->At(ix-1) );
00400 next->SetPreviousStep(previous);
00401 }
00402 else
00403 {
00404 next->SetPreviousStep(0);
00405 }
00406 fiLastStepIndex=ix;
00407 rev=kTRUE;
00408 TGo4Analysis::Instance()->Message(1,"Analysis: Added analysis step %s",
00409 next->GetName());
00410 }
00411 else
00412 {
00413
00414 GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Analysis step was already there",__LINE__, __FILE__));
00415 rev=kFALSE;
00416 TGo4Analysis::Instance()->Message(2,"Analysis: WARNING - analysis step %s was already in steplist",
00417 next->GetName() );
00418 }
00419 }
00420 else
00421 {
00422 GO4TRACE((12,"TGo4AnalysisStepManager::AddAnalysisStep -- Zero Analysis step pointer",__LINE__, __FILE__));
00423 rev=kFALSE;
00424 TGo4Analysis::Instance()->Message(2,"Analysis: WARNING - did not add zero analysis step pointer to steplist");
00425 }
00426 return rev;
00427 }
00428
00429 TGo4AnalysisStep * TGo4AnalysisStepManager::GetAnalysisStep(const char* name)
00430 {
00431 GO4TRACE((11,"TGo4AnalysisStepManager::GetAnalysisStep(const char *)",__LINE__, __FILE__));
00432 TGo4AnalysisStep* step=0;
00433 if(name==0)
00434 step=dynamic_cast<TGo4AnalysisStep*>( fxStepList->At(fiFirstStepIndex));
00435 else
00436 step = dynamic_cast<TGo4AnalysisStep*>( fxStepList->FindObject(name) );
00437 return step;
00438 }
00439
00440 Int_t TGo4AnalysisStepManager::GetNumberOfAnalysisSteps()
00441 {
00442 return fxStepList ? fxStepList->GetLast() + 1 : 0;
00443 }
00444
00445 TGo4AnalysisStep* TGo4AnalysisStepManager::GetAnalysisStepNum(Int_t number)
00446 {
00447 GO4TRACE((11,"TGo4AnalysisStepManager::GetAnalysisStepNum(Int_t)",__LINE__, __FILE__));
00448 if ((number<0) || (number>fxStepList->GetLast())) return 0;
00449 return dynamic_cast<TGo4AnalysisStep*>(fxStepList->At(number));
00450 }
00451
00452
00453 Int_t TGo4AnalysisStepManager::ProcessAnalysisSteps()
00454 {
00455 GO4TRACE((11,"TGo4AnalysisStepManager::ProcessAnalysisSteps()",__LINE__, __FILE__));
00456
00457 fxCurrentStep = 0;
00458 fiCurrentStepIndex = 0;
00459 Bool_t isfirststep = kTRUE;
00460
00461 Int_t repeatinputstart=-1;
00462 for(fiCurrentStepIndex = fiFirstStepIndex; fiCurrentStepIndex<=fiLastStepIndex;fiCurrentStepIndex++) {
00463 fxCurrentStep = (TGo4AnalysisStep*) (fxStepList->UncheckedAt(fiCurrentStepIndex));
00464 if(fxCurrentStep->IsKeepInputEvent()) {
00465 repeatinputstart=fiCurrentStepIndex;
00466 break;
00467 }
00468 }
00469
00470 SetOutputEvent(0);
00471 for(fiCurrentStepIndex = fiFirstStepIndex; fiCurrentStepIndex<=fiLastStepIndex;fiCurrentStepIndex++) {
00472 fxCurrentStep = (TGo4AnalysisStep*) (fxStepList->UncheckedAt(fiCurrentStepIndex));
00473 if(fxCurrentStep==0) break;
00474 if(IsStepChecking() && isfirststep ) {
00475
00476 isfirststep = kFALSE;
00477 if(fxCurrentStep->IsSourceImplemented())
00478 fxCurrentStep->SetSourceEnabled();
00479 else {
00480 fxCurrentStep->SetStatusMessage("!!! No Event Source for first analysis step !!!");
00481 throw TGo4AnalysisStepException(fxCurrentStep);
00482 }
00483 }
00484 if(fiCurrentStepIndex<repeatinputstart) continue;
00485
00486 fxCurrentStep->Process();
00487
00488 if(fxCurrentStep->IsKeepOutputEvent()) break;
00489 }
00490
00491 if(TGo4MainTree::Exists()) TGo4MainTree::Instance()->Update();
00492 return 0;
00493 }
00494
00495 void TGo4AnalysisStepManager::UpdateStatus(TGo4AnalysisStatus* state)
00496 {
00497 GO4TRACE((11,"TGo4AnalysisStepManager::UpdateStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
00498 if(state!=0) {
00499 state->SetFirstStepIndex(fiFirstStepIndex);
00500 state->SetLastStepIndex(fiLastStepIndex);
00501 state->SetStepChecking(fbStepCheckingMode);
00502 fxCurrentStep=0;
00503 fxStepIterator->Reset();
00504 while((fxCurrentStep= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
00505 {
00506 TGo4AnalysisStepStatus* stepstate= fxCurrentStep->CreateStatus();
00507 state->AddStepStatus(stepstate);
00508 }
00509 }
00510 }
00511
00512 void TGo4AnalysisStepManager::SetStatus(TGo4AnalysisStatus * state)
00513 {
00514 GO4TRACE((11,"TGo4AnalysisStepManager::SetStatus(TGo4AnalysisStatus*)",__LINE__, __FILE__));
00515 if(state!=0) {
00516 fiFirstStepIndex=state->GetFirstStepIndex();
00517 fiLastStepIndex=state->GetLastStepIndex();
00518 fbStepCheckingMode=state->IsStepChecking();
00519
00520
00521
00522 fxCurrentStep=0;
00523 fxStepIterator->Reset();
00524 while((fxCurrentStep= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
00525 {
00526 const char* name= fxCurrentStep->GetName();
00527 TGo4AnalysisStepStatus* stepstate= state->GetStepStatus(name);
00528 fxCurrentStep->SetStatus(stepstate);
00529
00530 }
00531 }
00532 }
00533
00534 void TGo4AnalysisStepManager::AutoSave()
00535 {
00536 GO4TRACE((12,"TGo4AnalysisStepManager::AutoSave()",__LINE__, __FILE__));
00537
00538
00539 TGo4Analysis::Instance()->Message(0,"Analysis Step Manager -- AutoSaving....");
00540 TGo4AnalysisStep* step=0;
00541 fxStepIterator->Reset();
00542 while((step= dynamic_cast<TGo4AnalysisStep*>( fxStepIterator->Next() ) ) !=0)
00543 {
00544 step->StoreCalibration();
00545 }
00546
00547
00548 if(TGo4MainTree::Exists()) {
00549 TGo4MainTree::Instance()->Write();
00550 }
00551 }
00552
00553 Int_t TGo4AnalysisStepManager::IsErrorStopEnabled()
00554 {
00555 return kTRUE;
00556
00557 return (fxCurrentStep!=0) ? fxCurrentStep->IsErrorStopEnabled() : kTRUE;
00558 }