CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQM/TrigXMonitorClient/interface/HLTScalersClient.h

Go to the documentation of this file.
00001 // -*-c++-*-
00002 // 
00003 // Client class for HLT Scalers module.
00004 // 
00005 // $Id: HLTScalersClient.h,v 1.14 2010/04/02 20:48:11 wittich Exp $
00006 
00007 // $Log: HLTScalersClient.h,v $
00008 // Revision 1.14  2010/04/02 20:48:11  wittich
00009 // updates to scale entries by received number of FU's
00010 //
00011 // Revision 1.13  2010/03/17 20:56:18  wittich
00012 // Check for good updates based on mergeCount values
00013 // add code for rates normalized per FU
00014 //
00015 // Revision 1.12  2010/03/16 22:19:19  wittich
00016 // updates for per-LS normalization for variable
00017 // number of FU's sending information back to the clients.
00018 //
00019 // Revision 1.11  2010/02/15 17:10:45  wittich
00020 // Allow for longer length runs (2400 ls)
00021 // this is only in the client
00022 //
00023 // Revision 1.10  2010/02/11 23:55:18  wittich
00024 // - adapt to shorter Lumi Section length
00025 // - fix bug in how history of counts was filled
00026 //
00027 // Revision 1.9  2010/02/11 00:11:09  wmtan
00028 // Adapt to moved framework header
00029 //
00030 // Revision 1.8  2010/02/02 11:44:20  wittich
00031 // more diagnostics for online scalers
00032 //
00033 // Revision 1.7  2009/12/15 20:41:16  wittich
00034 // better hlt scalers client
00035 //
00036 // Revision 1.6  2009/11/22 14:17:46  puigh
00037 // fix compilation warning
00038 //
00039 // Revision 1.5  2009/11/22 13:32:38  puigh
00040 // clean beginJob
00041 //
00042 
00043 #ifndef HLTSCALERSCLIENT_H
00044 #define HLTSCALERSCLIENT_H
00045 #include <fstream>
00046 #include <vector>
00047 #include <deque>
00048 #include <utility> 
00049 
00050 #include "FWCore/Framework/interface/Frameworkfwd.h"
00051 #include "FWCore/Framework/interface/EDAnalyzer.h"
00052 
00053 #include "DQMServices/Core/interface/DQMStore.h"
00054 
00055 #include "DQMServices/Core/interface/MonitorElement.h"
00056 #include "FWCore/Utilities/interface/InputTag.h"
00057 //#include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00058 
00059 #define MAX_PATHS 200
00060 #define MAX_LUMI_SEG_HLT 2400
00061 
00062 class HLTScalersClient: public edm::EDAnalyzer
00063 {
00064 private:
00065   std::ofstream textfile_;
00066 
00067 public:
00068 //   typedef std::pair<int,double> CountLS_t;
00069 //   //typedef std::deque<CountLS_t> CountLSFifo_t;
00070 //   typedef std::map<int,double> CountLSFifo_t;
00071 
00072   // helper data structures - slightly modified stl objects
00073   class CountLS_t: public std::pair<int,double>
00074   {
00075   public:
00076     CountLS_t(int ls, double cnt):
00077       std::pair<int,double>(ls,cnt)
00078     {};
00079     bool operator==(int ls) const
00080     {
00081       return ls == this->first;
00082     }
00083     bool operator<(CountLS_t & rhs ) 
00084     {
00085       return  this->first< rhs.first;
00086     };
00087 
00088   };
00089 
00090   class CountLSFifo_t: public std::deque<CountLS_t> 
00091   {
00092   private:
00093     unsigned int targetSize_;
00094     bool accumulate_;
00095   public:
00096     // default constructor
00097     CountLSFifo_t(unsigned int sz = 3) :
00098       std::deque<CountLS_t>(),
00099       targetSize_(sz)
00100     {}
00101     unsigned int targetSize() { return targetSize_; };
00102     double getCount(int ls)
00103     {
00104       CountLSFifo_t::iterator p = std::find(this->begin(), this->end(),
00105                                             ls);
00106       if ( p != end() ) 
00107         return p->second;
00108       else
00109         return -1;
00110     }
00111 
00112 
00113     void update( const CountLS_t & T)
00114     {
00115       // do we already have data for this LS?
00116       CountLSFifo_t::iterator p = std::find(this->begin(), this->end(),
00117                                             T.first);
00118       if ( p != this->end() ) { // we already have data for this LS
00119         p->second = T.second; 
00120       }
00121       else { // new data
00122         this->push_back(T);
00123       }
00124       trim_();
00125     }
00126   private:
00127     void trim_()
00128     {
00129       if ( this->size() > targetSize_ ) {
00130         std::sort(begin(), end());
00131         while ( size() > targetSize_ ) {
00132           pop_front();
00133         }
00134       }
00135     }
00136   };
00137 
00138   
00139 public:
00141   HLTScalersClient(const edm::ParameterSet& ps);
00142   
00144   virtual ~HLTScalersClient() {
00145     if ( debug_ ) {
00146       textfile_.close();
00147     }
00148   };
00149   
00151   void beginJob(void);
00152 
00153   
00155   void beginRun(const edm::Run& run, const edm::EventSetup& c);
00156 
00158   void endRun(const edm::Run& run, const edm::EventSetup& c);
00159 
00160   
00163   void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, 
00164                           const edm::EventSetup& c);
00165 
00166   // unused
00167   void analyze(const edm::Event& e, const edm::EventSetup& c) ;
00168 
00169 
00170 private:
00171   DQMStore * dbe_;
00172 
00173   int nev_; // Number of events processed
00174   int nLumi_; // number of lumi blocks
00175   int currentRun_;
00176 
00177   MonitorElement *currentRate_;
00178   int currentLumiBlockNumber_;
00179   std::vector<MonitorElement*> rateHistories_; 
00180   std::vector<MonitorElement*> countHistories_; 
00181 
00182   std::vector<MonitorElement*> hltCurrentRate_;
00183   MonitorElement *hltRate_; // global rate - any accept
00184   MonitorElement *hltCount_; // globalCounts
00185   //  MonitorElement *hltCountN_; // globalCounts normalized
00186   MonitorElement *updates_;
00187   MonitorElement *mergeCount_;
00188 
00189   // Normalized
00190   MonitorElement *hltNormRate_; // global rate - any accept
00191   MonitorElement *currentNormRate_;
00192   std::vector<MonitorElement*> rateNormHistories_; 
00193   std::vector<MonitorElement*> hltCurrentNormRate_;
00194   
00195   bool first_, missingPathNames_;
00196   std::string folderName_;
00197   unsigned int kRateIntegWindow_;
00198   std::string processName_;
00199   //HLTConfigProvider hltConfig_;
00200   std::deque<int> ignores_;
00201   std::pair<double,double> getSlope_(CountLSFifo_t points);
00202 private:
00203   bool debug_;
00204   int maxFU_;
00205   std::vector<CountLSFifo_t> recentPathCountsPerLS_;
00206   CountLSFifo_t recentOverallCountsPerLS_;
00207 
00208   std::vector<CountLSFifo_t> recentNormedPathCountsPerLS_;
00209   CountLSFifo_t recentNormedOverallCountsPerLS_;
00210 
00211 
00212 };
00213 
00214 
00215 #endif // HLTSCALERSCLIENT_H