CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TriggerResultsFilterFromDB.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 #include <boost/foreach.hpp>
16 
25 
29 
30 //
31 // constructors and destructor
32 //
34  m_eventSetupPathsKey(config.getParameter<std::string>("eventSetupPathsKey")),
35  m_eventSetupWatcher(),
36  m_expression(0),
37  m_eventCache(config,consumesCollector())
38 {
39 }
40 
42 {
43  delete m_expression;
44 }
45 
46 void
49  // # HLT results - set to empty to ignore HLT
50  desc.add<edm::InputTag>("hltResults",edm::InputTag("TriggerResults"));
51  // # L1 GT results - set to empty to ignore L1T
52  desc.add<edm::InputTag>("l1tResults",edm::InputTag("hltGtDigis"));
53  // # use L1 mask
54  desc.add<bool>("l1tIgnoreMask",false);
55  // # read L1 technical bits from PSB#9, bypassing the prescales
56  desc.add<bool>("l1techIgnorePrescales",false);
57  // # used by the definition of the L1 mask
58  desc.add<unsigned int>("daqPartitions",0x01);
59  // # throw exception on unknown trigger names
60  desc.add<bool>("throw",true);
61  // # read paths from AlCaRecoTriggerBitsRcd via this key
62  desc.add<std::string>("eventSetupPathsKey","");
63  descriptions.add("triggerResultsFilterFromDB", desc);
64 }
65 
66 void TriggerResultsFilterFromDB::parse(const std::vector<std::string> & expressions) {
67  // parse the logical expressions into functionals
68  if (expressions.size() == 0) {
69  edm::LogWarning("Configuration") << "Empty trigger results expression";
70  } else if (expressions.size() == 1) {
71  parse( expressions[0] );
72  } else {
73  std::stringstream expression;
74  expression << "(" << expressions[0] << ")";
75  for (unsigned int i = 1; i < expressions.size(); ++i)
76  expression << " OR (" << expressions[i] << ")";
77  parse( expression.str() );
78  }
79 }
80 
82  // parse the logical expressions into functionals
83  m_expression = triggerExpression::parse( expression );
84 
85  // check if the expressions were parsed correctly
86  if (not m_expression)
87  edm::LogWarning("Configuration") << "Couldn't parse trigger results expression \"" << expression << "\"";
88 }
89 
90 // read the triggerConditions from the database
92 {
93  // Get map of strings to concatenated list of names of HLT paths from EventSetup:
95  setup.get<AlCaRecoTriggerBitsRcd>().get(triggerBits);
96  typedef std::map<std::string, std::string> TriggerMap;
97  const TriggerMap & triggerMap = triggerBits->m_alcarecoToTrig;
98 
99  TriggerMap::const_iterator listIter = triggerMap.find(m_eventSetupPathsKey);
100  if (listIter == triggerMap.end()) {
101  throw cms::Exception("Configuration") << "TriggerResultsFilterFromDB [instance: " << moduleDescription().moduleLabel()
102  << "]: No triggerList with key " << m_eventSetupPathsKey << " in AlCaRecoTriggerBitsRcd";
103  }
104 
105  // avoid a map<string,vector<string> > in DB for performance reason,
106  // the paths are mapped into one string that we have to decompose:
107  parse( triggerBits->decompose(listIter->second) );
108 }
109 
111 {
112  // if the IOV has changed, re-read the triggerConditions from the database
113  if (m_eventSetupWatcher.check(setup))
114  pathsFromSetup(event, setup);
115 
116  if (not m_expression)
117  // no valid expression has been parsed
118  return false;
119 
120  if (not m_eventCache.setEvent(event, setup))
121  // couldn't properly access all information from the Event
122  return false;
123 
124  // if the L1 or HLT configurations have changed, (re)initialize the filters (including during the first event)
126  m_expression->init(m_eventCache);
127 
128  // log the expanded configuration
129  edm::LogInfo("Configuration") << "TriggerResultsFilterFromDB configuration updated: " << *m_expression;
130  }
131 
132  // run the trigger results filter
133  return (*m_expression)(m_eventCache);
134 }
135 
136 // register as framework plugin
int i
Definition: DBlmapReader.cc:9
Evaluator * parse(const T &text)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::string m_eventSetupPathsKey
read the triggerConditions from the database
ModuleDescription const & moduleDescription() const
Definition: EDFilterBase.h:58
std::string const & moduleLabel() const
edm::ESWatcher< AlCaRecoTriggerBitsRcd > m_eventSetupWatcher
bool filter(edm::Event &, const edm::EventSetup &) override
triggerExpression::Evaluator * m_expression
evaluator for the trigger condition
ParameterDescriptionBase * add(U const &iLabel, T const &value)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
triggerExpression::Data m_eventCache
cache some data from the Event for faster access by the m_expression
void parse(const std::string &expression)
parse the logical expression into functionals
TriggerResultsFilterFromDB(const edm::ParameterSet &)
const T & get() const
Definition: EventSetup.h:56
bool setEvent(const edm::Event &event, const edm::EventSetup &setup)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void pathsFromSetup(const edm::Event &, const edm::EventSetup &setup)
read the triggerConditions from the database
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")