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

Speed up the use of DDFilteredViews #17778

Merged
merged 14 commits into from Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from 12 commits
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
12 changes: 2 additions & 10 deletions Alignment/CocoaApplication/src/CocoaAnalyzer.cc
Expand Up @@ -132,18 +132,10 @@ void CocoaAnalyzer::ReadXMLFile( const edm::EventSetup& evts )
// It stores these objects in a private data member, opt
std::string attribute = "COCOA";
std::string value = "COCOA";
DDValue val(attribute, value, 0.0);

// get all parts labelled with COCOA using a SpecPar
DDSpecificsFilter filter;
filter.setCriteria(val, // name & value of a variable
DDCompOp::matches,
DDLogOp::AND,
true, // compare strings otherwise doubles
true // use merged-specifics or simple-specifics
);
DDFilteredView fv(*cpv);
fv.addFilter(filter);
DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
DDFilteredView fv(*cpv, filter);
bool doCOCOA = fv.firstChild();

// Loop on parts
Expand Down
12 changes: 2 additions & 10 deletions CalibMuon/DTCalibration/plugins/DTGeometryParserFromDDD.cc
Expand Up @@ -14,18 +14,10 @@ DTGeometryParserFromDDD::DTGeometryParserFromDDD(const DDCompactView* cview, con
try {
std::string attribute = "MuStructure";
std::string value = "MuonBarrelDT";
DDValue val(attribute, value, 0.0);

// Asking only for the Muon DTs
DDSpecificsFilter filter;
filter.setCriteria(val, // name & value of a variable
DDCompOp::matches,
DDLogOp::AND,
true, // compare strings otherwise doubles
true // use merged-specifics or simple-specifics
);
DDFilteredView fview(*cview);
fview.addFilter(filter);
DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
DDFilteredView fview(*cview,filter);

parseGeometry(fview, muonConstants, theLayerIdWiresMap);
}
Expand Down
81 changes: 62 additions & 19 deletions DetectorDescription/Core/interface/DDFilter.h
Expand Up @@ -10,11 +10,8 @@ class DDExpandedView;
class DDQuery;

//! comparison operators to be used with this filter
enum class DDCompOp { equals, matches, not_equals, not_matches, smaller, bigger, smaller_equals, bigger_equals };
enum class DDCompOp { equals, not_equals};

//! logical operations to obtain one result from two filter comparisons
enum class DDLogOp { AND, OR };

//! A Filter accepts or rejects a DDExpandedNode based on a user-coded decision rule
class DDFilter
{
Expand All @@ -29,6 +26,15 @@ class DDFilter
virtual bool accept(const DDExpandedView &) const = 0;
};

//! A DDFilter that always returns true
class DDPassAllFilter : public DDFilter
{
public:
bool accept(const DDExpandedView &) const override final {
return true;
}
};

//! The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs
class DDSpecificsFilter : public DDFilter
{
Expand All @@ -39,41 +45,78 @@ class DDSpecificsFilter : public DDFilter

~DDSpecificsFilter();

bool accept(const DDExpandedView &) const;
bool accept(const DDExpandedView &) const override final;

void setCriteria(const DDValue & nameVal, // name & value of a variable
DDCompOp,
DDLogOp l = DDLogOp::AND,
bool asString = true, // compare strings otherwise doubles
bool merged = true // use merged-specifics or simple-specifics
);
DDCompOp );

struct SpecificCriterion {
SpecificCriterion(const DDValue & nameVal,
DDCompOp op,
bool asString,
bool merged)
DDCompOp op)
: nameVal_(nameVal),
comp_(op),
asString_(asString),
merged_(merged)
comp_(op)
{ }

DDValue nameVal_;
DDCompOp comp_;
bool asString_;
bool merged_;
};

protected:

bool accept_impl(const DDExpandedView &) const;

std::vector<SpecificCriterion> criteria_;
std::vector<DDLogOp> logOps_;
};

std::ostream & operator<<(std::ostream & os, const DDSpecificsFilter & f);

class DDSpecificsHasNamedValueFilter : public DDFilter {
public:
explicit DDSpecificsHasNamedValueFilter(const std::string& iAttribute):
attribute_(iAttribute,"",0 )
{}

bool accept(const DDExpandedView &) const override final;

private:
DDValue attribute_;

};

class DDSpecificsMatchesValueFilter : public DDFilter {
public:
explicit DDSpecificsMatchesValueFilter(const DDValue& iValue):
value_(iValue)
{}

bool accept(const DDExpandedView &) const override final;

private:
DDValue value_;

};

template<typename F1, typename F2>
class DDAndFilter : public DDFilter {
public:
DDAndFilter(F1 iF1, F2 iF2):
f1_(std::move(iF1)),
f2_(std::move(iF2)) {}

bool accept(const DDExpandedView & node) const override final {
return f1_.accept(node) && f2_.accept(node);
}
private:
F1 f1_;
F2 f2_;
};

template<typename F1, typename F2>
DDAndFilter<F1,F2> make_and_ddfilter(F1 f1, F2 f2)
{
return DDAndFilter<F1,F2>(std::move(f1), std::move(f2));
}

#endif


16 changes: 7 additions & 9 deletions DetectorDescription/Core/interface/DDFilteredView.h
Expand Up @@ -19,14 +19,13 @@ class DDFilteredView
{
public:
typedef DDExpandedView::nav_type nav_type;

//!Keeps a pointer to the DDfilter
DDFilteredView(const DDCompactView &, const DDFilter&);

DDFilteredView() = delete;

DDFilteredView(const DDCompactView &);

~DDFilteredView();

void addFilter(const DDFilter &, DDLogOp op = DDLogOp::AND);

//! The logical-part of the current node in the filtered-view
//! The logical-part of the current node in the filtered-view
const DDLogicalPart & logicalPart() const;

//! The absolute translation of the current node
Expand Down Expand Up @@ -88,8 +87,7 @@ class DDFilteredView
bool filter();

DDExpandedView epv_;
std::vector<DDFilter const *> criteria_;
std::vector<DDLogOp> logOps_; // logical operation for merging the result of 2 filters
DDFilter const* filter_;
std::vector<DDGeoHistory> parents_; // filtered-parents
};

Expand Down
3 changes: 1 addition & 2 deletions DetectorDescription/Core/interface/DDQuery.h
Expand Up @@ -24,7 +24,7 @@ class DDQuery

virtual const std::vector<DDExpandedNode> & exec();

virtual void addFilter(const DDFilter &, DDLogOp op = DDLogOp::AND);
virtual void addFilter(const DDFilter &);

virtual void setScope(const DDScope &);

Expand All @@ -33,7 +33,6 @@ class DDQuery
const DDScope * scope_;

std::vector<std::pair<bool, DDFilter *> > criteria_; // one filter and the result on the current node
std::vector<DDLogOp> logOps_; // logical operation for merging the result of 2 filters
std::vector<DDExpandedNode> result_; // query result
};

Expand Down