43 explicit VectorConfig(
const MapType& map) : map_(map), size_(map.size()) {}
49 virtual void AddField(
const std::string& name,
const std::string& title) {
50 map_.insert(std::make_pair(name,
ConfigElement(size_++, title)));
52 virtual void AddField(
const std::string& name, ShortInt_t
id,
const std::string& title) {
55 void AddField(
const std::string& name,
const ConfigElement& field) {
56 map_.insert(std::make_pair(name, field));
58 virtual void AddFields(
const std::vector<std::string>& names,
const std::string& title) {
59 for (
const auto& name : names) {
60 map_.insert(std::make_pair(name,
ConfigElement(size_++, title)));
64 ANALYSISTREE_ATTR_NODISCARD ShortInt_t GetId(
const std::string& sField)
const {
65 auto search = map_.find(sField);
66 if (search != map_.end()) {
67 return search->second.id_;
69 return UndefValueShort;
73 ANALYSISTREE_ATTR_NODISCARD
virtual const MapType& GetMap()
const {
return map_; }
74 ANALYSISTREE_ATTR_NODISCARD
virtual ShortInt_t GetSize()
const {
return size_; }
76 virtual void Print()
const {
77 if (map_.empty())
return;
79 auto print_row = [](
const std::vector<std::pair<std::string, int>>& elements) {
80 for (
const auto& el : elements) {
81 std::cout << std::left << std::setw(el.second) << std::setfill(
' ') << el.first;
83 std::cout << std::endl;
87 for (
const auto& entry : map_) {
88 name_strlen = std::max(name_strlen, (
int) entry.first.length());
92 print_row({{
"Id", 10}, {
"Name", name_strlen}, {
"Info", 50}});
93 for (
const auto& entry : map_) {
94 if (entry.second.title_.find(
"\n") == std::string::npos) {
95 print_row({{std::to_string(entry.second.id_), 10}, {entry.first, name_strlen}, {entry.second.title_, 50}});
97 auto est = SplitString(entry.second.title_);
98 print_row({{std::to_string(entry.second.id_), 10}, {entry.first, name_strlen}, {est.at(0), 50}});
99 for (
int iest = 1; iest < est.size(); ++iest) {
100 print_row({{
"", 10}, {
"", name_strlen}, {est.at(iest), 50}});
107 static std::vector<std::string> SplitString(
const std::string& input);
108 void RemoveField(
const std::string& name,
int id);
128 BranchConfig(std::string name, DetType type, std::string title =
"");
130 void Print()
const override;
132 void PrintBranchId()
const;
134 ANALYSISTREE_ATTR_NODISCARD Types GetFieldType(
const std::string& sField)
const;
135 ANALYSISTREE_ATTR_NODISCARD ShortInt_t GetFieldId(
const std::string& sField)
const;
139 void AddField(
const std::string& name,
const std::string& title =
"") {
140 GuaranteeFieldNameVacancy(name);
144 void AddFields(
const std::vector<std::string>& names,
const std::string& title =
"") {
145 for (
auto& n : names) {
146 GuaranteeFieldNameVacancy(n);
151 void AddField(
const std::string& name, ShortInt_t
id,
const std::string& title =
"") {
152 GuaranteeFieldNameVacancy(name);
156 void RemoveField(
const std::string& name);
158 void RemoveFields(
const std::vector<std::string>& names) {
159 for (
auto& n : names) {
164 void SetTitle(std::string title) { title_ = std::move(title); }
172 ANALYSISTREE_ATTR_NODISCARD std::string GetName()
const {
return name_; }
173 ANALYSISTREE_ATTR_NODISCARD std::string GetTitle()
const {
return title_; }
176 ANALYSISTREE_ATTR_NODISCARD std::vector<std::string> GetFieldsNamesT()
const {
177 std::vector<std::string> result;
178 std::transform(begin(GetMap<T>()), end(GetMap<T>()), back_inserter(result),
179 [](
const typename MapType::value_type& elem) {
return elem.first; });
182 ANALYSISTREE_ATTR_NODISCARD
size_t GetId()
const {
return id_; }
183 ANALYSISTREE_ATTR_NODISCARD DetType GetType()
const {
return type_; }
190 ANALYSISTREE_ATTR_NODISCARD
BranchConfig Clone(
const std::string& name, DetType type)
const;
194 bool HasField(
const std::string& field)
const {
return GetFieldId(field) != UndefValueShort; }
199 void GuaranteeFieldNameVacancy(
const std::string& name)
const;
204 DetType type_{DetType(UndefValueShort)};
ANALYSISTREE_ATTR_NODISCARD BranchConfig Clone(const std::string &name, DetType type) const
Creates a copy with different name and/or detector type.
Definition BranchConfig.cpp:90