CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DQMOffline/CalibTracker/plugins/SiStripBadComponentsDQMServiceReader.cc

Go to the documentation of this file.
00001 #include "CondFormats/SiStripObjects/interface/SiStripBadStrip.h"
00002 #include "CondFormats/DataRecord/interface/SiStripBadStripRcd.h"
00003 
00004 #include "DQMOffline/CalibTracker/plugins/SiStripBadComponentsDQMServiceReader.h"
00005 
00006 #include <iostream>
00007 #include <stdio.h>
00008 #include <sys/time.h>
00009 
00010 #include <boost/lexical_cast.hpp>
00011 
00012 using namespace std;
00013 
00014 SiStripBadComponentsDQMServiceReader::SiStripBadComponentsDQMServiceReader( const edm::ParameterSet& iConfig ):
00015   printdebug_(iConfig.getUntrackedParameter<bool>("printDebug",true)){}
00016 
00017 SiStripBadComponentsDQMServiceReader::~SiStripBadComponentsDQMServiceReader(){}
00018 
00019 void SiStripBadComponentsDQMServiceReader::analyze( const edm::Event& e, const edm::EventSetup& iSetup)
00020 {
00021   uint32_t FedErrorMask = 1;     // bit 0
00022   uint32_t DigiErrorMask = 2;    // bit 1
00023   uint32_t ClusterErrorMask = 4; // bit 2
00024 
00025   edm::ESHandle<SiStripBadStrip> SiStripBadStrip_;
00026   iSetup.get<SiStripBadStripRcd>().get(SiStripBadStrip_);
00027   edm::LogInfo("SiStripBadComponentsDQMServiceReader") << "[SiStripBadComponentsDQMServiceReader::analyze] End Reading SiStripBadStrip" << std::endl;
00028 
00029   std::vector<uint32_t> detid;
00030   SiStripBadStrip_->getDetIds(detid);
00031 
00032   std::stringstream ss;
00033 
00034   // ss << " detid" << " \t\t\t" << "FED error" << " \t" << "Digi test failed" << " \t" << "Cluster test failed" << std::endl;
00035 
00036   ss << "subdet  layer   stereo  side \t detId \t\t Errors" << std::endl;
00037 
00038   for (size_t id=0;id<detid.size();id++) {
00039     SiStripBadStrip::Range range=SiStripBadStrip_->getRange(detid[id]);
00040 
00041     for(int it=0;it<range.second-range.first;it++){
00042       unsigned int value=(*(range.first+it));
00043       ss << detIdToString(detid[id]) << "\t" << detid[id] << "\t";
00044 
00045       uint32_t flag = boost::lexical_cast<uint32_t>(SiStripBadStrip_->decode(value).flag);
00046 
00047       printError( ss, ((flag & FedErrorMask) == FedErrorMask), "Fed error, " );
00048       printError( ss, ((flag & DigiErrorMask) == DigiErrorMask), "Digi error, " );
00049       printError( ss, ((flag & ClusterErrorMask) == ClusterErrorMask), "Cluster error" );
00050       ss << std::endl;
00051 
00052       if (printdebug_) {
00053         ss << " firstBadStrip " <<  SiStripBadStrip_->decode(value).firstStrip << "\t "
00054            << " NconsecutiveBadStrips " << SiStripBadStrip_->decode(value).range << "\t " // << std::endl;
00055            << " flag " << SiStripBadStrip_->decode(value).flag << "\t "
00056            << " packed integer " <<  std::hex << value << std::dec << "\t " << std::endl;
00057       }
00058     }
00059     ss << std::endl;
00060   }
00061   edm::LogInfo("SiStripBadComponentsDQMServiceReader") << ss.str();
00062 }
00063 
00064 void SiStripBadComponentsDQMServiceReader::printError( std::stringstream & ss, const bool error, const std::string & errorText)
00065 {
00066   if( error ) {
00067     ss << errorText << "\t ";
00068   }
00069   else {
00070     ss << "\t\t ";
00071   }
00072 }
00073 
00074 string SiStripBadComponentsDQMServiceReader::detIdToString(const DetId & detid)
00075 {
00076   std::string detector;
00077   int layer = 0;
00078   int stereo = 0;
00079   int side = -1;
00080 
00081   // Using the operator[] if the element does not exist it is created with the default value. That is 0 for integral types.
00082   switch (detid.subdetId()) {
00083   case StripSubdetector::TIB:
00084     {
00085       TIBDetId theTIBDetId(detid.rawId());
00086       detector = "TIB";
00087       layer = theTIBDetId.layer();
00088       stereo = theTIBDetId.stereo();
00089       break;
00090     }
00091   case StripSubdetector::TOB:
00092     {
00093       TOBDetId theTOBDetId(detid.rawId());
00094       detector = "TOB";
00095       layer = theTOBDetId.layer();
00096       stereo = theTOBDetId.stereo();
00097       break;
00098     }
00099   case StripSubdetector::TEC:
00100     {
00101       TECDetId theTECDetId(detid.rawId());
00102       // is this module in TEC+ or TEC-?
00103       side = theTECDetId.side();
00104       detector = "TEC";
00105       layer = theTECDetId.wheel();
00106       stereo = theTECDetId.stereo();
00107       break;
00108     }
00109   case StripSubdetector::TID:
00110     {
00111       TIDDetId theTIDDetId(detid.rawId());
00112       // is this module in TID+ or TID-?
00113       side = theTIDDetId.side();
00114       detector = "TID";
00115       layer = theTIDDetId.wheel();
00116       stereo = theTIDDetId.stereo();
00117       break;
00118     }
00119   }
00120   std::string name( detector + "\t" + boost::lexical_cast<string>(layer) + "\t" + boost::lexical_cast<string>(stereo) + "\t" );
00121   if( side == 1 ) {
00122     name += "-";
00123   }
00124   else if ( side == 2 ) {
00125     name += "+";
00126   }
00127 //   if( side != -1 ) {
00128 //     name += boost::lexical_cast<string>(side);
00129 //   }
00130 
00131   return name;
00132 }