00001
00002
00003 #include "DQM/SiStripCommissioningDbClients/interface/ApvTimingHistosUsingDb.h"
00004 #include "CondFormats/SiStripObjects/interface/ApvTimingAnalysis.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 ApvTimingHistosUsingDb::ApvTimingHistosUsingDb( DQMOldReceiver* mui,
00016 SiStripConfigDb* const db )
00017 : CommissioningHistograms( mui, sistrip::APV_TIMING ),
00018 CommissioningHistosUsingDb( db, mui, sistrip::APV_TIMING ),
00019 ApvTimingHistograms( mui ),
00020 uploadFecSettings_(true),
00021 uploadFedSettings_(true)
00022 {
00023 LogTrace(mlDqmClient_)
00024 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00025 << " Constructing object...";
00026 }
00027
00028
00030 ApvTimingHistosUsingDb::ApvTimingHistosUsingDb( DQMStore* bei,
00031 SiStripConfigDb* const db )
00032 : CommissioningHistosUsingDb( db, sistrip::APV_TIMING ),
00033 ApvTimingHistograms( bei ),
00034 uploadFecSettings_(true),
00035 uploadFedSettings_(true)
00036 {
00037 LogTrace(mlDqmClient_)
00038 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00039 << " Constructing object...";
00040 }
00041
00042
00044 ApvTimingHistosUsingDb::~ApvTimingHistosUsingDb() {
00045 LogTrace(mlDqmClient_)
00046 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00047 << " Destructing object...";
00048 }
00049
00050
00052 void ApvTimingHistosUsingDb::uploadConfigurations() {
00053 LogTrace(mlDqmClient_)
00054 << "[ApvTimingHistosUsingDb::" << __func__ << "]";
00055
00056 if ( !db() ) {
00057 edm::LogError(mlDqmClient_)
00058 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00059 << " NULL pointer to SiStripConfigDb interface!"
00060 << " Aborting upload...";
00061 return;
00062 }
00063
00064 if ( uploadFecSettings_ ) {
00065
00066
00067 SiStripConfigDb::DeviceDescriptionsRange devices = db()->getDeviceDescriptions( PLL );
00068 bool upload = update( devices );
00069
00070
00071 if ( !upload ) {
00072 edm::LogError(mlDqmClient_)
00073 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00074 << " Found invalid PLL settings (coarse > 15)"
00075 << " Aborting update to database...";
00076 return;
00077 }
00078
00079
00080 if ( doUploadConf() ) {
00081 edm::LogVerbatim(mlDqmClient_)
00082 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00083 << " Uploading PLL settings to DB...";
00084 db()->uploadDeviceDescriptions();
00085 edm::LogVerbatim(mlDqmClient_)
00086 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00087 << " Upload of PLL settings to DB finished!";
00088 } else {
00089 edm::LogWarning(mlDqmClient_)
00090 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00091 << " TEST only! No PLL settings will be uploaded to DB...";
00092 }
00093
00094 } else {
00095 LogTrace(mlDqmClient_)
00096 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00097 << " No upload of PLL settings to DB, as defined by .cfg file!";
00098 }
00099
00100 if ( uploadFedSettings_ ) {
00101
00102
00103 SiStripConfigDb::FedDescriptionsRange feds = db()->getFedDescriptions();
00104 update( feds );
00105
00106
00107 if ( doUploadConf() ) {
00108 edm::LogVerbatim(mlDqmClient_)
00109 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00110 << " Uploading FED ticker thresholds to DB...";
00111 db()->uploadFedDescriptions();
00112 edm::LogVerbatim(mlDqmClient_)
00113 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00114 << " Upload of FED ticker thresholds to DB finished!";
00115 } else {
00116 edm::LogWarning(mlDqmClient_)
00117 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00118 << " TEST only! No FED ticker thresholds will be uploaded to DB...";
00119 }
00120
00121 } else {
00122 LogTrace(mlDqmClient_)
00123 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00124 << " No Upload of FED ticker thresholds to DB, as defined by .cfg file!";
00125 }
00126
00127 }
00128
00129
00131 bool ApvTimingHistosUsingDb::update( SiStripConfigDb::DeviceDescriptionsRange devices ) {
00132
00133
00134 uint16_t updated = 0;
00135 std::vector<SiStripFecKey> invalid;
00136 SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
00137 for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
00138
00139
00140 if ( (*idevice)->getDeviceType() != PLL ) { continue; }
00141
00142
00143 pllDescription* desc = dynamic_cast<pllDescription*>( *idevice );
00144 if ( !desc ) { continue; }
00145
00146
00147 const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
00148 SiStripFecKey fec_path;
00149
00150
00151 uint32_t coarse = sistrip::invalid_;
00152 uint32_t fine = sistrip::invalid_;
00153
00154
00155 for ( uint16_t ichan = 0; ichan < sistrip::CHANS_PER_LLD; ichan++ ) {
00156
00157
00158 SiStripFecKey fec_key( addr.fecCrate_,
00159 addr.fecSlot_,
00160 addr.fecRing_,
00161 addr.ccuAddr_,
00162 addr.ccuChan_,
00163 ichan+1 );
00164 fec_path = fec_key;
00165
00166
00167 Analyses::const_iterator iter = data().find( fec_key.key() );
00168 if ( iter != data().end() ) {
00169
00170 if ( !iter->second->isValid() ) {
00171 addProblemDevice( fec_key );
00172 continue;
00173 }
00174
00175 ApvTimingAnalysis* anal = dynamic_cast<ApvTimingAnalysis*>( iter->second );
00176 if ( !anal ) {
00177 edm::LogError(mlDqmClient_)
00178 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00179 << " NULL pointer to analysis object!";
00180 continue;
00181 }
00182
00183
00184 uint32_t delay = static_cast<uint32_t>( rint( anal->delay() * 24. / 25. ) );
00185 coarse = static_cast<uint16_t>( desc->getDelayCoarse() )
00186 + ( static_cast<uint16_t>( desc->getDelayFine() ) + delay ) / 24;
00187 fine = ( static_cast<uint16_t>( desc->getDelayFine() ) + delay ) % 24;
00188
00189
00190 if ( coarse > 15 ) { invalid.push_back(fec_key); }
00191
00192 } else {
00193 if ( deviceIsPresent(fec_key) ) {
00194 edm::LogWarning(mlDqmClient_)
00195 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00196 << " Unable to find FEC key with params crate/FEC/ring/CCU/module/LLD: "
00197 << fec_key.fecCrate() << "/"
00198 << fec_key.fecSlot() << "/"
00199 << fec_key.fecRing() << "/"
00200 << fec_key.ccuAddr() << "/"
00201 << fec_key.ccuChan() << "/"
00202 << fec_key.channel();
00203 }
00204 }
00205
00206
00207 if ( coarse != sistrip::invalid_ &&
00208 fine != sistrip::invalid_ ) { break; }
00209
00210 }
00211
00212
00213 if ( coarse != sistrip::invalid_ &&
00214 fine != sistrip::invalid_ ) {
00215
00216 if ( edm::isDebugEnabled() ) {
00217 std::stringstream ss;
00218 ss << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00219 << " Updating coarse/fine PLL settings"
00220 << " for crate/FEC/ring/CCU/module "
00221 << fec_path.fecCrate() << "/"
00222 << fec_path.fecSlot() << "/"
00223 << fec_path.fecRing() << "/"
00224 << fec_path.ccuAddr() << "/"
00225 << fec_path.ccuChan()
00226 << " from "
00227 << static_cast<uint16_t>( desc->getDelayCoarse() ) << "/"
00228 << static_cast<uint16_t>( desc->getDelayFine() );
00229 desc->setDelayCoarse(coarse);
00230 desc->setDelayFine(fine);
00231 updated++;
00232 ss << " to "
00233 << static_cast<uint16_t>( desc->getDelayCoarse() ) << "/"
00234 << static_cast<uint16_t>( desc->getDelayFine() );
00235 LogTrace(mlDqmClient_) << ss.str();
00236 }
00237
00238 } else {
00239 edm::LogWarning(mlDqmClient_)
00240 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00241 << " Invalid PLL delay settings for crate/FEC/ring/CCU/module "
00242 << fec_path.fecCrate() << "/"
00243 << fec_path.fecSlot() << "/"
00244 << fec_path.fecRing() << "/"
00245 << fec_path.ccuAddr() << "/"
00246 << fec_path.ccuChan();
00247 }
00248
00249 }
00250
00251
00252 if ( !invalid.empty() ) {
00253 std::stringstream ss;
00254 ss << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00255 << " Found PLL coarse setting of >15"
00256 << " (not allowed!) for "
00257 << invalid.size()
00258 << " channels";
00259 ss << " (Example is crate/FEC/ring/CCU/module/LLD: "
00260 << invalid.front().fecCrate() << "/"
00261 << invalid.front().fecSlot() << "/"
00262 << invalid.front().fecRing() << "/"
00263 << invalid.front().ccuAddr() << "/"
00264 << invalid.front().ccuChan() << "/"
00265 << invalid.front().channel();
00266 edm::LogWarning(mlDqmClient_) << ss.str();
00267 return false;
00268 }
00269
00270 edm::LogVerbatim(mlDqmClient_)
00271 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00272 << " Updated PLL settings for "
00273 << updated << " modules";
00274 return true;
00275
00276 }
00277
00278
00280 void ApvTimingHistosUsingDb::update( SiStripConfigDb::FedDescriptionsRange feds ) {
00281
00282
00283 std::vector<uint16_t> ids = cabling()->feds();
00284
00285
00286 uint16_t updated = 0;
00287 SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
00288 for ( ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
00289
00290
00291 if ( find( ids.begin(), ids.end(), (*ifed)->getFedId() ) == ids.end() ) { continue; }
00292
00293 for ( uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++ ) {
00294
00295
00296 const FedChannelConnection& conn = cabling()->connection( (*ifed)->getFedId(), ichan );
00297 if ( conn.fecCrate() == sistrip::invalid_ ||
00298 conn.fecSlot() == sistrip::invalid_ ||
00299 conn.fecRing() == sistrip::invalid_ ||
00300 conn.ccuAddr() == sistrip::invalid_ ||
00301 conn.ccuChan() == sistrip::invalid_ ||
00302 conn.lldChannel() == sistrip::invalid_ ) { continue; }
00303 SiStripFedKey fed_key( conn.fedId(),
00304 SiStripFedKey::feUnit( conn.fedCh() ),
00305 SiStripFedKey::feChan( conn.fedCh() ) );
00306 SiStripFecKey fec_key( conn.fecCrate(),
00307 conn.fecSlot(),
00308 conn.fecRing(),
00309 conn.ccuAddr(),
00310 conn.ccuChan(),
00311 conn.lldChannel() );
00312
00313
00314 Analyses::const_iterator iter = data().find( fec_key.key() );
00315 if ( iter != data().end() ) {
00316
00317 ApvTimingAnalysis* anal = dynamic_cast<ApvTimingAnalysis*>( iter->second );
00318 if ( !anal ) {
00319 edm::LogError(mlDqmClient_)
00320 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00321 << " NULL pointer to analysis object!";
00322 continue;
00323 }
00324
00325
00326 Fed9U::Fed9UAddress addr( ichan );
00327 uint16_t old_threshold = static_cast<uint16_t>( (*ifed)->getFrameThreshold( addr ) );
00328 if ( anal->isValid() ) {
00329 (*ifed)->setFrameThreshold( addr, anal->frameFindingThreshold() );
00330 updated++;
00331 }
00332 uint16_t new_threshold = static_cast<uint16_t>( (*ifed)->getFrameThreshold( addr ) );
00333
00334
00335 std::stringstream ss;
00336 ss << "[ApvTimingHistosUsingDb::" << __func__ << "]";
00337 if ( anal->isValid() ) {
00338 ss << " Updating the frame-finding threshold"
00339 << " from " << old_threshold
00340 << " to " << new_threshold
00341 << " using tick mark base/peak/height "
00342 << anal->base() << "/"
00343 << anal->peak() << "/"
00344 << anal->height();
00345 } else {
00346 ss << " Cannot update the frame-finding threshold"
00347 << " from " << old_threshold
00348 << " to a new value using invalid analysis ";
00349 }
00350 ss << " for crate/FEC/ring/CCU/module/LLD "
00351 << fec_key.fecCrate() << "/"
00352 << fec_key.fecSlot() << "/"
00353 << fec_key.fecRing() << "/"
00354 << fec_key.ccuAddr() << "/"
00355 << fec_key.ccuChan()
00356 << fec_key.channel()
00357 << " and FED id/ch "
00358 << fed_key.fedId() << "/"
00359 << fed_key.fedChannel();
00360 anal->print(ss);
00361
00362
00363 } else {
00364 if ( deviceIsPresent(fec_key) ) {
00365 std::stringstream ss;
00366 ss << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00367 << " Unable to find analysis object and update ticker thresholds"
00368 << " for key/crate/FEC/ring/CCU/module/LLD "
00369 << std::hex << std::setw(8) << std::setfill('0') << fec_key.key() << std::dec
00370 << fec_key.fecCrate() << "/"
00371 << fec_key.fecSlot() << "/"
00372 << fec_key.fecRing() << "/"
00373 << fec_key.ccuAddr() << "/"
00374 << fec_key.ccuChan() << "/"
00375 << fec_key.channel()
00376 << " and FED key/id/ch "
00377 << std::hex << std::setw(8) << std::setfill('0') << fed_key.key() << std::dec
00378 << fed_key.fedId() << "/"
00379 << fed_key.fedChannel();
00380 edm::LogWarning(mlDqmClient_) << ss.str();
00381 }
00382 }
00383 }
00384 }
00385
00386 edm::LogVerbatim(mlDqmClient_)
00387 << "[ApvTimingHistosUsingDb::" << __func__ << "]"
00388 << " Updated ticker thresholds for " << updated
00389 << " channels on " << ids.size() << " FEDs!";
00390
00391 }
00392
00393
00395 void ApvTimingHistosUsingDb::create( SiStripConfigDb::AnalysisDescriptionsV& desc,
00396 Analysis analysis ) {
00397
00398 #ifdef USING_NEW_DATABASE_MODEL
00399
00400 ApvTimingAnalysis* anal = dynamic_cast<ApvTimingAnalysis*>( analysis->second );
00401 if ( !anal ) { return; }
00402
00403 SiStripFecKey fec_key( anal->fecKey() );
00404 SiStripFedKey fed_key( anal->fedKey() );
00405
00406 for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 TimingAnalysisDescription* tmp;
00421 tmp = new TimingAnalysisDescription( anal->time(),
00422 anal->refTime(),
00423 anal->delay(),
00424 anal->height(),
00425 anal->base(),
00426 anal->peak(),
00427 anal->frameFindingThreshold(),
00428 anal->optimumSamplingPoint(),
00429 ApvTimingAnalysis::tickMarkHeightThreshold_,
00430 true,
00431 fec_key.fecCrate(),
00432 fec_key.fecSlot(),
00433 fec_key.fecRing(),
00434 fec_key.ccuAddr(),
00435 fec_key.ccuChan(),
00436 SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ),
00437 db()->dbParams().partitions().begin()->second.partitionName(),
00438 db()->dbParams().partitions().begin()->second.runNumber(),
00439 anal->isValid(),
00440 "",
00441 fed_key.fedId(),
00442 fed_key.feUnit(),
00443 fed_key.feChan(),
00444 fed_key.fedApv() );
00445
00446
00447 typedef std::vector<std::string> Strings;
00448 Strings errors = anal->getErrorCodes();
00449 Strings::const_iterator istr = errors.begin();
00450 Strings::const_iterator jstr = errors.end();
00451 for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
00452
00453
00454 desc.push_back( tmp );
00455
00456 }
00457
00458 #endif
00459
00460 }