00001
00002
00003 #include "DQM/SiStripCommissioningDbClients/interface/PedestalsHistosUsingDb.h"
00004 #include "CondFormats/SiStripObjects/interface/PedestalsAnalysis.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 PedestalsHistosUsingDb::PedestalsHistosUsingDb( DQMOldReceiver* mui,
00016 SiStripConfigDb* const db )
00017 : CommissioningHistograms( mui, sistrip::PEDESTALS ),
00018 CommissioningHistosUsingDb( db, mui, sistrip::PEDESTALS ),
00019 PedestalsHistograms( mui )
00020 {
00021 LogTrace(mlDqmClient_)
00022 << "[PedestalsHistosUsingDb::" << __func__ << "]"
00023 << " Constructing object...";
00024 }
00025
00026
00028 PedestalsHistosUsingDb::PedestalsHistosUsingDb( DQMStore* bei,
00029 SiStripConfigDb* const db )
00030 : CommissioningHistosUsingDb( db, sistrip::PEDESTALS ),
00031 PedestalsHistograms( bei )
00032 {
00033 LogTrace(mlDqmClient_)
00034 << "[PedestalsHistosUsingDb::" << __func__ << "]"
00035 << " Constructing object...";
00036 }
00037
00038
00040 PedestalsHistosUsingDb::~PedestalsHistosUsingDb() {
00041 LogTrace(mlDqmClient_)
00042 << "[PedestalsHistosUsingDb::" << __func__ << "]"
00043 << " Destructing object...";
00044 }
00045
00046
00048 void PedestalsHistosUsingDb::uploadConfigurations() {
00049 LogTrace(mlDqmClient_)
00050 << "[PedestalsHistosUsingDb::" << __func__ << "]";
00051
00052 if ( !db() ) {
00053 edm::LogError(mlDqmClient_)
00054 << "[PedestalsHistosUsingDb::" << __func__ << "]"
00055 << " NULL pointer to SiStripConfigDb interface!"
00056 << " Aborting upload...";
00057 return;
00058 }
00059
00060
00061 SiStripConfigDb::FedDescriptionsRange feds = db()->getFedDescriptions();
00062 update( feds );
00063 if ( doUploadConf() ) {
00064 edm::LogVerbatim(mlDqmClient_)
00065 << "[PedestalsHistosUsingDb::" << __func__ << "]"
00066 << " Uploading pedestals/noise to DB...";
00067 db()->uploadFedDescriptions();
00068 edm::LogVerbatim(mlDqmClient_)
00069 << "[PedestalsHistosUsingDb::" << __func__ << "]"
00070 << " Completed database upload of " << feds.size()
00071 << " FED descriptions!";
00072 } else {
00073 edm::LogWarning(mlDqmClient_)
00074 << "[PedestalsHistosUsingDb::" << __func__ << "]"
00075 << " TEST only! No pedestals/noise values will be uploaded to DB...";
00076 }
00077
00078 }
00079
00080
00082 void PedestalsHistosUsingDb::update( SiStripConfigDb::FedDescriptionsRange feds ) {
00083
00084
00085 uint16_t updated = 0;
00086 SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
00087 for ( ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
00088
00089 for ( uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++ ) {
00090
00091
00092 const FedChannelConnection& conn = cabling()->connection( (*ifed)->getFedId(), ichan );
00093 if ( conn.fecCrate() == sistrip::invalid_ ||
00094 conn.fecSlot() == sistrip::invalid_ ||
00095 conn.fecRing() == sistrip::invalid_ ||
00096 conn.ccuAddr() == sistrip::invalid_ ||
00097 conn.ccuChan() == sistrip::invalid_ ||
00098 conn.lldChannel() == sistrip::invalid_ ) { continue; }
00099 SiStripFedKey fed_key( conn.fedId(),
00100 SiStripFedKey::feUnit( conn.fedCh() ),
00101 SiStripFedKey::feChan( conn.fedCh() ) );
00102 SiStripFecKey fec_key( conn.fecCrate(),
00103 conn.fecSlot(),
00104 conn.fecRing(),
00105 conn.ccuAddr(),
00106 conn.ccuChan(),
00107 conn.lldChannel() );
00108
00109
00110 Analyses::const_iterator iter = data().find( fec_key.key() );
00111 if ( iter != data().end() ) {
00112
00113
00114 if ( !iter->second->isValid() ) {
00115 addProblemDevice( fec_key );
00116 continue;
00117 }
00118
00119 PedestalsAnalysis* anal = dynamic_cast<PedestalsAnalysis*>( iter->second );
00120 if ( !anal ) {
00121 edm::LogError(mlDqmClient_)
00122 << "[PedestalsHistosUsingDb::" << __func__ << "]"
00123 << " NULL pointer to analysis object!";
00124 continue;
00125 }
00126
00127
00128 for ( uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++ ) {
00129 for ( uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++ ) {
00130
00131 static float high_threshold = 5.;
00132 static float low_threshold = 2.;
00133 static bool disable_strip = false;
00134 Fed9U::Fed9UStripDescription data( static_cast<uint32_t>( anal->peds()[iapv][istr] ),
00135 high_threshold,
00136 low_threshold,
00137 anal->noise()[iapv][istr],
00138 disable_strip );
00139 Fed9U::Fed9UAddress addr( ichan, iapv, istr );
00140 (*ifed)->getFedStrips().setStrip( addr, data );
00141
00142 }
00143 }
00144 updated++;
00145
00146 } else {
00147 if ( deviceIsPresent(fec_key) ) {
00148 edm::LogWarning(mlDqmClient_)
00149 << "[PedestalsHistosUsingDb::" << __func__ << "]"
00150 << " Unable to find pedestals/noise for FedKey/Id/Ch: "
00151 << hex << setw(8) << setfill('0') << fed_key.key() << dec << "/"
00152 << (*ifed)->getFedId() << "/"
00153 << ichan
00154 << " and device with FEC/slot/ring/CCU/LLD "
00155 << fec_key.fecCrate() << "/"
00156 << fec_key.fecSlot() << "/"
00157 << fec_key.fecRing() << "/"
00158 << fec_key.ccuAddr() << "/"
00159 << fec_key.ccuChan() << "/"
00160 << fec_key.channel();
00161 }
00162 }
00163 }
00164 }
00165
00166 edm::LogVerbatim(mlDqmClient_)
00167 << "[PedestalsHistosUsingDb::" << __func__ << "]"
00168 << " Updated FED pedestals/noise for "
00169 << updated << " channels";
00170
00171 }
00172
00173
00175 void PedestalsHistosUsingDb::create( SiStripConfigDb::AnalysisDescriptionsV& desc,
00176 Analysis analysis ) {
00177
00178 #ifdef USING_NEW_DATABASE_MODEL
00179
00180 PedestalsAnalysis* anal = dynamic_cast<PedestalsAnalysis*>( analysis->second );
00181 if ( !anal ) { return; }
00182
00183 SiStripFecKey fec_key( anal->fecKey() );
00184 SiStripFedKey fed_key( anal->fedKey() );
00185
00186 for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
00187
00188
00189 PedestalsAnalysisDescription* tmp;
00190 tmp = new PedestalsAnalysisDescription( anal->dead()[iapv],
00191 anal->noisy()[iapv],
00192 anal->pedsMean()[iapv],
00193 anal->pedsSpread()[iapv],
00194 anal->noiseMean()[iapv],
00195 anal->noiseSpread()[iapv],
00196 anal->rawMean()[iapv],
00197 anal->rawSpread()[iapv],
00198 anal->pedsMax()[iapv],
00199 anal->pedsMin()[iapv],
00200 anal->noiseMax()[iapv],
00201 anal->noiseMin()[iapv],
00202 anal->rawMax()[iapv],
00203 anal->rawMin()[iapv],
00204 fec_key.fecCrate(),
00205 fec_key.fecSlot(),
00206 fec_key.fecRing(),
00207 fec_key.ccuAddr(),
00208 fec_key.ccuChan(),
00209 SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ),
00210 db()->dbParams().partitions().begin()->second.partitionName(),
00211 db()->dbParams().partitions().begin()->second.runNumber(),
00212 anal->isValid(),
00213 "",
00214 fed_key.fedId(),
00215 fed_key.feUnit(),
00216 fed_key.feChan(),
00217 fed_key.fedApv() );
00218
00219
00220 typedef std::vector<std::string> Strings;
00221 Strings errors = anal->getErrorCodes();
00222 Strings::const_iterator istr = errors.begin();
00223 Strings::const_iterator jstr = errors.end();
00224 for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
00225
00226
00227 desc.push_back( tmp );
00228
00229 }
00230
00231 #endif
00232
00233 }
00234