CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
57  public:
58 
59  typedef std::vector<std::string> Strings;
60  typedef std::map<std::string, unsigned int> IndexMap;
61 
62  // Users should not construct these. Instead they should
63  // get a reference to the current one from the Event. See
64  // comments above.
65  TriggerNames();
67 
68  Strings const& triggerNames() const;
69 
70  // Throws if the index is out of range.
71  std::string const& triggerName(unsigned int index) const;
72 
73  // If the input name is not known, this returns a value
74  // equal to the size.
75  unsigned int triggerIndex(std::string const& name) const;
76 
77  // The number of trigger names.
78  Strings::size_type size() const;
79 
80  // Can be used to quickly compare two TriggerNames objects
81  // to see whether or not they contain the same names.
82  ParameterSetID const& parameterSetID() const;
83 
84  private:
85 
87 
90  };
91 }
92 #endif
std::map< std::string, unsigned int > IndexMap
Definition: TriggerNames.h:60
Strings::size_type size() const
Definition: TriggerNames.cc:39
IndexMap indexMap_
Definition: TriggerNames.h:89
uint16_t size_type
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
ParameterSetID const & parameterSetID() const
Definition: TriggerNames.cc:42
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
std::vector< std::string > Strings
Definition: TriggerNames.h:59
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
Strings triggerNames_
Definition: TriggerNames.h:88
ParameterSetID psetID_
Definition: TriggerNames.h:86