Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:57:28

0001 // -*-c++-*-
0002 //
0003 // Client class for HLT Scalers module.
0004 //
0005 
0006 // Revision 1.13  2010/03/17 20:56:18  wittich
0007 // Check for good updates based on mergeCount values
0008 // add code for rates normalized per FU
0009 //
0010 // Revision 1.12  2010/03/16 22:19:19  wittich
0011 // updates for per-LS normalization for variable
0012 // number of FU's sending information back to the clients.
0013 //
0014 // Revision 1.11  2010/02/15 17:10:45  wittich
0015 // Allow for longer length runs (2400 ls)
0016 // this is only in the client
0017 //
0018 // Revision 1.10  2010/02/11 23:55:18  wittich
0019 // - adapt to shorter Lumi Section length
0020 // - fix bug in how history of counts was filled
0021 //
0022 // Revision 1.9  2010/02/11 00:11:09  wmtan
0023 // Adapt to moved framework header
0024 //
0025 // Revision 1.8  2010/02/02 11:44:20  wittich
0026 // more diagnostics for online scalers
0027 //
0028 // Revision 1.7  2009/12/15 20:41:16  wittich
0029 // better hlt scalers client
0030 //
0031 // Revision 1.6  2009/11/22 14:17:46  puigh
0032 // fix compilation warning
0033 //
0034 // Revision 1.5  2009/11/22 13:32:38  puigh
0035 // clean beginJob
0036 //
0037 
0038 #ifndef HLTSCALERSCLIENT_H
0039 #define HLTSCALERSCLIENT_H
0040 #include <deque>
0041 #include <fstream>
0042 #include <utility>
0043 #include <vector>
0044 
0045 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0046 #include "FWCore/Framework/interface/Frameworkfwd.h"
0047 
0048 #include "DQMServices/Core/interface/DQMStore.h"
0049 
0050 #include "FWCore/Utilities/interface/InputTag.h"
0051 //#include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0052 
0053 #define MAX_PATHS 200
0054 #define MAX_LUMI_SEG_HLT 2400
0055 
0056 class HLTScalersClient
0057     : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
0058 private:
0059   std::ofstream textfile_;
0060 
0061 public:
0062   typedef dqm::legacy::MonitorElement MonitorElement;
0063   typedef dqm::legacy::DQMStore DQMStore;
0064   //   typedef std::pair<int,double> CountLS_t;
0065   //   //typedef std::deque<CountLS_t> CountLSFifo_t;
0066   //   typedef std::map<int,double> CountLSFifo_t;
0067 
0068   // helper data structures - slightly modified stl objects
0069   class CountLS_t : public std::pair<int, double> {
0070   public:
0071     CountLS_t(int ls, double cnt) : std::pair<int, double>(ls, cnt){};
0072     bool operator==(int ls) const { return ls == this->first; }
0073     bool operator<(CountLS_t &rhs) { return this->first < rhs.first; };
0074   };
0075 
0076   class CountLSFifo_t : public std::deque<CountLS_t> {
0077   private:
0078     unsigned int targetSize_;
0079     bool accumulate_;
0080 
0081   public:
0082     // default constructor
0083     CountLSFifo_t(unsigned int sz = 3) : std::deque<CountLS_t>(), targetSize_(sz) {}
0084     unsigned int targetSize() const { return targetSize_; };
0085     double getCount(int ls) {
0086       CountLSFifo_t::iterator p = std::find(this->begin(), this->end(), ls);
0087       if (p != end())
0088         return p->second;
0089       else
0090         return -1;
0091     }
0092 
0093     void update(const CountLS_t &T) {
0094       // do we already have data for this LS?
0095       CountLSFifo_t::iterator p = std::find(this->begin(), this->end(), T.first);
0096       if (p != this->end()) {  // we already have data for this LS
0097         p->second = T.second;
0098       } else {  // new data
0099         this->push_back(T);
0100       }
0101       trim_();
0102     }
0103 
0104   private:
0105     void trim_() {
0106       if (this->size() > targetSize_) {
0107         std::sort(begin(), end());
0108         while (size() > targetSize_) {
0109           pop_front();
0110         }
0111       }
0112     }
0113   };
0114 
0115 public:
0116   /// Constructors
0117   HLTScalersClient(const edm::ParameterSet &ps);
0118 
0119   /// Destructor
0120   ~HLTScalersClient() override {
0121     if (debug_) {
0122       textfile_.close();
0123     }
0124   };
0125 
0126   /// BeginJob
0127   void beginJob(void) override;
0128 
0129   /// BeginRun
0130   void beginRun(const edm::Run &run, const edm::EventSetup &c) override;
0131 
0132   /// EndRun
0133   void endRun(const edm::Run &run, const edm::EventSetup &c) override;
0134 
0135   /// End LumiBlock
0136   /// DQM Client Diagnostic should be performed here
0137   void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override {}
0138   void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override;
0139 
0140   // unused
0141   void analyze(const edm::Event &e, const edm::EventSetup &c) override;
0142 
0143 private:
0144   DQMStore *dbe_;
0145 
0146   int nev_;    // Number of events processed
0147   int nLumi_;  // number of lumi blocks
0148   int currentRun_;
0149 
0150   MonitorElement *currentRate_;
0151   int currentLumiBlockNumber_;
0152   std::vector<MonitorElement *> rateHistories_;
0153   std::vector<MonitorElement *> countHistories_;
0154 
0155   std::vector<MonitorElement *> hltCurrentRate_;
0156   MonitorElement *hltRate_;   // global rate - any accept
0157   MonitorElement *hltCount_;  // globalCounts
0158   //  MonitorElement *hltCountN_; // globalCounts normalized
0159   MonitorElement *updates_;
0160   MonitorElement *mergeCount_;
0161 
0162   // Normalized
0163   MonitorElement *hltNormRate_;  // global rate - any accept
0164   MonitorElement *currentNormRate_;
0165   std::vector<MonitorElement *> rateNormHistories_;
0166   std::vector<MonitorElement *> hltCurrentNormRate_;
0167 
0168   bool first_, missingPathNames_;
0169   std::string folderName_;
0170   unsigned int kRateIntegWindow_;
0171   std::string processName_;
0172   // HLTConfigProvider hltConfig_;
0173   std::deque<int> ignores_;
0174   std::pair<double, double> getSlope_(const CountLSFifo_t &points);
0175 
0176 private:
0177   bool debug_;
0178   int maxFU_;
0179   std::vector<CountLSFifo_t> recentPathCountsPerLS_;
0180   CountLSFifo_t recentOverallCountsPerLS_;
0181 
0182   std::vector<CountLSFifo_t> recentNormedPathCountsPerLS_;
0183   CountLSFifo_t recentNormedOverallCountsPerLS_;
0184 };
0185 
0186 #endif  // HLTSCALERSCLIENT_H