Skip to content

Commit

Permalink
Add name selector based on path
Browse files Browse the repository at this point in the history
  • Loading branch information
ianna committed Feb 28, 2020
1 parent 7f0e61a commit 5b4a781
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
3 changes: 3 additions & 0 deletions DetectorDescription/DDCMS/interface/DDSpecParRegistry.h
Expand Up @@ -14,6 +14,7 @@ namespace cms {
struct DDSpecPar {
std::string_view strValue(const std::string&) const;
bool hasValue(const std::string& key) const;
bool hasPath(const std::string& path) const;
double dblValue(const std::string&) const;

template <typename T>
Expand All @@ -22,6 +23,7 @@ namespace cms {
DDPaths paths;
DDPartSelectionMap spars;
DDVectorsMap numpars;
std::string_view name;
};

using DDSpecParMap = tbb::concurrent_unordered_map<std::string, DDSpecPar>;
Expand All @@ -31,6 +33,7 @@ namespace cms {
void filter(DDSpecParRefs&, std::string_view, std::string_view) const;
void filter(DDSpecParRefs&, std::string_view) 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;
const DDSpecPar* specPar(std::string_view) const;

Expand Down
12 changes: 11 additions & 1 deletion DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc
Expand Up @@ -37,7 +37,11 @@ void DDTestSpecParsFilter::analyze(const Event&, const EventSetup& iEventSetup)
LogVerbatim("Geometry") << "DDTestSpecParsFilter::analyze: " << m_tag << " for attribute " << m_attribute
<< " and value " << m_value;
LogVerbatim("Geometry") << "DD SpecPar Registry size: " << registry->specpars.size();

std::cout << "*** Check names in a path:\n";
std::vector<std::string_view> namesInPath = registry->names("//ME11AlumFrame");
for (auto i : namesInPath) {
std::cout << i << "\n";
}
DDSpecParRefs myReg;
if (m_value.empty())
registry->filter(myReg, m_attribute);
Expand All @@ -60,6 +64,12 @@ void DDTestSpecParsFilter::analyze(const Event&, const EventSetup& iEventSetup)
}
}
});
std::cout << "*** Check names in a path after filtering:\n";
for (auto it : myReg) {
if (it->hasPath("//ME11AlumFrame")) {
std::cout << it->name << "\n";
}
}
}

DEFINE_FWK_MODULE(DDTestSpecParsFilter);
23 changes: 21 additions & 2 deletions DetectorDescription/DDCMS/src/DDSpecparRegistry.cc
Expand Up @@ -21,6 +21,14 @@ bool DDSpecPar::hasValue(const string& key) const {
return false;
}

bool DDSpecPar::hasPath(const string& path) const {
auto result = std::find(std::begin(paths), std::end(paths), path);
if (result != end(paths))
return true;
else
return false;
}

template <>
std::vector<double> DDSpecPar::value<std::vector<double>>(const string& key) const {
std::vector<double> result;
Expand Down Expand Up @@ -70,7 +78,7 @@ double DDSpecPar::dblValue(const string& key) const {

void DDSpecParRegistry::filter(DDSpecParRefs& refs, string_view attribute, string_view value) const {
bool found(false);
for_each(begin(specpars), end(specpars), [&refs, &attribute, &value, &found](const auto& k) {
for_each(begin(specpars), end(specpars), [&refs, &attribute, &value, &found](auto& k) {
found = false;
for_each(begin(k.second.spars), end(k.second.spars), [&](const auto& l) {
if (l.first == attribute) {
Expand All @@ -81,26 +89,37 @@ void DDSpecParRegistry::filter(DDSpecParRefs& refs, string_view attribute, strin
}
});
if (found) {
k.second.name = k.first;
refs.emplace_back(&k.second);
}
});
}

void DDSpecParRegistry::filter(DDSpecParRefs& refs, string_view attribute) const {
bool found(false);
for_each(begin(specpars), end(specpars), [&refs, &attribute, &found](const auto& k) {
for_each(begin(specpars), end(specpars), [&refs, &attribute, &found](auto& k) {
found = false;
for_each(begin(k.second.spars), end(k.second.spars), [&](const auto& l) {
if (l.first == attribute) {
found = true;
}
});
if (found) {
k.second.name = k.first;
refs.emplace_back(&k.second);
}
});
}

std::vector<std::string_view> DDSpecParRegistry::names(const std::string& path) const {
std::vector<std::string_view> result;
for_each(begin(specpars), end(specpars), [&](const auto& i) {
if (i.second.hasPath(path))
result.emplace_back(i.first);
});
return result;
}

std::vector<std::string_view> DDSpecParRegistry::names() const {
std::vector<std::string_view> result;
for_each(begin(specpars), end(specpars), [&result](const auto& i) { result.emplace_back(i.first); });
Expand Down
Expand Up @@ -49,7 +49,7 @@
process.test = cms.EDAnalyzer("DDTestSpecParsFilter",
DDDetector = cms.ESInputTag('','CMS'),
attribute = cms.untracked.string('MuStructure'),
value = cms.untracked.string('MuonBarrelDT')
value = cms.untracked.string('MuonEndcapCSC') ###'MuonBarrelDT')
)

process.p = cms.Path(process.test)

0 comments on commit 5b4a781

Please sign in to comment.