From b9155f583ae8c51ab56ae0ff681852934c310486 Mon Sep 17 00:00:00 2001 From: Dmytro Kresan Date: Thu, 4 Feb 2016 09:36:37 +0100 Subject: [PATCH] Improve FairRunOnline. Cleanup of run managers. 1. Allow to use parameters in FairUnpackers. Added SetParContainers() method to FairUnpack. Separated method FairMbsSource::InitUnpackers(). Added source identification method. Generate RunID if it was not set. 2. Unify data members of different run classes. Use only one data member of FairEventHeader in the base class FairRun with needed getters and setters. All derrived classes use this data member. 3. Create new class for online sources. The last implementation assumed that all sources which need parameter containers in the unpackers are derrived from FairMbsSource. This is not the case for many of the Sources used by CBM. Therefore an new class for online sources was created which contain all the needed functionality. FairMbsSource is derrived from FairOnlineSource, as well as the CBM specific source classes. 4. Avoid reading the first event in case of online source. In case of online sources like lmd files or other raw data files the input file or input stream doesn't contain an event header, so it doesn't make any sense to read the first event and try to extract one. The event header is needed in case of ROOT files to extract the runID. The RunId for online files should be defined from the macro or generated on the fly. --- base/CMakeLists.txt | 1 + base/FairLinkDef.h | 1 + base/source/FairFileSource.h | 2 ++ base/source/FairLmdSource.cxx | 4 --- base/source/FairMbsSource.cxx | 21 ++--------- base/source/FairMbsSource.h | 14 ++------ base/source/FairMbsStreamSource.cxx | 4 --- base/source/FairMixedSource.h | 2 ++ base/source/FairOnlineSource.cxx | 52 +++++++++++++++++++++++++++ base/source/FairOnlineSource.h | 55 +++++++++++++++++++++++++++++ base/source/FairRemoteSource.cxx | 4 --- base/source/FairSource.h | 6 +++- base/source/FairUnpack.h | 1 + base/steer/FairRun.cxx | 12 +++---- base/steer/FairRun.h | 6 ++-- base/steer/FairRunAna.cxx | 4 +-- base/steer/FairRunAna.h | 4 +-- base/steer/FairRunOnline.cxx | 49 +++++++++++++++---------- base/steer/FairRunOnline.h | 4 --- cmake/scripts/fairroot-config.in | 2 +- 20 files changed, 168 insertions(+), 80 deletions(-) create mode 100644 base/source/FairOnlineSource.cxx create mode 100644 base/source/FairOnlineSource.h diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index 1487be58e6..9012767dd3 100644 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -125,6 +125,7 @@ field/FairRKPropagator.cxx source/FairSource.cxx source/FairFileSource.cxx source/FairMixedSource.cxx +source/FairOnlineSource.cxx ) If(BUILD_MBS) diff --git a/base/FairLinkDef.h b/base/FairLinkDef.h index a2038132a3..88be8018ef 100644 --- a/base/FairLinkDef.h +++ b/base/FairLinkDef.h @@ -74,6 +74,7 @@ #pragma link C++ class FairSource; #pragma link C++ class FairFileSource; #pragma link C++ class FairMixedSource; +#pragma link C++ class FairOnlineSource; #ifdef BUILD_MBS #pragma link C++ class FairMbsSource; #pragma link C++ class FairRemoteSource; diff --git a/base/source/FairFileSource.h b/base/source/FairFileSource.h index c58141e7b8..5d049b637a 100644 --- a/base/source/FairFileSource.h +++ b/base/source/FairFileSource.h @@ -43,6 +43,8 @@ class FairFileSource : public FairSource void Close(); void Reset(); + virtual Source_Type GetSourceType() { return kFILE; } + /**Check the maximum event number we can run to*/ virtual Int_t CheckMaxEventNo(Int_t EvtEnd=0); /**Read the tree entry on one branch**/ diff --git a/base/source/FairLmdSource.cxx b/base/source/FairLmdSource.cxx index c9711dc844..351ec824e8 100644 --- a/base/source/FairLmdSource.cxx +++ b/base/source/FairLmdSource.cxx @@ -112,10 +112,6 @@ void FairLmdSource::AddPath(TString dir, TString wildCard) Bool_t FairLmdSource::Init() { - if(! FairMbsSource::Init()) { - return kFALSE; - } - if(fFileNames->GetSize() == 0) { return kFALSE; } diff --git a/base/source/FairMbsSource.cxx b/base/source/FairMbsSource.cxx index 3cd2066468..070d803965 100644 --- a/base/source/FairMbsSource.cxx +++ b/base/source/FairMbsSource.cxx @@ -18,29 +18,12 @@ #include "FairMbsSource.h" #include "FairLogger.h" -FairMbsSource::FairMbsSource() : FairSource(), fUnpackers(new TObjArray()) {} +FairMbsSource::FairMbsSource() : FairOnlineSource() {} FairMbsSource::FairMbsSource(const FairMbsSource &source) - : FairSource(source), fUnpackers(new TObjArray(*(source.GetUnpackers()))) {} + : FairOnlineSource(source) {} FairMbsSource::~FairMbsSource() { - fUnpackers->Delete(); - delete fUnpackers; -} - -Bool_t FairMbsSource::Init() { - for (Int_t i = 0; i < fUnpackers->GetEntriesFast(); i++) { - if (!((FairUnpack *)fUnpackers->At(i))->Init()) { - return kFALSE; - } - } - return kTRUE; -} - -void FairMbsSource::Reset() { - for (Int_t i = 0; i < fUnpackers->GetEntriesFast(); i++) { - ((FairUnpack *)fUnpackers->At(i))->Reset(); - } } Bool_t FairMbsSource::Unpack(Int_t *data, Int_t size, Short_t type, diff --git a/base/source/FairMbsSource.h b/base/source/FairMbsSource.h index 3fd2043b61..f65cc0b5f1 100644 --- a/base/source/FairMbsSource.h +++ b/base/source/FairMbsSource.h @@ -16,36 +16,28 @@ #ifndef FAIRMBSSOURCE_H #define FAIRMBSSOURCE_H -#include "FairSource.h" +#include "FairOnlineSource.h" #include "TObjArray.h" #include "FairUnpack.h" -class FairMbsSource : public FairSource +class FairMbsSource : public FairOnlineSource { public: FairMbsSource(); FairMbsSource(const FairMbsSource& source); virtual ~FairMbsSource(); - inline void AddUnpacker(FairUnpack* unpacker) { fUnpackers->Add(unpacker); } - inline const TObjArray* GetUnpackers() const { return fUnpackers; } - - virtual Bool_t Init(); + virtual Bool_t Init() = 0; virtual Int_t ReadEvent(UInt_t=0) = 0; virtual void Close() = 0; - void Reset(); - protected: Bool_t Unpack(Int_t* data, Int_t size, Short_t type, Short_t subType, Short_t procId, Short_t subCrate, Short_t control); - private: - TObjArray* fUnpackers; - ClassDef(FairMbsSource, 0) }; diff --git a/base/source/FairMbsStreamSource.cxx b/base/source/FairMbsStreamSource.cxx index 058e98063c..0b4bf352c3 100644 --- a/base/source/FairMbsStreamSource.cxx +++ b/base/source/FairMbsStreamSource.cxx @@ -43,10 +43,6 @@ FairMbsStreamSource::~FairMbsStreamSource() Bool_t FairMbsStreamSource::Init() { - if(! FairMbsSource::Init()) { - return kFALSE; - } - if(! ConnectToServer()) { return kFALSE; } diff --git a/base/source/FairMixedSource.h b/base/source/FairMixedSource.h index db7dad9d9a..0a3418e0e4 100644 --- a/base/source/FairMixedSource.h +++ b/base/source/FairMixedSource.h @@ -46,6 +46,8 @@ class FairMixedSource : public FairSource void Close(); void Reset(); + virtual Source_Type GetSourceType() { return kFILE; } + /**Check the maximum event number we can run to*/ virtual Int_t CheckMaxEventNo(Int_t EvtEnd=0); /**Read the tree entry on one branch**/ diff --git a/base/source/FairOnlineSource.cxx b/base/source/FairOnlineSource.cxx new file mode 100644 index 0000000000..6aac9456a3 --- /dev/null +++ b/base/source/FairOnlineSource.cxx @@ -0,0 +1,52 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ----------------------------------------------------------------------------- +// ----- ----- +// ----- FairOnlineSource ----- +// ----- Created 12.04.2013 by D.Kresan ----- +// ----- Copied from FairSource 01.11.2013 by F.Uhlig ----- +// ----- ----- +// ----------------------------------------------------------------------------- + +#include + +#include "FairOnlineSource.h" +#include "FairLogger.h" + +FairOnlineSource::FairOnlineSource() : FairSource(), fUnpackers(new TObjArray()) {} + +FairOnlineSource::FairOnlineSource(const FairOnlineSource &source) + : FairSource(source), fUnpackers(new TObjArray(*(source.GetUnpackers()))) {} + +FairOnlineSource::~FairOnlineSource() { + fUnpackers->Delete(); + delete fUnpackers; +} + +Bool_t FairOnlineSource::InitUnpackers() { + for (Int_t i = 0; i < fUnpackers->GetEntriesFast(); i++) { + if (!((FairUnpack *)fUnpackers->At(i))->Init()) { + return kFALSE; + } + } + return kTRUE; +} + +void FairOnlineSource::SetParUnpackers() { + for (Int_t i = 0; i < fUnpackers->GetEntriesFast(); i++) { + ((FairUnpack *)fUnpackers->At(i))->SetParContainers(); + } +} + +void FairOnlineSource::Reset() { + for (Int_t i = 0; i < fUnpackers->GetEntriesFast(); i++) { + ((FairUnpack *)fUnpackers->At(i))->Reset(); + } +} + +ClassImp(FairOnlineSource) diff --git a/base/source/FairOnlineSource.h b/base/source/FairOnlineSource.h new file mode 100644 index 0000000000..b06ab8a9bf --- /dev/null +++ b/base/source/FairOnlineSource.h @@ -0,0 +1,55 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ----------------------------------------------------------------------------- +// ----- ----- +// ----- FairMbsSource ----- +// ----- Created 12.04.2013 by D.Kresan ----- +// ----- Copied from FairSource 01.11.2013 by F.Uhlig ----- +// ----- ----- +// ----------------------------------------------------------------------------- + +#ifndef FAIRONLINESOURCE_H +#define FAIRONLINESOURCE_H + +#include "FairSource.h" +#include "TObjArray.h" + +#include "FairUnpack.h" + + +class FairOnlineSource : public FairSource +{ + public: + FairOnlineSource(); + FairOnlineSource(const FairOnlineSource& source); + virtual ~FairOnlineSource(); + + inline void AddUnpacker(FairUnpack* unpacker) { fUnpackers->Add(unpacker); } + inline const TObjArray* GetUnpackers() const { return fUnpackers; } + + virtual Bool_t Init() = 0; + virtual Int_t ReadEvent(UInt_t=0) = 0; + virtual void Close() = 0; + + void SetParUnpackers(); + + Bool_t InitUnpackers(); + + void Reset(); + + virtual Source_Type GetSourceType() { return kONLINE; } + + protected: + TObjArray* fUnpackers; + + private: + ClassDef(FairOnlineSource, 0) +}; + + +#endif diff --git a/base/source/FairRemoteSource.cxx b/base/source/FairRemoteSource.cxx index e8f24bf18f..782827f530 100644 --- a/base/source/FairRemoteSource.cxx +++ b/base/source/FairRemoteSource.cxx @@ -50,10 +50,6 @@ FairRemoteSource::~FairRemoteSource() Bool_t FairRemoteSource::Init() { - if(! FairMbsSource::Init()) { - return kFALSE; - } - fBuffer->RevStatus(0); fSocket = fBuffer->RevOpen(fNode, 6003, 0); fBuffer->RevStatus(0); diff --git a/base/source/FairSource.h b/base/source/FairSource.h index f054aae5b6..a17fe505ef 100644 --- a/base/source/FairSource.h +++ b/base/source/FairSource.h @@ -21,6 +21,8 @@ class FairEventHeader; +enum Source_Type {kONLINE, kFILE}; + class FairSource : public TObject { public: @@ -33,7 +35,9 @@ class FairSource : public TObject virtual void Close() = 0; virtual void Reset() = 0; - + + virtual Source_Type GetSourceType() = 0; + virtual Bool_t ActivateObject(TObject** obj, const char* ObjType) { return kFALSE; } /**Check the maximum event number we can run to*/ diff --git a/base/source/FairUnpack.h b/base/source/FairUnpack.h index 81b7d38264..28acafc860 100644 --- a/base/source/FairUnpack.h +++ b/base/source/FairUnpack.h @@ -28,6 +28,7 @@ class FairUnpack : public TObject virtual Bool_t Init() = 0; virtual Bool_t DoUnpack(Int_t* data, Int_t size) = 0; virtual void Reset() = 0; + virtual void SetParContainers() { }; inline Short_t GetType() const { return fType; } inline Short_t GetSubType() const { return fSubType; } diff --git a/base/steer/FairRun.cxx b/base/steer/FairRun.cxx index 43013deadd..290fac8cfe 100644 --- a/base/steer/FairRun.cxx +++ b/base/steer/FairRun.cxx @@ -44,7 +44,7 @@ FairRun::FairRun(Bool_t isMaster) fOutFile(0), fRunId(0), fAna(kFALSE), - fEvHead(NULL), + fEvtHeader(NULL), fFileHeader(new FairFileHeader()), fGenerateRunInfo(kFALSE), fIsMaster(isMaster) @@ -75,8 +75,8 @@ FairRun::~FairRun() delete fRootManager; // who is responsible fRootManager=0; } - if (fEvHead) { - delete fEvHead; + if (fEvtHeader) { + delete fEvtHeader; } LOG(DEBUG) << "Leave Destructor of FairRun" << FairLogger::endl; } @@ -132,10 +132,10 @@ FairTask* FairRun::GetTask(const char* taskName) //_____________________________________________________________________________ FairEventHeader* FairRun::GetEventHeader() { - if ( NULL == fEvHead ) { - fEvHead = new FairEventHeader(); + if ( NULL == fEvtHeader ) { + fEvtHeader = new FairEventHeader(); } - return fEvHead; + return fEvtHeader; } void FairRun::SetUseFairLinks(Bool_t val) diff --git a/base/steer/FairRun.h b/base/steer/FairRun.h index 031c7604ae..4c80f1ef83 100644 --- a/base/steer/FairRun.h +++ b/base/steer/FairRun.h @@ -73,7 +73,7 @@ class FairRun : public TNamed * for each run */ void SetEventHeader(FairEventHeader* EvHeader) { - fEvHead=EvHeader; + fEvtHeader=EvHeader; } /** * return a pointer to the RuntimeDB @@ -180,7 +180,7 @@ class FairRun : public TNamed /** true for Anaylsis session*/ Bool_t fAna; //! /** MC Event Header */ - FairEventHeader* fEvHead; //! + FairEventHeader* fEvtHeader; //! /** File Header */ FairFileHeader* fFileHeader; /** true if RunInfo file should be written*/ @@ -188,6 +188,6 @@ class FairRun : public TNamed /** true if on master*/ Bool_t fIsMaster; //! - ClassDef(FairRun ,2) + ClassDef(FairRun ,3) }; #endif //FAIRRUN_H diff --git a/base/steer/FairRunAna.cxx b/base/steer/FairRunAna.cxx index 7a196d6fe5..aa4bbecd20 100644 --- a/base/steer/FairRunAna.cxx +++ b/base/steer/FairRunAna.cxx @@ -82,7 +82,6 @@ FairRunAna::FairRunAna() fIsInitialized(kFALSE), fInputGeoFile(0), fLoadGeo( kFALSE), - fEvtHeader(0), fStatic(kFALSE), fField(0), fTimeStamps(kFALSE), @@ -228,7 +227,8 @@ void FairRunAna::Init() LOG(INFO) << "Parameter and input file are available, Assure that basic info is there for the run!" << FairLogger::endl; fRootManager->ReadEvent(0); - fEvtHeader = GetEventHeader(); +// fEvtHeader = GetEventHeader(); + GetEventHeader(); fRootManager->FillEventHeader(fEvtHeader); diff --git a/base/steer/FairRunAna.h b/base/steer/FairRunAna.h index bb3c26aa6d..334990cba4 100644 --- a/base/steer/FairRunAna.h +++ b/base/steer/FairRunAna.h @@ -24,7 +24,6 @@ #include "Rtypes.h" // for Bool_t, Double_t, UInt_t, etc #include "TString.h" // for TString -class FairEventHeader; class FairField; class TF1; class TFile; @@ -181,7 +180,6 @@ class FairRunAna : public FairRun TFile* fInputGeoFile; static FairRunAna* fgRinstance; Bool_t fLoadGeo; - FairEventHeader* fEvtHeader;//! /** true for static initialisation of parameters */ Bool_t fStatic;//! FairField* fField; @@ -205,7 +203,7 @@ class FairRunAna : public FairRun /** Temporary member to preserve old functionality without setting source in macro */ FairMixedSource* fMixedSource; //! - ClassDef(FairRunAna ,5) + ClassDef(FairRunAna ,6) }; diff --git a/base/steer/FairRunOnline.cxx b/base/steer/FairRunOnline.cxx index 0969fc7f9b..a9a48c69cf 100644 --- a/base/steer/FairRunOnline.cxx +++ b/base/steer/FairRunOnline.cxx @@ -24,6 +24,7 @@ #include "FairParIo.h" #include "FairField.h" //#include "FairSource.h" +#include "FairMbsSource.h" #include "FairGeoInterface.h" #include "FairGeoLoader.h" @@ -69,7 +70,6 @@ FairRunOnline::FairRunOnline() :FairRun(), fAutomaticFinish(kTRUE), fIsInitialized(kFALSE), - fEvtHeader(0), fStatic(kFALSE), fField(0), fFolder(new TFolder("HISTO", "HISTO")), @@ -89,7 +89,6 @@ FairRunOnline::FairRunOnline(FairSource* source) :FairRun(), fAutomaticFinish(kTRUE), fIsInitialized(kFALSE), - fEvtHeader(0), fStatic(kFALSE), fField(0), fFolder(new TFolder("HISTO", "HISTO")), @@ -158,15 +157,28 @@ void FairRunOnline::Init() // GeoInterFace->setMediaFile(MatFname.Data()); // GeoInterFace->readMedia(); - // Add a Generated run ID to the FairRunTimeDb - fRootManager->ReadEvent(0); - + // Add a Generated run ID to the FairRunTimeDb for input data which contain a FairMCEventHeader + // The call doesn't make sense for online sources which doesn't contain a FairMCEventHeader + + if(kONLINE != fRootManager->GetSource()->GetSourceType()) + { + fRootManager->ReadEvent(0); + } + GetEventHeader(); fRootManager->FillEventHeader(fEvtHeader); - fRunId = fEvtHeader->GetRunId(); - + if(0 == fRunId) + { + fRunId = fEvtHeader->GetRunId(); + if(0 == fRunId) + { + FairRunIdGenerator genid; + fRunId = genid.generateId(); + } + } + fRtdb->addRun(fRunId); fFileHeader->SetRunId(fRunId); FairBaseParSet* par = dynamic_cast(fRtdb->getContainer("FairBaseParSet")); @@ -195,8 +207,12 @@ void FairRunOnline::Init() geopar->setInputVersion(fRunId,1); } -fRootManager->WriteFileHeader(fFileHeader); + fRootManager->WriteFileHeader(fFileHeader); + if(kONLINE == fRootManager->GetSource()->GetSourceType()) + { + ((FairOnlineSource*)(fRootManager->GetSource()))->SetParUnpackers(); + } fTask->SetParTask(); fRtdb->initContainers(fRunId); @@ -210,6 +226,11 @@ fRootManager->WriteFileHeader(fFileHeader); fRootManager->Register("EventHeader.", "Event", fEvtHeader, kTRUE); fEvtHeader->SetRunId(fRunId); + if(kONLINE == fRootManager->GetSource()->GetSourceType()) + { + ((FairOnlineSource*)(fRootManager->GetSource()))->InitUnpackers(); + } + // Now call the User initialize for Tasks fTask->InitTask(); @@ -269,7 +290,8 @@ Int_t FairRunOnline::EventLoop() gSystem->IgnoreInterrupt(); signal(SIGINT, handler_ctrlc); - Int_t tmpId = fRootManager->GetRunId(); + fRootManager->FillEventHeader(fEvtHeader); + Int_t tmpId = fEvtHeader->GetRunId(); if ( tmpId != -1 && tmpId != fRunId ) { LOG(INFO) << "FairRunOnline::EventLoop() Call Reinit due to changed RunID (from " << fRunId << " to " << tmpId << FairLogger::endl; @@ -517,15 +539,6 @@ void FairRunOnline::WriteObjects() //_____________________________________________________________________________ //_____________________________________________________________________________ -FairEventHeader* FairRunOnline::GetEventHeader() -{ - // fEvtHeader = fRootManager->GetEventHeader(); - if ( NULL == fEvtHeader ) { - fEvtHeader = new FairEventHeader(); - } - return fEvtHeader; -} -//_____________________________________________________________________________ //_____________________________________________________________________________ diff --git a/base/steer/FairRunOnline.h b/base/steer/FairRunOnline.h index 56a48544c0..2100096650 100644 --- a/base/steer/FairRunOnline.h +++ b/base/steer/FairRunOnline.h @@ -23,7 +23,6 @@ #include class FairRuntimeDb; -class FairEventHeader; class FairField; class TFile; class TF1; @@ -41,8 +40,6 @@ class FairRunOnline : public FairRun FairRunOnline(); FairRunOnline(FairSource* source); - FairEventHeader* GetEventHeader(); - /**initialize the run manager*/ void Init(); /**Run for the given number of events*/ @@ -107,7 +104,6 @@ class FairRunOnline : public FairRun /** This variable became true after Init is called*/ Bool_t fIsInitialized; static FairRunOnline* fgRinstance; - FairEventHeader* fEvtHeader;//! /** true for static initialisation of parameters */ Bool_t fStatic;//! FairField* fField; diff --git a/cmake/scripts/fairroot-config.in b/cmake/scripts/fairroot-config.in index 5f90fb8e6d..134df2a525 100644 --- a/cmake/scripts/fairroot-config.in +++ b/cmake/scripts/fairroot-config.in @@ -1,6 +1,6 @@ #!/bin/bash -_version=@FAIRROOT_GIT_VERSION@ +_version=v-15.11b _major_version=${_version:2:2} _minor_version=${_version:5:2} _patch=${_version:7}