00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <memory>
00011 #include <iostream>
00012 #include <fstream>
00013 #include <iomanip>
00014
00015 #include "TCanvas.h"
00016 #include "TStyle.h"
00017 #include "TGraph.h"
00018 #include "TLine.h"
00019
00020 #include "DQMServices/Core/interface/DQMStore.h"
00021
00022 #include "DQM/EcalCommon/interface/UtilsClient.h"
00023 #include "DQM/EcalCommon/interface/Numbers.h"
00024
00025 #include <DQM/EcalEndcapMonitorClient/interface/EEStatusFlagsClient.h>
00026
00027 using namespace cms;
00028 using namespace edm;
00029 using namespace std;
00030
00031 EEStatusFlagsClient::EEStatusFlagsClient(const ParameterSet& ps) {
00032
00033
00034 cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00035
00036
00037 verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00038
00039
00040 debug_ = ps.getUntrackedParameter<bool>("debug", false);
00041
00042
00043 prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
00044
00045
00046 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00047
00048
00049 superModules_.reserve(18);
00050 for ( unsigned int i = 1; i <= 18; i++ ) superModules_.push_back(i);
00051 superModules_ = ps.getUntrackedParameter<vector<int> >("superModules", superModules_);
00052
00053 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00054
00055 int ism = superModules_[i];
00056
00057 h01_[ism-1] = 0;
00058
00059 meh01_[ism-1] = 0;
00060
00061 h02_[ism-1] = 0;
00062
00063 meh02_[ism-1] = 0;
00064
00065 }
00066
00067 }
00068
00069 EEStatusFlagsClient::~EEStatusFlagsClient() {
00070
00071 }
00072
00073 void EEStatusFlagsClient::beginJob(DQMStore* dqmStore) {
00074
00075 dqmStore_ = dqmStore;
00076
00077 if ( debug_ ) cout << "EEStatusFlagsClient: beginJob" << endl;
00078
00079 ievt_ = 0;
00080 jevt_ = 0;
00081
00082 }
00083
00084 void EEStatusFlagsClient::beginRun(void) {
00085
00086 if ( debug_ ) cout << "EEStatusFlagsClient: beginRun" << endl;
00087
00088 jevt_ = 0;
00089
00090 this->setup();
00091
00092 }
00093
00094 void EEStatusFlagsClient::endJob(void) {
00095
00096 if ( debug_ ) cout << "EEStatusFlagsClient: endJob, ievt = " << ievt_ << endl;
00097
00098 this->cleanup();
00099
00100 }
00101
00102 void EEStatusFlagsClient::endRun(void) {
00103
00104 if ( debug_ ) cout << "EEStatusFlagsClient: endRun, jevt = " << jevt_ << endl;
00105
00106 this->cleanup();
00107
00108 }
00109
00110 void EEStatusFlagsClient::setup(void) {
00111
00112 dqmStore_->setCurrentFolder( prefixME_ + "/EEStatusFlagsClient" );
00113
00114 }
00115
00116 void EEStatusFlagsClient::cleanup(void) {
00117
00118 if ( ! enableCleanup_ ) return;
00119
00120 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00121
00122 int ism = superModules_[i];
00123
00124 if ( cloneME_ ) {
00125 if ( h01_[ism-1] ) delete h01_[ism-1];
00126 if ( h02_[ism-1] ) delete h02_[ism-1];
00127 }
00128
00129 h01_[ism-1] = 0;
00130 h02_[ism-1] = 0;
00131
00132 meh01_[ism-1] = 0;
00133 meh02_[ism-1] = 0;
00134
00135 }
00136
00137 dqmStore_->setCurrentFolder( prefixME_ + "/EEStatusFlagsClient" );
00138
00139 }
00140
00141 bool EEStatusFlagsClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status, bool flag) {
00142
00143 status = true;
00144
00145 if ( ! flag ) return false;
00146
00147 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00148
00149 int ism = superModules_[i];
00150
00151 if ( verbose_ ) {
00152 cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << endl;
00153 cout << endl;
00154 UtilsClient::printBadChannels(meh01_[ism-1], UtilsClient::getHisto<TH2F*>(meh01_[ism-1]), true);
00155 }
00156
00157 if ( meh01_[ism-1] ) {
00158 if ( meh01_[ism-1]->getEntries() != 0 ) status = false;
00159 }
00160
00161 }
00162
00163 return true;
00164
00165 }
00166
00167 void EEStatusFlagsClient::analyze(void) {
00168
00169 ievt_++;
00170 jevt_++;
00171 if ( ievt_ % 10 == 0 ) {
00172 if ( debug_ ) cout << "EEStatusFlagsClient: ievt/jevt = " << ievt_ << "/" << jevt_ << endl;
00173 }
00174
00175 char histo[200];
00176
00177 MonitorElement* me;
00178
00179 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00180
00181 int ism = superModules_[i];
00182
00183 sprintf(histo, (prefixME_ + "/EEStatusFlagsTask/FEStatus/EESFT front-end status %s").c_str(), Numbers::sEE(ism).c_str());
00184 me = dqmStore_->get(histo);
00185 h01_[ism-1] = UtilsClient::getHisto<TH2F*>( me, cloneME_, h01_[ism-1] );
00186 meh01_[ism-1] = me;
00187
00188 sprintf(histo, (prefixME_ + "/EEStatusFlagsTask/FEStatus/EESFT front-end status bits %s").c_str(), Numbers::sEE(ism).c_str());
00189 me = dqmStore_->get(histo);
00190 h02_[ism-1] = UtilsClient::getHisto<TH1F*>( me, cloneME_, h02_[ism-1] );
00191 meh02_[ism-1] = me;
00192
00193 }
00194
00195 }
00196
00197 void EEStatusFlagsClient::softReset(bool flag) {
00198
00199 }
00200
00201 void EEStatusFlagsClient::htmlOutput(int run, string& htmlDir, string& htmlName) {
00202
00203 if ( verbose_ ) cout << "Preparing EEStatusFlagsClient html output ..." << endl;
00204
00205 ofstream htmlFile;
00206
00207 htmlFile.open((htmlDir + htmlName).c_str());
00208
00209
00210 htmlFile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"> " << endl;
00211 htmlFile << "<html> " << endl;
00212 htmlFile << "<head> " << endl;
00213 htmlFile << " <meta content=\"text/html; charset=ISO-8859-1\" " << endl;
00214 htmlFile << " https-equiv=\"content-type\"> " << endl;
00215 htmlFile << " <title>Monitor:StatusFlagsTask output</title> " << endl;
00216 htmlFile << "</head> " << endl;
00217 htmlFile << "<style type=\"text/css\"> td { font-weight: bold } </style>" << endl;
00218 htmlFile << "<body> " << endl;
00219
00220 htmlFile << "<a name=""top""></a>" << endl;
00221 htmlFile << "<h2>Run: " << endl;
00222 htmlFile << " <span " << endl;
00223 htmlFile << " style=\"color: rgb(0, 0, 153);\">" << run << "</span></h2>" << endl;
00224 htmlFile << "<h2>Monitoring task: <span " << endl;
00225 htmlFile << " style=\"color: rgb(0, 0, 153);\">DATA FLAGS</span></h2> " << endl;
00226 htmlFile << "<hr>" << endl;
00227 htmlFile << "<table border=1><tr><td bgcolor=red>channel has problems in this task</td>" << endl;
00228 htmlFile << "<td bgcolor=lime>channel has NO problems</td>" << endl;
00229 htmlFile << "<td bgcolor=yellow>channel is missing</td></table>" << endl;
00230 htmlFile << "<br>" << endl;
00231 htmlFile << "<table border=1>" << std::endl;
00232 for ( unsigned int i=0; i<superModules_.size(); i ++ ) {
00233 htmlFile << "<td bgcolor=white><a href=""#"
00234 << Numbers::sEE(superModules_[i]) << ">"
00235 << setfill( '0' ) << setw(2) << superModules_[i] << "</a></td>";
00236 }
00237 htmlFile << std::endl << "</table>" << std::endl;
00238
00239
00240
00241 const int csize = 250;
00242
00243 const double histMax = 1.e15;
00244
00245 int pCol5[10];
00246 for ( int i = 0; i < 10; i++ ) pCol5[i] = 501+i;
00247
00248 TH2S labelGrid("labelGrid","label grid", 100, -2., 98., 100, -2., 98.);
00249 for ( short j=0; j<400; j++ ) {
00250 int x = 5*(1 + j%20);
00251 int y = 5*(1 + j/20);
00252 labelGrid.SetBinContent(x, y, Numbers::inTowersEE[j]);
00253 }
00254 labelGrid.SetMarkerSize(1);
00255 labelGrid.SetMinimum(0.1);
00256
00257 string imgNameQual, imgNameBits, imgName, meName;
00258
00259 TCanvas* cStatus = new TCanvas("cStatus", "Temp", 2*csize, 2*csize);
00260 TCanvas* cStatusBits = new TCanvas("cStatusBits", "Temp", 3*csize, csize);
00261
00262 TH2F* obj2f;
00263 TH1F* obj1f;
00264
00265
00266
00267 for ( unsigned int i=0; i<superModules_.size(); i ++ ) {
00268
00269 int ism = superModules_[i];
00270
00271
00272
00273 imgNameQual = "";
00274
00275 obj2f = h01_[ism-1];
00276
00277 if ( obj2f ) {
00278
00279 meName = obj2f->GetName();
00280
00281 replace(meName.begin(), meName.end(), ' ', '_');
00282 imgNameQual = meName + ".png";
00283 imgName = htmlDir + imgNameQual;
00284
00285 cStatus->cd();
00286 gStyle->SetOptStat(" ");
00287 gStyle->SetPalette(10, pCol5);
00288 cStatus->SetGridx();
00289 cStatus->SetGridy();
00290 obj2f->GetXaxis()->SetLabelSize(0.02);
00291 obj2f->GetXaxis()->SetTitleSize(0.02);
00292 obj2f->GetYaxis()->SetLabelSize(0.02);
00293 obj2f->GetYaxis()->SetTitleSize(0.02);
00294 obj2f->GetZaxis()->SetLabelSize(0.02);
00295 obj2f->SetMinimum(0.0);
00296 obj2f->Draw("colz");
00297 int x1 = labelGrid.GetXaxis()->FindFixBin(Numbers::ix0EE(ism)+0.);
00298 int x2 = labelGrid.GetXaxis()->FindFixBin(Numbers::ix0EE(ism)+50.);
00299 int y1 = labelGrid.GetYaxis()->FindFixBin(Numbers::iy0EE(ism)+0.);
00300 int y2 = labelGrid.GetYaxis()->FindFixBin(Numbers::iy0EE(ism)+50.);
00301 labelGrid.GetXaxis()->SetRange(x1, x2);
00302 labelGrid.GetYaxis()->SetRange(y1, y2);
00303 labelGrid.Draw("text,same");
00304 cStatus->SetBit(TGraph::kClipFrame);
00305 TLine l;
00306 l.SetLineWidth(1);
00307 for ( int i=0; i<201; i=i+1) {
00308 if ( (Numbers::ixSectorsEE[i]!=0 || Numbers::iySectorsEE[i]!=0) && (Numbers::ixSectorsEE[i+1]!=0 || Numbers::iySectorsEE[i+1]!=0) ) {
00309 l.DrawLine(Numbers::ixSectorsEE[i], Numbers::iySectorsEE[i], Numbers::ixSectorsEE[i+1], Numbers::iySectorsEE[i+1]);
00310 }
00311 }
00312 cStatus->Update();
00313 cStatus->SaveAs(imgName.c_str());
00314
00315 }
00316
00317 imgNameBits = "";
00318
00319 obj1f = h02_[ism-1];
00320
00321 if ( obj1f ) {
00322
00323 meName = obj1f->GetName();
00324
00325 replace(meName.begin(), meName.end(), ' ', '_');
00326 imgNameBits = meName + ".png";
00327 imgName = htmlDir + imgNameBits;
00328
00329 cStatusBits->cd();
00330 gStyle->SetOptStat("e");
00331 obj1f->SetStats(kTRUE);
00332 if ( obj1f->GetMaximum(histMax) > 0. ) {
00333 gPad->SetLogy(kTRUE);
00334 } else {
00335 gPad->SetLogy(kFALSE);
00336 }
00337 gPad->SetBottomMargin(0.25);
00338 obj1f->GetXaxis()->LabelsOption("v");
00339 obj1f->GetXaxis()->SetLabelSize(0.05);
00340 obj1f->Draw();
00341 cStatusBits->Update();
00342 cStatusBits->SaveAs(imgName.c_str());
00343 gPad->SetLogy(kFALSE);
00344
00345 }
00346
00347 if( i>0 ) htmlFile << "<a href=""#top"">Top</a>" << std::endl;
00348 htmlFile << "<hr>" << std::endl;
00349 htmlFile << "<h3><a name="""
00350 << Numbers::sEE(ism) << """></a><strong>"
00351 << Numbers::sEE(ism) << "</strong></h3>" << endl;
00352 htmlFile << "<table border=\"0\" cellspacing=\"0\" " << endl;
00353 htmlFile << "cellpadding=\"10\" align=\"center\"> " << endl;
00354 htmlFile << "<tr align=\"center\">" << endl;
00355
00356 if ( imgNameQual.size() != 0 )
00357 htmlFile << "<td colspan=\"2\"><img src=\"" << imgNameQual << "\"></td>" << endl;
00358 else
00359 htmlFile << "<td colspan=\"2\"><img src=\"" << " " << "\"></td>" << endl;
00360
00361 htmlFile << "</tr>" << endl;
00362 htmlFile << "<tr>" << endl;
00363
00364 if ( imgNameBits.size() != 0 )
00365 htmlFile << "<td colspan=\"2\"><img src=\"" << imgNameBits << "\"></td>" << endl;
00366 else
00367 htmlFile << "<td colspan=\"2\"><img src=\"" << " " << "\"></td>" << endl;
00368
00369 htmlFile << "</tr>" << endl;
00370
00371 htmlFile << "</table>" << endl;
00372 htmlFile << "<br>" << endl;
00373
00374 }
00375
00376 delete cStatus;
00377 delete cStatusBits;
00378
00379
00380 htmlFile << "</body> " << endl;
00381 htmlFile << "</html> " << endl;
00382
00383 htmlFile.close();
00384
00385 }
00386