CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/DQM/SiStripCommissioningClients/src/OptoScanHistograms.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommissioningClients/interface/OptoScanHistograms.h"
00002 #include "CondFormats/SiStripObjects/interface/OptoScanAnalysis.h"
00003 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00004 #include "DQM/SiStripCommissioningAnalysis/interface/OptoScanAlgorithm.h"
00005 #include "DQM/SiStripCommissioningSummary/interface/OptoScanSummaryFactory.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 OptoScanHistograms::OptoScanHistograms( const edm::ParameterSet& pset,
00019                                         DQMStore* bei )
00020   : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("OptoScanParameters"),
00021                              bei,
00022                              sistrip::OPTO_SCAN )
00023 {
00024   factory_ = auto_ptr<OptoScanSummaryFactory>( new OptoScanSummaryFactory );
00025   LogTrace(mlDqmClient_) 
00026     << "[OptoScanHistograms::" << __func__ << "]"
00027     << " Constructing object...";
00028 }
00029 
00030 // -----------------------------------------------------------------------------
00032 OptoScanHistograms::~OptoScanHistograms() {
00033   LogTrace(mlDqmClient_) 
00034     << "[OptoScanHistograms::" << __func__ << "]"
00035     << " Denstructing object...";
00036 }
00037 
00038 // -----------------------------------------------------------------------------         
00040 void OptoScanHistograms::histoAnalysis( bool debug ) {
00041   LogTrace(mlDqmClient_)
00042     << "[OptoScanHistograms::" << __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         << "[OptoScanHistograms::" << __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     OptoScanAnalysis* anal = new OptoScanAnalysis( iter->first );
00078     OptoScanAlgorithm algo( this->pset(), anal );
00079     algo.analysis( profs );
00080     data()[iter->first] = anal; 
00081     if ( anal->isValid() ) { valid++; }
00082     if ( !anal->getErrorCodes().empty() ) { 
00083       errors[anal->getErrorCodes()[0]]++;
00084     }
00085     
00086   }
00087   
00088   if ( !histos().empty() ) {
00089     edm::LogVerbatim(mlDqmClient_) 
00090       << "[OptoScanHistograms::" << __func__ << "]"
00091       << " Analyzed histograms for " << histos().size() 
00092       << " FED channels, of which " << valid 
00093       << " (" << 100 * valid / histos().size()
00094       << "%) are valid.";
00095   } else {
00096     edm::LogWarning(mlDqmClient_) 
00097       << "[OptoScanHistograms::" << __func__ << "]"
00098       << " No histograms to analyze!";
00099   }
00100 
00101   if ( !histos().empty() ) {
00102     edm::LogVerbatim(mlDqmClient_) 
00103       << "[OptoScanHistograms::" << __func__ << "]"
00104       << " Analyzed histograms for " << histos().size() 
00105       << " FED channels, of which " << valid 
00106       << " (" << 100 * valid / histos().size()
00107       << "%) are valid.";
00108     if ( !errors.empty() ) {
00109       uint16_t count = 0;
00110       std::stringstream ss;
00111       ss << std::endl;
00112       std::map<std::string,uint16_t>::const_iterator ii;
00113       for ( ii = errors.begin(); ii != errors.end(); ++ii ) { 
00114         ss << " " << ii->first << ": " << ii->second << std::endl;
00115         count += ii->second;
00116       }
00117       edm::LogWarning(mlDqmClient_) 
00118         << "[OptoScanHistograms::" << __func__ << "]"
00119         << " Found " << count << " errors ("
00120         << 100 * count / histos().size() << "%): " 
00121         << ss.str();
00122     }
00123   } else {
00124     edm::LogWarning(mlDqmClient_) 
00125       << "[OptoScanHistograms::" << __func__ << "]"
00126       << " No histograms to analyze!";
00127   }
00128   
00129 }
00130 
00131 // -----------------------------------------------------------------------------
00133 void OptoScanHistograms::printAnalyses() {
00134   Analyses::iterator ianal = data().begin();
00135   Analyses::iterator janal = data().end();
00136   for ( ; ianal != janal; ++ianal ) {
00137     if ( ianal->second ) {
00138       std::stringstream ss;
00139       if ( ianal->second->isValid() ) {
00140         ianal->second->print( ss );
00141         LogTrace(mlDqmClient_) << ss.str();
00142       } else {
00143         ianal->second->print( ss, 0 );
00144         ianal->second->print( ss, 1 );
00145         ianal->second->print( ss, 2 );
00146         ianal->second->print( ss, 3 );
00147         edm::LogWarning(mlDqmClient_) << ss.str();
00148       }
00149     }
00150   }
00151 }
00152