CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/DQM/SiStripCommissioningSources/src/CommissioningTask.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommissioningSources/interface/CommissioningTask.h"
00002 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00003 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
00004 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
00005 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
00006 #include "DQM/SiStripCommon/interface/UpdateTProfile.h"
00007 #include "DQMServices/Core/interface/MonitorElement.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "TAxis.h"
00010 #include <iostream>
00011 #include <iostream>
00012 
00013 using namespace sistrip;
00014 
00015 // -----------------------------------------------------------------------------
00016 //
00017 CommissioningTask::CommissioningTask( DQMStore* dqm,
00018                                       const FedChannelConnection& conn,
00019                                       const std::string& my_name ) :
00020   dqm_(dqm),
00021   updateFreq_(0),
00022   fillCntr_(0),
00023   connection_(conn),
00024   fedKey_(0),
00025   fecKey_(0),
00026   booked_(false),
00027   myName_(my_name),
00028   eventSetup_(0)
00029 {
00030   uint16_t fed_ch = connection_.fedCh();
00031   fedKey_ = SiStripFedKey( connection_.fedId(), 
00032                            SiStripFedKey::feUnit(fed_ch),
00033                            SiStripFedKey::feChan(fed_ch) ).key();
00034   fecKey_ = SiStripFecKey( connection_.fecCrate(),
00035                            connection_.fecSlot(),
00036                            connection_.fecRing(),
00037                            connection_.ccuAddr(),
00038                            connection_.ccuChan(),
00039                            connection_.lldChannel() ).key();
00040   
00041   LogTrace(mlDqmSource_)
00042     << "[CommissioningTask::" << __func__ << "]" 
00043     << " Constructing '" << myName_
00044     << "' object for FecKey/FedKey: "
00045     << "0x" << std::hex << std::setw(8) << std::setfill('0') << fecKey_ << std::dec
00046     << "/"
00047     << "0x" << std::hex << std::setw(8) << std::setfill('0') << fedKey_ << std::dec
00048     << " and Crate/FEC/ring/CCU/module/LLDchan: " 
00049     << connection_.fecCrate() << "/"
00050     << connection_.fecSlot() << "/" 
00051     << connection_.fecRing() << "/" 
00052     << connection_.ccuAddr() << "/" 
00053     << connection_.ccuChan() << "/" 
00054     << connection_.lldChannel() 
00055     << " and FedId/Ch: " 
00056     << connection_.fedId() << "/" 
00057     << connection_.fedCh();
00058 }
00059 
00060 // -----------------------------------------------------------------------------
00061 //
00062 CommissioningTask::~CommissioningTask() {
00063   LogTrace(mlDqmSource_)
00064     << "[CommissioningTask::" << __func__ << "]" 
00065     << " Destructing object for FED id/ch " 
00066     << " Constructing '" << myName_
00067     << "' object for FecKey/FedKey: "
00068     << "0x" << std::hex << std::setw(8) << std::setfill('0') << fecKey_ << std::dec
00069     << "/"
00070     << "0x" << std::hex << std::setw(8) << std::setfill('0') << fedKey_ << std::dec
00071     << " and Crate/FEC/ring/CCU/module/LLDchan: " 
00072     << connection_.fecCrate() << "/"
00073     << connection_.fecSlot() << "/" 
00074     << connection_.fecRing() << "/" 
00075     << connection_.ccuAddr() << "/" 
00076     << connection_.ccuChan() << "/" 
00077     << connection_.lldChannel() 
00078     << " and FedId/Ch: " 
00079     << connection_.fedId() << "/" 
00080     << connection_.fedCh();
00081   //@@ do not delete EventSetup pointer!
00082 }
00083 
00084 // -----------------------------------------------------------------------------
00085 //
00086 CommissioningTask::HistoSet::HistoSet() : 
00087   vNumOfEntries_(), 
00088   vSumOfContents_(), 
00089   vSumOfSquares_(), 
00090   isProfile_(true),
00091   explicitFill_(false),
00092   histo_(0),
00093   axis_(0)
00094 {;}
00095 
00096 // -----------------------------------------------------------------------------
00097 //
00098 CommissioningTask::CompactHistoSet::CompactHistoSet() :
00099   vNumOfEntries_(), 
00100   explicitFill_(false),
00101   histo_(0)
00102 {;}
00103 
00104 // -----------------------------------------------------------------------------
00105 //
00106 MonitorElement* CommissioningTask::HistoSet::histo() { return histo_; }
00107 
00108 // -----------------------------------------------------------------------------
00109 //
00110 MonitorElement* CommissioningTask::CompactHistoSet::histo() { return histo_; }
00111 
00112 // -----------------------------------------------------------------------------
00113 //
00114 void CommissioningTask::HistoSet::histo( MonitorElement* me ) {
00115   histo_   = me;
00116   TH1* histo = ExtractTObject<TH1>().extract( histo_ );
00117   if ( histo_ ) { axis_ = histo->GetXaxis(); }
00118   //TProfile* prof = ExtractTObject<TProfile>().extract( histo_ );
00119   //if ( prof ) { prof->SetErrorOption("s"); }
00120 }
00121 
00122 // -----------------------------------------------------------------------------
00123 //
00124 void CommissioningTask::CompactHistoSet::histo( MonitorElement* me ) {
00125   histo_ = me;
00126 }
00127 
00128 // -----------------------------------------------------------------------------
00129 //
00130 uint32_t CommissioningTask::HistoSet::bin( float value ) {
00131   if ( !axis_ ) { return 0; }
00132   float range = axis_->GetXmax() - axis_->GetXmin();
00133   if ( range > 0. ) {
00134     int32_t bin = static_cast<int32_t>( ( value - axis_->GetXmin() ) * 
00135                                         ( axis_->GetNbins() / range ) ) + 1;
00136     if ( bin < 0 ) { return 0; }
00137     else if ( bin > axis_->GetNbins() ) { return static_cast<uint32_t>( axis_->GetNbins() + 1 ); }
00138     else { return bin; }
00139   } else { return 0; }      
00140 }
00141 
00142 // -----------------------------------------------------------------------------
00143 //
00144 void CommissioningTask::book() {
00145   edm::LogWarning(mlDqmSource_)
00146     << "[CommissioningTask::" << __func__ << "]"
00147     << " No derived implementation exists!";
00148 }
00149 
00150 // -----------------------------------------------------------------------------
00151 //
00152 void CommissioningTask::fill( const SiStripEventSummary& summary,
00153                               const edm::DetSet<SiStripRawDigi>& digis ) {
00154   edm::LogWarning(mlDqmSource_)
00155     << "[CommissioningTask::" << __func__ << "]"
00156     << " No derived implementation exists!";
00157 }
00158 
00159 // -----------------------------------------------------------------------------
00160 //
00161 void CommissioningTask::fill( const SiStripEventSummary& summary,
00162                               const uint16_t& fed_id,
00163                               const std::map<uint16_t,float>& fed_ch ) {
00164   edm::LogWarning(mlDqmSource_)
00165     << "[CommissioningTask::" << __func__ << "]"
00166     << " No derived implementation exists!";
00167 }
00168 
00169 // -----------------------------------------------------------------------------
00170 //
00171 void CommissioningTask::update() {
00172   edm::LogWarning(mlDqmSource_)
00173     << "[CommissioningTask::" << __func__ << "]"
00174     << " No derived implementation exists!";
00175 }
00176 
00177 // -----------------------------------------------------------------------------
00178 //
00179 void CommissioningTask::bookHistograms() {
00180   book();
00181   booked_ = true;
00182 }
00183 
00184 // -----------------------------------------------------------------------------
00185 //
00186 void CommissioningTask::fillHistograms( const SiStripEventSummary& summary,
00187                                         const edm::DetSet<SiStripRawDigi>& digis ) {
00188   if ( !booked_ ) {
00189     edm::LogWarning(mlDqmSource_)
00190       << "[CommissioningTask::" << __func__ << "]"
00191       << " Attempting to fill histos that haven't been booked yet!";
00192     return;
00193   }
00194   fillCntr_++;
00195   fill( summary, digis ); 
00196   if ( updateFreq_ && !(fillCntr_%updateFreq_) ) { 
00197     update(); 
00198   }
00199   
00200 }
00201 
00202 // -----------------------------------------------------------------------------
00203 //
00204 void CommissioningTask::fillHistograms( const SiStripEventSummary& summary,
00205                                         const uint16_t& fed_id,
00206                                         const std::map<uint16_t,float>& fed_ch ) {
00207   if ( !booked_ ) {
00208     edm::LogWarning(mlDqmSource_)
00209       << "[CommissioningTask::" << __func__ << "]"
00210       << " Attempting to fill histos that haven't been booked yet!";
00211     return;
00212   }
00213   fillCntr_++;
00214   fill( summary, fed_id, fed_ch ); 
00215   if ( updateFreq_ && !(fillCntr_%updateFreq_) ) { 
00216     update(); 
00217   }
00218   
00219 }
00220 
00221 // -----------------------------------------------------------------------------
00222 //
00223 void CommissioningTask::updateHistograms() {
00224   update();
00225 }
00226 
00227 // -----------------------------------------------------------------------------
00228 //
00229 void CommissioningTask::updateHistoSet( HistoSet& histo_set, 
00230                                         const uint32_t& bin ) {
00231   float value = 1.;
00232   updateHistoSet( histo_set, bin, value );
00233 }
00234 
00235 // -----------------------------------------------------------------------------
00236 //
00237 void CommissioningTask::updateHistoSet( CompactHistoSet& histo_set, 
00238                                         const uint32_t& bin ) {
00239   short value = 1;
00240   updateHistoSet( histo_set, bin, value );
00241 }
00242 
00243 // -----------------------------------------------------------------------------
00244 //
00245 void CommissioningTask::updateHistoSet( HistoSet& histo_set, 
00246                                         const float& value ) {
00247   float weight = 1.;
00248   updateHistoSet( histo_set, histo_set.bin(value), weight );
00249 }
00250 
00251 // -----------------------------------------------------------------------------
00252 //
00253 void CommissioningTask::updateHistoSet( HistoSet& histo_set, 
00254                                         const uint32_t& bin,
00255                                         const float& value ) {
00256   
00257   // Check bin number
00258   if ( bin >= histo_set.vNumOfEntries_.size() && !histo_set.explicitFill_ ) { 
00259     edm::LogWarning(mlDqmSource_)
00260       << "[CommissioningTask::" << __func__ << "]"
00261       << " Unexpected bin number " << bin 
00262       << " when filling histogram of size " << histo_set.vNumOfEntries_.size();
00263     return;
00264   }
00265   
00266   // Check if histo is TProfile or not
00267   if ( !histo_set.isProfile_ ) {
00268     // Set entries
00269     if (histo_set.explicitFill_) {
00270       float origVal = histo_set.histo()->getBinContent( bin+1 );
00271       histo_set.histo()->setBinContent( bin+1, origVal + value );
00272     } else {
00273       histo_set.vNumOfEntries_[bin]+=value;
00274     }
00275   } else {
00276     // Set entries
00277     histo_set.vNumOfEntries_[bin]++;
00278     
00279     // Check bin number
00280     if ( bin >= histo_set.vSumOfContents_.size() || 
00281          bin >= histo_set.vSumOfSquares_.size() ) { 
00282       edm::LogWarning(mlDqmSource_)
00283         << "[CommissioningTask::" << __func__ << "]"
00284         << " Unexpected bin when filling histogram: " << bin;
00285       return;
00286     }
00287     
00288     // Set sum of contents and squares
00289     histo_set.vSumOfContents_[bin] += value;
00290     histo_set.vSumOfSquares_[bin] += value*value;
00291   }
00292 
00293 }
00294 
00295 // -----------------------------------------------------------------------------
00296 //
00297 void CommissioningTask::updateHistoSet( CompactHistoSet& histo_set, 
00298                                         const uint32_t& bin,
00299                                         const short& value ) {
00300   
00301   // Check bin number
00302   if ( bin >= histo_set.vNumOfEntries_.size() && !histo_set.explicitFill_ ) { 
00303     edm::LogWarning(mlDqmSource_)
00304       << "[CommissioningTask::" << __func__ << "]"
00305       << " Unexpected bin number " << bin 
00306       << " when filling histogram of size " << histo_set.vNumOfEntries_.size();
00307     return;
00308   }
00309 
00310   if (histo_set.explicitFill_) {
00311     float origVal = histo_set.histo()->getBinContent( bin+1 );
00312     histo_set.histo()->setBinContent( bin+1, origVal + value );
00313   } else {
00314     // Set entries
00315     histo_set.vNumOfEntries_[bin] += value;
00316   }
00317 
00318 }
00319 
00320 // -----------------------------------------------------------------------------
00321 //
00322 void CommissioningTask::updateHistoSet( HistoSet& histo_set ) {
00323   
00324   // Check if histo exists
00325   if ( !histo_set.histo() ) {
00326     edm::LogWarning(mlDqmSource_)
00327       << "[CommissioningTask::" << __func__ << "]"
00328       << " NULL pointer to MonitorElement!";
00329     return;
00330   }
00331 
00332   if (!histo_set.explicitFill_) {
00333 
00334    if ( histo_set.isProfile_ ) {
00335 
00336     TProfile* prof = ExtractTObject<TProfile>().extract( histo_set.histo() );
00337     // if ( prof ) { prof->SetErrorOption("s"); } //@@ necessary?
00338     static UpdateTProfile profile;
00339     for ( uint32_t ibin = 0; ibin < histo_set.vNumOfEntries_.size(); ibin++ ) {
00340       profile.setBinContents( prof,
00341                               ibin+1, 
00342                               histo_set.vNumOfEntries_[ibin],
00343                               histo_set.vSumOfContents_[ibin],
00344                               histo_set.vSumOfSquares_[ibin] );
00345     }
00346 
00347    } else {
00348 
00349     for ( uint32_t ibin = 0; ibin < histo_set.vNumOfEntries_.size(); ibin++ ) {
00350       histo_set.histo()->setBinContent( ibin+1, histo_set.vNumOfEntries_[ibin] );
00351     }
00352     
00353    }
00354 
00355   }
00356   
00357 }
00358 
00359 // -----------------------------------------------------------------------------
00360 //
00361 void CommissioningTask::updateHistoSet( CompactHistoSet& histo_set ) {
00362   
00363   // Check if histo exists
00364   if ( !histo_set.histo() ) {
00365     edm::LogWarning(mlDqmSource_)
00366       << "[CommissioningTask::" << __func__ << "]"
00367       << " NULL pointer to MonitorElement!";
00368     return;
00369   }
00370 
00371   if (!histo_set.explicitFill_) {
00372     for ( uint32_t ibin = 0; ibin < histo_set.vNumOfEntries_.size(); ibin++ ) {
00373       histo_set.histo()->setBinContent( ibin+1, histo_set.vNumOfEntries_[ibin] );
00374     }
00375   }
00376   
00377 }