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