Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-24 01:14:43

0001 #ifndef HLTrigger_HLTfilters_TriggerExpressionOperators_h
0002 #define HLTrigger_HLTfilters_TriggerExpressionOperators_h
0003 
0004 #include <memory>
0005 #include "HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h"
0006 
0007 namespace triggerExpression {
0008 
0009   // abstract unary operator
0010   class UnaryOperator : public Evaluator {
0011   public:
0012     UnaryOperator(Evaluator* arg) : m_arg(arg) {}
0013 
0014     // initialize the depending modules
0015     void init(const Data& data) override { m_arg->init(data); }
0016 
0017     // return the patterns from the depending modules
0018     std::vector<std::string> patterns() const override { return m_arg->patterns(); }
0019 
0020   protected:
0021     std::unique_ptr<Evaluator> m_arg;
0022   };
0023 
0024   // abstract binary operator
0025   class BinaryOperator : public Evaluator {
0026   public:
0027     BinaryOperator(Evaluator* arg1, Evaluator* arg2) : m_arg1(arg1), m_arg2(arg2) {}
0028 
0029     // initialize the depending modules
0030     void init(const Data& data) override {
0031       m_arg1->init(data);
0032       m_arg2->init(data);
0033     }
0034 
0035     // return the patterns from the depending modules
0036     std::vector<std::string> patterns() const override {
0037       std::vector<std::string> patterns = m_arg1->patterns();
0038       auto patterns2 = m_arg2->patterns();
0039       patterns.insert(
0040           patterns.end(), std::make_move_iterator(patterns2.begin()), std::make_move_iterator(patterns2.end()));
0041       return patterns;
0042     }
0043 
0044   protected:
0045     std::unique_ptr<Evaluator> m_arg1;
0046     std::unique_ptr<Evaluator> m_arg2;
0047   };
0048 
0049   // concrete operators
0050 
0051   class OperatorNot : public UnaryOperator {
0052   public:
0053     OperatorNot(Evaluator* arg) : UnaryOperator(arg) {}
0054 
0055     bool operator()(const Data& data) const override { return not(*m_arg)(data); }
0056 
0057     void dump(std::ostream& out) const override {
0058       out << "NOT ";
0059       m_arg->dump(out);
0060     }
0061   };
0062 
0063   class OperatorAnd : public BinaryOperator {
0064   public:
0065     OperatorAnd(Evaluator* arg1, Evaluator* arg2) : BinaryOperator(arg1, arg2) {}
0066 
0067     bool operator()(const Data& data) const override {
0068       // force the execution af both arguments, otherwise precalers won't work properly
0069       bool r1 = (*m_arg1)(data);
0070       bool r2 = (*m_arg2)(data);
0071       return r1 and r2;
0072     }
0073 
0074     void dump(std::ostream& out) const override {
0075       m_arg1->dump(out);
0076       out << " AND ";
0077       m_arg2->dump(out);
0078     }
0079   };
0080 
0081   class OperatorOr : public BinaryOperator {
0082   public:
0083     OperatorOr(Evaluator* arg1, Evaluator* arg2) : BinaryOperator(arg1, arg2) {}
0084 
0085     bool operator()(const Data& data) const override {
0086       // force the execution af both arguments, otherwise precalers won't work properly
0087       bool r1 = (*m_arg1)(data);
0088       bool r2 = (*m_arg2)(data);
0089       return r1 or r2;
0090     }
0091 
0092     void dump(std::ostream& out) const override {
0093       m_arg1->dump(out);
0094       out << " OR ";
0095       m_arg2->dump(out);
0096     }
0097   };
0098 
0099   class OperatorXor : public BinaryOperator {
0100   public:
0101     OperatorXor(Evaluator* arg1, Evaluator* arg2) : BinaryOperator(arg1, arg2) {}
0102 
0103     bool operator()(const Data& data) const override {
0104       // force the execution af both arguments, otherwise precalers won't work properly
0105       bool r1 = (*m_arg1)(data);
0106       bool r2 = (*m_arg2)(data);
0107       return r1 xor r2;
0108     }
0109 
0110     void dump(std::ostream& out) const override {
0111       m_arg1->dump(out);
0112       out << " XOR ";
0113       m_arg2->dump(out);
0114     }
0115   };
0116 
0117 }  // namespace triggerExpression
0118 
0119 #endif  // HLTrigger_HLTfilters_TriggerExpressionOperators_h