diff --git a/DDCore/CMakeLists.txt b/DDCore/CMakeLists.txt index 6a4f9b73e2484f7fab1c1f1661006646544ad451..a3ded85e8279557a320a4984fbe35fdf7cdcf719 100644 --- a/DDCore/CMakeLists.txt +++ b/DDCore/CMakeLists.txt @@ -15,7 +15,7 @@ dd4hep_print("|++> Will be Building DDCore") file(GLOB DDCore_SOURCES src/*.cpp src/segmentations/*.cpp src/XML/*.cpp) -if(NOT DD4HEP_USE_TBB OR ${CMAKE_CXX_STANDARD} LESS 17) +if(${CMAKE_CXX_STANDARD} LESS 17) list(APPEND EXCLUDE_HEADER include/DD4hep/SpecParRegistry.h) list(APPEND EXCLUDE_HEADER include/DD4hep/Filter.h) list(FILTER DDCore_SOURCES EXCLUDE REGEX Filter\.cpp|SpecParRegistry\.cpp ) diff --git a/DDCore/include/DD4hep/Filter.h b/DDCore/include/DD4hep/Filter.h index 734d48b4463cb93b1079b858854c5488f90c33ad..b2e5d865142251aa21f70a84e82cdab4e3f09d3a 100644 --- a/DDCore/include/DD4hep/Filter.h +++ b/DDCore/include/DD4hep/Filter.h @@ -39,7 +39,7 @@ namespace dd4hep { struct Filter { std::vector<bool> isRegex; - std::vector<bool> hasNamaspace; + std::vector<bool> hasNamespace; std::vector<int> index; std::vector<std::string_view> skeys; std::vector<std::regex> keys; @@ -50,11 +50,14 @@ namespace dd4hep { namespace dd { bool accepted(std::vector<std::regex> const&, std::string_view); + bool accepted(const Filter*, std::string_view); bool isRegex(std::string_view); bool hasNamespace(std::string_view); bool isMatch(std::string_view, std::string_view); bool compareEqual(std::string_view, std::string_view); bool compareEqual(std::string_view, std::regex); + bool compareEqualName(std::string_view, std::string_view); + bool compareEqualCopyNumber(std::string_view, int); std::string_view realTopName(std::string_view); std::vector<std::string_view> split(std::string_view, const char*); std::string_view noNamespace(std::string_view); diff --git a/DDCore/include/DD4hep/SpecParRegistry.h b/DDCore/include/DD4hep/SpecParRegistry.h index ae80b3df4a6a005253dab2d8a4477b47146af636..44a1c739f9f42ef76d8ac0c0d2944b78057c8527 100644 --- a/DDCore/include/DD4hep/SpecParRegistry.h +++ b/DDCore/include/DD4hep/SpecParRegistry.h @@ -38,10 +38,11 @@ namespace dd4hep { }; using SpecParMap = std::unordered_map<std::string, SpecPar>; - using SpecParRefs = std::vector<std::pair<std::string_view, const SpecPar*>>; + using SpecParRefs = std::vector<std::pair<std::string, const SpecPar*>>; struct SpecParRegistry { - void filter(SpecParRefs&, const std::string&, const std::string& = "") const; + void filter(SpecParRefs&, const std::string&, const std::string&) const; + void filter(SpecParRefs&, const std::string&) const; std::vector<std::string_view> names() const; std::vector<std::string_view> names(const std::string& path) const; bool hasSpecPar(std::string_view) const; diff --git a/DDCore/src/Filter.cpp b/DDCore/src/Filter.cpp index fa8e66be9d2ec7facde8b52be7302472bf7a0053..ff46f738d253b129777cd85a9a46705703c6f946 100644 --- a/DDCore/src/Filter.cpp +++ b/DDCore/src/Filter.cpp @@ -23,11 +23,42 @@ namespace dd4hep { return regex_match(std::string(node.data(), node.size()), pattern); } + bool compareEqualName(const std::string_view selection, const std::string_view name) { + return (!(dd4hep::dd::isRegex(selection)) ? dd4hep::dd::compareEqual(name, selection) + : regex_match(name.begin(), name.end(), regex(std::string(selection)))); + } + + bool compareEqualCopyNumber(std::string_view name, int copy) { + auto pos = name.rfind('['); + if (pos != name.npos) { + if (std::stoi(std::string(name.substr(pos + 1, name.rfind(']')))) == copy) { + return true; + } + } + + return false; + } + bool accepted(vector<std::regex> const& keys, string_view node) { return (find_if(begin(keys), end(keys), [&](const auto& n) -> bool { return compareEqual(node, n); }) != end(keys)); } + bool accepted(const Filter* filter, std::string_view name) { + for(unsigned int i = 0; i < filter->isRegex.size(); i++ ) { + if(!filter->isRegex[i]) { + if(compareEqual(filter->skeys[i], name)) { + return true; + } + } else { + if(compareEqual(name, filter->keys[filter->index[i]])) { + return true; + } + } + } + return false; + } + bool isRegex(string_view input) { return (input.find(".") != std::string_view::npos) || (input.find("*") != std::string_view::npos); } diff --git a/DDCore/src/SpecParRegistry.cpp b/DDCore/src/SpecParRegistry.cpp index db6dcd7d5724f590799ec6c82df726bc18128609..062c5dde649bb77563d2f8fd0d40808cb3850b30 100644 --- a/DDCore/src/SpecParRegistry.cpp +++ b/DDCore/src/SpecParRegistry.cpp @@ -110,11 +110,20 @@ void SpecParRegistry::filter(SpecParRefs& refs, const std::string& attribute, co } }); if (found) { - refs.emplace_back(std::make_pair(k.first, &k.second)); + refs.emplace_back(std::string(k.first.data(), k.first.size()), &k.second); } }); } +void SpecParRegistry::filter(SpecParRefs& refs, const std::string& key) const { + for (auto const& it : specpars) { + if (it.second.hasValue(key) || (it.second.spars.find(key) != end(it.second.spars))) { + refs.emplace_back(it.first, &it.second); + } + } +} + + std::vector<std::string_view> SpecParRegistry::names(const std::string& path) const { std::vector<std::string_view> result; for_each(begin(specpars), end(specpars), [&](const auto& i) {