00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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;
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
00068 dbe_ = edm::Service<DQMStore>().operator->();
00069 assert(dbe_ != 0);
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;
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
00086 char metitle[40];
00087 char mename[40];
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;
00137 LogDebug("Status") << "I see " << npaths << " paths. ";
00138
00139
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
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_ ) {
00181 LogInfo("Status") << "divide by zero: same lumi section 2x " << nL;
00182 return;
00183 }
00184
00185 for ( int i = 1; i <= npaths; ++i ) {
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
00194 scalerCounters_[i-1] = ulong(current_count);
00195 rateHistories_[i-1]->setBinContent(nL, rate);
00196 }
00197 currentLumiBlockNumber_ = nL;
00198
00199 }
00200
00201
00202 void HLTScalersClient::analyze(const edm::Event& e, const edm::EventSetup& c)
00203 {
00204 }