CMS 3D CMS Logo

CalibrationHistosUsingDb.cc

Go to the documentation of this file.
00001 // Last commit: $Id: CalibrationHistosUsingDb.cc,v 1.8 2008/10/22 10:40:09 delaer Exp $
00002 
00003 #include "DQM/SiStripCommissioningDbClients/interface/CalibrationHistosUsingDb.h"
00004 #include "CondFormats/SiStripObjects/interface/CalibrationAnalysis.h"
00005 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00006 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
00007 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include <iostream>
00010 
00011 using namespace sistrip;
00012 
00013 // -----------------------------------------------------------------------------
00015 CalibrationHistosUsingDb::CalibrationHistosUsingDb( DQMOldReceiver* mui,
00016                                                     SiStripConfigDb* const db,
00017                                                     const sistrip::RunType& task )
00018   : CommissioningHistograms( mui, task ),
00019     CommissioningHistosUsingDb( db, mui, task),
00020     CalibrationHistograms( mui, task )
00021 {
00022   LogTrace(mlDqmClient_) 
00023     << "[CalibrationHistosUsingDb::" << __func__ << "]"
00024     << " Constructing object...";
00025   // Load and dump the current ISHA/VFS values. This is used by the standalone analysis script
00026   const SiStripConfigDb::DeviceDescriptionsRange & apvDescriptions = db->getDeviceDescriptions(APV25);
00027   for(SiStripConfigDb::DeviceDescriptionsV::const_iterator apv = apvDescriptions.begin();apv!=apvDescriptions.end();++apv) {
00028     apvDescription* desc = dynamic_cast<apvDescription*>( *apv );
00029     if ( !desc ) { continue; }
00030     // Retrieve device addresses from device description
00031     const SiStripConfigDb::DeviceAddress& addr = db->deviceAddress(*desc);
00032     std::stringstream bin;
00033     bin        << std::setw(1) << std::setfill('0') << addr.fecCrate_;
00034     bin << "." << std::setw(2) << std::setfill('0') << addr.fecSlot_;
00035     bin << "." << std::setw(1) << std::setfill('0') << addr.fecRing_;
00036     bin << "." << std::setw(3) << std::setfill('0') << addr.ccuAddr_;
00037     bin << "." << std::setw(2) << std::setfill('0') << addr.ccuChan_;
00038     bin << "." << desc->getAddress();
00039     LogTrace(mlDqmClient_) << "Present values for ISHA/VFS of APV " 
00040                            << bin.str() << " : " 
00041                            << static_cast<uint16_t>(desc->getIsha()) << " " << static_cast<uint16_t>(desc->getVfs());
00042   }
00043   // Load the histograms with the results
00044   std::string pwd = bei()->pwd();
00045   std::string ishaPath = pwd.substr(0,pwd.find(sistrip::root_ + "/")+sistrip::root_.size()+1);
00046   ishaPath += "/ControlView/isha";
00047   LogTrace(mlDqmClient_) << "Looking for " << ishaPath;
00048   ishaHistogram_ = ExtractTObject<TH1F>().extract( bei()->get(ishaPath) );
00049   std::string vfsPath = pwd.substr(0,pwd.find(sistrip::root_ + "/")+sistrip::root_.size()+1);
00050   vfsPath += "/ControlView/vfs";
00051   LogTrace(mlDqmClient_) << "Looking for " << vfsPath;
00052   vfsHistogram_ = ExtractTObject<TH1F>().extract( bei()->get(vfsPath) );
00053 
00054 }
00055 
00056 // -----------------------------------------------------------------------------
00058 CalibrationHistosUsingDb::CalibrationHistosUsingDb( DQMStore* bei,
00059                                                     SiStripConfigDb* const db,
00060                                                     const sistrip::RunType& task ) 
00061   : CommissioningHistosUsingDb( db, task ),
00062     CalibrationHistograms( bei, task )
00063 {
00064   LogTrace(mlDqmClient_) 
00065     << "[CalibrationHistosUsingDb::" << __func__ << "]"
00066     << " Constructing object...";
00067   // Load and dump the current ISHA/VFS values. This is used by the standalone analysis script
00068   const SiStripConfigDb::DeviceDescriptionsRange & apvDescriptions = db->getDeviceDescriptions(APV25);
00069   for(SiStripConfigDb::DeviceDescriptionsV::const_iterator apv = apvDescriptions.begin();apv!=apvDescriptions.end();++apv) {
00070     apvDescription* desc = dynamic_cast<apvDescription*>( *apv );
00071     if ( !desc ) { continue; }
00072     // Retrieve device addresses from device description
00073     const SiStripConfigDb::DeviceAddress& addr = db->deviceAddress(*desc);
00074     std::stringstream bin;
00075     bin        << std::setw(1) << std::setfill('0') << addr.fecCrate_;
00076     bin << "." << std::setw(2) << std::setfill('0') << addr.fecSlot_;
00077     bin << "." << std::setw(1) << std::setfill('0') << addr.fecRing_;
00078     bin << "." << std::setw(3) << std::setfill('0') << addr.ccuAddr_;
00079     bin << "." << std::setw(2) << std::setfill('0') << addr.ccuChan_;
00080     bin << "." << desc->getAddress();
00081     LogTrace(mlDqmClient_) << "Present values for ISHA/VFS of APV " 
00082                            << bin.str() << " : " 
00083                            << static_cast<uint16_t>(desc->getIsha()) << " " << static_cast<uint16_t>(desc->getVfs());
00084   }
00085   // Load the histograms with the results
00086   std::string pwd = bei->pwd();
00087   std::string ishaPath = pwd.substr(0,pwd.find(sistrip::root_ + "/")+sistrip::root_.size()+1);
00088   ishaPath += "/ControlView/isha";
00089   LogTrace(mlDqmClient_) << "Looking for " << ishaPath;
00090   ishaHistogram_ = ExtractTObject<TH1F>().extract( bei->get(ishaPath) );
00091   std::string vfsPath = pwd.substr(0,pwd.find(sistrip::root_ + "/")+sistrip::root_.size()+1);
00092   vfsPath += "/ControlView/vfs";
00093   LogTrace(mlDqmClient_) << "Looking for " << vfsPath;
00094   vfsHistogram_ = ExtractTObject<TH1F>().extract( bei->get(vfsPath) );
00095   
00096 }
00097 
00098 // -----------------------------------------------------------------------------
00100 CalibrationHistosUsingDb::~CalibrationHistosUsingDb() {
00101   LogTrace(mlDqmClient_) 
00102     << "[CalibrationHistosUsingDb::" << __func__ << "]"
00103     << " Destructing object...";
00104 }
00105 
00106 // -----------------------------------------------------------------------------
00108 void CalibrationHistosUsingDb::uploadConfigurations() {
00109   
00110   LogTrace(mlDqmClient_)
00111     << "[CalibrationHistosUsingDb::" << __func__ << "]" << ishaHistogram_ << " " << vfsHistogram_;
00112 
00113   if(!ishaHistogram_ && !vfsHistogram_) return;
00114 
00115   if ( !db() ) {
00116     edm::LogWarning(mlDqmClient_) 
00117       << "[CalibrationHistosUsingDb::" << __func__ << "]"
00118       << " NULL pointer to SiStripConfigDb interface!"
00119       << " Aborting upload...";
00120     return;
00121   }
00122   
00123   // Update all APV device descriptions with new ISHA and VFS settings
00124   SiStripConfigDb::DeviceDescriptionsRange devices = db()->getDeviceDescriptions();
00125   update( devices );
00126   if ( doUploadConf() ) {
00127     edm::LogVerbatim(mlDqmClient_)
00128       << "[CalibrationHistosUsingDb::" << __func__ << "]"
00129       << " Uploading ISHA/VFS settings to DB...";
00130     db()->uploadDeviceDescriptions();
00131     edm::LogVerbatim(mlDqmClient_)
00132       << "[CalibrationHistosUsingDb::" << __func__ << "]"
00133       << " Uploaded ISHA/VFS settings to DB!";
00134   } else {
00135     edm::LogWarning(mlDqmClient_)
00136       << "[CalibrationHistosUsingDb::" << __func__ << "]"
00137       << " TEST only! No ISHA/VFS settings will be uploaded to DB...";
00138   }
00139 
00140   LogTrace(mlDqmClient_)
00141     << "[CalibrationHistosUsingDb::" << __func__ << "]"
00142     << " Upload of ISHA/VFS settings to DB finished!";
00143 
00144 }
00145 
00146 // -----------------------------------------------------------------------------
00148 void CalibrationHistosUsingDb::update( SiStripConfigDb::DeviceDescriptionsRange& devices ) {
00149   
00150   if(!ishaHistogram_ && !vfsHistogram_) return;
00151   
00152   // Iterate through devices and update device descriptions
00153   SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
00154   for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
00155 
00156     // Check device type
00157     if ( (*idevice)->getDeviceType() != APV25 ) { continue; }
00158 
00159     // Cast to retrieve appropriate description object
00160     apvDescription* desc = dynamic_cast<apvDescription*>( *idevice );
00161     if ( !desc ) { continue; }
00162 
00163     // Retrieve the device address from device description
00164     const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
00165 
00166     // Construct the string for that address
00167     std::stringstream bin;
00168     bin        << std::setw(1) << std::setfill('0') << addr.fecCrate_;
00169     bin << "." << std::setw(2) << std::setfill('0') << addr.fecSlot_;
00170     bin << "." << std::setw(1) << std::setfill('0') << addr.fecRing_;
00171     bin << "." << std::setw(3) << std::setfill('0') << addr.ccuAddr_;
00172     bin << "." << std::setw(2) << std::setfill('0') << addr.ccuChan_;
00173     bin << "." << desc->getAddress();
00174 
00175     // Iterate over the histo bins and find the right one
00176     for(int i = 1;i <= ishaHistogram_->GetNbinsX(); ++i) {
00177       std::string label = ishaHistogram_->GetXaxis()->GetBinLabel(i);
00178       if(label == bin.str()) {
00179         desc->setIsha( (int)round(ishaHistogram_->GetBinContent(i)) );
00180         LogDebug(mlDqmClient_) << "Setting ISHA to " << ((int)round(ishaHistogram_->GetBinContent(i))) << " for " << label;
00181       }
00182     }
00183     for(int i = 1;i <= vfsHistogram_->GetNbinsX(); ++i) {
00184       std::string label = vfsHistogram_->GetXaxis()->GetBinLabel(i);
00185       if(label == bin.str()) {
00186         desc->setVfs( (int)round(vfsHistogram_->GetBinContent(i)) );
00187         LogDebug(mlDqmClient_) << "Setting VFS to " << ((int)round(vfsHistogram_->GetBinContent(i))) << " for " << label;
00188       }
00189     }
00190     
00191   }
00192 
00193 }
00194 
00195 // -----------------------------------------------------------------------------
00197 void CalibrationHistosUsingDb::create( SiStripConfigDb::AnalysisDescriptionsV& desc,
00198                                        Analysis analysis) {
00199 
00200 #ifdef USING_NEW_DATABASE_MODEL
00201 
00202   CalibrationAnalysis* anal = dynamic_cast<CalibrationAnalysis*>( analysis->second );
00203   if ( !anal ) { return; }
00204 
00205   SiStripFecKey fec_key( anal->fecKey() );
00206   SiStripFedKey fed_key( anal->fedKey() );
00207 
00208   std::ofstream ofile("calibrationResults.txt",ios_base::app);
00209   for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
00210 
00211     // Create description
00212     CalibrationAnalysisDescription *tmp;
00213     tmp = new CalibrationAnalysisDescription(anal->amplitudeMean()[iapv],
00214                                              anal->tailMean()[iapv],
00215                                              anal->riseTimeMean()[iapv],
00216                                              anal->timeConstantMean()[iapv],
00217                                              anal->smearingMean()[iapv],
00218                                              anal->chi2Mean()[iapv],
00219                                              anal->deconvMode(),
00220                                              fec_key.fecCrate(),
00221                                              fec_key.fecSlot(),
00222                                              fec_key.fecRing(),
00223                                              fec_key.ccuAddr(),
00224                                              fec_key.ccuChan(),
00225                                              SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ),
00226                                              db()->dbParams().partitions().begin()->second.partitionName(),
00227                                              db()->dbParams().partitions().begin()->second.runNumber(),
00228                                              anal->isValid(),
00229                                              "",
00230                                              fed_key.fedId(),
00231                                              fed_key.feUnit(),
00232                                              fed_key.feChan(),
00233                                              fed_key.fedApv(),
00234                                              calchan_,
00235                                              isha_,
00236                                              vfs_ );
00237   
00238     // debug simplified printout in text file
00239     ofile << " " <<  anal->amplitudeMean()[iapv]
00240           << " " <<  anal->tailMean()[iapv]
00241           << " " <<  anal->riseTimeMean()[iapv]
00242           << " " <<  anal->timeConstantMean()[iapv]
00243           << " " <<  anal->smearingMean()[iapv]
00244           << " " <<  anal->chi2Mean()[iapv]
00245           << " " <<  anal->deconvMode()
00246           << " " <<  fec_key.fecCrate()
00247           << " " <<  fec_key.fecSlot()
00248           << " " <<  fec_key.fecRing()
00249           << " " <<  fec_key.ccuAddr()
00250           << " " <<  fec_key.ccuChan()
00251           << " " <<  SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv )
00252           << " " <<  db()->dbParams().partitions().begin()->second.partitionName()
00253           << " " <<  db()->dbParams().partitions().begin()->second.runNumber()
00254           << " " <<  fed_key.fedId()
00255           << " " <<  fed_key.feUnit()
00256           << " " <<  fed_key.feChan()
00257           << " " <<  fed_key.fedApv()
00258           << " " <<  calchan_
00259           << " " <<  isha_
00260           << " " <<  vfs_ << std::endl;
00261 
00262     // Add comments
00263     typedef std::vector<std::string> Strings;
00264     Strings errors = anal->getErrorCodes();
00265     Strings::const_iterator istr = errors.begin();
00266     Strings::const_iterator jstr = errors.end();
00267     for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
00268   
00269     // Store description
00270     desc.push_back( tmp );
00271   }
00272   ofile.close();
00273   
00274 #endif
00275 
00276 }
00277 

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