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 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 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 5bb24f7..b7a43d4 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 = 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()); 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 = 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()); 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 = 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()); 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 = 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()); 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 = 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()); auto var_id_x = AddEntry(AnalysisEntry({entries_.back().GetVariables()[0]}, cuts_x)); @@ -140,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; @@ -164,8 +169,15 @@ 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 +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 267692f..bdcaa9e 100644 --- a/src/Task.hpp +++ b/src/Task.hpp @@ -52,9 +52,18 @@ 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 SetTopLevelDirName(const std::string& name) { toplevel_dir_name_ = name; } - void ResetTopLevelDirName() { toplevel_dir_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, 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); @@ -62,18 +71,21 @@ 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; } 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);