#include <DQM/SiStripCommissioningSources/interface/CalibrationTask.h>
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 | |
MonitorElement * | calchanElement_ |
std::vector< HistoSet > | calib_ |
std::string | filename_ |
uint16_t | lastCalChan_ |
uint16_t | nBins_ |
std::vector< uint16_t > | ped |
uint32_t | run_ |
sistrip::RunType | runType_ |
Definition at line 10 of file CalibrationTask.h.
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(), int, LogDebug, ped, strip(), and value.
00025 : 00026 CommissioningTask( dqm, conn, "CalibrationTask" ), 00027 runType_(rtype), 00028 nBins_(65),lastCalChan_(8), 00029 filename_(filename), 00030 run_(run) 00031 { 00032 LogDebug("Commissioning") << "[CalibrationTask::CalibrationTask] Constructing object..."; 00033 // load the pedestals 00034 edm::ESHandle<SiStripPedestals> pedestalsHandle; 00035 setup.get<SiStripPedestalsRcd>().get(pedestalsHandle); 00036 SiStripPedestals::Range detPedRange = pedestalsHandle->getRange(conn.detId()); 00037 int start = conn.apvPairNumber()*256; 00038 int stop = start + 256; 00039 int value = 0; 00040 ped.reserve(256); 00041 for(int strip = start; strip < stop; ++strip) { 00042 value = int(pedestalsHandle->getPed(strip,detPedRange)); 00043 if(value>895) value -= 1024; 00044 ped.push_back(value); 00045 } 00046 }
CalibrationTask::~CalibrationTask | ( | ) | [virtual] |
Definition at line 50 of file CalibrationTask.cc.
References LogDebug.
00050 { 00051 LogDebug("Commissioning") << "[CalibrationTask::CalibrationTask] Destructing object..."; 00052 }
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, detId, CommissioningTask::dqm(), sistrip::EXPERT_HISTO, find(), DQMStore::get(), DQMStore::getMEs(), i, LogDebug, nBins_, DQMStore::pwd(), sistrip::root_, runType_, DQMStore::setCurrentFolder(), and indexGen::title.
00056 { 00057 LogDebug("Commissioning") << "[CalibrationTask::book]"; 00058 00059 // book 32 histograms, one for each strip in a calibration group on 2 APVs 00060 calib_.resize(32); 00061 for(int apv=0;apv<2;++apv) { 00062 for(int i=0;i<16;++i) { 00063 std::string title = SiStripHistoTitle( sistrip::EXPERT_HISTO, 00064 runType_, 00065 sistrip::DET_KEY, 00066 connection().detId(), 00067 sistrip::APV, 00068 connection().i2cAddr(apv) ).title(); 00069 std::stringstream complement; 00070 complement << "_" << i ; 00071 title += complement.str(); 00072 calib_[apv*16+i].histo( dqm()->book1D( title, title, nBins_, 0, 203.125) ); 00073 calib_[apv*16+i].isProfile_=false; 00074 calib_[apv*16+i].vNumOfEntries_.resize(nBins_,0); 00075 } 00076 } 00077 00078 // book the calchan values 00079 std::string pwd = dqm()->pwd(); 00080 std::string rootDir = pwd.substr(0,pwd.find(sistrip::root_ + "/")+sistrip::root_.size()); 00081 dqm()->setCurrentFolder( rootDir ); 00082 std::vector<std::string> existingMEs = dqm()->getMEs(); 00083 if(find(existingMEs.begin(),existingMEs.end(),"calchan")!=existingMEs.end()) { 00084 calchanElement_ = dqm()->get(dqm()->pwd()+"/calchan"); 00085 } else { 00086 calchanElement_ = dqm()->bookInt("calchan"); 00087 } 00088 dqm()->setCurrentFolder(pwd); 00089 00090 LogDebug("Commissioning") << "[CalibrationTask::book] done"; 00091 00092 }
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, detId, dir, directory(), CommissioningTask::dqm(), sistrip::EXPERT_HISTO, cmsPerfPublish::fail(), filename_, MonitorElement::Fill(), i, in, it, lastCalChan_, LogTrace, name, nBins_, NULL, run_, runType_, DQMStore::save(), ss, indexGen::title, and update().
Referenced by fill().
00127 { 00128 //for the first time 00129 if(lastCalChan_==8) { 00130 // set new parameter value 00131 lastCalChan_ = calchan; 00132 calchanElement_->Fill(lastCalChan_); 00133 return; 00134 } 00135 00136 //check if CDRV register (ical) has changed 00137 // in that case, save the histograms, reset them, change the title and continue 00138 if(calchan!=lastCalChan_) { 00139 00140 // set histograms before saving 00141 update(); //TODO: we must do this for all tasks, otherwise only the first is updated. 00142 00143 // change the title 00144 for(int apv=0;apv<2;++apv) { 00145 for(int i=0;i<16;++i) { 00146 std::stringstream complement; 00147 complement << "STRIP_" << (apv*128+lastCalChan_+i*8) ; 00148 std::string title = SiStripHistoTitle( sistrip::EXPERT_HISTO, 00149 runType_, 00150 sistrip::DET_KEY, 00151 connection().detId(), 00152 sistrip::APV, 00153 connection().i2cAddr(apv), 00154 complement.str() ).title(); 00155 calib_[apv*16+i].histo()->setTitle(title); 00156 calib_[apv*16+i].histo()->setAxisTitle(title); 00157 } 00158 } 00159 00160 // Strip filename of ".root" extension 00161 std::string name; 00162 if ( filename_.find(".root",0) == std::string::npos ) { name = filename_; } 00163 else { name = filename_.substr( 0, filename_.find(".root",0) ); } 00164 00165 // Retrieve SCRATCH directory 00166 std::string scratch = "SCRATCH"; //@@ remove trailing slash!!! 00167 std::string dir = ""; 00168 if ( getenv(scratch.c_str()) != NULL ) { 00169 dir = getenv(scratch.c_str()); 00170 } 00171 00172 // Save file with appropriate filename 00173 std::stringstream ss; 00174 if ( !dir.empty() ) { ss << dir << "/"; } 00175 else { ss << "/tmp/"; } 00176 ss << name << "_"; 00177 directory(ss,run_); // Add filename with run number, host ip, pid and .root extension 00178 ss << "_CALCHAN" << lastCalChan_; // Add CalChan value 00179 ss << "_000"; // Add FU instance number (fake) 00180 ss << ".root"; // Append ".root" extension 00181 if ( !filename_.empty() ) { 00182 if(ifstream(ss.str().c_str(),ifstream::in).fail()) { //save only once. Skip if the file already exist 00183 dqm()->save( ss.str() ); 00184 LogTrace("DQMsource") 00185 << "[SiStripCommissioningSource::" << __func__ << "]" 00186 << " Saved all histograms to file \"" 00187 << ss.str() << "\""; 00188 } else { 00189 LogTrace("DQMsource") 00190 << "[SiStripCommissioningSource::" << __func__ << "]" 00191 << " Skipping creation of file \"" 00192 << ss.str() << "\" that already exists" ; 00193 } 00194 } else { 00195 edm::LogWarning("DQMsource") 00196 << "[SiStripCommissioningSource::" << __func__ << "]" 00197 << " NULL value for filename! No root file saved!"; 00198 } 00199 00200 // reset 00201 for(std::vector<HistoSet>::iterator it=calib_.begin();it<calib_.end();++it) { 00202 it->vNumOfEntries_.clear(); 00203 it->vNumOfEntries_.resize(nBins_,0); 00204 } 00205 // set new parameter values 00206 lastCalChan_ = calchan; 00207 calchanElement_->Fill(lastCalChan_); 00208 } 00209 }
void CalibrationTask::directory | ( | std::stringstream & | dir, | |
uint32_t | run_number = 0 | |||
) | [private] |
Definition at line 213 of file CalibrationTask.cc.
References gethostname(), and tmp.
Referenced by checkAndSave().
00214 { 00215 00216 // Get details about host 00217 char hn[256]; 00218 gethostname( hn, sizeof(hn) ); 00219 struct hostent* he; 00220 he = gethostbyname(hn); 00221 00222 // Extract host name and ip 00223 std::string host_name; 00224 std::string host_ip; 00225 if ( he ) { 00226 host_name = std::string(he->h_name); 00227 host_ip = std::string( inet_ntoa( *(struct in_addr*)(he->h_addr) ) ); 00228 } else { 00229 host_name = "unknown.cern.ch"; 00230 host_ip = "255.255.255.255"; 00231 } 00232 00233 // Reformat IP address 00234 std::string::size_type pos = 0; 00235 std::stringstream ip; 00236 //for ( uint16_t ii = 0; ii < 4; ++ii ) { 00237 while ( pos != std::string::npos ) { 00238 std::string::size_type tmp = host_ip.find(".",pos); 00239 if ( tmp != std::string::npos ) { 00240 ip << std::setw(3) 00241 << std::setfill('0') 00242 << host_ip.substr( pos, tmp-pos ) 00243 << "."; 00244 pos = tmp+1; // skip the delimiter "." 00245 } else { 00246 ip << std::setw(3) 00247 << std::setfill('0') 00248 << host_ip.substr( pos ); 00249 pos = std::string::npos; 00250 } 00251 } 00252 00253 // Get pid 00254 pid_t pid = getpid(); 00255 00256 // Construct string 00257 dir << std::setw(8) 00258 << std::setfill('0') 00259 << run_number 00260 << "_" 00261 << ip.str() 00262 << "_" 00263 << std::setw(5) 00264 << std::setfill('0') 00265 << pid; 00266 00267 }
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 SiStripEventSummary::calChan(), calib_, SiStripEventSummary::calSel(), checkAndSave(), edm::DetSet< T >::data, k, SiStripEventSummary::latency(), LogDebug, ped, update(), and CommissioningTask::updateHistoSet().
00097 { 00098 LogDebug("Commissioning") << "[CalibrationTask::fill]"; 00099 // Check if CalChan changed. In that case, save, reset histo, change title, and continue 00100 int isub,ical = summary.calChan(); 00101 isub = ical<4 ? ical+4 : ical-4; 00102 checkAndSave(ical); 00103 // retrieve the delay from the EventSummary 00104 int bin = (100-summary.latency())*8+(7-summary.calSel()); 00105 // Fill the histograms. 00106 // data-ped -(data-ped)_isub 00107 // the second term corresponds to the common mode substraction, looking at a strip far away. 00108 for (int apv=0; apv<2; ++apv) { 00109 for (int k=0;k<16;++k) { 00110 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])); 00111 } 00112 } 00113 if(bin>=62) update(); //TODO: temporary: find a better solution later 00114 }
void CalibrationTask::update | ( | ) | [private, virtual] |
Reimplemented from CommissioningTask.
Definition at line 118 of file CalibrationTask.cc.
References calib_, it, LogDebug, and CommissioningTask::updateHistoSet().
Referenced by checkAndSave(), and fill().
00118 { 00119 LogDebug("Commissioning") << "[CalibrationTask::update]"; 00120 for(std::vector<HistoSet>::iterator it=calib_.begin();it<calib_.end();++it) { 00121 updateHistoSet( *it ); 00122 } 00123 }
MonitorElement* CalibrationTask::calchanElement_ [private] |
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] |
uint16_t CalibrationTask::lastCalChan_ [private] |
uint16_t CalibrationTask::nBins_ [private] |
std::vector<uint16_t> CalibrationTask::ped [private] |
uint32_t CalibrationTask::run_ [private] |
sistrip::RunType CalibrationTask::runType_ [private] |