CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/FWCore/Common/interface/TriggerNames.h

Go to the documentation of this file.
00001 #ifndef FWCore_Common_TriggerNames_h
00002 #define FWCore_Common_TriggerNames_h
00003 
00004 // -*- C++ -*-
00005 /*
00006 Original Author:  W. David Dagenhart 1 June 2007
00007 (originally this was in the FWCore/Framework package)
00008 
00009 Used to access the names and indices of the triggers corresponding
00010 to a particular TriggerResults object (usually from the HLT process
00011 but one could also access the path names of other cmsRun processes
00012 used to create the input file).
00013 
00014 One normally gets a TriggerNames object from the event with a line
00015 of code that looks like this:
00016 
00017 const edm::TriggerNames & triggerNames = event.triggerNames(*triggerResults);
00018 
00019 where "event" has type edm::Event and "triggerResults" has type
00020 edm::Handle<edm::TriggerResults>. It is a very good idea to
00021 check if the Handle is valid before dereferencing it. "*triggerResults"
00022 will seg fault if the Handle is invalid.  Note the return value is
00023 a reference. Also the accessors inside TriggerNames that return the
00024 names return references. Code will perform faster and use less memory
00025 if the references are used instead of needlessly copying the strings.
00026 Note that the Event maintains a cache of TriggerNames objects for
00027 rapid lookup. There should be no reason for each module that uses
00028 TriggerNames to maintain its own cache of TriggerNames objects
00029 or strings, not even of the current trigger names.
00030 
00031 Some users may need to know when the trigger names have changed,
00032 because they initialize data structures or book histograms or
00033 something when this occurs.  This can be determined quickly and
00034 efficiently by saving the ParameterSetID associated with a TriggerNames
00035 object and then comparing with the ParameterSetID of subsequent objects.
00036 If the ParameterSetIDs are the same, then all the names are the
00037 same. This is much more efficient than comparing all the names
00038 in the object. Although generally for real data we expect the names
00039 should only change at run boundaries, there already exist simulation
00040 samples where the names change more often than that. There is nothing
00041 in the offline code to prevent this and it probably makes sense to check
00042 for names changing more often than by run even in real data.
00043 */
00044 
00045 #include "DataFormats/Provenance/interface/ParameterSetID.h"
00046 
00047 #include <string>
00048 #include <map>
00049 #include <vector>
00050 
00051 namespace edm {
00052 
00053   class ParameterSet;
00054 
00055   class TriggerNames {
00056 
00057   public:
00058 
00059     typedef std::vector<std::string> Strings;
00060     typedef std::map<std::string, unsigned int> IndexMap;
00061 
00062     // Users should not construct these.  Instead they should
00063     // get a reference to the current one from the Event. See
00064     // comments above.
00065     TriggerNames();
00066     TriggerNames(edm::ParameterSet const& pset);
00067 
00068     Strings const& triggerNames() const;
00069 
00070     // Throws if the index is out of range.
00071     std::string const& triggerName(unsigned int index) const;
00072 
00073     // If the input name is not known, this returns a value
00074     // equal to the size.
00075     unsigned int triggerIndex(std::string const& name) const;
00076 
00077     // The number of trigger names.
00078     Strings::size_type size() const;
00079 
00080     // Can be used to quickly compare two TriggerNames objects
00081     // to see whether or not they contain the same names.
00082     ParameterSetID const& parameterSetID() const;
00083 
00084   private:
00085 
00086     ParameterSetID psetID_;
00087 
00088     Strings triggerNames_;
00089     IndexMap indexMap_;
00090   };
00091 }
00092 #endif