CMS 3D CMS Logo

HLTScalersClient.cc

Go to the documentation of this file.
00001 // $Id: HLTScalersClient.cc,v 1.8 2008/09/07 12:16:23 wittich Exp $
00002 // 
00003 // $Log: HLTScalersClient.cc,v $
00004 // Revision 1.8  2008/09/07 12:16:23  wittich
00005 // protect against divide-by-zero in rate calculation
00006 //
00007 // Revision 1.7  2008/09/04 11:06:02  lorenzo
00008 // changed to _EvF folder
00009 //
00010 // Revision 1.6  2008/09/03 02:13:48  wittich
00011 // - bug fix in L1Scalers
00012 // - configurable dqm directory in L1SCalers
00013 // - other minor tweaks in HLTScalers
00014 //
00015 // Revision 1.5  2008/08/28 22:22:13  wittich
00016 // - make delta_t absolute value
00017 // - add some more LogDebug statements
00018 // tested in full chain on .cms network
00019 //
00020 // Revision 1.4  2008/08/26 01:38:55  wittich
00021 // re-add Don's 20 entry histograms with full bin labels
00022 //
00023 // Revision 1.3  2008/08/25 00:38:27  wittich
00024 // Remove defunct couts
00025 //
00026 // Revision 1.2  2008/08/24 16:34:56  wittich
00027 // - rate calculation cleanups
00028 // - fix error logging with LogDebug
00029 // - report the actual lumi segment number that we think it might be
00030 //
00031 // Revision 1.1  2008/08/22 20:56:57  wittich
00032 // - add client for HLT Scalers
00033 // - Move rate calculation to HLTScalersClient and slim down the
00034 //   filter-farm part of HLTScalers
00035 //
00036 
00037 #include <cassert>
00038 
00039 #include "DQM/TrigXMonitorClient/interface/HLTScalersClient.h"
00040 
00041 #include "FWCore/ServiceRegistry/interface/Service.h"
00042 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00043 #include "FWCore/Framework/interface/LuminosityBlock.h"
00044 
00045 
00046 #include "DQMServices/Core/interface/DQMStore.h"
00047 #include "DQMServices/Core/interface/MonitorElement.h"
00048 
00049 
00050 using edm::LogInfo;
00051 using edm::LogWarning;
00052 
00053 #define SECS_PER_LUMI_SECTION 93.3
00054 const int kPerHisto = 20;
00055 const int kNumHistos = MAX_PATHS/kPerHisto; // this hasta be w/o remainders
00056 
00057 
00059 HLTScalersClient::HLTScalersClient(const edm::ParameterSet& ps):
00060   dbe_(0),
00061   nLumi_(0),
00062   currentRate_(0),
00063   currentLumiBlockNumber_(0),
00064   first_(true)
00065 {
00066   LogDebug("Status") << "constructor" ;
00067   // get back-end interface
00068   dbe_ = edm::Service<DQMStore>().operator->();
00069   assert(dbe_ != 0); // blammo!
00070   dbe_->setCurrentFolder("HLT/HLTScalers_EvF");
00071 
00072   currentRate_ = dbe_->book1D("cur_rate", 
00073                               "current lumi section rate per path",
00074                               MAX_PATHS, -0.5, MAX_PATHS-0.5);
00075 
00076   for (int i = 0; i < MAX_PATHS; ++i ) {
00077     scalerCounters_[i] = 0UL;
00078     rateHistories_[i] = 0; // not really needed but ...
00079     char name[256]; snprintf(name, 256, "rate_p%03d", i);
00080     LogDebug("Parameter") << "name " << i << " is " << name ;
00081     rateHistories_[i] = dbe_->book1D(name, name, MAX_LUMI_SEG, 
00082                                      -0.5, MAX_LUMI_SEG-0.5);
00083   }
00084 
00085   // split hlt scalers up into groups of 20, assuming total of 200 paths
00086   char metitle[40]; //histo name
00087   char mename[40]; //ME name
00088   for( int k = 0; k < kNumHistos; k++ ) {
00089     int npath_low = kPerHisto*k;
00090     int npath_high = kPerHisto*(k+1)-1;
00091     snprintf(mename, 40, "hltScalers_%0d", k);
00092     snprintf(metitle, 40, "HLT scalers - Paths %d to %d", npath_low, 
00093              npath_high);
00094     hltCurrentRate_[k]= dbe_->book1D(mename, metitle, kPerHisto, 
00095                                      -0.5 + npath_low, npath_high+0.5);
00096   }
00097 }
00098 
00099 
00101 void HLTScalersClient::beginJob(const edm::EventSetup& c)
00102 {
00103   LogDebug("Status") << "beingJob" ;
00104   if (dbe_) {
00105     dbe_->setCurrentFolder("HLT/HLTScalers_EvF");
00106   }
00107 }
00108 
00109 
00111 void HLTScalersClient::beginRun(const edm::Run& run, const edm::EventSetup& c)
00112 {
00113 }
00114 
00116 void HLTScalersClient::endRun(const edm::Run& run, const edm::EventSetup& c)
00117 {
00118 }
00119 
00120 
00123 void HLTScalersClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, 
00124                         const edm::EventSetup& c)
00125 {
00126   nLumi_ = lumiSeg.id().luminosityBlock();
00127 
00128   MonitorElement *scalers = dbe_->get("HLT/HLTScalers_EvF/hltScalers");
00129   if ( scalers == 0 ) {
00130     LogInfo("Status") << "cannot get hlt scalers histogram, bailing out.";
00131     return;
00132   }
00133 
00134 
00135   int npaths = scalers->getNbinsX();
00136   if ( npaths > MAX_PATHS ) npaths = MAX_PATHS; // HARD CODE FOR NOW
00137   LogDebug("Status") << "I see " << npaths << " paths. ";
00138 
00139   // set the bin labels on the first go-through
00140   if ( first_) {
00141     for ( int i = 0; i < npaths; ++i ) {
00142       int whichHisto = i/kPerHisto;
00143       int whichBin = i%kPerHisto + 1;
00144       char pname[256];
00145       snprintf(pname, 256, "HLT/HLTScalers_EvF/path%03d", i);
00146       MonitorElement *name = dbe_->get(pname);
00147       std::string sname;
00148       if ( name ) {
00149         sname = std::string (name->getStringValue());
00150       }
00151       else {
00152         sname = std::string("unknown");
00153       }
00154       hltCurrentRate_[whichHisto]->setBinLabel(whichBin, sname.c_str());
00155       snprintf(pname, 256, "Rate - path %s (Path # %03d)", sname.c_str(), i);
00156       rateHistories_[i]->setTitle(pname);
00157     }
00158     first_ = false;
00159   }
00160 
00161   MonitorElement *nLumi = dbe_->get("HLT/HLTScalers_EvF/nLumiBlock");
00162   int testval = (nLumi!=0?nLumi->getIntValue():-1);
00163   LogDebug("Parameter") << "Lumi Block from DQM: "
00164                         << testval
00165                         << ", local is " << nLumi_;
00166   int nL = (nLumi!=0?nLumi->getIntValue():nLumi_);
00167   if ( nL > MAX_LUMI_SEG ) {
00168     LogDebug("Status") << "Too many Lumi segments, "
00169                       << nL << " is greater than MAX_LUMI_SEG,"
00170                       << " wrapping to " 
00171                       << (nL%MAX_LUMI_SEG);
00172     //nL = MAX_LUMI_SEG;
00173     nL = nL%MAX_LUMI_SEG;
00174   }
00175   float delta_t = (nL - currentLumiBlockNumber_)*SECS_PER_LUMI_SECTION;
00176   if ( delta_t < 0 ) {
00177     LogDebug("Status") << " time is negative ... " << delta_t;
00178     delta_t = -delta_t;
00179   }
00180   else if ( nL == currentLumiBlockNumber_ ) { // divide-by-zero
00181     LogInfo("Status") << "divide by zero: same lumi section 2x " << nL;
00182     return;
00183   }
00184   // fill in the rates
00185   for ( int i = 1; i <= npaths; ++i ) { // bins start at 1
00186     float current_count = scalers->getBinContent(i);
00187     float rate = (current_count-scalerCounters_[i-1])/delta_t;
00188     if ( rate > 1E-3 ) {
00189       LogDebug("Parameter") << "rate path " << i << " is " << rate;
00190     }
00191     currentRate_->setBinContent(i, rate);
00192     hltCurrentRate_[i/kPerHisto]->setBinContent(i%kPerHisto+1, rate);
00193     //currentRate_->setBinError(i, error);
00194     scalerCounters_[i-1] = ulong(current_count);
00195     rateHistories_[i-1]->setBinContent(nL, rate);
00196   }
00197   currentLumiBlockNumber_ = nL;
00198 
00199 }
00200 
00201 // unused
00202 void HLTScalersClient::analyze(const edm::Event& e, const edm::EventSetup& c) 
00203 {
00204 }

Generated on Tue Jun 9 17:33:43 2009 for CMSSW by  doxygen 1.5.4