diff --git a/DetectorDescription/DDCMS/interface/DDFilteredView.h b/DetectorDescription/DDCMS/interface/DDFilteredView.h index d8faa534e0a3e..c3fc4873e7527 100644 --- a/DetectorDescription/DDCMS/interface/DDFilteredView.h +++ b/DetectorDescription/DDCMS/interface/DDFilteredView.h @@ -163,6 +163,11 @@ namespace cms { template T get(const std::string&, const std::string&) const; + //! convert an attribute value from SpecPar + // without passing it through an evaluator, + // e.g. the original values have no units + std::vector get(const std::string&, const std::string&) const; + std::string_view getString(const std::string&) const; //! return the stack of sibling numbers which indicates diff --git a/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h b/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h index 84eb0ed63e27f..e3cbda77a203b 100644 --- a/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h +++ b/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h @@ -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 @@ -22,6 +23,7 @@ namespace cms { DDPaths paths; DDPartSelectionMap spars; DDVectorsMap numpars; + std::string_view name; }; using DDSpecParMap = tbb::concurrent_unordered_map; @@ -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 names() const; + std::vector names(const std::string& path) const; bool hasSpecPar(std::string_view) const; const DDSpecPar* specPar(std::string_view) const; diff --git a/DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc b/DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc index d0396c9f1a84a..673c7ae1995dd 100644 --- a/DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc +++ b/DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc @@ -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 namesInPath = registry->names("//ME11AlumFrame"); + for (auto i : namesInPath) { + std::cout << i << "\n"; + } DDSpecParRefs myReg; if (m_value.empty()) registry->filter(myReg, m_attribute); @@ -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); diff --git a/DetectorDescription/DDCMS/src/DDFilteredView.cc b/DetectorDescription/DDCMS/src/DDFilteredView.cc index 2211eaebb08d9..d22578c53ddc1 100644 --- a/DetectorDescription/DDCMS/src/DDFilteredView.cc +++ b/DetectorDescription/DDCMS/src/DDFilteredView.cc @@ -391,6 +391,15 @@ std::vector DDFilteredView::get>(const str return std::vector(); } +std::vector DDFilteredView::get(const string& name, const string& key) const { + std::vector stringVector = get>(name, key); + std::vector doubleVector(stringVector.size()); + std::transform(stringVector.begin(), stringVector.end(), doubleVector.begin(), [](const std::string& val) { + return std::stod(val); + }); + return doubleVector; +} + std::string_view DDFilteredView::getString(const std::string& key) const { assert(currentFilter_); assert(currentFilter_->spec); diff --git a/DetectorDescription/DDCMS/src/DDSpecparRegistry.cc b/DetectorDescription/DDCMS/src/DDSpecparRegistry.cc index 6cdff853abb90..011265033f9b8 100644 --- a/DetectorDescription/DDCMS/src/DDSpecparRegistry.cc +++ b/DetectorDescription/DDCMS/src/DDSpecparRegistry.cc @@ -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 DDSpecPar::value>(const string& key) const { std::vector result; @@ -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) { @@ -81,6 +89,7 @@ void DDSpecParRegistry::filter(DDSpecParRefs& refs, string_view attribute, strin } }); if (found) { + k.second.name = k.first; refs.emplace_back(&k.second); } }); @@ -88,7 +97,7 @@ void DDSpecParRegistry::filter(DDSpecParRefs& refs, string_view attribute, strin 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) { @@ -96,11 +105,21 @@ void DDSpecParRegistry::filter(DDSpecParRefs& refs, string_view attribute) const } }); if (found) { + k.second.name = k.first; refs.emplace_back(&k.second); } }); } +std::vector DDSpecParRegistry::names(const std::string& path) const { + std::vector result; + for_each(begin(specpars), end(specpars), [&](const auto& i) { + if (i.second.hasPath(path)) + result.emplace_back(i.first); + }); + return result; +} + std::vector DDSpecParRegistry::names() const { std::vector result; for_each(begin(specpars), end(specpars), [&result](const auto& i) { result.emplace_back(i.first); }); diff --git a/DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc b/DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc index 7d6d72c6a2262..4ec3ff8d0ce41 100644 --- a/DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc +++ b/DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc @@ -117,4 +117,20 @@ void testDDFilteredView::checkFilteredView() { CPPUNIT_ASSERT(i.compare(refsLongFL_[count]) == 0); count++; } + + cout << "Get CSC upar parameters for ChamberSpecs_ME11 as a vector of strings:\n"; + std::vector cscsPars = fview.get>("ChamberSpecs_ME11", "upar"); + for (auto const& i : cscsPars) { + std::cout << i << ", "; + count++; + } + std::cout << "\n"; + + cout << "Get CSC upar parameters for ChamberSpecs_ME11 as a vector of doubles:\n"; + std::vector upars = fview.get("ChamberSpecs_ME11", "upar"); + for (auto const& i : upars) { + std::cout << i << ", "; + count++; + } + std::cout << "\n"; } diff --git a/DetectorDescription/DDCMS/test/python/testDDSpecParsFilter.py b/DetectorDescription/DDCMS/test/python/testDDSpecParsFilter.py index ae6335ba94d88..844d79d782d12 100644 --- a/DetectorDescription/DDCMS/test/python/testDDSpecParsFilter.py +++ b/DetectorDescription/DDCMS/test/python/testDDSpecParsFilter.py @@ -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)