Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:54

0001 #ifndef DDCore_DDFilter_h
0002 #define DDCore_DDFilter_h
0003 
0004 #include <iosfwd>
0005 #include <vector>
0006 
0007 #include "DetectorDescription/Core/interface/DDValue.h"
0008 
0009 class DDExpandedView;
0010 
0011 //! comparison operators to be used with this filter
0012 enum class DDCompOp { equals, not_equals };
0013 
0014 //! A Filter accepts or rejects a DDExpandedNode based on a user-coded decision rule
0015 class DDFilter {
0016 public:
0017   DDFilter();
0018 
0019   virtual ~DDFilter();
0020 
0021   //! true, if the DDExpandedNode fulfills the filter criteria
0022   virtual bool accept(const DDExpandedView &) const = 0;
0023 };
0024 
0025 //! A DDFilter that always returns true
0026 class DDPassAllFilter : public DDFilter {
0027 public:
0028   bool accept(const DDExpandedView &) const final { return true; }
0029 };
0030 
0031 //! The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs
0032 class DDSpecificsFilter : public DDFilter {
0033   friend std::ostream &operator<<(std::ostream &os, const DDSpecificsFilter &f);
0034 
0035 public:
0036   DDSpecificsFilter();
0037 
0038   ~DDSpecificsFilter() override;
0039 
0040   bool accept(const DDExpandedView &) const final;
0041 
0042   void setCriteria(const DDValue &nameVal,  // name & value of a variable
0043                    DDCompOp);
0044 
0045   struct SpecificCriterion {
0046     SpecificCriterion(const DDValue &nameVal, DDCompOp op) : nameVal_(nameVal), comp_(op) {}
0047 
0048     DDValue nameVal_;
0049     DDCompOp comp_;
0050   };
0051 
0052 protected:
0053   bool accept_impl(const DDExpandedView &) const;
0054 
0055   std::vector<SpecificCriterion> criteria_;
0056 };
0057 
0058 std::ostream &operator<<(std::ostream &os, const DDSpecificsFilter &f);
0059 
0060 class DDSpecificsHasNamedValueFilter : public DDFilter {
0061 public:
0062   explicit DDSpecificsHasNamedValueFilter(const std::string &iAttribute) : attribute_(iAttribute, "", 0) {}
0063 
0064   bool accept(const DDExpandedView &) const final;
0065 
0066 private:
0067   DDValue attribute_;
0068 };
0069 
0070 class DDSpecificsMatchesValueFilter : public DDFilter {
0071 public:
0072   explicit DDSpecificsMatchesValueFilter(const DDValue &iValue) : value_(iValue) {}
0073 
0074   bool accept(const DDExpandedView &) const final;
0075 
0076 private:
0077   DDValue value_;
0078 };
0079 
0080 template <typename F1, typename F2>
0081 class DDAndFilter : public DDFilter {
0082 public:
0083   DDAndFilter(F1 iF1, F2 iF2) : f1_(std::move(iF1)), f2_(std::move(iF2)) {}
0084 
0085   bool accept(const DDExpandedView &node) const final { return f1_.accept(node) && f2_.accept(node); }
0086 
0087 private:
0088   F1 f1_;
0089   F2 f2_;
0090 };
0091 
0092 template <typename F1, typename F2>
0093 DDAndFilter<F1, F2> make_and_ddfilter(F1 f1, F2 f2) {
0094   return DDAndFilter<F1, F2>(std::move(f1), std::move(f2));
0095 }
0096 
0097 #endif