Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:59

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 <vector>
0022 #include <ostream>
0023 
0024 namespace edm {
0025   class HLTGlobalStatus {
0026   private:
0027     /// Status of each HLT path
0028     std::vector<HLTPathStatus> paths_;
0029 
0030   public:
0031     /// Constructor - for n paths
0032     HLTGlobalStatus(const unsigned int n = 0) : paths_(n) {}
0033 
0034     /// Get number of paths stored
0035     unsigned int size() const { return paths_.size(); }
0036 
0037     /// Reset status for all paths
0038     void reset() {
0039       const unsigned int n(size());
0040       for (unsigned int i = 0; i != n; ++i)
0041         paths_[i].reset();
0042     }
0043 
0044     // global "state" variables calculated on the fly!
0045 
0046     /// Was at least one path run?
0047     bool wasrun() const { return State(0); }
0048     /// Has at least one path accepted the event?
0049     bool accept() const { return State(1); }
0050     /// Has any path encountered an error (exception)
0051     bool error() const { return State(2); }
0052 
0053     // get hold of individual elements, using safe indexing with "at" which throws!
0054 
0055     const HLTPathStatus& at(const unsigned int i) const { return paths_.at(i); }
0056     HLTPathStatus& at(const unsigned int i) { return paths_.at(i); }
0057     const HLTPathStatus& operator[](const unsigned int i) const { return paths_.at(i); }
0058     HLTPathStatus& operator[](const unsigned int i) { return paths_.at(i); }
0059 
0060     /// Was ith path run?
0061     bool wasrun(const unsigned int i) const { return at(i).wasrun(); }
0062     /// Has ith path accepted the event?
0063     bool accept(const unsigned int i) const { return at(i).accept(); }
0064     /// Has ith path encountered an error (exception)?
0065     bool error(const unsigned int i) const { return at(i).error(); }
0066 
0067     /// Get status of ith path
0068     hlt::HLTState state(const unsigned int i) const { return at(i).state(); }
0069     /// Get index (slot position) of module giving the decision of the ith path
0070     unsigned int index(const unsigned int i) const { return at(i).index(); }
0071     /// Reset the ith path
0072     void reset(const unsigned int i) { at(i).reset(); }
0073     /// swap function
0074     void swap(HLTGlobalStatus& other) { paths_.swap(other.paths_); }
0075     /// copy assignment implemented with swap()
0076     HLTGlobalStatus& operator=(HLTGlobalStatus const& rhs) {
0077       HLTGlobalStatus temp(rhs);
0078       this->swap(temp);
0079       return *this;
0080     }
0081 
0082   private:
0083     /// Global state variable calculated on the fly
0084     bool State(unsigned int icase) const {
0085       bool flags[3] = {false, false, false};
0086       const unsigned int n(size());
0087       for (unsigned int i = 0; i != n; ++i) {
0088         const hlt::HLTState s(state(i));
0089         if (s != hlt::Ready) {
0090           flags[0] = true;  // at least one trigger was run
0091           if (s == hlt::Pass) {
0092             flags[1] = true;  // at least one trigger accepted
0093           } else if (s == hlt::Exception) {
0094             flags[2] = true;  // at least one trigger with error
0095           }
0096         }
0097       }
0098       return flags[icase];
0099     }
0100   };
0101 
0102   /// Free swap function
0103   inline void swap(HLTGlobalStatus& lhs, HLTGlobalStatus& rhs) { lhs.swap(rhs); }
0104 
0105   /// Formatted printout of trigger tbale
0106   inline std::ostream& operator<<(std::ostream& ost, const HLTGlobalStatus& hlt) {
0107     std::vector<std::string> text(4);
0108     text[0] = "n";
0109     text[1] = "1";
0110     text[2] = "0";
0111     text[3] = "e";
0112     const unsigned int n(hlt.size());
0113     for (unsigned int i = 0; i != n; ++i)
0114       ost << text.at(hlt.state(i));
0115     return ost;
0116   }
0117 
0118 }  // namespace edm
0119 
0120 // The standard allows us to specialize std::swap for non-templates.
0121 // This ensures that HLTGlobalStatus::swap() will be used in algorithms.
0122 
0123 namespace std {
0124   template <>
0125   inline void swap(edm::HLTGlobalStatus& lhs, edm::HLTGlobalStatus& rhs) {
0126     lhs.swap(rhs);
0127   }
0128 }  // namespace std
0129 
0130 #endif  // DataFormats_Common_HLTGlobalStatus_h