00001
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( DQMOldReceiver* mui,
00015 SiStripConfigDb* const db )
00016 : CommissioningHistograms( mui, sistrip::VPSP_SCAN ),
00017 CommissioningHistosUsingDb( db, sistrip::VPSP_SCAN ),
00018 VpspScanHistograms( mui )
00019 {
00020 LogTrace(mlDqmClient_)
00021 << "[VpspScanHistosUsingDb::" << __func__ << "]"
00022 << " Constructing object...";
00023 }
00024
00025
00027 VpspScanHistosUsingDb::VpspScanHistosUsingDb( DQMStore* bei,
00028 SiStripConfigDb* const db )
00029 : CommissioningHistosUsingDb( db, sistrip::VPSP_SCAN ),
00030 VpspScanHistograms( bei )
00031 {
00032 LogTrace(mlDqmClient_)
00033 << "[VpspScanHistosUsingDb::" << __func__ << "]"
00034 << " Constructing object...";
00035 }
00036
00037
00039 VpspScanHistosUsingDb::~VpspScanHistosUsingDb() {
00040 LogTrace(mlDqmClient_)
00041 << "[VpspScanHistosUsingDb::" << __func__ << "]"
00042 << " Destructing object...";
00043 }
00044
00045
00047 void VpspScanHistosUsingDb::uploadConfigurations() {
00048 LogTrace(mlDqmClient_)
00049 << "[VpspScanHistosUsingDb::" << __func__ << "]";
00050
00051 if ( !db() ) {
00052 edm::LogError(mlDqmClient_)
00053 << "[VpspScanHistosUsingDb::" << __func__ << "]"
00054 << " NULL pointer to SiStripConfigDb interface!"
00055 << " Aborting upload...";
00056 return;
00057 }
00058
00059
00060 SiStripConfigDb::DeviceDescriptionsRange devices = db()->getDeviceDescriptions();
00061 update( devices );
00062 if ( doUploadConf() ) {
00063 edm::LogVerbatim(mlDqmClient_)
00064 << "[VpspScanHistosUsingDb::" << __func__ << "]"
00065 << " Uploading VPSP settings to DB...";
00066 db()->uploadDeviceDescriptions();
00067 edm::LogVerbatim(mlDqmClient_)
00068 << "[VpspScanHistosUsingDb::" << __func__ << "]"
00069 << " Uploaded VPSP settings to DB!";
00070 } else {
00071 edm::LogWarning(mlDqmClient_)
00072 << "[VpspScanHistosUsingDb::" << __func__ << "]"
00073 << " TEST only! No VPSP settings will be uploaded to DB...";
00074 }
00075 LogTrace(mlDqmClient_)
00076 << "[VpspScanHistosUsingDb::" << __func__ << "]"
00077 << " Upload of VPSP settings to DB finished!";
00078
00079 }
00080
00081
00083 void VpspScanHistosUsingDb::update( SiStripConfigDb::DeviceDescriptionsRange devices ) {
00084
00085
00086 SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
00087 for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
00088
00089
00090 if ( (*idevice)->getDeviceType() != APV25 ) { continue; }
00091
00092
00093 apvDescription* desc = dynamic_cast<apvDescription*>( *idevice );
00094 if ( !desc ) { continue; }
00095
00096
00097 const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
00098
00099
00100 uint16_t ichan = ( desc->getAddress() - 0x20 ) / 2;
00101 uint16_t iapv = ( desc->getAddress() - 0x20 ) % 2;
00102
00103
00104 SiStripFecKey fec_key( addr.fecCrate_,
00105 addr.fecSlot_,
00106 addr.fecRing_,
00107 addr.ccuAddr_,
00108 addr.ccuChan_,
00109 ichan+1 );
00110
00111
00112 Analyses::const_iterator iter = data().find( fec_key.key() );
00113 if ( iter != data().end() ) {
00114
00115 if ( !iter->second->isValid() ) {
00116 addProblemDevice( fec_key );
00117 continue;
00118 }
00119
00120 VpspScanAnalysis* anal = dynamic_cast<VpspScanAnalysis*>( iter->second );
00121 if ( !anal ) {
00122 edm::LogError(mlDqmClient_)
00123 << "[VpspScanHistosUsingDb::" << __func__ << "]"
00124 << " NULL pointer to analysis object!";
00125 continue;
00126 }
00127
00128 std::stringstream ss;
00129 ss << "[VpspScanHistosUsingDb::" << __func__ << "]"
00130 << " Updating VPSP setting for crate/FEC/slot/ring/CCU/LLD/APV "
00131 << fec_key.fecCrate() << "/"
00132 << fec_key.fecSlot() << "/"
00133 << fec_key.fecRing() << "/"
00134 << fec_key.ccuAddr() << "/"
00135 << fec_key.ccuChan() << "/"
00136 << fec_key.channel()
00137 << iapv
00138 << " from "
00139 << static_cast<uint16_t>(desc->getVpsp());
00140 if ( iapv == 0 ) { desc->setVpsp( anal->vpsp()[0] ); }
00141 if ( iapv == 1 ) { desc->setVpsp( anal->vpsp()[1] ); }
00142 ss << " to " << static_cast<uint16_t>(desc->getVpsp());
00143 LogTrace(mlDqmClient_) << ss.str();
00144
00145 } else {
00146 if ( deviceIsPresent(fec_key) ) {
00147 edm::LogWarning(mlDqmClient_)
00148 << "[VpspScanHistosUsingDb::" << __func__ << "]"
00149 << " Unable to find FEC key with params FEC/slot/ring/CCU/LLDchan/APV: "
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 << iapv+1;
00157 }
00158 }
00159 }
00160
00161 }
00162
00163
00165 void VpspScanHistosUsingDb::create( SiStripConfigDb::AnalysisDescriptionsV& desc,
00166 Analysis analysis ) {
00167
00168 #ifdef USING_NEW_DATABASE_MODEL
00169
00170 VpspScanAnalysis* anal = dynamic_cast<VpspScanAnalysis*>( analysis->second );
00171 if ( !anal ) { return; }
00172
00173 SiStripFecKey fec_key( anal->fecKey() );
00174 SiStripFedKey fed_key( anal->fedKey() );
00175
00176 for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
00177
00178
00179 VpspScanAnalysisDescription* tmp;
00180 tmp = new VpspScanAnalysisDescription( anal->vpsp()[iapv],
00181 anal->adcLevel()[iapv],
00182 anal->fraction()[iapv],
00183 anal->topEdge()[iapv],
00184 anal->bottomEdge()[iapv],
00185 anal->topLevel()[iapv],
00186 anal->bottomLevel()[iapv],
00187 fec_key.fecCrate(),
00188 fec_key.fecSlot(),
00189 fec_key.fecRing(),
00190 fec_key.ccuAddr(),
00191 fec_key.ccuChan(),
00192 SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ),
00193 db()->dbParams().partitions().begin()->second.partitionName(),
00194 db()->dbParams().partitions().begin()->second.runNumber(),
00195 anal->isValid(),
00196 "",
00197 fed_key.fedId(),
00198 fed_key.feUnit(),
00199 fed_key.feChan(),
00200 fed_key.fedApv() );
00201
00202
00203 typedef std::vector<std::string> Strings;
00204 Strings errors = anal->getErrorCodes();
00205 Strings::const_iterator istr = errors.begin();
00206 Strings::const_iterator jstr = errors.end();
00207 for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
00208
00209
00210 desc.push_back( tmp );
00211
00212 }
00213
00214 #endif
00215
00216 }
00217