CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/DQM/BeamMonitor/plugins/TKStatus.cc

Go to the documentation of this file.
00001 #include "FWCore/ServiceRegistry/interface/Service.h"
00002 #include "DataFormats/Scalers/interface/DcsStatus.h"
00003 #include "FWCore/Framework/interface/Run.h"
00004 #include "FWCore/Framework/interface/LuminosityBlock.h"
00005 #include "FWCore/Framework/interface/MakerMacros.h"
00006 #include "DQM/BeamMonitor/plugins/TKStatus.h"
00007 #include <iostream>
00008 
00009 using namespace edm;
00010 
00011 TKStatus::TKStatus( const ParameterSet& ps ) : 
00012   checkStatus_(true) {
00013   parameters_     = ps;
00014   dcsTkFileName_  = parameters_.getParameter<ParameterSet>("BeamFitter").getUntrackedParameter<std::string>("DIPFileName");
00015   for (int i=0;i<6;i++) dcsTk[i]=true;
00016   countLumi_ = lastlumi_ = 0;
00017   runnum = -1;
00018 }
00019 
00020 TKStatus::~TKStatus() {
00021 
00022 }
00023 
00024 //--------------------------------------------------------
00025 void TKStatus::beginJob() {
00026 }
00027 
00028 //--------------------------------------------------------
00029 void TKStatus::beginRun(const edm::Run& r, const EventSetup& context) {
00030   runnum = r.run();
00031 }
00032 
00033 //--------------------------------------------------------
00034 void TKStatus::beginLuminosityBlock(const LuminosityBlock& lumiSeg, 
00035                                     const EventSetup& context) {
00036   int nthlumi = lumiSeg.luminosityBlock();
00037   if (nthlumi <= lastlumi_) return;
00038   checkStatus_ = true;
00039   lastlumi_ = nthlumi;
00040 }
00041 
00042 // ----------------------------------------------------------
00043 void TKStatus::analyze(const Event& iEvent, 
00044                        const EventSetup& iSetup ) {
00045   if (checkStatus_) { // check every LS
00046     // Checking TK status
00047     Handle<DcsStatusCollection> dcsStatus;
00048     iEvent.getByLabel("scalersRawToDigi", dcsStatus);
00049     for (int i=0;i<6;i++) dcsTk[i]=true;
00050     for (DcsStatusCollection::const_iterator dcsStatusItr = dcsStatus->begin(); 
00051          dcsStatusItr != dcsStatus->end(); ++dcsStatusItr) {
00052       if (!dcsStatusItr->ready(DcsStatus::BPIX))   dcsTk[0]=false;
00053       if (!dcsStatusItr->ready(DcsStatus::FPIX))   dcsTk[1]=false;
00054       if (!dcsStatusItr->ready(DcsStatus::TIBTID)) dcsTk[2]=false;
00055       if (!dcsStatusItr->ready(DcsStatus::TOB))    dcsTk[3]=false;
00056       if (!dcsStatusItr->ready(DcsStatus::TECp))   dcsTk[4]=false;
00057       if (!dcsStatusItr->ready(DcsStatus::TECm))   dcsTk[5]=false;
00058     }
00059     dumpTkDcsStatus(dcsTkFileName_);
00060     checkStatus_ = false;
00061   }
00062 }
00063 
00064 //--------------------------------------------------------
00065 void TKStatus::endLuminosityBlock(const LuminosityBlock& lumiSeg, 
00066                                   const EventSetup& iSetup) {
00067   int nlumi = lumiSeg.id().luminosityBlock();
00068   if (nlumi <= lastlumi_ ) return;
00069 
00070 }
00071 
00072 //--------------------------------------------------------
00073 void TKStatus::endRun(const Run& r, const EventSetup& context){
00074 
00075 }
00076 
00077 //--------------------------------------------------------
00078 void TKStatus::endJob(const LuminosityBlock& lumiSeg, 
00079                       const EventSetup& iSetup){
00080 
00081 }
00082 
00083 //--------------------------------------------------------
00084 void TKStatus::dumpTkDcsStatus(std::string & fileName){
00085   std::ofstream outFile;
00086   std::string tmpname = fileName;
00087   char index[10];
00088   sprintf(index,"%s","_TkStatus");
00089   tmpname.insert(fileName.length()-4,index);
00090 
00091   outFile.open(tmpname.c_str());
00092   outFile << "BPIX " << (dcsTk[0]?"On":"Off") << std::endl;
00093   outFile << "FPIX " << (dcsTk[1]?"On":"Off") << std::endl;
00094   outFile << "TIBTID " << (dcsTk[2]?"On":"Off") << std::endl;
00095   outFile << "TOB " << (dcsTk[3]?"On":"Off") << std::endl;
00096   outFile << "TECp " << (dcsTk[4]?"On":"Off") << std::endl;
00097   outFile << "TECm " << (dcsTk[5]?"On":"Off") << std::endl;
00098   bool AllTkOn = true;
00099   for (int i=0; i<5; i++) {
00100     if (!dcsTk[i]) {
00101       AllTkOn = false;
00102       break;
00103     }
00104   }
00105   outFile << "WholeTrackerOn " << (AllTkOn?"Yes":"No") << std::endl;
00106   outFile << "Runnumber " << runnum << std::endl;
00107  
00108   outFile.close();
00109 }
00110 
00111 DEFINE_FWK_MODULE(TKStatus);