Skip to content

Commit

Permalink
Adjust object name, add error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wiechula committed Feb 11, 2025
1 parent 43d17e8 commit f4788ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class CalibdEdxCorrection

void clear();

void writeToFile(std::string_view fileName, std::string_view objName = "CalibdEdxCorrection") const;
void loadFromFile(std::string_view fileName, std::string_view objName = "CalibdEdxCorrection");
void writeToFile(std::string_view fileName, std::string_view objName = "ccdb_object") const;
void loadFromFile(std::string_view fileName, std::string_view objName = "ccdb_object");

/// \param outFileName name of the output file
void dumpToTree(const char* outFileName = "calib_dedx.root") const;
Expand Down
13 changes: 13 additions & 0 deletions DataFormats/Detectors/TPC/src/CalibdEdxCorrection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <string_view>

// o2 includes
#include "Framework/Logger.h"
#include "DataFormatsTPC/Defs.h"
#include "CommonUtils/TreeStreamRedirector.h"

Expand All @@ -39,15 +40,27 @@ void CalibdEdxCorrection::clear()
void CalibdEdxCorrection::writeToFile(std::string_view fileName, std::string_view objName) const
{
std::unique_ptr<TFile> file(TFile::Open(fileName.data(), "recreate"));
if (!file) {
LOGP(error, "Failed to open file {} for writing", fileName.data());
return;
}

file->WriteObject(this, objName.data());
}

void CalibdEdxCorrection::loadFromFile(std::string_view fileName, std::string_view objName)
{
std::unique_ptr<TFile> file(TFile::Open(fileName.data()));
if (!file || file->IsZombie()) {
LOGP(error, "Failed to open file {}", fileName.data());
return;
}

auto tmp = file->Get<CalibdEdxCorrection>(objName.data());
if (tmp != nullptr) {
*this = *tmp;
} else {
LOGP(error, "Failed to load object with name {} from file {}", objName.data(), fileName.data());
}
}

Expand Down
2 changes: 1 addition & 1 deletion Detectors/TPC/workflow/src/CalibdEdxSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class CalibdEdxDevice : public Task

if (mDumpToFile) {
mCalib->dumpToFile("calibdEdx_Obj.root", "calib");
mCalib->getCalib().writeToFile("calibdEdx.root", "ccdb_object");
mCalib->getCalib().writeToFile("calibdEdx.root");
if (mDumpToFile > 1) {
mCalib->writeTTree("calibdEdx.histo.tree.root");
}
Expand Down

0 comments on commit f4788ab

Please sign in to comment.