Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:55

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