Skip to content

Commit 366d75e

Browse files
committed
Add possibility to store canvases in single PDF
1 parent 0a49d52 commit 366d75e

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

Detectors/TPC/base/src/Utils.cxx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,47 @@ void utils::addFECInfo()
133133
h->SetTitle(title.data());
134134
}
135135

136-
void utils::saveCanvases(TObjArray& arr, std::string_view outDir, std::string_view types, std::string_view rootFileName, std::string nameAdd)
136+
void utils::saveCanvases(TObjArray& arr, std::string_view outDir, std::string_view types, std::string_view singleOutFileName, std::string nameAdd)
137137
{
138138
if (types.size()) {
139139
for (auto c : arr) {
140140
utils::saveCanvas(*static_cast<TCanvas*>(c), outDir, types, nameAdd);
141141
}
142142
}
143143

144-
if (rootFileName.size()) {
145-
std::unique_ptr<TFile> outFile(TFile::Open(fmt::format("{}/{}", outDir, rootFileName).data(), "recreate"));
146-
arr.Write(arr.GetName(), TObject::kSingleKey);
147-
outFile->Close();
144+
if (singleOutFileName.size()) {
145+
const auto outFileNames = o2::utils::Str::tokenize(singleOutFileName.data(), ',');
146+
for (const auto& outFileName : outFileNames) {
147+
auto fileName = fmt::format("{}/{}", outDir, outFileName);
148+
if (o2::utils::Str::endsWith(outFileName, ".root")) {
149+
std::unique_ptr<TFile> outFile(TFile::Open(fileName.data(), "recreate"));
150+
arr.Write(arr.GetName(), TObject::kSingleKey);
151+
outFile->Close();
152+
} else if (o2::utils::Str::endsWith(outFileName, ".pdf")) {
153+
const auto nCanv = arr.GetEntries();
154+
for (int i = 0; i < nCanv; ++i) {
155+
auto fileName2 = fileName;
156+
if (i == 0) {
157+
fileName2 += "(";
158+
} else if (i == nCanv - 1) {
159+
fileName2 += ")";
160+
}
161+
auto c = static_cast<TCanvas*>(arr.UncheckedAt(i));
162+
c->Print(fileName2.data(), fmt::format("Title:{}", c->GetTitle()).data());
163+
}
164+
}
165+
}
148166
}
149167
}
150168

151-
void utils::saveCanvases(std::vector<TCanvas*>& canvases, std::string_view outDir, std::string_view types, std::string_view rootFileName, std::string nameAdd)
169+
void utils::saveCanvases(std::vector<TCanvas*>& canvases, std::string_view outDir, std::string_view types, std::string_view singleOutFileName, std::string nameAdd)
152170
{
153171
TObjArray arr;
154172
for (auto c : canvases) {
155173
arr.Add(c);
156174
}
157175

158-
saveCanvases(arr, outDir, types, rootFileName, nameAdd);
176+
saveCanvases(arr, outDir, types, singleOutFileName, nameAdd);
159177
}
160178

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

0 commit comments

Comments
 (0)