Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:24

0001 #ifndef HLTrigger_HLTcore_TriggerExpressionOperators_h
0002 #define HLTrigger_HLTcore_TriggerExpressionOperators_h
0003 
0004 #include <memory>
0005 
0006 #include "HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h"
0007 
0008 namespace triggerExpression {
0009 
0010   // abstract unary operator
0011   class UnaryOperator : public Evaluator {
0012   public:
0013     UnaryOperator(Evaluator* arg) : m_arg(arg) {}
0014 
0015     // initialize the depending modules
0016     void init(const Data& data) override { m_arg->init(data); }
0017 
0018     // apply mask(s) to the Evaluator
0019     void mask(Evaluator const& arg) override { m_arg->mask(arg); }
0020 
0021     // return the patterns from the depending modules
0022     std::vector<std::string> patterns() const override { return m_arg->patterns(); }
0023 
0024   protected:
0025     std::unique_ptr<Evaluator> m_arg;
0026   };
0027 
0028   // abstract binary operator
0029   class BinaryOperator : public Evaluator {
0030   public:
0031     BinaryOperator(Evaluator* arg1, Evaluator* arg2) : m_arg1(arg1), m_arg2(arg2) {}
0032 
0033     // initialize the depending modules
0034     void init(const Data& data) override {
0035       m_arg1->init(data);
0036       m_arg2->init(data);
0037     }
0038 
0039     // apply mask(s) to the Evaluators
0040     void mask(Evaluator const& arg) override {
0041       m_arg1->mask(arg);
0042       m_arg2->mask(arg);
0043     }
0044 
0045     // return the patterns from the depending modules
0046     std::vector<std::string> patterns() const override {
0047       std::vector<std::string> patterns = m_arg1->patterns();
0048       auto patterns2 = m_arg2->patterns();
0049       patterns.insert(
0050           patterns.end(), std::make_move_iterator(patterns2.begin()), std::make_move_iterator(patterns2.end()));
0051       return patterns;
0052     }
0053 
0054   protected:
0055     std::unique_ptr<Evaluator> m_arg1;
0056     std::unique_ptr<Evaluator> m_arg2;
0057   };
0058 
0059   // concrete operators
0060 
0061   class OperatorNot : public UnaryOperator {
0062   public:
0063     OperatorNot(Evaluator* arg) : UnaryOperator(arg) {}
0064 
0065     bool operator()(const Data& data) const override { return not(*m_arg)(data); }
0066 
0067     void dump(std::ostream& out, bool const ignoreMasks = false) const override {
0068       out << '(';
0069       out << "NOT ";
0070       m_arg->dump(out, ignoreMasks);
0071       out << ')';
0072     }
0073   };
0074 
0075   class OperatorAnd : public BinaryOperator {
0076   public:
0077     OperatorAnd(Evaluator* arg1, Evaluator* arg2) : BinaryOperator(arg1, arg2) {}
0078 
0079     bool operator()(const Data& data) const override {
0080       // force the execution of both arguments, otherwise prescalers won't work properly
0081       bool r1 = (*m_arg1)(data);
0082       bool r2 = (*m_arg2)(data);
0083       return r1 and r2;
0084     }
0085 
0086     void dump(std::ostream& out, bool const ignoreMasks = false) const override {
0087       out << '(';
0088       m_arg1->dump(out, ignoreMasks);
0089       out << " AND ";
0090       m_arg2->dump(out, ignoreMasks);
0091       out << ')';
0092     }
0093   };
0094 
0095   class OperatorOr : public BinaryOperator {
0096   public:
0097     OperatorOr(Evaluator* arg1, Evaluator* arg2) : BinaryOperator(arg1, arg2) {}
0098 
0099     bool operator()(const Data& data) const override {
0100       // force the execution of both arguments, otherwise prescalers won't work properly
0101       bool r1 = (*m_arg1)(data);
0102       bool r2 = (*m_arg2)(data);
0103       return r1 or r2;
0104     }
0105 
0106     void dump(std::ostream& out, bool const ignoreMasks = false) const override {
0107       out << '(';
0108       m_arg1->dump(out, ignoreMasks);
0109       out << " OR ";
0110       m_arg2->dump(out, ignoreMasks);
0111       out << ')';
0112     }
0113   };
0114 
0115   class OperatorXor : public BinaryOperator {
0116   public:
0117     OperatorXor(Evaluator* arg1, Evaluator* arg2) : BinaryOperator(arg1, arg2) {}
0118 
0119     bool operator()(const Data& data) const override {
0120       // force the execution of both arguments, otherwise prescalers won't work properly
0121       bool r1 = (*m_arg1)(data);
0122       bool r2 = (*m_arg2)(data);
0123       return r1 xor r2;
0124     }
0125 
0126     void dump(std::ostream& out, bool const ignoreMasks = false) const override {
0127       out << '(';
0128       m_arg1->dump(out, ignoreMasks);
0129       out << " XOR ";
0130       m_arg2->dump(out, ignoreMasks);
0131       out << ')';
0132     }
0133   };
0134 
0135   class OperatorMasking : public BinaryOperator {
0136   public:
0137     OperatorMasking(Evaluator* arg1, Evaluator* arg2) : BinaryOperator(arg1, arg2) {}
0138 
0139     bool operator()(const Data& data) const override { return (*m_arg1)(data); }
0140 
0141     void init(const Data& data) override {
0142       m_arg1->init(data);
0143       m_arg2->init(data);
0144       m_arg1->mask(*m_arg2);
0145     }
0146 
0147     // apply mask(s) only to the first Evaluator
0148     // (the second Evaluator is not used in the decision of OperatorMasking)
0149     void mask(Evaluator const& arg) override { m_arg1->mask(arg); }
0150 
0151     void dump(std::ostream& out, bool const ignoreMasks = false) const override {
0152       out << '(';
0153       // ignore masks on the first Evaluator to dump the full logical expression
0154       m_arg1->dump(out, true);
0155       out << " MASKING ";
0156       m_arg2->dump(out, ignoreMasks);
0157       out << ')';
0158     }
0159   };
0160 
0161 }  // namespace triggerExpression
0162 
0163 #endif  // HLTrigger_HLTcore_TriggerExpressionOperators_h