Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:06

0001 #ifndef FWCore_Framework_TriggerNamesService_h
0002 #define FWCore_Framework_TriggerNamesService_h
0003 
0004 // -*- C++ -*-
0005 /*
0006 
0007  Original Author:  Jim Kowalkowski 26-01-06
0008 
0009 
0010  This service makes the trigger names available.  They are provided
0011  in the same order that the pass/fail status of these triggers is
0012  recorded in the TriggerResults object.  These trigger names are
0013  the names of the paths that appear in the configuration (excluding
0014  end paths).  The order is the same as in the configuration.
0015 
0016  There are also accessors for the end path names.  
0017 
0018  There are other accessors for other trigger related information from the
0019  job configuration: the process name, whether a report on trigger results
0020  was requested and the parameter set containing the list of trigger paths.
0021 
0022  Almost all the functions return information related to the current
0023  process only.  The second and third getTrigPaths functions are exceptions.
0024  They will return the trigger path names from previous processes.
0025 
0026  Unit tests for parts of this class are in FWCore/Integration/run_SelectEvents.sh
0027  and the code it invokes.
0028 
0029 */
0030 
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 
0033 #include <string>
0034 #include <map>
0035 #include <vector>
0036 #include <unordered_set>
0037 
0038 namespace edm {
0039 
0040   class TriggerResults;
0041 
0042   namespace service {
0043     class TriggerNamesService {
0044     public:
0045       typedef std::vector<std::string> Strings;
0046       typedef std::map<std::string, unsigned int> PosMap;
0047       typedef PosMap::size_type size_type;
0048 
0049       explicit TriggerNamesService(ParameterSet const& proc_pset);
0050       // Default copy, copy assignment, d'tor all do the right thing.
0051 
0052       // trigger names for the current process
0053 
0054       // Return the number of trigger paths in the current process.
0055       size_type size() const { return trignames_.size(); }
0056       Strings const& getTrigPaths() const { return trignames_; }
0057       std::string const& getTrigPath(size_type const i) const { return trignames_.at(i); }
0058       size_type findTrigPath(std::string const& name) const { return find(trigpos_, name); }
0059 
0060       // Get the ordered vector of trigger names that corresponds to the bits
0061       // in the TriggerResults object.  Unlike the other functions in this class,
0062       // the next two functions will retrieve the names for previous processes.
0063       // If the TriggerResults object is from the current process, this only
0064       // works for modules in end paths, because the TriggerResults object is
0065       // not created until the normal paths complete execution.
0066       // Returns false if it fails to find the trigger path names.
0067       bool getTrigPaths(TriggerResults const& triggerResults, Strings& trigPaths);
0068 
0069       // This is the same as the previous function except the value returned in
0070       // the last argument indicates whether the results were retrieved from the
0071       // ParameterSet registry.  This will always be true except in old data where
0072       // the trigger names were stored inside of the TriggerResults object.
0073       bool getTrigPaths(TriggerResults const& triggerResults, Strings& trigPaths, bool& fromPSetRegistry);
0074 
0075       Strings const& getEndPaths() const { return end_names_; }
0076       std::string const& getEndPath(size_type const i) const { return end_names_.at(i); }
0077       size_type findEndPath(std::string const& name) const { return find(end_pos_, name); }
0078 
0079       Strings const& getTrigPathModules(std::string const& name) const { return modulenames_.at(find(trigpos_, name)); }
0080       Strings const& getTrigPathModules(size_type const i) const { return modulenames_.at(i); }
0081       std::string const& getTrigPathModule(std::string const& name, size_type const j) const {
0082         return (modulenames_.at(find(trigpos_, name))).at(j);
0083       }
0084       std::string const& getTrigPathModule(size_type const i, size_type const j) const {
0085         return (modulenames_.at(i)).at(j);
0086       }
0087       Strings const& getEndPathModules(std::string const& name) const {
0088         return end_modulenames_.at(find(end_pos_, name));
0089       }
0090       Strings const& getEndPathModules(size_type const i) const { return end_modulenames_.at(i); }
0091       std::string const& getEndPathModule(std::string const& name, size_type const j) const {
0092         return (end_modulenames_.at(find(end_pos_, name))).at(j);
0093       }
0094       std::string const& getEndPathModule(size_type const i, size_type const j) const {
0095         return (end_modulenames_.at(i)).at(j);
0096       }
0097 
0098       size_type find(PosMap const& posmap, std::string const& name) const {
0099         PosMap::const_iterator const pos(posmap.find(name));
0100         if (pos == posmap.end()) {
0101           return posmap.size();
0102         } else {
0103           return pos->second;
0104         }
0105       }
0106 
0107       std::string const& getProcessName() const { return process_name_; }
0108       bool wantSummary() const { return wantSummary_; }
0109 
0110       // Parameter set containing the trigger paths
0111       edm::ParameterSet const& getTriggerPSet() const { return trigger_pset_; }
0112 
0113     private:
0114       void loadPosMap(PosMap& posmap, Strings const& names) {
0115         size_type const n(names.size());
0116         for (size_type i = 0; i != n; ++i) {
0117           posmap[names[i]] = i;
0118         }
0119       }
0120 
0121       edm::ParameterSet trigger_pset_;
0122 
0123       Strings trignames_;
0124       PosMap trigpos_;
0125       Strings end_names_;
0126       PosMap end_pos_;
0127 
0128       std::vector<Strings> modulenames_;      // modules on trigger paths
0129       std::vector<Strings> end_modulenames_;  // modules on endpaths
0130 
0131       std::string process_name_;
0132       bool wantSummary_;
0133     };
0134   }  // namespace service
0135 }  // namespace edm
0136 
0137 #endif