From 08a2d48e1ecaf2024581f6e258d91f0aab7732ce Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Mon, 5 Aug 2024 10:34:48 +0200 Subject: [PATCH 1/2] enable fields removing; bugfix PR #125: don't create matching_case var multiple times --- core/BranchConfig.cpp | 29 ++++++++++++++++++++++++++++- core/BranchConfig.hpp | 9 +++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/core/BranchConfig.cpp b/core/BranchConfig.cpp index 3eedf9e5..87e2f042 100644 --- a/core/BranchConfig.cpp +++ b/core/BranchConfig.cpp @@ -128,7 +128,9 @@ BranchConfig BranchConfig::CloneAndMerge(const BranchConfig& attached) const { result.AddField(name2 + "_" + field.first, name2 + ": " + field.second.title_); } - result.AddField("matching_case", "0 - both present, 1 - only first present, 2 - only second present"); + if(type1!=DetType::kEventHeader && attached.GetType()!=DetType::kEventHeader) { + result.AddField("matching_case", "0 - both present, 1 - only first present, 2 - only second present"); + } return result; } @@ -150,6 +152,31 @@ std::vector VectorConfig::SplitString(const std::string& input) return result; } +template +void VectorConfig::RemoveField(const std::string& name, int id) { + auto iter = map_.find(name); + map_.erase(iter); + for(auto& m : map_) { + if(m.second.id_>id) { + m.second.id_ --; + } + } +} + +void BranchConfig::RemoveField(const std::string& name) { + if(!HasField(name)) { + throw std::runtime_error("BranchConfig::RemoveField(): no field " + name + " to be removed"); + } + auto field_type = GetFieldType(name); + auto field_id = GetFieldId(name); + if(field_id<0) { + throw std::runtime_error("BranchConfig::RemoveField(): default field " + name + " cannot be removed"); + } + if(field_type == Types::kInteger) VectorConfig::RemoveField(name, field_id); + if(field_type == Types::kFloat) VectorConfig::RemoveField(name, field_id); + if(field_type == Types::kBool) VectorConfig::RemoveField(name, field_id); +} + void BranchConfig::GuaranteeFieldNameVacancy(const std::string& name) const { if (HasField(name)) { throw std::runtime_error("BranchConfig::GuaranteeFieldNameVacancy(): field " + name + " already exists"); diff --git a/core/BranchConfig.hpp b/core/BranchConfig.hpp index 82637a18..39f7b4fb 100644 --- a/core/BranchConfig.hpp +++ b/core/BranchConfig.hpp @@ -105,6 +105,7 @@ class VectorConfig { protected: static std::vector SplitString(const std::string& input); + void RemoveField(const std::string& name, int id); MapType map_{}; ShortInt_t size_{0}; ClassDef(VectorConfig, 2) @@ -150,6 +151,14 @@ class BranchConfig : public VectorConfig, public VectorConfig, publi VectorConfig::AddField(name, id, title); } + void RemoveField(const std::string& name); + + void RemoveFields(const std::vector& names) { + for(auto& n : names) { + RemoveField(n); + } + } + // Getters template ANALYSISTREE_ATTR_NODISCARD const MapType& GetMap() const { return VectorConfig::GetMap(); } From 2a30382ab67ec1cd92f87dc1f76dc3fd38c28fcf Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Mon, 5 Aug 2024 10:35:30 +0200 Subject: [PATCH 2/2] apply clang format --- core/BranchConfig.cpp | 18 +++++++++--------- core/BranchConfig.hpp | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/BranchConfig.cpp b/core/BranchConfig.cpp index 87e2f042..23e704c7 100644 --- a/core/BranchConfig.cpp +++ b/core/BranchConfig.cpp @@ -128,7 +128,7 @@ BranchConfig BranchConfig::CloneAndMerge(const BranchConfig& attached) const { result.AddField(name2 + "_" + field.first, name2 + ": " + field.second.title_); } - if(type1!=DetType::kEventHeader && attached.GetType()!=DetType::kEventHeader) { + if (type1 != DetType::kEventHeader && attached.GetType() != DetType::kEventHeader) { result.AddField("matching_case", "0 - both present, 1 - only first present, 2 - only second present"); } @@ -156,25 +156,25 @@ template void VectorConfig::RemoveField(const std::string& name, int id) { auto iter = map_.find(name); map_.erase(iter); - for(auto& m : map_) { - if(m.second.id_>id) { - m.second.id_ --; + for (auto& m : map_) { + if (m.second.id_ > id) { + m.second.id_--; } } } void BranchConfig::RemoveField(const std::string& name) { - if(!HasField(name)) { + if (!HasField(name)) { throw std::runtime_error("BranchConfig::RemoveField(): no field " + name + " to be removed"); } auto field_type = GetFieldType(name); auto field_id = GetFieldId(name); - if(field_id<0) { + if (field_id < 0) { throw std::runtime_error("BranchConfig::RemoveField(): default field " + name + " cannot be removed"); } - if(field_type == Types::kInteger) VectorConfig::RemoveField(name, field_id); - if(field_type == Types::kFloat) VectorConfig::RemoveField(name, field_id); - if(field_type == Types::kBool) VectorConfig::RemoveField(name, field_id); + if (field_type == Types::kInteger) VectorConfig::RemoveField(name, field_id); + if (field_type == Types::kFloat) VectorConfig::RemoveField(name, field_id); + if (field_type == Types::kBool) VectorConfig::RemoveField(name, field_id); } void BranchConfig::GuaranteeFieldNameVacancy(const std::string& name) const { diff --git a/core/BranchConfig.hpp b/core/BranchConfig.hpp index 39f7b4fb..0a944aaf 100644 --- a/core/BranchConfig.hpp +++ b/core/BranchConfig.hpp @@ -154,7 +154,7 @@ class BranchConfig : public VectorConfig, public VectorConfig, publi void RemoveField(const std::string& name); void RemoveFields(const std::vector& names) { - for(auto& n : names) { + for (auto& n : names) { RemoveField(n); } }