Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DD4hep] DDFilteredView level and goto methods with unit tests #31508

Merged
merged 3 commits into from Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions DetectorDescription/DDCMS/interface/DDFilteredView.h
Expand Up @@ -207,6 +207,13 @@ namespace cms {
// the current position in the DDFilteredView
nav_type navPos() const;

//! get Iterator level
const int level() const;

//! transversed the DDFilteredView according
// to the given stack of sibling numbers
bool goTo(const nav_type&);

//! print Filter paths and selections
void printFilter() const;

Expand Down
36 changes: 36 additions & 0 deletions DetectorDescription/DDCMS/src/DDFilteredView.cc
Expand Up @@ -560,6 +560,42 @@ DDFilteredView::nav_type DDFilteredView::navPos() const {
return pos;
}

const int DDFilteredView::level() const {
ianna marked this conversation as resolved.
Show resolved Hide resolved
int level(0);
if (not it_.empty()) {
level = it_.back().GetLevel();
}
return level;
}

bool DDFilteredView::goTo(const nav_type& newpos) {
bool result(false);

// save the current position
it_.emplace_back(Iterator(it_.back().GetTopVolume()));
Node* node = nullptr;

// try to navigate down to the newpos
int level = 1;
for (auto const& i : newpos) {
it_.back().SetType(0);
node = it_.back().Next();
for (int j = 1; j <= i; j++) {
it_.back().SetType(1);
node = it_.back().Next();
}
level++;
ianna marked this conversation as resolved.
Show resolved Hide resolved
}
if (node != nullptr) {
node_ = node;
result = true;
} else {
it_.pop_back();
}

return result;
}

const std::vector<const Node*> DDFilteredView::geoHistory() const {
std::vector<const Node*> result;
if (not it_.empty()) {
Expand Down
10 changes: 10 additions & 0 deletions DetectorDescription/DDCMS/test/BuildFile.xml
Expand Up @@ -4,6 +4,16 @@
<use name="dd4hep"/>
</bin>

<bin name="testDD4hepFilteredViewLevel" file="DDFilteredView.level.cppunit.cc,testRunner.cpp">
ianna marked this conversation as resolved.
Show resolved Hide resolved
<use name="DetectorDescription/DDCMS"/>
<use name="dd4hep"/>
</bin>

<bin name="testDD4hepFilteredViewGoTo" file="DDFilteredView.goto.cppunit.cc,testRunner.cpp">
<use name="DetectorDescription/DDCMS"/>
<use name="dd4hep"/>
</bin>

<bin name="testDD4hepCompactView" file="DDCompactView.cppunit.cc,testRunner.cpp">
<use name="DetectorDescription/DDCMS"/>
<use name="dd4hep"/>
Expand Down