CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

CalibrationTask Class Reference

#include <CalibrationTask.h>

Inheritance diagram for CalibrationTask:
CommissioningTask

List of all members.

Public Member Functions

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

Private Member Functions

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

Private Attributes

MonitorElementcalchanElement_
std::vector< HistoSetcalib_
std::string filename_
uint16_t lastCalChan_
uint16_t nBins_
std::vector< uint16_t > ped
uint32_t run_
sistrip::RunType runType_

Detailed Description

Definition at line 10 of file CalibrationTask.h.


Constructor & Destructor Documentation

CalibrationTask::CalibrationTask ( 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 CalibrationTask.cc.

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

                                                          :
  CommissioningTask( dqm, conn, "CalibrationTask" ),
  runType_(rtype),
  nBins_(65),lastCalChan_(8),
  filename_(filename),
  run_(run)
{
  LogDebug("Commissioning") << "[CalibrationTask::CalibrationTask] 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);
  for(int strip = start; strip < stop; ++strip) {
    value = int(pedestalsHandle->getPed(strip,detPedRange));
    if(value>895) value -= 1024;
    ped.push_back(value);
  }
}
CalibrationTask::~CalibrationTask ( ) [virtual]

Definition at line 50 of file CalibrationTask.cc.

References LogDebug.

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

Member Function Documentation

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

Reimplemented from CommissioningTask.

Definition at line 56 of file CalibrationTask.cc.

References sistrip::APV, DQMStore::bookInt(), calchanElement_, calib_, CommissioningTask::connection(), sistrip::DET_KEY, CommissioningTask::dqm(), sistrip::EXPERT_HISTO, spr::find(), DQMStore::get(), DQMStore::getMEs(), i, LogDebug, nBins_, DQMStore::pwd(), alignCSCRings::pwd, sistrip::root_, runType_, DQMStore::setCurrentFolder(), SiStripHistoTitle::title(), and indexGen::title.

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

  // book 32 histograms, one for each strip in a calibration group on 2 APVs
  calib_.resize(32);
  for(int apv=0;apv<2;++apv) {
    for(int i=0;i<16;++i) {
      std::string title = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
                                             runType_, 
                                             sistrip::DET_KEY, 
                                             connection().detId(),
                                             sistrip::APV, 
                                             connection().i2cAddr(apv) ).title(); 
      std::stringstream complement;
      complement << "_" << i ;
      title += complement.str();                        
      calib_[apv*16+i].histo( dqm()->book1D( title, title, nBins_, 0, 203.125) );
      calib_[apv*16+i].isProfile_=false;
      calib_[apv*16+i].vNumOfEntries_.resize(nBins_,0);
    }
  }

  // book the calchan 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(),"calchan")!=existingMEs.end()) {
    calchanElement_ = dqm()->get(dqm()->pwd()+"/calchan");
  } else {
    calchanElement_ = dqm()->bookInt("calchan");
  }
  dqm()->setCurrentFolder(pwd);
  
  LogDebug("Commissioning") << "[CalibrationTask::book] done";
  
}
void CalibrationTask::checkAndSave ( const uint16_t &  calchan) [private]

Definition at line 127 of file CalibrationTask.cc.

References sistrip::APV, calchanElement_, calib_, CommissioningTask::connection(), sistrip::DET_KEY, dir, directory(), CommissioningTask::dqm(), sistrip::EXPERT_HISTO, cmsPerfPublish::fail(), filename_, MonitorElement::Fill(), i, recoMuon::in, lastCalChan_, LogTrace, mergeVDriftHistosByStation::name, nBins_, NULL, run_, runType_, DQMStore::save(), indexGen::title, and update().

Referenced by fill().

                                                          {
  //for the first time
  if(lastCalChan_==8) {
    // set new parameter value
    lastCalChan_ = calchan;
    calchanElement_->Fill(lastCalChan_);
    return;
  }

  //check if CDRV register (ical) has changed
  // in that case, save the histograms, reset them, change the title and continue
  if(calchan!=lastCalChan_) {
    
    // set histograms before saving
    update(); //TODO: we must do this for all tasks, otherwise only the first is updated.

    // change the title
    for(int apv=0;apv<2;++apv) {
      for(int i=0;i<16;++i) {
        std::stringstream complement;
        complement << "STRIP_" << (apv*128+lastCalChan_+i*8) ;
        std::string title = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
                                               runType_, 
                                               sistrip::DET_KEY, 
                                               connection().detId(),
                                               sistrip::APV, 
                                               connection().i2cAddr(apv),
                                               complement.str() ).title(); 
        calib_[apv*16+i].histo()->setTitle(title);
        calib_[apv*16+i].histo()->setAxisTitle(title);
      }
    }

    // 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 << "_CALCHAN" << lastCalChan_; // Add CalChan value
    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
    for(std::vector<HistoSet>::iterator it=calib_.begin();it<calib_.end();++it) {
      it->vNumOfEntries_.clear();
      it->vNumOfEntries_.resize(nBins_,0);
    }
    // set new parameter values
    lastCalChan_ = calchan;
    calchanElement_->Fill(lastCalChan_);
  }
}
void CalibrationTask::directory ( std::stringstream &  dir,
uint32_t  run_number = 0 
) [private]

Definition at line 213 of file CalibrationTask.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 CalibrationTask::fill ( const SiStripEventSummary summary,
const edm::DetSet< SiStripRawDigi > &  digis 
) [private, virtual]

Reimplemented from CommissioningTask.

Definition at line 96 of file CalibrationTask.cc.

References newFWLiteAna::bin, SiStripEventSummary::calChan(), calib_, SiStripEventSummary::calSel(), checkAndSave(), edm::DetSet< T >::data, gen::k, SiStripEventSummary::latency(), LogDebug, ped, update(), and CommissioningTask::updateHistoSet().

                                                                     {
  LogDebug("Commissioning") << "[CalibrationTask::fill]";
  // Check if CalChan changed. In that case, save, reset histo, change title, and continue
  int isub,ical = summary.calChan();
  isub = ical<4 ? ical+4 : ical-4;
  checkAndSave(ical);
  // retrieve the delay from the EventSummary
  int bin = (100-summary.latency())*8+(7-summary.calSel());
  // Fill the histograms.
  // data-ped -(data-ped)_isub
  // the second term corresponds to the common mode substraction, looking at a strip far away.
  for (int apv=0; apv<2; ++apv) {
    for (int k=0;k<16;++k)  {
      updateHistoSet( calib_[apv*16+k],bin,digis.data[apv*128+ical+k*8].adc()-ped[apv*128+ical+k*8]-(digis.data[apv*128+isub+k*8].adc()-ped[apv*128+isub+k*8]));
    }
  }
  update(); //TODO: temporary: find a better solution later
}
void CalibrationTask::update ( void  ) [private, virtual]

Reimplemented from CommissioningTask.

Definition at line 118 of file CalibrationTask.cc.

References calib_, and CommissioningTask::updateHistoSet().

Referenced by checkAndSave(), and fill().

                             {
  // LogDebug("Commissioning") << "[CalibrationTask::update]"; // huge output
  for(std::vector<HistoSet>::iterator it=calib_.begin();it<calib_.end();++it) {
    updateHistoSet( *it );
  }
}

Member Data Documentation

Definition at line 37 of file CalibrationTask.h.

Referenced by book(), and checkAndSave().

std::vector<HistoSet> CalibrationTask::calib_ [private]

Definition at line 30 of file CalibrationTask.h.

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

std::string CalibrationTask::filename_ [private]

Definition at line 34 of file CalibrationTask.h.

Referenced by checkAndSave().

uint16_t CalibrationTask::lastCalChan_ [private]

Definition at line 33 of file CalibrationTask.h.

Referenced by checkAndSave().

uint16_t CalibrationTask::nBins_ [private]

Definition at line 32 of file CalibrationTask.h.

Referenced by book(), and checkAndSave().

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

Definition at line 35 of file CalibrationTask.h.

Referenced by CalibrationTask(), and fill().

uint32_t CalibrationTask::run_ [private]

Definition at line 36 of file CalibrationTask.h.

Referenced by checkAndSave().

Definition at line 28 of file CalibrationTask.h.

Referenced by book(), and checkAndSave().