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
29 changes: 28 additions & 1 deletion core/BranchConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ BranchConfig BranchConfig::CloneAndMerge(const BranchConfig& attached) const {
result.AddField<bool>(name2 + "_" + field.first, name2 + ": " + field.second.title_);
}

result.AddField<int>("matching_case", "0 - both present, 1 - only first present, 2 - only second present");
if (type1 != DetType::kEventHeader && attached.GetType() != DetType::kEventHeader) {
result.AddField<int>("matching_case", "0 - both present, 1 - only first present, 2 - only second present");
}

return result;
}
Expand All @@ -150,6 +152,31 @@ std::vector<std::string> VectorConfig<T>::SplitString(const std::string& input)
return result;
}

template<typename T>
void VectorConfig<T>::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<int>::RemoveField(name, field_id);
if (field_type == Types::kFloat) VectorConfig<float>::RemoveField(name, field_id);
if (field_type == Types::kBool) VectorConfig<bool>::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");
Expand Down
9 changes: 9 additions & 0 deletions core/BranchConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class VectorConfig {

protected:
static std::vector<std::string> SplitString(const std::string& input);
void RemoveField(const std::string& name, int id);
MapType map_{};
ShortInt_t size_{0};
ClassDef(VectorConfig, 2)
Expand Down Expand Up @@ -150,6 +151,14 @@ class BranchConfig : public VectorConfig<int>, public VectorConfig<float>, publi
VectorConfig<T>::AddField(name, id, title);
}

void RemoveField(const std::string& name);

void RemoveFields(const std::vector<std::string>& names) {
for (auto& n : names) {
RemoveField(n);
}
}

// Getters
template<typename T>
ANALYSISTREE_ATTR_NODISCARD const MapType& GetMap() const { return VectorConfig<T>::GetMap(); }
Expand Down