CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/DQMOffline/CalibTracker/plugins/SiStripPedestalsDQMService.cc

Go to the documentation of this file.
00001 #include "DQMOffline/CalibTracker/plugins/SiStripPedestalsDQMService.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 
00011 using namespace std;
00012 
00013 SiStripPedestalsDQMService::SiStripPedestalsDQMService(const edm::ParameterSet& iConfig,const edm::ActivityRegistry& aReg):
00014   // SiStripCondObjBuilderBase<SiStripPedestals>::SiStripCondObjBuilderBase(iConfig),
00015   SiStripBaseServiceFromDQM<SiStripPedestals>::SiStripBaseServiceFromDQM(iConfig),
00016   iConfig_(iConfig),
00017   fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat")))
00018 {
00019   obj_ = 0;
00020   edm::LogInfo("SiStripPedestalsDQMService") <<  "[SiStripPedestalsDQMService::SiStripPedestalsDQMService]";
00021 }
00022 
00023 SiStripPedestalsDQMService::~SiStripPedestalsDQMService()
00024 {
00025   edm::LogInfo("SiStripPedestalsDQMService") <<  "[SiStripPedestalsDQMService::~SiStripPedestalsDQMService]";
00026 }
00027 
00028 void SiStripPedestalsDQMService::readPedestals()
00029 {
00030   std::cout << "SiStripPedestalsDQMService::readPedestals" << std::endl;
00031 
00032   openRequestedFile();
00033 
00034   std::cout << "[readBadComponents]: opened requested file" << std::endl;
00035 
00036   obj_= new SiStripPedestals;
00037 
00038   SiStripDetInfoFileReader reader(fp_.fullPath());
00039 
00040   // dqmStore_->cd(iConfig_.getUntrackedParameter<std::string>("ME_DIR"));
00041   dqmStore_->cd();
00042 
00043   uint32_t stripsPerApv = 128;
00044 
00045   // Get the full list of monitoring elements
00046   // const std::vector<MonitorElement*>& MEs = dqmStore_->getAllContents(iConfig_.getUntrackedParameter<std::string>("ME_DIR","DQMData"));
00047 
00048   // Take a copy of the vector
00049   std::vector<MonitorElement*> MEs = dqmStore_->getAllContents(iConfig_.getUntrackedParameter<std::string>("ME_DIR","DQMData"));
00050   // Remove all but the MEs we are using
00051   std::vector<MonitorElement*>::iterator newEnd = remove_if(MEs.begin(), MEs.end(), StringNotMatch("PedsPerStrip__det__"));
00052   MEs.erase(newEnd, MEs.end());
00053 
00054 
00055   // The histograms are one per DetId, loop on all the DetIds and extract the corresponding histogram
00056   const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo> DetInfos  = reader.getAllData();
00057   for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator it = DetInfos.begin(); it != DetInfos.end(); ++it) {
00058 
00059 
00060     SiStripPedestals::InputVector theSiStripVector;
00061 
00062     // Take the path for each DetId and build the complete path + histogram name
00063 
00064 
00065     // MonitorElement * mE = getModuleHistogram(it->first, "PedsPerStrip");
00066 
00067 
00068     MonitorElement * mE = 0;
00069     std::string MEname("PedsPerStrip__det__"+boost::lexical_cast<string>(it->first));
00070     for( std::vector<MonitorElement*>::const_iterator MEit = MEs.begin();
00071          MEit != MEs.end(); ++MEit ) {
00072       if( (*MEit)->getName() == MEname ) {
00073         mE = *MEit;
00074         break;
00075       }
00076     }
00077 
00078     // find( MEs.begin(), MEs.end(), "PedsPerStrip__det__"+boost::lexical_cast<string>(it->first), findMEbyName() );
00079     // MonitorElement * mE = *(find( MEs.begin(), MEs.end(), findMEbyName("PedsPerStrip__det__"+boost::lexical_cast<string>(it->first)) ));
00080 
00081     if( mE != 0 ) {
00082       TH1F* histo = mE->getTH1F();
00083 
00084       if( histo != 0 ) {
00085 
00086         // Read the pedestals from the histograms
00087         uint32_t nBinsX = histo->GetXaxis()->GetNbins();
00088 
00089         if( nBinsX != stripsPerApv*(it->second.nApvs) ) {
00090           std::cout << "ERROR: number of bin = " << nBinsX << " != number of strips = " << stripsPerApv*(it->second.nApvs) << std::endl;
00091         }
00092 
00093         // std::cout << "Bin 0 = " << histo->GetBinContent(0) << std::endl;
00094 
00095         // TH1 bins start from 1, 0 is the underflow, nBinsX+1 the overflow.
00096         for( uint32_t iBin = 1; iBin <= nBinsX; ++iBin ) {
00097           // encode the pedestal value and put it in the vector (push_back)
00098           obj_->setData( histo->GetBinContent(iBin), theSiStripVector );
00099         }
00100       }
00101       else {
00102         std::cout << "ERROR: histo = " << histo << std::endl;
00103       }
00104     }
00105     else {
00106       std::cout << "ERROR: ME = " << mE << std::endl;
00107     }
00108     // If the ME was absent fill the vector with 0
00109     if( theSiStripVector.empty() ) {
00110       for(unsigned short j=0; j<128*it->second.nApvs; ++j){
00111         obj_->setData(0, theSiStripVector);
00112       }
00113     }
00114 
00115     if ( ! obj_->put(it->first, theSiStripVector) )
00116       edm::LogError("SiStripPedestalsFakeESSource::produce ")<<" detid already exists"<<std::endl;
00117   }
00118   dqmStore_->cd();
00119 }