CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQM/SiStripCommissioningDbClients/src/VpspScanHistosUsingDb.cc

Go to the documentation of this file.
00001 // Last commit: $Id: VpspScanHistosUsingDb.cc,v 1.21 2010/04/21 14:26:30 dstrom Exp $
00002 
00003 #include "DQM/SiStripCommissioningDbClients/interface/VpspScanHistosUsingDb.h"
00004 #include "CondFormats/SiStripObjects/interface/VpspScanAnalysis.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 VpspScanHistosUsingDb::VpspScanHistosUsingDb( const edm::ParameterSet & pset,
00015                                               DQMStore* bei,
00016                                               SiStripConfigDb* const db ) 
00017   : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("VpspScanParameters"),
00018                              bei,
00019                              sistrip::VPSP_SCAN ),
00020     CommissioningHistosUsingDb( db,
00021                                 sistrip::VPSP_SCAN ),
00022     VpspScanHistograms( pset.getParameter<edm::ParameterSet>("VpspScanParameters"),
00023                         bei )
00024 {
00025   LogTrace(mlDqmClient_) 
00026     << "[VpspScanHistosUsingDb::" << __func__ << "]"
00027     << " Constructing object...";
00028 }
00029 
00030 // -----------------------------------------------------------------------------
00032 VpspScanHistosUsingDb::~VpspScanHistosUsingDb() {
00033   LogTrace(mlDqmClient_) 
00034     << "[VpspScanHistosUsingDb::" << __func__ << "]"
00035     << " Destructing object...";
00036 }
00037 
00038 // -----------------------------------------------------------------------------
00040 void VpspScanHistosUsingDb::uploadConfigurations() {
00041   LogTrace(mlDqmClient_) 
00042     << "[VpspScanHistosUsingDb::" << __func__ << "]";
00043   
00044   if ( !db() ) {
00045     edm::LogError(mlDqmClient_) 
00046       << "[VpspScanHistosUsingDb::" << __func__ << "]"
00047       << " NULL pointer to SiStripConfigDb interface!"
00048       << " Aborting upload...";
00049     return;
00050   }
00051   
00052   // Update all APV device descriptions with new VPSP settings
00053   SiStripConfigDb::DeviceDescriptionsRange devices = db()->getDeviceDescriptions();
00054   update( devices );
00055   if ( doUploadConf() ) { 
00056     edm::LogVerbatim(mlDqmClient_) 
00057       << "[VpspScanHistosUsingDb::" << __func__ << "]"
00058       << " Uploading VPSP settings to DB...";
00059     db()->uploadDeviceDescriptions(); 
00060     edm::LogVerbatim(mlDqmClient_) 
00061       << "[VpspScanHistosUsingDb::" << __func__ << "]"
00062       << " Uploaded VPSP settings to DB!";
00063   } else {
00064     edm::LogWarning(mlDqmClient_) 
00065       << "[VpspScanHistosUsingDb::" << __func__ << "]"
00066       << " TEST only! No VPSP settings will be uploaded to DB...";
00067   }
00068   LogTrace(mlDqmClient_) 
00069     << "[VpspScanHistosUsingDb::" << __func__ << "]"
00070     << " Upload of VPSP settings to DB finished!";
00071   
00072 }
00073 
00074 // -----------------------------------------------------------------------------
00076 void VpspScanHistosUsingDb::update( SiStripConfigDb::DeviceDescriptionsRange devices ) {
00077   
00078   // Iterate through devices and update device descriptions
00079   SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
00080   for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
00081     
00082     // Check device type
00083     if ( (*idevice)->getDeviceType() != APV25 ) { continue; }
00084     
00085     // Cast to retrieve appropriate description object
00086     apvDescription* desc = dynamic_cast<apvDescription*>( *idevice );
00087     if ( !desc ) { continue; }
00088     
00089     // Retrieve device addresses from device description
00090     const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
00091     
00092     // Retrieve LLD channel and APV numbers
00093     uint16_t ichan = ( desc->getAddress() - 0x20 ) / 2;
00094     uint16_t iapv  = ( desc->getAddress() - 0x20 ) % 2;
00095     
00096     // Construct key from device description
00097     SiStripFecKey fec_key( addr.fecCrate_, 
00098                            addr.fecSlot_, 
00099                            addr.fecRing_, 
00100                            addr.ccuAddr_, 
00101                            addr.ccuChan_,
00102                            ichan+1 );
00103       
00104     // Iterate through all channels and extract LLD settings 
00105     Analyses::const_iterator iter = data().find( fec_key.key() );
00106     if ( iter != data().end() ) {
00107 
00108       VpspScanAnalysis* anal = dynamic_cast<VpspScanAnalysis*>( iter->second );
00109       if ( !anal ) { 
00110         edm::LogError(mlDqmClient_)
00111           << "[VpspScanHistosUsingDb::" << __func__ << "]"
00112           << " NULL pointer to analysis object!";
00113         continue; 
00114       }
00115       
00116       std::stringstream ss;
00117       ss << "[VpspScanHistosUsingDb::" << __func__ << "]"
00118          << " Updating VPSP setting for crate/FEC/slot/ring/CCU/LLD/APV " 
00119          << fec_key.fecCrate() << "/"
00120          << fec_key.fecSlot() << "/"
00121          << fec_key.fecRing() << "/"
00122          << fec_key.ccuAddr() << "/"
00123          << fec_key.ccuChan() << "/"
00124          << fec_key.channel() 
00125          << iapv
00126          << " from "
00127          << static_cast<uint16_t>(desc->getVpsp());
00128       if ( iapv == 0 ) { desc->setVpsp( anal->vpsp()[0] ); }
00129       if ( iapv == 1 ) { desc->setVpsp( anal->vpsp()[1] ); }
00130       ss << " to " << static_cast<uint16_t>(desc->getVpsp());
00131       LogTrace(mlDqmClient_) << ss.str();
00132       
00133     } else {
00134       if ( deviceIsPresent(fec_key) ) {
00135         edm::LogWarning(mlDqmClient_) 
00136           << "[VpspScanHistosUsingDb::" << __func__ << "]"
00137           << " Unable to find FEC key with params FEC/slot/ring/CCU/LLDchan/APV: " 
00138           << fec_key.fecCrate() << "/"
00139           << fec_key.fecSlot() << "/"
00140           << fec_key.fecRing() << "/"
00141           << fec_key.ccuAddr() << "/"
00142           << fec_key.ccuChan() << "/"
00143           << fec_key.channel() << "/" 
00144           << iapv+1;
00145       }
00146     }
00147   }
00148   
00149 }
00150 
00151 // -----------------------------------------------------------------------------
00153 void VpspScanHistosUsingDb::create( SiStripConfigDb::AnalysisDescriptionsV& desc,
00154                                     Analysis analysis ) {
00155 
00156   VpspScanAnalysis* anal = dynamic_cast<VpspScanAnalysis*>( analysis->second );
00157   if ( !anal ) { return; }
00158   
00159   SiStripFecKey fec_key( anal->fecKey() ); 
00160   SiStripFedKey fed_key( anal->fedKey() );
00161   
00162   for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
00163 
00164     // Create description
00165     VpspScanAnalysisDescription* tmp;
00166     tmp = new VpspScanAnalysisDescription( anal->vpsp()[iapv],
00167                                            anal->adcLevel()[iapv],
00168                                            anal->fraction()[iapv],
00169                                            anal->topEdge()[iapv],
00170                                            anal->bottomEdge()[iapv],
00171                                            anal->topLevel()[iapv],
00172                                            anal->bottomLevel()[iapv],
00173                                            fec_key.fecCrate(),
00174                                            fec_key.fecSlot(),
00175                                            fec_key.fecRing(),
00176                                            fec_key.ccuAddr(),
00177                                            fec_key.ccuChan(),
00178                                            SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ), 
00179                                            db()->dbParams().partitions().begin()->second.partitionName(),
00180                                            db()->dbParams().partitions().begin()->second.runNumber(),
00181                                            anal->isValid(),
00182                                            "",
00183                                            fed_key.fedId(),
00184                                            fed_key.feUnit(),
00185                                            fed_key.feChan(),
00186                                            fed_key.fedApv() );
00187     
00188     // Add comments
00189     typedef std::vector<std::string> Strings;
00190     Strings errors = anal->getErrorCodes();
00191     Strings::const_iterator istr = errors.begin();
00192     Strings::const_iterator jstr = errors.end();
00193     for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
00194 
00195     // Store description
00196     desc.push_back( tmp );
00197       
00198   }
00199 
00200 }
00201