CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/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 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00006 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00007 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00008 
00009 #include <iostream>
00010 #include <stdio.h>
00011 #include <sys/time.h>
00012 
00013 #include <boost/lexical_cast.hpp>
00014 
00015 using namespace std;
00016 
00017 SiStripBadComponentsDQMServiceReader::SiStripBadComponentsDQMServiceReader( const edm::ParameterSet& iConfig ):
00018   printdebug_(iConfig.getUntrackedParameter<bool>("printDebug",true)){}
00019 
00020 SiStripBadComponentsDQMServiceReader::~SiStripBadComponentsDQMServiceReader(){}
00021 
00022 void SiStripBadComponentsDQMServiceReader::analyze( const edm::Event& e, const edm::EventSetup& iSetup)
00023 {
00024   //Retrieve tracker topology from geometry
00025   edm::ESHandle<TrackerTopology> tTopoHandle;
00026   iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
00027   const TrackerTopology* const tTopo = tTopoHandle.product();
00028 
00029   uint32_t FedErrorMask = 1;     // bit 0
00030   uint32_t DigiErrorMask = 2;    // bit 1
00031   uint32_t ClusterErrorMask = 4; // bit 2
00032 
00033   edm::ESHandle<SiStripBadStrip> SiStripBadStrip_;
00034   iSetup.get<SiStripBadStripRcd>().get(SiStripBadStrip_);
00035   edm::LogInfo("SiStripBadComponentsDQMServiceReader") << "[SiStripBadComponentsDQMServiceReader::analyze] End Reading SiStripBadStrip" << std::endl;
00036 
00037   std::vector<uint32_t> detid;
00038   SiStripBadStrip_->getDetIds(detid);
00039 
00040   std::stringstream ss;
00041 
00042   // ss << " detid" << " \t\t\t" << "FED error" << " \t" << "Digi test failed" << " \t" << "Cluster test failed" << std::endl;
00043 
00044   ss << "subdet  layer   stereo  side \t detId \t\t Errors" << std::endl;
00045 
00046   for (size_t id=0;id<detid.size();id++) {
00047     SiStripBadStrip::Range range=SiStripBadStrip_->getRange(detid[id]);
00048 
00049     for(int it=0;it<range.second-range.first;it++){
00050       unsigned int value=(*(range.first+it));
00051       ss << detIdToString(detid[id], tTopo) << "\t" << detid[id] << "\t";
00052 
00053       uint32_t flag = boost::lexical_cast<uint32_t>(SiStripBadStrip_->decode(value).flag);
00054 
00055       printError( ss, ((flag & FedErrorMask) == FedErrorMask), "Fed error, " );
00056       printError( ss, ((flag & DigiErrorMask) == DigiErrorMask), "Digi error, " );
00057       printError( ss, ((flag & ClusterErrorMask) == ClusterErrorMask), "Cluster error" );
00058       ss << std::endl;
00059 
00060       if (printdebug_) {
00061         ss << " firstBadStrip " <<  SiStripBadStrip_->decode(value).firstStrip << "\t "
00062            << " NconsecutiveBadStrips " << SiStripBadStrip_->decode(value).range << "\t " // << std::endl;
00063            << " flag " << SiStripBadStrip_->decode(value).flag << "\t "
00064            << " packed integer " <<  std::hex << value << std::dec << "\t " << std::endl;
00065       }
00066     }
00067     ss << std::endl;
00068   }
00069   edm::LogInfo("SiStripBadComponentsDQMServiceReader") << ss.str();
00070 }
00071 
00072 void SiStripBadComponentsDQMServiceReader::printError( std::stringstream & ss, const bool error, const std::string & errorText)
00073 {
00074   if( error ) {
00075     ss << errorText << "\t ";
00076   }
00077   else {
00078     ss << "\t\t ";
00079   }
00080 }
00081 
00082 string SiStripBadComponentsDQMServiceReader::detIdToString(const DetId & detid, const TrackerTopology* tTopo)
00083 {
00084   std::string detector;
00085   int layer = 0;
00086   int stereo = 0;
00087   int side = -1;
00088 
00089   // Using the operator[] if the element does not exist it is created with the default value. That is 0 for integral types.
00090   switch (detid.subdetId()) {
00091   case StripSubdetector::TIB:
00092     {
00093       
00094       detector = "TIB";
00095       layer = tTopo->tibLayer(detid.rawId());
00096       stereo = tTopo->tibStereo(detid.rawId());
00097       break;
00098     }
00099   case StripSubdetector::TOB:
00100     {
00101       
00102       detector = "TOB";
00103       layer = tTopo->tobLayer(detid.rawId());
00104       stereo = tTopo->tobStereo(detid.rawId());
00105       break;
00106     }
00107   case StripSubdetector::TEC:
00108     {
00109       
00110       // is this module in TEC+ or TEC-?
00111       side = tTopo->tecSide(detid.rawId());
00112       detector = "TEC";
00113       layer = tTopo->tecWheel(detid.rawId());
00114       stereo = tTopo->tecStereo(detid.rawId());
00115       break;
00116     }
00117   case StripSubdetector::TID:
00118     {
00119       
00120       // is this module in TID+ or TID-?
00121       side = tTopo->tidSide(detid.rawId());
00122       detector = "TID";
00123       layer = tTopo->tidWheel(detid.rawId());
00124       stereo = tTopo->tidStereo(detid.rawId());
00125       break;
00126     }
00127   }
00128   std::string name( detector + "\t" + boost::lexical_cast<string>(layer) + "\t" + boost::lexical_cast<string>(stereo) + "\t" );
00129   if( side == 1 ) {
00130     name += "-";
00131   }
00132   else if ( side == 2 ) {
00133     name += "+";
00134   }
00135 //   if( side != -1 ) {
00136 //     name += boost::lexical_cast<string>(side);
00137 //   }
00138 
00139   return name;
00140 }