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