CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/DQM/SiStripCommissioningDbClients/src/PedsOnlyHistosUsingDb.cc

Go to the documentation of this file.
00001 // Last commit: $Id: PedsOnlyHistosUsingDb.cc,v 1.7 2009/11/10 14:49:02 lowette Exp $
00002 
00003 #include "DQM/SiStripCommissioningDbClients/interface/PedsOnlyHistosUsingDb.h"
00004 #include "CondFormats/SiStripObjects/interface/PedsOnlyAnalysis.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 PedsOnlyHistosUsingDb::PedsOnlyHistosUsingDb( const edm::ParameterSet & pset,
00016                                               DQMStore* bei,
00017                                               SiStripConfigDb* const db ) 
00018   : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("PedsOnlyParameters"),
00019                              bei,
00020                              sistrip::PEDS_ONLY ),
00021     CommissioningHistosUsingDb( db,
00022                                 sistrip::PEDS_ONLY ),
00023     PedsOnlyHistograms( pset.getParameter<edm::ParameterSet>("PedsOnlyParameters"),
00024                         bei )
00025 {
00026   LogTrace(mlDqmClient_) 
00027     << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
00028     << " Constructing object...";
00029 }
00030 
00031 // -----------------------------------------------------------------------------
00033 PedsOnlyHistosUsingDb::~PedsOnlyHistosUsingDb() {
00034   LogTrace(mlDqmClient_) 
00035     << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
00036     << " Destructing object...";
00037 }
00038 
00039 // -----------------------------------------------------------------------------
00041 void PedsOnlyHistosUsingDb::uploadConfigurations() {
00042   LogTrace(mlDqmClient_) 
00043     << "[PedsOnlyHistosUsingDb::" << __func__ << "]";
00044 
00045   if ( !db() ) {
00046     edm::LogError(mlDqmClient_) 
00047       << "[PedsOnlyHistosUsingDb::" << __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       << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
00059       << " Uploading pedestals/noise to DB...";
00060     db()->uploadFedDescriptions(); 
00061     edm::LogVerbatim(mlDqmClient_) 
00062       << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
00063       << " Completed database upload of " << feds.size() 
00064       << " FED descriptions!";
00065   } else {
00066     edm::LogWarning(mlDqmClient_) 
00067       << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
00068       << " TEST only! No pedestals/noise values will be uploaded to DB...";
00069   }
00070   
00071 }
00072 
00073 // -----------------------------------------------------------------------------
00075 void PedsOnlyHistosUsingDb::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         PedsOnlyAnalysis* anal = dynamic_cast<PedsOnlyAnalysis*>( iter->second );
00110         if ( !anal ) { 
00111           edm::LogError(mlDqmClient_)
00112             << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
00113             << " NULL pointer to analysis object!";
00114           continue; 
00115         }
00116         
00117         // Determine the pedestal shift to apply
00118         uint32_t pedshift = 127;
00119         for ( uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++ ) {
00120           uint32_t pedmin = (uint32_t) anal->pedsMin()[iapv];
00121           pedshift = pedmin < pedshift ? pedmin : pedshift;
00122         }
00123 
00124         // Iterate through APVs and strips
00125         for ( uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++ ) {
00126           for ( uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++ ) { 
00127             
00128             static float high_threshold = 5.;
00129             static float low_threshold  = 2.;
00130             static bool  disable_strip  = false;
00131             Fed9U::Fed9UStripDescription data( static_cast<uint32_t>( anal->peds()[iapv][istr]-pedshift ), 
00132                                                high_threshold, 
00133                                                low_threshold, 
00134                                                anal->raw()[iapv][istr], //@@ raw noise!
00135                                                disable_strip );
00136             Fed9U::Fed9UAddress addr( ichan, iapv, istr );
00137             (*ifed)->getFedStrips().setStrip( addr, data );
00138             
00139           }
00140         }
00141         updated++;
00142       
00143       } else {
00144         edm::LogWarning(mlDqmClient_) 
00145           << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
00146           << " Unable to find pedestals/noise for FedKey/Id/Ch: " 
00147           << hex << setw(8) << setfill('0') << fed_key.key() << dec << "/"
00148           << (*ifed)->getFedId() << "/"
00149           << ichan
00150           << " and device with FEC/slot/ring/CCU/LLD " 
00151           << fec_key.fecCrate() << "/"
00152           << fec_key.fecSlot() << "/"
00153           << fec_key.fecRing() << "/"
00154           << fec_key.ccuAddr() << "/"
00155           << fec_key.ccuChan() << "/"
00156           << fec_key.channel();
00157       }
00158     }
00159   }
00160 
00161   edm::LogVerbatim(mlDqmClient_) 
00162     << "[PedsOnlyHistosUsingDb::" << __func__ << "]"
00163     << " Updated FED pedestals/noise for " 
00164     << updated << " channels";
00165 
00166 }
00167 
00168 // -----------------------------------------------------------------------------
00170 void PedsOnlyHistosUsingDb::create( SiStripConfigDb::AnalysisDescriptionsV& desc,
00171                                     Analysis analysis ) {
00172 
00173   PedsOnlyAnalysis* anal = dynamic_cast<PedsOnlyAnalysis*>( analysis->second );
00174   if ( !anal ) { return; }
00175   
00176   SiStripFecKey fec_key( anal->fecKey() );
00177   SiStripFedKey fed_key( anal->fedKey() );
00178   
00179   for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
00180     
00181     // Create description
00182     PedestalsAnalysisDescription* tmp;
00183     tmp = new PedestalsAnalysisDescription( std::vector<uint16_t>(0,0), //@@
00184                                             std::vector<uint16_t>(0,0), //@@
00185                                             anal->pedsMean()[iapv],
00186                                             anal->pedsSpread()[iapv],
00187                                             1.*sistrip::invalid_, //@@
00188                                             1.*sistrip::invalid_, //@@
00189                                             anal->rawMean()[iapv],
00190                                             anal->rawSpread()[iapv],
00191                                             anal->pedsMax()[iapv], 
00192                                             anal->pedsMin()[iapv], 
00193                                             1.*sistrip::invalid_, //@@
00194                                             1.*sistrip::invalid_, //@@
00195                                             anal->rawMax()[iapv],
00196                                             anal->rawMin()[iapv],
00197                                             fec_key.fecCrate(),
00198                                             fec_key.fecSlot(),
00199                                             fec_key.fecRing(),
00200                                             fec_key.ccuAddr(),
00201                                             fec_key.ccuChan(),
00202                                             SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ), 
00203                                             db()->dbParams().partitions().begin()->second.partitionName(),
00204                                             db()->dbParams().partitions().begin()->second.runNumber(),
00205                                             anal->isValid(),
00206                                             "",
00207                                             fed_key.fedId(),
00208                                             fed_key.feUnit(),
00209                                             fed_key.feChan(),
00210                                             fed_key.fedApv() );
00211     
00212     // Add comments
00213     typedef std::vector<std::string> Strings;
00214     Strings errors = anal->getErrorCodes();
00215     Strings::const_iterator istr = errors.begin();
00216     Strings::const_iterator jstr = errors.end();
00217     for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
00218 
00219     // Store description
00220     desc.push_back( tmp );
00221       
00222   }
00223 
00224 }
00225