Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4AnalysisStep.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
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(); // note: we always have the analysis framework!
00054    fxEventFactory=eventfactory;
00055    if(fxStoreType)
00056       fxStoreType->SetTitle(GetName()); // set title of eventstore parameter to analysis step name
00057                                         // this might be used to indicate tree name
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          // usage by streamer, do not delete!
00092       }
00093 
00094 
00095 
00096 }
00097 
00098 void TGo4AnalysisStep::InitEventClasses()
00099 {
00100 TRACE((15,"TGo4AnalysisStep::InitEventClasses()",__LINE__, __FILE__));
00101    // note: the order is important here, from source to drain...
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 //cout <<"Processing Step " <<GetName() << endl;
00117    TGo4EventElement* input;
00118    fiProcessStatus=0;
00120    if(fbSourceEnabled && (fxEventSource!=0) )
00121       {
00122          // fill input event from own source
00123          fxInputEvent->SetEventSource(fxEventSource);
00124          fxInputEvent->Fill();
00125          input=fxInputEvent;
00126 
00127       }
00128    else
00129       {
00130          // get input event structure from previous step
00131          input=fxOwner->GetOutputEvent();
00132       } // end if(fbSourceEnabled && (fxEventSource!=0) )
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 //                  cout <<"StoreEnabled:"<< fbStoreEnabled << endl;
00151 //                  cout <<"EventStore: "<< fxEventStore << endl;
00152 //                  if(fxEventStore) cout <<" "<<fxEventStore->GetName()<<endl;
00153 //                  cout <<"Outputevent valid: "<<fxOutputEvent->IsValid()  << endl;
00154 
00155          } // end if(fbStoreEnabled && (fxEventStore!=0) )
00156       }
00157    else
00158       {
00159          SetStatusMessage("! AnalysisStep -- Process Error: no output event !");
00160          throw TGo4AnalysisStepException(this);
00161       } // end if(fxOutputEvent!=0)
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          // no processor error!
00248          //TGo4Analysis::Instance()->Message(2," ! AnalysisStep -- StoreCalibration: no event processor ! ");
00249 
00250       }
00251    if (fxEventStore && fbStoreEnabled)
00252       {
00253          fxEventStore->Store(cali);
00254       }
00255    else
00256       {
00257          // no storage!
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       // only check if this step is active, otherwise no event classes are initialized!
00302    TGo4EventElement* prevevent;
00303    if(fxPrevious!=0)
00304       {
00305          prevevent = fxPrevious->GetOutputEvent();
00306       }
00307    else
00308       {
00309 //         cout << "no previous analysis step for" << GetName() << endl;
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 //         cout << "no previous event for step " << GetName() << endl;
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(); // make sure that any histograms of source are not assigned
00355                               // to a file possibly opened before...
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                         // check if previous step would overwrite our event source:
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                            } // if(evstorename!= ... )
00377                      }
00378                   else
00379                      {
00380                         fxEventSource=fxEventFactory->CreateEventSource(kind);
00381                      } // if(fxPrevious)
00382                   gROOT->cd(); // back to global directory; rootfile as eventsource would be cd here!
00383                }
00384             else
00385                {
00386                   fxEventSource=0;// if not enabled, do not open files or connect...
00387                } // if(fbSourceEnabled)
00388 
00389          if(fxEventSource)
00390             {
00391                fbSourceImplemented=kTRUE;
00392                fxOwner->AddEventSource(fxEventSource); // reference to eventsource class
00393                // we have to set reference to new source in input event:
00394                if(fxInputEvent)
00395                   {
00396                       fxInputEvent->SetEventSource(fxEventSource);
00397                       fxInputEvent->Init(); // this should check if source is correct
00398                   }
00399             }
00400          else
00401             {
00402                TGo4Analysis::Instance()->Message(0,"AnalysisStep %s : No EventSource instance created by EventFactory",
00403                         GetName());
00404                 fbSourceImplemented=kFALSE;
00405             } // if(fxEventSource)
00406       }
00407    else
00408       {
00409          TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventSource Error: no event factory ");
00410       } // if(fxEventFactory)
00411 // for InitEventClasses we must store the source type:
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(); // make sure that store is not assigned
00422                   // to a file possibly opened before...
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                //kind->PrintParameter();
00433             }
00434          else
00435             {
00436                // store not enabled, so do not open/replace file
00437             }
00438 
00439          if(fxEventStore)
00440             {
00441                fbStoreImplemented=kTRUE;
00442                TTree* atree= fxEventStore->GetTree();
00443                fxOwner->AddTree(atree); // reference to tree
00444                fxOwner->AddEventStore(fxEventStore); // reference to storage class
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(); // make sure that objects assigned after us are in global dir!
00458    // for InitEventClasses :
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(); // make sure that any histograms of processor are not assigned
00468                            // to a file possibly opened before...
00469          fxEventProcessor=fxEventFactory->CreateEventProcessor(kind);
00470          fxOwner->AddEventProcessor(fxEventProcessor);
00471          if(fxEventProcessor)
00472             {
00473                 fxEventProcessor->SetInputEvent(fxInputEvent);
00474                 // method of processor might init the types here...
00475             }
00476          if(fxOutputEvent)
00477             {
00478                fxOutputEvent->SetEventSource(fxEventProcessor);
00479                fxOutputEvent->Init(); // should check event source
00480             }
00481       }
00482    else
00483       {
00484          TGo4Analysis::Instance()->Message(3,"AnalysisStep -- NewEventProcessor Error: no event factory !");
00485       }
00486    // for InitEventClasses :
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          // if user has defined the source as null, we provide dummy for gui
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(); // this should check if source is correct
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(); // should check event source
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;   // reset run status parameters to default
00572          fiProcessStatus=0;      // dito
00573       }
00574    else {}
00575 }
00576 
00577 void TGo4AnalysisStep::SetEventProcessor(TGo4EventProcessorParameter* kind)
00578 {
00579    if(kind==fxProcessorType) return; // avoid deleting valid parameter
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; // avoid deleting valid parameter
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; // avoid deleting valid parameter
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          // set title of eventstore parameter to analysis step name
00608          // this might be used to indicate tree name
00609 }
00610 
00611 
00612 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:04 2008 for Go4-v3.04-1 by  doxygen 1.4.2