CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DQM/HcalMonitorClient/src/HcalMonitorClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file HcalMonitorClient.cc
00003  * 
00004  * $Date: 2013/01/21 12:53:19 $
00005  * $Revision: 1.105 $
00006  * \author J. Temple
00007  * 
00008  */
00009 
00010 #include "DQM/HcalMonitorClient/interface/HcalMonitorClient.h"
00011 #include "DQM/HcalMonitorClient/interface/HcalDeadCellClient.h"
00012 #include "DQM/HcalMonitorClient/interface/HcalHotCellClient.h"
00013 #include "DQM/HcalMonitorClient/interface/HcalRecHitClient.h"
00014 #include "DQM/HcalMonitorClient/interface/HcalRawDataClient.h"
00015 #include "DQM/HcalMonitorClient/interface/HcalDigiClient.h"
00016 #include "DQM/HcalMonitorClient/interface/HcalTrigPrimClient.h"
00017 #include "DQM/HcalMonitorClient/interface/HcalBeamClient.h"
00018 #include "DQM/HcalMonitorClient/interface/HcalNZSClient.h"
00019 #include "DQM/HcalMonitorClient/interface/HcalSummaryClient.h"
00020 #include "DQM/HcalMonitorClient/interface/HcalDetDiagPedestalClient.h"
00021 #include "DQM/HcalMonitorClient/interface/HcalDetDiagLaserClient.h"
00022 #include "DQM/HcalMonitorClient/interface/HcalDetDiagLEDClient.h"
00023 #include "DQM/HcalMonitorClient/interface/HcalDetDiagNoiseMonitorClient.h"
00024 #include "DQM/HcalMonitorClient/interface/HcalDetDiagTimingClient.h"
00025 #include "DQM/HcalMonitorClient/interface/HcalCoarsePedestalClient.h"
00026 #include "DQM/HcalMonitorClient/interface/ZDCMonitorClient.h"
00027 
00028 #include "FWCore/Framework/interface/Run.h"
00029 #include "FWCore/Framework/interface/LuminosityBlock.h"
00030 #include "FWCore/Framework/interface/Event.h"
00031 #include "FWCore/Framework/interface/MakerMacros.h"
00032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00033 #include "FWCore/ServiceRegistry/interface/Service.h"
00034 #include "FWCore/Framework/interface/ESHandle.h"
00035 
00036 #include "DQMServices/Core/interface/MonitorElement.h"
00037 #include "DQMServices/Core/interface/DQMStore.h"
00038 
00039 #include "CondFormats/HcalObjects/interface/HcalChannelStatus.h"
00040 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
00041 #include "CondFormats/HcalObjects/interface/HcalCondObjectContainer.h"
00042 #include "CondFormats/DataRecord/interface/HcalChannelQualityRcd.h"
00043 
00044 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
00045 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00046 
00047 #include <iostream>
00048 #include <iomanip>
00049 #include <fstream>
00050 
00051 #include "TROOT.h"
00052 #include "TH1.h"
00053 
00054 //'using' declarations should only be used within classes/functions, and 'using namespace std;' should not be used,
00055 // according to Bill Tanenbaum  (DQM development hypernews, 25 March 2010)
00056 
00057 HcalMonitorClient::HcalMonitorClient(const edm::ParameterSet& ps)
00058 {
00059   debug_ = ps.getUntrackedParameter<int>("debug",0);
00060   inputFile_ = ps.getUntrackedParameter<std::string>("inputFile","");
00061   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00062   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00063   prescaleFactor_ = ps.getUntrackedParameter<int>("prescaleFactor", -1);
00064   prefixME_ = ps.getUntrackedParameter<std::string>("subSystemFolder", "Hcal/");
00065   if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00066     prefixME_.append("/");
00067   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00068   enabledClients_ = ps.getUntrackedParameter<std::vector<std::string> >("enabledClients", enabledClients_);
00069 
00070   updateTime_ = ps.getUntrackedParameter<int>("UpdateTime",0);
00071   baseHtmlDir_ = ps.getUntrackedParameter<std::string>("baseHtmlDir", "");
00072   htmlUpdateTime_ = ps.getUntrackedParameter<int>("htmlUpdateTime", 0);
00073   htmlFirstUpdate_ = ps.getUntrackedParameter<int>("htmlFirstUpdate",20);
00074   databasedir_   = ps.getUntrackedParameter<std::string>("databaseDir","");
00075   databaseUpdateTime_ = ps.getUntrackedParameter<int>("databaseUpdateTime",0);
00076   databaseFirstUpdate_ = ps.getUntrackedParameter<int>("databaseFirstUpdate",10);
00077 
00078   saveByLumiSection_  = ps.getUntrackedParameter<bool>("saveByLumiSection",false);
00079   Online_                = ps.getUntrackedParameter<bool>("online",false);
00080 
00081 
00082   if (debug_>0)
00083     {
00084       std::cout <<"HcalMonitorClient:: The following clients are enabled:"<<std::endl;
00085       for (unsigned int i=0;i<enabledClients_.size();++i)
00086           std::cout <<enabledClients_[i]<<std::endl;
00087     } // if (debug_>0)
00088 
00089   // Set all EtaPhiHists pointers to 0 to start
00090   ChannelStatus=0; 
00091   ADC_PedestalFromDBByDepth=0;
00092   ADC_WidthFromDBByDepth=0;
00093   fC_PedestalFromDBByDepth=0;
00094   fC_WidthFromDBByDepth=0;
00095 
00096   // Add all relevant clients
00097   clients_.clear();
00098   clients_.reserve(14); // any reason to reserve ahead of time?
00099   summaryClient_=0;
00100 
00101   clients_.push_back(new HcalBaseDQClient((std::string)"HcalMonitorModule",ps));
00102   if (find(enabledClients_.begin(), enabledClients_.end(),"DeadCellMonitor")!=enabledClients_.end())
00103     clients_.push_back(new HcalDeadCellClient((std::string)"DeadCellMonitor",ps));
00104   if (find(enabledClients_.begin(), enabledClients_.end(),"HotCellMonitor")!=enabledClients_.end())
00105     clients_.push_back(new HcalHotCellClient((std::string)"HotCellMonitor",ps));
00106   if (find(enabledClients_.begin(), enabledClients_.end(),"RecHitMonitor")!=enabledClients_.end())
00107     clients_.push_back(new HcalRecHitClient((std::string)"RecHitMonitor",ps));
00108   if (find(enabledClients_.begin(), enabledClients_.end(),"DigiMonitor")!=enabledClients_.end())
00109     clients_.push_back(new HcalDigiClient((std::string)"DigiMonitor",ps));
00110   if (find(enabledClients_.begin(), enabledClients_.end(),"RawDataMonitor")!=enabledClients_.end())
00111     clients_.push_back(new HcalRawDataClient((std::string)"RawDataMonitor",ps));
00112   if (find(enabledClients_.begin(), enabledClients_.end(),"TrigPrimMonitor")!=enabledClients_.end())
00113     clients_.push_back(new HcalTrigPrimClient((std::string)"TrigPrimMonitor",ps));
00114   if (find(enabledClients_.begin(), enabledClients_.end(),"NZSMonitor")!=enabledClients_.end())
00115     clients_.push_back(new HcalNZSClient((std::string)"NZSMonitor",ps));
00116   if (find(enabledClients_.begin(), enabledClients_.end(),"BeamMonitor")!=enabledClients_.end())
00117     clients_.push_back(new HcalBeamClient((std::string)"BeamMonitor",ps));
00118   if (find(enabledClients_.begin(), enabledClients_.end(),"DetDiagPedestalMonitor")!=enabledClients_.end())
00119     clients_.push_back(new HcalDetDiagPedestalClient((std::string)"DetDiagPedestalMonitor",ps));
00120   if (find(enabledClients_.begin(), enabledClients_.end(),"DetDiagLaserMonitor")!=enabledClients_.end())
00121     clients_.push_back(new HcalDetDiagLaserClient((std::string)"DetDiagLaserMonitor",ps));
00122   if (find(enabledClients_.begin(), enabledClients_.end(),"DetDiagLEDMonitor")!=enabledClients_.end())
00123     clients_.push_back(new HcalDetDiagLEDClient((std::string)"DetDiagLEDMonitor",ps));
00124   if (find(enabledClients_.begin(), enabledClients_.end(),"DetDiagNoiseMonitor")!=enabledClients_.end())
00125     clients_.push_back(new HcalDetDiagNoiseMonitorClient((std::string)"DetDiagNoiseMonitor",ps));
00126   if (find(enabledClients_.begin(), enabledClients_.end(),"DetDiagTimingMonitor")!=enabledClients_.end())
00127     clients_.push_back(new HcalDetDiagTimingClient((std::string)"DetDiagTimingMonitor",ps));
00128  if (find(enabledClients_.begin(), enabledClients_.end(),"CoarsePedestalMonitor")!=enabledClients_.end())
00129     clients_.push_back(new HcalCoarsePedestalClient((std::string)"CoarsePedestalMonitor",ps));
00130  if (find(enabledClients_.begin(), enabledClients_.end(),"ZDCMonitor")!=enabledClients_.end())
00131     clients_.push_back(new ZDCMonitorClient((std::string)"ZDCMonitor",ps));
00132 
00133   if (find(enabledClients_.begin(), enabledClients_.end(),"Summary")!=enabledClients_.end())
00134     summaryClient_ = new HcalSummaryClient((std::string)"ReportSummaryClient",ps);
00135   
00136 } // HcalMonitorClient constructor
00137 
00138 
00139 HcalMonitorClient::~HcalMonitorClient()
00140 {
00141   if (debug_>0) std::cout <<"<HcalMonitorClient>  Exiting..."<<std::endl;
00142   for (unsigned int i=0;i<clients_.size();++i)
00143     delete clients_[i];
00144   //if (summaryClient_) delete summaryClient_;
00145 
00146 }
00147 
00148 void HcalMonitorClient::beginJob(void)
00149 {
00150 
00151   begin_run_ = false;
00152   end_run_   = false;
00153 
00154   run_=-1;
00155   evt_=-1;
00156   ievt_=0;
00157   jevt_=0;
00158 
00159   current_time_ = time(NULL);
00160   last_time_html_ = 0; 
00161   last_time_db_ = 0;   
00162 
00163   // get hold of back-end interface
00164 
00165   dqmStore_ = edm::Service<DQMStore>().operator->();
00166 
00167   if ( inputFile_.size() != 0 ) 
00168     {
00169       if ( dqmStore_ )    dqmStore_->open(inputFile_);
00170     }
00171 
00172   for ( unsigned int i=0; i<clients_.size();++i ) 
00173     clients_[i]->beginJob();
00174 
00175   if ( summaryClient_ ) summaryClient_->beginJob();
00176   
00177 
00178 } // void HcalMonitorClient::beginJob(void)
00179 
00180 
00181 void HcalMonitorClient::beginRun(const edm::Run& r, const edm::EventSetup& c) 
00182 {
00183   if (debug_>0) std::cout <<"<HcalMonitorClient::beginRun(r,c)>"<<std::endl;
00184   begin_run_ = true;
00185   end_run_   = false;
00186 
00187   run_=r.id().run();
00188   evt_=0;
00189   jevt_=0;
00190   htmlcounter_=0;
00191 
00192   // Store list of bad channels and their values
00193   std::map <HcalDetId, unsigned int> badchannelmap; 
00194   badchannelmap.clear();
00195 
00196   // Let's get the channel status quality
00197   edm::ESHandle<HcalChannelQuality> p;
00198   c.get<HcalChannelQualityRcd>().get(p);
00199   chanquality_= new HcalChannelQuality(*p.product());
00200  
00201   if (dqmStore_ && ChannelStatus==0)
00202     {
00203       dqmStore_->setCurrentFolder(prefixME_+"HcalInfo/ChannelStatus");
00204       ChannelStatus=new EtaPhiHists;
00205       ChannelStatus->setup(dqmStore_,"ChannelStatus");
00206       std::stringstream x;
00207       for (unsigned int d=0;d<ChannelStatus->depth.size();++d)
00208         {
00209           ChannelStatus->depth[d]->Reset();
00210           x<<"1+log2(status) for HCAL depth "<<d+1;
00211           if (ChannelStatus->depth[d]) ChannelStatus->depth[d]->setTitle(x.str().c_str());
00212           x.str("");
00213         }
00214     }
00215 
00216   edm::ESHandle<HcalDbService> conditions;
00217   c.get<HcalDbRecord>().get(conditions);
00218   // Now let's setup pedestals
00219   if (dqmStore_ )
00220     {
00221       dqmStore_->setCurrentFolder(prefixME_+"HcalInfo/PedestalsFromCondDB");
00222       if (ADC_PedestalFromDBByDepth==0)
00223         {
00224           ADC_PedestalFromDBByDepth = new EtaPhiHists;
00225           ADC_PedestalFromDBByDepth->setup(dqmStore_,"ADC Pedestals From Conditions DB");
00226         }
00227       if (ADC_WidthFromDBByDepth==0)
00228         {
00229           ADC_WidthFromDBByDepth = new EtaPhiHists;
00230           ADC_WidthFromDBByDepth->setup(dqmStore_,"ADC Widths From Conditions DB");
00231         }
00232       if (fC_PedestalFromDBByDepth==0)
00233         {
00234           fC_PedestalFromDBByDepth = new EtaPhiHists;
00235           fC_PedestalFromDBByDepth->setup(dqmStore_,"fC Pedestals From Conditions DB");
00236         }
00237       if (fC_WidthFromDBByDepth==0)
00238         {
00239           fC_WidthFromDBByDepth = new EtaPhiHists;
00240           fC_WidthFromDBByDepth->setup(dqmStore_,"fC Widths From Conditions DB");
00241         }
00242       PlotPedestalValues(*conditions);
00243     }
00244 
00245   // Find only channels with non-zero quality, and add them to badchannelmap
00246   std::vector<DetId> mydetids = chanquality_->getAllChannels();
00247   for (std::vector<DetId>::const_iterator i = mydetids.begin();i!=mydetids.end();++i)
00248     {
00249       if (i->det()!=DetId::Hcal) continue; // not an hcal cell
00250       HcalDetId id=HcalDetId(*i);
00251       int status=(chanquality_->getValues(id))->getValue();
00252       //if (status!=status) status=-1;  // protects against NaN values
00253       // The above line doesn't seem to work in identifying NaNs;  ints for bad values come back as negative numbers (at least in run 146501)
00254       if (status==0) continue;
00255       badchannelmap[id]=status;
00256 
00257       // Fill Channel Status histogram
00258       if (dqmStore_==0) continue;
00259       int depth=id.depth();
00260       if (depth<1 || depth>4) continue;
00261       int ieta=id.ieta();
00262       int iphi=id.iphi();
00263       if (id.subdet()==HcalForward)
00264         ieta>0 ? ++ieta: --ieta;
00265 
00266       double logstatus = 0;
00267       // Fill ChannelStatus value with '-1' when a 'NaN' occurs
00268       if (status<0)
00269         logstatus=-1*(log2(-1.*status)+1);
00270       else
00271         logstatus=log2(1.*status)+1;
00272       if (ChannelStatus->depth[depth-1]) ChannelStatus->depth[depth-1]->Fill(ieta,iphi,logstatus);
00273     }
00274     
00275   for (unsigned int i=0;i<clients_.size();++i)
00276     {
00277       if (clients_[i]->name()=="RawDataMonitor") clients_[i]->setEventSetup(c);
00278       clients_[i]->beginRun();
00279       clients_[i]->setStatusMap(badchannelmap);
00280     }
00281   
00282   if (summaryClient_!=0)
00283     {
00284       summaryClient_->getFriends(clients_);
00285       summaryClient_->beginRun();
00286     }
00287 
00288 } // void HcalMonitorClient::beginRun(const Run& r, const EventSetup& c)
00289 
00290 void HcalMonitorClient::beginRun()
00291 {
00292   // What is the difference between this and beginRun above?
00293   // When would this be called?
00294   begin_run_ = true;
00295   end_run_   = false;
00296   jevt_ = 0;
00297   htmlcounter_=0;
00298 
00299   if (dqmStore_==0 || ChannelStatus!=0) return;
00300   dqmStore_->setCurrentFolder(prefixME_+"HcalInfo");
00301   ChannelStatus=new EtaPhiHists;
00302   ChannelStatus->setup(dqmStore_,"ChannelStatus");
00303   std::stringstream x;
00304   for (unsigned int d=0;d<ChannelStatus->depth.size();++d)
00305     {
00306       x<<"1+log2(status) for HCAL depth "<<d+1;
00307       if (ChannelStatus->depth[d]) ChannelStatus->depth[d]->setTitle(x.str().c_str());
00308       x.str("");
00309     }
00310 } // void HcalMonitorClient::beginRun()
00311 
00312 void HcalMonitorClient::setup(void)
00313 {
00314   // no setup required
00315 }
00316 
00317 void HcalMonitorClient::beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &c) 
00318 {
00319   if (debug_>0) std::cout <<"<HcalMonitorClient::beginLuminosityBlock>"<<std::endl;
00320 } // void HcalMonitorClient::beginLuminosityBlock
00321 
00322 void HcalMonitorClient::analyze(const edm::Event & e, const edm::EventSetup & c)
00323 {
00324   if (debug_>4) 
00325     std::cout <<"HcalMonitorClient::analyze(const edm::Event&, const edm::EventSetup&) ievt_ = "<<ievt_<<std::endl;
00326   ievt_++;
00327   jevt_++;
00328 
00329   run_=e.id().run();
00330   evt_=e.id().event();
00331   if (prescaleFactor_>0 && jevt_%prescaleFactor_==0) this->analyze(e.luminosityBlock());
00332 
00333 } // void HcalMonitorClient::analyze(const edm::Event & e, const edm::EventSetup & c)
00334 
00335 void HcalMonitorClient::analyze(int LS)
00336 {
00337   if (debug_>0)
00338     std::cout <<"HcalMonitorClient::analyze() "<<std::endl;
00339   current_time_ = time(NULL);
00340   // no ievt_, jevt_ counters needed here:  this function gets called at endlumiblock, after default analyze function runs
00341   for (unsigned int i=0;i<clients_.size();++i)
00342     clients_[i]->analyze();
00343   if (summaryClient_!=0)
00344     {
00345       // Always call basic analyze to form histograms for each task
00346       summaryClient_->analyze(LS);
00347       // Call this if LS-by-LS enabling is set to true
00348       if (saveByLumiSection_==true)
00349         summaryClient_->fillReportSummaryLSbyLS(LS);
00350     }
00351 } // void HcalMonitorClient::analyze()
00352 
00353 
00354 void HcalMonitorClient::endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &c) 
00355 {
00356   if (debug_>0) std::cout <<"<HcalMonitorClient::endLuminosityBlock>"<<std::endl;
00357   current_time_ = time(NULL);
00358   if (updateTime_>0)
00359     {
00360       if ((current_time_-last_time_update_)<60*updateTime_)
00361         return;
00362       last_time_update_ = current_time_;
00363     }
00364   this->analyze(l.luminosityBlock());
00365 
00366   if (databaseUpdateTime_>0)
00367     {
00368       if (
00369           // first update occurs at after databaseFirstUpdate_ minutes
00370           (last_time_db_==0 && (current_time_-last_time_db_)>=60*databaseFirstUpdate_)
00371           ||
00372           // following updates follow once every databaseUpdateTime_ minutes
00373           ((current_time_-last_time_db_)>=60*databaseUpdateTime_)
00374           )
00375         {
00376           this->writeChannelStatus();
00377           last_time_db_=current_time_;
00378         }
00379     }
00380 
00381   if (htmlUpdateTime_>0)
00382     {
00383       if (
00384           (last_time_html_==0 && (current_time_-last_time_html_)>=60*htmlFirstUpdate_)
00385           // 
00386           ||((current_time_-last_time_html_)>=60*htmlUpdateTime_)
00387           ) // htmlUpdateTime_ in minutes
00388         {
00389           this->writeHtml();
00390           last_time_html_=current_time_;
00391         }
00392     }
00393 
00394 } // void HcalMonitorClient::endLuminosityBlock
00395 
00396 void HcalMonitorClient::endRun(void)
00397 {
00398   begin_run_ = false;
00399   end_run_   = true;
00400 
00401   // Always fill summaryClient at end of run (as opposed to the end-lumi fills, which may just contain info for a single LS)
00402   // At the end of this run, set LS=-1  (LS-based plotting in doesn't work yet anyway)
00403   if (summaryClient_)
00404     summaryClient_->analyze(-1);
00405 
00406   if (databasedir_.size()>0)
00407     this->writeChannelStatus();
00408   // writeHtml takes longer; run it last 
00409   // Also, don't run it if htmlUpdateTime_>0 -- it should have already been run
00410   if (baseHtmlDir_.size()>0 && htmlUpdateTime_==0)
00411     this->writeHtml();
00412 }
00413 
00414 void HcalMonitorClient::endRun(const edm::Run& r, const edm::EventSetup& c) 
00415 {
00416   // Set values here, because the "analyze" method occasionally times out, 
00417   // which keeps the endRun() call from being made.  This causes endJob to
00418   // crash, since end_run_ is still set to false at that point.
00419   begin_run_ = false;
00420   end_run_   = true;
00421 
00422   this->analyze();
00423   this->endRun();
00424 }
00425 
00426 void HcalMonitorClient::endJob(void)
00427 {
00428   // Temporary fix for crash of April 2011 in online DQM
00429   if (Online_==true)
00430     return;
00431 
00432   if (! end_run_)
00433     {
00434       this->analyze();
00435       this->endRun();
00436     }
00437   this->cleanup(); // currently does nothing
00438 
00439   for ( unsigned int i=0; i<clients_.size(); i++ ) 
00440     clients_[i]->endJob();
00441   //if ( summaryClient_ ) summaryClient_->endJob();
00442 
00443 } // void HcalMonitorClient::endJob(void)
00444 
00445 void HcalMonitorClient::cleanup(void)
00446 {
00447   if (!enableCleanup_) return;
00448   // other cleanup?
00449 } // void HcalMonitorClient::cleanup(void)
00450 
00451 
00452 void HcalMonitorClient::writeHtml()
00453 {
00454   if (debug_>0) std::cout << "Preparing HcalMonitorClient html output ..." << std::endl;
00455   
00456 
00457   // global ROOT style
00458   gStyle->Reset("Default");
00459   gStyle->SetCanvasColor(0);
00460   gStyle->SetPadColor(0);
00461   gStyle->SetFillColor(0);
00462   gStyle->SetTitleFillColor(10);
00463   //  gStyle->SetOptStat(0);
00464   gStyle->SetOptStat("ouemr");
00465   gStyle->SetPalette(1);
00466 
00467   char tmp[20];
00468 
00469   if(run_!=-1) sprintf(tmp, "DQM_%s_R%09d_%i", prefixME_.substr(0,prefixME_.size()-1).c_str(),run_,htmlcounter_);
00470   else sprintf(tmp, "DQM_%s_R%09d_%i", prefixME_.substr(0,prefixME_.size()-1).c_str(),0,htmlcounter_);
00471   std::string htmlDir = baseHtmlDir_ + "/" + tmp + "/";
00472   system(("/bin/mkdir -p " + htmlDir).c_str());
00473 
00474   ++htmlcounter_;
00475 
00476   ofstream htmlFile;
00477   htmlFile.open((htmlDir + "index.html").c_str());
00478 
00479   // html page header
00480   htmlFile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">  " << std::endl;
00481   htmlFile << "<html>  " << std::endl;
00482   htmlFile << "<head>  " << std::endl;
00483   htmlFile << "  <meta content=\"text/html; charset=ISO-8859-1\"  " << std::endl;
00484   htmlFile << " https-equiv=\"content-type\">  " << std::endl;
00485   htmlFile << "  <title>Hcal Data Quality Monitor</title> " << std::endl;
00486   htmlFile << "</head>  " << std::endl;
00487   htmlFile << "<body>  " << std::endl;
00488   htmlFile << "<br>  " << std::endl;
00489  htmlFile << "<center><h1>Hcal Data Quality Monitor</h1></center>" << std::endl;
00490   htmlFile << "<h2>Run Number:&nbsp;&nbsp;&nbsp;" << std::endl;
00491   htmlFile << "<span style=\"color: rgb(0, 0, 153);\">" << run_ <<"</span></h2> " << std::endl;
00492   htmlFile << "<h2>Events processed:&nbsp;&nbsp;&nbsp;" << std::endl;
00493   htmlFile << "<span style=\"color: rgb(0, 0, 153);\">" << ievt_ <<"</span></h2> " << std::endl;
00494   htmlFile << "<hr>" << std::endl;
00495   htmlFile << "<ul>" << std::endl;
00496 
00497   for (unsigned int i=0;i<clients_.size();++i)
00498     {
00499       if (clients_[i]->validHtmlOutput()==true)
00500         {
00501           clients_[i]->htmlOutput(htmlDir);
00502           // Always print this out?  Or only when validHtmlOutput is true? 
00503           htmlFile << "<table border=0 WIDTH=\"50%\"><tr>" << std::endl;
00504           htmlFile << "<td WIDTH=\"35%\"><a href=\"" << clients_[i]->name_ << ".html"<<"\">"<<clients_[i]->name_<<"</a></td>" << std::endl;
00505           if(clients_[i]->hasErrors_Temp()) htmlFile << "<td bgcolor=red align=center>This monitor task has errors.</td>" << std::endl;
00506           else if(clients_[i]->hasWarnings_Temp()) htmlFile << "<td bgcolor=yellow align=center>This monitor task has warnings.</td>" << std::endl;
00507           else if(clients_[i]->hasOther_Temp()) htmlFile << "<td bgcolor=aqua align=center>This monitor task has messages.</td>" << std::endl;
00508           else htmlFile << "<td bgcolor=lime align=center>This monitor task has no problems</td>" << std::endl;
00509           htmlFile << "</tr></table>" << std::endl;
00510         }
00511     }
00512 
00513   // Add call to reportSummary html output
00514   if (summaryClient_)
00515     {
00516       summaryClient_->htmlOutput(htmlDir);
00517       htmlFile << "<table border=0 WIDTH=\"50%\"><tr>" << std::endl;
00518       htmlFile << "<td WIDTH=\"35%\"><a href=\"" << summaryClient_->name_ << ".html"<<"\">"<<summaryClient_->name_<<"</a></td>" << std::endl;
00519       if(summaryClient_->hasErrors_Temp()) htmlFile << "<td bgcolor=red align=center>This monitor task has errors.</td>" << std::endl;
00520       else if(summaryClient_->hasWarnings_Temp()) htmlFile << "<td bgcolor=yellow align=center>This monitor task has warnings.</td>" << std::endl;
00521       else if(summaryClient_->hasOther_Temp()) htmlFile << "<td bgcolor=aqua align=center>This monitor task has messages.</td>" << std::endl;
00522       else htmlFile << "<td bgcolor=lime align=center>This monitor task has no problems</td>" << std::endl;
00523       htmlFile << "</tr></table>" << std::endl;
00524     }
00525 
00526   htmlFile << "</ul>" << std::endl;
00527 
00528   // html page footer
00529   htmlFile << "</body> " << std::endl;
00530   htmlFile << "</html> " << std::endl;
00531 
00532   htmlFile.close();
00533   if (debug_>0) std::cout << "HcalMonitorClient html output done..." << std::endl;
00534   
00535 } // void HcalMonitorClient::writeHtml()
00536 
00537 void HcalMonitorClient::writeChannelStatus()
00538 {
00539   if (databasedir_.size()==0) return;
00540   if (debug_>0) std::cout <<"<HcalMonitorClient::writeDBfile>  Writing file for database"<<std::endl;
00541 
00542   std::map<HcalDetId, unsigned int> myquality; //map of quality flags as reported by each client
00543   // Get status from all channels (we need to store all channels in case a bad channel suddenly becomes good)
00544   for (std::vector<HcalBaseDQClient*>::size_type i=0;i<clients_.size();++i)
00545     clients_[i]->updateChannelStatus(myquality);
00546 
00547   if (debug_>0) std::cout <<"<HcalMonitorClient::writeChannelStatus()>  myquality size = "<<myquality.size()<<std::endl;
00548 
00549   std::vector<DetId> mydetids = chanquality_->getAllChannels();
00550   HcalChannelQuality* newChanQual = new HcalChannelQuality();
00551 
00552   for (unsigned int i=0;i<mydetids.size();++i)
00553     {
00554       if (mydetids[i].det()!=DetId::Hcal) continue; // not hcal
00555       
00556       HcalDetId id=mydetids[i];
00557       // get original channel status item
00558       const HcalChannelStatus* origstatus=chanquality_->getValues(mydetids[i]);
00559       // make copy of status
00560       HcalChannelStatus* mystatus=new HcalChannelStatus(origstatus->rawId(),origstatus->getValue());
00561       // loop over myquality flags
00562       if (myquality.find(id)!=myquality.end())
00563         {
00564           
00565           // check dead cells
00566           if ((myquality[id]>>HcalChannelStatus::HcalCellDead)&0x1)
00567             mystatus->setBit(HcalChannelStatus::HcalCellDead);
00568           else
00569             mystatus->unsetBit(HcalChannelStatus::HcalCellDead);
00570           // check hot cells
00571           if ((myquality[id]>>HcalChannelStatus::HcalCellHot)&0x1)
00572             mystatus->setBit(HcalChannelStatus::HcalCellHot);
00573           else
00574             mystatus->unsetBit(HcalChannelStatus::HcalCellHot);
00575         } // if (myquality.find_...)
00576       newChanQual->addValues(*mystatus);
00577     } // for (unsigned int i=0;...)
00578   
00579   //Now dump out to text file
00580   std::ostringstream file;
00581   databasedir_=databasedir_+"/"; // add extra slash, just in case
00582   //file <<databasedir_<<"HcalDQMstatus_"<<run_<<".txt";
00583   file <<databasedir_<<"HcalDQMstatus.txt";
00584   std::ofstream outStream(file.str().c_str());
00585   outStream<<"###  Run # "<<run_<<std::endl;
00586   HcalDbASCIIIO::dumpObject (outStream, (*newChanQual));
00587   return;
00588 } // void HcalMonitorClient::writeChannelStatus()
00589 
00590 
00591 void HcalMonitorClient::PlotPedestalValues(const HcalDbService& cond)
00592 {
00593   const HcalQIEShape* shape_ = cond.getHcalShape(); // this one is generic
00594 
00595   double ADC_ped=0;
00596   double ADC_width=0;
00597   double fC_ped=0;
00598   double fC_width=0;
00599   double temp_ADC=0;
00600   double temp_fC=0;
00601 
00602   int ieta=-9999;
00603   int iphi=-9999;
00604   HcalCalibrations calibs_;
00605 
00606   ADC_PedestalFromDBByDepth->Reset();
00607   ADC_WidthFromDBByDepth->Reset();
00608   fC_PedestalFromDBByDepth->Reset();
00609   fC_WidthFromDBByDepth->Reset();
00610 
00611 
00612   for (int subdet=1; subdet<=4;++subdet)
00613     {
00614       for (int depth=0;depth<4;++depth)
00615         {
00616           int etabins= ADC_PedestalFromDBByDepth->depth[depth]->getNbinsX();
00617           int phibins = ADC_PedestalFromDBByDepth->depth[depth]->getNbinsY();
00618           for (int eta=0;eta<etabins;++eta)
00619             {
00620               ieta=CalcIeta(subdet,eta,depth+1);
00621               if (ieta==-9999) continue;
00622               for (int phi=0;phi<phibins;++phi)
00623                 {
00624                   iphi=phi+1;
00625                   if (!validDetId((HcalSubdetector)(subdet), ieta, iphi, depth+1)) continue;
00626                   HcalDetId detid((HcalSubdetector)(subdet), ieta, iphi, depth+1);
00627                   ADC_ped=0;
00628                   ADC_width=0;
00629                   fC_ped=0;
00630                   fC_width=0;
00631                   calibs_= cond.getHcalCalibrations(detid);  
00632                   const HcalPedestalWidth* pedw = cond.getPedestalWidth(detid);
00633                   const HcalQIECoder* channelCoder_ = cond.getHcalCoder(detid);
00634 
00635                   // Loop over capIDs
00636                   for (unsigned int capid=0;capid<4;++capid)
00637                     {
00638                       // Still need to determine how to convert widths to ADC or fC
00639                       // calibs_.pedestal value is always in fC, according to Radek
00640                       temp_fC = calibs_.pedestal(capid);
00641                       fC_ped+= temp_fC;
00642                       // convert to ADC from fC
00643                       temp_ADC=channelCoder_->adc(*shape_,
00644                                                   (float)calibs_.pedestal(capid),
00645                                                   capid);
00646                       ADC_ped+=temp_ADC;
00647                       // Pedestals assumed to be read out in fC
00648                       temp_fC=pedw->getSigma(capid,capid);
00649                       fC_width+=temp_fC;
00650                       temp_ADC=pedw->getSigma(capid,capid)*pow(1.*channelCoder_->adc(*shape_,(float)calibs_.pedestal(capid),capid)/calibs_.pedestal(capid),2);
00651                       ADC_width+=temp_ADC;
00652                     }//capid loop
00653 
00654                   // Pedestal values are average over four cap IDs
00655                   // widths are sqrt(SUM [sigma_ii^2])/4.
00656                   fC_ped/=4.;
00657                   ADC_ped/=4.;
00658 
00659                   // Divide width by 2, or by four?
00660                   // Dividing by 2 gives subtracted results closer to zero -- estimate of variance?
00661                   fC_width=pow(fC_width,0.5)/2.;
00662                   ADC_width=pow(ADC_width,0.5)/2.;
00663 
00664                   if (debug_>1)
00665                     {
00666                       std::cout <<"<HcalMonitorClient::PlotPedestalValues> HcalDet ID = "<<(HcalSubdetector)subdet<<": ("<<ieta<<", "<<iphi<<", "<<depth<<")"<<std::endl;
00667                       std::cout <<"\tADC pedestal = "<<ADC_ped<<" +/- "<<ADC_width<<std::endl;
00668                       std::cout <<"\tfC pedestal = "<<fC_ped<<" +/- "<<fC_width<<std::endl;
00669                     }
00670                   // Shift HF by -/+1 when filling eta-phi histograms
00671                   int zside=0;
00672                   if (subdet==4)
00673                     {
00674                       if (ieta<0) zside=-1;
00675                       else zside=1;
00676                     }
00677                   ADC_PedestalFromDBByDepth->depth[depth]->Fill(ieta+zside,iphi,ADC_ped);
00678                   ADC_WidthFromDBByDepth->depth[depth]->Fill(ieta+zside, iphi, ADC_width);
00679                   fC_PedestalFromDBByDepth->depth[depth]->Fill(ieta+zside,iphi,fC_ped);
00680                   fC_WidthFromDBByDepth->depth[depth]->Fill(ieta+zside, iphi, fC_width);
00681                 } // phi loop
00682             } // eta loop
00683         } //depth loop
00684 
00685     } // subdet loop
00686   FillUnphysicalHEHFBins(*ADC_PedestalFromDBByDepth);
00687   FillUnphysicalHEHFBins(*ADC_WidthFromDBByDepth);
00688   FillUnphysicalHEHFBins(*fC_PedestalFromDBByDepth);
00689   FillUnphysicalHEHFBins(*fC_WidthFromDBByDepth);
00690 
00691   // Center ADC pedestal values near 3 +/- 1
00692   for (unsigned int i=0;i<ADC_PedestalFromDBByDepth->depth.size();++i)
00693   {
00694     ADC_PedestalFromDBByDepth->depth[i]->getTH2F()->SetMinimum(0);
00695     if (ADC_PedestalFromDBByDepth->depth[i]->getTH2F()->GetMaximum()<6)
00696       ADC_PedestalFromDBByDepth->depth[i]->getTH2F()->SetMaximum(6);
00697   }
00698 
00699   for (unsigned int i=0;i<ADC_WidthFromDBByDepth->depth.size();++i)
00700   {
00701     ADC_WidthFromDBByDepth->depth[i]->getTH2F()->SetMinimum(0);
00702     if (ADC_WidthFromDBByDepth->depth[i]->getTH2F()->GetMaximum()<2)
00703       ADC_WidthFromDBByDepth->depth[i]->getTH2F()->SetMaximum(2);
00704   }
00705 
00706 }
00707 
00708 DEFINE_FWK_MODULE(HcalMonitorClient);