CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQM/SiStripCommissioningDbClients/src/NoiseHistosUsingDb.cc

Go to the documentation of this file.
00001 // Last commit: $Id: NoiseHistosUsingDb.cc,v 1.5 2009/11/10 14:49:02 lowette Exp $
00002 
00003 #include "DQM/SiStripCommissioningDbClients/interface/NoiseHistosUsingDb.h"
00004 #include "CondFormats/SiStripObjects/interface/NoiseAnalysis.h"
00005 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00006 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
00007 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include <iostream>
00010 
00011 using namespace sistrip;
00012 
00013 // -----------------------------------------------------------------------------
00015 NoiseHistosUsingDb::NoiseHistosUsingDb( const edm::ParameterSet & pset,
00016                                         DQMStore* bei,
00017                                         SiStripConfigDb* const db ) 
00018   : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("NoiseParameters"),
00019                              bei,
00020                              sistrip::NOISE ),
00021     CommissioningHistosUsingDb( db,
00022                                 sistrip::NOISE ),
00023     NoiseHistograms( pset.getParameter<edm::ParameterSet>("NoiseParameters"),
00024                      bei )
00025 {
00026   LogTrace(mlDqmClient_) 
00027     << "[NoiseHistosUsingDb::" << __func__ << "]"
00028     << " Constructing object...";
00029 }
00030 
00031 // -----------------------------------------------------------------------------
00033 NoiseHistosUsingDb::~NoiseHistosUsingDb() {
00034   LogTrace(mlDqmClient_) 
00035     << "[NoiseHistosUsingDb::" << __func__ << "]"
00036     << " Destructing object...";
00037 }
00038 
00039 // -----------------------------------------------------------------------------
00041 void NoiseHistosUsingDb::uploadConfigurations() {
00042   LogTrace(mlDqmClient_) 
00043     << "[NoiseHistosUsingDb::" << __func__ << "]";
00044 
00045   if ( !db() ) {
00046     edm::LogError(mlDqmClient_) 
00047       << "[NoiseHistosUsingDb::" << __func__ << "]"
00048       << " NULL pointer to SiStripConfigDb interface!"
00049       << " Aborting upload...";
00050     return;
00051   }
00052   
00053   // Update FED descriptions with new peds/noise values
00054   SiStripConfigDb::FedDescriptionsRange feds = db()->getFedDescriptions(); 
00055   update( feds );
00056   if ( doUploadConf() ) { 
00057     edm::LogVerbatim(mlDqmClient_) 
00058       << "[NoiseHistosUsingDb::" << __func__ << "]"
00059       << " Uploading pedestals/noise to DB...";
00060     db()->uploadFedDescriptions();
00061     edm::LogVerbatim(mlDqmClient_) 
00062       << "[NoiseHistosUsingDb::" << __func__ << "]"
00063       << " Completed database upload of " << feds.size() 
00064       << " FED descriptions!";
00065   } else {
00066     edm::LogWarning(mlDqmClient_) 
00067       << "[NoiseHistosUsingDb::" << __func__ << "]"
00068       << " TEST only! No pedestals/noise values will be uploaded to DB...";
00069   }
00070   
00071 }
00072 
00073 // -----------------------------------------------------------------------------
00075 void NoiseHistosUsingDb::update( SiStripConfigDb::FedDescriptionsRange feds ) {
00076  
00077   // Iterate through feds and update fed descriptions
00078   uint16_t updated = 0;
00079   SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
00080   for ( ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
00081     
00082     for ( uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++ ) {
00083 
00084       // Build FED and FEC keys
00085       const FedChannelConnection& conn = cabling()->connection( (*ifed)->getFedId(), ichan );
00086       if ( conn.fecCrate() == sistrip::invalid_ ||
00087            conn.fecSlot() == sistrip::invalid_ ||
00088            conn.fecRing() == sistrip::invalid_ ||
00089            conn.ccuAddr() == sistrip::invalid_ ||
00090            conn.ccuChan() == sistrip::invalid_ ||
00091            conn.lldChannel() == sistrip::invalid_ ) { continue; }
00092       SiStripFedKey fed_key( conn.fedId(), 
00093                              SiStripFedKey::feUnit( conn.fedCh() ),
00094                              SiStripFedKey::feChan( conn.fedCh() ) );
00095       SiStripFecKey fec_key( conn.fecCrate(), 
00096                              conn.fecSlot(), 
00097                              conn.fecRing(), 
00098                              conn.ccuAddr(), 
00099                              conn.ccuChan(), 
00100                              conn.lldChannel() );
00101 
00102       // Locate appropriate analysis object 
00103       Analyses::const_iterator iter = data().find( fec_key.key() );
00104       if ( iter != data().end() ) {
00105 
00106         // Check if analysis is valid
00107         if ( !iter->second->isValid() ) { continue; }
00108         
00109         NoiseAnalysis* anal = dynamic_cast<NoiseAnalysis*>( iter->second );
00110         if ( !anal ) { 
00111           edm::LogError(mlDqmClient_)
00112             << "[NoiseHistosUsingDb::" << __func__ << "]"
00113             << " NULL pointer to analysis object!";
00114           continue; 
00115         }
00116         
00117         // Iterate through APVs and strips
00118         for ( uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++ ) {
00119           for ( uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++ ) { 
00120             
00121             static float high_threshold = 5.;
00122             static float low_threshold  = 2.;
00123             static bool  disable_strip  = false;
00124             Fed9U::Fed9UStripDescription data( static_cast<uint32_t>( anal->peds()[iapv][istr] ), 
00125                                                high_threshold, 
00126                                                low_threshold, 
00127                                                anal->noise()[iapv][istr],
00128                                                disable_strip );
00129             Fed9U::Fed9UAddress addr( ichan, iapv, istr );
00130             (*ifed)->getFedStrips().setStrip( addr, data );
00131             
00132           }
00133         }
00134         updated++;
00135       
00136       } else {
00137         edm::LogWarning(mlDqmClient_) 
00138           << "[NoiseHistosUsingDb::" << __func__ << "]"
00139           << " Unable to find pedestals/noise for FedKey/Id/Ch: " 
00140           << hex << setw(8) << setfill('0') << fed_key.key() << dec << "/"
00141           << (*ifed)->getFedId() << "/"
00142           << ichan
00143           << " and device with FEC/slot/ring/CCU/LLD " 
00144           << fec_key.fecCrate() << "/"
00145           << fec_key.fecSlot() << "/"
00146           << fec_key.fecRing() << "/"
00147           << fec_key.ccuAddr() << "/"
00148           << fec_key.ccuChan() << "/"
00149           << fec_key.channel();
00150       }
00151     }
00152   }
00153 
00154   edm::LogVerbatim(mlDqmClient_) 
00155     << "[NoiseHistosUsingDb::" << __func__ << "]"
00156     << " Updated FED pedestals/noise for " 
00157     << updated << " channels";
00158 
00159 }
00160 
00161 // -----------------------------------------------------------------------------
00163 void NoiseHistosUsingDb::create( SiStripConfigDb::AnalysisDescriptionsV& desc,
00164                                  Analysis analysis ) {
00165 
00166   NoiseAnalysis* anal = dynamic_cast<NoiseAnalysis*>( analysis->second );
00167   if ( !anal ) { return; }
00168   
00169   SiStripFecKey fec_key( anal->fecKey() );
00170   SiStripFedKey fed_key( anal->fedKey() );
00171   
00172   for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
00173     
00174     // Create description
00175     PedestalsAnalysisDescription* tmp;
00176     tmp = new PedestalsAnalysisDescription( anal->dead()[iapv],
00177                                             anal->noisy()[iapv],
00178                                             anal->pedsMean()[iapv],
00179                                             anal->pedsSpread()[iapv],
00180                                             anal->noiseMean()[iapv],
00181                                             anal->noiseSpread()[iapv],
00182                                             anal->rawMean()[iapv],
00183                                             anal->rawSpread()[iapv],
00184                                             anal->pedsMax()[iapv], 
00185                                             anal->pedsMin()[iapv], 
00186                                             anal->noiseMax()[iapv],
00187                                             anal->noiseMin()[iapv],
00188                                             anal->rawMax()[iapv],
00189                                             anal->rawMin()[iapv],
00190                                             fec_key.fecCrate(),
00191                                             fec_key.fecSlot(),
00192                                             fec_key.fecRing(),
00193                                             fec_key.ccuAddr(),
00194                                             fec_key.ccuChan(),
00195                                             SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ), 
00196                                             db()->dbParams().partitions().begin()->second.partitionName(),
00197                                             db()->dbParams().partitions().begin()->second.runNumber(),
00198                                             anal->isValid(),
00199                                             "",
00200                                             fed_key.fedId(),
00201                                             fed_key.feUnit(),
00202                                             fed_key.feChan(),
00203                                             fed_key.fedApv() );
00204     
00205     // Add comments
00206     typedef std::vector<std::string> Strings;
00207     Strings errors = anal->getErrorCodes();
00208     Strings::const_iterator istr = errors.begin();
00209     Strings::const_iterator jstr = errors.end();
00210     for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
00211 
00212     // Store description
00213     desc.push_back( tmp );
00214       
00215   }
00216 
00217 }
00218