From ca74d9d6a3f3087e3a9e5247ae22c8022a61ff96 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Sun, 15 Mar 2020 18:29:07 +0100 Subject: [PATCH 1/8] Add more debug info and speed it up a bit --- .../DDCMS/interface/DDFilteredView.h | 8 +- DetectorDescription/DDCMS/interface/Filter.h | 7 +- .../DDCMS/src/DDFilteredView.cc | 77 ++++++------------- DetectorDescription/DDCMS/src/Filter.cc | 14 ++-- .../DDCMS/test/Filter.cppunit.cc | 22 ++++-- .../plugins/dd4hep/DTGeometryBuilder.cc | 2 + .../test/python/testDTGeometry.py | 5 +- 7 files changed, 64 insertions(+), 71 deletions(-) diff --git a/DetectorDescription/DDCMS/interface/DDFilteredView.h b/DetectorDescription/DDCMS/interface/DDFilteredView.h index c3fc4873e7527..91ba295ed5172 100644 --- a/DetectorDescription/DDCMS/interface/DDFilteredView.h +++ b/DetectorDescription/DDCMS/interface/DDFilteredView.h @@ -75,6 +75,9 @@ namespace cms { const std::vector copyNumbers() { return copyNos(); } + //! Debug filter + void printFilter() const { printFilter(currentFilter_); }; + //! The absolute translation of the current node // Return value is Double_t translation[3] with x, y, z elements. const Double_t* trans() const; @@ -176,13 +179,12 @@ namespace cms { private: bool accept(std::string_view); - bool addPath(Node* const); - bool addNode(Node* const); const TClass* getShape() const; //! set the current node to the first sibling bool firstSibling(); - + void printFilter(const Filter* filter) const; + ExpandedNodes nodes_; std::vector it_; std::vector> filters_; diff --git a/DetectorDescription/DDCMS/interface/Filter.h b/DetectorDescription/DDCMS/interface/Filter.h index 6374058c2c212..eb9caf4d95a67 100644 --- a/DetectorDescription/DDCMS/interface/Filter.h +++ b/DetectorDescription/DDCMS/interface/Filter.h @@ -20,22 +20,25 @@ // #include #include +#include namespace cms { struct DDSpecPar; struct Filter { - std::vector keys; + std::vector> keys; std::unique_ptr next; struct Filter* up; const DDSpecPar* spec = nullptr; }; namespace dd { - bool accepted(std::vector const&, std::string_view); + bool accepted(std::vector> const&, std::string_view); int contains(std::string_view, std::string_view); bool isRegex(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); std::string_view realTopName(std::string_view); std::vector split(std::string_view, const char*); std::string_view noNamespace(std::string_view); diff --git a/DetectorDescription/DDCMS/src/DDFilteredView.cc b/DetectorDescription/DDCMS/src/DDFilteredView.cc index d22578c53ddc1..7d8f1bb804cfc 100644 --- a/DetectorDescription/DDCMS/src/DDFilteredView.cc +++ b/DetectorDescription/DDCMS/src/DDFilteredView.cc @@ -147,7 +147,7 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { for (const auto& j : i->paths) { vector toks = split(j, "/"); auto const& filter = find_if(begin(filters_), end(filters_), [&](auto const& f) { - auto const& k = find(begin(f->keys), end(f->keys), toks.front()); + auto const& k = find_if(begin(f->keys), end(f->keys), [&](auto const& p) { return p.first == toks.front(); }); if (k != end(f->keys)) { currentFilter_ = f.get(); return true; @@ -155,25 +155,42 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { return false; }); if (filter == end(filters_)) { - filters_.emplace_back(unique_ptr(new Filter{{toks.front()}, nullptr, nullptr, i})); - currentFilter_ = filters_.back().get(); + filters_.emplace_back(unique_ptr( + new Filter{{std::pair( + toks.front(), regex(std::string(toks.front().data(), toks.front().size())))}, + nullptr, nullptr, i})); } // all next levels for (size_t pos = 1; pos < toks.size(); ++pos) { if (currentFilter_->next != nullptr) { currentFilter_ = currentFilter_->next.get(); - auto const& l = find(begin(currentFilter_->keys), end(currentFilter_->keys), toks[pos]); + auto const& l = find_if(begin(currentFilter_->keys), end(currentFilter_->keys), [&](auto const& p) { + return p.first == toks[pos]; + }); if (l == end(currentFilter_->keys)) { - currentFilter_->keys.emplace_back(toks[pos]); + currentFilter_->keys.emplace_back(toks[pos], std::string(toks[pos].data(), toks[pos].size())); } } else { - currentFilter_->next.reset(new Filter{{toks[pos]}, nullptr, currentFilter_, i}); + currentFilter_->next.reset(new Filter{{std::pair( + toks[pos], regex(std::string(toks[pos].data(), toks[pos].size())))}, + nullptr, + currentFilter_, + i}); } } } } } +void DDFilteredView::printFilter(const Filter* filter) const { + if (filter != nullptr) { + for (auto it : filter->keys) + std::cout << "//" << std::string(it.first.data(), it.first.size()) << "\n"; + if (filter->next != nullptr) + printFilter(filter->next.get()); + } + } + bool DDFilteredView::firstChild() { if (it_.empty()) { LogVerbatim("DDFilteredView") << "Iterator vector has zero size."; @@ -415,33 +432,6 @@ DDFilteredView::nav_type DDFilteredView::navPos() const { return pos; } -bool DDFilteredView::addPath(Node* const node) { - assert(registry_); - node_ = node; - nodes_.tags.clear(); - nodes_.offsets.clear(); - nodes_.copyNos.clear(); - bool result(false); - - int level = it_.back().GetLevel(); - for (int nit = level; nit > 0; --nit) { - for_each(begin(registry_->specpars), end(registry_->specpars), [&](auto const& i) { - auto k = find_if(begin(i.second.paths), end(i.second.paths), [&](auto const& j) { - return (compareEqual(noNamespace(it_.back().GetNode(nit)->GetVolume()->GetName()), - *begin(split(realTopName(j), "/"))) && - (i.second.hasValue("CopyNoTag") || i.second.hasValue("CopyNoOffset"))); - }); - if (k != end(i.second.paths)) { - nodes_.tags.emplace_back(i.second.dblValue("CopyNoTag")); - nodes_.offsets.emplace_back(i.second.dblValue("CopyNoOffset")); - nodes_.copyNos.emplace_back(it_.back().GetNode(nit)->GetNumber()); - result = true; - } - }); - } - return result; -} - const ExpandedNodes& DDFilteredView::history() { assert(registry_); nodes_.tags.clear(); @@ -453,7 +443,7 @@ const ExpandedNodes& DDFilteredView::history() { for (int nit = level; nit > 0; --nit) { for_each(begin(registry_->specpars), end(registry_->specpars), [&](auto const& i) { auto k = find_if(begin(i.second.paths), end(i.second.paths), [&](auto const& j) { - return (compareEqual(noNamespace(it_.back().GetNode(nit)->GetVolume()->GetName()), + return (isMatch(noNamespace(it_.back().GetNode(nit)->GetVolume()->GetName()), *begin(split(realTopName(j), "/"))) && (i.second.hasValue("CopyNoTag") || i.second.hasValue("CopyNoOffset"))); }); @@ -469,25 +459,6 @@ const ExpandedNodes& DDFilteredView::history() { return nodes_; } -bool DDFilteredView::addNode(Node* const node) { - assert(registry_); - node_ = node; - bool result(false); - for_each(begin(registry_->specpars), end(registry_->specpars), [&](auto const& i) { - auto k = find_if(begin(i.second.paths), end(i.second.paths), [&](auto const& j) { - return (compareEqual(node_->GetVolume()->GetName(), *begin(split(realTopName(j), "/"))) && - (i.second.hasValue("CopyNoTag") || i.second.hasValue("CopyNoOffset"))); - }); - if (k != end(i.second.paths)) { - nodes_.tags.emplace_back(i.second.dblValue("CopyNoTag")); - nodes_.offsets.emplace_back(i.second.dblValue("CopyNoOffset")); - nodes_.copyNos.emplace_back(node_->GetNumber()); - result = true; - } - }); - return result; -} - const TClass* DDFilteredView::getShape() const { assert(node_); Volume currVol = node_->GetVolume(); diff --git a/DetectorDescription/DDCMS/src/Filter.cc b/DetectorDescription/DDCMS/src/Filter.cc index c472c3fb73841..8c5fae343a735 100644 --- a/DetectorDescription/DDCMS/src/Filter.cc +++ b/DetectorDescription/DDCMS/src/Filter.cc @@ -8,7 +8,7 @@ using namespace std; namespace cms { namespace dd { - bool compareEqual(string_view node, string_view name) { + bool isMatch(string_view node, string_view name) { if (!isRegex(name)) { return (name == node); } else { @@ -17,11 +17,15 @@ namespace cms { } } - bool accepted(vector const& names, string_view node) { - return (find_if(begin(names), end(names), [&](const auto& n) -> bool { return compareEqual(node, n); }) != - end(names)); - } + bool compareEqual(string_view node, string_view name) { return (name == node); } + + bool compareEqual(string_view node, regex pattern) { return regex_match(begin(node), end(node), pattern); } + bool accepted(vector> const& keys, string_view node) { + return (find_if(begin(keys), end(keys), [&](const auto& n) -> bool { return compareEqual(node, n.second); }) != + end(keys)); + } + int contains(string_view input, string_view needle) { auto const& it = search(begin(input), end(input), default_searcher(begin(needle), end(needle))); if (it != end(input)) { diff --git a/DetectorDescription/DDCMS/test/Filter.cppunit.cc b/DetectorDescription/DDCMS/test/Filter.cppunit.cc index 851422e0e2ba7..4e3f2e141f912 100644 --- a/DetectorDescription/DDCMS/test/Filter.cppunit.cc +++ b/DetectorDescription/DDCMS/test/Filter.cppunit.cc @@ -44,7 +44,7 @@ void testFilter::setUp() { vector toks = split(i, "/"); unique_ptr f = nullptr; auto const& filter = find_if(begin(filters_), end(filters_), [&](auto const& f) { - auto const& k = find(begin(f->keys), end(f->keys), toks.front()); + auto const& k = find_if(begin(f->keys), end(f->keys), [&](auto const& p) { return p.first == toks.front(); }); if (k != end(f->keys)) { currentFilter = f.get(); return true; @@ -52,19 +52,27 @@ void testFilter::setUp() { return false; }); if (filter == end(filters_)) { - filters_.emplace_back(unique_ptr(new Filter{{toks.front()}, nullptr, nullptr})); + filters_.emplace_back(unique_ptr( + new Filter{{std::pair( + toks.front(), regex(std::string(toks.front().data(), toks.front().size())))}, + nullptr, + nullptr})); currentFilter = filters_.back().get(); } // all next levels for (size_t pos = 1; pos < toks.size(); ++pos) { if (currentFilter->next != nullptr) { currentFilter = currentFilter->next.get(); - auto const& l = find(begin(currentFilter->keys), end(currentFilter->keys), toks[pos]); + auto const& l = find_if( + begin(currentFilter->keys), end(currentFilter->keys), [&](auto const& p) { return p.first == toks[pos]; }); if (l == end(currentFilter->keys)) { - currentFilter->keys.emplace_back(toks[pos]); + currentFilter->keys.emplace_back(toks[pos], regex(std::string(toks.front().data(), toks.front().size()))); } } else { - currentFilter->next.reset(new Filter{{toks[pos]}, nullptr, currentFilter}); + currentFilter->next.reset(new Filter{ + {std::pair(toks[pos], regex({toks[pos].data(), toks[pos].size()}))}, + nullptr, + currentFilter}); } } } @@ -72,7 +80,7 @@ void testFilter::setUp() { void testFilter::checkFilter() { string_view name = "MB2P.*"sv; - CPPUNIT_ASSERT(filters_.front()->keys.front() == name); + CPPUNIT_ASSERT(filters_.front()->keys.front().first == name); CPPUNIT_ASSERT(filters_.front()->up == nullptr); CPPUNIT_ASSERT(filters_.front()->next != nullptr); CPPUNIT_ASSERT(filters_.size() == 1); @@ -90,7 +98,7 @@ void testFilter::checkFilter() { void testFilter::print(Filter* filter) { for (auto const& it : filter->keys) { - cout << it << " "; + cout << it.first << " "; } cout << "\n"; } diff --git a/Geometry/DTGeometryBuilder/plugins/dd4hep/DTGeometryBuilder.cc b/Geometry/DTGeometryBuilder/plugins/dd4hep/DTGeometryBuilder.cc index 10756210af15a..40f99a8e0e3f0 100644 --- a/Geometry/DTGeometryBuilder/plugins/dd4hep/DTGeometryBuilder.cc +++ b/Geometry/DTGeometryBuilder/plugins/dd4hep/DTGeometryBuilder.cc @@ -56,11 +56,13 @@ void DTGeometryBuilder::buildGeometry(DDFilteredView& fview, DTGeometry& geom, c // Loop on SLs bool doSL = fview.nextSibling(); + while (doSL) { DTSuperLayer* sl = buildSuperLayer(fview, chamber, num); // Loop on Layers fview.down(); + bool doLayers = fview.sibling(); while (doLayers) { DTLayer* l = buildLayer(fview, sl, num); diff --git a/Geometry/DTGeometryBuilder/test/python/testDTGeometry.py b/Geometry/DTGeometryBuilder/test/python/testDTGeometry.py index 6ce74f0f1fa18..14b58e86bf087 100644 --- a/Geometry/DTGeometryBuilder/test/python/testDTGeometry.py +++ b/Geometry/DTGeometryBuilder/test/python/testDTGeometry.py @@ -10,7 +10,7 @@ process.MessageLogger = cms.Service( "MessageLogger", statistics = cms.untracked.vstring('cout', 'dtGeometry'), - categories = cms.untracked.vstring('DTGeometryTest'), + categories = cms.untracked.vstring('DTGeometryTest', 'Geometry'), cout = cms.untracked.PSet( threshold = cms.untracked.string('WARNING'), noLineBreaks = cms.untracked.bool(True) @@ -31,6 +31,9 @@ ), threshold = cms.untracked.string('INFO'), DTGeometryTest = cms.untracked.PSet( + limit = cms.untracked.int32(-1) + ), + Geometry = cms.untracked.PSet( limit = cms.untracked.int32(-1) ) ), From ed97a4fe204153ecbe4e7ac6edf8c4f6835b220f Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Sun, 15 Mar 2020 18:30:41 +0100 Subject: [PATCH 2/8] code format --- .../DDCMS/interface/DDFilteredView.h | 2 +- .../DDCMS/src/DDFilteredView.cc | 50 ++++++++++--------- DetectorDescription/DDCMS/src/Filter.cc | 8 +-- .../DDCMS/test/Filter.cppunit.cc | 22 ++++---- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/DetectorDescription/DDCMS/interface/DDFilteredView.h b/DetectorDescription/DDCMS/interface/DDFilteredView.h index 91ba295ed5172..88673443b4f78 100644 --- a/DetectorDescription/DDCMS/interface/DDFilteredView.h +++ b/DetectorDescription/DDCMS/interface/DDFilteredView.h @@ -184,7 +184,7 @@ namespace cms { //! set the current node to the first sibling bool firstSibling(); void printFilter(const Filter* filter) const; - + ExpandedNodes nodes_; std::vector it_; std::vector> filters_; diff --git a/DetectorDescription/DDCMS/src/DDFilteredView.cc b/DetectorDescription/DDCMS/src/DDFilteredView.cc index 7d8f1bb804cfc..071520003d055 100644 --- a/DetectorDescription/DDCMS/src/DDFilteredView.cc +++ b/DetectorDescription/DDCMS/src/DDFilteredView.cc @@ -147,7 +147,7 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { for (const auto& j : i->paths) { vector toks = split(j, "/"); auto const& filter = find_if(begin(filters_), end(filters_), [&](auto const& f) { - auto const& k = find_if(begin(f->keys), end(f->keys), [&](auto const& p) { return p.first == toks.front(); }); + auto const& k = find_if(begin(f->keys), end(f->keys), [&](auto const& p) { return p.first == toks.front(); }); if (k != end(f->keys)) { currentFilter_ = f.get(); return true; @@ -155,27 +155,29 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { return false; }); if (filter == end(filters_)) { - filters_.emplace_back(unique_ptr( - new Filter{{std::pair( - toks.front(), regex(std::string(toks.front().data(), toks.front().size())))}, - nullptr, nullptr, i})); + filters_.emplace_back(unique_ptr( + new Filter{{std::pair( + toks.front(), regex(std::string(toks.front().data(), toks.front().size())))}, + nullptr, + nullptr, + i})); } // all next levels for (size_t pos = 1; pos < toks.size(); ++pos) { if (currentFilter_->next != nullptr) { currentFilter_ = currentFilter_->next.get(); - auto const& l = find_if(begin(currentFilter_->keys), end(currentFilter_->keys), [&](auto const& p) { - return p.first == toks[pos]; - }); + auto const& l = find_if(begin(currentFilter_->keys), end(currentFilter_->keys), [&](auto const& p) { + return p.first == toks[pos]; + }); if (l == end(currentFilter_->keys)) { - currentFilter_->keys.emplace_back(toks[pos], std::string(toks[pos].data(), toks[pos].size())); + currentFilter_->keys.emplace_back(toks[pos], std::string(toks[pos].data(), toks[pos].size())); } } else { - currentFilter_->next.reset(new Filter{{std::pair( - toks[pos], regex(std::string(toks[pos].data(), toks[pos].size())))}, - nullptr, - currentFilter_, - i}); + currentFilter_->next.reset(new Filter{{std::pair( + toks[pos], regex(std::string(toks[pos].data(), toks[pos].size())))}, + nullptr, + currentFilter_, + i}); } } } @@ -183,13 +185,13 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { } void DDFilteredView::printFilter(const Filter* filter) const { - if (filter != nullptr) { - for (auto it : filter->keys) - std::cout << "//" << std::string(it.first.data(), it.first.size()) << "\n"; - if (filter->next != nullptr) - printFilter(filter->next.get()); - } - } + if (filter != nullptr) { + for (auto it : filter->keys) + std::cout << "//" << std::string(it.first.data(), it.first.size()) << "\n"; + if (filter->next != nullptr) + printFilter(filter->next.get()); + } +} bool DDFilteredView::firstChild() { if (it_.empty()) { @@ -443,9 +445,9 @@ const ExpandedNodes& DDFilteredView::history() { for (int nit = level; nit > 0; --nit) { for_each(begin(registry_->specpars), end(registry_->specpars), [&](auto const& i) { auto k = find_if(begin(i.second.paths), end(i.second.paths), [&](auto const& j) { - return (isMatch(noNamespace(it_.back().GetNode(nit)->GetVolume()->GetName()), - *begin(split(realTopName(j), "/"))) && - (i.second.hasValue("CopyNoTag") || i.second.hasValue("CopyNoOffset"))); + return ( + isMatch(noNamespace(it_.back().GetNode(nit)->GetVolume()->GetName()), *begin(split(realTopName(j), "/"))) && + (i.second.hasValue("CopyNoTag") || i.second.hasValue("CopyNoOffset"))); }); if (k != end(i.second.paths)) { nodes_.tags.emplace_back(i.second.dblValue("CopyNoTag")); diff --git a/DetectorDescription/DDCMS/src/Filter.cc b/DetectorDescription/DDCMS/src/Filter.cc index 8c5fae343a735..5fae497808a90 100644 --- a/DetectorDescription/DDCMS/src/Filter.cc +++ b/DetectorDescription/DDCMS/src/Filter.cc @@ -22,10 +22,10 @@ namespace cms { bool compareEqual(string_view node, regex pattern) { return regex_match(begin(node), end(node), pattern); } bool accepted(vector> const& keys, string_view node) { - return (find_if(begin(keys), end(keys), [&](const auto& n) -> bool { return compareEqual(node, n.second); }) != - end(keys)); - } - + return (find_if(begin(keys), end(keys), [&](const auto& n) -> bool { return compareEqual(node, n.second); }) != + end(keys)); + } + int contains(string_view input, string_view needle) { auto const& it = search(begin(input), end(input), default_searcher(begin(needle), end(needle))); if (it != end(input)) { diff --git a/DetectorDescription/DDCMS/test/Filter.cppunit.cc b/DetectorDescription/DDCMS/test/Filter.cppunit.cc index 4e3f2e141f912..3874c3ff3443b 100644 --- a/DetectorDescription/DDCMS/test/Filter.cppunit.cc +++ b/DetectorDescription/DDCMS/test/Filter.cppunit.cc @@ -53,26 +53,26 @@ void testFilter::setUp() { }); if (filter == end(filters_)) { filters_.emplace_back(unique_ptr( - new Filter{{std::pair( - toks.front(), regex(std::string(toks.front().data(), toks.front().size())))}, - nullptr, - nullptr})); + new Filter{{std::pair( + toks.front(), regex(std::string(toks.front().data(), toks.front().size())))}, + nullptr, + nullptr})); currentFilter = filters_.back().get(); } // all next levels for (size_t pos = 1; pos < toks.size(); ++pos) { if (currentFilter->next != nullptr) { currentFilter = currentFilter->next.get(); - auto const& l = find_if( - begin(currentFilter->keys), end(currentFilter->keys), [&](auto const& p) { return p.first == toks[pos]; }); + auto const& l = find_if( + begin(currentFilter->keys), end(currentFilter->keys), [&](auto const& p) { return p.first == toks[pos]; }); if (l == end(currentFilter->keys)) { - currentFilter->keys.emplace_back(toks[pos], regex(std::string(toks.front().data(), toks.front().size()))); + currentFilter->keys.emplace_back(toks[pos], regex(std::string(toks.front().data(), toks.front().size()))); } } else { - currentFilter->next.reset(new Filter{ - {std::pair(toks[pos], regex({toks[pos].data(), toks[pos].size()}))}, - nullptr, - currentFilter}); + currentFilter->next.reset(new Filter{ + {std::pair(toks[pos], regex({toks[pos].data(), toks[pos].size()}))}, + nullptr, + currentFilter}); } } } From ab4972e2ea4425ed47f99193038c1b3c03ba5bcc Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Mon, 16 Mar 2020 16:15:02 +0100 Subject: [PATCH 3/8] restructure to match an Hcal user story --- .../DDCMS/interface/DDFilteredView.h | 26 ++++-- .../DDCMS/interface/DDSpecParRegistry.h | 4 +- DetectorDescription/DDCMS/interface/Filter.h | 4 +- .../DDCMS/src/DDFilteredView.cc | 41 ++++----- .../DDCMS/src/DDSpecparRegistry.cc | 36 ++++++-- DetectorDescription/DDCMS/src/Filter.cc | 4 +- .../DDCMS/test/Filter.cppunit.cc | 20 ++--- .../cms-test-Phase2GeometryFine-algorithm.xml | 2 +- .../hcalsens/HGCal/2021/v1/hcalsenspmf.xml | 19 +++++ .../interface/HcalSimParametersFromDD.h | 4 +- .../plugins/HcalSimParametersESModule.cc | 2 +- .../src/HcalSimParametersFromDD.cc | 84 +++++++++++-------- .../test/plugins/DD4hepTestDDDWorld.cc | 12 +-- 13 files changed, 166 insertions(+), 92 deletions(-) create mode 100644 Geometry/HcalCommonData/data/hcalsens/HGCal/2021/v1/hcalsenspmf.xml diff --git a/DetectorDescription/DDCMS/interface/DDFilteredView.h b/DetectorDescription/DDCMS/interface/DDFilteredView.h index 88673443b4f78..c1b1e0dd8ad8c 100644 --- a/DetectorDescription/DDCMS/interface/DDFilteredView.h +++ b/DetectorDescription/DDCMS/interface/DDFilteredView.h @@ -50,14 +50,28 @@ namespace cms { using Node = TGeoNode; using Translation = ROOT::Math::DisplacementVector3D>; using RotationMatrix = ROOT::Math::Rotation3D; - using DDFilter = std::string_view; - + + struct DDFilter { + DDFilter(const std::string& attribute = "", const std::string& value = "") + : m_attribute(attribute), + m_value(value) {} + const std::string& attribute() const { + return m_attribute; + } + const std::string& value() const { + return m_value; + } + private: + const std::string m_attribute; + const std::string m_value; + }; + class DDFilteredView { public: using nav_type = std::vector; DDFilteredView(const DDDetector*, const Volume); - DDFilteredView(const DDCompactView&, const DDFilter& = ""); + DDFilteredView(const DDCompactView&, const cms::DDFilter&); DDFilteredView() = delete; //! The numbering history of the current node @@ -75,9 +89,6 @@ namespace cms { const std::vector copyNumbers() { return copyNos(); } - //! Debug filter - void printFilter() const { printFilter(currentFilter_); }; - //! The absolute translation of the current node // Return value is Double_t translation[3] with x, y, z elements. const Double_t* trans() const; @@ -90,6 +101,9 @@ namespace cms { //! User specific data void mergedSpecifics(DDSpecParRefs const&); + const cms::DDSpecParRefs specpars() const { + return refs_; + } //! set the current node to the first child bool firstChild(); diff --git a/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h b/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h index e3cbda77a203b..8f1bca9043c5a 100644 --- a/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h +++ b/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h @@ -30,8 +30,8 @@ namespace cms { using DDSpecParRefs = std::vector; struct DDSpecParRegistry { - void filter(DDSpecParRefs&, std::string_view, std::string_view) const; - void filter(DDSpecParRefs&, std::string_view) const; + void filter(DDSpecParRefs&, const std::string&, const std::string&) const; + void filter(DDSpecParRefs&, const std::string&) const; std::vector names() const; std::vector names(const std::string& path) const; bool hasSpecPar(std::string_view) const; diff --git a/DetectorDescription/DDCMS/interface/Filter.h b/DetectorDescription/DDCMS/interface/Filter.h index eb9caf4d95a67..06fd050405235 100644 --- a/DetectorDescription/DDCMS/interface/Filter.h +++ b/DetectorDescription/DDCMS/interface/Filter.h @@ -26,14 +26,14 @@ namespace cms { struct DDSpecPar; struct Filter { - std::vector> keys; + std::vector keys; std::unique_ptr next; struct Filter* up; const DDSpecPar* spec = nullptr; }; namespace dd { - bool accepted(std::vector> const&, std::string_view); + bool accepted(std::vector const&, std::string_view); int contains(std::string_view, std::string_view); bool isRegex(std::string_view); bool isMatch(std::string_view, std::string_view); diff --git a/DetectorDescription/DDCMS/src/DDFilteredView.cc b/DetectorDescription/DDCMS/src/DDFilteredView.cc index 071520003d055..3e2df695b4637 100644 --- a/DetectorDescription/DDCMS/src/DDFilteredView.cc +++ b/DetectorDescription/DDCMS/src/DDFilteredView.cc @@ -41,12 +41,12 @@ DDFilteredView::DDFilteredView(const DDDetector* det, const Volume volume) : reg it_.emplace_back(Iterator(volume)); } -DDFilteredView::DDFilteredView(const DDCompactView& cpv, const DDFilter& attribute) : registry_(&cpv.specpars()) { +DDFilteredView::DDFilteredView(const DDCompactView& cpv, const cms::DDFilter& filter) : registry_(&cpv.specpars()) { it_.emplace_back(Iterator(cpv.detector()->worldVolume())); - registry_->filter(refs_, attribute); + registry_->filter(refs_, filter.attribute(), filter.value()); mergedSpecifics(refs_); LogVerbatim("Geometry").log([&](auto& log) { - log << "Filtered DD SpecPar Registry size: " << refs_.size() << "\n"; + log << "Filtered by an attribute " << filter.attribute() << "==" << filter.value() << " DD SpecPar Registry size: " << refs_.size() << "\n"; for (const auto& t : refs_) { log << "\nRegExps { "; for (const auto& ki : t->paths) @@ -143,11 +143,15 @@ void DDFilteredView::rot(dd4hep::Rotation3D& matrixOut) const { } void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { + if (!filters_.empty()) { + filters_.clear(); + filters_.shrink_to_fit(); + } for (const auto& i : specs) { for (const auto& j : i->paths) { vector toks = split(j, "/"); auto const& filter = find_if(begin(filters_), end(filters_), [&](auto const& f) { - auto const& k = find_if(begin(f->keys), end(f->keys), [&](auto const& p) { return p.first == toks.front(); }); + auto const& k = find_if(begin(f->keys), end(f->keys), [&](auto const& p) { return std::regex_match(std::string({toks.front().data(), toks.front().size()}), p); }); if (k != end(f->keys)) { currentFilter_ = f.get(); return true; @@ -156,8 +160,8 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { }); if (filter == end(filters_)) { filters_.emplace_back(unique_ptr( - new Filter{{std::pair( - toks.front(), regex(std::string(toks.front().data(), toks.front().size())))}, + new Filter{{std::regex( + std::string(toks.front().data(), toks.front().size()))}, nullptr, nullptr, i})); @@ -167,14 +171,14 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { if (currentFilter_->next != nullptr) { currentFilter_ = currentFilter_->next.get(); auto const& l = find_if(begin(currentFilter_->keys), end(currentFilter_->keys), [&](auto const& p) { - return p.first == toks[pos]; + return std::regex_match(std::string({toks.front().data(), toks.front().size()}), p); }); if (l == end(currentFilter_->keys)) { - currentFilter_->keys.emplace_back(toks[pos], std::string(toks[pos].data(), toks[pos].size())); + currentFilter_->keys.emplace_back(std::string(toks[pos].data(), toks[pos].size())); } } else { - currentFilter_->next.reset(new Filter{{std::pair( - toks[pos], regex(std::string(toks[pos].data(), toks[pos].size())))}, + currentFilter_->next.reset(new Filter{{std::regex( + std::string(toks[pos].data(), toks[pos].size()))}, nullptr, currentFilter_, i}); @@ -184,15 +188,6 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { } } -void DDFilteredView::printFilter(const Filter* filter) const { - if (filter != nullptr) { - for (auto it : filter->keys) - std::cout << "//" << std::string(it.first.data(), it.first.size()) << "\n"; - if (filter->next != nullptr) - printFilter(filter->next.get()); - } -} - bool DDFilteredView::firstChild() { if (it_.empty()) { LogVerbatim("DDFilteredView") << "Iterator vector has zero size."; @@ -402,6 +397,14 @@ std::vector DDFilteredView::get>(const string& name, return std::vector(); } +template <> +std::vector DDFilteredView::get>(const string& name, const string& key) const { + if (registry_->hasSpecPar(name)) + return registry_->specPar(name)->value>(key); + else + return std::vector(); +} + template <> std::vector DDFilteredView::get>(const string& name, const string& key) const { if (registry_->hasSpecPar(name)) diff --git a/DetectorDescription/DDCMS/src/DDSpecparRegistry.cc b/DetectorDescription/DDCMS/src/DDSpecparRegistry.cc index 011265033f9b8..35e349a9dfeb1 100644 --- a/DetectorDescription/DDCMS/src/DDSpecparRegistry.cc +++ b/DetectorDescription/DDCMS/src/DDSpecparRegistry.cc @@ -48,6 +48,25 @@ std::vector DDSpecPar::value>(const string& key) con return result; } +template <> +std::vector DDSpecPar::value>(const string& key) const { + std::vector result; + + auto const& nitem = numpars.find(key); + if (nitem != end(numpars)) { + return std::vector(begin(nitem->second), end(nitem->second)); + } + + auto const& sitem = spars.find(key); + if (sitem != end(spars)) { + std::transform(begin(sitem->second), end(sitem->second), std::back_inserter(result), [](auto& i) -> int { + return dd4hep::_toInt(i); + }); + } + + return result; +} + template <> std::vector DDSpecPar::value>(const string& key) const { std::vector result; @@ -76,16 +95,21 @@ double DDSpecPar::dblValue(const string& key) const { return *begin(item->second); } -void DDSpecParRegistry::filter(DDSpecParRefs& refs, string_view attribute, string_view value) const { +void DDSpecParRegistry::filter(DDSpecParRefs& refs, const std::string& attribute, const std::string& value) const { bool found(false); 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) { - for_each(begin(l.second), end(l.second), [&](const auto& m) { - if (m == value) - found = true; - }); + if (value.empty()) { + found = true; + } + else { + for_each(begin(l.second), end(l.second), [&](const auto& m) { + if (m == value) + found = true; + }); + } } }); if (found) { @@ -95,7 +119,7 @@ void DDSpecParRegistry::filter(DDSpecParRefs& refs, string_view attribute, strin }); } -void DDSpecParRegistry::filter(DDSpecParRefs& refs, string_view attribute) const { +void DDSpecParRegistry::filter(DDSpecParRefs& refs, const std::string& attribute) const { bool found(false); for_each(begin(specpars), end(specpars), [&refs, &attribute, &found](auto& k) { found = false; diff --git a/DetectorDescription/DDCMS/src/Filter.cc b/DetectorDescription/DDCMS/src/Filter.cc index 5fae497808a90..0b5658b113b9e 100644 --- a/DetectorDescription/DDCMS/src/Filter.cc +++ b/DetectorDescription/DDCMS/src/Filter.cc @@ -21,8 +21,8 @@ namespace cms { bool compareEqual(string_view node, regex pattern) { return regex_match(begin(node), end(node), pattern); } - bool accepted(vector> const& keys, string_view node) { - return (find_if(begin(keys), end(keys), [&](const auto& n) -> bool { return compareEqual(node, n.second); }) != + bool accepted(vector const& keys, string_view node) { + return (find_if(begin(keys), end(keys), [&](const auto& n) -> bool { return compareEqual(node, n); }) != end(keys)); } diff --git a/DetectorDescription/DDCMS/test/Filter.cppunit.cc b/DetectorDescription/DDCMS/test/Filter.cppunit.cc index 3874c3ff3443b..b3d925ec37df9 100644 --- a/DetectorDescription/DDCMS/test/Filter.cppunit.cc +++ b/DetectorDescription/DDCMS/test/Filter.cppunit.cc @@ -44,7 +44,7 @@ void testFilter::setUp() { vector toks = split(i, "/"); unique_ptr f = nullptr; auto const& filter = find_if(begin(filters_), end(filters_), [&](auto const& f) { - auto const& k = find_if(begin(f->keys), end(f->keys), [&](auto const& p) { return p.first == toks.front(); }); + auto const& k = find_if(begin(f->keys), end(f->keys), [&](auto const& p) { return std::regex_match(std::string({toks.front().data(), toks.front().size()}), p); }); if (k != end(f->keys)) { currentFilter = f.get(); return true; @@ -53,8 +53,8 @@ void testFilter::setUp() { }); if (filter == end(filters_)) { filters_.emplace_back(unique_ptr( - new Filter{{std::pair( - toks.front(), regex(std::string(toks.front().data(), toks.front().size())))}, + new Filter{{std::regex( + regex(std::string(toks.front().data(), toks.front().size())))}, nullptr, nullptr})); currentFilter = filters_.back().get(); @@ -64,13 +64,13 @@ void testFilter::setUp() { if (currentFilter->next != nullptr) { currentFilter = currentFilter->next.get(); auto const& l = find_if( - begin(currentFilter->keys), end(currentFilter->keys), [&](auto const& p) { return p.first == toks[pos]; }); + begin(currentFilter->keys), end(currentFilter->keys), [&](auto const& p) { return std::regex_match(std::string({toks[pos].data(), toks[pos].size()}), p); }); if (l == end(currentFilter->keys)) { - currentFilter->keys.emplace_back(toks[pos], regex(std::string(toks.front().data(), toks.front().size()))); + currentFilter->keys.emplace_back(std::regex(std::string(toks.front().data(), toks.front().size()))); } } else { currentFilter->next.reset(new Filter{ - {std::pair(toks[pos], regex({toks[pos].data(), toks[pos].size()}))}, + {std::regex(std::string({toks[pos].data(), toks[pos].size()}))}, nullptr, currentFilter}); } @@ -80,7 +80,7 @@ void testFilter::setUp() { void testFilter::checkFilter() { string_view name = "MB2P.*"sv; - CPPUNIT_ASSERT(filters_.front()->keys.front().first == name); + CPPUNIT_ASSERT(std::regex_match(std::string({name.data(), name.size()}), filters_.front()->keys.front()) == 1); CPPUNIT_ASSERT(filters_.front()->up == nullptr); CPPUNIT_ASSERT(filters_.front()->next != nullptr); CPPUNIT_ASSERT(filters_.size() == 1); @@ -97,8 +97,8 @@ void testFilter::checkFilter() { } void testFilter::print(Filter* filter) { - for (auto const& it : filter->keys) { - cout << it.first << " "; - } + // for (auto const& it : filter->keys) { + // // cout << std::string(it) << " "; + // } cout << "\n"; } diff --git a/Geometry/HcalAlgo/data/cms-test-Phase2GeometryFine-algorithm.xml b/Geometry/HcalAlgo/data/cms-test-Phase2GeometryFine-algorithm.xml index 031456e8eddf2..6de53ba8f8af9 100644 --- a/Geometry/HcalAlgo/data/cms-test-Phase2GeometryFine-algorithm.xml +++ b/Geometry/HcalAlgo/data/cms-test-Phase2GeometryFine-algorithm.xml @@ -57,7 +57,7 @@ - + diff --git a/Geometry/HcalCommonData/data/hcalsens/HGCal/2021/v1/hcalsenspmf.xml b/Geometry/HcalCommonData/data/hcalsens/HGCal/2021/v1/hcalsenspmf.xml new file mode 100644 index 0000000000000..cffda3838bc31 --- /dev/null +++ b/Geometry/HcalCommonData/data/hcalsens/HGCal/2021/v1/hcalsenspmf.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Geometry/HcalCommonData/interface/HcalSimParametersFromDD.h b/Geometry/HcalCommonData/interface/HcalSimParametersFromDD.h index 98291a94f5b57..f848b5288922c 100644 --- a/Geometry/HcalCommonData/interface/HcalSimParametersFromDD.h +++ b/Geometry/HcalCommonData/interface/HcalSimParametersFromDD.h @@ -15,12 +15,12 @@ class HcalSimParametersFromDD { HcalSimParametersFromDD() = default; bool build(const DDCompactView*, HcalSimulationParameters&); - bool build(const cms::DDCompactView*, HcalSimulationParameters&); + bool build(const cms::DDCompactView&, HcalSimulationParameters&); private: bool buildParameters(const HcalSimulationParameters&); void fillNameVector(const DDCompactView*, const std::string&, const std::string&, std::vector&); - void fillNameVector(const cms::DDCompactView*, const std::string&, std::vector&); + void fillNameVector(const cms::DDCompactView&, const std::string&, std::vector&); void fillPMTs(const std::vector&, bool, HcalSimulationParameters&); bool isItHF(const std::string&, const HcalSimulationParameters&); std::vector getNames(DDFilteredView& fv); diff --git a/Geometry/HcalCommonData/plugins/HcalSimParametersESModule.cc b/Geometry/HcalCommonData/plugins/HcalSimParametersESModule.cc index 74241a1401630..d33c92597be15 100644 --- a/Geometry/HcalCommonData/plugins/HcalSimParametersESModule.cc +++ b/Geometry/HcalCommonData/plugins/HcalSimParametersESModule.cc @@ -61,7 +61,7 @@ HcalSimParametersESModule::ReturnType HcalSimParametersESModule::produce(const H edm::LogVerbatim("HCalGeom") << "HcalSimParametersESModule::Try to access cms::DDCompactView"; #endif edm::ESTransientHandle cpv = iRecord.getTransientHandle(cpvTokenDD4Hep_); - builder.build(&(*cpv), *ptp); + builder.build(*cpv, *ptp); } else { edm::ESTransientHandle cpv = iRecord.getTransientHandle(cpvTokenDDD_); builder.build(&(*cpv), *ptp); diff --git a/Geometry/HcalCommonData/src/HcalSimParametersFromDD.cc b/Geometry/HcalCommonData/src/HcalSimParametersFromDD.cc index 52ea483967831..825790139a01d 100644 --- a/Geometry/HcalCommonData/src/HcalSimParametersFromDD.cc +++ b/Geometry/HcalCommonData/src/HcalSimParametersFromDD.cc @@ -4,6 +4,7 @@ #include "DetectorDescription/Core/interface/DDSplit.h" #include "DetectorDescription/Core/interface/DDValue.h" #include "DetectorDescription/Core/interface/DDutils.h" +#include "DetectorDescription/DDCMS/interface/BenchmarkGrd.h" #include "DataFormats/Math/interface/GeantUnits.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" @@ -99,67 +100,77 @@ bool HcalSimParametersFromDD::build(const DDCompactView* cpv, HcalSimulationPara return buildParameters(php); } -bool HcalSimParametersFromDD::build(const cms::DDCompactView* cpv, HcalSimulationParameters& php) { +bool HcalSimParametersFromDD::build(const cms::DDCompactView& cpv, HcalSimulationParameters& php) { #ifdef EDM_ML_DEBUG edm::LogVerbatim("HCalGeom") << "Inside HcalSimParametersFromDD::build(const cms::DDCompactView*, HcalSimulationParameters&)"; #endif - // Parameters for the fibers - fillNameVector(cpv, "HF", php.hfNames_); - - // The level positions - cms::DDFilteredView fv1(cpv->detector(), cpv->detector()->worldVolume()); - php.hfLevels_ = dbl_to_int(fv1.get >("hf", "Levels")); + // HCal materials + const cms::DDFilter filter("OnlyForHcalSimNumbering", "HCAL"); + cms::DDFilteredView fv2(cpv, filter); + + { + BenchmarkGrd counter("HcalSimParametersFromDD get all vectors\n"); + + // The level positions + // const cms::DDFilter filter("", ""); + // cms::DDFilteredView fv1(cpv, filter); + php.hfLevels_ = fv2.get >("hf", "Levels"); // Attenuation length static const double cminv2mminv = 0.1; - php.attenuationLength_ = fv1.get >("hf", "attl"); + php.attenuationLength_ = fv2.get >("hf", "attl"); std::for_each(php.attenuationLength_.begin(), php.attenuationLength_.end(), [](double& n) { n *= cminv2mminv; }); // Limits on Lambda - php.lambdaLimits_ = dbl_to_int(fv1.get >("hf", "lambLim")); + php.lambdaLimits_ = fv2.get >("hf", "lambLim"); // Fibre Lengths - php.longFiberLength_ = fv1.get >("hf", "LongFL"); + php.longFiberLength_ = fv2.get >("hf", "LongFL"); std::for_each(php.longFiberLength_.begin(), php.longFiberLength_.end(), [](double& n) { n = convertCmToMm(n); }); - php.shortFiberLength_ = fv1.get >("hf", "ShortFL"); + php.shortFiberLength_ = fv2.get >("hf", "ShortFL"); std::for_each(php.shortFiberLength_.begin(), php.shortFiberLength_.end(), [](double& n) { n = convertCmToMm(n); }); //Parameters for the PMT - std::vector neta = fv1.get >("hfpmt", "indexPMTR"); + std::vector neta = fv2.get >("hfpmt", "indexPMTR"); fillPMTs(neta, false, php); - neta = fv1.get >("hfpmt", "indexPMTL"); + neta = fv2.get >("hfpmt", "indexPMTL"); fillPMTs(neta, true, php); + // Parameters for the fibers + fillNameVector(cpv, "HF", php.hfNames_); + //Names of special volumes (HFFibre, HFPMT, HFFibreBundles) fillNameVector(cpv, "HFFibre", php.hfFibreNames_); fillNameVector(cpv, "HFPMT", php.hfPMTNames_); fillNameVector(cpv, "HFFibreBundleStraight", php.hfFibreStraightNames_); fillNameVector(cpv, "HFFibreBundleConical", php.hfFibreConicalNames_); + } + { + BenchmarkGrd counter("HcalSimParametersFromDD HCal materials OnlyForHcalSimNumbering, HCAL"); - // HCal materials - cms::DDFilteredView fv2(cpv->detector(), cpv->detector()->worldVolume()); - cms::DDSpecParRefs ref2; - const cms::DDSpecParRegistry& par2 = cpv->specpars(); - par2.filter(ref2, "OnlyForHcalSimNumbering", "HCAL"); - fv2.mergedSpecifics(ref2); - - while (fv2.firstChild()) { - const std::string matName{cms::dd::noNamespace(fv2.materialName()).data(), - cms::dd::noNamespace(fv2.materialName()).size()}; + while (fv2.firstChild()) { + std::vector copy = fv2.copyNos(); // idet = 3 for HB and 4 for HE (convention in the ddalgo code for HB/HE) int idet = (copy.size() > 1) ? (copy[1] / 1000) : 0; - if (((idet == 3) || (idet == 4)) && - std::find(std::begin(php.hcalMaterialNames_), std::end(php.hcalMaterialNames_), matName) == - std::end(php.hcalMaterialNames_)) { - php.hcalMaterialNames_.emplace_back(matName); + if ((idet == 3) || (idet == 4)) { + std::string_view matName = cms::dd::noNamespace(fv2.materialName()); + if (std::find(std::begin(php.hcalMaterialNames_), std::end(php.hcalMaterialNames_), matName) == + std::end(php.hcalMaterialNames_)) { + php.hcalMaterialNames_.emplace_back(matName); + } } - }; + } + } + + return buildParameters(php); + } + bool HcalSimParametersFromDD::buildParameters(const HcalSimulationParameters& php) { #ifdef EDM_ML_DEBUG std::stringstream ss0; @@ -252,18 +263,20 @@ void HcalSimParametersFromDD::fillNameVector(const DDCompactView* cpv, lvnames = getNames(fv); } -void HcalSimParametersFromDD::fillNameVector(const cms::DDCompactView* cpv, +void HcalSimParametersFromDD::fillNameVector(const cms::DDCompactView& cpv, const std::string& value, std::vector& lvnames) { - cms::DDFilteredView fv(cpv->detector(), cpv->detector()->worldVolume()); - cms::DDSpecParRefs refs; - const cms::DDSpecParRegistry& mypar = cpv->specpars(); - mypar.filter(refs, "Volume", value); - fv.mergedSpecifics(refs); - lvnames = getNames(fv); + { + BenchmarkGrd counter("HcalSimParametersFromDD::fillNameVector"); + const cms::DDFilter filter("Volume", value); + cms::DDFilteredView fv(cpv, filter); + lvnames = getNames(fv); + } } void HcalSimParametersFromDD::fillPMTs(const std::vector& neta, bool lOrR, HcalSimulationParameters& php) { + { + BenchmarkGrd counter("HcalSimParametersFromDD::fillPMTs"); for (unsigned int ii = 0; ii < neta.size(); ii++) { int index = static_cast(neta[ii]); int ir = -1, ifib = -1; @@ -279,6 +292,7 @@ void HcalSimParametersFromDD::fillPMTs(const std::vector& neta, bool lOr php.pmtFiberRight_.push_back(ifib); } } + } } bool HcalSimParametersFromDD::isItHF(const std::string& name, const HcalSimulationParameters& php) { diff --git a/SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc b/SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc index 38ac85dcfb3f4..5487c9d8439f7 100644 --- a/SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc +++ b/SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc @@ -64,14 +64,14 @@ class DD4hepTestDDDWorld : public one::EDAnalyzer<> { G4MTRunManagerKernel* kernel_; DDSpecParRefs specs_; vector> vec_; - string_view keywordRegion_; + const string keywordRegion_; unique_ptr world_; int verbosity_; }; DD4hepTestDDDWorld::DD4hepTestDDDWorld(const ParameterSet& iConfig) - : tag_(iConfig.getParameter("DDDetector")) { - keywordRegion_ = "CMSCutsRegion"; + : tag_(iConfig.getParameter("DDDetector")), + keywordRegion_("CMSCutsRegion") { verbosity_ = iConfig.getUntrackedParameter("Verbosity", 1); kernel_ = new G4MTRunManagerKernel(); } @@ -135,10 +135,10 @@ void DD4hepTestDDDWorld::initialize(const dd4hep::sim::Geant4GeometryMaps::Volum // Now generate all the regions for (auto const& it : vec_) { - auto regName = it.second->strValue(keywordRegion_.data()); + auto regName = it.second->strValue(keywordRegion_); G4Region* region = G4RegionStore::GetInstance()->FindOrCreateRegion({regName.data(), regName.size()}); region->AddRootLogicalVolume(it.first); - LogVerbatim("Geometry") << it.first->GetName() << ": " << it.second->strValue(keywordRegion_.data()); + LogVerbatim("Geometry") << it.first->GetName() << ": " << it.second->strValue(keywordRegion_); LogVerbatim("Geometry") << " MakeRegions: added " << it.first->GetName() << " to region " << region->GetName(); } } @@ -160,7 +160,7 @@ void DD4hepTestDDDWorld::update() { }); // Loop over all DDLP and provide the cuts for each region for (auto const& it : vec_) { - auto regName = it.second->strValue(keywordRegion_.data()); + auto regName = it.second->strValue(keywordRegion_); G4Region* region = G4RegionStore::GetInstance()->FindOrCreateRegion({regName.data(), regName.size()}); // From 80589519872c55b8c45b29592a8bb4eab00ce6e8 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Mon, 16 Mar 2020 16:46:18 +0100 Subject: [PATCH 4/8] clean up and code format --- .../DDCMS/interface/DDFilteredView.h | 21 ++-- .../DDCMS/interface/DDSpecParRegistry.h | 3 +- .../DDCMS/src/DDFilteredView.cc | 24 ++-- .../DDCMS/src/DDSpecparRegistry.cc | 33 ++---- .../DDCMS/test/Filter.cppunit.cc | 20 ++-- .../src/HcalSimParametersFromDD.cc | 112 +++++++++--------- .../test/plugins/DD4hepTestDDDWorld.cc | 3 +- 7 files changed, 89 insertions(+), 127 deletions(-) diff --git a/DetectorDescription/DDCMS/interface/DDFilteredView.h b/DetectorDescription/DDCMS/interface/DDFilteredView.h index c1b1e0dd8ad8c..2ff9a8a067628 100644 --- a/DetectorDescription/DDCMS/interface/DDFilteredView.h +++ b/DetectorDescription/DDCMS/interface/DDFilteredView.h @@ -50,22 +50,18 @@ namespace cms { using Node = TGeoNode; using Translation = ROOT::Math::DisplacementVector3D>; using RotationMatrix = ROOT::Math::Rotation3D; - + struct DDFilter { DDFilter(const std::string& attribute = "", const std::string& value = "") - : m_attribute(attribute), - m_value(value) {} - const std::string& attribute() const { - return m_attribute; - } - const std::string& value() const { - return m_value; - } + : m_attribute(attribute), m_value(value) {} + const std::string& attribute() const { return m_attribute; } + const std::string& value() const { return m_value; } + private: const std::string m_attribute; const std::string m_value; }; - + class DDFilteredView { public: using nav_type = std::vector; @@ -101,9 +97,7 @@ namespace cms { //! User specific data void mergedSpecifics(DDSpecParRefs const&); - const cms::DDSpecParRefs specpars() const { - return refs_; - } + const cms::DDSpecParRefs specpars() const { return refs_; } //! set the current node to the first child bool firstChild(); @@ -197,7 +191,6 @@ namespace cms { //! set the current node to the first sibling bool firstSibling(); - void printFilter(const Filter* filter) const; ExpandedNodes nodes_; std::vector it_; diff --git a/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h b/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h index 8f1bca9043c5a..d7e4b82bb2dad 100644 --- a/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h +++ b/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h @@ -30,8 +30,7 @@ namespace cms { using DDSpecParRefs = std::vector; struct DDSpecParRegistry { - void filter(DDSpecParRefs&, const std::string&, const std::string&) const; - void filter(DDSpecParRefs&, const std::string&) const; + void filter(DDSpecParRefs&, const std::string&, const std::string& = "") const; std::vector names() const; std::vector names(const std::string& path) const; bool hasSpecPar(std::string_view) const; diff --git a/DetectorDescription/DDCMS/src/DDFilteredView.cc b/DetectorDescription/DDCMS/src/DDFilteredView.cc index 3e2df695b4637..e6184cc390e6c 100644 --- a/DetectorDescription/DDCMS/src/DDFilteredView.cc +++ b/DetectorDescription/DDCMS/src/DDFilteredView.cc @@ -46,7 +46,8 @@ DDFilteredView::DDFilteredView(const DDCompactView& cpv, const cms::DDFilter& fi registry_->filter(refs_, filter.attribute(), filter.value()); mergedSpecifics(refs_); LogVerbatim("Geometry").log([&](auto& log) { - log << "Filtered by an attribute " << filter.attribute() << "==" << filter.value() << " DD SpecPar Registry size: " << refs_.size() << "\n"; + log << "Filtered by an attribute " << filter.attribute() << "==" << filter.value() + << " DD SpecPar Registry size: " << refs_.size() << "\n"; for (const auto& t : refs_) { log << "\nRegExps { "; for (const auto& ki : t->paths) @@ -151,7 +152,9 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { for (const auto& j : i->paths) { vector toks = split(j, "/"); auto const& filter = find_if(begin(filters_), end(filters_), [&](auto const& f) { - auto const& k = find_if(begin(f->keys), end(f->keys), [&](auto const& p) { return std::regex_match(std::string({toks.front().data(), toks.front().size()}), p); }); + auto const& k = find_if(begin(f->keys), end(f->keys), [&](auto const& p) { + return std::regex_match(std::string({toks.front().data(), toks.front().size()}), p); + }); if (k != end(f->keys)) { currentFilter_ = f.get(); return true; @@ -160,28 +163,21 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { }); if (filter == end(filters_)) { filters_.emplace_back(unique_ptr( - new Filter{{std::regex( - std::string(toks.front().data(), toks.front().size()))}, - nullptr, - nullptr, - i})); + new Filter{{std::regex(std::string(toks.front().data(), toks.front().size()))}, nullptr, nullptr, i})); } // all next levels for (size_t pos = 1; pos < toks.size(); ++pos) { if (currentFilter_->next != nullptr) { currentFilter_ = currentFilter_->next.get(); auto const& l = find_if(begin(currentFilter_->keys), end(currentFilter_->keys), [&](auto const& p) { - return std::regex_match(std::string({toks.front().data(), toks.front().size()}), p); + return std::regex_match(std::string({toks.front().data(), toks.front().size()}), p); }); if (l == end(currentFilter_->keys)) { currentFilter_->keys.emplace_back(std::string(toks[pos].data(), toks[pos].size())); } } else { - currentFilter_->next.reset(new Filter{{std::regex( - std::string(toks[pos].data(), toks[pos].size()))}, - nullptr, - currentFilter_, - i}); + currentFilter_->next.reset( + new Filter{{std::regex(std::string(toks[pos].data(), toks[pos].size()))}, nullptr, currentFilter_, i}); } } } @@ -355,7 +351,7 @@ template <> std::string_view DDFilteredView::get(const string& key) const { std::string_view result; DDSpecParRefs refs; - registry_->filter(refs, key); + registry_->filter(refs, key, ""); int level = it_.back().GetLevel(); for_each(begin(refs), end(refs), [&](auto const& i) { auto k = find_if(begin(i->paths), end(i->paths), [&](auto const& j) { diff --git a/DetectorDescription/DDCMS/src/DDSpecparRegistry.cc b/DetectorDescription/DDCMS/src/DDSpecparRegistry.cc index 35e349a9dfeb1..db9ed816eea1c 100644 --- a/DetectorDescription/DDCMS/src/DDSpecparRegistry.cc +++ b/DetectorDescription/DDCMS/src/DDSpecparRegistry.cc @@ -101,31 +101,14 @@ void DDSpecParRegistry::filter(DDSpecParRefs& refs, const std::string& attribute found = false; for_each(begin(k.second.spars), end(k.second.spars), [&](const auto& l) { if (l.first == attribute) { - if (value.empty()) { - found = true; - } - else { - for_each(begin(l.second), end(l.second), [&](const auto& m) { - if (m == value) - found = true; - }); - } - } - }); - if (found) { - k.second.name = k.first; - refs.emplace_back(&k.second); - } - }); -} - -void DDSpecParRegistry::filter(DDSpecParRefs& refs, const std::string& attribute) const { - bool found(false); - 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 (value.empty()) { + found = true; + } else { + for_each(begin(l.second), end(l.second), [&](const auto& m) { + if (m == value) + found = true; + }); + } } }); if (found) { diff --git a/DetectorDescription/DDCMS/test/Filter.cppunit.cc b/DetectorDescription/DDCMS/test/Filter.cppunit.cc index b3d925ec37df9..e4ac3c7ac216c 100644 --- a/DetectorDescription/DDCMS/test/Filter.cppunit.cc +++ b/DetectorDescription/DDCMS/test/Filter.cppunit.cc @@ -44,7 +44,9 @@ void testFilter::setUp() { vector toks = split(i, "/"); unique_ptr f = nullptr; auto const& filter = find_if(begin(filters_), end(filters_), [&](auto const& f) { - auto const& k = find_if(begin(f->keys), end(f->keys), [&](auto const& p) { return std::regex_match(std::string({toks.front().data(), toks.front().size()}), p); }); + auto const& k = find_if(begin(f->keys), end(f->keys), [&](auto const& p) { + return std::regex_match(std::string({toks.front().data(), toks.front().size()}), p); + }); if (k != end(f->keys)) { currentFilter = f.get(); return true; @@ -53,26 +55,22 @@ void testFilter::setUp() { }); if (filter == end(filters_)) { filters_.emplace_back(unique_ptr( - new Filter{{std::regex( - regex(std::string(toks.front().data(), toks.front().size())))}, - nullptr, - nullptr})); + new Filter{{std::regex(regex(std::string(toks.front().data(), toks.front().size())))}, nullptr, nullptr})); currentFilter = filters_.back().get(); } // all next levels for (size_t pos = 1; pos < toks.size(); ++pos) { if (currentFilter->next != nullptr) { currentFilter = currentFilter->next.get(); - auto const& l = find_if( - begin(currentFilter->keys), end(currentFilter->keys), [&](auto const& p) { return std::regex_match(std::string({toks[pos].data(), toks[pos].size()}), p); }); + auto const& l = find_if(begin(currentFilter->keys), end(currentFilter->keys), [&](auto const& p) { + return std::regex_match(std::string({toks[pos].data(), toks[pos].size()}), p); + }); if (l == end(currentFilter->keys)) { currentFilter->keys.emplace_back(std::regex(std::string(toks.front().data(), toks.front().size()))); } } else { - currentFilter->next.reset(new Filter{ - {std::regex(std::string({toks[pos].data(), toks[pos].size()}))}, - nullptr, - currentFilter}); + currentFilter->next.reset( + new Filter{{std::regex(std::string({toks[pos].data(), toks[pos].size()}))}, nullptr, currentFilter}); } } } diff --git a/Geometry/HcalCommonData/src/HcalSimParametersFromDD.cc b/Geometry/HcalCommonData/src/HcalSimParametersFromDD.cc index 825790139a01d..3b983acba886a 100644 --- a/Geometry/HcalCommonData/src/HcalSimParametersFromDD.cc +++ b/Geometry/HcalCommonData/src/HcalSimParametersFromDD.cc @@ -106,71 +106,65 @@ bool HcalSimParametersFromDD::build(const cms::DDCompactView& cpv, HcalSimulatio << "Inside HcalSimParametersFromDD::build(const cms::DDCompactView*, HcalSimulationParameters&)"; #endif - // HCal materials - const cms::DDFilter filter("OnlyForHcalSimNumbering", "HCAL"); - cms::DDFilteredView fv2(cpv, filter); - + // HCal materials + const cms::DDFilter filter("OnlyForHcalSimNumbering", "HCAL"); + cms::DDFilteredView fv(cpv, filter); + { BenchmarkGrd counter("HcalSimParametersFromDD get all vectors\n"); - + // The level positions - // const cms::DDFilter filter("", ""); - // cms::DDFilteredView fv1(cpv, filter); - php.hfLevels_ = fv2.get >("hf", "Levels"); + php.hfLevels_ = fv.get >("hf", "Levels"); - // Attenuation length - static const double cminv2mminv = 0.1; - php.attenuationLength_ = fv2.get >("hf", "attl"); - std::for_each(php.attenuationLength_.begin(), php.attenuationLength_.end(), [](double& n) { n *= cminv2mminv; }); + // Attenuation length + static const double cminv2mminv = 0.1; + php.attenuationLength_ = fv.get >("hf", "attl"); + std::for_each(php.attenuationLength_.begin(), php.attenuationLength_.end(), [](double& n) { n *= cminv2mminv; }); - // Limits on Lambda - php.lambdaLimits_ = fv2.get >("hf", "lambLim"); + // Limits on Lambda + php.lambdaLimits_ = fv.get >("hf", "lambLim"); - // Fibre Lengths - php.longFiberLength_ = fv2.get >("hf", "LongFL"); - std::for_each(php.longFiberLength_.begin(), php.longFiberLength_.end(), [](double& n) { n = convertCmToMm(n); }); - php.shortFiberLength_ = fv2.get >("hf", "ShortFL"); - std::for_each(php.shortFiberLength_.begin(), php.shortFiberLength_.end(), [](double& n) { n = convertCmToMm(n); }); + // Fibre Lengths + php.longFiberLength_ = fv.get >("hf", "LongFL"); + std::for_each(php.longFiberLength_.begin(), php.longFiberLength_.end(), [](double& n) { n = convertCmToMm(n); }); + php.shortFiberLength_ = fv.get >("hf", "ShortFL"); + std::for_each(php.shortFiberLength_.begin(), php.shortFiberLength_.end(), [](double& n) { n = convertCmToMm(n); }); - //Parameters for the PMT - std::vector neta = fv2.get >("hfpmt", "indexPMTR"); - fillPMTs(neta, false, php); - neta = fv2.get >("hfpmt", "indexPMTL"); - fillPMTs(neta, true, php); + //Parameters for the PMT + std::vector neta = fv.get >("hfpmt", "indexPMTR"); + fillPMTs(neta, false, php); + neta = fv.get >("hfpmt", "indexPMTL"); + fillPMTs(neta, true, php); - // Parameters for the fibers - fillNameVector(cpv, "HF", php.hfNames_); + // Parameters for the fibers + fillNameVector(cpv, "HF", php.hfNames_); - //Names of special volumes (HFFibre, HFPMT, HFFibreBundles) - fillNameVector(cpv, "HFFibre", php.hfFibreNames_); - fillNameVector(cpv, "HFPMT", php.hfPMTNames_); - fillNameVector(cpv, "HFFibreBundleStraight", php.hfFibreStraightNames_); - fillNameVector(cpv, "HFFibreBundleConical", php.hfFibreConicalNames_); + //Names of special volumes (HFFibre, HFPMT, HFFibreBundles) + fillNameVector(cpv, "HFFibre", php.hfFibreNames_); + fillNameVector(cpv, "HFPMT", php.hfPMTNames_); + fillNameVector(cpv, "HFFibreBundleStraight", php.hfFibreStraightNames_); + fillNameVector(cpv, "HFFibreBundleConical", php.hfFibreConicalNames_); } { BenchmarkGrd counter("HcalSimParametersFromDD HCal materials OnlyForHcalSimNumbering, HCAL"); - while (fv2.firstChild()) { - - std::vector copy = fv2.copyNos(); - // idet = 3 for HB and 4 for HE (convention in the ddalgo code for HB/HE) - int idet = (copy.size() > 1) ? (copy[1] / 1000) : 0; - if ((idet == 3) || (idet == 4)) { - std::string_view matName = cms::dd::noNamespace(fv2.materialName()); - if (std::find(std::begin(php.hcalMaterialNames_), std::end(php.hcalMaterialNames_), matName) == - std::end(php.hcalMaterialNames_)) { - php.hcalMaterialNames_.emplace_back(matName); + while (fv.firstChild()) { + std::vector copy = fv.copyNos(); + // idet = 3 for HB and 4 for HE (convention in the ddalgo code for HB/HE) + int idet = (copy.size() > 1) ? (copy[1] / 1000) : 0; + if ((idet == 3) || (idet == 4)) { + std::string_view matName = cms::dd::noNamespace(fv.materialName()); + if (std::find(std::begin(php.hcalMaterialNames_), std::end(php.hcalMaterialNames_), matName) == + std::end(php.hcalMaterialNames_)) { + php.hcalMaterialNames_.emplace_back(matName); + } } } } - } - return buildParameters(php); - } - bool HcalSimParametersFromDD::buildParameters(const HcalSimulationParameters& php) { #ifdef EDM_ML_DEBUG std::stringstream ss0; @@ -277,22 +271,22 @@ void HcalSimParametersFromDD::fillNameVector(const cms::DDCompactView& cpv, void HcalSimParametersFromDD::fillPMTs(const std::vector& neta, bool lOrR, HcalSimulationParameters& php) { { BenchmarkGrd counter("HcalSimParametersFromDD::fillPMTs"); - for (unsigned int ii = 0; ii < neta.size(); ii++) { - int index = static_cast(neta[ii]); - int ir = -1, ifib = -1; - if (index >= 0) { - ir = index / 10; - ifib = index % 10; - } - if (lOrR) { - php.pmtLeft_.push_back(ir); - php.pmtFiberLeft_.push_back(ifib); - } else { - php.pmtRight_.push_back(ir); - php.pmtFiberRight_.push_back(ifib); + for (unsigned int ii = 0; ii < neta.size(); ii++) { + int index = static_cast(neta[ii]); + int ir = -1, ifib = -1; + if (index >= 0) { + ir = index / 10; + ifib = index % 10; + } + if (lOrR) { + php.pmtLeft_.push_back(ir); + php.pmtFiberLeft_.push_back(ifib); + } else { + php.pmtRight_.push_back(ir); + php.pmtFiberRight_.push_back(ifib); + } } } - } } bool HcalSimParametersFromDD::isItHF(const std::string& name, const HcalSimulationParameters& php) { diff --git a/SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc b/SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc index 5487c9d8439f7..3d10eda7e2f6c 100644 --- a/SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc +++ b/SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc @@ -70,8 +70,7 @@ class DD4hepTestDDDWorld : public one::EDAnalyzer<> { }; DD4hepTestDDDWorld::DD4hepTestDDDWorld(const ParameterSet& iConfig) - : tag_(iConfig.getParameter("DDDetector")), - keywordRegion_("CMSCutsRegion") { + : tag_(iConfig.getParameter("DDDetector")), keywordRegion_("CMSCutsRegion") { verbosity_ = iConfig.getUntrackedParameter("Verbosity", 1); kernel_ = new G4MTRunManagerKernel(); } From 59e68bff9c3d76cccfe18b5a0426558804bae0b5 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Mon, 16 Mar 2020 17:16:15 +0100 Subject: [PATCH 5/8] remove print --- DetectorDescription/DDCMS/test/Filter.cppunit.cc | 12 +----------- .../plugins/dd4hep/DTGeometryBuilder.cc | 2 -- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/DetectorDescription/DDCMS/test/Filter.cppunit.cc b/DetectorDescription/DDCMS/test/Filter.cppunit.cc index e4ac3c7ac216c..e063489b81518 100644 --- a/DetectorDescription/DDCMS/test/Filter.cppunit.cc +++ b/DetectorDescription/DDCMS/test/Filter.cppunit.cc @@ -24,7 +24,6 @@ class testFilter : public CppUnit::TestFixture { void checkFilter(); private: - void print(Filter*); vector> filters_; }; @@ -55,7 +54,7 @@ void testFilter::setUp() { }); if (filter == end(filters_)) { filters_.emplace_back(unique_ptr( - new Filter{{std::regex(regex(std::string(toks.front().data(), toks.front().size())))}, nullptr, nullptr})); + new Filter{{std::regex(std::string(toks.front().data(), toks.front().size()))}, nullptr, nullptr})); currentFilter = filters_.back().get(); } // all next levels @@ -84,19 +83,10 @@ void testFilter::checkFilter() { CPPUNIT_ASSERT(filters_.size() == 1); Filter* current = nullptr; - cout << "Filters...\n"; for (auto const& i : filters_) { current = i.get(); do { - print(current); current = current->next.get(); } while (current != nullptr); } } - -void testFilter::print(Filter* filter) { - // for (auto const& it : filter->keys) { - // // cout << std::string(it) << " "; - // } - cout << "\n"; -} diff --git a/Geometry/DTGeometryBuilder/plugins/dd4hep/DTGeometryBuilder.cc b/Geometry/DTGeometryBuilder/plugins/dd4hep/DTGeometryBuilder.cc index 40f99a8e0e3f0..10756210af15a 100644 --- a/Geometry/DTGeometryBuilder/plugins/dd4hep/DTGeometryBuilder.cc +++ b/Geometry/DTGeometryBuilder/plugins/dd4hep/DTGeometryBuilder.cc @@ -56,13 +56,11 @@ void DTGeometryBuilder::buildGeometry(DDFilteredView& fview, DTGeometry& geom, c // Loop on SLs bool doSL = fview.nextSibling(); - while (doSL) { DTSuperLayer* sl = buildSuperLayer(fview, chamber, num); // Loop on Layers fview.down(); - bool doLayers = fview.sibling(); while (doLayers) { DTLayer* l = buildLayer(fview, sl, num); From b8ad3402f09cfebc69ac95e5c92ced39aa6520ee Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 17 Mar 2020 12:05:17 +0100 Subject: [PATCH 6/8] Cleanup Hcal parameters built from DD4hep --- .../DDCMS/interface/DDCompactView.h | 2 +- .../DDCMS/src/DDCompactView.cc | 27 +-- .../interface/HcalGeomParameters.h | 2 +- .../interface/HcalParametersFromDD.h | 2 +- .../plugins/HcalParametersESModule.cc | 2 +- .../HcalCommonData/src/HcalGeomParameters.cc | 10 +- .../src/HcalParametersFromDD.cc | 185 +++++------------- 7 files changed, 76 insertions(+), 154 deletions(-) diff --git a/DetectorDescription/DDCMS/interface/DDCompactView.h b/DetectorDescription/DDCMS/interface/DDCompactView.h index e2bc5f74060cb..153963c90328e 100644 --- a/DetectorDescription/DDCMS/interface/DDCompactView.h +++ b/DetectorDescription/DDCMS/interface/DDCompactView.h @@ -32,7 +32,7 @@ namespace cms { const cms::DDDetector* detector() const { return &m_det; } DDSpecParRegistry const& specpars() const { return m_det.specpars(); } template - std::vector getVector(std::string_view) const; + std::vector getVector(const std::string&) const; private: const cms::DDDetector& m_det; diff --git a/DetectorDescription/DDCMS/src/DDCompactView.cc b/DetectorDescription/DDCMS/src/DDCompactView.cc index 1a1cc6f9b754e..4db370c846a9a 100644 --- a/DetectorDescription/DDCMS/src/DDCompactView.cc +++ b/DetectorDescription/DDCMS/src/DDCompactView.cc @@ -4,29 +4,32 @@ #include template <> -std::vector cms::DDCompactView::getVector(std::string_view key) const { - cms::DDVectorsMap vmap = this->detector()->vectors(); - std::vector temp; +std::vector cms::DDCompactView::getVector(const std::string& key) const { + const cms::DDVectorsMap& vmap = this->detector()->vectors(); + std::vector result; for (auto const& it : vmap) { - if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), key)) { + if (cms::dd::noNamespace(it.first) == key) { for (const auto& i : it.second) { - temp.emplace_back(std::round(i)); + result.emplace_back(std::round(i)); } + break; } } - return temp; + return result; } template <> -std::vector cms::DDCompactView::getVector(std::string_view key) const { - cms::DDVectorsMap vmap = this->detector()->vectors(); - std::vector temp; +std::vector cms::DDCompactView::getVector(const std::string& key) const { + const cms::DDVectorsMap& vmap = this->detector()->vectors(); + std::vector result; + for (auto const& it : vmap) { - if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), key)) { + if (cms::dd::noNamespace(it.first) == key) { for (const auto& i : it.second) { - temp.emplace_back(i); + result.emplace_back(i); } + break; } } - return temp; + return result; } diff --git a/Geometry/HcalCommonData/interface/HcalGeomParameters.h b/Geometry/HcalCommonData/interface/HcalGeomParameters.h index fc44621d787e2..d9c323e8259cd 100644 --- a/Geometry/HcalCommonData/interface/HcalGeomParameters.h +++ b/Geometry/HcalCommonData/interface/HcalGeomParameters.h @@ -40,7 +40,7 @@ class HcalGeomParameters { void getConstRHO(std::vector&) const; std::vector getModHalfHBHE(const int type) const; void loadGeometry(const DDFilteredView& _fv, HcalParameters& php); - void loadGeometry(const cms::DDCompactView* cpv, HcalParameters& php); + void loadGeometry(const cms::DDCompactView& cpv, HcalParameters& php); private: unsigned find(int element, std::vector& array) const; diff --git a/Geometry/HcalCommonData/interface/HcalParametersFromDD.h b/Geometry/HcalCommonData/interface/HcalParametersFromDD.h index 7d2dc7eaba61c..93c6760592096 100644 --- a/Geometry/HcalCommonData/interface/HcalParametersFromDD.h +++ b/Geometry/HcalCommonData/interface/HcalParametersFromDD.h @@ -11,7 +11,7 @@ class HcalParametersFromDD { HcalParametersFromDD() = default; bool build(const DDCompactView*, HcalParameters&); - bool build(const cms::DDCompactView*, HcalParameters&); + bool build(const cms::DDCompactView&, HcalParameters&); private: bool build(HcalParameters&); diff --git a/Geometry/HcalCommonData/plugins/HcalParametersESModule.cc b/Geometry/HcalCommonData/plugins/HcalParametersESModule.cc index 8817752bfe08c..7f7ad0c8ce0e1 100644 --- a/Geometry/HcalCommonData/plugins/HcalParametersESModule.cc +++ b/Geometry/HcalCommonData/plugins/HcalParametersESModule.cc @@ -58,7 +58,7 @@ HcalParametersESModule::ReturnType HcalParametersESModule::produce(const HcalPar edm::LogVerbatim("HCalGeom") << "HcalParametersESModule::Try to access cms::DDCompactView"; #endif edm::ESTransientHandle cpv = iRecord.getTransientHandle(cpvTokenDD4Hep_); - builder.build(&(*cpv), *ptp); + builder.build(*cpv, *ptp); } else { #ifdef EDM_ML_DEBUG edm::LogVerbatim("HCalGeom") << "HcalParametersESModule::Try to access DDCompactView"; diff --git a/Geometry/HcalCommonData/src/HcalGeomParameters.cc b/Geometry/HcalCommonData/src/HcalGeomParameters.cc index c0d23908d0ade..a5a1c3010b98a 100644 --- a/Geometry/HcalCommonData/src/HcalGeomParameters.cc +++ b/Geometry/HcalCommonData/src/HcalGeomParameters.cc @@ -236,13 +236,9 @@ void HcalGeomParameters::loadGeometry(const DDFilteredView& _fv, HcalParameters& loadfinal(php); } -void HcalGeomParameters::loadGeometry(const cms::DDCompactView* cpv, HcalParameters& php) { - cms::DDFilteredView fv(cpv->detector(), cpv->detector()->worldVolume()); - std::string attribute = "OnlyForHcalSimNumbering"; - cms::DDSpecParRefs ref; - const cms::DDSpecParRegistry& mypar = cpv->specpars(); - mypar.filter(ref, attribute, "HCAL"); - fv.mergedSpecifics(ref); +void HcalGeomParameters::loadGeometry(const cms::DDCompactView& cpv, HcalParameters& php) { + const cms::DDFilter filter("OnlyForHcalSimNumbering", "HCAL"); + cms::DDFilteredView fv(cpv, filter); clear(php); bool hf(false); while (fv.firstChild()) { diff --git a/Geometry/HcalCommonData/src/HcalParametersFromDD.cc b/Geometry/HcalCommonData/src/HcalParametersFromDD.cc index cbdf15d1a2385..65a850a665483 100644 --- a/Geometry/HcalCommonData/src/HcalParametersFromDD.cc +++ b/Geometry/HcalCommonData/src/HcalParametersFromDD.cc @@ -138,148 +138,71 @@ bool HcalParametersFromDD::build(const DDCompactView* cpv, HcalParameters& php) return build(php); } -bool HcalParametersFromDD::build(const cms::DDCompactView* cpv, HcalParameters& php) { +bool HcalParametersFromDD::build(const cms::DDCompactView& cpv, HcalParameters& php) { #ifdef EDM_ML_DEBUG edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD::build(const cms::DDCompactView*, HcalParameters&) is called"; #endif - //Special parameters at simulation level - cms::DDFilteredView fv1(cpv->detector(), cpv->detector()->worldVolume()); - cms::DDVectorsMap vmap = cpv->detector()->vectors(); - std::string attribute = "OnlyForHcalSimNumbering"; - cms::DDSpecParRefs ref1; - const cms::DDSpecParRegistry& mypar1 = cpv->specpars(); - mypar1.filter(ref1, attribute, "HCAL"); - fv1.mergedSpecifics(ref1); - const int nEtaMax = 100; - if (fv1.firstChild()) { - std::unique_ptr geom = std::make_unique(); - geom->loadGeometry(cpv, php); - php.modHB = geom->getModHalfHBHE(0); - php.modHE = geom->getModHalfHBHE(1); - php.dzVcal = geom->getConstDzHF(); - geom->getConstRHO(php.rHO); + std::unique_ptr geom = std::make_unique(); + geom->loadGeometry(cpv, php); + php.modHB = geom->getModHalfHBHE(0); + php.modHE = geom->getModHalfHBHE(1); + php.dzVcal = geom->getConstDzHF(); + geom->getConstRHO(php.rHO); - for (auto const& it : vmap) { - if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "phioff")) { - for (const auto& i : it.second) - php.phioff.emplace_back(i); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "etaTable")) { - for (const auto& i : it.second) - php.etaTable.emplace_back(i); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "rTable")) { - for (const auto& i : it.second) - php.rTable.emplace_back(i); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "phibin")) { - for (const auto& i : it.second) - php.phibin.emplace_back(i); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "phitable")) { - for (const auto& i : it.second) - php.phitable.emplace_back(i); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "etaMin")) { - for (const auto& i : it.second) - php.etaMin.emplace_back(std::round(i)); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "etaMax")) { - for (const auto& i : it.second) - php.etaMax.emplace_back(std::round(i)); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "etaRange")) { - for (const auto& i : it.second) - php.etaRange.emplace_back(i); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "gparHF")) { - for (const auto& i : it.second) - php.gparHF.emplace_back(i); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "noff")) { - for (const auto& i : it.second) - php.noff.emplace_back(std::round(i)); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "Layer0Wt")) { - for (const auto& i : it.second) - php.Layer0Wt.emplace_back(i); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "HBGains")) { - for (const auto& i : it.second) - php.HBGains.emplace_back(i); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "HBShift")) { - for (const auto& i : it.second) - php.HBShift.emplace_back(round(i)); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "HEGains")) { - for (const auto& i : it.second) - php.HEGains.emplace_back(i); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "HEShift")) { - for (const auto& i : it.second) - php.HEShift.emplace_back(round(i)); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "HFGains")) { - for (const auto& i : it.second) - php.HFGains.emplace_back(i); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "HFShift")) { - for (const auto& i : it.second) - php.HFShift.emplace_back(round(i)); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "MaxDepth")) { - for (const auto& i : it.second) - php.maxDepth.emplace_back(round(i)); - } - } - rescale(php.rTable, HcalGeomParameters::k_ScaleFromDD4HepToG4); - rescale(php.gparHF, HcalGeomParameters::k_ScaleFromDD4HepToG4); - for (unsigned int i = 1; i <= nEtaMax; ++i) { - std::stringstream sstm; - sstm << "layerGroupSimEta" << i; - std::string tempName = sstm.str(); - for (auto const& it : vmap) { - if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), tempName)) { - HcalParameters::LayerItem layerGroupEta; - layerGroupEta.layer = i; - for (const auto& i : it.second) - layerGroupEta.layerGroup.emplace_back(round(i)); - php.layerGroupEtaSim.emplace_back(layerGroupEta); - break; - } - } + php.phioff = cpv.getVector("phioff"); + php.etaTable = cpv.getVector("etaTable"); + php.rTable = cpv.getVector("rTable"); + php.phibin = cpv.getVector("phibin"); + php.phitable = cpv.getVector("phitable"); + php.etaMin = cpv.getVector("etaMin"); + php.etaMax = cpv.getVector("etaMax"); + php.etaRange = cpv.getVector("etaRange"); + php.gparHF = cpv.getVector("gparHF"); + php.noff = cpv.getVector("noff"); + php.Layer0Wt = cpv.getVector("Layer0Wt"); + php.HBGains = cpv.getVector("HBGains"); + php.HBShift = cpv.getVector("HBShift"); + php.HEGains = cpv.getVector("HEGains"); + php.HEShift = cpv.getVector("HEShift"); + php.HFGains = cpv.getVector("HFGains"); + php.HFShift = cpv.getVector("HFShift"); + php.maxDepth = cpv.getVector("MaxDepth"); + + rescale(php.rTable, HcalGeomParameters::k_ScaleFromDD4HepToG4); + rescale(php.gparHF, HcalGeomParameters::k_ScaleFromDD4HepToG4); + for (unsigned int i = 1; i <= nEtaMax; ++i) { + HcalParameters::LayerItem layerGroupEta; + layerGroupEta.layer = i; + layerGroupEta.layerGroup = cpv.getVector(std::string("layerGroupSimEta") + std::to_string(i)); + if (!layerGroupEta.layerGroup.empty()) { + php.layerGroupEtaSim.emplace_back(layerGroupEta); } - } else { - throw cms::Exception("HcalParametersFromDD") << "Not found " << attribute.c_str() << " but needed."; } //Special parameters at reconstruction level - cms::DDFilteredView fv2(cpv->detector(), cpv->detector()->worldVolume()); - attribute = "OnlyForHcalRecNumbering"; - cms::DDSpecParRefs ref2; - const cms::DDSpecParRegistry& mypar2 = cpv->specpars(); - mypar2.filter(ref2, attribute, "HCAL"); - fv2.mergedSpecifics(ref2); - if (fv2.firstChild()) { - std::vector tempS = fv2.get >("hcal", "TopologyMode"); - std::string sv = (!tempS.empty()) ? tempS[0] : "HcalTopologyMode::SLHC"; - int topoMode = getTopologyMode(sv, true); - tempS = fv2.get >("hcal", "TriggerMode"); - sv = (!tempS.empty()) ? tempS[0] : "HcalTopologyMode::TriggerMode_2021"; - int trigMode = getTopologyMode(sv, false); - php.topologyMode = ((trigMode & 0xFF) << 8) | (topoMode & 0xFF); - for (auto const& it : vmap) { - if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "etagroup")) { - for (const auto& i : it.second) - php.etagroup.emplace_back(round(i)); - } else if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), "phigroup")) { - for (const auto& i : it.second) - php.phigroup.emplace_back(round(i)); - } - } - for (unsigned int i = 1; i <= nEtaMax; ++i) { - std::stringstream sstm; - sstm << "layerGroupRecEta" << i; - std::string tempName = sstm.str(); - for (auto const& it : vmap) { - if (cms::dd::compareEqual(cms::dd::noNamespace(it.first), tempName)) { - HcalParameters::LayerItem layerGroupEta; - layerGroupEta.layer = i; - for (const auto& i : it.second) - layerGroupEta.layerGroup.emplace_back(round(i)); - php.layerGroupEtaRec.emplace_back(layerGroupEta); - break; - } - } + const cms::DDFilter filter("OnlyForHcalRecNumbering", "HCAL"); + cms::DDFilteredView fv(cpv, filter); + + std::vector tempS = fv.get >("hcal", "TopologyMode"); + std::string sv = (!tempS.empty()) ? tempS[0] : "HcalTopologyMode::SLHC"; + int topoMode = getTopologyMode(sv, true); + tempS = fv.get >("hcal", "TriggerMode"); + sv = (!tempS.empty()) ? tempS[0] : "HcalTopologyMode::TriggerMode_2021"; + int trigMode = getTopologyMode(sv, false); + php.topologyMode = ((trigMode & 0xFF) << 8) | (topoMode & 0xFF); + + php.etagroup = cpv.getVector("etagroup"); + php.phigroup = cpv.getVector("phigroup"); + + for (unsigned int i = 1; i <= nEtaMax; ++i) { + HcalParameters::LayerItem layerGroupEta; + layerGroupEta.layer = i; + layerGroupEta.layerGroup = cpv.getVector(std::string("layerGroupRecEta") + std::to_string(i)); + if (!layerGroupEta.layerGroup.empty()) { + php.layerGroupEtaRec.emplace_back(layerGroupEta); } - } else { - throw cms::Exception("HcalParametersFromDD") << "Not found " << attribute.c_str() << " but needed."; } return build(php); From ba2c14807dd29f9f007a84b9e42bd4d35ff96167 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 17 Mar 2020 12:06:42 +0100 Subject: [PATCH 7/8] code format --- DetectorDescription/DDCMS/src/DDCompactView.cc | 2 +- Geometry/HcalCommonData/src/HcalParametersFromDD.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DetectorDescription/DDCMS/src/DDCompactView.cc b/DetectorDescription/DDCMS/src/DDCompactView.cc index 4db370c846a9a..8394f5f811d60 100644 --- a/DetectorDescription/DDCMS/src/DDCompactView.cc +++ b/DetectorDescription/DDCMS/src/DDCompactView.cc @@ -10,7 +10,7 @@ std::vector cms::DDCompactView::getVector(const std::string& key) cons for (auto const& it : vmap) { if (cms::dd::noNamespace(it.first) == key) { for (const auto& i : it.second) { - result.emplace_back(std::round(i)); + result.emplace_back(std::round(i)); } break; } diff --git a/Geometry/HcalCommonData/src/HcalParametersFromDD.cc b/Geometry/HcalCommonData/src/HcalParametersFromDD.cc index 65a850a665483..6ba4fca6563b2 100644 --- a/Geometry/HcalCommonData/src/HcalParametersFromDD.cc +++ b/Geometry/HcalCommonData/src/HcalParametersFromDD.cc @@ -169,7 +169,7 @@ bool HcalParametersFromDD::build(const cms::DDCompactView& cpv, HcalParameters& php.HFGains = cpv.getVector("HFGains"); php.HFShift = cpv.getVector("HFShift"); php.maxDepth = cpv.getVector("MaxDepth"); - + rescale(php.rTable, HcalGeomParameters::k_ScaleFromDD4HepToG4); rescale(php.gparHF, HcalGeomParameters::k_ScaleFromDD4HepToG4); for (unsigned int i = 1; i <= nEtaMax; ++i) { From 0bb2c0c1219da8ce602e3a2a2687bfee3123fcf9 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 17 Mar 2020 12:11:40 +0100 Subject: [PATCH 8/8] fix unit test --- Geometry/DTGeometryBuilder/test/runTest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Geometry/DTGeometryBuilder/test/runTest.sh b/Geometry/DTGeometryBuilder/test/runTest.sh index 48473f9ded536..ee27cafcaefbe 100755 --- a/Geometry/DTGeometryBuilder/test/runTest.sh +++ b/Geometry/DTGeometryBuilder/test/runTest.sh @@ -5,7 +5,7 @@ function checkDiff { FSIZE=$(stat -c%s "$1") echo "The output diff is $FSIZE:" cat $1; - if [ $FSIZE -gt 0 ] + if [ $FSIZE -gt 1000 ] then exit -1; fi