00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4AnalysisStep.h"
00017
00018 #include "Riostream.h"
00019
00020 #include "TROOT.h"
00021
00022 #include "TGo4Log.h"
00023 #include "TGo4AnalysisImp.h"
00024 #include "TGo4AnalysisStepStatus.h"
00025 #include "TGo4AnalysisStepException.h"
00026
00027 #include "TGo4EventStoreParameter.h"
00028 #include "TGo4EventSourceParameter.h"
00029 #include "TGo4EventProcessorParameter.h"
00030
00031 #include "TGo4EventCalibration.h"
00032 #include "TGo4FileSourceParameter.h"
00033 #include "TGo4FileStoreParameter.h"
00034
00035 #include "TGo4EventElement.h"
00036 #include "TGo4EventFactory.h"
00037 #include "TGo4EventProcessor.h"
00038 #include "TGo4EventStore.h"
00039 #include "TGo4EventSource.h"
00040
00041 TGo4AnalysisStep::TGo4AnalysisStep(const char* name, TGo4EventFactory* eventfactory, TGo4EventSourceParameter* sourcetype, TGo4EventStoreParameter* storetype, TGo4EventProcessorParameter* processortype)
00042 :TNamed(name,"This is a Go4 analysis step"),
00043 fxPrevious(0), fxEventStore(0), fxEventSource(0), fxEventProcessor(0),
00044 fxInputEvent(0), fxOutputEvent(0),
00045 fxSourceType(sourcetype), fxStoreType(storetype), fxProcessorType(processortype),
00046 fbSourceEnabled(kFALSE), fbSourceImplemented(kFALSE),
00047 fbStoreEnabled(kFALSE), fbStoreImplemented(kFALSE),
00048 fbProcessEnabled(kTRUE),
00049 fbErrorStopEnabled(kFALSE), fbErrorStopped(kFALSE)
00050
00051 {
00052 TRACE((15,"TGo4AnalysisStep::TGo4AnalysisStep(const char*, TGo4EventFactory*)",__LINE__, __FILE__));
00053 fxOwner=TGo4Analysis::Instance();
00054 fxEventFactory=eventfactory;
00055 if(fxStoreType)
00056 fxStoreType->SetTitle(GetName());
00057
00058 SetStatusMessage(" Analysis Step is created ");
00059 }
00060
00061
00062 TGo4AnalysisStep::TGo4AnalysisStep()
00063 :TNamed("Default Analysis Step","This is a Go4 analysis step"),
00064 fxPrevious(0), fxEventStore(0), fxEventSource(0), fxEventProcessor(0),
00065 fxInputEvent(0), fxOutputEvent(0),
00066 fxSourceType(0), fxStoreType(0), fxProcessorType(0),
00067 fbSourceEnabled(kFALSE), fbSourceImplemented(kFALSE),
00068 fbStoreEnabled(kFALSE), fbStoreImplemented(kFALSE),
00069 fbProcessEnabled(kTRUE),
00070 fbErrorStopEnabled(kFALSE), fbErrorStopped(kFALSE)
00071 {
00072 TRACE((15,"TGo4AnalysisStep::TGo4AnalysisStep()",__LINE__, __FILE__));
00073
00074 fxOwner=0;
00075 fxEventFactory=0;
00076 }
00077
00078 TGo4AnalysisStep::~TGo4AnalysisStep()
00079 {
00080 TRACE((15,"TGo4AnalysisStep::~TGo4AnalysisStep()",__LINE__, __FILE__));
00081 if(fxOwner)
00082 {
00083 Close();
00084 delete fxEventFactory;
00085 delete fxSourceType;
00086 delete fxStoreType;
00087 delete fxProcessorType;
00088 }
00089 else
00090 {
00091
00092 }
00093
00094
00095
00096 }
00097
00098 void TGo4AnalysisStep::InitEventClasses()
00099 {
00100 TRACE((15,"TGo4AnalysisStep::InitEventClasses()",__LINE__, __FILE__));
00101
00102 if(fbProcessEnabled)
00103 {
00104 NewEventSource(fxSourceType);
00105 NewInputEvent();
00106 NewEventProcessor(fxProcessorType);
00107 NewOutputEvent();
00108 NewEventStore(fxStoreType);
00109 } else {}
00110 }
00111
00112 void TGo4AnalysisStep::Process()
00113 {
00114 TRACE((12,"TGo4AnalysisStep::Process()",__LINE__, __FILE__));
00115 if(!fbProcessEnabled) return;
00116
00117 TGo4EventElement* input;
00118 fiProcessStatus=0;
00120 if(fbSourceEnabled && (fxEventSource!=0) )
00121 {
00122
00123 fxInputEvent->SetEventSource(fxEventSource);
00124 fxInputEvent->Fill();
00125 input=fxInputEvent;
00126
00127 }
00128 else
00129 {
00130
00131 input=fxOwner->GetOutputEvent();
00132 }
00134 if(fxEventProcessor==0)
00135 {
00136 SetStatusMessage("! AnalysisStep -- Process Error: no event processor !");
00137 throw TGo4AnalysisStepException(this);
00138 }
00139 fxEventProcessor->SetInputEvent(input);
00140 if(fxOutputEvent!=0)
00141 {
00142 fxOutputEvent->SetEventSource(fxEventProcessor);
00143 fxOutputEvent->Fill();
00144 fxOwner->SetOutputEvent(fxOutputEvent);
00145 if(fbStoreEnabled && (fxEventStore!=0) && fxOutputEvent->IsValid())
00146 {
00147 fxEventStore->Store(fxOutputEvent);
00148 }
00149 else {
00150
00151
00152
00153
00154
00155 }
00156 }
00157 else
00158 {
00159 SetStatusMessage("! AnalysisStep -- Process Error: no output event !");
00160 throw TGo4AnalysisStepException(this);
00161 }
00162
00163 }
00164
00165 void TGo4AnalysisStep::Close()
00166 {
00167 TRACE((14,"TGo4AnalysisStep::Close()",__LINE__, __FILE__));
00168 CloseEventStore();
00169 DeleteOutputEvent();
00170 CloseEventProcessor();
00171 DeleteInputEvent();
00172 CloseEventSource();
00173 }
00174
00175 void TGo4AnalysisStep::CloseEventStore()
00176 {
00177 TRACE((14,"TGo4AnalysisStep::CloseEventStore()",__LINE__, __FILE__));
00178 if(fxEventStore)
00179 {
00180 TTree* atree= fxEventStore->GetTree();
00181 fxOwner->RemoveTree(atree);
00182 fxOwner->RemoveEventStore(fxEventStore);
00183 delete fxEventStore;
00184 fxEventStore=0;
00185 fbStoreImplemented=kFALSE;
00186 }
00187 }
00188
00189
00190 void TGo4AnalysisStep::CloseEventSource()
00191 {
00192 TRACE((14,"TGo4AnalysisStep::CloseEventSource()",__LINE__, __FILE__));
00193 if(fxEventSource)
00194 {
00195 fxOwner->RemoveEventSource(fxEventSource);
00196 delete fxEventSource;
00197 fxEventSource=0;
00198 fbSourceImplemented=kFALSE;
00199 }
00200 }
00201
00202 void TGo4AnalysisStep::CloseEventProcessor()
00203 {
00204 TRACE((14,"TGo4AnalysisStep::CloseEventProcessor()",__LINE__, __FILE__));
00205 if(fxEventProcessor)
00206 {
00207 fxOwner->RemoveEventProcessor(fxEventProcessor);
00208 delete fxEventProcessor;
00209 fxEventProcessor=0;
00210 }
00211 }
00212
00213 void TGo4AnalysisStep::DeleteInputEvent()
00214 {
00215 TRACE((14,"TGo4AnalysisStep::DeleteInputEvent()",__LINE__, __FILE__));
00216 if(fxInputEvent)
00217 {
00218 fxOwner->RemoveEventStructure(fxInputEvent);
00219 delete fxInputEvent;
00220 fxInputEvent=0;
00221 }
00222 }
00223
00224 void TGo4AnalysisStep::DeleteOutputEvent()
00225 {
00226 TRACE((14,"TGo4AnalysisStep::DeleteOutputEvent()",__LINE__, __FILE__));
00227 if(fxOutputEvent)
00228 {
00229 fxOwner->RemoveEventStructure(fxOutputEvent);
00230 delete fxOutputEvent;
00231 fxOutputEvent=0;
00232 }
00233 }
00234
00235
00236
00237 void TGo4AnalysisStep::StoreCalibration()
00238 {
00239 TRACE((14,"TGo4AnalysisStep::StoreCalibration()",__LINE__, __FILE__));
00240 TGo4EventCalibration* cali=0;
00241 if(fxEventProcessor)
00242 {
00243 cali= fxEventProcessor->GetCalibration();
00244 }
00245 else
00246 {
00247
00248
00249
00250 }
00251 if (fxEventStore && fbStoreEnabled)
00252 {
00253 fxEventStore->Store(cali);
00254 }
00255 else
00256 {
00257
00258 }
00259 }
00260
00261 Int_t TGo4AnalysisStep::Store(TGo4Parameter* cali)
00262 {
00263 if (fxEventStore && fbStoreEnabled)
00264 return (fxEventStore->Store(cali));
00265 else
00266 return -1;
00267 }
00268
00269 Int_t TGo4AnalysisStep::Store(TGo4Condition* conny)
00270 {
00271 if (fxEventStore && fbStoreEnabled)
00272 return (fxEventStore->Store(conny));
00273 else
00274 return -1;
00275
00276 }
00277
00278 Int_t TGo4AnalysisStep::Store(TGo4Fitter* fitter)
00279 {
00280 if (fxEventStore && fbStoreEnabled)
00281 return (fxEventStore->Store(fitter));
00282 else
00283 return -1;
00284
00285 }
00286
00287 Int_t TGo4AnalysisStep::Store(TFolder* fold)
00288 {
00289 if (fxEventStore && fbStoreEnabled)
00290 return (fxEventStore->Store(fold));
00291 else
00292 return -1;
00293
00294 }
00295
00296
00297 Bool_t TGo4AnalysisStep::IsMatchingPrevious()
00298 {
00299 TRACE((14,"TGo4AnalysisStep::IsMatchingPrevious(TGo4AnalysisStep*)",__LINE__, __FILE__));
00300 if(!IsProcessEnabled()) return kTRUE;
00301
00302 TGo4EventElement* prevevent;
00303 if(fxPrevious!=0)
00304 {
00305 prevevent = fxPrevious->GetOutputEvent();
00306 }
00307 else
00308 {
00309
00310 return kTRUE;
00311 }
00312 if(prevevent!=0)
00313 {
00314 if(!strcmp(prevevent->ClassName(),fxInputEvent->ClassName()) &&
00315 !strcmp(prevevent->GetName(),fxInputEvent->GetName()))
00316 {
00317 return kTRUE;
00318 }
00319 else
00320 {
00321 return kFALSE;
00322 }
00323 }
00324 else
00325 {
00326
00327 return kTRUE;
00328 }
00329
00330 }
00331
00332 const char* TGo4AnalysisStep::GetEventStoreName()
00333 {
00334 TRACE((12,"TGo4AnalysisStep::GetEventStoreName()",__LINE__, __FILE__));
00335
00336 return (fxEventStore==0) ? 0 : fxEventStore->GetName();
00337 }
00338
00339 const char* TGo4AnalysisStep::GetEventSourceName()
00340 {
00341 return (fxEventSource==0) ? 0 : fxEventSource->GetActiveName();
00342 }
00343
00344
00345 void TGo4AnalysisStep::NewEventSource(TGo4EventSourceParameter * kind)
00346 {
00347 TRACE((12,"TGo4AnalysisStep::NewEventSource(Int_t)",__LINE__, __FILE__));
00348 const char* sourcename = "";
00349 if (kind) sourcename = kind->GetName();
00350
00351 CloseEventSource();
00352 if(fxEventFactory)
00353 {
00354 gROOT->cd();
00355
00356 if(fbSourceEnabled)
00357 {
00358 if(kind && kind->InheritsFrom("TGo4TreeSourceParameter"))
00359 {
00360 SetStatusMessage("Did not init TGo4TreeSource, please use TGo4FileSource instead !");
00361 throw TGo4AnalysisStepException(this);
00362 }
00363 if(fxPrevious)
00364 {
00365
00366 const char* evstorename=fxPrevious->GetEventStoreName();
00367 if(evstorename!=0 && !strcmp(evstorename, sourcename) && fxPrevious->IsStoreEnabled())
00368 {
00369 TGo4Analysis::Instance()->Message(2,"AnalysisStep %s: Event source %s not created: previous store of same name !",
00370 GetName(), sourcename);
00371 fxEventSource=0;
00372 }
00373 else
00374 {
00375 fxEventSource=fxEventFactory->CreateEventSource(kind);
00376 }
00377 }
00378 else
00379 {
00380 fxEventSource=fxEventFactory->CreateEventSource(kind);
00381 }
00382 gROOT->cd();
00383 }
00384 else
00385 {
00386 fxEventSource=0;
00387 }
00388
00389 if(fxEventSource)
00390 {
00391 fbSourceImplemented=kTRUE;
00392 fxOwner->AddEventSource(fxEventSource);
00393
00394 if(fxInputEvent)
00395 {
00396 fxInputEvent->SetEventSource(fxEventSource);
00397 fxInputEvent->Init();
00398 }
00399 }
00400 else
00401 {
00402 TGo4Analysis::Instance()->Message(0,"AnalysisStep %s : No EventSource instance created by EventFactory",
00403 GetName());
00404 fbSourceImplemented=kFALSE;
00405 }
00406 }
00407 else
00408 {
00409 TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventSource Error: no event factory ");
00410 }
00411
00412 SetEventSource(kind);
00413 }
00414
00415 void TGo4AnalysisStep::NewEventStore(TGo4EventStoreParameter * kind)
00416 {
00417 TRACE((12,"TGo4AnalysisStep::NewEventStore(Int_t)",__LINE__, __FILE__));
00418 CloseEventStore();
00419 if(fxEventFactory)
00420 {
00421 gROOT->cd();
00422
00423 if(fbStoreEnabled)
00424 {
00425 if(kind && kind->InheritsFrom("TGo4TreeStoreParameter"))
00426 {
00427 SetStatusMessage("! Did not init TGo4TreeStore, please use TGo4FileStore instead !");
00428 throw TGo4AnalysisStepException(this);
00429 }
00430
00431 fxEventStore=fxEventFactory->CreateEventStore(kind);
00432
00433 }
00434 else
00435 {
00436
00437 }
00438
00439 if(fxEventStore)
00440 {
00441 fbStoreImplemented=kTRUE;
00442 TTree* atree= fxEventStore->GetTree();
00443 fxOwner->AddTree(atree);
00444 fxOwner->AddEventStore(fxEventStore);
00445 }
00446 else
00447 {
00448 TGo4Analysis::Instance()->Message(0,"AnalysisStep %s : No EventStore instance created by EventFactory",
00449 GetName() );
00450 fbStoreImplemented=kFALSE;
00451 }
00452 }
00453 else
00454 {
00455 TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventStore Error: no event factory !");
00456 }
00457 gROOT->cd();
00458
00459 SetEventStore(kind);
00460 }
00461 void TGo4AnalysisStep::NewEventProcessor(TGo4EventProcessorParameter * kind)
00462 {
00463 TRACE((12,"TGo4AnalysisStep::NewEventProcessor(Int_t)",__LINE__, __FILE__));
00464 CloseEventProcessor();
00465 if(fxEventFactory)
00466 {
00467 gROOT->cd();
00468
00469 fxEventProcessor=fxEventFactory->CreateEventProcessor(kind);
00470 fxOwner->AddEventProcessor(fxEventProcessor);
00471 if(fxEventProcessor)
00472 {
00473 fxEventProcessor->SetInputEvent(fxInputEvent);
00474
00475 }
00476 if(fxOutputEvent)
00477 {
00478 fxOutputEvent->SetEventSource(fxEventProcessor);
00479 fxOutputEvent->Init();
00480 }
00481 }
00482 else
00483 {
00484 TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventProcessor Error: no event factory !");
00485 }
00486
00487 SetEventProcessor(kind);
00488 }
00489 TGo4AnalysisStepStatus * TGo4AnalysisStep::CreateStatus()
00490 {
00491 TRACE((11,"TGo4AnalysisStep::CreateStatus()",__LINE__, __FILE__));
00492 TGo4AnalysisStepStatus* state= new TGo4AnalysisStepStatus( GetName() );
00493 state->SetProcessorPar(fxProcessorType);
00494 if(fxSourceType==0)
00495 {
00496
00497 fxSourceType= new TGo4FileSourceParameter("NoInputDefined");
00498 fbSourceEnabled=kFALSE;
00499 }
00500 else {}
00501 state->SetSourcePar(fxSourceType);
00502 state->SetSourceEnabled(fbSourceEnabled);
00503 if(fxStoreType==0)
00504 {
00505 fxStoreType= new TGo4FileStoreParameter("NoOutputDefined");
00506 fbStoreEnabled=kFALSE;
00507 }
00508 else{}
00509 state->SetStorePar(fxStoreType);
00510 state->SetStoreEnabled(fbStoreEnabled);
00511 state->SetProcessEnabled(fbProcessEnabled);
00512 state->SetErrorStopEnabled(fbErrorStopEnabled);
00513 state->SetErrorStopped(fbErrorStopped);
00514 state->SetProcessStatus(fiProcessStatus);
00515 return state;
00516 }
00517
00518 void TGo4AnalysisStep::NewInputEvent()
00519 {
00520 TRACE((12,"TGo4AnalysisStep::NewInputEvent()",__LINE__, __FILE__));
00521 DeleteInputEvent();
00522 if(fxEventFactory)
00523 {
00524 fxInputEvent=fxEventFactory->CreateInputEvent();
00525 fxOwner->AddEventStructure(fxInputEvent);
00526 if(fxInputEvent)
00527 {
00528 fxInputEvent->SetEventSource(fxEventSource);
00529 fxInputEvent->Init();
00530 }
00531 }
00532 else
00533 {
00534 TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewInputEvent Error: no event factory !");
00535 }
00536 }
00537
00538 void TGo4AnalysisStep::NewOutputEvent()
00539 {
00540 TRACE((12,"TGo4AnalysisStep::NewOutputEvent()",__LINE__, __FILE__));
00541 DeleteOutputEvent();
00542 if(fxEventFactory)
00543 {
00544 fxOutputEvent=fxEventFactory->CreateOutputEvent();
00545 fxOwner->AddEventStructure(fxOutputEvent);
00546 if(fxOutputEvent)
00547 {
00548 fxOutputEvent->SetEventSource(fxEventProcessor);
00549 fxOutputEvent->Init();
00550 }
00551 }
00552 else
00553 {
00554 TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewOutputEvent Error: no event factory !");
00555 }
00556 }
00557
00558
00559 void TGo4AnalysisStep::SetStatus(TGo4AnalysisStepStatus * state)
00560 {
00561 TRACE((11,"TGo4AnalysisStep::SetStatus(TGo4AnalysisStepStatus*)",__LINE__, __FILE__));
00562 if(state!=0)
00563 {
00564 SetEventProcessor(state->GetProcessorPar());
00565 SetEventSource(state->GetSourcePar());
00566 SetEventStore(state->GetStorePar());
00567 SetProcessEnabled(state->IsProcessEnabled());
00568 SetSourceEnabled(state->IsSourceEnabled());
00569 SetStoreEnabled(state->IsStoreEnabled());
00570 SetErrorStopEnabled(state->IsErrorStopEnabled());
00571 fbErrorStopped=kFALSE;
00572 fiProcessStatus=0;
00573 }
00574 else {}
00575 }
00576
00577 void TGo4AnalysisStep::SetEventProcessor(TGo4EventProcessorParameter* kind)
00578 {
00579 if(kind==fxProcessorType) return;
00580 if(fxProcessorType) delete fxProcessorType;
00581 if(kind)
00582 fxProcessorType=dynamic_cast<TGo4EventProcessorParameter*>(kind->Clone());
00583 else
00584 fxProcessorType=0;
00585 }
00586
00587 void TGo4AnalysisStep::SetEventSource(TGo4EventSourceParameter* kind)
00588 {
00589 if(kind==fxSourceType) return;
00590 if(fxSourceType) delete fxSourceType;
00591 if(kind)
00592 fxSourceType=dynamic_cast<TGo4EventSourceParameter*>(kind->Clone());
00593 else
00594 fxSourceType=0;
00595 }
00596
00597 void TGo4AnalysisStep::SetEventStore(TGo4EventStoreParameter* kind)
00598 {
00599 if(kind==fxStoreType) return;
00600 if(fxStoreType) delete fxStoreType;
00601 if(kind)
00602 fxStoreType=dynamic_cast<TGo4EventStoreParameter*>(kind->Clone());
00603 else
00604 fxStoreType=0;
00605 if(fxStoreType)
00606 fxStoreType->SetTitle(GetName());
00607
00608
00609 }
00610
00611
00612