CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQMOffline/CalibTracker/plugins/SiStripBadComponentsDQMService.cc

Go to the documentation of this file.
00001 #include "DQMOffline/CalibTracker/plugins/SiStripBadComponentsDQMService.h"
00002 #include "DQMServices/Core/interface/MonitorElement.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00005 #include <string>
00006 #include <sstream>
00007 #include <cctype>
00008 #include <time.h>
00009 #include "boost/cstdint.hpp"
00010 #include "boost/lexical_cast.hpp"
00011 
00012 using namespace std;
00013 
00014 SiStripBadComponentsDQMService::SiStripBadComponentsDQMService(const edm::ParameterSet& iConfig,const edm::ActivityRegistry& aReg):
00015   SiStripCondObjBuilderBase<SiStripBadStrip>::SiStripCondObjBuilderBase(iConfig),
00016   iConfig_(iConfig),
00017   fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))),
00018   notAlreadyRead_(true)
00019 {
00020   obj_ = 0;
00021   edm::LogInfo("SiStripBadComponentsDQMService") <<  "[SiStripBadComponentsDQMService::SiStripBadComponentsDQMService]";
00022 }
00023 
00024 SiStripBadComponentsDQMService::~SiStripBadComponentsDQMService()
00025 {
00026   edm::LogInfo("SiStripBadComponentsDQMService") <<  "[SiStripBadComponentsDQMService::~SiStripBadComponentsDQMService]";
00027 }
00028 
00029 void SiStripBadComponentsDQMService::getMetaDataString(std::stringstream& ss)
00030 {
00031   ss << "Run " << getRunNumber() << std::endl;
00032   readBadComponents();
00033   obj_->printSummary(ss);
00034 }
00035 
00036 bool SiStripBadComponentsDQMService::checkForCompatibility(std::string ss)
00037 {
00038   std::stringstream localString;
00039   getMetaDataString(localString);
00040   if( ss == localString.str() ) return false;
00041 
00042   return true;
00043 }
00044 
00045 void SiStripBadComponentsDQMService::readBadComponents()
00046 {
00047   // Do this only if it was not already read
00048   if( notAlreadyRead_ ) {
00049     //*LOOP OVER THE LIST OF SUMMARY OBJECTS TO INSERT IN DB*//
00050 
00051       openRequestedFile();
00052 
00053     std::cout << "[readBadComponents]: opened requested file" << std::endl;
00054 
00055     obj_=new SiStripBadStrip();
00056 
00057     SiStripDetInfoFileReader reader(fp_.fullPath());
00058 
00059     dqmStore_->cd();
00060 
00061     std::string mdir = "MechanicalView";
00062     if (!goToDir(dqmStore_, mdir)) return;
00063     std::string mechanicalview_dir = dqmStore_->pwd();
00064 
00065     std::vector<std::string> subdet_folder;
00066     subdet_folder.push_back("TIB");
00067     subdet_folder.push_back("TOB");
00068     subdet_folder.push_back("TEC/side_1");
00069     subdet_folder.push_back("TEC/side_2");
00070     subdet_folder.push_back("TID/side_1");
00071     subdet_folder.push_back("TID/side_2");
00072 
00073     int nDetsTotal = 0;
00074     int nDetsWithErrorTotal = 0;
00075     for( std::vector<std::string>::const_iterator im = subdet_folder.begin(); im != subdet_folder.end(); ++im ) {
00076       std::string dname = mechanicalview_dir + "/" + (*im);
00077       if (!dqmStore_->dirExists(dname)) continue;
00078 
00079       dqmStore_->cd(dname);
00080       std::vector<std::string> module_folders;
00081       getModuleFolderList(dqmStore_, module_folders);
00082       int nDets = module_folders.size();
00083 
00084       int nDetsWithError = 0;
00085       std::string bad_module_folder = dname + "/" + "BadModuleList";
00086       if (dqmStore_->dirExists(bad_module_folder)) {
00087         std::vector<MonitorElement *> meVec = dqmStore_->getContents(bad_module_folder);
00088         for( std::vector<MonitorElement *>::const_iterator it = meVec.begin(); it != meVec.end(); ++it ) {
00089           nDetsWithError++;
00090           std::cout << (*it)->getName() <<  " " << (*it)->getIntValue() << std::endl;
00091           uint32_t detId = boost::lexical_cast<uint32_t>((*it)->getName());
00092           short flag = (*it)->getIntValue();
00093 
00094           std::vector<unsigned int> theSiStripVector;
00095 
00096           unsigned short firstBadStrip=0, NconsecutiveBadStrips=0;
00097           unsigned int theBadStripRange;
00098 
00099           // for(std::vector<uint32_t>::const_iterator is=BadApvList_.begin(); is!=BadApvList_.end(); ++is){
00100 
00101           //   firstBadStrip=(*is)*128;
00102           NconsecutiveBadStrips=reader.getNumberOfApvsAndStripLength(detId).first*128;
00103 
00104           theBadStripRange = obj_->encode(firstBadStrip,NconsecutiveBadStrips,flag);
00105 
00106           LogDebug("SiStripBadComponentsDQMService") << "detid " << detId << " \t"
00107                                                      << ", flag " << flag
00108                                                      << std::endl;
00109 
00110           theSiStripVector.push_back(theBadStripRange);
00111           // }
00112 
00113           SiStripBadStrip::Range range(theSiStripVector.begin(),theSiStripVector.end());
00114           if ( !obj_->put(detId,range) ) {
00115             edm::LogError("SiStripBadFiberBuilder")<<"[SiStripBadFiberBuilder::analyze] detid already exists"<<std::endl;
00116           }
00117         }
00118       }
00119       nDetsTotal += nDets;
00120       nDetsWithErrorTotal += nDetsWithError;        
00121     }
00122     dqmStore_->cd();
00123   }
00124 }
00125 
00126 void SiStripBadComponentsDQMService::openRequestedFile()
00127 {
00128   dqmStore_ = edm::Service<DQMStore>().operator->();
00129 
00130   // ** FIXME ** // 
00131   dqmStore_->setVerbose(0); //add config param
00132 
00133   if( iConfig_.getParameter<bool>("accessDQMFile") ){
00134     
00135     std::string fileName = iConfig_.getUntrackedParameter<std::string>("FILE_NAME","");
00136     
00137     edm::LogInfo("SiStripBadComponentsDQMService") <<  "[SiStripBadComponentsDQMService::openRequestedFile] Accessing root File" << fileName;
00138 
00139     dqmStore_->open(fileName, false); 
00140   } else {
00141     edm::LogInfo("SiStripBadComponentsDQMService") <<  "[SiStripBadComponentsDQMService::openRequestedFile] Accessing dqmStore stream in Online Operation";
00142   }
00143 }
00144  
00145 uint32_t SiStripBadComponentsDQMService::getRunNumber() const {
00146   edm::LogInfo("SiStripBadComponentsDQMService") <<  "[SiStripBadComponentsDQMService::getRunNumber] " << iConfig_.getParameter<uint32_t>("RunNb");
00147   return iConfig_.getParameter<uint32_t>("RunNb");
00148 }
00149 
00150 bool SiStripBadComponentsDQMService::goToDir(DQMStore * dqm_store, std::string name)
00151 {
00152   std::string currDir = dqm_store->pwd();
00153   std::string dirName = currDir.substr(currDir.find_last_of("/")+1);
00154   if (dirName.find(name) == 0) {
00155     return true;
00156   }
00157   std::vector<std::string> subDirVec = dqm_store->getSubdirs();
00158   for (std::vector<std::string>::const_iterator ic = subDirVec.begin();
00159        ic != subDirVec.end(); ic++) {
00160     dqm_store->cd(*ic);
00161     if (!goToDir(dqm_store, name))  dqm_store->goUp();
00162     else return true;
00163   }
00164   return false;
00165 }
00166 
00167 void SiStripBadComponentsDQMService::getModuleFolderList(DQMStore * dqm_store, std::vector<std::string>& mfolders)
00168 {
00169   std::string currDir = dqm_store->pwd();
00170   if (currDir.find("module_") != std::string::npos)  {
00171     //    std::string mId = currDir.substr(currDir.find("module_")+7, 9);
00172     mfolders.push_back(currDir);
00173   } else {  
00174     std::vector<std::string> subdirs = dqm_store->getSubdirs();
00175     for( std::vector<std::string>::const_iterator it = subdirs.begin();
00176          it != subdirs.end(); ++it) {
00177       dqm_store->cd(*it);
00178       getModuleFolderList(dqm_store, mfolders);
00179       dqm_store->goUp();
00180     }
00181   }
00182 }