Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions examples/get_test_input.sh

This file was deleted.

5 changes: 0 additions & 5 deletions examples/rootlogon.C

This file was deleted.

2 changes: 1 addition & 1 deletion src/EntryConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,4 @@ std::string EntryConfig::GetDirectoryName() const {
return name;
}

} // namespace AnalysisTree::QA
}// namespace AnalysisTree::QA
28 changes: 20 additions & 8 deletions src/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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()));
Expand All @@ -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()));
Expand All @@ -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()));
Expand All @@ -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));
Expand Down Expand Up @@ -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<std::string> result;
std::stringstream ss(str);
std::string item;
Expand All @@ -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
20 changes: 16 additions & 4 deletions src/Task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,40 @@ class Task : public AnalysisTask {
size_t AddIntegral(const Axis& x, const Axis& y, Cuts* cuts_x = nullptr, Cuts* cuts_y = nullptr);

std::vector<EntryConfig>& 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);
TDirectory* MkMultiLevelDir(TFile* file, const std::string& name) const;

template<typename T>
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<EntryConfig> entries_{};
std::map<std::string, TDirectory*> 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);
Expand Down