CMS 3D CMS Logo

OptoScanHistosUsingDb.cc

Go to the documentation of this file.
00001 // Last commit: $Id: OptoScanHistosUsingDb.cc,v 1.17 2008/07/01 14:36:41 bainbrid Exp $
00002 
00003 #include "DQM/SiStripCommissioningDbClients/interface/OptoScanHistosUsingDb.h"
00004 #include "CondFormats/SiStripObjects/interface/OptoScanAnalysis.h"
00005 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00006 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include <iostream>
00009 
00010 using namespace sistrip;
00011 
00012 // -----------------------------------------------------------------------------
00014 OptoScanHistosUsingDb::OptoScanHistosUsingDb( DQMOldReceiver* mui,
00015                                               SiStripConfigDb* const db )
00016   : CommissioningHistograms( mui, sistrip::OPTO_SCAN ),
00017     CommissioningHistosUsingDb( db, mui, sistrip::OPTO_SCAN ),
00018     OptoScanHistograms( mui )
00019 {
00020   LogTrace(mlDqmClient_) 
00021     << "[OptoScanHistosUsingDb::" << __func__ << "]"
00022     << " Constructing object...";
00023 }
00024 
00025 // -----------------------------------------------------------------------------
00027 OptoScanHistosUsingDb::OptoScanHistosUsingDb( DQMStore* bei,
00028                                               SiStripConfigDb* const db ) 
00029   : CommissioningHistosUsingDb( db, sistrip::OPTO_SCAN ),
00030     OptoScanHistograms( bei )
00031 {
00032   LogTrace(mlDqmClient_) 
00033     << "[OptoScanHistosUsingDb::" << __func__ << "]"
00034     << " Constructing object...";
00035 }
00036 
00037 // -----------------------------------------------------------------------------
00039 OptoScanHistosUsingDb::~OptoScanHistosUsingDb() {
00040   LogTrace(mlDqmClient_) 
00041     << "[OptoScanHistosUsingDb::" << __func__ << "]"
00042     << " Destructing object...";
00043 }
00044 
00045 // -----------------------------------------------------------------------------
00047 void OptoScanHistosUsingDb::uploadConfigurations() {
00048   LogTrace(mlDqmClient_) 
00049     << "[OptoScanHistosUsingDb::" << __func__ << "]";
00050 
00051   if ( !db() ) {
00052     edm::LogError(mlDqmClient_) 
00053       << "[OptoScanHistosUsingDb::" << __func__ << "]"
00054       << " NULL pointer to SiStripConfigDb interface!"
00055       << " Aborting upload...";
00056     return;
00057   }
00058   
00059   // Update LLD descriptions with new bias/gain settings
00060   SiStripConfigDb::DeviceDescriptionsRange devices = db()->getDeviceDescriptions( LASERDRIVER ); 
00061   update( devices );
00062   if ( doUploadConf() ) { 
00063     edm::LogVerbatim(mlDqmClient_) 
00064       << "[OptoScanHistosUsingDb::" << __func__ << "]"
00065       << " Uploading LLD settings to DB...";
00066     db()->uploadDeviceDescriptions(); 
00067     edm::LogVerbatim(mlDqmClient_) 
00068       << "[OptoScanHistosUsingDb::" << __func__ << "]"
00069       << " Upload of LLD settings to DB finished!";
00070   } else {
00071     edm::LogWarning(mlDqmClient_) 
00072       << "[OptoScanHistosUsingDb::" << __func__ << "]"
00073       << " TEST only! No LLD settings will be uploaded to DB...";
00074   }
00075   
00076 }
00077 
00078 // -----------------------------------------------------------------------------
00080 void OptoScanHistosUsingDb::update( SiStripConfigDb::DeviceDescriptionsRange devices ) {
00081   
00082   // Iterate through devices and update device descriptions
00083   uint16_t updated = 0;
00084   SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
00085   for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
00086     
00087     if ( (*idevice)->getDeviceType() != LASERDRIVER ) { continue; }
00088 
00089     // Cast to retrieve appropriate description object
00090     laserdriverDescription* desc = dynamic_cast<laserdriverDescription*>( *idevice );
00091     if ( !desc ) { continue; }
00092     
00093     // Retrieve device addresses from device description
00094     const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
00095     
00096     // Iterate through LLD channels
00097     for ( uint16_t ichan = 0; ichan < sistrip::CHANS_PER_LLD; ichan++ ) {
00098       
00099       // Construct key from device description
00100       SiStripFecKey fec_key( addr.fecCrate_, 
00101                              addr.fecSlot_, 
00102                              addr.fecRing_, 
00103                              addr.ccuAddr_, 
00104                              addr.ccuChan_,
00105                              ichan+1 );
00106       
00107       // Iterate through all channels and extract LLD settings 
00108       Analyses::const_iterator iter = data().find( fec_key.key() );
00109       if ( iter != data().end() ) {
00110 
00111         if ( !iter->second->isValid() ) { 
00112           addProblemDevice( fec_key ); //@@ Remove problem device
00113           continue; 
00114         }
00115 
00116         OptoScanAnalysis* anal = dynamic_cast<OptoScanAnalysis*>( iter->second );
00117         if ( !anal ) { 
00118           edm::LogError(mlDqmClient_)
00119             << "[OptoScanHistosUsingDb::" << __func__ << "]"
00120             << " NULL pointer to analysis object!";     
00121           continue; 
00122         }
00123         
00124         uint16_t gain = anal->gain();
00125         std::stringstream ss;
00126         ss << "[OptoScanHistosUsingDb::" << __func__ << "]"
00127            << " Updating LLD gain/bias settings for crate/crate/FEC/ring/CCU/module/LLD "
00128            << fec_key.fecCrate() << "/"
00129            << fec_key.fecSlot() << "/"
00130            << fec_key.fecRing() << "/"
00131            << fec_key.ccuAddr() << "/"
00132            << fec_key.ccuChan() << "/"
00133            << fec_key.channel() 
00134            << " from "
00135            << static_cast<uint16_t>( desc->getGain(ichan) ) << "/" 
00136            << static_cast<uint16_t>( desc->getBias(ichan) );
00137         desc->setGain( ichan, gain );
00138         desc->setBias( ichan, anal->bias()[gain] );
00139         updated++;
00140         ss << " to "
00141            << static_cast<uint16_t>(desc->getGain(ichan)) << "/" 
00142            << static_cast<uint16_t>(desc->getBias(ichan));
00143         LogTrace(mlDqmClient_) << ss.str();
00144         
00145       } else {
00146         if ( deviceIsPresent(fec_key) ) { 
00147           edm::LogWarning(mlDqmClient_) 
00148             << "[OptoScanHistosUsingDb::" << __func__ << "]"
00149             << " Unable to find FEC key with params crate/FEC/ring/CCU/module/LLD " 
00150             << fec_key.fecCrate() << "/"
00151             << fec_key.fecSlot() << "/"
00152             << fec_key.fecRing() << "/"
00153             << fec_key.ccuAddr() << "/"
00154             << fec_key.ccuChan() << "/"
00155             << fec_key.channel();
00156         }
00157       }
00158     }
00159   }
00160 
00161   edm::LogVerbatim(mlDqmClient_) 
00162     << "[OptoScanHistosUsingDb::" << __func__ << "]"
00163     << " Updated LLD bias/gain settings for " 
00164     << updated << " modules";
00165   
00166 
00167 }
00168 
00169 // -----------------------------------------------------------------------------
00171 void OptoScanHistosUsingDb::create( SiStripConfigDb::AnalysisDescriptionsV& desc,
00172                                     Analysis analysis ) {
00173   
00174 #ifdef USING_NEW_DATABASE_MODEL
00175 
00176   OptoScanAnalysis* anal = dynamic_cast<OptoScanAnalysis*>( analysis->second );
00177   if ( !anal ) { return; }
00178   
00179   SiStripFecKey fec_key( anal->fecKey() ); 
00180   SiStripFedKey fed_key( anal->fedKey() );
00181 
00182   for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
00183 
00184     // Create description
00185     OptoScanAnalysisDescription* tmp;
00186     tmp = new OptoScanAnalysisDescription( anal->baseSlope()[0],
00187                                            anal->baseSlope()[1],
00188                                            anal->baseSlope()[2],
00189                                            anal->baseSlope()[3],
00190                                            anal->gain(),
00191                                            anal->bias()[0],
00192                                            anal->bias()[1],
00193                                            anal->bias()[2],
00194                                            anal->bias()[3],
00195                                            anal->measGain()[0],
00196                                            anal->measGain()[1],
00197                                            anal->measGain()[2],
00198                                            anal->measGain()[3],
00199                                            anal->zeroLight()[0],
00200                                            anal->zeroLight()[1],
00201                                            anal->zeroLight()[2],
00202                                            anal->zeroLight()[3],
00203                                            anal->linkNoise()[0],
00204                                            anal->linkNoise()[1],
00205                                            anal->linkNoise()[2],
00206                                            anal->linkNoise()[3],
00207                                            anal->liftOff()[0],
00208                                            anal->liftOff()[1],
00209                                            anal->liftOff()[2],
00210                                            anal->liftOff()[3],
00211                                            anal->threshold()[0],
00212                                            anal->threshold()[1],
00213                                            anal->threshold()[2],
00214                                            anal->threshold()[3],
00215                                            anal->tickHeight()[0],
00216                                            anal->tickHeight()[1],
00217                                            anal->tickHeight()[2],
00218                                            anal->tickHeight()[3],
00219                                            fec_key.fecCrate(),
00220                                            fec_key.fecSlot(),
00221                                            fec_key.fecRing(),
00222                                            fec_key.ccuAddr(),
00223                                            fec_key.ccuChan(),
00224                                            SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ), 
00225                                            db()->dbParams().partitions().begin()->second.partitionName(),
00226                                            db()->dbParams().partitions().begin()->second.runNumber(),
00227                                            anal->isValid(),
00228                                            "",
00229                                            fed_key.fedId(),
00230                                            fed_key.feUnit(),
00231                                            fed_key.feChan(),
00232                                            fed_key.fedApv() );
00233     
00234     // Add comments
00235     typedef std::vector<std::string> Strings;
00236     Strings errors = anal->getErrorCodes();
00237     Strings::const_iterator istr = errors.begin();
00238     Strings::const_iterator jstr = errors.end();
00239     for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
00240     
00241     // Store description
00242     desc.push_back( tmp );
00243     
00244   }
00245 
00246 #endif
00247 
00248 }
00249 

Generated on Tue Jun 9 17:33:31 2009 for CMSSW by  doxygen 1.5.4