Skip to content

Commit

Permalink
feat(parbase): Improve logging around FairParSet::init
Browse files Browse the repository at this point in the history
And re-arrange some if statements
  • Loading branch information
ChristianTackeGSI authored and karabowi committed Jul 12, 2024
1 parent 1756504 commit 1750b27
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 45 deletions.
24 changes: 13 additions & 11 deletions fairroot/parbase/FairDetParRootFileIo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
#include <TDirectory.h> // for TDirectory, gDirectory
#include <TKey.h> // for TKey
#include <TROOT.h> // for TROOT, gROOT
#include <fmt/core.h> // for format
#include <iostream> // for operator<<, basic_ostream, etc
#include <fairlogger/Logger.h>
#include <fmt/core.h> // for format
#include <iostream> // for operator<<, basic_ostream, etc

using std::cout;
using std::endl;
Expand Down Expand Up @@ -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)
Expand Down
47 changes: 24 additions & 23 deletions fairroot/parbase/FairParSet.cxx
Original file line number Diff line number Diff line change
@@ -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, *
Expand Down Expand Up @@ -40,38 +40,39 @@ 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
// database. If this is not successful it is initialized from
// 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()
Expand Down
3 changes: 3 additions & 0 deletions fairroot/parbase/FairParSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
33 changes: 22 additions & 11 deletions fairroot/parbase/FairRuntimeDb.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<FairParSet*>(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) {
Expand Down

0 comments on commit 1750b27

Please sign in to comment.