AnalysisTree
Loading...
Searching...
No Matches
Configuration.hpp
1/* Copyright (C) 2019-2021 GSI, Universität Tübingen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Viktor Klochkov, Ilya Selyuzhenkov */
4
5#ifndef ANALYSISTREE_CONFIGURATION_H
6#define ANALYSISTREE_CONFIGURATION_H
7
8#include <array>
9#include <map>
10#include <string>
11#include <utility>
12#include <vector>
13
14#include <TObject.h>
15
16#include "BranchConfig.hpp"
17
18namespace AnalysisTree {
19
20class Matching;
21
24 public:
25 MatchingConfig() = default;
26 MatchingConfig(std::string Branch1,
27 std::string Branch2,
28 std::string DataBranch) : branch1_(std::move(Branch1)), branch2_(std::move(Branch2)), data_branch_(std::move(DataBranch)) {}
29
30 [[nodiscard]] std::string GetFirstBranchName() const { return branch1_; }
31 [[nodiscard]] std::string GetSecondBranchName() const { return branch2_; }
32 [[nodiscard]] std::string GetDataBranchName() const { return data_branch_; }
33
34 private:
35 std::string branch1_;
36 std::string branch2_;
37 std::string data_branch_;
38
39 ClassDefNV(MatchingConfig, 2);
40};
41
43class Configuration_v3 : public TObject {
44 public:
45 std::string name_;
46 std::map<size_t, BranchConfig> branches_{};
47 std::map<std::array<std::string, 2>, std::string> matches_{};
48
49 ClassDef(Configuration_v3, 1);
50};
51
53
58class Configuration : public TObject {
59
60 public:
61 using MatchingIndex = std::map<std::array<std::string, 2>, std::string>;
62
63 Configuration() = default;
64 explicit Configuration(std::string name) : name_(std::move(name)){};
65 Configuration(const Configuration&) = default;
66 Configuration(Configuration&&) = default;
67 Configuration& operator=(Configuration&&) = default;
68 Configuration& operator=(const Configuration&) = default;
69
70 void AddBranchConfig(const BranchConfig& branch) {
71 branches_.emplace(branch.GetId(), branch);
72 }
73
74 void RemoveBranchConfig(const std::string& branchname);
75
76 [[nodiscard]] std::vector<std::string> GetMatchesOfBranch(const std::string& branchname) const;
77
78 void AddMatch(Matching* match);
79
80 void AddMatch(const MatchingConfig& matching_config);
81
82 ANALYSISTREE_ATTR_NODISCARD BranchConfig& GetBranchConfig(const std::string& name);
83 ANALYSISTREE_ATTR_NODISCARD const BranchConfig& GetBranchConfig(const std::string& name) const;
84 ANALYSISTREE_ATTR_NODISCARD const BranchConfig& GetBranchConfig(size_t i) const {
85 auto it = branches_.find(i);
86 if (it == branches_.end()) {
87 throw std::runtime_error("Branch with id = " + std::to_string(i) + " not found");
88 }
89 return it->second;
90 }
91 ANALYSISTREE_ATTR_NODISCARD const std::map<size_t, BranchConfig>& GetBranchConfigs() const { return branches_; }
92 ANALYSISTREE_ATTR_NODISCARD const std::vector<MatchingConfig>& GetMatchingConfigs() const { return matches_; }
93 ANALYSISTREE_ATTR_NODISCARD unsigned int GetNumberOfBranches() const { return branches_.size(); }
94
95 ANALYSISTREE_ATTR_NODISCARD const std::string& GetMatchName(const std::string& br1, const std::string& br2) const;
96 ANALYSISTREE_ATTR_NODISCARD std::pair<std::string, bool> GetMatchInfo(const std::string& br1, const std::string& br2) const;
97 ANALYSISTREE_ATTR_NODISCARD const MatchingIndex& GetMatches() const { return matches_index_; }
98
99 void Print(Option_t* = "") const;
100
101 void PrintBranchIds() const;
102
103 static MatchingIndex MakeMatchingIndex(const std::vector<MatchingConfig>& matches) {
104 MatchingIndex result;
105 for (auto& match : matches) {
106 std::array<std::string, 2> map_key{match.GetFirstBranchName(), match.GetSecondBranchName()};
107 auto emplace_result = result.emplace(map_key, match.GetDataBranchName());
108 if (!emplace_result.second) {
109 throw std::runtime_error("Two matches with same first and second branch added");
110 }
111 }
112 return result;
113 }
114
115 static std::vector<MatchingConfig> MakeMatchConfigsFromIndex(const MatchingIndex& matching_index) {
116 std::vector<MatchingConfig> result;
117 for (auto& matching_index_element : matching_index) {
118 result.emplace_back(matching_index_element.first[0],
119 matching_index_element.first[1],
120 matching_index_element.second);
121 }
122 return result;
123 }
124
125 [[nodiscard]] std::vector<std::string> GetListOfBranches() const;
126
132 void Merge(const Configuration& other) {
133 for (auto& other_branch : other.branches_) {
134 const auto other_id = other_branch.second.GetId();
135 const auto other_name = other_branch.second.GetName();
136 for (auto& local_branch : branches_) {
137 if (other_id == local_branch.second.GetId()) {
138 throw std::runtime_error("Configurations contain branches with the same id-s");
139 }
140 if (other_name == local_branch.second.GetName()) {
141 throw std::runtime_error("Configurations contain branches with the same names");
142 }
143 }
145 branches_.emplace(other_branch);
146 }
147 }
148
149 protected:
150 std::string name_;
151 std::map<size_t, BranchConfig> branches_{};
152 std::vector<MatchingConfig> matches_{};
153
154 MatchingIndex matches_index_{};
155
156 void AddMatch(const std::string& br1, const std::string& br2, const std::string& data_branch);
157
158 ClassDef(Configuration, 4)
159};
160
161}// namespace AnalysisTree
162#endif//ANALYSISTREE_CONFIGURATION_H
A class to store configuration of the Container.
Definition BranchConfig.hpp:118
Some ROOT magic, ask Eugeny.
Definition Configuration.hpp:43
A class to store configuration of the whole AnalysisTree object.
Definition Configuration.hpp:58
void Merge(const Configuration &other)
Merge two configurations without reindexing of the branches THIS FUNCTION IS USED IN THE Infra v1.
Definition Configuration.hpp:132
Information to store about Matching.
Definition Configuration.hpp:23
Definition Matching.hpp:17
Cuts keep list of SimpleCuts. Logical AND is applied for all SimpleCut in the Cuts object.
Definition BranchConfig.cpp:10