Skip to content

Commit bdd262f

Browse files
wiechulashahor02
authored andcommitted
TPC: small fixes
* pass by referenc * fix output file name * only save if formats are given
1 parent c70258a commit bdd262f

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Detectors/TPC/base/include/TPCBase/Utils.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ class TCanvas;
2727
class TH1;
2828
class TChain;
2929

30-
namespace o2
31-
{
32-
namespace tpc
30+
namespace o2::tpc
3331
{
3432

3533
/// \namespace utils
@@ -47,7 +45,7 @@ const std::vector<std::string> tokenize(const std::string_view input, const std:
4745
TH1* getBinInfoXY(int& binx, int& biny, float& bincx, float& bincy);
4846
void addFECInfo();
4947
void saveCanvases(TObjArray& arr, std::string_view outDir, std::string_view types = "png,pdf", std::string_view rootFileName = "");
50-
void saveCanvases(std::vector<TCanvas*> canvases, std::string_view outDir, std::string_view types = "png,pdf", std::string_view rootFileName = "");
48+
void saveCanvases(std::vector<TCanvas*>& canvases, std::string_view outDir, std::string_view types = "png,pdf", std::string_view rootFileName = "");
5149
void saveCanvas(TCanvas& c, std::string_view outDir, std::string_view types);
5250
std::vector<CalPad*> readCalPads(const std::string_view fileName, const std::vector<std::string>& calPadNames);
5351
std::vector<CalPad*> readCalPads(const std::string_view fileName, const std::string_view calPadNames);
@@ -72,7 +70,6 @@ void mergeCalPads(std::string_view outputFileName, std::string_view inputFileNam
7270
TChain* buildChain(std::string_view command, std::string_view treeName, std::string_view treeTitle);
7371

7472
} // namespace utils
75-
} // namespace tpc
76-
} // namespace o2
73+
} // namespace o2::tpc
7774

7875
#endif

Detectors/TPC/base/src/Utils.cxx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,20 @@ void utils::addFECInfo()
121121

122122
void utils::saveCanvases(TObjArray& arr, std::string_view outDir, std::string_view types, std::string_view rootFileName)
123123
{
124-
for (auto c : arr) {
125-
utils::saveCanvas(*static_cast<TCanvas*>(c), outDir, types);
124+
if (types.size()) {
125+
for (auto c : arr) {
126+
utils::saveCanvas(*static_cast<TCanvas*>(c), outDir, types);
127+
}
126128
}
127129

128130
if (rootFileName.size()) {
129-
std::unique_ptr<TFile> outFile(TFile::Open(fmt::format("{}/NoiseAndPedestalCanvases.root", outDir).data(), "recreate"));
131+
std::unique_ptr<TFile> outFile(TFile::Open(fmt::format("{}/{}", outDir, rootFileName).data(), "recreate"));
130132
arr.Write(arr.GetName(), TObject::kSingleKey);
131133
outFile->Close();
132134
}
133135
}
134136

135-
void utils::saveCanvases(std::vector<TCanvas*> canvases, std::string_view outDir, std::string_view types, std::string_view rootFileName)
137+
void utils::saveCanvases(std::vector<TCanvas*>& canvases, std::string_view outDir, std::string_view types, std::string_view rootFileName)
136138
{
137139
TObjArray arr;
138140
for (auto c : canvases) {
@@ -144,6 +146,9 @@ void utils::saveCanvases(std::vector<TCanvas*> canvases, std::string_view outDir
144146

145147
void utils::saveCanvas(TCanvas& c, std::string_view outDir, std::string_view types)
146148
{
149+
if (!types.size()) {
150+
return;
151+
}
147152
const auto typesVec = tokenize(types, ",");
148153
for (const auto& type : typesVec) {
149154
c.SaveAs(fmt::format("{}/{}.{}", outDir, c.GetName(), type).data());

0 commit comments

Comments
 (0)