From d5ee0fb603c33df9fd3bd12c827a1fc8cec68df9 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 19 Mar 2019 18:47:57 +0100 Subject: [PATCH 1/2] DD Filtered view --- .../DDCMS/data/cms-2015-muon-geometry.xml | 2 +- .../DDCMS/interface/DDExpandedNode.h | 36 -- .../DDCMS/interface/DDFilteredView.h | 108 +++--- .../DDCMS/interface/ExpandedNodes.h | 33 ++ DetectorDescription/DDCMS/interface/Filter.h | 45 +++ .../DDCMS/interface/MuonNumbering.h | 4 +- .../DDCMS/python/cmsMFGeometryXML_cfi.py | 3 +- .../DDCMS/src/DDFilteredView.cc | 303 +++++++++-------- DetectorDescription/DDCMS/src/Filter.cc | 87 +++++ .../DDCMS/src/MuonNumbering.cc | 2 +- DetectorDescription/DDCMS/test/BuildFile.xml | 9 + .../DDCMS/test/DDFilteredView.cppunit.cc | 26 ++ .../DDCMS/test/Filter.cppunit.cc | 103 ++++++ .../interface/DTGeometryBuilder.h | 17 +- .../RecoGeometry/plugins/DTGeometryTest.cc | 20 ++ .../RecoGeometry/src/DTGeometryBuilder.cc | 199 ++++------- .../dtSpecsFilter/2019/v1/dtSpecsFilter.xml | 318 ++++++++++++++++++ 17 files changed, 916 insertions(+), 399 deletions(-) delete mode 100644 DetectorDescription/DDCMS/interface/DDExpandedNode.h create mode 100644 DetectorDescription/DDCMS/interface/ExpandedNodes.h create mode 100644 DetectorDescription/DDCMS/interface/Filter.h create mode 100644 DetectorDescription/DDCMS/src/Filter.cc create mode 100644 DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc create mode 100644 DetectorDescription/DDCMS/test/Filter.cppunit.cc create mode 100644 Geometry/DTGeometryBuilder/data/dtSpecsFilter/2019/v1/dtSpecsFilter.xml diff --git a/DetectorDescription/DDCMS/data/cms-2015-muon-geometry.xml b/DetectorDescription/DDCMS/data/cms-2015-muon-geometry.xml index ee790a1a553a4..3edc29e248829 100644 --- a/DetectorDescription/DDCMS/data/cms-2015-muon-geometry.xml +++ b/DetectorDescription/DDCMS/data/cms-2015-muon-geometry.xml @@ -57,7 +57,7 @@ - + diff --git a/DetectorDescription/DDCMS/interface/DDExpandedNode.h b/DetectorDescription/DDCMS/interface/DDExpandedNode.h deleted file mode 100644 index 7ab09663fc8c3..0000000000000 --- a/DetectorDescription/DDCMS/interface/DDExpandedNode.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef DETECTOR_DESCRIPTION_DD_EXPANDED_NODE_H -#define DETECTOR_DESCRIPTION_DD_EXPANDED_NODE_H - -#include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h" -#include -#include - -#include - -namespace cms { - - using DDVolume = dd4hep::Volume; - using DDTranslation = ROOT::Math::DisplacementVector3D>; - using DDRotationMatrix = ROOT::Math::Rotation3D; - - struct DDExpandedNode { - - DDVolume volume; // logicalpart to provide access to solid & material information - DDTranslation trans; // absolute translation - DDRotationMatrix rot; // absolute rotation - int copyNo; - int siblingno; // internal sibling-numbering from 0 to max-sibling - DDSpecPar specpar; - - DDExpandedNode(DDVolume const& aVolume, DDTranslation const& aTrans, - DDRotationMatrix const& aRot, int aCopyNo, int num) - : volume(aVolume), - trans(aTrans), - rot(aRot), - copyNo(aCopyNo), - siblingno(num) { - } - }; -} - -#endif diff --git a/DetectorDescription/DDCMS/interface/DDFilteredView.h b/DetectorDescription/DDCMS/interface/DDFilteredView.h index 32c8d0c13621d..b6772e49c5034 100644 --- a/DetectorDescription/DDCMS/interface/DDFilteredView.h +++ b/DetectorDescription/DDCMS/interface/DDFilteredView.h @@ -18,36 +18,44 @@ // Created: Wed, 30 Jan 2019 09:24:30 GMT // // -#include "DetectorDescription/DDCMS/interface/DDExpandedNode.h" - +#include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h" +#include "DetectorDescription/DDCMS/interface/ExpandedNodes.h" +#include "DetectorDescription/DDCMS/interface/Filter.h" +#include +#include #include namespace cms { class DDDetector; - //! Geometrical 'path' of the current node up to the root-node - using DDGeoHistory = std::vector; using Volume = dd4hep::Volume; + using PlacedVolume = dd4hep::PlacedVolume; + using ExpandedNodes = cms::ExpandedNodes; + using Filter = cms::Filter; + using Iterator = TGeoIterator; + using Node = TGeoNode; + + class DDFilteredView { + + public: - struct DDFilteredView { - - struct ExpandedNodes { - std::vector tags; - std::vector offsets; - std::vector copyNos; - } nodes; + DDFilteredView(const DDDetector*, const Volume); + DDFilteredView() = delete; - DDFilteredView(const DDDetector*); + //! The numbering history of the current node + const ExpandedNodes& history() const { + return nodes_; + } - //! The logical-part of the current node in the filtered-view - const DDVolume & volume() const; + //! The physical volume of the current node + const PlacedVolume volume() const; //! The absolute translation of the current node - const DDTranslation & translation() const; + const Double_t* trans() const; //! The absolute rotation of the current node - const DDRotationMatrix & rotation() const; + const Double_t* rot() const; //! User specific data void mergedSpecifics(DDSpecParRefs const&); @@ -55,51 +63,49 @@ namespace cms { //! set the current node to the first child bool firstChild(); + //! set the current node to the first sibling + bool firstSibling(); + //! set the current node to the next sibling bool nextSibling(); - //! set current node to the next node in the filtered tree - bool next(); + //! set the current node to the next sub sibling + bool sibling(); + bool siblingNoCheck(); - //! The list of ancestors up to the root-node of the current node - const DDGeoHistory & geoHistory() const; - - bool accepted(std::string_view, std::string_view) const; - bool accepted(std::vector const&, std::string_view) const; - bool acceptedM(std::vector&, std::string_view) const; - std::vector const& topNodes() const { return topNodes_; } - std::vector const& nextNodes() const { return nextNodes_; } - std::vector const& afterNextNodes() const { return afterNextNodes_; } + //! count the number of children matching selection + bool checkChild(); - std::vector extractParameters() const; - std::vector paths(const char*) const; - bool checkPath(std::string_view, TGeoNode *); - bool checkNode(TGeoNode *); + //! set the current node to the parent node ... + bool parent(); + + //! set current node to the next node in the filtered tree + bool next(int); + + //! set current node to the child node in the filtered tree + void down(); + + //! set current node to the parent node in the filtered tree + void up(); + + //! pop current node void unCheckNode(); - void filter(DDSpecParRefs&, std::string_view, std::string_view) const; - std::vector vPathsTo(const DDSpecPar&, unsigned int) const; - std::vector tails(const std::vector& fullPath) const; - DDGeoHistory parents_; - + //! extract shape parameters + std::vector extractParameters() const; + private: - const DDSpecParRegistry* registry_; - bool isRegex(std::string_view) const; - int contains(std::string_view, std::string_view) const; - std::string_view realTopName(std::string_view input) const; - int copyNo(std::string_view input) const; - std::string_view noCopyNo(std::string_view input) const; - std::string_view noNamespace(std::string_view input) const; - std::vector split(std::string_view, const char*) const; - bool acceptRegex(std::string_view, std::string_view) const; + bool accept(std::string_view); + bool addPath(std::string_view, Node* const); + bool addNode(Node* const); - std::vector topNodes_; - std::vector nextNodes_; - std::vector afterNextNodes_; - - TGeoVolume *topVolume_ = nullptr; - TGeoNode *node_ = nullptr; + ExpandedNodes nodes_; + std::vector it_; + std::vector> filters_; + Filter* currentFilter_ = nullptr; + Node *node_ = nullptr; + const DDSpecParRegistry* registry_; }; } diff --git a/DetectorDescription/DDCMS/interface/ExpandedNodes.h b/DetectorDescription/DDCMS/interface/ExpandedNodes.h new file mode 100644 index 0000000000000..59580d16990ec --- /dev/null +++ b/DetectorDescription/DDCMS/interface/ExpandedNodes.h @@ -0,0 +1,33 @@ +#ifndef DETECTOR_DESCRIPTION_EXPANDED_NODES_H +#define DETECTOR_DESCRIPTION_EXPANDED_NODES_H + +// -*- C++ -*- +// +// Package: DetectorDescription/ExpandedNodes +// Class: ExpandedNodes +// +/**\class ExpandedNodes + + Description: ExpandedNodes extra attributes: tags, offsets + and copy numbers + + Implementation: + ExpandedNodes structure to keep the nodes history +*/ +// +// Original Author: Ianna Osborne +// Created: Tue, 18 Mar 2019 12:22:35 CET +// +// +#include + +namespace cms { + + struct ExpandedNodes { + std::vector tags; + std::vector offsets; + std::vector copyNos; + }; +} + +#endif diff --git a/DetectorDescription/DDCMS/interface/Filter.h b/DetectorDescription/DDCMS/interface/Filter.h new file mode 100644 index 0000000000000..02a0a5f86df35 --- /dev/null +++ b/DetectorDescription/DDCMS/interface/Filter.h @@ -0,0 +1,45 @@ +#ifndef DETECTOR_DESCRIPTION_FILTER_H +#define DETECTOR_DESCRIPTION_FILTER_H + +// -*- C++ -*- +// +// Package: DetectorDescription/Filter +// Class: Filter +// +/**\class Filter + + Description: Filter list + + Implementation: + Filter criteria is defined in XML +*/ +// +// Original Author: Ianna Osborne +// Created: Tue, 12 Mar 2019 09:51:33 CET +// +// +#include +#include + +namespace cms { + + struct Filter { + std::vector keys; + struct std::unique_ptr next; + struct Filter* up; + }; + + namespace dd { + bool accepted(std::vector const&, std::string_view); + int contains(std::string_view, std::string_view); + bool isRegex(std::string_view); + bool compareEqual(std::string_view, std::string_view); + std::string_view realTopName(std::string_view input); + std::string_view noCopyNo(std::string_view input); + int copyNo(std::string_view input); + std::string_view noNamespace(std::string_view input); + std::vector split(std::string_view, const char*); + } +} + +#endif diff --git a/DetectorDescription/DDCMS/interface/MuonNumbering.h b/DetectorDescription/DDCMS/interface/MuonNumbering.h index 923c0f4773cc7..c86f6bfd898ed 100644 --- a/DetectorDescription/DDCMS/interface/MuonNumbering.h +++ b/DetectorDescription/DDCMS/interface/MuonNumbering.h @@ -1,7 +1,7 @@ #ifndef DETECTOR_DESCRIPTION_MUON_NUMBERING_H #define DETECTOR_DESCRIPTION_MUON_NUMBERING_H -#include "DetectorDescription/DDCMS/interface/DDFilteredView.h" +#include "DetectorDescription/DDCMS/interface/ExpandedNodes.h" #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h" #include #include @@ -13,7 +13,7 @@ namespace cms { using MuonConstants = std::unordered_map; struct MuonNumbering { - const MuonBaseNumber geoHistoryToBaseNumber(const DDFilteredView::ExpandedNodes&) const; + const MuonBaseNumber geoHistoryToBaseNumber(const cms::ExpandedNodes&) const; const int get(const char*) const; MuonConstants values; diff --git a/DetectorDescription/DDCMS/python/cmsMFGeometryXML_cfi.py b/DetectorDescription/DDCMS/python/cmsMFGeometryXML_cfi.py index 2ec10f69415bc..9016cda62f751 100644 --- a/DetectorDescription/DDCMS/python/cmsMFGeometryXML_cfi.py +++ b/DetectorDescription/DDCMS/python/cmsMFGeometryXML_cfi.py @@ -3,8 +3,9 @@ XMLIdealGeometryESSource = cms.ESSource("XMLIdealGeometryESSource", geomXMLFiles = cms.vstring('Geometry/CMSCommonData/data/normal/cmsextent.xml', 'Geometry/CMSCommonData/data/cms.xml', - 'Geometry/CMSCommonData/data/cmsMagneticField.xml', + 'Geometry/CMSCommonData/data/cmsMagneticField.xml', 'MagneticField/GeomBuilder/data/MagneticFieldVolumes_160812_1.xml', + 'MagneticField/GeomBuilder/data/MagneticFieldVolumes_160812_2.xml', 'Geometry/CMSCommonData/data/materials.xml'), rootNodeName = cms.string('cms:MCMS') ) diff --git a/DetectorDescription/DDCMS/src/DDFilteredView.cc b/DetectorDescription/DDCMS/src/DDFilteredView.cc index 44eaf6bd28d70..ad31b44f8872e 100644 --- a/DetectorDescription/DDCMS/src/DDFilteredView.cc +++ b/DetectorDescription/DDCMS/src/DDFilteredView.cc @@ -3,97 +3,146 @@ #include "DD4hep/Detector.h" #include #include -#include -#include -#include #include using namespace cms; using namespace std; +using namespace cms::dd; -DDFilteredView::DDFilteredView(const DDDetector* det) +DDFilteredView::DDFilteredView(const DDDetector* det, const Volume volume) : registry_(&det->specpars()) { - dd4hep::DetElement world = det->description()->world(); - parents_.emplace_back(DDExpandedNode(world.volume(), DDTranslation(), DDRotationMatrix(), 1, 0)); - topVolume_ = world.volume(); - TGeoIterator next(topVolume_); - next.SetType(0); // 0: DFS; 1: BFS + it_.emplace_back(Iterator(volume)); } -const DDVolume& +const PlacedVolume DDFilteredView::volume() const { - return parents_.back().volume; + return PlacedVolume(node_); } -const DDTranslation& -DDFilteredView::translation() const { - return parents_.back().trans; +const Double_t* +DDFilteredView::trans() const { + return it_.back().GetCurrentMatrix()->GetTranslation(); } -const DDRotationMatrix& -DDFilteredView::rotation() const { - return parents_.back().rot; +const Double_t* +DDFilteredView::rot() const { + return it_.back().GetCurrentMatrix()->GetRotationMatrix(); } void -DDFilteredView::mergedSpecifics(DDSpecParRefs const& refs) { - for(const auto& i : refs) { - auto tops = vPathsTo(*i, 1); - // auto tops = vPathsTo(*i.second, 1); - topNodes_.insert(end(topNodes_), begin(tops), end(tops)); +DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { + 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(begin(f->keys), end(f->keys), toks.front()); + if(k != end(f->keys)) { + currentFilter_ = f.get(); + return true; + } + return false; + }); + if(filter == end(filters_)) { + filters_.emplace_back(unique_ptr(new Filter{{toks.front()}, 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]); + if(l == end(currentFilter_->keys)) { + currentFilter_->keys.emplace_back(toks[pos]); + } + } else { + currentFilter_->next.reset(new Filter{{toks[pos]}, nullptr, currentFilter_}); + } + } + } } } bool DDFilteredView::firstChild() { + it_.back().SetType(0); + Node *node = nullptr; + while((node = it_.back().Next())) { + if(accept(noNamespace(node->GetVolume()->GetName()))) { + TString path; + it_.back().GetPath(path); + addPath(path, node); + + return true; + } + } return false; } bool -DDFilteredView::nextSibling() { +DDFilteredView::firstSibling() { + next(0); + it_.emplace_back(Iterator(it_.back())); + it_.back().SetType(1); + if(currentFilter_->next) + currentFilter_ = currentFilter_->next.get(); + else + return false; + do { + if(accepted(currentFilter_->keys, noNamespace(node_->GetVolume()->GetName()))) { + addNode(node_); + return true; + } + } while((node_ = it_.back().Next())); + return false; } bool -DDFilteredView::next() { - return false; -} +DDFilteredView::nextSibling() { + it_.back().SetType(1); + unCheckNode(); + do { + if(accepted(currentFilter_->keys, noNamespace(node_->GetVolume()->GetName()))) { + addNode(node_); + return true; + } + } while((node_ = it_.back().Next())); -const DDGeoHistory& -DDFilteredView::geoHistory() const { - return parents_; + return false; } bool -DDFilteredView::acceptRegex(string_view name, string_view node) const { - if(!isRegex(name) && !isRegex(node)) { - return (name == node); - } else { - if(isRegex(name)) { - regex pattern({name.data(), name.size()}); - return regex_search(begin(node), end(node), pattern); - } else if(isRegex(node)) { - regex pattern({node.data(), node.size()}); - return regex_search(begin(name), end(name), pattern); +DDFilteredView::sibling() { + it_.back().SetType(1); + Node *node = nullptr; + while((node = it_.back().Next())) { + if(accepted(currentFilter_->keys, noNamespace(node->GetVolume()->GetName()))) { + addNode(node); + return true; } } return false; } bool -DDFilteredView::accepted(string_view name, string_view node) const { - if(!isRegex(name)) { - return (name == node); - } else { - regex pattern({name.data(), name.size()}); - return regex_search(begin(node), end(node), pattern); +DDFilteredView::siblingNoCheck() { + it_.back().SetType(1); + Node *node = nullptr; + while((node = it_.back().Next())) { + if(accepted(currentFilter_->keys, noNamespace(node->GetVolume()->GetName()))) { + node_ = node; + return true; + } } + return false; } bool -DDFilteredView::accepted(vector const& names, string_view node) const { - for(auto const& i : names) { - if(accepted(i, node)) { +DDFilteredView::checkChild() { + it_.back().SetType(1); + Node *node = nullptr; + while((node = it_.back().Next())) { + if(accepted(currentFilter_->keys, noNamespace(node->GetVolume()->GetName()))) { return true; } } @@ -101,46 +150,51 @@ DDFilteredView::accepted(vector const& names, string_view node) con } bool -DDFilteredView::acceptedM(vector& names, string_view node) const { - auto itr = find_if(names.begin(), names.end(), [ & ]( const auto& i){ return accepted(i, node); }); - if(itr != names.end() && (!isRegex(*itr))) { - names.erase(itr); - return true; - } - return false; +DDFilteredView::parent() { + up(); + it_.back().SetType(0); + it_.back().Skip(); + + return true; } -string_view -DDFilteredView::realTopName(string_view input) const { - string_view v = input; - auto first = v.find_first_of("//"); - v.remove_prefix(min(first+2, v.size())); - return v; +bool +DDFilteredView::next(int type) { + it_.back().SetType(type); + Node *node = nullptr; + if((node = it_.back().Next())) { + node_ = node; + return true; + } + else + return false; } -string_view -DDFilteredView::noNamespace(string_view input) const { - string_view v = input; - auto first = v.find_first_of(":"); - v.remove_prefix(min(first+1, v.size())); - return v; +void +DDFilteredView::down() { + it_.emplace_back(Iterator(it_.back())); + next(0); + if(currentFilter_->next) + currentFilter_ = currentFilter_->next.get(); } -string_view -DDFilteredView::noCopyNo(string_view input) const { - string_view v = input; - auto last = v.find_last_of("_"); - v.remove_suffix(v.size() - min(last, v.size())); - return v; +void +DDFilteredView::up() { + it_.pop_back(); + if(currentFilter_->up) + currentFilter_ = currentFilter_->up; } -int -DDFilteredView::copyNo(string_view input) const { - string_view v = input; - auto last = v.find_last_of("_"); - v.remove_prefix(min(last+1, v.size())); - - return stoi({v.data(), v.size()}); +bool +DDFilteredView::accept(std::string_view name) { + bool result = false; + for(const auto& it : filters_) { + currentFilter_ = it.get(); + result = accepted(currentFilter_->keys, name); + if(result) + return result; + } + return result; } vector @@ -163,28 +217,12 @@ DDFilteredView::extractParameters() const { } bool -DDFilteredView::isRegex(string_view input) const { - return ((contains(input, "*") != -1) || - (contains(input, ".") != -1)); -} - -int -DDFilteredView::contains(string_view input, string_view needle) const { - auto const& it = search(begin(input), end(input), - boyer_moore_searcher(begin(needle), end(needle))); - if(it != end(input)) { - return (it - begin(input)); - } - return -1; -} - -bool -DDFilteredView::checkPath(string_view path, TGeoNode *node) { +DDFilteredView::addPath(string_view path, Node* const node) { assert(registry_); node_ = node; - nodes.tags.clear(); - nodes.offsets.clear(); - nodes.copyNos.clear(); + nodes_.tags.clear(); + nodes_.offsets.clear(); + nodes_.copyNos.clear(); bool result(false); auto v = split(path, "/"); @@ -194,14 +232,14 @@ DDFilteredView::checkPath(string_view path, TGeoNode *node) { for(auto const& rv : v) { 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 (acceptRegex(noCopyNo(rv), *begin(split(realTopName(j), "/"))) && + return (compareEqual(noCopyNo(rv), *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(copyNo(rv)); + nodes_.tags.emplace_back(i.second.dblValue("CopyNoTag")); + nodes_.offsets.emplace_back(i.second.dblValue("CopyNoOffset")); + nodes_.copyNos.emplace_back(copyNo(rv)); result = true; } }); @@ -210,20 +248,20 @@ DDFilteredView::checkPath(string_view path, TGeoNode *node) { } bool -DDFilteredView::checkNode(TGeoNode *node) { +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 (acceptRegex(noCopyNo(noNamespace(node_->GetName())), *begin(split(realTopName(j), "/"))) && + return (compareEqual(noCopyNo(noNamespace(node_->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(copyNo(node_->GetName())); + nodes_.tags.emplace_back(i.second.dblValue("CopyNoTag")); + nodes_.offsets.emplace_back(i.second.dblValue("CopyNoOffset")); + nodes_.copyNos.emplace_back(copyNo(node_->GetName())); result = true; } }); @@ -232,48 +270,7 @@ DDFilteredView::checkNode(TGeoNode *node) { void DDFilteredView::unCheckNode() { - nodes.tags.pop_back(); - nodes.offsets.pop_back(); - nodes.copyNos.pop_back(); -} - -vector -DDFilteredView::split(string_view str, const char* delims) const { - vector ret; - - string_view::size_type start = 0; - auto pos = str.find_first_of(delims, start); - while(pos != string_view::npos) { - if(pos != start) { - ret.emplace_back(str.substr(start, pos - start)); - } - start = pos + 1; - pos = str.find_first_of(delims, start); - } - if(start < str.length()) - ret.emplace_back(str.substr(start, str.length() - start)); - return ret; -} - -vector -DDFilteredView::vPathsTo(const DDSpecPar& specpar, unsigned int level) const { - vector result; - for(auto const& i : specpar.paths) { - vector toks = split(i, "/"); - if(level == toks.size()) - result.emplace_back(realTopName(i)); - } - return result; -} - -vector -DDFilteredView::tails(const vector& fullPath) const { - vector result; - for(auto const& v : fullPath) { - auto found = v.find_last_of("/"); - if(found != v.npos) { - result.emplace_back(v.substr(found + 1)); - } - } - return result; + nodes_.tags.pop_back(); + nodes_.offsets.pop_back(); + nodes_.copyNos.pop_back(); } diff --git a/DetectorDescription/DDCMS/src/Filter.cc b/DetectorDescription/DDCMS/src/Filter.cc new file mode 100644 index 0000000000000..f237c066a5d43 --- /dev/null +++ b/DetectorDescription/DDCMS/src/Filter.cc @@ -0,0 +1,87 @@ +#include "DetectorDescription/DDCMS/interface/Filter.h" +#include +#include +#include + +using namespace std; + +namespace cms { + namespace dd { + + bool compareEqual(string_view node, string_view name) { + if(!isRegex(name)) { + return (name == node); + } else { + regex pattern({name.data(), name.size()}); + return regex_match(begin(node), end(node), pattern); + } + } + + 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)); + } + + 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)) { + return (it - begin(input)); + } + return -1; + } + + bool isRegex(string_view input) { + return ((contains(input, "*") != -1) || + (contains(input, ".") != -1)); + } + + string_view realTopName(string_view input) { + string_view v = input; + auto first = v.find_first_of("//"); + v.remove_prefix(min(first+2, v.size())); + return v; + } + + string_view noCopyNo(string_view input) { + string_view v = input; + auto last = v.find_last_of("_"); + v.remove_suffix(v.size() - min(last, v.size())); + return v; + } + + int copyNo(string_view input) { + string_view v = input; + auto last = v.find_last_of("_"); + v.remove_prefix(min(last+1, v.size())); + + return stoi({v.data(), v.size()}); + } + + string_view noNamespace(string_view input) { + string_view v = input; + auto first = v.find_first_of(":"); + v.remove_prefix(min(first+1, v.size())); + return v; + } + + vector + split(string_view str, const char* delims) { + vector ret; + + string_view::size_type start = 0; + auto pos = str.find_first_of(delims, start); + while(pos != string_view::npos) { + if(pos != start) { + ret.emplace_back(str.substr(start, pos - start)); + } + start = pos + 1; + pos = str.find_first_of(delims, start); + } + if(start < str.length()) + ret.emplace_back(str.substr(start, str.length() - start)); + return ret; + } + } +} diff --git a/DetectorDescription/DDCMS/src/MuonNumbering.cc b/DetectorDescription/DDCMS/src/MuonNumbering.cc index 1bda339c3eea5..bdbbc39d9a4a0 100644 --- a/DetectorDescription/DDCMS/src/MuonNumbering.cc +++ b/DetectorDescription/DDCMS/src/MuonNumbering.cc @@ -9,7 +9,7 @@ using namespace std; using namespace edm; const MuonBaseNumber -MuonNumbering::geoHistoryToBaseNumber(const DDFilteredView::ExpandedNodes &nodes) const { +MuonNumbering::geoHistoryToBaseNumber(const cms::ExpandedNodes &nodes) const { MuonBaseNumber num; int levelPart = get("level"); diff --git a/DetectorDescription/DDCMS/test/BuildFile.xml b/DetectorDescription/DDCMS/test/BuildFile.xml index 39115623289e2..01ad605820adf 100644 --- a/DetectorDescription/DDCMS/test/BuildFile.xml +++ b/DetectorDescription/DDCMS/test/BuildFile.xml @@ -1,4 +1,13 @@ + + + + + + + + + diff --git a/DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc b/DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc new file mode 100644 index 0000000000000..4781ca1c69506 --- /dev/null +++ b/DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc @@ -0,0 +1,26 @@ +#include + +#include "DetectorDescription/DDCMS/interface/DDFilteredView.h" + +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" + +class testDDFilteredView : public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(testDDFilteredView); + CPPUNIT_TEST(checkFilteredView); + CPPUNIT_TEST_SUITE_END(); + +public: + + void setUp() override {} + void tearDown() override {} + void checkFilteredView(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(testDDFilteredView); + +void testDDFilteredView::checkFilteredView() +{ + cms::DDFilteredView fview(); +} diff --git a/DetectorDescription/DDCMS/test/Filter.cppunit.cc b/DetectorDescription/DDCMS/test/Filter.cppunit.cc new file mode 100644 index 0000000000000..01a803b4c8ef9 --- /dev/null +++ b/DetectorDescription/DDCMS/test/Filter.cppunit.cc @@ -0,0 +1,103 @@ +#include + +#include "DetectorDescription/DDCMS/interface/Filter.h" +#include +#include +#include + +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" + +using namespace cms; +using namespace cms::dd; +using namespace std; +using namespace std::literals; + +class testFilter : public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(testFilter); + CPPUNIT_TEST(checkFilter); + CPPUNIT_TEST_SUITE_END(); + +public: + + void setUp() override; + void tearDown() override {} + void checkFilter(); + +private: + void print(Filter*); + vector> filters_; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(testFilter); + +void +testFilter::setUp() +{ + vector selections = {"//MB2P.*", + "//MB2P.*/MB2SuperLayerPhi", + "//MB2P.*/MB2SuperLayerPhi/MB2SLPhiLayer_.*Cells.*", + "//MB2P.*/MB2SuperLayerPhi/MB2SLPhiLayer_.*Cells.*/MBSLPhiGas", + "//MB2P.*/MB2SuperLayerZ", + "//MB2P.*/MB2SuperLayerZ/MB2SLZLayer_.*Cells", + "//MB2P.*/MB2SuperLayerZ/MB2SLZLayer_.*Cells/MB2SLZGas"}; + Filter* currentFilter = nullptr; + + for(const auto& i : selections) { + 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()); + if(k != end(f->keys)) { + currentFilter = f.get(); + return true; + } + return false; + }); + if(filter == end(filters_)) { + filters_.emplace_back(unique_ptr(new Filter{{toks.front()}, 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]); + if(l == end(currentFilter->keys)) { + currentFilter->keys.emplace_back(toks[pos]); + } + } else { + currentFilter->next.reset(new Filter{{toks[pos]}, nullptr, currentFilter}); + } + } + } +} + +void +testFilter::checkFilter() +{ + string_view name = "MB2P.*"sv; + CPPUNIT_ASSERT(filters_.front()->keys.front() == name); + CPPUNIT_ASSERT(filters_.front()->up == nullptr); + CPPUNIT_ASSERT(filters_.front()->next != nullptr); + 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 << it << " "; + } + cout << "\n"; +} diff --git a/DetectorDescription/RecoGeometry/interface/DTGeometryBuilder.h b/DetectorDescription/RecoGeometry/interface/DTGeometryBuilder.h index e39e4ea9f79aa..0ca2a20a4ab54 100644 --- a/DetectorDescription/RecoGeometry/interface/DTGeometryBuilder.h +++ b/DetectorDescription/RecoGeometry/interface/DTGeometryBuilder.h @@ -4,8 +4,6 @@ #include "DataFormats/GeometrySurface/interface/ReferenceCounted.h" #include "DataFormats/GeometrySurface/interface/Plane.h" #include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h" -#include -#include namespace dd4hep { class Detector; @@ -29,9 +27,6 @@ namespace cms { ~DTGeometryBuilder() {} using Detector = dd4hep::Detector; - using DDRotationMatrix = ROOT::Math::Rotation3D; - using DDTranslation = ROOT::Math::DisplacementVector3D>; - using DD3Vector = ROOT::Math::DisplacementVector3D>; using DDSpecParRefs = std::vector; void build(DTGeometry&, @@ -40,33 +35,25 @@ namespace cms { const DDSpecParRefs&); private: void buildGeometry(DDFilteredView&, - const DDSpecPar&, DTGeometry&, const MuonNumbering&) const; /// create the chamber DTChamber* buildChamber(const DDFilteredView&, - const DDTranslation&, - const DDRotationMatrix&, const MuonNumbering&) const; /// create the SL DTSuperLayer* buildSuperLayer(const DDFilteredView&, DTChamber*, - const DDTranslation&, - const DDRotationMatrix&, const MuonNumbering&) const; /// create the layer - DTLayer* buildLayer(const DDFilteredView&, + DTLayer* buildLayer(DDFilteredView&, DTSuperLayer*, - const DDTranslation&, - const DDRotationMatrix&, const MuonNumbering&) const; using RCPPlane = ReferenceCountingPointer; - RCPPlane plane(const DDTranslation&, - const DDRotationMatrix&, + RCPPlane plane(const DDFilteredView&, Bounds* bounds) const; }; } diff --git a/DetectorDescription/RecoGeometry/plugins/DTGeometryTest.cc b/DetectorDescription/RecoGeometry/plugins/DTGeometryTest.cc index 8d369238512be..fb1d21590ed75 100644 --- a/DetectorDescription/RecoGeometry/plugins/DTGeometryTest.cc +++ b/DetectorDescription/RecoGeometry/plugins/DTGeometryTest.cc @@ -73,6 +73,26 @@ DTGeometryTest::analyze(const Event&, const EventSetup& iEventSetup) } }); LogVerbatim("Geometry") << "END " << string(120, '-'); + + // check layers + LogVerbatim("Geometry") << "LAYERS " << string(120, '-'); + + LogVerbatim("Geometry").log([&](auto& log) { + for(auto det : pDD->layers()){ + const DTTopology& topo = det->specificTopology(); + const BoundPlane& surf=det->surface(); + log << "Layer " << det->id() << " SL " << det->superLayer()->id() + << " chamber " << det->chamber()->id() + << " Topology W/H/L: " + << topo.cellWidth() << "/" << topo.cellHeight() << "/" << topo.cellLenght() + << " first/last/# wire " << topo.firstChannel() << "/" << topo.lastChannel() << "/" << topo.channels() + << " Position " << surf.position() + << " normVect " << surf.normalVector() + << " bounds W/H/L: " << surf.bounds().width() << "/" + << surf.bounds().thickness() << "/" << surf.bounds().length() << "\n"; + } + }); + LogVerbatim("Geometry") << "END " << string(120, '-'); } DEFINE_FWK_MODULE(DTGeometryTest); diff --git a/DetectorDescription/RecoGeometry/src/DTGeometryBuilder.cc b/DetectorDescription/RecoGeometry/src/DTGeometryBuilder.cc index 5de7cddf33f4b..c3417d3797001 100644 --- a/DetectorDescription/RecoGeometry/src/DTGeometryBuilder.cc +++ b/DetectorDescription/RecoGeometry/src/DTGeometryBuilder.cc @@ -55,149 +55,71 @@ using namespace edm; using namespace std; using namespace cms; -namespace { - - string_view noNamespace(string_view input) { - string_view v = input; - auto first = v.find_first_of(":"); - v.remove_prefix(min(first+1, v.size())); - return v; - } -} - void DTGeometryBuilder::buildGeometry(DDFilteredView& fview, - const DDSpecPar& specpar, DTGeometry& geom, const MuonNumbering& num) const { - TGeoVolume *topVolume = fview.geoHistory().back().volume; - TGeoIterator next(topVolume); - next.SetType(0); // 0: DFS; 1: BFS - TGeoNode *node; - - //find all Chamber nodes - auto const& chamberSelection = fview.vPathsTo(specpar, 1); - - //find all Super Layer nodes - auto const& superLayerSelection = fview.tails(fview.vPathsTo(specpar, 2)); - - //find all Layer nodes - auto const& layerSelection = fview.tails(fview.vPathsTo(specpar, 3)); - - // Not used: - // auto const& type = specpar.strValue("Type"); - // auto const& FEPos = specpar.strValue("FEPos"); + + bool doChamber = fview.firstChild(); - while((node = next())) { - // If the node matches the Chamber selection - if(fview.accepted(chamberSelection, noNamespace(node->GetVolume()->GetName()))) { - // The matrix is absolute - const TGeoMatrix *matrix = next.GetCurrentMatrix(); - const Double_t *rot = matrix->GetRotationMatrix(); - const Double_t *tr = matrix->GetTranslation(); - - // FIXME: Create an ExpanedNode here - int nd = node->GetNdaughters(); - TString path; - next.GetPath(path); - fview.checkPath(path, node); + while(doChamber) { + DTChamber* chamber = buildChamber(fview, num); + + // Loop on SLs + bool doSL = fview.firstSibling(); + while(doSL) { + DTSuperLayer* sl = buildSuperLayer(fview, chamber, num); - DDTranslation chTr = DDTranslation(tr[0], tr[1], tr[2]); - DDRotationMatrix chRot = DDRotationMatrix(rot[0], rot[1], rot[2], - rot[3], rot[4], rot[5], - rot[6], rot[7], rot[8]); - DTChamber* chamber = buildChamber(fview, - chTr, chRot, - num); - // Loop on SLs - TGeoNode *currentSLayer = nullptr; - - for(int i = 0; i < nd; ++i) { - currentSLayer = static_cast(node->GetNodes()->At(i)); - - if(fview.accepted(superLayerSelection, noNamespace(currentSLayer->GetVolume()->GetName()))) { - // The matrix is relative - const TGeoMatrix *slMatrix = currentSLayer->GetMatrix(); - const Double_t *slrot = slMatrix->GetRotationMatrix(); - const Double_t *sltr = slMatrix->GetTranslation(); - // This matrix is absolute - DDTranslation slTr = chTr + (chRot * DDTranslation(sltr[0], sltr[1], sltr[2])); - DDRotationMatrix slRot = chRot * DDRotationMatrix(slrot[0], slrot[1], slrot[2], - slrot[3], slrot[4], slrot[5], - slrot[6], slrot[7], slrot[8]); - - fview.checkNode(currentSLayer); - - DTSuperLayer* sl = buildSuperLayer(fview, chamber, - slTr, slRot, - num); - // Loop on Layers - TGeoNode *currentLayer = nullptr; - int ndLs = currentSLayer->GetNdaughters(); - for(int j = 0; j < ndLs; ++j) { - currentLayer = static_cast(currentSLayer->GetNodes()->At(j)); - if(fview.accepted(layerSelection, noNamespace(currentLayer->GetVolume()->GetName()))) { - // The matrix is relative - const TGeoMatrix *lMatrix = currentLayer->GetMatrix(); - const Double_t *lrot = lMatrix->GetRotationMatrix(); - const Double_t *ltr = lMatrix->GetTranslation(); + // Loop on Layers + fview.down(); + bool doLayers = fview.sibling(); + while(doLayers) { + DTLayer* l = buildLayer(fview, sl, num); + fview.unCheckNode(); + geom.add(l); - // This matrix is absolute - DDTranslation lTr = slTr + (slRot * DDTranslation(ltr[0], ltr[1], ltr[2])); - DDRotationMatrix lRot = slRot * DDRotationMatrix(lrot[0], lrot[1], lrot[2], - lrot[3], lrot[4], lrot[5], - lrot[6], lrot[7], lrot[8]); - - fview.checkNode(currentLayer); - - DTLayer* l = buildLayer(fview, sl, - lTr, lRot, - num); - fview.unCheckNode(); - geom.add(l); - } - } - fview.unCheckNode(); - geom.add(sl); - } + doLayers = fview.sibling(); // go to next Layer } - geom.add(chamber); + // Done with layers, go up + fview.up(); + + geom.add(sl); + doSL = fview.nextSibling(); // go to next SL } + geom.add(chamber); + + fview.parent(); // stop iterating current branch + doChamber = fview.firstChild(); // go to next chamber } } DTGeometryBuilder::RCPPlane -DTGeometryBuilder::plane(const DDTranslation& trans, - const DDRotationMatrix& rotation, +DTGeometryBuilder::plane(const DDFilteredView& fview, Bounds* bounds) const { - const Surface::PositionType posResult(trans.x(), - trans.y(), - trans.z()); - DD3Vector x, y, z; - rotation.GetComponents(x,y,z); - - Surface::RotationType rotResult(x.X(), x.Y(), x.Z(), - y.X(), y.Y(), y.Z(), - z.X(), z.Y(), z.Z()); + const Double_t *tr = fview.trans(); + const Double_t *rot = fview.rot(); - return RCPPlane(new Plane(posResult, rotResult, bounds)); + return RCPPlane(new Plane(Surface::PositionType(tr[0], tr[1], tr[2]), + Surface::RotationType(rot[0], rot[3], rot[6], + rot[1], rot[4], rot[7], + rot[2], rot[5], rot[8]), + bounds)); } DTChamber* DTGeometryBuilder::buildChamber(const DDFilteredView& fview, - const DDTranslation& trans, - const DDRotationMatrix& rotation, const MuonNumbering& muonConstants) const { MuonConstants cons = muonConstants.values; DTNumberingScheme dtnum(cons); - int rawid = dtnum.getDetId(muonConstants.geoHistoryToBaseNumber(fview.nodes)); + int rawid = dtnum.getDetId(muonConstants.geoHistoryToBaseNumber(fview.history())); DTChamberId detId(rawid); auto const& par = fview.extractParameters(); // par[0] r-phi dimension - different in different chambers // par[1] z dimension - constant 125.55 cm // par[2] radial thickness - almost constant about 18 cm - RCPPlane surf(plane(trans, rotation, new RectangularPlaneBounds(par[0], par[1], par[2]))); + + RCPPlane surf(plane(fview, new RectangularPlaneBounds(par[0], par[1], par[2]))); DTChamber* chamber = new DTChamber(detId, surf); @@ -207,13 +129,11 @@ DTGeometryBuilder::buildChamber(const DDFilteredView& fview, DTSuperLayer* DTGeometryBuilder::buildSuperLayer(const DDFilteredView& fview, DTChamber* chamber, - const DDTranslation& trans, - const DDRotationMatrix& rotation, const MuonNumbering& muonConstants) const { MuonConstants cons = muonConstants.values; DTNumberingScheme dtnum(cons); - int rawid = dtnum.getDetId(muonConstants.geoHistoryToBaseNumber(fview.nodes)); + int rawid = dtnum.getDetId(muonConstants.geoHistoryToBaseNumber(fview.history())); DTSuperLayerId slId(rawid); auto const& par = fview.extractParameters(); @@ -222,7 +142,7 @@ DTGeometryBuilder::buildSuperLayer(const DDFilteredView& fview, // par[2] radial thickness - almost constant about 20 cm // Ok this is the slayer position... - RCPPlane surf(plane(trans, rotation, new RectangularPlaneBounds(par[0], par[1], par[2]))); + RCPPlane surf(plane(fview, new RectangularPlaneBounds(par[0], par[1], par[2]))); DTSuperLayer* slayer = new DTSuperLayer(slId, surf, chamber); @@ -233,15 +153,13 @@ DTGeometryBuilder::buildSuperLayer(const DDFilteredView& fview, } DTLayer* -DTGeometryBuilder::buildLayer(const DDFilteredView& fview, +DTGeometryBuilder::buildLayer(DDFilteredView& fview, DTSuperLayer* sl, - const DDTranslation& trans, - const DDRotationMatrix& rotation, const MuonNumbering& muonConstants) const { MuonConstants cons = muonConstants.values; DTNumberingScheme dtnum(cons); - int rawid = dtnum.getDetId(muonConstants.geoHistoryToBaseNumber(fview.nodes)); + int rawid = dtnum.getDetId(muonConstants.geoHistoryToBaseNumber(fview.history())); DTLayerId layId(rawid); auto const& par = fview.extractParameters(); @@ -249,25 +167,28 @@ DTGeometryBuilder::buildLayer(const DDFilteredView& fview, // par[0] r-phi dimension - changes in different chambers // par[1] z dimension - constant 126.8 cm // par[2] radial thickness - almost constant about 20 cm - RCPPlane surf(plane(trans, rotation, new RectangularPlaneBounds(par[0], par[1], par[2]))); + RCPPlane surf(plane(fview, new RectangularPlaneBounds(par[0], par[1], par[2]))); + + // Loop on wires + fview.down(); + bool doWire = fview.siblingNoCheck(); + int firstWire = fview.volume()->GetNumber(); // copy no + auto const& wpar = fview.extractParameters(); + float wireLength = wpar[1]; - // FIXME: // Loop on wires - // bool doWire = fv.firstChild(); int WCounter = 0; - int firstWire = 1; //FIXME: copyno; - // par = extractParameters(fv); - float wireLength = par[1]; - // while (doWire) { - // WCounter++; - // doWire = fv.nextSibling(); // next wire - // } - // //int lastWire=fv.copyno(); + while(doWire) { + doWire = fview.checkChild(); + WCounter++; + } + fview.up(); + DTTopology topology(firstWire, WCounter, wireLength); DTLayerType layerType; DTLayer* layer = new DTLayer(layId, surf, topology, layerType, sl); - + sl->add(layer); return layer; } @@ -277,9 +198,9 @@ DTGeometryBuilder::build(DTGeometry& geom, const cms::DDDetector* det, const MuonNumbering& num, const DDSpecParRefs& refs) { - DDFilteredView fview(det); - for(const auto& i: refs) { - buildGeometry(fview, *i, geom, num); - } + dd4hep::DetElement world = det->description()->world(); + DDFilteredView fview(det, world.volume()); + fview.mergedSpecifics(refs); + buildGeometry(fview, geom, num); } diff --git a/Geometry/DTGeometryBuilder/data/dtSpecsFilter/2019/v1/dtSpecsFilter.xml b/Geometry/DTGeometryBuilder/data/dtSpecsFilter/2019/v1/dtSpecsFilter.xml new file mode 100644 index 0000000000000..fdc2be9704343 --- /dev/null +++ b/Geometry/DTGeometryBuilder/data/dtSpecsFilter/2019/v1/dtSpecsFilter.xml @@ -0,0 +1,318 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 642e62113231f796a45ef0fc88986ae46f119333 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 20 Mar 2019 12:07:50 +0100 Subject: [PATCH 2/2] Add unit tests --- DetectorDescription/DDCMS/interface/Filter.h | 2 +- DetectorDescription/DDCMS/test/BuildFile.xml | 1 + .../DDCMS/test/DDFilteredView.cppunit.cc | 24 ++++++++-- .../DDCMS/test/ExpandedNodes.cppunit.cc | 46 +++++++++++++++++++ .../interface/DTGeometryBuilder.h | 2 +- 5 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 DetectorDescription/DDCMS/test/ExpandedNodes.cppunit.cc diff --git a/DetectorDescription/DDCMS/interface/Filter.h b/DetectorDescription/DDCMS/interface/Filter.h index 02a0a5f86df35..f07c720d4d269 100644 --- a/DetectorDescription/DDCMS/interface/Filter.h +++ b/DetectorDescription/DDCMS/interface/Filter.h @@ -25,7 +25,7 @@ namespace cms { struct Filter { std::vector keys; - struct std::unique_ptr next; + std::unique_ptr next; struct Filter* up; }; diff --git a/DetectorDescription/DDCMS/test/BuildFile.xml b/DetectorDescription/DDCMS/test/BuildFile.xml index 01ad605820adf..d56021563ca5f 100644 --- a/DetectorDescription/DDCMS/test/BuildFile.xml +++ b/DetectorDescription/DDCMS/test/BuildFile.xml @@ -1,6 +1,7 @@ + diff --git a/DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc b/DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc index 4781ca1c69506..b4ea649e29b26 100644 --- a/DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc +++ b/DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc @@ -1,26 +1,44 @@ #include #include "DetectorDescription/DDCMS/interface/DDFilteredView.h" +#include "DetectorDescription/DDCMS/interface/DDDetector.h" +#include "FWCore/ParameterSet/interface/FileInPath.h" +#include "DD4hep/Detector.h" + +#include +#include #include "cppunit/TestAssert.h" #include "cppunit/TestFixture.h" +using namespace cms; +using namespace std; + class testDDFilteredView : public CppUnit::TestFixture { - + CPPUNIT_TEST_SUITE(testDDFilteredView); CPPUNIT_TEST(checkFilteredView); CPPUNIT_TEST_SUITE_END(); public: - void setUp() override {} + void setUp() override; void tearDown() override {} void checkFilteredView(); + +private: + + string fileName_; }; CPPUNIT_TEST_SUITE_REGISTRATION(testDDFilteredView); +void testDDFilteredView::setUp() { + fileName_ = edm::FileInPath("DetectorDescription/DDCMS/data/cms-2015-muon-geometry.xml").fullPath(); +} + void testDDFilteredView::checkFilteredView() { - cms::DDFilteredView fview(); +unique_ptr det = make_unique("DUMMY", fileName_); + DDFilteredView fview(det.get(), det->description()->worldVolume()); } diff --git a/DetectorDescription/DDCMS/test/ExpandedNodes.cppunit.cc b/DetectorDescription/DDCMS/test/ExpandedNodes.cppunit.cc new file mode 100644 index 0000000000000..0948e9deea2dc --- /dev/null +++ b/DetectorDescription/DDCMS/test/ExpandedNodes.cppunit.cc @@ -0,0 +1,46 @@ +#include + +#include "DetectorDescription/DDCMS/interface/ExpandedNodes.h" + +#include + +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" + +using namespace cms; +using namespace std; + +class testExpandedNodes : public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(testExpandedNodes); + CPPUNIT_TEST(checkExpandedNodes); + CPPUNIT_TEST_SUITE_END(); + +public: + + void setUp() override; + void tearDown() override {} + void checkExpandedNodes(); + +private: + ExpandedNodes nodes_; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(testExpandedNodes); + +void +testExpandedNodes::setUp() { + nodes_.tags = { 1., 2., 3. }; + nodes_.offsets = { 1., 2., 3. }; + nodes_.copyNos = { 1, 2, 3 }; +} + +void +testExpandedNodes::checkExpandedNodes() { + cout << "Expanded Nodes...\n"; + CPPUNIT_ASSERT(nodes_.tags.size() == nodes_.offsets.size()); + CPPUNIT_ASSERT(nodes_.tags.size() == nodes_.copyNos.size()); + + for(auto const& i : nodes_.tags) + cout << i << " "; +} diff --git a/DetectorDescription/RecoGeometry/interface/DTGeometryBuilder.h b/DetectorDescription/RecoGeometry/interface/DTGeometryBuilder.h index 0ca2a20a4ab54..b82d354a97541 100644 --- a/DetectorDescription/RecoGeometry/interface/DTGeometryBuilder.h +++ b/DetectorDescription/RecoGeometry/interface/DTGeometryBuilder.h @@ -17,7 +17,7 @@ class DTLayer; namespace cms { class DDDetector; - struct DDFilteredView; + class DDFilteredView; struct MuonNumbering; struct DDSpecPar;