Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:15

0001 #ifndef DQMServices_StreamerIO_TriggerSelector_h
0002 #define DQMServices_StreamerIO_TriggerSelector_h
0003 
0004 #include <memory>
0005 #include <string>
0006 #include <vector>
0007 
0008 namespace edm {
0009   class EventSelector;
0010   class HLTGlobalStatus;
0011   class TriggerResults;
0012 }  // namespace edm
0013 
0014 namespace dqmservices {
0015   /**
0016  * Event selector allowing for and/not combination of triggers/paths
0017  *
0018  */
0019 
0020   class TriggerSelector {
0021   public:
0022     typedef std::vector<std::string> Strings;
0023 
0024     /**
0025    * Initializes TriggerSelector to use edm::EventSelector for selection.
0026    */
0027     TriggerSelector(Strings const& pathspecs, Strings const& names);
0028 
0029     /**
0030    * Takes selection string and list of triggers
0031    */
0032     TriggerSelector(std::string const& expression, Strings const& triggernames);
0033 
0034     ~TriggerSelector() = default;
0035 
0036     /**
0037    * Returns status of always positive bit
0038    */
0039     bool wantAll() const { return acceptAll_; }
0040 
0041     /**
0042    * Evaluates if trigger results pass selection
0043    */
0044     bool acceptEvent(edm::TriggerResults const&) const;
0045 
0046     /*
0047    * Takes array of trigger results and a number of triggers in array and
0048    * returns
0049    * if it passes selection
0050    */
0051     bool acceptEvent(unsigned char const*, int) const;
0052 
0053     /*
0054    * Returns if HLTGlobalStatus passes selection
0055    */
0056     bool returnStatus(edm::HLTGlobalStatus const& trStatus) const { return masterElement_->returnStatus(trStatus); }
0057 
0058     /*
0059    * Does XMl compatible formatting of the selection string
0060    */
0061     static std::string makeXMLString(std::string const& input);
0062 
0063   private:
0064     bool acceptAll_;
0065 
0066     /*
0067    * Starts parsing selection string
0068    */
0069     void init(std::string const& path, Strings const& triggernames);
0070 
0071     /*
0072    * Removes extra spaces from string
0073    */
0074     static std::string trim(std::string input);
0075 
0076     /*
0077    * Class used for storing internal representation of the selection string
0078    */
0079     class TreeElement {
0080       enum TreeOperator { NonInit = 0, AND = 1, OR = 2, NOT = 3, BR = 4 };
0081 
0082     public:
0083       /*
0084      * Parser of selection string. Splits string into tokens and initializes new
0085      * elements to parse them.
0086      */
0087       TreeElement(std::string const& inputString, Strings const& tr, TreeElement* parentElement = nullptr);
0088       ~TreeElement();
0089 
0090       /*
0091      * Returns selection status of current element calculated recursively from
0092      * it's child elements
0093      */
0094       bool returnStatus(edm::HLTGlobalStatus const& trStatus) const;
0095 
0096       /*
0097      * Returns operator type of the element
0098      */
0099       TreeOperator op() const { return op_; }
0100 
0101       /*
0102      * Returns parent element
0103      */
0104       TreeElement* parent() const { return parent_; }
0105 
0106     private:
0107       TreeElement* parent_;
0108       std::vector<TreeElement*> children_;
0109       TreeOperator op_;
0110       int trigBit_;
0111     };
0112 
0113     std::shared_ptr<TreeElement> masterElement_;
0114 
0115     // keep a copy of initialization string
0116     std::string expression_;
0117 
0118     std::shared_ptr<edm::EventSelector> eventSelector_;
0119     bool useOld_;
0120 
0121     static const bool debug_ = false;
0122   };
0123 
0124 }  // namespace dqmservices
0125 
0126 #endif  // DQMServices_StreamerIO_TriggerSelector_h