CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DQM/SiStripCommissioningDbClients/src/PedestalsHistosUsingDb.cc

Go to the documentation of this file.
00001 // Last commit: $Id: PedestalsHistosUsingDb.cc,v 1.27 2010/04/21 14:26:28 dstrom Exp $
00002 
00003 #include "DQM/SiStripCommissioningDbClients/interface/PedestalsHistosUsingDb.h"
00004 #include "CondFormats/SiStripObjects/interface/PedestalsAnalysis.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 PedestalsHistosUsingDb::PedestalsHistosUsingDb( const edm::ParameterSet & pset,
00016                                                 DQMStore* bei,
00017                                                 SiStripConfigDb* const db ) 
00018   : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("PedestalsParameters"),
00019                              bei,
00020                              sistrip::PEDESTALS ),
00021     CommissioningHistosUsingDb( db,
00022                                 sistrip::PEDESTALS ),
00023     PedestalsHistograms( pset.getParameter<edm::ParameterSet>("PedestalsParameters"),
00024                          bei )
00025 {
00026   LogTrace(mlDqmClient_) 
00027     << "[PedestalsHistosUsingDb::" << __func__ << "]"
00028     << " Constructing object...";
00029   highThreshold_ = this->pset().getParameter<double>("HighThreshold");
00030   lowThreshold_ = this->pset().getParameter<double>("LowThreshold");
00031   LogTrace(mlDqmClient_)
00032     << "[PedestalsHistosUsingDb::" << __func__ << "]"
00033     << " Set FED zero suppression high/low threshold to "
00034     << highThreshold_ << "/" << lowThreshold_;
00035   disableBadStrips_ = this->pset().getParameter<bool>("DisableBadStrips");
00036   keepStripsDisabled_ = this->pset().getParameter<bool>("KeepStripsDisabled");
00037   LogTrace(mlDqmClient_)
00038     << "[PedestalsHistosUsingDb::" << __func__ << "]"
00039     << " Disabling strips: " << disableBadStrips_
00040     << " ; keeping previously disabled strips: " << keepStripsDisabled_;
00041 }
00042 
00043 // -----------------------------------------------------------------------------
00045 PedestalsHistosUsingDb::~PedestalsHistosUsingDb() {
00046   LogTrace(mlDqmClient_) 
00047     << "[PedestalsHistosUsingDb::" << __func__ << "]"
00048     << " Destructing object...";
00049 }
00050 
00051 // -----------------------------------------------------------------------------
00053 void PedestalsHistosUsingDb::uploadConfigurations() {
00054   LogTrace(mlDqmClient_) 
00055     << "[PedestalsHistosUsingDb::" << __func__ << "]";
00056 
00057   if ( !db() ) {
00058     edm::LogError(mlDqmClient_) 
00059       << "[PedestalsHistosUsingDb::" << __func__ << "]"
00060       << " NULL pointer to SiStripConfigDb interface!"
00061       << " Aborting upload...";
00062     return;
00063   }
00064   
00065   // Update FED descriptions with new peds/noise values
00066   SiStripConfigDb::FedDescriptionsRange feds = db()->getFedDescriptions(); 
00067   update( feds );
00068   if ( doUploadConf() ) { 
00069     edm::LogVerbatim(mlDqmClient_) 
00070       << "[PedestalsHistosUsingDb::" << __func__ << "]"
00071       << " Uploading pedestals/noise to DB...";
00072     db()->uploadFedDescriptions();
00073     edm::LogVerbatim(mlDqmClient_) 
00074       << "[PedestalsHistosUsingDb::" << __func__ << "]"
00075       << " Completed database upload of " << feds.size() 
00076       << " FED descriptions!";
00077   } else {
00078     edm::LogWarning(mlDqmClient_) 
00079       << "[PedestalsHistosUsingDb::" << __func__ << "]"
00080       << " TEST! No pedestals/noise values will be uploaded to DB...";
00081   }
00082   
00083 }
00084 
00085 // -----------------------------------------------------------------------------
00087 void PedestalsHistosUsingDb::update( SiStripConfigDb::FedDescriptionsRange feds ) {
00088  
00089   // Iterate through feds and update fed descriptions
00090   uint16_t updated = 0;
00091   SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
00092   for ( ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
00093     
00094     for ( uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++ ) {
00095 
00096       // Build FED and FEC keys
00097       const FedChannelConnection& conn = cabling()->connection( (*ifed)->getFedId(), ichan );
00098       if ( conn.fecCrate() == sistrip::invalid_ ||
00099            conn.fecSlot() == sistrip::invalid_ ||
00100            conn.fecRing() == sistrip::invalid_ ||
00101            conn.ccuAddr() == sistrip::invalid_ ||
00102            conn.ccuChan() == sistrip::invalid_ ||
00103            conn.lldChannel() == sistrip::invalid_ ) { continue; }
00104       SiStripFedKey fed_key( conn.fedId(), 
00105                              SiStripFedKey::feUnit( conn.fedCh() ),
00106                              SiStripFedKey::feChan( conn.fedCh() ) );
00107       SiStripFecKey fec_key( conn.fecCrate(), 
00108                              conn.fecSlot(), 
00109                              conn.fecRing(), 
00110                              conn.ccuAddr(), 
00111                              conn.ccuChan(), 
00112                              conn.lldChannel() );
00113 
00114       // Locate appropriate analysis object 
00115       Analyses::const_iterator iter = data().find( fec_key.key() );
00116       if ( iter != data().end() ) {
00117 
00118          PedestalsAnalysis* anal = dynamic_cast<PedestalsAnalysis*>( iter->second );
00119          if ( !anal ) { 
00120            edm::LogError(mlDqmClient_)
00121              << "[PedestalsHistosUsingDb::" << __func__ << "]"
00122              << " NULL pointer to analysis object!";
00123            continue; 
00124          }
00125 
00126         // Determine the pedestal shift to apply
00127         uint32_t pedshift = 127;
00128         for ( uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++ ) {
00129           uint32_t pedmin = (uint32_t) anal->pedsMin()[iapv];
00130           pedshift = pedmin < pedshift ? pedmin : pedshift;
00131         }
00132 
00133         // Iterate through APVs and strips
00134         for ( uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++ ) {
00135           for ( uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++ ) { 
00136 
00137             // get the information on the strip as it was on the db
00138             Fed9U::Fed9UAddress addr( ichan, iapv, istr );
00139             Fed9U::Fed9UStripDescription temp = (*ifed)->getFedStrips().getStrip( addr );
00140 
00141             // determine whether we need to disable the strip
00142             bool disableStrip = false;
00143             if ( keepStripsDisabled_ ) {
00144               disableStrip = temp.getDisable();
00145             } else if (disableBadStrips_) {
00146               PedestalsAnalysis::VInt dead = anal->dead()[iapv];
00147               if ( find( dead.begin(), dead.end(), istr ) != dead.end() ) disableStrip = true;
00148               PedestalsAnalysis::VInt noisy = anal->noisy()[iapv];
00149               if ( find( noisy.begin(), noisy.end(), istr ) != noisy.end() ) disableStrip = true;
00150             }
00151 
00152             Fed9U::Fed9UStripDescription data( static_cast<uint32_t>( anal->peds()[iapv][istr]-pedshift ),
00153                                                highThreshold_,
00154                                                lowThreshold_,
00155                                                anal->noise()[iapv][istr],
00156                                                disableStrip );
00157 
00158             std::stringstream ss;
00159             if ( data.getDisable() && edm::isDebugEnabled() ) {
00160               ss << "[PedestalsHistosUsingDb::" << __func__ << "]"
00161                  << " Disabling strip in Fed9UStripDescription object..." << std::endl
00162                  << " for FED id/channel and APV/strip : "
00163                  << fed_key.fedId() << "/"
00164                  << fed_key.fedChannel() << " "
00165                  << iapv << "/"
00166                  << istr << std::endl 
00167                  << " and crate/FEC/ring/CCU/module    : "
00168                  << fec_key.fecCrate() << "/"
00169                  << fec_key.fecSlot() << "/"
00170                  << fec_key.fecRing() << "/"
00171                  << fec_key.ccuAddr() << "/"
00172                  << fec_key.ccuChan() << std::endl 
00173                  << " from ped/noise/high/low/disable  : "
00174                  << static_cast<uint16_t>( temp.getPedestal() ) << "/" 
00175                  << static_cast<uint16_t>( temp.getHighThreshold() ) << "/" 
00176                  << static_cast<uint16_t>( temp.getLowThreshold() ) << "/" 
00177                  << static_cast<uint16_t>( temp.getNoise() ) << "/" 
00178                  << static_cast<uint16_t>( temp.getDisable() ) << std::endl;
00179             }
00180             (*ifed)->getFedStrips().setStrip( addr, data );
00181             if ( data.getDisable() && edm::isDebugEnabled() ) {
00182               ss << " to ped/noise/high/low/disable    : "
00183                  << static_cast<uint16_t>( data.getPedestal() ) << "/" 
00184                  << static_cast<uint16_t>( data.getHighThreshold() ) << "/" 
00185                  << static_cast<uint16_t>( data.getLowThreshold() ) << "/" 
00186                  << static_cast<uint16_t>( data.getNoise() ) << "/" 
00187                  << static_cast<uint16_t>( data.getDisable() ) << std::endl;
00188               LogTrace(mlDqmClient_) << ss.str();
00189             }
00190     
00191           } // end loop on strips
00192         } // end loop on apvs
00193         updated++;
00194       
00195       } else {
00196         if ( deviceIsPresent(fec_key) ) {
00197           edm::LogWarning(mlDqmClient_) 
00198             << "[PedestalsHistosUsingDb::" << __func__ << "]"
00199             << " Unable to find pedestals/noise for FedKey/Id/Ch: " 
00200             << hex << setw(8) << setfill('0') << fed_key.key() << dec << "/"
00201             << (*ifed)->getFedId() << "/"
00202             << ichan
00203             << " and device with FEC/slot/ring/CCU/LLD " 
00204             << fec_key.fecCrate() << "/"
00205             << fec_key.fecSlot() << "/"
00206             << fec_key.fecRing() << "/"
00207             << fec_key.ccuAddr() << "/"
00208             << fec_key.ccuChan() << "/"
00209             << fec_key.channel();
00210         }
00211       }
00212     }
00213   }
00214   
00215   edm::LogVerbatim(mlDqmClient_) 
00216     << "[PedestalsHistosUsingDb::" << __func__ << "]"
00217     << " Updated FED pedestals/noise for " 
00218     << updated << " channels";
00219 
00220 }
00221 
00222 // -----------------------------------------------------------------------------
00224 void PedestalsHistosUsingDb::create( SiStripConfigDb::AnalysisDescriptionsV& desc,
00225                                      Analysis analysis ) {
00226 
00227   PedestalsAnalysis* anal = dynamic_cast<PedestalsAnalysis*>( analysis->second );
00228   if ( !anal ) { return; }
00229   
00230   SiStripFecKey fec_key( anal->fecKey() );
00231   SiStripFedKey fed_key( anal->fedKey() );
00232   
00233   for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
00234     
00235     // Create description
00236     PedestalsAnalysisDescription* tmp;
00237     tmp = new PedestalsAnalysisDescription( 
00238       anal->dead()[iapv],
00239       anal->noisy()[iapv],
00240       anal->pedsMean()[iapv],
00241       anal->pedsSpread()[iapv],
00242       anal->noiseMean()[iapv],
00243       anal->noiseSpread()[iapv],
00244       anal->rawMean()[iapv],
00245       anal->rawSpread()[iapv],
00246       anal->pedsMax()[iapv], 
00247       anal->pedsMin()[iapv], 
00248       anal->noiseMax()[iapv],
00249       anal->noiseMin()[iapv],
00250       anal->rawMax()[iapv],
00251       anal->rawMin()[iapv],
00252       fec_key.fecCrate(),
00253       fec_key.fecSlot(),
00254       fec_key.fecRing(),
00255       fec_key.ccuAddr(),
00256       fec_key.ccuChan(),
00257       SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ), 
00258       db()->dbParams().partitions().begin()->second.partitionName(),
00259       db()->dbParams().partitions().begin()->second.runNumber(),
00260       anal->isValid(),
00261       "",
00262       fed_key.fedId(),
00263       fed_key.feUnit(),
00264       fed_key.feChan(),
00265       fed_key.fedApv()
00266     );
00267     
00268     // Add comments
00269     typedef std::vector<std::string> Strings;
00270     Strings errors = anal->getErrorCodes();
00271     Strings::const_iterator istr = errors.begin();
00272     Strings::const_iterator jstr = errors.end();
00273     for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
00274 
00275     // Store description
00276     desc.push_back( tmp );
00277       
00278   }
00279 
00280 }
00281