FWCore
Common
interface
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
45
#include "
DataFormats/Provenance/interface/ParameterSetID.h
"
46
47
#include <string>
48
#include <utility>
49
#include <vector>
50
51
namespace
edm
{
52
53
class
ParameterSet
;
54
55
class
TriggerNames
{
56
public
:
57
using
IndexMap
= std::vector<std::pair<std::string_view, unsigned int>>;
58
using
Strings
= std::vector<std::string>;
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
() =
default
;
64
explicit
TriggerNames
(
edm::ParameterSet
const
&
pset
);
65
66
TriggerNames
(
TriggerNames
const
&);
67
TriggerNames
(
TriggerNames
&&) =
default
;
68
TriggerNames
&
operator=
(
TriggerNames
const
&);
69
TriggerNames
&
operator=
(
TriggerNames
&&) =
default
;
70
71
// called as part of reading back object from ROOT storage
72
void
initializeTriggerIndex
();
73
74
Strings
const
&
triggerNames
()
const
;
75
76
// Throws if the index is out of range.
77
std::string
const
&
triggerName
(
unsigned
int
index
)
const
;
78
79
// If the input name is not known, this returns a value
80
// equal to the size.
81
unsigned
int
triggerIndex
(std::string_view
name
)
const
;
82
83
// The number of trigger names.
84
std::size_t
size
()
const
;
85
86
// Can be used to quickly compare two TriggerNames objects
87
// to see whether or not they contain the same names.
88
ParameterSetID
const
&
parameterSetID
()
const
;
89
90
private
:
91
ParameterSetID
psetID_
;
92
93
Strings
triggerNames_
;
94
IndexMap
indexMap_
;
95
};
96
}
// namespace edm
97
#endif
edm::TriggerNames::parameterSetID
ParameterSetID const & parameterSetID() const
Definition:
TriggerNames.cc:61
edm
HLT enums.
Definition:
AlignableModifier.h:19
edm::TriggerNames::TriggerNames
TriggerNames()=default
edm::TriggerNames::triggerNames_
Strings triggerNames_
Definition:
TriggerNames.h:93
edm::TriggerNames::indexMap_
IndexMap indexMap_
Definition:
TriggerNames.h:94
edm::Hash< ParameterSetType >
edm::TriggerNames::triggerNames
Strings const & triggerNames() const
Definition:
TriggerNames.cc:48
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition:
ParameterSet.h:47
ParameterSet
Definition:
Functions.h:16
edm::TriggerNames::IndexMap
std::vector< std::pair< std::string_view, unsigned int > > IndexMap
Definition:
TriggerNames.h:57
edm::TriggerNames::triggerIndex
unsigned int triggerIndex(std::string_view name) const
Definition:
TriggerNames.cc:52
edm::TriggerNames::triggerName
std::string const & triggerName(unsigned int index) const
Definition:
TriggerNames.cc:50
edm::TriggerNames::psetID_
ParameterSetID psetID_
Definition:
TriggerNames.h:91
edm::TriggerNames::size
std::size_t size() const
Definition:
TriggerNames.cc:59
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::operator=
TriggerNames & operator=(TriggerNames const &)
Definition:
TriggerNames.cc:32
edm::TriggerNames::Strings
std::vector< std::string > Strings
Definition:
TriggerNames.h:58
muonDTDigis_cfi.pset
pset
Definition:
muonDTDigis_cfi.py:27
edm::TriggerNames::initializeTriggerIndex
void initializeTriggerIndex()
Definition:
TriggerNames.cc:38
Generated for CMSSW Reference Manual by
1.8.16