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) {