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