CMS 3D CMS Logo

TriggerNames.h
Go to the documentation of this file.
1 #ifndef FWCore_Common_TriggerNames_h
2 #define FWCore_Common_TriggerNames_h
3 
4 // -*- C++ -*-
5 /*
6 Original Author: W. David Dagenhart 1 June 2007
7 (originally this was in the FWCore/Framework package)
8 
9 Used to access the names and indices of the triggers corresponding
10 to a particular TriggerResults object (usually from the HLT process
11 but one could also access the path names of other cmsRun processes
12 used to create the input file).
13 
14 One normally gets a TriggerNames object from the event with a line
15 of code that looks like this:
16 
17 const edm::TriggerNames & triggerNames = event.triggerNames(*triggerResults);
18 
19 where "event" has type edm::Event and "triggerResults" has type
20 edm::Handle<edm::TriggerResults>. It is a very good idea to
21 check if the Handle is valid before dereferencing it. "*triggerResults"
22 will seg fault if the Handle is invalid. Note the return value is
23 a reference. Also the accessors inside TriggerNames that return the
24 names return references. Code will perform faster and use less memory
25 if the references are used instead of needlessly copying the strings.
26 Note that the Event maintains a cache of TriggerNames objects for
27 rapid lookup. There should be no reason for each module that uses
28 TriggerNames to maintain its own cache of TriggerNames objects
29 or strings, not even of the current trigger names.
30 
31 Some users may need to know when the trigger names have changed,
32 because they initialize data structures or book histograms or
33 something when this occurs. This can be determined quickly and
34 efficiently by saving the ParameterSetID associated with a TriggerNames
35 object and then comparing with the ParameterSetID of subsequent objects.
36 If the ParameterSetIDs are the same, then all the names are the
37 same. This is much more efficient than comparing all the names
38 in the object. Although generally for real data we expect the names
39 should only change at run boundaries, there already exist simulation
40 samples where the names change more often than that. There is nothing
41 in the offline code to prevent this and it probably makes sense to check
42 for names changing more often than by run even in real data.
43 */
44 
46 
47 #include <string>
48 #include <map>
49 #include <vector>
50 
51 namespace edm {
52 
53  class ParameterSet;
54 
55  class TriggerNames {
56  public:
57  typedef std::vector<std::string> Strings;
58  typedef std::map<std::string, unsigned int> IndexMap;
59 
60  // Users should not construct these. Instead they should
61  // get a reference to the current one from the Event. See
62  // comments above.
63  TriggerNames();
65 
66  Strings const& triggerNames() const;
67 
68  // Throws if the index is out of range.
69  std::string const& triggerName(unsigned int index) const;
70 
71  // If the input name is not known, this returns a value
72  // equal to the size.
73  unsigned int triggerIndex(std::string const& name) const;
74 
75  // The number of trigger names.
76  Strings::size_type size() const;
77 
78  // Can be used to quickly compare two TriggerNames objects
79  // to see whether or not they contain the same names.
80  ParameterSetID const& parameterSetID() const;
81 
82  private:
84 
87  };
88 } // namespace edm
89 #endif
edm::TriggerNames::TriggerNames
TriggerNames()
Definition: TriggerNames.cc:7
edm::TriggerNames::parameterSetID
ParameterSetID const & parameterSetID() const
Definition: TriggerNames.cc:33
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::TriggerNames::triggerNames_
Strings triggerNames_
Definition: TriggerNames.h:85
edm::TriggerNames::Strings
std::vector< std::string > Strings
Definition: TriggerNames.h:57
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
edm::TriggerNames::indexMap_
IndexMap indexMap_
Definition: TriggerNames.h:86
edm::Hash< ParameterSetType >
edm::TriggerNames::triggerNames
Strings const & triggerNames() const
Definition: TriggerNames.cc:20
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
edm::TriggerNames::IndexMap
std::map< std::string, unsigned int > IndexMap
Definition: TriggerNames.h:58
ParameterSet
Definition: Functions.h:16
edm::TriggerNames::triggerName
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:22
edm::TriggerNames::psetID_
ParameterSetID psetID_
Definition: TriggerNames.h:83
edm::TriggerNames::size
Strings::size_type size() const
Definition: TriggerNames.cc:31
edm::TriggerNames
Definition: TriggerNames.h:55
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
ParameterSetID.h
edm::TriggerNames::triggerIndex
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:24
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27