Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-11-02 03:10:56

0001 #ifndef DataFormats_Common_HLTGlobalStatus_h
0002 #define DataFormats_Common_HLTGlobalStatus_h
0003 
0004 /** \class edm::HLTGlobalStatus
0005  *
0006  *  
0007  *  The HLT global status, summarising the status of the individual
0008  *  HLT triggers, is implemented as a vector of HLTPathStatus objects.
0009  *
0010  *  If the user wants map-like indexing of HLT triggers through their
0011  *  names as key, s/he must use the TriggerNamesService.
0012  *
0013  *
0014  *  \author Martin Grunewald
0015  *
0016  */
0017 
0018 #include "DataFormats/Common/interface/HLTenums.h"
0019 #include "DataFormats/Common/interface/HLTPathStatus.h"
0020 
0021 #include <string>
0022 #include <ostream>
0023 #include <vector>
0024 
0025 namespace edm {
0026 
0027   class HLTGlobalStatus {
0028   private:
0029     /// Status of each HLT path
0030     std::vector<HLTPathStatus> paths_;
0031 
0032   public:
0033     /// Constructor - for n paths
0034     HLTGlobalStatus(const unsigned int n = 0) : paths_(n) {}
0035 
0036     /// Get number of paths stored
0037     unsigned int size() const { return paths_.size(); }
0038 
0039     /// Reset status for all paths
0040     void reset() {
0041       const unsigned int n(size());
0042       for (unsigned int i = 0; i != n; ++i)
0043         paths_[i].reset();
0044     }
0045 
0046     // global "state" variables calculated on the fly!
0047 
0048     /// Was at least one path run?
0049     bool wasrun() const { return State(0); }
0050     /// Has at least one path accepted the event?
0051     bool accept() const { return State(1); }
0052     /// Has any path encountered an error (exception)
0053     bool error() const { return State(2); }
0054 
0055     // accessors to ith element of paths_
0056 
0057     const HLTPathStatus& at(const unsigned int i) const { return paths_.at(i); }
0058     HLTPathStatus& at(const unsigned int i) { return paths_.at(i); }
0059     const HLTPathStatus& operator[](const unsigned int i) const { return paths_[i]; }
0060     HLTPathStatus& operator[](const unsigned int i) { return paths_[i]; }
0061 
0062     /// Was ith path run?
0063     bool wasrun(const unsigned int i) const { return at(i).wasrun(); }
0064     /// Has ith path accepted the event?
0065     bool accept(const unsigned int i) const { return at(i).accept(); }
0066     /// Has ith path encountered an error (exception)?
0067     bool error(const unsigned int i) const { return at(i).error(); }
0068 
0069     /// Get status of ith path
0070     hlt::HLTState state(const unsigned int i) const { return at(i).state(); }
0071     /// Get index (slot position) of module giving the decision of the ith path
0072     unsigned int index(const unsigned int i) const { return at(i).index(); }
0073     /// Reset the ith path
0074     void reset(const unsigned int i) { at(i).reset(); }
0075     /// swap function
0076     void swap(HLTGlobalStatus& other) { paths_.swap(other.paths_); }
0077 
0078   private:
0079     /// Global state variable calculated on the fly
0080     bool State(unsigned int icase) const {
0081       bool flags[3] = {false, false, false};
0082       const unsigned int n(size());
0083       for (unsigned int i = 0; i != n; ++i) {
0084         const hlt::HLTState s(state(i));
0085         if (s != hlt::Ready) {
0086           flags[0] = true;  // at least one trigger was run
0087           if (s == hlt::Pass) {
0088             flags[1] = true;  // at least one trigger accepted
0089           } else if (s == hlt::Exception) {
0090             flags[2] = true;  // at least one trigger with error
0091           }
0092         }
0093       }
0094       return flags[icase];
0095     }
0096   };
0097 
0098   /// Free swap function
0099   inline void swap(HLTGlobalStatus& lhs, HLTGlobalStatus& rhs) { lhs.swap(rhs); }
0100 
0101   /// Formatted printout of trigger table
0102   inline std::ostream& operator<<(std::ostream& ost, const HLTGlobalStatus& hlt) {
0103     std::vector<std::string> text(4);
0104     text[0] = "n";
0105     text[1] = "1";
0106     text[2] = "0";
0107     text[3] = "e";
0108     const unsigned int n(hlt.size());
0109     for (unsigned int i = 0; i != n; ++i)
0110       ost << text[hlt.state(i)];
0111     return ost;
0112   }
0113 
0114 }  // namespace edm
0115 
0116 #endif  // DataFormats_Common_HLTGlobalStatus_h