CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/DQM/SiStripCommissioningDbClients/src/OptoScanHistosUsingDb.cc

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