CMS 3D CMS Logo

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