Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:36

0001 #ifndef FWCore_Common_TriggerNames_h
0002 #define FWCore_Common_TriggerNames_h
0003 
0004 // -*- C++ -*-
0005 /*
0006 Original Author:  W. David Dagenhart 1 June 2007
0007 (originally this was in the FWCore/Framework package)
0008 
0009 Used to access the names and indices of the triggers corresponding
0010 to a particular TriggerResults object (usually from the HLT process
0011 but one could also access the path names of other cmsRun processes
0012 used to create the input file).
0013 
0014 One normally gets a TriggerNames object from the event with a line
0015 of code that looks like this:
0016 
0017 const edm::TriggerNames & triggerNames = event.triggerNames(*triggerResults);
0018 
0019 where "event" has type edm::Event and "triggerResults" has type
0020 edm::Handle<edm::TriggerResults>. It is a very good idea to
0021 check if the Handle is valid before dereferencing it. "*triggerResults"
0022 will seg fault if the Handle is invalid.  Note the return value is
0023 a reference. Also the accessors inside TriggerNames that return the
0024 names return references. Code will perform faster and use less memory
0025 if the references are used instead of needlessly copying the strings.
0026 Note that the Event maintains a cache of TriggerNames objects for
0027 rapid lookup. There should be no reason for each module that uses
0028 TriggerNames to maintain its own cache of TriggerNames objects
0029 or strings, not even of the current trigger names.
0030 
0031 Some users may need to know when the trigger names have changed,
0032 because they initialize data structures or book histograms or
0033 something when this occurs.  This can be determined quickly and
0034 efficiently by saving the ParameterSetID associated with a TriggerNames
0035 object and then comparing with the ParameterSetID of subsequent objects.
0036 If the ParameterSetIDs are the same, then all the names are the
0037 same. This is much more efficient than comparing all the names
0038 in the object. Although generally for real data we expect the names
0039 should only change at run boundaries, there already exist simulation
0040 samples where the names change more often than that. There is nothing
0041 in the offline code to prevent this and it probably makes sense to check
0042 for names changing more often than by run even in real data.
0043 */
0044 
0045 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0046 
0047 #include <string>
0048 #include <utility>
0049 #include <vector>
0050 
0051 namespace edm {
0052 
0053   class ParameterSet;
0054 
0055   class TriggerNames {
0056   public:
0057     using IndexMap = std::vector<std::pair<std::string_view, unsigned int>>;
0058     using Strings = std::vector<std::string>;
0059 
0060     // Users should not construct these.  Instead they should
0061     // get a reference to the current one from the Event. See
0062     // comments above.
0063     TriggerNames() = default;
0064     explicit TriggerNames(edm::ParameterSet const& pset);
0065 
0066     TriggerNames(TriggerNames const&);
0067     TriggerNames(TriggerNames&&) = default;
0068     TriggerNames& operator=(TriggerNames const&);
0069     TriggerNames& operator=(TriggerNames&&) = default;
0070 
0071     // called as part of reading back object from ROOT storage
0072     void initializeTriggerIndex();
0073 
0074     Strings const& triggerNames() const;
0075 
0076     // Throws if the index is out of range.
0077     std::string const& triggerName(unsigned int index) const;
0078 
0079     // If the input name is not known, this returns a value
0080     // equal to the size.
0081     unsigned int triggerIndex(std::string_view name) const;
0082 
0083     // The number of trigger names.
0084     std::size_t size() const;
0085 
0086     // Can be used to quickly compare two TriggerNames objects
0087     // to see whether or not they contain the same names.
0088     ParameterSetID const& parameterSetID() const;
0089 
0090   private:
0091     ParameterSetID psetID_;
0092 
0093     Strings triggerNames_;
0094     IndexMap indexMap_;
0095   };
0096 }  // namespace edm
0097 #endif