CMS 3D CMS Logo

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   histo_(0),
00092   axis_(0)
00093 {;}
00094 
00095 // -----------------------------------------------------------------------------
00096 //
00097 MonitorElement* CommissioningTask::HistoSet::histo() { return histo_; }
00098 
00099 // -----------------------------------------------------------------------------
00100 //
00101 void CommissioningTask::HistoSet::histo( MonitorElement* me ) {
00102   histo_   = me;
00103   TH1* histo = ExtractTObject<TH1>().extract( histo_ );
00104   if ( histo_ ) { axis_ = histo->GetXaxis(); }
00105   //TProfile* prof = ExtractTObject<TProfile>().extract( histo_ );
00106   //if ( prof ) { prof->SetErrorOption("s"); }
00107 }
00108 
00109 // -----------------------------------------------------------------------------
00110 //
00111 uint32_t CommissioningTask::HistoSet::bin( float value ) {
00112   if ( !axis_ ) { return 0; }
00113   float range = axis_->GetXmax() - axis_->GetXmin();
00114   if ( range > 0. ) {
00115     int32_t bin = static_cast<int32_t>( ( value - axis_->GetXmin() ) * 
00116                                         ( axis_->GetNbins() / range ) ) + 1;
00117     if ( bin < 0 ) { return 0; }
00118     else if ( bin > axis_->GetNbins() ) { return static_cast<uint32_t>( axis_->GetNbins() + 1 ); }
00119     else { return bin; }
00120   } else { return 0; }      
00121 }
00122 
00123 // -----------------------------------------------------------------------------
00124 //
00125 void CommissioningTask::book() {
00126   edm::LogWarning(mlDqmSource_)
00127     << "[CommissioningTask::" << __func__ << "]"
00128     << " No derived implementation exists!";
00129 }
00130 
00131 // -----------------------------------------------------------------------------
00132 //
00133 void CommissioningTask::fill( const SiStripEventSummary& summary,
00134                               const edm::DetSet<SiStripRawDigi>& digis ) {
00135   edm::LogWarning(mlDqmSource_)
00136     << "[CommissioningTask::" << __func__ << "]"
00137     << " No derived implementation exists!";
00138 }
00139 
00140 // -----------------------------------------------------------------------------
00141 //
00142 void CommissioningTask::fill( const SiStripEventSummary& summary,
00143                               const uint16_t& fed_id,
00144                               const std::map<uint16_t,float>& fed_ch ) {
00145   edm::LogWarning(mlDqmSource_)
00146     << "[CommissioningTask::" << __func__ << "]"
00147     << " No derived implementation exists!";
00148 }
00149 
00150 // -----------------------------------------------------------------------------
00151 //
00152 void CommissioningTask::update() {
00153   edm::LogWarning(mlDqmSource_)
00154     << "[CommissioningTask::" << __func__ << "]"
00155     << " No derived implementation exists!";
00156 }
00157 
00158 // -----------------------------------------------------------------------------
00159 //
00160 void CommissioningTask::bookHistograms() {
00161   book();
00162   booked_ = true;
00163 }
00164 
00165 // -----------------------------------------------------------------------------
00166 //
00167 void CommissioningTask::fillHistograms( const SiStripEventSummary& summary,
00168                                         const edm::DetSet<SiStripRawDigi>& digis ) {
00169   if ( !booked_ ) {
00170     edm::LogWarning(mlDqmSource_)
00171       << "[CommissioningTask::" << __func__ << "]"
00172       << " Attempting to fill histos that haven't been booked yet!";
00173     return;
00174   }
00175   fillCntr_++;
00176   fill( summary, digis ); 
00177   if ( updateFreq_ && !(fillCntr_%updateFreq_) ) { 
00178     update(); 
00179   }
00180   
00181 }
00182 
00183 // -----------------------------------------------------------------------------
00184 //
00185 void CommissioningTask::fillHistograms( const SiStripEventSummary& summary,
00186                                         const uint16_t& fed_id,
00187                                         const std::map<uint16_t,float>& fed_ch ) {
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, fed_id, fed_ch ); 
00196   if ( updateFreq_ && !(fillCntr_%updateFreq_) ) { 
00197     update(); 
00198   }
00199   
00200 }
00201 
00202 // -----------------------------------------------------------------------------
00203 //
00204 void CommissioningTask::updateHistograms() {
00205   update();
00206 }
00207 
00208 // -----------------------------------------------------------------------------
00209 //
00210 void CommissioningTask::updateHistoSet( HistoSet& histo_set, 
00211                                         const uint32_t& bin ) {
00212   float value = 1.;
00213   updateHistoSet( histo_set, bin, value );
00214 }
00215 
00216 // -----------------------------------------------------------------------------
00217 //
00218 void CommissioningTask::updateHistoSet( HistoSet& histo_set, 
00219                                         const float& value ) {
00220   float weight = 1.;
00221   updateHistoSet( histo_set, histo_set.bin(value), weight );
00222 }
00223 
00224 // -----------------------------------------------------------------------------
00225 //
00226 void CommissioningTask::updateHistoSet( HistoSet& histo_set, 
00227                                         const uint32_t& bin,
00228                                         const float& value ) {
00229   
00230   // Check bin number
00231   if ( bin >= histo_set.vNumOfEntries_.size() ) { 
00232     edm::LogWarning(mlDqmSource_)
00233       << "[CommissioningTask::" << __func__ << "]"
00234       << " Unexpected bin number " << bin 
00235       << " when filling histogram of size " << histo_set.vNumOfEntries_.size();
00236     return;
00237   }
00238   
00239   // Check if histo is TProfile or not
00240   if ( !histo_set.isProfile_ ) {
00241     // Set entries
00242     histo_set.vNumOfEntries_[bin]+=value;
00243   } else {
00244     // Set entries
00245     histo_set.vNumOfEntries_[bin]++;
00246     
00247     // Check bin number
00248     if ( bin >= histo_set.vSumOfContents_.size() || 
00249          bin >= histo_set.vSumOfSquares_.size() ) { 
00250       edm::LogWarning(mlDqmSource_)
00251         << "[CommissioningTask::" << __func__ << "]"
00252         << " Unexpected bin when filling histogram: " << bin;
00253       return;
00254     }
00255     
00256     // Set sum of contents and squares
00257     histo_set.vSumOfContents_[bin] += value;
00258     histo_set.vSumOfSquares_[bin] += value*value;
00259   }
00260 
00261 }
00262 
00263 // -----------------------------------------------------------------------------
00264 //
00265 void CommissioningTask::updateHistoSet( HistoSet& histo_set ) {
00266   
00267   // Check if histo exists
00268   if ( !histo_set.histo() ) {
00269     edm::LogWarning(mlDqmSource_)
00270       << "[CommissioningTask::" << __func__ << "]"
00271       << " NULL pointer to MonitorElement!";
00272     return;
00273   }
00274 
00275   if ( histo_set.isProfile_ ) {
00276 
00277     TProfile* prof = ExtractTObject<TProfile>().extract( histo_set.histo() );
00278     // if ( prof ) { prof->SetErrorOption("s"); } //@@ necessary?
00279     static UpdateTProfile profile;
00280     for ( uint32_t ibin = 0; ibin < histo_set.vNumOfEntries_.size(); ibin++ ) {
00281       profile.setBinContents( prof,
00282                               ibin+1, 
00283                               histo_set.vNumOfEntries_[ibin],
00284                               histo_set.vSumOfContents_[ibin],
00285                               histo_set.vSumOfSquares_[ibin] );
00286     }
00287 
00288   } else {
00289 
00290     for ( uint32_t ibin = 0; ibin < histo_set.vNumOfEntries_.size(); ibin++ ) {
00291       histo_set.histo()->setBinContent( ibin+1, histo_set.vNumOfEntries_[ibin] );
00292     }
00293     
00294   }
00295   
00296 }

Generated on Tue Jun 9 17:33:33 2009 for CMSSW by  doxygen 1.5.4