From e3603822722b72105e3d609e0545380fa3c0636c Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 4 Apr 2025 19:06:53 +0200 Subject: [PATCH 1/7] do not complicate dir path if top level dir is set --- src/Task.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index 5bb24f7..017ab27 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -8,7 +8,8 @@ size_t Task::AddH1(const std::string& name, const Axis& x, Cuts* cuts, Variable CreateOutputFileIfNotYet(); weight.IfEmptyVariableConvertToOnes(x); entries_.emplace_back(x, weight, name, cuts, false); - TDirectory* dir = MkMultiLevelDir(out_file_, toplevel_dir_name_ + "/" + entries_.back().GetDirectoryName()); + const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; + TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); auto var_id = AddEntry(AnalysisEntry(entries_.back().GetVariables(), entries_.back().GetEntryCuts(), entries_.back().GetVariableForWeight())); @@ -24,7 +25,8 @@ size_t Task::AddH2(const std::string& name, const Axis& x, const Axis& y, Cuts* CreateOutputFileIfNotYet(); weight.IfEmptyVariableConvertToOnes(x); entries_.emplace_back(x, y, weight, name, cuts); - TDirectory* dir = MkMultiLevelDir(out_file_, toplevel_dir_name_ + "/" + entries_.back().GetDirectoryName()); + const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; + TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); auto var_id = AddEntry(AnalysisEntry(entries_.back().GetVariables(), entries_.back().GetEntryCuts(), entries_.back().GetVariableForWeight())); @@ -40,7 +42,8 @@ size_t Task::AddProfile(const std::string& name, const Axis& x, const Axis& y, C CreateOutputFileIfNotYet(); weight.IfEmptyVariableConvertToOnes(x); entries_.emplace_back(x, y, weight, name, cuts, true); - TDirectory* dir = MkMultiLevelDir(out_file_, toplevel_dir_name_ + "/" + entries_.back().GetDirectoryName()); + const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; + TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); auto var_id = AddEntry(AnalysisEntry(entries_.back().GetVariables(), entries_.back().GetEntryCuts(), entries_.back().GetVariableForWeight())); @@ -56,7 +59,8 @@ size_t Task::AddIntegral(const std::string& name, const Axis& x, Cuts* cuts, Var CreateOutputFileIfNotYet(); weight.IfEmptyVariableConvertToOnes(x); entries_.emplace_back(x, weight, name, cuts, true); - TDirectory* dir = MkMultiLevelDir(out_file_, toplevel_dir_name_ + "/" + entries_.back().GetDirectoryName()); + const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; + TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); auto var_id = AddEntry(AnalysisEntry(entries_.back().GetVariables(), entries_.back().GetEntryCuts(), entries_.back().GetVariableForWeight())); @@ -71,7 +75,8 @@ size_t Task::AddIntegral(const Axis& x, Cuts* cuts, Variable weight) { size_t Task::AddIntegral(const Axis& x, const Axis& y, Cuts* cuts_x, Cuts* cuts_y) { CreateOutputFileIfNotYet(); entries_.emplace_back(x, cuts_x, y, cuts_y); - TDirectory* dir = MkMultiLevelDir(out_file_, toplevel_dir_name_ + "/" + entries_.back().GetDirectoryName()); + const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; + TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); auto var_id_x = AddEntry(AnalysisEntry({entries_.back().GetVariables()[0]}, cuts_x)); From 006570c0078ca9883347221a1fcbdda513e7767f Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 4 Apr 2025 19:15:15 +0200 Subject: [PATCH 2/7] remove rootlogon.C --- examples/rootlogon.C | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 examples/rootlogon.C diff --git a/examples/rootlogon.C b/examples/rootlogon.C deleted file mode 100644 index 8765e0f..0000000 --- a/examples/rootlogon.C +++ /dev/null @@ -1,5 +0,0 @@ -{ - gSystem->Load("libAnalysisTreeBase"); - gSystem->Load("libAnalysisTreeInfra"); - gSystem->Load("libAnalysisTreeQA"); -} \ No newline at end of file From 7998640c1d097359662b8a5e2de283099fc517a8 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 2 May 2025 16:14:54 +0200 Subject: [PATCH 3/7] enable update of the output file (in addition to recreate=default) --- src/Task.cpp | 2 +- src/Task.hpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index 017ab27..c9ec5fe 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -169,7 +169,7 @@ TDirectory* Task::MkMultiLevelDir(TFile* file, const std::string& name) const { } void Task::CreateOutputFileIfNotYet() { - if (out_file_ == nullptr) out_file_ = new TFile(out_file_name_.c_str(), "recreate"); + if (out_file_ == nullptr) out_file_ = new TFile(out_file_name_.c_str(), out_file_option_.c_str()); } } // namespace AnalysisTree::QA diff --git a/src/Task.hpp b/src/Task.hpp index 267692f..90b5faa 100644 --- a/src/Task.hpp +++ b/src/Task.hpp @@ -52,7 +52,10 @@ class Task : public AnalysisTask { size_t AddIntegral(const Axis& x, const Axis& y, Cuts* cuts_x = nullptr, Cuts* cuts_y = nullptr); std::vector& Entries() { return entries_; } - void SetOutputFileName(std::string name) { out_file_name_ = std::move(name); } + void SetOutputFileName(std::string name, std::string option="recreate") { + out_file_name_ = std::move(name); + out_file_option_ = std::move(option); + } void SetTopLevelDirName(const std::string& name) { toplevel_dir_name_ = name; } void ResetTopLevelDirName() { toplevel_dir_name_ = ""; } @@ -73,6 +76,7 @@ class Task : public AnalysisTask { std::vector entries_{}; std::map dir_map_{}; std::string out_file_name_{"QA.root"}; + std::string out_file_option_{"recreate"}; std::string toplevel_dir_name_{""}; TFile* out_file_{nullptr}; From 279f77c6387e2bfa6660122122e9ca2075e3acc1 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Fri, 2 May 2025 16:16:53 +0200 Subject: [PATCH 4/7] apply clang-format --- src/EntryConfig.cpp | 2 +- src/Task.cpp | 15 +++++++-------- src/Task.hpp | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/EntryConfig.cpp b/src/EntryConfig.cpp index 4ac232f..0177301 100644 --- a/src/EntryConfig.cpp +++ b/src/EntryConfig.cpp @@ -175,4 +175,4 @@ std::string EntryConfig::GetDirectoryName() const { return name; } -} // namespace AnalysisTree::QA +}// namespace AnalysisTree::QA diff --git a/src/Task.cpp b/src/Task.cpp index c9ec5fe..4523c42 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -9,7 +9,7 @@ size_t Task::AddH1(const std::string& name, const Axis& x, Cuts* cuts, Variable weight.IfEmptyVariableConvertToOnes(x); entries_.emplace_back(x, weight, name, cuts, false); const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; - TDirectory* dir = MkMultiLevelDir(out_file_, dirName); + TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); auto var_id = AddEntry(AnalysisEntry(entries_.back().GetVariables(), entries_.back().GetEntryCuts(), entries_.back().GetVariableForWeight())); @@ -26,7 +26,7 @@ size_t Task::AddH2(const std::string& name, const Axis& x, const Axis& y, Cuts* weight.IfEmptyVariableConvertToOnes(x); entries_.emplace_back(x, y, weight, name, cuts); const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; - TDirectory* dir = MkMultiLevelDir(out_file_, dirName); + TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); auto var_id = AddEntry(AnalysisEntry(entries_.back().GetVariables(), entries_.back().GetEntryCuts(), entries_.back().GetVariableForWeight())); @@ -43,7 +43,7 @@ size_t Task::AddProfile(const std::string& name, const Axis& x, const Axis& y, C weight.IfEmptyVariableConvertToOnes(x); entries_.emplace_back(x, y, weight, name, cuts, true); const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; - TDirectory* dir = MkMultiLevelDir(out_file_, dirName); + TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); auto var_id = AddEntry(AnalysisEntry(entries_.back().GetVariables(), entries_.back().GetEntryCuts(), entries_.back().GetVariableForWeight())); @@ -60,7 +60,7 @@ size_t Task::AddIntegral(const std::string& name, const Axis& x, Cuts* cuts, Var weight.IfEmptyVariableConvertToOnes(x); entries_.emplace_back(x, weight, name, cuts, true); const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; - TDirectory* dir = MkMultiLevelDir(out_file_, dirName); + TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); auto var_id = AddEntry(AnalysisEntry(entries_.back().GetVariables(), entries_.back().GetEntryCuts(), entries_.back().GetVariableForWeight())); @@ -76,7 +76,7 @@ size_t Task::AddIntegral(const Axis& x, const Axis& y, Cuts* cuts_x, Cuts* cuts_ CreateOutputFileIfNotYet(); entries_.emplace_back(x, cuts_x, y, cuts_y); const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; - TDirectory* dir = MkMultiLevelDir(out_file_, dirName); + TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); auto var_id_x = AddEntry(AnalysisEntry({entries_.back().GetVariables()[0]}, cuts_x)); @@ -145,7 +145,7 @@ void Task::Finish() { } TDirectory* Task::MkMultiLevelDir(TFile* file, const std::string& name) const { - auto splitBySlash = [] (const std::string& str) { + auto splitBySlash = [](const std::string& str) { std::vector result; std::stringstream ss(str); std::string item; @@ -172,5 +172,4 @@ void Task::CreateOutputFileIfNotYet() { if (out_file_ == nullptr) out_file_ = new TFile(out_file_name_.c_str(), out_file_option_.c_str()); } -} // namespace AnalysisTree::QA - +}// namespace AnalysisTree::QA diff --git a/src/Task.hpp b/src/Task.hpp index 90b5faa..0210aea 100644 --- a/src/Task.hpp +++ b/src/Task.hpp @@ -52,7 +52,7 @@ class Task : public AnalysisTask { size_t AddIntegral(const Axis& x, const Axis& y, Cuts* cuts_x = nullptr, Cuts* cuts_y = nullptr); std::vector& Entries() { return entries_; } - void SetOutputFileName(std::string name, std::string option="recreate") { + void SetOutputFileName(std::string name, std::string option = "recreate") { out_file_name_ = std::move(name); out_file_option_ = std::move(option); } @@ -65,7 +65,7 @@ class Task : public AnalysisTask { template TDirectory* MkDirIfNotExists(T* fod, std::string name) const { - if(fod == nullptr) throw std::runtime_error("Task::MkDirIfNotExists(): file or directory ptr is null"); + if (fod == nullptr) throw std::runtime_error("Task::MkDirIfNotExists(): file or directory ptr is null"); TDirectory* result = fod->GetDirectory(name.c_str()); if (result == nullptr) result = fod->mkdir(name.c_str()); return result; From 02ddf88c0873ede0bf3dd2ec65c8c9267d881fe1 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Thu, 8 May 2025 17:13:34 +0200 Subject: [PATCH 5/7] rm obsolete script --- examples/get_test_input.sh | 6 ------ 1 file changed, 6 deletions(-) delete mode 100755 examples/get_test_input.sh diff --git a/examples/get_test_input.sh b/examples/get_test_input.sh deleted file mode 100755 index e4dfdd5..0000000 --- a/examples/get_test_input.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -mkdir -p data/analysistree -rsync -av /u/klochkov/temp/temp/atree/1.analysistree.root data/analysistree/ - -ls -d data/analysistree/ > data/filelist.txt \ No newline at end of file From 9c94753d56388da9362cefb54a5a00dd656c8b12 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Wed, 9 Jul 2025 19:20:32 +0200 Subject: [PATCH 6/7] make optional appending toplevel_dir_name_ with entry name --- src/Task.cpp | 18 +++++++++++++----- src/Task.hpp | 12 ++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index 4523c42..5052063 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -8,7 +8,7 @@ size_t Task::AddH1(const std::string& name, const Axis& x, Cuts* cuts, Variable CreateOutputFileIfNotYet(); weight.IfEmptyVariableConvertToOnes(x); entries_.emplace_back(x, weight, name, cuts, false); - const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; + const std::string dirName = ConstructOutputDirectoryName(); TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); @@ -25,7 +25,7 @@ size_t Task::AddH2(const std::string& name, const Axis& x, const Axis& y, Cuts* CreateOutputFileIfNotYet(); weight.IfEmptyVariableConvertToOnes(x); entries_.emplace_back(x, y, weight, name, cuts); - const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; + const std::string dirName = ConstructOutputDirectoryName(); TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); @@ -42,7 +42,7 @@ size_t Task::AddProfile(const std::string& name, const Axis& x, const Axis& y, C CreateOutputFileIfNotYet(); weight.IfEmptyVariableConvertToOnes(x); entries_.emplace_back(x, y, weight, name, cuts, true); - const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; + const std::string dirName = ConstructOutputDirectoryName(); TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); @@ -59,7 +59,7 @@ size_t Task::AddIntegral(const std::string& name, const Axis& x, Cuts* cuts, Var CreateOutputFileIfNotYet(); weight.IfEmptyVariableConvertToOnes(x); entries_.emplace_back(x, weight, name, cuts, true); - const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; + const std::string dirName = ConstructOutputDirectoryName(); TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); @@ -75,7 +75,7 @@ size_t Task::AddIntegral(const Axis& x, Cuts* cuts, Variable weight) { size_t Task::AddIntegral(const Axis& x, const Axis& y, Cuts* cuts_x, Cuts* cuts_y) { CreateOutputFileIfNotYet(); entries_.emplace_back(x, cuts_x, y, cuts_y); - const std::string dirName = toplevel_dir_name_.empty() ? entries_.back().GetDirectoryName() : toplevel_dir_name_; + const std::string dirName = ConstructOutputDirectoryName(); TDirectory* dir = MkMultiLevelDir(out_file_, dirName); ANALYSISTREE_UTILS_VISIT(setdirectory_struct(dir), entries_.back().GetPlot()); ANALYSISTREE_UTILS_VISIT(setname_struct(entries_.back().GetName()), entries_.back().GetPlot()); @@ -172,4 +172,12 @@ void Task::CreateOutputFileIfNotYet() { if (out_file_ == nullptr) out_file_ = new TFile(out_file_name_.c_str(), out_file_option_.c_str()); } +std::string Task::ConstructOutputDirectoryName() { + const std::string entryName = entries_.back().GetDirectoryName(); + std::string dirName = toplevel_dir_name_.empty() ? entryName : toplevel_dir_name_; + if(is_append_dir_name_with_entry_name_ && !toplevel_dir_name_.empty()) dirName.append("/" + entryName); + + return dirName; +} + }// namespace AnalysisTree::QA diff --git a/src/Task.hpp b/src/Task.hpp index 0210aea..3957e30 100644 --- a/src/Task.hpp +++ b/src/Task.hpp @@ -56,8 +56,14 @@ class Task : public AnalysisTask { out_file_name_ = std::move(name); out_file_option_ = std::move(option); } - void SetTopLevelDirName(const std::string& name) { toplevel_dir_name_ = name; } - void ResetTopLevelDirName() { toplevel_dir_name_ = ""; } + void SetTopLevelDirName(const std::string& name, bool is_append_dir_name_with_entry_name=false) { + toplevel_dir_name_ = name; + is_append_dir_name_with_entry_name_ = is_append_dir_name_with_entry_name; + } + void ResetTopLevelDirName() { + toplevel_dir_name_ = ""; + is_append_dir_name_with_entry_name_ = false; + } private: void FillIntegral(EntryConfig& plot); @@ -72,12 +78,14 @@ class Task : public AnalysisTask { } void CreateOutputFileIfNotYet(); + std::string ConstructOutputDirectoryName(); std::vector entries_{}; std::map dir_map_{}; std::string out_file_name_{"QA.root"}; std::string out_file_option_{"recreate"}; std::string toplevel_dir_name_{""}; + bool is_append_dir_name_with_entry_name_{false}; TFile* out_file_{nullptr}; ClassDefOverride(Task, 1); From ef749c06727dd0263fc74e83af84590cc1d45f8a Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Wed, 9 Jul 2025 19:23:22 +0200 Subject: [PATCH 7/7] apply clang format --- src/Task.cpp | 2 +- src/Task.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index 5052063..b7a43d4 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -175,7 +175,7 @@ void Task::CreateOutputFileIfNotYet() { std::string Task::ConstructOutputDirectoryName() { const std::string entryName = entries_.back().GetDirectoryName(); std::string dirName = toplevel_dir_name_.empty() ? entryName : toplevel_dir_name_; - if(is_append_dir_name_with_entry_name_ && !toplevel_dir_name_.empty()) dirName.append("/" + entryName); + if (is_append_dir_name_with_entry_name_ && !toplevel_dir_name_.empty()) dirName.append("/" + entryName); return dirName; } diff --git a/src/Task.hpp b/src/Task.hpp index 3957e30..bdcaa9e 100644 --- a/src/Task.hpp +++ b/src/Task.hpp @@ -56,7 +56,7 @@ class Task : public AnalysisTask { out_file_name_ = std::move(name); out_file_option_ = std::move(option); } - void SetTopLevelDirName(const std::string& name, bool is_append_dir_name_with_entry_name=false) { + void SetTopLevelDirName(const std::string& name, bool is_append_dir_name_with_entry_name = false) { toplevel_dir_name_ = name; is_append_dir_name_with_entry_name_ = is_append_dir_name_with_entry_name; }