CMS 3D CMS Logo

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 
24 
28 
29 //
30 // constructors and destructor
31 //
33  m_eventSetupPathsKey(config.getParameter<std::string>("eventSetupPathsKey")),
34  m_eventSetupWatcher(),
35  m_expression(nullptr),
36  m_eventCache(config, consumesCollector())
37 {
38 }
39 
41 {
42  delete m_expression;
43 }
44 
45 void
48  // # HLT results - set to empty to ignore HLT
49  desc.add<edm::InputTag>("hltResults", edm::InputTag("TriggerResults"));
50  // # L1 uGT results - set to empty to ignore L1T
51  desc.add<edm::InputTag>("l1tResults", edm::InputTag("hltGtStage2Digis"));
52  // # use initial L1 decision, before masks and prescales
53  desc.add<bool>("l1tIgnoreMaskAndPrescale", false);
54  // # OBSOLETE - these parameters are ignored, they are left only not to break old configurations
55  // they will not be printed in the generated cfi.py file
56  desc.addOptionalNode(edm::ParameterDescription<bool>("l1tIgnoreMask", false, true), false)->setComment("This parameter is obsolete and will be ignored.");
57  desc.addOptionalNode(edm::ParameterDescription<bool>("l1techIgnorePrescales", false, true), false)->setComment("This parameter is obsolete and will be ignored.");
58  desc.addOptionalNode(edm::ParameterDescription<unsigned int>("daqPartitions", 0x01, true), false)->setComment("This parameter is obsolete and will be ignored.");
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.empty()) {
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  auto 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
std::map< std::string, std::string > m_alcarecoToTrig
void setComment(std::string const &value)
Evaluator * parse(const T &text)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define nullptr
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
std::vector< std::string > decompose(const std::string &concatPaths) const
Decompose one value of map from concatenated string.
Definition: config.py:1
std::string m_eventSetupPathsKey
read the triggerConditions from the database
ModuleDescription const & moduleDescription() const
Definition: EDFilterBase.h:59
std::string const & moduleLabel() const
edm::ESWatcher< AlCaRecoTriggerBitsRcd > m_eventSetupWatcher
bool filter(edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ParameterDescriptionNode * addOptionalNode(ParameterDescriptionNode const &node, bool writeToCfi)
triggerExpression::Evaluator * m_expression
evaluator for the trigger condition
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool setEvent(const edm::Event &event, const edm::EventSetup &setup)
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 &)
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:52
T get() const
Definition: EventSetup.h:71
Definition: event.py:1