CMS 3D CMS Logo

TriggerResultsFilter.cc
Go to the documentation of this file.
1 
10 #include <vector>
11 #include <string>
12 #include <sstream>
13 #include <iostream>
14 #include <iomanip>
15 
22 
25 #include "TriggerResultsFilter.h"
26 
27 //
28 // constructors and destructor
29 //
31  m_expression(nullptr),
32  m_eventCache(config, consumesCollector())
33 {
34  const std::vector<std::string> & expressions = config.getParameter<std::vector<std::string>>("triggerConditions");
35  parse( expressions );
36 }
37 
39 {
40  delete m_expression;
41 }
42 
43 void
46  // # HLT results - set to empty to ignore HLT
47  desc.add<edm::InputTag>("hltResults", edm::InputTag("TriggerResults"));
48  // # L1 uGT results - set to empty to ignore L1T
49  desc.add<edm::InputTag>("l1tResults", edm::InputTag("hltGtStage2Digis"));
50  // # use initial L1 decision, before masks and prescales
51  desc.add<bool>("l1tIgnoreMaskAndPrescale", false);
52  // # OBSOLETE - these parameters are ignored, they are left only not to break old configurations
53  // they will not be printed in the generated cfi.py file
54  desc.addOptionalNode(edm::ParameterDescription<bool>("l1tIgnoreMask", false, true), false)->setComment("This parameter is obsolete and will be ignored.");
55  desc.addOptionalNode(edm::ParameterDescription<bool>("l1techIgnorePrescales", false, true), false)->setComment("This parameter is obsolete and will be ignored.");
56  desc.addOptionalNode(edm::ParameterDescription<unsigned int>("daqPartitions", 0x01, true), false)->setComment("This parameter is obsolete and will be ignored.");
57  // # throw exception on unknown trigger names
58  desc.add<bool>("throw", true);
59  // # trigger conditions
60  std::vector<std::string> triggerConditions(1,"HLT_*");
61  desc.add<std::vector<std::string>>("triggerConditions", triggerConditions);
62  descriptions.add("triggerResultsFilter", desc);
63 }
64 
65 void TriggerResultsFilter::parse(const std::vector<std::string> & expressions) {
66  // parse the logical expressions into functionals
67  if (expressions.empty()) {
68  edm::LogWarning("Configuration") << "Empty trigger results expression";
69  } else if (expressions.size() == 1) {
70  parse( expressions[0] );
71  } else {
72  std::stringstream expression;
73  expression << "(" << expressions[0] << ")";
74  for (unsigned int i = 1; i < expressions.size(); ++i)
75  expression << " OR (" << expressions[i] << ")";
76  parse( expression.str() );
77  }
78 }
79 
80 void TriggerResultsFilter::parse(const std::string & expression) {
81  // parse the logical expressions into functionals
82  m_expression = triggerExpression::parse( expression );
83 
84  // check if the expressions were parsed correctly
85  if (not m_expression)
86  edm::LogWarning("Configuration") << "Couldn't parse trigger results expression \"" << expression << "\"";
87 }
88 
90 {
91  if (not m_expression)
92  // no valid expression has been parsed
93  return false;
94 
95  if (not m_eventCache.setEvent(event, setup))
96  // couldn't properly access all information from the Event
97  return false;
98 
99  // if the L1 or HLT configurations have changed, (re)initialize the filters (including during the first event)
101  m_expression->init(m_eventCache);
102 
103  // log the expanded configuration
104  edm::LogInfo("Configuration") << "TriggerResultsFilter configuration updated: " << *m_expression;
105  }
106 
107  // run the trigger results filter
108  return (*m_expression)(m_eventCache);
109 }
110 
111 // register as framework plugin
T getParameter(std::string const &) const
void setComment(std::string const &value)
void parse(const std::string &expression)
parse the logical expression into functionals
Evaluator * parse(const T &text)
triggerExpression::Data m_eventCache
cache some data from the Event for faster access by the m_expression
#define nullptr
TriggerResultsFilter(const edm::ParameterSet &)
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
Definition: config.py:1
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
triggerExpression::Evaluator * m_expression
evaluator for the trigger condition
ParameterDescriptionNode * addOptionalNode(ParameterDescriptionNode const &node, bool writeToCfi)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool setEvent(const edm::Event &event, const edm::EventSetup &setup)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: event.py:1