Skip to content

Commit

Permalink
Add possibility to store canvases in single PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
wiechula committed Dec 19, 2024
1 parent 545e609 commit 7695af3
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions Detectors/TPC/base/src/Utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,47 @@ void utils::addFECInfo()
h->SetTitle(title.data());
}

void utils::saveCanvases(TObjArray& arr, std::string_view outDir, std::string_view types, std::string_view rootFileName, std::string nameAdd)
void utils::saveCanvases(TObjArray& arr, std::string_view outDir, std::string_view types, std::string_view singleOutFileName, std::string nameAdd)
{
if (types.size()) {
for (auto c : arr) {
utils::saveCanvas(*static_cast<TCanvas*>(c), outDir, types, nameAdd);
}
}

if (rootFileName.size()) {
std::unique_ptr<TFile> outFile(TFile::Open(fmt::format("{}/{}", outDir, rootFileName).data(), "recreate"));
arr.Write(arr.GetName(), TObject::kSingleKey);
outFile->Close();
if (singleOutFileName.size()) {
const auto outFileNames = o2::utils::Str::tokenize(singleOutFileName.data(), ',');
for (const auto& outFileName : outFileNames) {
auto fileName = fmt::format("{}/{}", outDir, outFileName);
if (o2::utils::Str::endsWith(outFileName, ".root")) {
std::unique_ptr<TFile> outFile(TFile::Open(fileName.data(), "recreate"));
arr.Write(arr.GetName(), TObject::kSingleKey);
outFile->Close();
} else if (o2::utils::Str::endsWith(outFileName, ".pdf")) {
const auto nCanv = arr.GetEntries();
for (int i = 0; i < nCanv; ++i) {
auto fileName2 = fileName;
if (i == 0) {
fileName2 += "(";
} else if (i == nCanv - 1) {
fileName2 += ")";
}
auto c = static_cast<TCanvas*>(arr.UncheckedAt(i));
c->Print(fileName2.data(), fmt::format("Title:{}", c->GetTitle()).data());
}
}
}
}
}

void utils::saveCanvases(std::vector<TCanvas*>& canvases, std::string_view outDir, std::string_view types, std::string_view rootFileName, std::string nameAdd)
void utils::saveCanvases(std::vector<TCanvas*>& canvases, std::string_view outDir, std::string_view types, std::string_view singleOutFileName, std::string nameAdd)
{
TObjArray arr;
for (auto c : canvases) {
arr.Add(c);
}

saveCanvases(arr, outDir, types, rootFileName, nameAdd);
saveCanvases(arr, outDir, types, singleOutFileName, nameAdd);
}

void utils::saveCanvas(TCanvas& c, std::string_view outDir, std::string_view types, std::string nameAdd)
Expand Down

0 comments on commit 7695af3

Please sign in to comment.