CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/DQM/SiStripCommissioningDbClients/src/PedsFullNoiseHistosUsingDb.cc

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