Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
81 changes: 37 additions & 44 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 @@ -35,43 +35,44 @@ 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;
}
}

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_t allFound = kFALSE;
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 All @@ -91,44 +92,36 @@ 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();
}

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;
}
}

Expand All @@ -150,7 +143,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;
Expand Down
29 changes: 16 additions & 13 deletions fairroot/parbase/FairParSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand All @@ -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];
Expand All @@ -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(); }

Expand All @@ -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