00001 #include "DQM/SiStripCommissioningSources/interface/SiStripCommissioningSource.h"
00002 #include "CalibFormats/SiStripObjects/interface/SiStripFecCabling.h"
00003 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
00004 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00007 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
00008 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
00009 #include "DataFormats/SiStripCommon/interface/SiStripEventSummary.h"
00010 #include "DQM/SiStripCommissioningSources/interface/Averages.h"
00011 #include "DQM/SiStripCommissioningSources/interface/FastFedCablingTask.h"
00012 #include "DQM/SiStripCommissioningSources/interface/FedCablingTask.h"
00013 #include "DQM/SiStripCommissioningSources/interface/ApvTimingTask.h"
00014 #include "DQM/SiStripCommissioningSources/interface/FedTimingTask.h"
00015 #include "DQM/SiStripCommissioningSources/interface/OptoScanTask.h"
00016 #include "DQM/SiStripCommissioningSources/interface/VpspScanTask.h"
00017 #include "DQM/SiStripCommissioningSources/interface/PedestalsTask.h"
00018 #include "DQM/SiStripCommissioningSources/interface/PedsOnlyTask.h"
00019 #include "DQM/SiStripCommissioningSources/interface/NoiseTask.h"
00020 #include "DQM/SiStripCommissioningSources/interface/PedsFullNoiseTask.h"
00021 #include "DQM/SiStripCommissioningSources/interface/DaqScopeModeTask.h"
00022 #include "DQM/SiStripCommissioningSources/interface/LatencyTask.h"
00023 #include "DQM/SiStripCommissioningSources/interface/FineDelayTask.h"
00024 #include "DQM/SiStripCommissioningSources/interface/CalibrationTask.h"
00025 #include "DQM/SiStripCommissioningSources/interface/CalibrationScanTask.h"
00026 #include "DQMServices/Core/interface/DQMStore.h"
00027 #include "FWCore/Framework/interface/ESHandle.h"
00028 #include "FWCore/Framework/interface/EventSetup.h"
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "FWCore/ServiceRegistry/interface/Service.h"
00033 #include "FWCore/Utilities/interface/Exception.h"
00034 #include <boost/cstdint.hpp>
00035 #include <memory>
00036 #include <iomanip>
00037 #include <sstream>
00038 #include <time.h>
00039
00040 #include <sys/types.h>
00041 #include <unistd.h>
00042 #include <iomanip>
00043
00044 #include <arpa/inet.h>
00045 #include <sys/unistd.h>
00046 #include <sys/socket.h>
00047 #include <netdb.h>
00048 #include <stdio.h>
00049
00050
00051 using namespace sistrip;
00052
00053
00054
00055 SiStripCommissioningSource::SiStripCommissioningSource( const edm::ParameterSet& pset ) :
00056 dqm_(0),
00057 fedCabling_(0),
00058 fecCabling_(0),
00059 inputModuleLabel_( pset.getParameter<std::string>( "InputModuleLabel" ) ),
00060 inputModuleLabelSummary_( pset.getParameter<std::string>( "SummaryInputModuleLabel" ) ),
00061 filename_( pset.getUntrackedParameter<std::string>("RootFileName",sistrip::dqmSourceFileName_) ),
00062 run_(0),
00063 time_(0),
00064 taskConfigurable_( pset.getUntrackedParameter<std::string>("CommissioningTask","UNDEFINED") ),
00065 task_(sistrip::UNDEFINED_RUN_TYPE),
00066 tasks_(),
00067 cablingTasks_(),
00068 tasksExist_(false),
00069 cablingTask_(false),
00070 updateFreq_( pset.getUntrackedParameter<int>("HistoUpdateFreq",1) ),
00071 base_(""),
00072 view_( pset.getUntrackedParameter<std::string>("View", "Default") ),
00073 parameters_(pset)
00074 {
00075 LogTrace(mlDqmSource_)
00076 << "[SiStripCommissioningSource::" << __func__ << "]"
00077 << " Constructing object...";
00078 tasks_.clear();
00079 tasks_.resize( 1024, VecOfTasks(96,static_cast<CommissioningTask*>(0)) );
00080 }
00081
00082
00083
00084 SiStripCommissioningSource::~SiStripCommissioningSource() {
00085 LogTrace(mlDqmSource_)
00086 << "[SiStripCommissioningSource::" << __func__ << "]"
00087 << " Destructing object...";
00088 }
00089
00090
00091
00092 DQMStore* const SiStripCommissioningSource::dqm( std::string method ) const {
00093 if ( !dqm_ ) {
00094 std::stringstream ss;
00095 if ( method != "" ) { ss << "[SiStripCommissioningSource::" << method << "]" << std::endl; }
00096 else { ss << "[SiStripCommissioningSource]" << std::endl; }
00097 ss << " NULL pointer to DQMStore";
00098 edm::LogWarning(mlDqmSource_) << ss.str();
00099 return 0;
00100 } else { return dqm_; }
00101 }
00102
00103
00104
00105
00106
00107 void SiStripCommissioningSource::beginRun( edm::Run const & run, const edm::EventSetup & setup ) {
00108 LogTrace(mlDqmSource_)
00109 << "[SiStripCommissioningSource::" << __func__ << "]"
00110 << " Configuring..." << std::endl;
00111
00112
00113
00114 dqm_ = edm::Service<DQMStore>().operator->();
00115 edm::LogInfo(mlDqmSource_)
00116 << "[SiStripCommissioningSource::" << __func__ << "]"
00117 << " DQMStore service: "
00118 << dqm_;
00119 dqm(__func__);
00120 dqm()->setVerbose(0);
00121
00122
00123
00124 std::stringstream dir("");
00125 base_ = dir.str();
00126
00127
00128
00129 edm::ESHandle<SiStripFedCabling> fed_cabling;
00130 setup.get<SiStripFedCablingRcd>().get( fed_cabling );
00131 fedCabling_ = const_cast<SiStripFedCabling*>( fed_cabling.product() );
00132 LogDebug(mlDqmSource_)
00133 << "[SiStripCommissioningSource::" << __func__ << "]"
00134 << "Initialized FED cabling. Number of FEDs is " << fedCabling_->feds().size();
00135 fecCabling_ = new SiStripFecCabling( *fed_cabling );
00136 if ( fecCabling_->crates().empty() ) {
00137 std::stringstream ss;
00138 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00139 << " Empty std::vector returned by FEC cabling object!"
00140 << " Check if database connection failed...";
00141 edm::LogWarning(mlDqmSource_) << ss.str();
00142 }
00143
00144
00145
00146 tasksExist_ = false;
00147 task_ = sistrip::UNDEFINED_RUN_TYPE;
00148 cablingTask_ = false;
00149
00150 remove();
00151
00152 clearCablingTasks();
00153 clearTasks();
00154
00155 }
00156
00157
00158
00159 void SiStripCommissioningSource::endJob() {
00160 LogTrace(mlDqmSource_)
00161 << "[SiStripCommissioningSource::" << __func__ << "]"
00162 << " Halting..." << std::endl;
00163
00164
00165
00166
00167 for ( TaskMap::iterator itask = cablingTasks_.begin(); itask != cablingTasks_.end(); itask++ ) {
00168 if ( itask->second ) { itask->second->updateHistograms(); }
00169 }
00170
00171 if (task_ == sistrip::APV_LATENCY) {
00172 for (uint16_t partition = 0; partition < 4; ++partition) {
00173 tasks_[0][partition]->updateHistograms();
00174 }
00175 } else if (task_ == sistrip::FINE_DELAY ) {
00176 tasks_[0][0]->updateHistograms();
00177 } else {
00178
00179 uint16_t fed_id = 0;
00180 uint16_t fed_ch = 0;
00181 std::vector<uint16_t>::const_iterator ifed = fedCabling_->feds().begin();
00182 for ( ; ifed != fedCabling_->feds().end(); ifed++ ) {
00183 const std::vector<FedChannelConnection>& conns = fedCabling_->connections(*ifed);
00184 std::vector<FedChannelConnection>::const_iterator iconn = conns.begin();
00185 for ( ; iconn != conns.end(); iconn++ ) {
00186 if ( !iconn->isConnected() ) { continue; }
00187 fed_id = iconn->fedId();
00188 fed_ch = iconn->fedCh();
00189 if ( tasks_[fed_id][fed_ch] ) {
00190 tasks_[fed_id][fed_ch]->updateHistograms();
00191 delete tasks_[fed_id][fed_ch];
00192 }
00193 }
00194 }
00195 }
00196
00197
00198
00199
00200 std::string name;
00201 if ( filename_.find(".root",0) == std::string::npos ) { name = filename_; }
00202 else { name = filename_.substr( 0, filename_.find(".root",0) ); }
00203
00204
00205 std::string scratch = "SCRATCH";
00206 std::string dir = "";
00207 if ( getenv(scratch.c_str()) != NULL ) {
00208 dir = getenv(scratch.c_str());
00209 }
00210
00211
00212 std::stringstream ss;
00213 if ( !dir.empty() ) { ss << dir << "/"; }
00214 else { ss << "/tmp/"; }
00215
00216
00217 ss << name << "_";
00218 directory(ss,run_);
00219 ss << ".root";
00220
00221
00222 if ( !filename_.empty() ) {
00223 if ( run_ != 0 ) { dqm()->save( ss.str() ); }
00224 else {
00225 edm::LogWarning(mlDqmSource_)
00226 << "[SiStripCommissioningSource::" << __func__ << "]"
00227 << " NULL value for RunNumber! No root file saved!";
00228 }
00229 } else {
00230 edm::LogWarning(mlDqmSource_)
00231 << "[SiStripCommissioningSource::" << __func__ << "]"
00232 << " NULL value for filename! No root file saved!";
00233 }
00234
00235 LogTrace(mlDqmSource_)
00236 << "[SiStripCommissioningSource::" << __func__ << "]"
00237 << " Saved all histograms to file \""
00238 << ss.str() << "\"";
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 if ( fedCabling_ ) { fedCabling_ = 0; }
00252 if ( fecCabling_ ) { delete fecCabling_; fecCabling_ = 0; }
00253
00254 }
00255
00256
00257
00258 void SiStripCommissioningSource::analyze( const edm::Event& event,
00259 const edm::EventSetup& setup ) {
00260
00261 edm::Handle<SiStripEventSummary> summary;
00262 event.getByLabel( inputModuleLabelSummary_, summary );
00263
00264
00265 if ( ( summary->runType() == sistrip::UNDEFINED_RUN_TYPE ||
00266 summary->runType() == sistrip::UNKNOWN_RUN_TYPE ) &&
00267 summary->nullParams() ) {
00268 edm::LogWarning(mlDqmSource_)
00269 << "[SiStripCommissioningSource::" << __func__ << "]"
00270 << " Unknown/undefined RunType and NULL parameter values!"
00271 << " It may be that the 'trigger FED' object was not found!";
00272 }
00273
00274
00275
00276
00277
00278 if ( event.id().run() != run_ ) {
00279 run_ = event.id().run();
00280 createRunNumber();
00281 }
00282
00283
00284 if ( !(event.id().event()%updateFreq_) ) {
00285 std::stringstream ss;
00286 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00287 << " The last " << updateFreq_
00288 << " events were processed at a rate of ";
00289 if ( time(NULL) == time_ ) { ss << ">" << updateFreq_ << " Hz"; }
00290 else { ss << (updateFreq_/(time(NULL)-time_)) << " Hz"; }
00291 edm::LogVerbatim(mlDqmSource_) << ss.str();
00292 time_ = time(NULL);
00293 }
00294
00295
00296 if ( !tasksExist_ ) { createTask( summary.product(), setup ); }
00297
00298
00299 edm::Handle< edm::DetSetVector<SiStripRawDigi> > raw;
00300 if ( task_ == sistrip::DAQ_SCOPE_MODE ) {
00301 if ( summary->fedReadoutMode() == FED_VIRGIN_RAW ) {
00302 event.getByLabel( inputModuleLabel_, "VirginRaw", raw );
00303 } else if ( summary->fedReadoutMode() == FED_SCOPE_MODE ) {
00304 event.getByLabel( inputModuleLabel_, "ScopeMode", raw );
00305 } else {
00306 std::stringstream ss;
00307 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00308 << " Requested DAQ_SCOPE_MODE but unknown FED"
00309 << " readout mode retrieved from SiStripEventSummary: "
00310 << SiStripEnumsAndStrings::fedReadoutMode( summary->fedReadoutMode() );
00311 edm::LogWarning(mlDqmSource_) << ss.str();
00312 }
00313 } else if ( task_ == sistrip::FAST_CABLING ||
00314 task_ == sistrip::FED_CABLING ||
00315 task_ == sistrip::APV_TIMING ||
00316 task_ == sistrip::FED_TIMING ||
00317 task_ == sistrip::OPTO_SCAN ) {
00318 event.getByLabel( inputModuleLabel_, "ScopeMode", raw );
00319 } else if ( task_ == sistrip::VPSP_SCAN ||
00320 task_ == sistrip::CALIBRATION ||
00321 task_ == sistrip::CALIBRATION_DECO ||
00322 task_ == sistrip::CALIBRATION_SCAN ||
00323 task_ == sistrip::CALIBRATION_SCAN_DECO ||
00324 task_ == sistrip::PEDESTALS ||
00325 task_ == sistrip::PEDS_ONLY ||
00326 task_ == sistrip::NOISE ||
00327 task_ == sistrip::PEDS_FULL_NOISE ) {
00328 event.getByLabel( inputModuleLabel_, "VirginRaw", raw );
00329 } else if ( task_ == sistrip::APV_LATENCY ||
00330 task_ == sistrip::FINE_DELAY ) {
00331 event.getByLabel( inputModuleLabel_, "FineDelaySelection", raw );
00332 } else {
00333 std::stringstream ss;
00334 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00335 << " Unknown CommissioningTask: "
00336 << SiStripEnumsAndStrings::runType( task_ )
00337 << " Unable to establish FED readout mode and retrieve digi container!"
00338 << " Check if SiStripEventSummary object is found/present in Event";
00339 edm::LogWarning(mlDqmSource_) << ss.str();
00340 return;
00341 }
00342
00343
00344 if ( &(*raw) == 0 ) {
00345 std::stringstream ss;
00346 ss << "[SiStripCommissioningSource::" << __func__ << "]" << std::endl
00347 << " NULL pointer to DetSetVector!" << std::endl
00348 << " Unable to fill histograms!";
00349 edm::LogWarning(mlDqmSource_) << ss.str();
00350 return;
00351 }
00352
00353 if ( !cablingTask_ ) { fillHistos( summary.product(), *raw ); }
00354 else { fillCablingHistos( summary.product(), *raw ); }
00355
00356 }
00357
00358
00359
00360 void SiStripCommissioningSource::fillCablingHistos( const SiStripEventSummary* const summary,
00361 const edm::DetSetVector<SiStripRawDigi>& raw ) {
00362
00363
00364 const SiStripModule& module = fecCabling_->module( summary->dcuId() );
00365 uint16_t lld_channel = ( summary->deviceId() & 0x3 ) + 1;
00366 SiStripFecKey key_object( module.key().fecCrate(),
00367 module.key().fecSlot(),
00368 module.key().fecRing(),
00369 module.key().ccuAddr(),
00370 module.key().ccuChan(),
00371 lld_channel );
00372 uint32_t fec_key = key_object.key();
00373 std::stringstream sss;
00374 sss << "[SiStripCommissioningSource::" << __func__ << "]"
00375 << " Found DcuId 0x"
00376 << std::hex << std::setw(8) << std::setfill('0') << summary->dcuId() << std::dec
00377 << " with Crate/FEC/Ring/CCU/Module/LLD: "
00378 << module.key().fecCrate() << "/"
00379 << module.key().fecSlot() << "/"
00380 << module.key().fecRing() << "/"
00381 << module.key().ccuAddr() << "/"
00382 << module.key().ccuChan() << "/"
00383 << lld_channel;
00384 edm::LogWarning(mlDqmSource_) << sss.str();
00385
00386
00387
00388
00389 if ( key_object.isInvalid( sistrip::CCU_CHAN ) ) {
00390 std::stringstream ss;
00391 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00392 << " DcuId 0x"
00393 << std::hex << std::setw(8) << std::setfill('0') << summary->dcuId() << std::dec
00394 << " in 'DAQ register' field not found in cabling map!"
00395 << " (NULL values returned for FEC path)";
00396 edm::LogWarning(mlDqmSource_) << ss.str();
00397 return;
00398 }
00399
00400
00401 std::vector<uint16_t>::const_iterator ifed = fedCabling_->feds().begin();
00402 for ( ; ifed != fedCabling_->feds().end(); ifed++ ) {
00403
00404
00405 if ( *ifed == sistrip::invalid_ ) { continue; }
00406
00407
00408 std::map<uint16_t,float> medians; medians.clear();
00409 std::map<uint16_t,float> medians1; medians1.clear();
00410
00411
00412 for ( uint16_t ichan = 0; ichan < 96; ichan++ ) {
00413
00414
00415
00416
00417
00418
00419
00420 uint32_t fed_key = ( ( *ifed & sistrip::invalid_ ) << 16 ) | ( ichan & sistrip::invalid_ );
00421
00422 std::vector< edm::DetSet<SiStripRawDigi> >::const_iterator digis = raw.find( fed_key );
00423 if ( digis != raw.end() ) {
00424 if ( digis->data.empty() ) { continue; }
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434 Averages ave;
00435 for ( uint16_t idigi = 0; idigi < digis->data.size(); idigi++ ) {
00436 ave.add( static_cast<uint32_t>(digis->data[idigi].adc()) );
00437 }
00438 Averages::Params params;
00439 ave.calc(params);
00440 medians[ichan] = params.median_;
00441 medians1[ichan] = digis->data[0].adc();
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 }
00461
00462 }
00463
00464
00465 Averages average;
00466 std::map<uint16_t,float>::const_iterator ii = medians.begin();
00467 for ( ; ii != medians.end(); ii++ ) { average.add( ii->second ); }
00468 Averages::Params tmp;
00469 average.calc(tmp);
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484 Averages truncated;
00485 std::map<uint16_t,float>::const_iterator jj = medians.begin();
00486 for ( ; jj != medians.end(); jj++ ) {
00487 if ( jj->second < tmp.median_+tmp.rms_ ) {
00488 truncated.add( jj->second );
00489 }
00490 }
00491 Averages::Params params;
00492 truncated.calc(params);
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507 std::stringstream ss2;
00508 std::stringstream ss3;
00509
00510
00511 std::map<uint16_t,float> channels;
00512 std::map<uint16_t,float>::const_iterator ichan = medians.begin();
00513 for ( ; ichan != medians.end(); ichan++ ) {
00514
00515
00516
00517
00518
00519
00520 if ( ichan->second > 200. ) {
00521 LogTrace(mlTest_) << "TEST FOUND SIGNAL HIGH: " << *ifed << " " << ichan->first << " " << ichan->second;
00522 channels[ichan->first] = ichan->second;
00523 }
00524 ss2
00525 << ichan->second << " ";
00526 ss3
00527 << medians1[ichan->first] << " ";
00528 }
00529
00530 ss2 << std::endl;
00531 ss3 << std::endl;
00532 LogTrace(mlTest_) << "DUMP for FED " << *ifed << ": " << ss2.str();
00533 LogTrace(mlTest_) << "FIRST ADC VAL " << *ifed << ": " << ss3.str();
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554 if ( cablingTasks_.find(fec_key) != cablingTasks_.end() ) {
00555 if ( !channels.empty() ) {
00556 cablingTasks_[fec_key]->fillHistograms( *summary, *ifed, channels );
00557 SiStripFecKey path( fec_key );
00558 std::stringstream ss;
00559 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00560 << " Filled histogram for '" << cablingTasks_[fec_key]->myName()
00561 << "' object with FecKey: 0x"
00562 << std::hex << std::setfill('0') << std::setw(8) << fec_key << std::dec
00563 << " and Crate/FEC/ring/CCU/module/LLDchan: "
00564 << path.fecCrate() << "/"
00565 << path.fecSlot() << "/"
00566 << path.fecRing() << "/"
00567 << path.ccuAddr() << "/"
00568 << path.ccuChan() << "/"
00569 << path.channel();
00570 LogTrace(mlDqmSource_) << ss.str();
00571 }
00572 } else {
00573 SiStripFecKey path( fec_key );
00574 std::stringstream ss;
00575 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00576 << " Unable to find CommissioningTask object with FecKey: 0x"
00577 << std::hex << std::setfill('0') << std::setw(8) << fec_key << std::dec
00578 << " and Crate/FEC/ring/CCU/module/LLDchan: "
00579 << path.fecCrate() << "/"
00580 << path.fecSlot() << "/"
00581 << path.fecRing() << "/"
00582 << path.ccuAddr() << "/"
00583 << path.ccuChan() << "/"
00584 << path.channel();
00585 edm::LogWarning(mlDqmSource_) << ss.str();
00586 }
00587
00588 }
00589
00590 }
00591
00592
00593
00594 void SiStripCommissioningSource::fillHistos( const SiStripEventSummary* const summary,
00595 const edm::DetSetVector<SiStripRawDigi>& raw ) {
00596
00597
00598 std::vector<uint16_t>::const_iterator ifed = fedCabling_->feds().begin();
00599 for ( ; ifed != fedCabling_->feds().end(); ifed++ ) {
00600
00601
00602 const std::vector<FedChannelConnection>& conns = fedCabling_->connections(*ifed);
00603 std::vector<FedChannelConnection>::const_iterator iconn = conns.begin();
00604 for ( ; iconn != conns.end(); iconn++ ) {
00605
00606 if ( !(iconn->fedId()) || iconn->fedId() > sistrip::valid_ ) { continue; }
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616 uint32_t fed_key = ( ( iconn->fedId() & sistrip::invalid_ ) << 16 ) | ( iconn->fedCh() & sistrip::invalid_ );
00617
00618
00619 std::vector< edm::DetSet<SiStripRawDigi> >::const_iterator digis = raw.find( fed_key );
00620
00621 if ( digis != raw.end() ) {
00622
00623 if (task_ == sistrip::APV_LATENCY) {
00624 if ( tasks_[0][iconn->fecCrate()-1] ) {
00625 tasks_[0][iconn->fecCrate()-1]->fillHistograms( *summary, *digis );
00626 } else {
00627 std::stringstream ss;
00628 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00629 << " Unable to find CommissioningTask for FEC crate "
00630 << iconn->fecCrate() << ". Unable to fill histograms!";
00631 edm::LogWarning(mlDqmSource_) << ss.str();
00632 }
00633 } else if (task_ == sistrip::FINE_DELAY) {
00634 if ( tasks_[0][0] ) {
00635 tasks_[0][0]->fillHistograms( *summary, *digis );
00636 } else {
00637 std::stringstream ss;
00638 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00639 << " Unable to find global CommissioningTask for FineDelay. Unable to fill histograms!";
00640 edm::LogWarning(mlDqmSource_) << ss.str();
00641 }
00642
00643 } else {
00644 if ( tasks_[iconn->fedId()][iconn->fedCh()] ) {
00645 tasks_[iconn->fedId()][iconn->fedCh()]->fillHistograms( *summary, *digis );
00646 } else {
00647 std::stringstream ss;
00648 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00649 << " Unable to find CommissioningTask object with FED key "
00650 << std::hex << std::setfill('0') << std::setw(8) << fed_key << std::dec
00651 << " and FED id/ch "
00652 << iconn->fedId() << "/"
00653 << iconn->fedCh()
00654 << " Unable to fill histograms!";
00655 edm::LogWarning(mlDqmSource_) << ss.str();
00656 }
00657 }
00658 } else {
00659
00660
00661 if ( task_ != sistrip::APV_LATENCY &&
00662 task_ != sistrip::FINE_DELAY ) {
00663 std::stringstream ss;
00664 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00665 << " Unable to find any DetSet containing digis for FED key "
00666 << std::hex << std::setfill('0') << std::setw(8) << fed_key << std::dec
00667 << " and FED id/ch "
00668 << iconn->fedId() << "/"
00669 << iconn->fedCh();
00670 edm::LogWarning(mlDqmSource_) << ss.str();
00671 }
00672 }
00673 }
00674 }
00675
00676 }
00677
00678
00679
00680 void SiStripCommissioningSource::createRunNumber() {
00681
00682
00683 if ( !run_ ) {
00684 edm::LogWarning(mlDqmSource_)
00685 << "[SiStripCommissioningSource::" << __func__ << "]"
00686 << " NULL run number!";
00687 return;
00688 }
00689
00690
00691 dqm()->setCurrentFolder( base_ + sistrip::root_ );
00692 std::stringstream run;
00693 run << run_;
00694 dqm()->bookString( std::string(sistrip::runNumber_) + sistrip::sep_ + run.str(), run.str() );
00695
00696 }
00697
00698
00699
00700 void SiStripCommissioningSource::createTask( const SiStripEventSummary* const summary, const edm::EventSetup& setup ) {
00701
00702
00703 task_ = sistrip::UNDEFINED_RUN_TYPE;
00704
00705
00706 if ( summary ) {
00707 task_ = summary->runType();
00708 std::stringstream ss;
00709 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00710 << " Identified CommissioningTask from EventSummary to be \""
00711 << SiStripEnumsAndStrings::runType( task_ )
00712 << "\"";
00713 LogTrace(mlDqmSource_) << ss.str();
00714 } else {
00715 task_ = sistrip::UNKNOWN_RUN_TYPE;
00716 std::stringstream ss;
00717 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00718 << " NULL pointer to SiStripEventSummary!"
00719 << " Check SiStripEventSummary is found/present in Event";
00720 edm::LogWarning(mlDqmSource_) << ss.str();
00721 }
00722
00723
00724 sistrip::RunType configurable = SiStripEnumsAndStrings::runType( taskConfigurable_ );
00725 if ( configurable != sistrip::UNDEFINED_RUN_TYPE &&
00726 configurable != sistrip::UNKNOWN_RUN_TYPE ) {
00727 std::stringstream ss;
00728 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00729 << " Overriding CommissioningTask from EventSummary (\""
00730 << SiStripEnumsAndStrings::runType( task_ )
00731 << "\") with value retrieved from .cfg file (\""
00732 << SiStripEnumsAndStrings::runType( configurable )
00733 << "\")!";
00734 LogTrace(mlDqmSource_) << ss.str();
00735 task_ = configurable;
00736 }
00737
00738
00739 dqm()->setCurrentFolder( base_ + sistrip::root_ );
00740 std::string task_str = SiStripEnumsAndStrings::runType( task_ );
00741 dqm()->bookString( std::string(sistrip::taskId_) + sistrip::sep_ + task_str, task_str );
00742
00743
00744 if ( task_ == sistrip::UNKNOWN_RUN_TYPE ||
00745 task_ == sistrip::UNDEFINED_RUN_TYPE ) {
00746 std::stringstream ss;
00747 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00748 << " Unexpected CommissioningTask found ("
00749 << static_cast<uint16_t>(task_) << ") \""
00750 << SiStripEnumsAndStrings::runType( task_ ) << "\""
00751 << " Unexpected value found in SiStripEventSummary and/or cfg file"
00752 << " If SiStripEventSummary is not present in Event,"
00753 << " check 'CommissioningTask' configurable in cfg file";
00754 edm::LogWarning(mlDqmSource_) << ss.str();
00755 return;
00756 } else {
00757 std::stringstream ss;
00758 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00759 << " Identified CommissioningTask to be \""
00760 << SiStripEnumsAndStrings::runType( task_ )
00761 << "\"";
00762 LogTrace(mlDqmSource_) << ss.str();
00763 }
00764
00765
00766 if ( task_ == sistrip::FED_CABLING ) { cablingTask_ = true; }
00767 else { cablingTask_ = false; }
00768
00769 std::stringstream ss;
00770 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00771 << " CommissioningTask: "
00772 << SiStripEnumsAndStrings::runType( summary->runType() );
00773 LogTrace(mlDqmSource_) << ss.str();
00774
00775 edm::LogVerbatim(mlDqmSource_)
00776 << "[SiStripCommissioningSource::" << __func__ << "]"
00777 << " Creating CommissioningTask objects and booking histograms...";
00778 if ( cablingTask_ ) { createCablingTasks(); }
00779 else { createTasks( task_ , setup ); }
00780 edm::LogVerbatim(mlDqmSource_)
00781 << "[SiStripCommissioningSource::" << __func__ << "]"
00782 << " Finished booking histograms!";
00783 tasksExist_ = true;
00784
00785 }
00786
00787
00788
00789 void SiStripCommissioningSource::createCablingTasks() {
00790
00791
00792 uint16_t booked = 0;
00793 for ( std::vector<SiStripFecCrate>::const_iterator icrate = fecCabling_->crates().begin(); icrate != fecCabling_->crates().end(); icrate++ ) {
00794 for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++ ) {
00795 for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); iring++ ) {
00796 for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); iccu++ ) {
00797 for ( std::vector<SiStripModule>::const_iterator imodule = iccu->modules().begin(); imodule != iccu->modules().end(); imodule++ ) {
00798
00799
00800 SiStripFecKey path( icrate->fecCrate(),
00801 ifec->fecSlot(),
00802 iring->fecRing(),
00803 iccu->ccuAddr(),
00804 imodule->ccuChan() );
00805
00806
00807 if ( !path.isValid() ) { continue; }
00808
00809
00810 std::string dir = base_ + path.path();
00811 dqm()->setCurrentFolder( dir );
00812
00813
00814 for ( uint16_t ipair = 0; ipair < imodule->nApvPairs(); ipair++ ) {
00815
00816
00817 SiStripModule::PairOfU16 apvs = imodule->activeApvPair( imodule->lldChannel(ipair) );
00818
00819
00820 FedChannelConnection conn( icrate->fecCrate(),
00821 ifec->fecSlot(),
00822 iring->fecRing(),
00823 iccu->ccuAddr(),
00824 imodule->ccuChan(),
00825 apvs.first,
00826 apvs.second,
00827 imodule->dcuId(),
00828 imodule->detId(),
00829 imodule->nApvPairs() );
00830
00831
00832 uint32_t key = SiStripFecKey( icrate->fecCrate(),
00833 ifec->fecSlot(),
00834 iring->fecRing(),
00835 iccu->ccuAddr(),
00836 imodule->ccuChan(),
00837 imodule->lldChannel(ipair) ).key();
00838
00839
00840 if ( !key ) {
00841 edm::LogWarning(mlDqmSource_)
00842 << "[SiStripCommissioningSource::" << __func__ << "]"
00843 << " Unexpected NULL value for FEC key!";
00844 continue;
00845 }
00846
00847
00848 if ( cablingTasks_.find( key ) == cablingTasks_.end() ) {
00849
00850 if ( task_ == sistrip::FED_CABLING ) {
00851 cablingTasks_[key] = new FedCablingTask( dqm(), conn );
00852 } else if ( task_ == sistrip::UNDEFINED_RUN_TYPE ) {
00853 edm::LogWarning(mlDqmSource_)
00854 << "[SiStripCommissioningSource::" << __func__ << "]"
00855 << " Undefined CommissioningTask"
00856 << " Unable to create FedCablingTask object!";
00857 } else if ( task_ == sistrip::UNKNOWN_RUN_TYPE ) {
00858 edm::LogWarning(mlDqmSource_)
00859 << "[SiStripCommissioningSource::" << __func__ << "]"
00860 << " Unknown CommissioningTask"
00861 << " Unable to create FedCablingTask object!";
00862 } else {
00863 edm::LogWarning(mlDqmSource_)
00864 << "[SiStripCommissioningSource::" << __func__ << "]"
00865 << " Unexpected CommissioningTask: "
00866 << SiStripEnumsAndStrings::runType( task_ )
00867 << " Unable to create FedCablingTask object!";
00868 }
00869
00870
00871 if ( cablingTasks_.find( key ) != cablingTasks_.end() ) {
00872 if ( cablingTasks_[key] ) {
00873 cablingTasks_[key]->bookHistograms();
00874 cablingTasks_[key]->updateFreq(1);
00875 booked++;
00876
00877
00878
00879
00880
00881
00882 } else {
00883 std::stringstream ss;
00884 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00885 << " NULL pointer to CommissioningTask for key 0x"
00886 << std::hex << std::setfill('0') << std::setw(8) << key << std::dec
00887 << " in directory " << dir
00888 << " Unable to book histograms!";
00889 edm::LogWarning(mlDqmSource_) << ss.str();
00890 }
00891 } else {
00892 std::stringstream ss;
00893 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00894 << " Unable to find CommissioningTask for key 0x"
00895 << std::hex << std::setfill('0') << std::setw(8) << key << std::dec
00896 << " in directory " << dir
00897 << " Unable to book histograms!";
00898 edm::LogWarning(mlDqmSource_) << ss.str();
00899 }
00900
00901 } else {
00902 std::stringstream ss;
00903 ss << "[SiStripCommissioningSource::" << __func__ << "]"
00904 << " CommissioningTask object already exists for key 0x"
00905 << std::hex << std::setfill('0') << std::setw(8) << key << std::dec
00906 << " in directory " << dir
00907 << " Unable to create FedCablingTask object!";
00908 edm::LogWarning(mlDqmSource_) << ss.str();
00909 }
00910
00911 }
00912 }
00913 }
00914 }
00915 }
00916 }
00917
00918 edm::LogVerbatim(mlDqmSource_)
00919 << "[SiStripCommissioningSource::" << __func__ << "]"
00920 << " Created " << booked
00921 << " CommissioningTask objects and booked histograms";
00922
00923 }
00924
00925
00926
00927 void SiStripCommissioningSource::createTasks( sistrip::RunType run_type, const edm::EventSetup& setup ) {
00928
00929 uint16_t booked = 0;
00930
00931
00932 if (task_ == sistrip::APV_LATENCY) {
00933
00934 for (uint16_t partition = 0; partition < 4; ++partition) {
00935
00936 tasks_[0][partition] = new LatencyTask( dqm(), FedChannelConnection(partition+1,sistrip::invalid_,sistrip::invalid_,sistrip::invalid_,sistrip::invalid_) );
00937 tasks_[0][partition]->eventSetup( &setup );
00938 tasks_[0][partition]->bookHistograms();
00939 tasks_[0][partition]->updateFreq( updateFreq_ );
00940 booked++;
00941 }
00942
00943
00944 } else if (task_ == sistrip::FINE_DELAY) {
00945
00946 tasks_[0][0] = new FineDelayTask( dqm(), FedChannelConnection() );
00947 tasks_[0][0]->eventSetup( &setup );
00948 tasks_[0][0]->bookHistograms();
00949 tasks_[0][0]->updateFreq( updateFreq_ );
00950 booked++;
00951
00952 } else {
00953
00954
00955 std::vector<uint16_t>::const_iterator ifed = fedCabling_->feds().begin();
00956 for ( ; ifed != fedCabling_->feds().end(); ifed++ ) {
00957
00958
00959
00960
00961 std::vector<FedChannelConnection> conns = fedCabling_->connections(*ifed);
00962 std::vector<FedChannelConnection>::const_iterator iconn = conns.begin();
00963 for ( ; iconn != conns.end(); iconn++ ) {
00964
00965
00966 SiStripFecKey fec_key( iconn->fecCrate(),
00967 iconn->fecSlot(),
00968 iconn->fecRing(),
00969 iconn->ccuAddr(),
00970 iconn->ccuChan() );
00971
00972 SiStripFedKey fed_key( iconn->fedId(),
00973 SiStripFedKey::feUnit(iconn->fedCh()),
00974 SiStripFedKey::feChan(iconn->fedCh()) );
00975 if ( !iconn->isConnected() ) { continue; }
00976
00977
00978
00979
00980
00981 std::stringstream dir;
00982 dir << base_;
00983 if (view_ == "Default") {
00984 if ( run_type == sistrip::FAST_CABLING ) {
00985 dir << fed_key.path();
00986 } else {
00987 dir << fec_key.path();
00988 }
00989 } else if (view_ == "FecView") {
00990 dir << fec_key.path();
00991 } else if (view_ == "FedView") {
00992 dir << fed_key.path();
00993 } else if (view_ == "DetView") {
00994
00995 dir << sistrip::root_ << sistrip::dir_
00996 << sistrip::detectorView_ << sistrip::dir_
00997 << iconn->detId();
00998 } else {
00999 edm::LogWarning(mlDqmSource_)
01000 << "[SiStripCommissioningSource::" << __func__ << "]"
01001 << " Invalid view " << view_ << std::endl
01002 << " Histograms will end up all in the top directory.";
01003 }
01004 dqm()->setCurrentFolder( dir.str() );
01005
01006
01007 if ( !tasks_[iconn->fedId()][iconn->fedCh()] ) {
01008 if ( task_ == sistrip::FAST_CABLING ) {
01009 tasks_[iconn->fedId()][iconn->fedCh()] = new FastFedCablingTask( dqm(), *iconn );
01010 } else if ( task_ == sistrip::APV_TIMING ) {
01011 tasks_[iconn->fedId()][iconn->fedCh()] = new ApvTimingTask( dqm(), *iconn );
01012 } else if ( task_ == sistrip::FED_TIMING ) {
01013 tasks_[iconn->fedId()][iconn->fedCh()] = new FedTimingTask( dqm(), *iconn );
01014 } else if ( task_ == sistrip::OPTO_SCAN ) {
01015 tasks_[iconn->fedId()][iconn->fedCh()] = new OptoScanTask( dqm(), *iconn );
01016 } else if ( task_ == sistrip::VPSP_SCAN ) {
01017 tasks_[iconn->fedId()][iconn->fedCh()] = new VpspScanTask( dqm(), *iconn );
01018 } else if ( task_ == sistrip::PEDESTALS ) {
01019 tasks_[iconn->fedId()][iconn->fedCh()] = new PedestalsTask( dqm(), *iconn );
01020 } else if ( task_ == sistrip::PEDS_ONLY ) {
01021 tasks_[iconn->fedId()][iconn->fedCh()] = new PedsOnlyTask( dqm(), *iconn );
01022 } else if ( task_ == sistrip::NOISE ) {
01023 tasks_[iconn->fedId()][iconn->fedCh()] = new NoiseTask( dqm(), *iconn );
01024 } else if ( task_ == sistrip::PEDS_FULL_NOISE ) {
01025 tasks_[iconn->fedId()][iconn->fedCh()] = new PedsFullNoiseTask( dqm(), *iconn, parameters_ );
01026 } else if ( task_ == sistrip::DAQ_SCOPE_MODE ) {
01027 tasks_[iconn->fedId()][iconn->fedCh()] = new DaqScopeModeTask( dqm(), *iconn );
01028 } else if ( task_ == sistrip::CALIBRATION_SCAN ||
01029 task_ == sistrip::CALIBRATION_SCAN_DECO ) {
01030 tasks_[iconn->fedId()][iconn->fedCh()] = new CalibrationScanTask( dqm(),
01031 *iconn,
01032 task_,
01033 filename_.c_str(),
01034 run_,
01035 setup );
01036 } else if ( task_ == sistrip::CALIBRATION ||
01037 task_ == sistrip::CALIBRATION_DECO ) {
01038 tasks_[iconn->fedId()][iconn->fedCh()] = new CalibrationTask( dqm(),
01039 *iconn,
01040 task_,
01041 filename_.c_str(),
01042 run_,
01043 setup );
01044 } else if ( task_ == sistrip::UNDEFINED_RUN_TYPE ) {
01045 edm::LogWarning(mlDqmSource_)
01046 << "[SiStripCommissioningSource::" << __func__ << "]"
01047 << " Undefined CommissioningTask"
01048 << " Unable to create CommissioningTask object!";
01049 } else {
01050 edm::LogWarning(mlDqmSource_)
01051 << "[SiStripCommissioningSource::" << __func__ << "]"
01052 << " Unknown CommissioningTask"
01053 << " Unable to create CommissioningTask object!";
01054 }
01055
01056
01057 if ( tasks_[iconn->fedId()][iconn->fedCh()] ) {
01058 tasks_[iconn->fedId()][iconn->fedCh()]->eventSetup( &setup );
01059 tasks_[iconn->fedId()][iconn->fedCh()]->bookHistograms();
01060 tasks_[iconn->fedId()][iconn->fedCh()]->updateFreq( updateFreq_ );
01061 booked++;
01062
01063
01064
01065
01066
01067
01068 } else {
01069 std::stringstream ss;
01070 ss << "[SiStripCommissioningSource::" << __func__ << "]"
01071 << " NULL pointer to CommissioningTask for key 0x"
01072 << std::hex << std::setfill('0') << std::setw(8) << fed_key.key() << std::dec
01073 << " in directory " << dir.str()
01074 << " Unable to book histograms!";
01075 edm::LogWarning(mlDqmSource_) << ss.str();
01076 }
01077
01078 } else {
01079 std::stringstream ss;
01080 ss << "[SiStripCommissioningSource::" << __func__ << "]"
01081 << " CommissioningTask object already exists for key 0x"
01082 << std::hex << std::setfill('0') << std::setw(8) << fed_key.key() << std::dec
01083 << " in directory " << dir.str()
01084 << " Unable to create CommissioningTask object!";
01085 edm::LogWarning(mlDqmSource_) << ss.str();
01086 }
01087
01088 }
01089 }
01090 }
01091
01092 edm::LogVerbatim(mlDqmSource_)
01093 << "[SiStripCommissioningSource::" << __func__ << "]"
01094 << " Created " << booked
01095 << " CommissioningTask objects and booked histograms";
01096 }
01097
01098
01099
01100 void SiStripCommissioningSource::clearCablingTasks() {
01101 if ( cablingTasks_.empty() ) { return; }
01102 for ( TaskMap::iterator itask = cablingTasks_.begin(); itask != cablingTasks_.end(); itask++ ) {
01103 if ( itask->second ) { delete itask->second; }
01104 }
01105 cablingTasks_.clear();
01106 }
01107
01108
01109
01110 void SiStripCommissioningSource::clearTasks() {
01111 if ( tasks_.empty() ) { return; }
01112 VecOfVecOfTasks::iterator ifed = tasks_.begin();
01113 for ( ; ifed != tasks_.end(); ifed++ ) {
01114 VecOfTasks::iterator ichan = ifed->begin();
01115 for ( ; ichan != ifed->end(); ichan++ ) {
01116 if ( *ichan ) { delete *ichan; *ichan = 0; }
01117 }
01118 ifed->resize(96,0);
01119 }
01120 tasks_.resize(1024);
01121 }
01122
01123
01124
01125 void SiStripCommissioningSource::remove() {
01126 dqm()->cd();
01127 dqm()->removeContents();
01128
01129 if( dqm()->dirExists(sistrip::root_) ) {
01130 dqm()->rmdir(sistrip::root_);
01131 }
01132 }
01133
01134
01135
01136 void SiStripCommissioningSource::directory( std::stringstream& dir,
01137 uint32_t run_number ) {
01138
01139
01140 char hn[256];
01141 gethostname( hn, sizeof(hn) );
01142 struct hostent* he;
01143 he = gethostbyname(hn);
01144
01145
01146 std::string host_name;
01147 std::string host_ip;
01148 if ( he ) {
01149 host_name = std::string(he->h_name);
01150 host_ip = std::string( inet_ntoa( *(struct in_addr*)(he->h_addr) ) );
01151 } else {
01152 host_name = "unknown.cern.ch";
01153 host_ip = "255.255.255.255";
01154 }
01155
01156
01157 std::string::size_type pos = 0;
01158 std::stringstream ip;
01159
01160 while ( pos != std::string::npos ) {
01161 std::string::size_type tmp = host_ip.find(".",pos);
01162 if ( tmp != std::string::npos ) {
01163 ip << std::setw(3)
01164 << std::setfill('0')
01165 << host_ip.substr( pos, tmp-pos )
01166 << ".";
01167 pos = tmp+1;
01168 } else {
01169 ip << std::setw(3)
01170 << std::setfill('0')
01171 << host_ip.substr( pos );
01172 pos = std::string::npos;
01173 }
01174 }
01175
01176
01177 pid_t pid = getpid();
01178
01179
01180 if ( run_number ) {
01181 dir << std::setw(8)
01182 << std::setfill('0')
01183 << run_number
01184 << "_";
01185 }
01186 dir << ip.str()
01187 << "_"
01188 << std::setw(5)
01189 << std::setfill('0')
01190 << pid;
01191
01192 }
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250