From 720fe9ba5b683624134eb49766aaf7e35d4d5abe Mon Sep 17 00:00:00 2001 From: Radoslaw Karabowicz Date: Wed, 5 Jun 2024 11:50:21 +0200 Subject: [PATCH 1/2] chore(parbase): Some cleanup of `FairParSet` --- fairroot/parbase/FairParSet.cxx | 36 +++++++++++++-------------------- fairroot/parbase/FairParSet.h | 26 ++++++++++++------------ 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/fairroot/parbase/FairParSet.cxx b/fairroot/parbase/FairParSet.cxx index 091a104bc5..b203c04e6a 100644 --- a/fairroot/parbase/FairParSet.cxx +++ b/fairroot/parbase/FairParSet.cxx @@ -35,7 +35,7 @@ FairParSet::FairParSet(const char* name, const char* title, const char* context, , author("") , description("") { - for (Int_t i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { versions[i] = -1; } } @@ -50,7 +50,7 @@ Bool_t FairParSet::init() // FairRunAna* fRun =FairRunAna::Instance(); // cout << "-I- FairParSet::init() " << GetName() << endl; - Bool_t allFound = kFALSE; + bool allFound = false; FairParIo* io = 0; if (rtdb) { io = rtdb->getFirstInput(); @@ -91,33 +91,25 @@ Int_t FairParSet::write() void FairParSet::print() { // prints information about container (versions,status,hasChanged...) - cout << "----- " << GetName() << " -----" << '\n'; + LOG(info) << "----- " << GetName() << " -----"; if (!paramContext.IsNull()) { - cout << "Context/Purpose: " << paramContext << '\n'; + LOG(info) << "Context/Purpose: " << paramContext; } if (!author.IsNull()) { - cout << "Author: " << author << '\n'; + LOG(info) << "Author: " << author; } if (!description.IsNull()) { - cout << "Description: " << description << '\n'; - } - cout << "first input version: " << versions[1] << '\n'; - cout << "second input version: " << versions[2] << '\n'; - if (changed) { - cout << "has changed" << '\n'; - } else { - cout << "has not changed" << '\n'; - } - if (status) { - cout << "is static" << '\n'; - } else { - cout << "is not static" << '\n'; + LOG(info) << "Description: " << description; } + LOG(info) << "first input version: " << versions[1]; + LOG(info) << "second input version: " << versions[2]; + LOG(info) << "has" << (changed ? "" : " not") << " changed"; + LOG(info) << "is" << (status ? "" : " not") << " static"; } void FairParSet::clear() { - status = kFALSE; + status = false; resetInputVersions(); } @@ -125,10 +117,10 @@ void FairParSet::resetInputVersions() { // resets the input versions if the container is not static if (!status) { - for (Int_t i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { versions[i] = -1; } - changed = kFALSE; + changed = false; } } @@ -150,7 +142,7 @@ FairParSet::FairParSet(const FairParSet& from) fTitle = from.fTitle; detName = from.detName; */ - for (Int_t i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) versions[i] = from.versions[i]; /* status = from.status; diff --git a/fairroot/parbase/FairParSet.h b/fairroot/parbase/FairParSet.h index 02fd00f9f8..ab9f4f0e6f 100644 --- a/fairroot/parbase/FairParSet.h +++ b/fairroot/parbase/FairParSet.h @@ -20,16 +20,16 @@ class FairParSet : public TObject TString fName; // TString fTitle; // TString detName; //! name of the detector the container belongs to - Int_t versions[3]; //! versions of container in the 2 possible inputs - Bool_t status; //! static flag - Bool_t changed; //! flag is kTRUE if parameters have changed - Bool_t owned; //! if flag is KTRUE FairDB has the par. class ownership + int versions[3]; //! versions of container in the 2 possible inputs + bool status; //! static flag + bool changed; //! flag is kTRUE if parameters have changed + bool owned; //! if flag is KTRUE FairDB has the par. class ownership TString paramContext; // Context/purpose for parameters and conditions TString author; // Author of parameters TString description; // Description of parameters public: - FairParSet(const char* name = "", const char* title = "", const char* context = "", Bool_t owner = kFALSE); + FairParSet(const char* name = "", const char* title = "", const char* context = "", bool owner = false); virtual ~FairParSet() {} const char* GetName() const override { return fName.Data(); } @@ -45,13 +45,13 @@ class FairParSet : public TObject const char* getDetectorName() { return detName.Data(); } void resetInputVersions(); - void setInputVersion(Int_t v = -1, Int_t i = 0) + void setInputVersion(int v = -1, int i = 0) { if (i >= 0 && i < 3) { versions[i] = v; } } - Int_t getInputVersion(Int_t i) + int getInputVersion(int i) { if (i >= 0 && i < 3) { return versions[i]; @@ -60,14 +60,14 @@ class FairParSet : public TObject } } - void setStatic(Bool_t flag = kTRUE) { status = flag; } - Bool_t isStatic() { return status; } + void setStatic(bool flag = kTRUE) { status = flag; } + bool isStatic() { return status; } - void setOwnership(Bool_t flag = kTRUE) { owned = flag; } - Bool_t isOwned() { return owned; } + void setOwnership(bool flag = kTRUE) { owned = flag; } + bool isOwned() { return owned; } - void setChanged(Bool_t flag = kTRUE) { changed = flag; } - Bool_t hasChanged() { return changed; } + void setChanged(bool flag = kTRUE) { changed = flag; } + bool hasChanged() { return changed; } const char* getParamContext() const { return paramContext.Data(); } From ba0f92d755e1ceacebcf3ac7471f2201897814e8 Mon Sep 17 00:00:00 2001 From: Christian Tacke <58549698+ChristianTackeGSI@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:13:26 +0200 Subject: [PATCH 2/2] feat(parbase): Improve logging around FairParSet::init And re-arrange some if statements --- fairroot/parbase/FairDetParRootFileIo.cxx | 24 ++++++------ fairroot/parbase/FairParSet.cxx | 47 ++++++++++++----------- fairroot/parbase/FairParSet.h | 3 ++ fairroot/parbase/FairRuntimeDb.cxx | 33 ++++++++++------ 4 files changed, 62 insertions(+), 45 deletions(-) diff --git a/fairroot/parbase/FairDetParRootFileIo.cxx b/fairroot/parbase/FairDetParRootFileIo.cxx index a32522ae8a..6d0da35b2c 100644 --- a/fairroot/parbase/FairDetParRootFileIo.cxx +++ b/fairroot/parbase/FairDetParRootFileIo.cxx @@ -30,8 +30,9 @@ #include // for TDirectory, gDirectory #include // for TKey #include // for TROOT, gROOT -#include // for format -#include // for operator<<, basic_ostream, etc +#include +#include // for format +#include // for operator<<, basic_ostream, etc using std::cout; using std::endl; @@ -62,16 +63,17 @@ Bool_t FairDetParRootFileIo::read(FairParSet* pPar) } TKey* key = gDirectory->GetKey(name, version); - if (key) { - pPar->clear(); - key->Read(pPar); - pPar->setInputVersion(version, inputNumber); - pPar->setChanged(); - cout << "Container " << pPar->GetName() << " initialized from ROOT file." << endl; - return kTRUE; + if (!key) { + pPar->setInputVersion(-1, inputNumber); + return kFALSE; } - pPar->setInputVersion(-1, inputNumber); - return kFALSE; + + pPar->clear(); + key->Read(pPar); + pPar->setInputVersion(version, inputNumber); + pPar->setChanged(); + LOG(info) << " Container " << pPar->GetName() << " initialized from ROOT file."; + return kTRUE; } Int_t FairDetParRootFileIo::write(FairParSet* pPar) diff --git a/fairroot/parbase/FairParSet.cxx b/fairroot/parbase/FairParSet.cxx index b203c04e6a..35caf2ae19 100644 --- a/fairroot/parbase/FairParSet.cxx +++ b/fairroot/parbase/FairParSet.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -40,6 +40,18 @@ FairParSet::FairParSet(const char* name, const char* title, const char* context, } } +bool FairParSet::CallInitIO(FairParIo* io, const char* context) +{ + if (!io) { + return false; + } + bool retval = init(io); + if (!retval) { + LOGP(warn, "{}({})::init(io) failed for {}", ClassName(), GetName(), context); + } + return retval; +} + Bool_t FairParSet::init() { // intitializes the container from an input in run time @@ -47,31 +59,20 @@ Bool_t FairParSet::init() // the second input. If this failes too, it returns an error. // (calls internally the init function in the derived class) FairRuntimeDb* rtdb = FairRuntimeDb::instance(); - // FairRunAna* fRun =FairRunAna::Instance(); - // cout << "-I- FairParSet::init() " << GetName() << endl; - - bool allFound = false; - FairParIo* io = 0; - if (rtdb) { - io = rtdb->getFirstInput(); - if (io) { - allFound = init(io); - } - if (!allFound) { - io = rtdb->getSecondInput(); - // cout << "-I FairParSet::init() 2 " << io << std::endl; - if (io) { - allFound = init(io); - } - } else { - setInputVersion(-1, 2); - } + if (!rtdb) { + LOG(error) << "FairParSet::init()/" << GetName() << ": No RTDB"; + return false; } + + bool allFound = CallInitIO(rtdb->getFirstInput(), "first input"); if (allFound) { - return kTRUE; + setInputVersion(-1, 2); + return allFound; } - LOG(error) << "init() " << GetName() << " not initialized"; - return kFALSE; + + allFound = CallInitIO(rtdb->getSecondInput(), "second input"); + + return allFound; } Int_t FairParSet::write() diff --git a/fairroot/parbase/FairParSet.h b/fairroot/parbase/FairParSet.h index ab9f4f0e6f..78cbfda952 100644 --- a/fairroot/parbase/FairParSet.h +++ b/fairroot/parbase/FairParSet.h @@ -92,6 +92,9 @@ class FairParSet : public TObject FairParSet& operator=(const FairParSet&); FairParSet(const FairParSet&); + private: + bool CallInitIO(FairParIo* io, const char* context); + ClassDefOverride(FairParSet, 2); // Base class for all parameter containers }; diff --git a/fairroot/parbase/FairRuntimeDb.cxx b/fairroot/parbase/FairRuntimeDb.cxx index 24323f912a..4d5c5ec4b1 100644 --- a/fairroot/parbase/FairRuntimeDb.cxx +++ b/fairroot/parbase/FairRuntimeDb.cxx @@ -526,24 +526,35 @@ Bool_t FairRuntimeDb::initContainers() secondInput->readVersions(refRun); } } - TIter next(containerList); - FairParSet* cont; - Bool_t rc = kTRUE; - cout << '\n' << "************************************************************* " << '\n'; + LOG(info) << "*************************************************************"; if (currentFileName.IsNull()) { - cout << " initialisation for run id " << currentRun->GetName(); + LOG(info) << " initialisation for run id " << currentRun->GetName(); } else { - cout << " initialisation for event file " << currentFileName.Data() << '\n'; - cout << " run id " << currentRun->GetName(); + LOG(info) << " initialisation for event file " << currentFileName.Data(); + LOG(info) << " run id " << currentRun->GetName(); } if (len > 0) { - cout << " --> " << refRunName; + LOG(info) << " --> " << refRunName; + } + LOG(info) << "*************************************************************"; + if (firstInput) { + LOG(info) << "First Input:"; + firstInput->print(); } - cout << '\n' << "************************************************************* " << '\n'; + if (secondInput) { + LOG(info) << "Second Input:"; + secondInput->print(); + } + bool rc = true; + TIter next(containerList); + FairParSet* cont; while ((cont = static_cast(next()))) { - cout << "-I- FairRunTimeDB::InitContainer() " << cont->GetName() << endl; + LOG(info) << "-I- FairRunTimeDB::initContainers() for " << cont->GetName(); if (!cont->isStatic()) { - rc = cont->init() && rc; + if (!cont->init()) { + LOGP(error, "{}({})::init(): failed", cont->ClassName(), cont->GetName()); + rc = false; + } } } if (!rc) {