CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/DQMServices/Components/src/DQMProvInfo.cc

Go to the documentation of this file.
00001 /*
00002  * \file DQMProvInfo.cc
00003  * \author A.Raval / A.Meyer - DESY
00004  * Last Update:
00005  * $Date: 2012/12/01 03:54:21 $
00006  * $Revision: 1.32 $
00007  * $Author: wmtan $
00008  *
00009  */
00010 
00011 #include "DQMProvInfo.h"
00012 #include <TSystem.h>
00013 #include "DataFormats/Provenance/interface/ProcessHistory.h"
00014 #include "DataFormats/Scalers/interface/DcsStatus.h"
00015 #include "DataFormats/L1GlobalTrigger/interface/L1GtFdlWord.h"
00016 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00017 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
00018 #include "FWCore/Framework/interface/LuminosityBlock.h"
00019 #include "FWCore/Version/interface/GetReleaseVersion.h"
00020 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00021 
00022 const static int XBINS=2500;
00023 const static int YBINS=28;
00024 
00025 DQMProvInfo::DQMProvInfo(const edm::ParameterSet& ps){
00026   
00027   parameters_ = ps;
00028   
00029   dbe_ = edm::Service<DQMStore>().operator->();
00030   globalTag_ = "MODULE::DEFAULT"; 
00031   runType_ = parameters_.getUntrackedParameter<std::string>("runType", "No run type selected") ;
00032   provinfofolder_ = parameters_.getUntrackedParameter<std::string>("provInfoFolder", "ProvInfo") ;
00033   subsystemname_ = parameters_.getUntrackedParameter<std::string>("subSystemFolder", "Info") ;
00034   
00035   // initialize
00036   nameProcess_ = "HLT"; // the process name is not contained in this ps
00037   gotProcessParameterSet_=false;
00038   physDecl_=true; // set true and switch off in case a single event in a given LS does not have it set.
00039   for (int i=0;i<25;i++) dcs25[i]=true;
00040   lastlumi_=0;
00041 }
00042 
00043 DQMProvInfo::~DQMProvInfo(){
00044 }
00045 
00046 void 
00047 DQMProvInfo::beginRun(const edm::Run& r, const edm::EventSetup &c ) {
00048 
00049   makeProvInfo();
00050   makeHLTKeyInfo(r,c);
00051 
00052   dbe_->cd(); 
00053   dbe_->setCurrentFolder(subsystemname_ +"/EventInfo/");
00054 
00055   reportSummary_=dbe_->bookFloat("reportSummary");
00056   reportSummaryMap_ = dbe_->book2D("reportSummaryMap",
00057                      "HV and Beam Status vs Lumi", XBINS, 1., XBINS+1, YBINS+1, 0., YBINS+1);
00058   reportSummaryMap_->setBinLabel(1," CSC+",2);   
00059   reportSummaryMap_->setBinLabel(2," CSC-",2);   
00060   reportSummaryMap_->setBinLabel(3," DT0",2);    
00061   reportSummaryMap_->setBinLabel(4," DT+",2);    
00062   reportSummaryMap_->setBinLabel(5," DT-",2);    
00063   reportSummaryMap_->setBinLabel(6," EB+",2);    
00064   reportSummaryMap_->setBinLabel(7," EB-",2);    
00065   reportSummaryMap_->setBinLabel(8," EE+",2);    
00066   reportSummaryMap_->setBinLabel(9," EE-",2);    
00067   reportSummaryMap_->setBinLabel(10,"ES+",2);    
00068   reportSummaryMap_->setBinLabel(11,"ES-",2);   
00069   reportSummaryMap_->setBinLabel(12,"HBHEa",2); 
00070   reportSummaryMap_->setBinLabel(13,"HBHEb",2); 
00071   reportSummaryMap_->setBinLabel(14,"HBHEc",2); 
00072   reportSummaryMap_->setBinLabel(15,"HF",2);    
00073   reportSummaryMap_->setBinLabel(16,"HO",2);    
00074   reportSummaryMap_->setBinLabel(17,"BPIX",2);  
00075   reportSummaryMap_->setBinLabel(18,"FPIX",2);  
00076   reportSummaryMap_->setBinLabel(19,"RPC",2);   
00077   reportSummaryMap_->setBinLabel(20,"TIBTID",2);
00078   reportSummaryMap_->setBinLabel(21,"TOB",2);   
00079   reportSummaryMap_->setBinLabel(22,"TECp",2);  
00080   reportSummaryMap_->setBinLabel(23,"TECm",2);  
00081   reportSummaryMap_->setBinLabel(24,"CASTOR",2);
00082   reportSummaryMap_->setBinLabel(25,"ZDC",2);
00083   reportSummaryMap_->setBinLabel(26,"PhysDecl",2);
00084   reportSummaryMap_->setBinLabel(27,"8 TeV",2);
00085   reportSummaryMap_->setBinLabel(28,"Stable B",2);
00086   reportSummaryMap_->setBinLabel(29,"Valid",2);
00087   reportSummaryMap_->setAxisTitle("Luminosity Section");
00088   reportSummaryMap_->getTH2F()->SetBit(TH1::kCanRebin);
00089 
00090   dbe_->cd();  
00091   dbe_->setCurrentFolder(subsystemname_ +"/LhcInfo/");
00092   hBeamMode_=dbe_->book1D("beamMode","beamMode",XBINS,1.,XBINS+1);
00093   hBeamMode_->getTH1F()->GetYaxis()->Set(21,0.5,21.5);
00094   hBeamMode_->getTH1F()->SetMaximum(21.5);
00095   hBeamMode_->getTH1F()->SetBit(TH1::kCanRebin);
00096 
00097   hBeamMode_->setAxisTitle("Luminosity Section",1);
00098   hBeamMode_->setBinLabel(1,"no mode",2);
00099   hBeamMode_->setBinLabel(2,"setup",2);
00100   hBeamMode_->setBinLabel(3,"inj pilot",2);
00101   hBeamMode_->setBinLabel(4,"inj intr",2);
00102   hBeamMode_->setBinLabel(5,"inj nomn",2);
00103   hBeamMode_->setBinLabel(6,"pre ramp",2);
00104   hBeamMode_->setBinLabel(7,"ramp",2);
00105   hBeamMode_->setBinLabel(8,"flat top",2);
00106   hBeamMode_->setBinLabel(9,"squeeze",2);
00107   hBeamMode_->setBinLabel(10,"adjust",2);
00108   hBeamMode_->setBinLabel(11,"stable",2);
00109   hBeamMode_->setBinLabel(12,"unstable",2);
00110   hBeamMode_->setBinLabel(13,"beam dump",2);
00111   hBeamMode_->setBinLabel(14,"ramp down",2);
00112   hBeamMode_->setBinLabel(15,"recovery",2);
00113   hBeamMode_->setBinLabel(16,"inj dump",2);
00114   hBeamMode_->setBinLabel(17,"circ dump",2);
00115   hBeamMode_->setBinLabel(18,"abort",2);
00116   hBeamMode_->setBinLabel(19,"cycling",2);
00117   hBeamMode_->setBinLabel(20,"warn b-dump",2);
00118   hBeamMode_->setBinLabel(21,"no beam",2);
00119   hBeamMode_->setBinContent(0.,22.);
00120   
00121 
00122   hLhcFill_=dbe_->book1D("lhcFill","LHC Fill Number",XBINS,1.,XBINS+1);
00123   hLhcFill_->setAxisTitle("Luminosity Section",1);
00124   hLhcFill_->getTH1F()->SetBit(TH1::kCanRebin);
00125   
00126   hMomentum_=dbe_->book1D("momentum","Beam Energy [GeV]",XBINS,1.,XBINS+1);
00127   hMomentum_->setAxisTitle("Luminosity Section",1);
00128   hMomentum_->getTH1F()->SetBit(TH1::kCanRebin);
00129 
00130   hIntensity1_=dbe_->book1D("intensity1","Intensity Beam 1",XBINS,1.,XBINS+1);
00131   hIntensity1_->setAxisTitle("Luminosity Section",1);
00132   hIntensity1_->setAxisTitle("N [E10]",2);
00133   hIntensity1_->getTH1F()->SetBit(TH1::kCanRebin);
00134   hIntensity2_=dbe_->book1D("intensity2","Intensity Beam 2",XBINS,1.,XBINS+1);
00135   hIntensity2_->setAxisTitle("Luminosity Section",1);
00136   hIntensity2_->setAxisTitle("N [E10]",2);
00137   hIntensity2_->getTH1F()->SetBit(TH1::kCanRebin);
00138 
00139   dbe_->cd();  
00140   dbe_->setCurrentFolder(subsystemname_ +"/ProvInfo/");
00141   hIsCollisionsRun_ = dbe_->bookInt("isCollisionsRun");
00142   hIsCollisionsRun_->Fill(0);
00143   
00144   // initialize
00145   physDecl_=true;
00146   for (int i=0;i<25;i++) dcs25[i]=true;
00147   lastlumi_=0;
00148 } 
00149 
00150 void DQMProvInfo::analyze(const edm::Event& e, const edm::EventSetup& c){
00151   if(!gotProcessParameterSet_){
00152     gotProcessParameterSet_=true;
00153     edm::ParameterSet ps;
00154     //fetch the real process name
00155     nameProcess_ = e.processHistory()[e.processHistory().size()-1].processName();
00156     e.getProcessParameterSet(nameProcess_,ps);
00157     globalTag_ = ps.getParameterSet("PoolDBESSource@GlobalTag").getParameter<std::string>("globaltag");
00158     versGlobaltag_->Fill(globalTag_);
00159   }
00160   
00161   makeDcsInfo(e);
00162   makeGtInfo(e);
00163 
00164   return;
00165 }
00166 
00167 void
00168 DQMProvInfo::endLuminosityBlock(const edm::LuminosityBlock& l, const edm::EventSetup& c)
00169 {
00170 
00171   int nlumi = l.id().luminosityBlock();
00172   
00173   edm::LogInfo("DQMProvInfo") << "nlumi: " <<  nlumi << " / number of bins: " << hBeamMode_->getTH1F()->GetNbinsX() << std::endl;
00174 
00175   if (nlumi <= lastlumi_ ) return;
00176 
00177   hBeamMode_->setBinContent(nlumi,beamMode_);
00178   hLhcFill_->setBinContent(nlumi,lhcFill_);
00179   hMomentum_->setBinContent(nlumi,momentum_);
00180   hIntensity1_->setBinContent(nlumi,intensity1_);
00181   hIntensity2_->setBinContent(nlumi,intensity2_);
00182 
00183   // set to previous in case there was a jump or no previous fill
00184   for (int l=lastlumi_+1;l<nlumi;l++)
00185   {
00186     if (lastlumi_ > 0 && reportSummaryMap_->getBinContent(lastlumi_,YBINS+1) == 1) 
00187     {
00188       reportSummaryMap_->setBinContent(l,YBINS+1,0.);
00189       for (int i=0;i<YBINS;i++)
00190       {
00191           float lastvalue = reportSummaryMap_->getBinContent(lastlumi_,i+1);
00192           reportSummaryMap_->setBinContent(l,i+1,lastvalue);
00193       }
00194     }
00195     else
00196     {
00197       reportSummaryMap_->setBinContent(l,YBINS+1,0.);
00198       for (int i=0;i<YBINS;i++)
00199         reportSummaryMap_->setBinContent(l,i+1,-1.);
00200     }
00201   }
00202 
00203       
00204   // fill dcs vs lumi
00205   reportSummaryMap_->setBinContent(nlumi,YBINS+1,1.);
00206   for (int i=0;i<25;i++)
00207   {
00208     if (dcs25[i])
00209       reportSummaryMap_->setBinContent(nlumi,i+1,1.);
00210     else
00211       reportSummaryMap_->setBinContent(nlumi,i+1,0.);
00212 
00213     // set next lumi to -1 for better visibility
00214     if (nlumi < XBINS)
00215       reportSummaryMap_->setBinContent(nlumi+1,i+1,-1.);
00216     dcs25[i]=true;
00217   }
00218 
00219   // fill physics decl. bit in y bin 26
00220   if (physDecl_) 
00221   {
00222     reportSummary_->Fill(1.); 
00223     reportSummaryMap_->setBinContent(nlumi,25+1,1.);
00224     if (nlumi < XBINS) 
00225       reportSummaryMap_->setBinContent(nlumi+1,25+1,-1.);
00226   }
00227   else
00228   {
00229     reportSummary_->Fill(0.); 
00230     reportSummaryMap_->setBinContent(nlumi,25+1,0.);
00231     if (nlumi < XBINS) 
00232       reportSummaryMap_->setBinContent(nlumi+1,25+1,-1.);
00233   }
00234   
00235   // fill 7 TeV bit in y bin 27
00236   if (momentum_ == 3500 || momentum_ == 4000 ) 
00237   {
00238     reportSummary_->Fill(1.); 
00239     reportSummaryMap_->setBinContent(nlumi,26+1,1.);
00240     if (nlumi < XBINS) 
00241       reportSummaryMap_->setBinContent(nlumi+1,26+1,-1.);
00242   }
00243   else
00244   {
00245     reportSummary_->Fill(0.); 
00246     reportSummaryMap_->setBinContent(nlumi,26+1,0.);
00247     if (nlumi < XBINS) 
00248       reportSummaryMap_->setBinContent(nlumi+1,26+1,-1.);
00249   }
00250 
00251   // fill stable beams bit in y bin 28
00252   if (beamMode_ == 11) 
00253   {
00254     hIsCollisionsRun_->Fill(1);
00255     reportSummary_->Fill(1.); 
00256     reportSummaryMap_->setBinContent(nlumi,27+1,1.);
00257     if (nlumi < XBINS) 
00258       reportSummaryMap_->setBinContent(nlumi+1,27+1,-1.);
00259   }
00260   else
00261   {
00262     reportSummary_->Fill(0.); 
00263     reportSummaryMap_->setBinContent(nlumi,27+1,0.);
00264     if (nlumi < XBINS) 
00265       reportSummaryMap_->setBinContent(nlumi+1,27+1,-1.);
00266   }
00267 
00268   // reset   
00269   physDecl_=true;  
00270   lastlumi_=nlumi;
00271 
00272   return;
00273   
00274 }
00275 
00276 // run showtag command line
00277 std::string 
00278 DQMProvInfo::getShowTags(void)
00279 {
00280    TString out;
00281    TString cwd;
00282    TString showtagswd;
00283    cwd=gSystem->pwd();
00284    showtagswd=gSystem->ExpandPathName("$CMSSW_BASE/");
00285    gSystem->ChangeDirectory(showtagswd);
00286    FILE *pipe = gSystem->OpenPipe("showtags u -t", "r");
00287 
00288    TString line;
00289    while (line.Gets(pipe,true)) {
00290      if (line.Contains("Test Release")) continue;
00291      if (line.Contains("Base Release")) continue;
00292      if (line.Contains("Test release")) continue;
00293      if (line.Contains("--- Tag ---")) continue;
00294      if (line.Contains(" ")) line.Replace(line.First(" "),1,":");
00295      line.ReplaceAll(" ","");
00296      out = out + line + ";";
00297      if (line.Contains("-------------------")) break;
00298      if (out.Length()>XBINS) break;
00299    }
00300    out.ReplaceAll("--","");
00301    out.ReplaceAll(";-",";");
00302    out.ReplaceAll(";;",";");
00303    out.ReplaceAll("\n","");
00304 
00305    Int_t r = gSystem->ClosePipe(pipe);
00306    gSystem->ChangeDirectory(cwd);
00307    if (r) {
00308      gSystem->Error("ShowTags","problem running command showtags -u -t");
00309    }
00310 
00311    std::string str(out);
00312    if (str.length()>2000) str.resize(2000);
00313 
00314    std::string safestr =
00315      "/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-;:";
00316    size_t found=str.find_first_not_of(safestr);
00317    if (found!=std::string::npos)
00318    {
00319      edm::LogWarning("DQMProvInfo::ShowTags") << " Illegal character found: " 
00320                << str[found] 
00321                << " at position " 
00322                << int(found) ;
00323      return "notags";
00324    }   
00325    return str;
00326 }
00327 
00328 
00329 void 
00330 DQMProvInfo::makeProvInfo()
00331 {
00332     dbe_->cd() ;
00333     dbe_->setCurrentFolder( subsystemname_ + "/" +  provinfofolder_) ;
00334 
00335     // if (dbe_->get("ProvInfo/CMSSW")) return ;
00336     
00337     versCMSSW_     = dbe_->bookString("CMSSW",edm::getReleaseVersion().c_str() );
00338     hostName_      = dbe_->bookString("hostName",gSystem->HostName());
00339     workingDir_    = dbe_->bookString("workingDir",gSystem->pwd());
00340     processId_     = dbe_->bookInt("processID"); processId_->Fill(gSystem->GetPid());
00341 
00342     //versDataset_   = dbe_->bookString("Dataset",workflow_);
00343     versGlobaltag_ = dbe_->bookString("Globaltag",globalTag_);
00344     versRuntype_ = dbe_->bookString("Run Type",runType_);
00345     versTaglist_   = dbe_->bookString("Taglist",getShowTags()); 
00346 
00347     isComplete_ = dbe_->bookInt("runIsComplete"); 
00348     //isComplete_->Fill((runIsComplete_?1:0));
00349     fileVersion_ = dbe_->bookInt("fileVersion");
00350     //fileVersion_->Fill(version_);
00351     
00352     return ;
00353 }
00354 void 
00355 DQMProvInfo::makeDcsInfo(const edm::Event& e)
00356 {
00357 
00358   edm::Handle<DcsStatusCollection> dcsStatus;
00359   e.getByLabel("scalersRawToDigi", dcsStatus);
00360   for (DcsStatusCollection::const_iterator dcsStatusItr = dcsStatus->begin(); 
00361                             dcsStatusItr != dcsStatus->end(); ++dcsStatusItr) 
00362   {
00363       // edm::LogInfo("DQMProvInfo") << "DCS status: 0x" << std::hex << dcsStatusItr->ready() << std::dec << std::endl;
00364       if (!dcsStatusItr->ready(DcsStatus::CSCp))   dcs25[0]=false;
00365       if (!dcsStatusItr->ready(DcsStatus::CSCm))   dcs25[1]=false;   
00366       if (!dcsStatusItr->ready(DcsStatus::DT0))    dcs25[2]=false;
00367       if (!dcsStatusItr->ready(DcsStatus::DTp))    dcs25[3]=false;
00368       if (!dcsStatusItr->ready(DcsStatus::DTm))    dcs25[4]=false;
00369       if (!dcsStatusItr->ready(DcsStatus::EBp))    dcs25[5]=false;
00370       if (!dcsStatusItr->ready(DcsStatus::EBm))    dcs25[6]=false;
00371       if (!dcsStatusItr->ready(DcsStatus::EEp))    dcs25[7]=false;
00372       if (!dcsStatusItr->ready(DcsStatus::EEm))    dcs25[8]=false;
00373       if (!dcsStatusItr->ready(DcsStatus::ESp))    dcs25[9]=false;
00374       if (!dcsStatusItr->ready(DcsStatus::ESm))    dcs25[10]=false; 
00375       if (!dcsStatusItr->ready(DcsStatus::HBHEa))  dcs25[11]=false;
00376       if (!dcsStatusItr->ready(DcsStatus::HBHEb))  dcs25[12]=false;
00377       if (!dcsStatusItr->ready(DcsStatus::HBHEc))  dcs25[13]=false; 
00378       if (!dcsStatusItr->ready(DcsStatus::HF))     dcs25[14]=false;
00379       if (!dcsStatusItr->ready(DcsStatus::HO))     dcs25[15]=false;
00380       if (!dcsStatusItr->ready(DcsStatus::BPIX))   dcs25[16]=false;
00381       if (!dcsStatusItr->ready(DcsStatus::FPIX))   dcs25[17]=false;
00382       if (!dcsStatusItr->ready(DcsStatus::RPC))    dcs25[18]=false;
00383       if (!dcsStatusItr->ready(DcsStatus::TIBTID)) dcs25[19]=false;
00384       if (!dcsStatusItr->ready(DcsStatus::TOB))    dcs25[20]=false;
00385       if (!dcsStatusItr->ready(DcsStatus::TECp))   dcs25[21]=false;
00386       if (!dcsStatusItr->ready(DcsStatus::TECm))   dcs25[22]=false;
00387       if (!dcsStatusItr->ready(DcsStatus::CASTOR)) dcs25[23]=false;
00388       if (!dcsStatusItr->ready(DcsStatus::ZDC))    dcs25[24]=false;
00389   }
00390       
00391   return ;
00392 }
00393 void 
00394 DQMProvInfo::makeHLTKeyInfo(const edm::Run& r, const edm::EventSetup &c ) 
00395 {
00396   
00397   std::string hltKey = "";
00398   HLTConfigProvider hltConfig;
00399   bool changed( true );
00400   if ( ! hltConfig.init( r, c, nameProcess_, changed) ) 
00401   {
00402     // edm::LogInfo("DQMProvInfo") << "errorHltConfigExtraction" << std::endl;
00403     hltKey = "error extraction" ;
00404   } 
00405   else if ( hltConfig.size() <= 0 ) 
00406   {
00407    // edm::LogInfo("DQMProvInfo") << "hltConfig" << std::endl;
00408     hltKey = "error key of length 0" ;
00409   } 
00410   else 
00411   {
00412     edm::LogInfo("DQMProvInfo") << "HLT key (run)  : " << hltConfig.tableName() << std::endl;
00413     hltKey =  hltConfig.tableName() ;
00414   }
00415 
00416   dbe_->cd() ;
00417   dbe_->setCurrentFolder( subsystemname_ + "/" +  provinfofolder_) ;
00418   hHltKey_= dbe_->bookString("hltKey",hltKey);
00419 
00420   return ;
00421   
00422 }
00423 void 
00424 DQMProvInfo::makeGtInfo(const edm::Event& e)
00425 {
00426 
00427   edm::Handle<L1GlobalTriggerReadoutRecord> gtrr_handle;
00428   e.getByLabel("gtDigis", gtrr_handle);
00429   L1GlobalTriggerReadoutRecord const* gtrr = gtrr_handle.product();
00430   L1GtFdlWord fdlWord ; 
00431   if (gtrr)
00432     fdlWord = gtrr->gtFdlWord();
00433   else
00434   {
00435     edm::LogWarning("DQMProvInfo") << " phys decl. bit not accessible !!!" ;
00436     physDecl_=false;
00437     return;
00438   }
00439   // cout << "phys decl. bit =" << static_cast<int>(fdlWord.physicsDeclared()) << endl;
00440   if (fdlWord.physicsDeclared() !=1) physDecl_=false;
00441 
00442 
00443   //
00444   edm::Handle<L1GlobalTriggerEvmReadoutRecord> gtEvm_handle;
00445   e.getByLabel("gtEvmDigis", gtEvm_handle);
00446   L1GlobalTriggerEvmReadoutRecord const* gtevm = gtEvm_handle.product();
00447 
00448   L1GtfeWord gtfeEvmWord;
00449   L1GtfeExtWord gtfeEvmExtWord;
00450   if (gtevm)
00451   {
00452      gtfeEvmWord = gtevm->gtfeWord();
00453      gtfeEvmExtWord = gtevm->gtfeWord();
00454   }
00455   else
00456     edm::LogInfo("DQMProvInfo") << " gtfeEvmWord inaccessible" ;
00457    
00458   lhcFill_ = gtfeEvmExtWord.lhcFillNumber();
00459   beamMode_ = gtfeEvmExtWord.beamMode();
00460   momentum_ = gtfeEvmExtWord.beamMomentum();
00461   intensity1_ = gtfeEvmExtWord.totalIntensityBeam1();
00462   intensity2_ = gtfeEvmExtWord.totalIntensityBeam2();
00463   
00464   edm::LogInfo("DQMProvInfo") << lhcFill_ << " " << beamMode_ << " " 
00465             << momentum_ << " " 
00466             << intensity1_ << " " << intensity2_ 
00467             << std::endl;
00468 
00469   return;
00470 }