CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

CalibrationScanTask Class Reference

#include <CalibrationScanTask.h>

Inheritance diagram for CalibrationScanTask:
CommissioningTask

List of all members.

Public Member Functions

 CalibrationScanTask (DQMStore *, const FedChannelConnection &, const sistrip::RunType &, const char *filename, uint32_t run, const edm::EventSetup &setup)
virtual ~CalibrationScanTask ()

Private Member Functions

virtual void book ()
void checkAndSave (const uint16_t &isha, const uint16_t &vfs)
void directory (std::stringstream &, uint32_t run_number=0)
virtual void fill (const SiStripEventSummary &, const edm::DetSet< SiStripRawDigi > &)
virtual void update ()

Private Attributes

MonitorElementcalchanElement_
HistoSet calib1_
HistoSet calib2_
std::string filename_
MonitorElementishaElement_
uint16_t lastCalchan_
uint16_t lastISHA_
uint16_t lastVFS_
uint16_t nBins_
std::vector< uint16_t > ped
uint32_t run_
sistrip::RunType runType_
MonitorElementvfsElement_

Detailed Description

Definition at line 10 of file CalibrationScanTask.h.


Constructor & Destructor Documentation

CalibrationScanTask::CalibrationScanTask ( DQMStore dqm,
const FedChannelConnection conn,
const sistrip::RunType rtype,
const char *  filename,
uint32_t  run,
const edm::EventSetup setup 
)

Definition at line 20 of file CalibrationScanTask.cc.

References FedChannelConnection::apvPairNumber(), FedChannelConnection::detId(), edm::EventSetup::get(), LogDebug, ped, strip(), and relativeConstraints::value.

                                                           :
  CommissioningTask( dqm, conn, "CalibrationScanTask" ),
  runType_(rtype),
  calib1_(),calib2_(),
  nBins_(65),lastISHA_(1000),lastVFS_(1000),lastCalchan_(1000),
  filename_(filename),
  run_(run)
{
  LogDebug("Commissioning") << "[CalibrationScanTask::CalibrationScanTask] Constructing object...";
  // load the pedestals
  edm::ESHandle<SiStripPedestals> pedestalsHandle;
  setup.get<SiStripPedestalsRcd>().get(pedestalsHandle);
  SiStripPedestals::Range detPedRange = pedestalsHandle->getRange(conn.detId());
  int start = conn.apvPairNumber()*256;
  int stop  = start + 256;
  int value = 0;
  ped.reserve(256);
  LogDebug("Commissioning") << "[CalibrationScanTask::CalibrationScanTask] Loading pedestal for " << conn.detId();
  if(conn.detId()==0) return;
  for(int strip = start; strip < stop; ++strip) {
    value = int(pedestalsHandle->getPed(strip,detPedRange));
    if(value>895) value -= 1024;
    ped.push_back(value);
  }
}
CalibrationScanTask::~CalibrationScanTask ( ) [virtual]

Definition at line 53 of file CalibrationScanTask.cc.

References LogDebug.

                                          {
  LogDebug("Commissioning") << "[CalibrationScanTask::CalibrationScanTask] Destructing object...";
}

Member Function Documentation

void CalibrationScanTask::book ( ) [private, virtual]

Reimplemented from CommissioningTask.

Definition at line 59 of file CalibrationScanTask.cc.

References sistrip::APV, DQMStore::bookInt(), calchanElement_, calib1_, calib2_, CommissioningTask::connection(), sistrip::DET_KEY, CommissioningTask::dqm(), sistrip::EXPERT_HISTO, spr::find(), DQMStore::get(), DQMStore::getMEs(), CommissioningTask::HistoSet::histo(), ishaElement_, CommissioningTask::HistoSet::isProfile_, LogDebug, nBins_, DQMStore::pwd(), createBeamHaloJobs::pwd, sistrip::root_, runType_, DQMStore::setCurrentFolder(), SiStripHistoTitle::title(), vfsElement_, and CommissioningTask::HistoSet::vNumOfEntries_.

                               {
  LogDebug("Commissioning") << "[CalibrationScanTask::book]";

  // construct the histo titles and book two histograms: one per APV
  std::string title1 = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
                                         runType_, 
                                         sistrip::DET_KEY, 
                                         connection().detId(),
                                         sistrip::APV, 
                                         connection().i2cAddr(0) ).title(); 
  calib1_.histo( dqm()->book1D( title1, title1, nBins_, 0, 203.125) );
  calib1_.isProfile_=false;
  calib1_.vNumOfEntries_.resize(nBins_,0);
  std::string title2 = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
                                         runType_, 
                                         sistrip::DET_KEY, 
                                         connection().detId(),
                                         sistrip::APV, 
                                         connection().i2cAddr(1) ).title(); 
  calib2_.histo( dqm()->book1D( title2, title2, nBins_, 0, 203.125) );
  calib2_.isProfile_=false;
  calib2_.vNumOfEntries_.resize(nBins_,0);

  // book the isha, vfs values
  std::string pwd = dqm()->pwd();
  std::string rootDir = pwd.substr(0,pwd.find(std::string(sistrip::root_) + "/")+(sizeof(sistrip::root_) - 1));
  dqm()->setCurrentFolder( rootDir );
  std::vector<std::string> existingMEs = dqm()->getMEs();
  if(find(existingMEs.begin(),existingMEs.end(),"isha")!=existingMEs.end()) {
    ishaElement_ = dqm()->get(dqm()->pwd()+"/isha");
  } else {
    ishaElement_ = dqm()->bookInt("isha");
  }
  if(find(existingMEs.begin(),existingMEs.end(),"isha")!=existingMEs.end()) {
    vfsElement_ = dqm()->get(dqm()->pwd()+"/vfs");  
  } else {
    vfsElement_ = dqm()->bookInt("vfs");
  }
  if(find(existingMEs.begin(),existingMEs.end(),"calchan")!=existingMEs.end()) {
    calchanElement_ = dqm()->get(dqm()->pwd()+"/calchan");
  } else {
    calchanElement_ = dqm()->bookInt("calchan");
  }
  
  LogDebug("Commissioning") << "[CalibrationScanTask::book] done";
  
}
void CalibrationScanTask::checkAndSave ( const uint16_t &  isha,
const uint16_t &  vfs 
) [private]

Definition at line 143 of file CalibrationScanTask.cc.

References sistrip::APV, calchanElement_, calib1_, calib2_, CommissioningTask::connection(), sistrip::DET_KEY, dir, directory(), CommissioningTask::dqm(), sistrip::EXPERT_HISTO, cmsPerfPublish::fail(), filename_, MonitorElement::Fill(), CommissioningTask::HistoSet::histo(), recoMuon::in, ishaElement_, lastCalchan_, lastISHA_, lastVFS_, LogTrace, mergeVDriftHistosByStation::name, nBins_, NULL, run_, runType_, DQMStore::save(), indexGen::title, update(), vfsElement_, and CommissioningTask::HistoSet::vNumOfEntries_.

Referenced by fill().

                                                                                 {
  //for the first time
  if(lastISHA_==1000 && lastVFS_==1000) {
    lastISHA_ = isha;
    lastVFS_  = vfs;
  }

  // set the calchan value in the correspond string
  ishaElement_->Fill(lastISHA_);
  vfsElement_->Fill(lastVFS_);
  calchanElement_->Fill(lastCalchan_);

  // check if ISHA/VFS has changed
  // in that case, save the histograms, reset them, change the title and continue
  if(lastISHA_!=isha || lastVFS_!=vfs) {

    // set histograms before saving
    update(); //TODO: we must do this for all tasks, otherwise only the first is updated.
    
    // change the title
    std::stringstream complement;
    complement << "ISHA" << isha << "_VFS" << vfs;
    std::string title1 = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
                                            runType_, 
                                            sistrip::DET_KEY, 
                                            connection().detId(),
                                            sistrip::APV, 
                                            connection().i2cAddr(0),
                                            complement.str() ).title(); 
    calib1_.histo()->setTitle(title1);

    std::string title2 = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
                                            runType_, 
                                            sistrip::DET_KEY, 
                                            connection().detId(),
                                            sistrip::APV, 
                                            connection().i2cAddr(1),
                                            complement.str() ).title(); 
    calib2_.histo()->setTitle(title2);

    // Strip filename of ".root" extension
    std::string name;
    if ( filename_.find(".root",0) == std::string::npos ) { name = filename_; }
    else { name = filename_.substr( 0, filename_.find(".root",0) ); }
  
    // Retrieve SCRATCH directory
    std::string scratch = "SCRATCH"; //@@ remove trailing slash!!!
    std::string dir = "";
    if ( getenv(scratch.c_str()) != NULL ) {
      dir = getenv(scratch.c_str());
    }
  
    // Save file with appropriate filename 
    std::stringstream ss;
    if ( !dir.empty() ) { ss << dir << "/"; }
    else { ss << "/tmp/"; }
    ss << name << "_";
    directory(ss,run_); // Add filename with run number, host ip, pid and .root extension
    ss << "_ISHA" << lastISHA_ << "_VFS" << lastVFS_; // Add ISHA and VFS values
    ss << "_000"; // Add FU instance number (fake)
    ss << ".root"; // Append ".root" extension
    if ( !filename_.empty() ) {
      if(ifstream(ss.str().c_str(),ifstream::in).fail()) { //save only once. Skip if the file already exist
        dqm()->save( ss.str() ); 
        LogTrace("DQMsource")
          << "[SiStripCommissioningSource::" << __func__ << "]"
          << " Saved all histograms to file \""
          << ss.str() << "\"";
      } else {
        LogTrace("DQMsource")
          << "[SiStripCommissioningSource::" << __func__ << "]"
          << " Skipping creation of file \""
          << ss.str() << "\" that already exists" ;
      }
    } else {
      edm::LogWarning("DQMsource")
        << "[SiStripCommissioningSource::" << __func__ << "]"
        << " NULL value for filename! No root file saved!";
    }
  
    // reset
    calib1_.vNumOfEntries_.clear();
    calib1_.vNumOfEntries_.resize(nBins_,0);
    calib2_.vNumOfEntries_.clear();
    calib2_.vNumOfEntries_.resize(nBins_,0);
  
    // set new parameter values
    lastISHA_=isha;
    lastVFS_=vfs;
    // set the calchan value in the correspond string
    ishaElement_->Fill(lastISHA_);
    vfsElement_->Fill(lastVFS_);
    calchanElement_->Fill(lastCalchan_);
  }
}
void CalibrationScanTask::directory ( std::stringstream &  dir,
uint32_t  run_number = 0 
) [private]

Definition at line 241 of file CalibrationScanTask.cc.

References evf::utils::pid, pos, and tmp.

Referenced by checkAndSave().

                                                                  {

  // Get details about host
  char hn[256];
  gethostname( hn, sizeof(hn) );
  struct hostent* he;
  he = gethostbyname(hn);

  // Extract host name and ip
  std::string host_name;
  std::string host_ip;
  if ( he ) { 
    host_name = std::string(he->h_name);
    host_ip = std::string( inet_ntoa( *(struct in_addr*)(he->h_addr) ) );
  } else {
    host_name = "unknown.cern.ch";
    host_ip = "255.255.255.255";
  }

  // Reformat IP address
  std::string::size_type pos = 0;
  std::stringstream ip;
  //for ( uint16_t ii = 0; ii < 4; ++ii ) {
  while ( pos != std::string::npos ) {
    std::string::size_type tmp = host_ip.find(".",pos);
    if ( tmp != std::string::npos ) {
      ip << std::setw(3)
         << std::setfill('0')
         << host_ip.substr( pos, tmp-pos ) 
         << ".";
      pos = tmp+1; // skip the delimiter "."
    } else {
      ip << std::setw(3)
         << std::setfill('0')
         << host_ip.substr( pos );
      pos = std::string::npos;
    }
  }
  
  // Get pid
  pid_t pid = getpid();

  // Construct string
  dir << std::setw(8) 
      << std::setfill('0') 
      << run_number
      << "_" 
      << ip.str()
      << "_"
      << std::setw(5) 
      << std::setfill('0') 
      << pid;

}
void CalibrationScanTask::fill ( const SiStripEventSummary summary,
const edm::DetSet< SiStripRawDigi > &  digis 
) [private, virtual]

Reimplemented from CommissioningTask.

Definition at line 109 of file CalibrationScanTask.cc.

References newFWLiteAna::bin, SiStripEventSummary::calChan(), calib1_, calib2_, SiStripEventSummary::calSel(), checkAndSave(), edm::DetSet< T >::data, SiStripEventSummary::isha(), gen::k, lastCalchan_, SiStripEventSummary::latency(), ped, update(), CommissioningTask::updateHistoSet(), and SiStripEventSummary::vfs().

                                                                     {
//  LogDebug("Commissioning") << "[CalibrationScanTask::fill]: isha/vfs = " << summary.isha() << "/" << summary.vfs();
  // Check if ISHA/VFS changed. In that case, save, reset histo, change title, and continue
  checkAndSave(summary.isha(),summary.vfs());
  // retrieve the delay from the EventSummary
  int bin = (100-summary.latency())*8+(7-summary.calSel());
  // loop on the strips to fill the histogram
  // digis are obtained for an APV pair. 
  // strips 0->127  : calib1_
  // strips 128->255: calib2_
  // then, only some strips are fired at a time.
  // We use calChan to know that
  int isub,ical = summary.calChan();
  isub = ical<4 ? ical+4 : ical-4;
  lastCalchan_ = ical;
  for (int k=0;k<16;++k)  {
    // all strips of the APV are merged in 
    updateHistoSet( calib1_,bin,digis.data[ical+k*8].adc()-ped[ical+k*8]-(digis.data[isub+k*8].adc()-ped[isub+k*8]));
    updateHistoSet( calib2_,bin,digis.data[128+ical+k*8].adc()-ped[128+ical+k*8]-(digis.data[128+isub+k*8].adc()-ped[128+isub+k*8]));
  }
  update(); //TODO: temporary: find a better solution later
}
void CalibrationScanTask::update ( void  ) [private, virtual]

Reimplemented from CommissioningTask.

Definition at line 135 of file CalibrationScanTask.cc.

References calib1_, calib2_, and CommissioningTask::updateHistoSet().

Referenced by checkAndSave(), and fill().

                                 {
  // LogDebug("Commissioning") << "[CalibrationScanTask::update]"; // huge output
  updateHistoSet( calib1_ );
  updateHistoSet( calib2_ );
}

Member Data Documentation

Definition at line 36 of file CalibrationScanTask.h.

Referenced by book(), and checkAndSave().

Definition at line 29 of file CalibrationScanTask.h.

Referenced by book(), checkAndSave(), fill(), and update().

Definition at line 29 of file CalibrationScanTask.h.

Referenced by book(), checkAndSave(), fill(), and update().

std::string CalibrationScanTask::filename_ [private]

Definition at line 33 of file CalibrationScanTask.h.

Referenced by checkAndSave().

Definition at line 36 of file CalibrationScanTask.h.

Referenced by book(), and checkAndSave().

Definition at line 32 of file CalibrationScanTask.h.

Referenced by checkAndSave(), and fill().

uint16_t CalibrationScanTask::lastISHA_ [private]

Definition at line 32 of file CalibrationScanTask.h.

Referenced by checkAndSave().

uint16_t CalibrationScanTask::lastVFS_ [private]

Definition at line 32 of file CalibrationScanTask.h.

Referenced by checkAndSave().

uint16_t CalibrationScanTask::nBins_ [private]

Definition at line 31 of file CalibrationScanTask.h.

Referenced by book(), and checkAndSave().

std::vector<uint16_t> CalibrationScanTask::ped [private]

Definition at line 34 of file CalibrationScanTask.h.

Referenced by CalibrationScanTask(), and fill().

uint32_t CalibrationScanTask::run_ [private]

Definition at line 35 of file CalibrationScanTask.h.

Referenced by checkAndSave().

Definition at line 27 of file CalibrationScanTask.h.

Referenced by book(), and checkAndSave().

Definition at line 36 of file CalibrationScanTask.h.

Referenced by book(), and checkAndSave().