CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQM/SiStripCommissioningClients/src/FastFedCablingHistograms.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommissioningClients/interface/FastFedCablingHistograms.h"
00002 #include "CondFormats/SiStripObjects/interface/FastFedCablingAnalysis.h"
00003 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00004 #include "DQM/SiStripCommissioningAnalysis/interface/FastFedCablingAlgorithm.h"
00005 #include "DQM/SiStripCommissioningSummary/interface/FastFedCablingSummaryFactory.h"
00006 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "TProfile.h"
00009 #include <iostream>
00010 #include <sstream>
00011 #include <iomanip>
00012 
00013 using namespace std;
00014 using namespace sistrip;
00015 
00016 // -----------------------------------------------------------------------------
00018 FastFedCablingHistograms::FastFedCablingHistograms( const edm::ParameterSet& pset,
00019                                                     DQMStore* bei )
00020   : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("FastFedCablingParameters"),
00021                              bei,
00022                              sistrip::FAST_CABLING )
00023 {
00024   factory_ = auto_ptr<FastFedCablingSummaryFactory>( new FastFedCablingSummaryFactory );
00025   LogTrace(mlDqmClient_) 
00026     << "[FastFedCablingHistograms::" << __func__ << "]"
00027     << " Constructing object...";
00028 }
00029 
00030 // -----------------------------------------------------------------------------
00032 FastFedCablingHistograms::~FastFedCablingHistograms() {
00033   LogTrace(mlDqmClient_) 
00034     << "[FastFedCablingHistograms::" << __func__ << "]"
00035     << " Destructing object...";
00036 }
00037 
00038 // -----------------------------------------------------------------------------         
00040 void FastFedCablingHistograms::histoAnalysis( bool debug ) {
00041   LogTrace(mlDqmClient_)
00042     << "[FastFedCablingHistograms::" << __func__ << "]";
00043 
00044   // Some initialisation
00045   uint16_t valid = 0;
00046   HistosMap::const_iterator iter;
00047   Analyses::iterator ianal;
00048   std::map<std::string,uint16_t> errors;
00049   
00050   // Clear map holding analysis objects
00051   for ( ianal = data().begin(); ianal != data().end(); ianal++ ) { 
00052     if ( ianal->second ) { delete ianal->second; }
00053   } 
00054   data().clear();
00055   
00056   // Iterate through map containing histograms
00057   for ( iter = histos().begin(); 
00058         iter != histos().end(); iter++ ) {
00059     
00060     // Check vector of histos is not empty
00061     if ( iter->second.empty() ) {
00062       edm::LogWarning(mlDqmClient_)
00063         << "[FastFedCablingHistograms::" << __func__ << "]"
00064         << " Zero histograms found!";
00065       continue;
00066     }
00067     
00068     // Retrieve pointers to histos
00069     std::vector<TH1*> profs;
00070     Histos::const_iterator ihis = iter->second.begin(); 
00071     for ( ; ihis != iter->second.end(); ihis++ ) {
00072       TProfile* prof = ExtractTObject<TProfile>().extract( (*ihis)->me_ );
00073       if ( prof ) { profs.push_back(prof); }
00074     } 
00075     
00076     // Perform histo analysis
00077     FastFedCablingAnalysis* anal = new FastFedCablingAnalysis( iter->first );
00078     FastFedCablingAlgorithm algo( this->pset(), anal );
00079     FedToFecMap::const_iterator ifed = mapping().find( iter->first );
00080     if ( ifed != mapping().end() ) { anal->fecKey( ifed->second ); }
00081     algo.analysis( profs );
00082     data()[iter->first] = anal; 
00083     if ( anal->isValid() ) { valid++; }
00084     if ( !anal->getErrorCodes().empty() ) { 
00085       errors[anal->getErrorCodes()[0]]++;
00086     }
00087     
00088   }
00089   
00090   if ( !histos().empty() ) {
00091     edm::LogVerbatim(mlDqmClient_) 
00092       << "[FastFedCablingHistograms::" << __func__ << "]"
00093       << " Analyzed histograms for " << histos().size() 
00094       << " FED channels, of which " << valid 
00095       << " (" << 100 * valid / histos().size()
00096       << "%) are valid.";
00097     if ( !errors.empty() ) {
00098       uint16_t count = 0;
00099       std::stringstream ss;
00100       ss << std::endl;
00101       std::map<std::string,uint16_t>::const_iterator ii;
00102       for ( ii = errors.begin(); ii != errors.end(); ++ii ) { 
00103         ss << " " << ii->first << ": " << ii->second << std::endl;
00104         count += ii->second;
00105       }
00106       edm::LogWarning(mlDqmClient_) 
00107         << "[FastFedCablingHistograms::" << __func__ << "]"
00108         << " Found " << count << " error strings: "
00109         << ss.str();
00110     }
00111   } else {
00112     edm::LogWarning(mlDqmClient_) 
00113       << "[FastFedCablingHistograms::" << __func__ << "]"
00114       << " No histograms to analyze!";
00115   }
00116   
00117 }
00118 
00119 // -----------------------------------------------------------------------------
00121 void FastFedCablingHistograms::printAnalyses() {
00122   Analyses::iterator ianal = data().begin();
00123   Analyses::iterator janal = data().end();
00124   for ( ; ianal != janal; ++ianal ) { 
00125 
00126     FastFedCablingAnalysis* anal = dynamic_cast<FastFedCablingAnalysis*>( ianal->second );
00127     if ( !anal ) { 
00128       edm::LogError(mlDqmClient_)
00129         << "[FastFedCablingHistograms::" << __func__ << "]"
00130         << " NULL pointer to analysis object!";
00131       continue; 
00132     }
00133 
00134     std::stringstream ss;
00135     anal->print( ss ); 
00136     if ( anal->isValid() &&
00137          !(anal->isDirty()) && 
00138          !(anal->badTrimDac()) ) { LogTrace(mlDqmClient_) << ss.str(); 
00139     } else { edm::LogWarning(mlDqmClient_) << ss.str(); }
00140 
00141   }
00142 
00143 }
00144 
00145 // -----------------------------------------------------------------------------
00147 void FastFedCablingHistograms::printSummary() {
00148 
00149   std::stringstream good;
00150   std::stringstream bad;
00151   
00152   Analyses::iterator ianal = data().begin();
00153   Analyses::iterator janal = data().end();
00154   for ( ; ianal != janal; ++ianal ) { 
00155 
00156     FastFedCablingAnalysis* anal = dynamic_cast<FastFedCablingAnalysis*>( ianal->second );
00157     if ( !anal ) { 
00158       edm::LogError(mlDqmClient_)
00159         << "[FastFedCablingHistograms::" << __func__ << "]"
00160         << " NULL pointer to analysis object!";
00161       continue; 
00162     }
00163 
00164     if ( anal->isValid() &&
00165          !(anal->isDirty()) && 
00166          !(anal->badTrimDac()) ) { 
00167       anal->summary( good ); 
00168     } else { anal->summary( bad ); }
00169 
00170   }
00171 
00172   if ( good.str().empty() ) { good << "None found!"; }
00173   LogTrace(mlDqmClient_) 
00174     << "[FastFedCablingHistograms::" << __func__ << "]"
00175     << " Printing summary of good analyses:" << "\n"
00176     << good.str();
00177   
00178   if ( bad.str().empty() ) { return; } //@@ bad << "None found!"; }
00179   LogTrace(mlDqmClient_) 
00180     << "[FastFedCablingHistograms::" << __func__ << "]"
00181     << " Printing summary of bad analyses:" << "\n"
00182     << bad.str();
00183   
00184 }