TreeElement

TreeOperator

TriggerSelector

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
#ifndef DQMServices_StreamerIO_TriggerSelector_h
#define DQMServices_StreamerIO_TriggerSelector_h

#include <memory>
#include <string>
#include <vector>

namespace edm {
  class EventSelector;
  class HLTGlobalStatus;
  class TriggerResults;
}  // namespace edm

namespace dqmservices {
  /**
 * Event selector allowing for and/not combination of triggers/paths
 *
 */

  class TriggerSelector {
  public:
    typedef std::vector<std::string> Strings;

    /**
   * Initializes TriggerSelector to use edm::EventSelector for selection.
   */
    TriggerSelector(Strings const& pathspecs, Strings const& names);

    /**
   * Takes selection string and list of triggers
   */
    TriggerSelector(std::string const& expression, Strings const& triggernames);

    ~TriggerSelector() = default;

    /**
   * Returns status of always positive bit
   */
    bool wantAll() const { return acceptAll_; }

    /**
   * Evaluates if trigger results pass selection
   */
    bool acceptEvent(edm::TriggerResults const&) const;

    /*
   * Takes array of trigger results and a number of triggers in array and
   * returns
   * if it passes selection
   */
    bool acceptEvent(unsigned char const*, int) const;

    /*
   * Returns if HLTGlobalStatus passes selection
   */
    bool returnStatus(edm::HLTGlobalStatus const& trStatus) const { return masterElement_->returnStatus(trStatus); }

    /*
   * Does XMl compatible formatting of the selection string
   */
    static std::string makeXMLString(std::string const& input);

  private:
    bool acceptAll_;

    /*
   * Starts parsing selection string
   */
    void init(std::string const& path, Strings const& triggernames);

    /*
   * Removes extra spaces from string
   */
    static std::string trim(std::string input);

    /*
   * Class used for storing internal representation of the selection string
   */
    class TreeElement {
      enum TreeOperator { NonInit = 0, AND = 1, OR = 2, NOT = 3, BR = 4 };

    public:
      /*
     * Parser of selection string. Splits string into tokens and initializes new
     * elements to parse them.
     */
      TreeElement(std::string const& inputString, Strings const& tr, TreeElement* parentElement = nullptr);
      ~TreeElement();

      /*
     * Returns selection status of current element calculated recursively from
     * it's child elements
     */
      bool returnStatus(edm::HLTGlobalStatus const& trStatus) const;

      /*
     * Returns operator type of the element
     */
      TreeOperator op() const { return op_; }

      /*
     * Returns parent element
     */
      TreeElement* parent() const { return parent_; }

    private:
      TreeElement* parent_;
      std::vector<TreeElement*> children_;
      TreeOperator op_;
      int trigBit_;
    };

    std::shared_ptr<TreeElement> masterElement_;

    // keep a copy of initialization string
    std::string expression_;

    std::shared_ptr<edm::EventSelector> eventSelector_;
    bool useOld_;

    static const bool debug_ = false;
  };

}  // namespace dqmservices

#endif  // DQMServices_StreamerIO_TriggerSelector_h