00001
00002
00003 #include "DQM/SiStripCommissioningDbClients/interface/CommissioningHistosUsingDb.h"
00004 #include "CalibFormats/SiStripObjects/interface/NumberOfDevices.h"
00005 #include "CalibFormats/SiStripObjects/interface/SiStripFecCabling.h"
00006 #include "CondFormats/SiStripObjects/interface/CommissioningAnalysis.h"
00007 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00008 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00009 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00010 #include "OnlineDB/SiStripConfigDb/interface/SiStripConfigDb.h"
00011 #include "OnlineDB/SiStripESSources/interface/SiStripFedCablingBuilderFromDb.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 #include <iostream>
00014
00015 using namespace sistrip;
00016
00017
00019 CommissioningHistosUsingDb::CommissioningHistosUsingDb( SiStripConfigDb* const db,
00020 sistrip::RunType type )
00021 : CommissioningHistograms(),
00022 runType_(type),
00023 db_(db),
00024 cabling_(0),
00025 detInfo_(),
00026 uploadAnal_(true),
00027 uploadConf_(false)
00028 {
00029 LogTrace(mlDqmClient_)
00030 << "[" << __PRETTY_FUNCTION__ << "]"
00031 << " Constructing object...";
00032
00033
00034 SiStripFecCabling fec_cabling;
00035 if ( runType_ == sistrip::FAST_CABLING ) {
00036 SiStripFedCablingBuilderFromDb::buildFecCablingFromDevices( db_, fec_cabling );
00037 } else {
00038 SiStripFedCablingBuilderFromDb::buildFecCabling( db_, fec_cabling );
00039 }
00040
00041
00042 cabling_ = new SiStripFedCabling();
00043 SiStripFedCablingBuilderFromDb::getFedCabling( fec_cabling, *cabling_ );
00044 std::stringstream ss;
00045 ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
00046 << " Terse print out of FED cabling:" << std::endl;
00047 cabling_->terse(ss);
00048 LogTrace(mlDqmClient_) << ss.str();
00049
00050 std::stringstream sss;
00051 sss << "[CommissioningHistosUsingDb::" << __func__ << "]"
00052 << " Summary of FED cabling:" << std::endl;
00053 cabling_->summary(sss);
00054 edm::LogVerbatim(mlDqmClient_) << sss.str();
00055
00056 }
00057
00058
00060 CommissioningHistosUsingDb::CommissioningHistosUsingDb()
00061 : CommissioningHistograms(),
00062 runType_(sistrip::UNDEFINED_RUN_TYPE),
00063 db_(0),
00064 cabling_(0),
00065 detInfo_(),
00066 uploadAnal_(false),
00067 uploadConf_(false)
00068 {
00069 LogTrace(mlDqmClient_)
00070 << "[" << __PRETTY_FUNCTION__ << "]"
00071 << " Constructing object..." << endl;
00072 }
00073
00074
00076 CommissioningHistosUsingDb::~CommissioningHistosUsingDb() {
00077 if ( db_ ) { delete db_; }
00078 LogTrace(mlDqmClient_)
00079 << "[" << __PRETTY_FUNCTION__ << "]"
00080 << " Destructing object...";
00081 }
00082
00083
00085 void CommissioningHistosUsingDb::uploadToConfigDb() {
00086 buildDetInfo();
00087 addDcuDetIds();
00088 uploadConfigurations();
00089 uploadAnalyses();
00090 }
00091
00092
00094 void CommissioningHistosUsingDb::uploadAnalyses() {
00095
00096 if ( !db_ ) {
00097 edm::LogError(mlDqmClient_)
00098 << "[CommissioningHistosUsingDb::" << __func__ << "]"
00099 << " NULL pointer to SiStripConfigDb interface!"
00100 << " Aborting upload...";
00101 return;
00102 }
00103
00104 db_->clearAnalysisDescriptions();
00105 SiStripDbParams::SiStripPartitions::const_iterator ip = db_->dbParams().partitions().begin();
00106 SiStripDbParams::SiStripPartitions::const_iterator jp = db_->dbParams().partitions().end();
00107 for ( ; ip != jp; ++ip ) {
00108
00109 edm::LogVerbatim(mlDqmClient_)
00110 << "[CommissioningHistosUsingDb::" << __func__ << "]"
00111 << " Starting from partition " << ip->first
00112 << " with versions:\n" << std::dec
00113 << " Conn: " << ip->second.cabVersion().first << "." << ip->second.cabVersion().second << "\n"
00114 << " FED: " << ip->second.fedVersion().first << "." << ip->second.fedVersion().second << "\n"
00115 << " FEC: " << ip->second.fecVersion().first << "." << ip->second.fecVersion().second << "\n"
00116 << " Mask: " << ip->second.maskVersion().first << "." << ip->second.maskVersion().second;
00117
00118
00119 SiStripConfigDb::AnalysisDescriptionsV anals;
00120 createAnalyses( anals );
00121
00122 edm::LogVerbatim(mlDqmClient_)
00123 << "[CommissioningHistosUsingDb::" << __func__ << "]"
00124 << " Created analysis descriptions for "
00125 << anals.size() << " devices";
00126
00127
00128 if ( uploadAnal_ ) {
00129 if ( uploadConf_ ) {
00130 edm::LogVerbatim(mlDqmClient_)
00131 << "[CommissioningHistosUsingDb::" << __func__ << "]"
00132 << " Uploading major version of analysis descriptions to DB"
00133 << " (will be used for physics)...";
00134 }
00135 else {
00136 edm::LogVerbatim(mlDqmClient_)
00137 << "[CommissioningHistosUsingDb::" << __func__ << "]"
00138 << " Uploading minor version of analysis descriptions to DB"
00139 << " (will not be used for physics)...";
00140 }
00141 db_->clearAnalysisDescriptions( ip->second.partitionName() );
00142 db_->addAnalysisDescriptions( ip->second.partitionName(), anals );
00143 db_->uploadAnalysisDescriptions( uploadConf_, ip->second.partitionName() );
00144 edm::LogVerbatim(mlDqmClient_)
00145 << "[CommissioningHistosUsingDb::" << __func__ << "]"
00146 << " Upload of analysis descriptions to DB finished!";
00147 }
00148 else {
00149 edm::LogWarning(mlDqmClient_)
00150 << "[CommissioningHistosUsingDb::" << __func__ << "]"
00151 << " TEST! No analysis descriptions will be uploaded to DB...";
00152 }
00153
00154 if ( uploadConf_ ) {
00155 SiStripDbParams::SiStripPartitions::const_iterator ip = db_->dbParams().partitions().begin();
00156 SiStripDbParams::SiStripPartitions::const_iterator jp = db_->dbParams().partitions().end();
00157 for ( ; ip != jp; ++ip ) {
00158 DeviceFactory* df = db_->deviceFactory();
00159 tkStateVector states = df->getCurrentStates();
00160 tkStateVector::const_iterator istate = states.begin();
00161 tkStateVector::const_iterator jstate = states.end();
00162 while ( istate != jstate ) {
00163 if ( *istate && ip->first == (*istate)->getPartitionName() ) { break; }
00164 istate++;
00165 }
00166
00167 if ( istate != states.end() ) {
00168 edm::LogVerbatim(mlDqmClient_)
00169 << "[CommissioningHistosUsingDb::" << __func__ << "]"
00170 << " Created new version for partition " << ip->first
00171 << ". Current state:\n" << std::dec
00172 << " Conn: " << (*istate)->getConnectionVersionMajorId() << "." << (*istate)->getConnectionVersionMinorId() << "\n"
00173 << " FED: " << (*istate)->getFedVersionMajorId() << "." << (*istate)->getFedVersionMinorId() << "\n"
00174 << " FEC: " << (*istate)->getFecVersionMajorId() << "." << (*istate)->getFecVersionMinorId() << "\n"
00175 << " Mask: " << (*istate)->getMaskVersionMajorId() << "." << (*istate)->getMaskVersionMinorId();
00176 }
00177 }
00178 }
00179
00180 }
00181
00182 }
00183
00184
00186 void CommissioningHistosUsingDb::addDcuDetIds() {
00187
00188 if ( !cabling_ ) {
00189 edm::LogWarning(mlDqmClient_)
00190 << "[CommissioningHistosUsingDb::" << __func__ << "]"
00191 << " NULL pointer to SiStripFedCabling object!";
00192 return;
00193 }
00194
00195 Analyses::iterator ianal = data().begin();
00196 Analyses::iterator janal = data().end();
00197 for ( ; ianal != janal; ++ianal ) {
00198
00199 CommissioningAnalysis* anal = ianal->second;
00200
00201 if ( !anal ) {
00202 edm::LogWarning(mlDqmClient_)
00203 << "[CommissioningHistosUsingDb::" << __func__ << "]"
00204 << " NULL pointer to CommissioningAnalysis object!";
00205 return;
00206 }
00207
00208 SiStripFedKey fed_key = anal->fedKey();
00209 SiStripFecKey fec_key = anal->fecKey();
00210
00211 FedChannelConnection conn = cabling_->connection( fed_key.fedId(),
00212 fed_key.fedChannel() );
00213
00214 SiStripFedKey fed( conn.fedId(),
00215 SiStripFedKey::feUnit( conn.fedCh() ),
00216 SiStripFedKey::feChan( conn.fedCh() ) );
00217
00218 SiStripFecKey fec( conn.fecCrate(),
00219 conn.fecSlot(),
00220 conn.fecRing(),
00221 conn.ccuAddr(),
00222 conn.ccuChan(),
00223 conn.lldChannel() );
00224
00225 if ( fed_key.path() != fed.path() ) {
00226
00227 std::stringstream ss;
00228 ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
00229 << " Cannot set DCU and DetId values in commissioning analysis object!" << std::endl
00230 << " Incompatible FED key retrieved from cabling!" << std::endl
00231 << " FED key from analysis object : " << fed_key.path() << std::endl
00232 << " FED key from cabling object : " << fed.path() << std::endl
00233 << " FED id/ch from analysis object: " << fed_key.fedId() << "/" << fed_key.fedChannel() << std::endl
00234 << " FED id/ch from cabling object : " << conn.fedId() << "/" << conn.fedCh();
00235 edm::LogWarning(mlDqmClient_) << ss.str();
00236
00237 } else if ( fec_key.path() != fec.path() ) {
00238
00239 std::stringstream ss;
00240 ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
00241 << " Cannot set DCU and DetId values in commissioning analysis object!" << std::endl
00242 << " Incompatible FEC key retrieved from cabling!" << std::endl
00243 << " FEC key from analysis object : " << fec_key.path() << std::endl
00244 << " FEC key from cabling object : " << fec.path();
00245 edm::LogWarning(mlDqmClient_) << ss.str();
00246
00247 } else {
00248
00249 anal->dcuId( conn.dcuId() );
00250 anal->detId( conn.detId() );
00251
00252 }
00253
00254 }
00255
00256 }
00257
00258
00259
00260 void CommissioningHistosUsingDb::createAnalyses( SiStripConfigDb::AnalysisDescriptionsV& desc ) {
00261
00262 LogTrace(mlDqmClient_)
00263 << "[CommissioningHistosUsingDb::" << __func__ << "]"
00264 << " Creating AnalysisDescriptions...";
00265
00266 desc.clear();
00267
00268
00269
00270
00271
00272
00273 Analyses::iterator ianal = data().begin();
00274 Analyses::iterator janal = data().end();
00275 for ( ; ianal != janal; ++ianal ) {
00276
00277
00278 create( desc, ianal );
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 }
00292
00293
00294
00295 }
00296
00297
00298
00299 void CommissioningHistosUsingDb::buildDetInfo() {
00300
00301 detInfo_.clear();
00302
00303 if ( !db() ) {
00304 edm::LogError(mlDqmClient_)
00305 << "[CommissioningHistosUsingDb::" << __func__ << "]"
00306 << " NULL pointer to SiStripConfigDb interface!";
00307 return;
00308 }
00309
00310 SiStripDbParams::SiStripPartitions::const_iterator ii = db_->dbParams().partitions().begin();
00311 SiStripDbParams::SiStripPartitions::const_iterator jj = db_->dbParams().partitions().end();
00312 for ( ; ii != jj; ++ii ) {
00313
00314
00315 std::string pp = ii->second.partitionName();
00316 SiStripConfigDb::DeviceDescriptionsRange dcus = db()->getDeviceDescriptions( DCU, pp );
00317 SiStripConfigDb::DcuDetIdsRange dets = db()->getDcuDetIds( pp );
00318
00319
00320 SiStripConfigDb::DeviceDescriptionsV::const_iterator idcu = dcus.begin();
00321 SiStripConfigDb::DeviceDescriptionsV::const_iterator jdcu = dcus.end();
00322 for ( ; idcu != jdcu; ++idcu ) {
00323
00324
00325 dcuDescription* dcu = dynamic_cast<dcuDescription*>( *idcu );
00326 if ( !dcu ) { continue; }
00327 if ( dcu->getDcuType() != "FEH" ) { continue; }
00328
00329
00330
00331
00332 if ( dcu->getDcuHardId() == 16448250 ) continue;
00333
00334
00335 SiStripConfigDb::DcuDetIdsV::const_iterator idet = dets.end();
00336 idet = SiStripConfigDb::findDcuDetId( dets.begin(), dets.end(), dcu->getDcuHardId() );
00337 if ( idet == dets.begin() ) { continue; }
00338
00339
00340 TkDcuInfo* det = idet->second;
00341 if ( !det ) { continue; }
00342
00343
00344 const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress( *dcu );
00345 SiStripFecKey fec_key( addr.fecCrate_,
00346 addr.fecSlot_,
00347 addr.fecRing_,
00348 addr.ccuAddr_,
00349 addr.ccuChan_ );
00350
00351
00352 DetInfo info;
00353 info.dcuId_ = det->getDcuHardId();
00354 info.detId_ = det->getDetId();
00355 info.pairs_ = det->getApvNumber()/2;
00356
00357
00358 if ( fec_key.isValid() ) { detInfo_[pp][fec_key.key()] = info; }
00359
00360 }
00361 }
00362
00363
00364 if ( edm::isDebugEnabled() ) {
00365 std::stringstream ss;
00366 ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
00367 << " List of modules for "
00368 << detInfo_.size()
00369 << " partitions, with their DCUids, DetIds, and nApvPairs: " << std::endl;
00370 std::map<std::string,DetInfos>::const_iterator ii = detInfo_.begin();
00371 std::map<std::string,DetInfos>::const_iterator jj = detInfo_.end();
00372 for ( ; ii != jj; ++ii ) {
00373 ss << " Partition \"" << ii->first
00374 << "\" has " << ii->second.size()
00375 << " modules:"
00376 << std::endl;
00377 DetInfos::const_iterator iii = ii->second.begin();
00378 DetInfos::const_iterator jjj = ii->second.end();
00379 for ( ; iii != jjj; ++iii ) {
00380 SiStripFecKey key = iii->first;
00381 ss << " module= "
00382 << key.fecCrate() << "/"
00383 << key.fecSlot() << "/"
00384 << key.fecRing() << "/"
00385 << key.ccuAddr() << "/"
00386 << key.ccuChan() << ", "
00387 << std::hex
00388 << " DCUid= "
00389 << std::setw(8) << std::setfill('0') << iii->second.dcuId_
00390 << " DetId= "
00391 << std::setw(8) << std::setfill('0') << iii->second.detId_
00392 << std::dec
00393 << " nPairs= "
00394 << iii->second.pairs_
00395 << std::endl;
00396 }
00397 }
00398
00399 }
00400
00401 }
00402
00403
00404
00405 std::pair<std::string,CommissioningHistosUsingDb::DetInfo> CommissioningHistosUsingDb::detInfo( const SiStripFecKey& key ) {
00406 SiStripFecKey tmp( key, sistrip::CCU_CHAN );
00407 if ( tmp.isInvalid() ) { return std::make_pair("",DetInfo()); }
00408 std::map<std::string,DetInfos>::const_iterator ii = detInfo_.begin();
00409 std::map<std::string,DetInfos>::const_iterator jj = detInfo_.end();
00410 for ( ; ii != jj; ++ii ) {
00411 DetInfos::const_iterator iii = ii->second.find( tmp.key() );
00412 if ( iii != ii->second.end() ) { return std::make_pair(ii->first,iii->second); }
00413 }
00414 return std::make_pair("",DetInfo());
00415 }
00416
00417
00418
00419 bool CommissioningHistosUsingDb::deviceIsPresent( const SiStripFecKey& key ) {
00420 SiStripFecKey tmp( key, sistrip::CCU_CHAN );
00421 std::pair<std::string,DetInfo> info = detInfo(key);
00422 if ( info.second.dcuId_ != sistrip::invalid32_ ) {
00423 if ( key.channel() == 2 && info.second.pairs_ == 2 ) { return false; }
00424 else { return true; }
00425 } else {
00426 std::stringstream ss;
00427 ss << "[CommissioningHistosUsingDb::" << __func__ << "]"
00428 << " Cannot find module (crate/FEC/ring/CCU/module): "
00429 << tmp.fecCrate() << "/"
00430 << tmp.fecSlot() << "/"
00431 << tmp.fecRing() << "/"
00432 << tmp.ccuAddr() << "/"
00433 << tmp.ccuChan()
00434 << "!";
00435 edm::LogWarning(mlDqmClient_) << ss.str();
00436 return true;
00437 }
00438 }
00439
00440
00441
00442