CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
EcalLaserCondTools::FileReader Class Reference
Inheritance diagram for EcalLaserCondTools::FileReader:
EcalLaserCondTools::CorrReader

Public Member Functions

 FileReader (const std::vector< std::string > &fnames)
 
bool readPs (DetId &rawdetid, EcalLaserAPDPNRatios::EcalLaserAPDPNpair &corr) override
 
bool readTime (int &t1, int t2[EcalLaserCondTools::nLmes], int &t3) override
 
 ~FileReader () override
 
- Public Member Functions inherited from EcalLaserCondTools::CorrReader
 CorrReader ()
 
virtual bool readTime (int &t1, int t2[nLmes], int &t3)
 
void setVerbosity (int verb)
 
virtual ~CorrReader ()
 

Private Member Functions

bool nextFile ()
 
void trim ()
 

Private Attributes

FILE * f_
 
std::vector< std::string > fnames_
 
unsigned ifile_
 
int iline_
 

Additional Inherited Members

- Protected Attributes inherited from EcalLaserCondTools::CorrReader
int verb_
 

Detailed Description

Definition at line 62 of file EcalLaserCondTools.h.

Constructor & Destructor Documentation

◆ FileReader()

EcalLaserCondTools::FileReader::FileReader ( const std::vector< std::string > &  fnames)
inline

Definition at line 64 of file EcalLaserCondTools.h.

64 : f_(nullptr), fnames_(fnames), ifile_(-1), iline_(0) {}

◆ ~FileReader()

EcalLaserCondTools::FileReader::~FileReader ( )
inlineoverride

Definition at line 67 of file EcalLaserCondTools.h.

67 {}

Member Function Documentation

◆ nextFile()

bool EcalLaserCondTools::FileReader::nextFile ( )
private

Definition at line 254 of file EcalLaserCondTools.cc.

254  {
255  for (;;) {
256  ++ifile_;
257  if (ifile_ >= fnames_.size()) {
258  if (verb_ > 1)
259  cout << "No more correction files.\n";
260  return false;
261  }
262  if (verb_ > 1)
263  cout << "Opening file " << fnames_[ifile_] << "\n";
264  f_ = fopen(fnames_[ifile_].c_str(), "r");
265  iline_ = 0;
266  if (f_ == nullptr) {
267  std::cerr << "Failed to open file " << fnames_[ifile_] << ". File skipped!\n";
268  } else {
269  return true;
270  }
271  }
272 }

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, gather_cfg::cout, f_, fnames_, ifile_, iline_, and EcalLaserCondTools::CorrReader::verb_.

◆ readPs()

bool EcalLaserCondTools::FileReader::readPs ( DetId rawdetid,
EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr 
)
overridevirtual

Reimplemented from EcalLaserCondTools::CorrReader.

Definition at line 323 of file EcalLaserCondTools.cc.

323  {
324  if (f_ == nullptr) {
325  if (verb_)
326  cout << "Requested to read p1..p3 parameter line while no file is closed.\n";
327  return false;
328  }
329 
330  trim();
331  int i = fgetc(f_);
332 
333  if (i != 'P') {
334  if (verb_ && i >= 0)
335  cout << "File " << fnames_[ifile_] << " line " << iline_ << ": unexpected line type, '" << (char)i
336  << "' while expecting 'P'\n";
337  if (verb_ && i < 0)
338  cout << "Failed to read p1..p3 parameter line\n";
339  return false;
340  }
341 
342  int rawdetid;
343  int n = fscanf(f_, "%d %f %f %f\n", &rawdetid, &corr.p1, &corr.p2, &corr.p3);
344  ++iline_;
345 
346  if (n != 4) {
347  // corr.p2=corr.p1;
348  // corr.p3=corr.p1;
349  throw cms::Exception("I/O") << "Syntax error at line " << iline_ << "of file " << fnames_[ifile_] << " read " << n
350  << " values,"
351  << " raw id" << rawdetid << ": " << corr.p1 << ", " << corr.p2;
352  }
353  detid = rawdetid;
354  constexpr int ECALID = 3;
355  if (detid.det() != ECALID)
356  throw cms::Exception("InvalidValue") << "Line " << iline_ << "of file " << fnames_[ifile_]
357  << " contains an invalid det ID (detector code is not ECAL!)\n";
358  if (detid.subdetId() == EcalBarrel) {
359  EBDetId ebDetId(detid);
360  if (!EBDetId::validDetId(ebDetId.ietaAbs(), ebDetId.iphi()))
361  throw cms::Exception("InvalidValue") << "Line " << iline_ << "of file " << fnames_[ifile_]
362  << " contains an invalid det ID (detector code is not ECAL!)\n";
363  }
364  if (detid.subdetId() == EcalEndcap) {
365  EEDetId eeDetId(detid);
366  if (!EEDetId::validDetId(eeDetId.ix(), eeDetId.iy(), eeDetId.zside()))
367  throw cms::Exception("InvalidValue") << "Line " << iline_ << "of file " << fnames_[ifile_]
368  << " contains an invalid det ID (detector code is not ECAL!)\n";
369  }
370  ++iline_;
371  return true;
372 }

References alignCSCRings::corr, gather_cfg::cout, DetId::det(), EcalBarrel, EcalEndcap, Exception, EcalLaserCondTools::fnames_, mps_fire::i, EBDetId::ietaAbs(), EBDetId::iphi(), EEDetId::ix(), EEDetId::iy(), dqmiodumpmetadata::n, DetId::subdetId(), trim(), EBDetId::validDetId(), EEDetId::validDetId(), EcalLaserCondTools::verb_, and EEDetId::zside().

◆ readTime()

bool EcalLaserCondTools::FileReader::readTime ( int &  t1,
int  t2[EcalLaserCondTools::nLmes],
int &  t3 
)
override

Definition at line 274 of file EcalLaserCondTools.cc.

274  {
275  trim();
276  if ((f_ == nullptr || feof(f_)) && !nextFile()) {
277  if (verb_ > 1)
278  cout << "No more record\n";
279  return false;
280  }
281  int i;
282  char* buf = nullptr;
283  size_t s = 0;
284  while ((i = fgetc(f_)) != 'T' && i != 'L' && i >= 0)
285  getline(&buf, &s, f_);
286  if (buf)
287  free(buf);
288  buf = nullptr;
289 
290  if (i == 'L') { //last record put 3 consecutive times starting from end of prev. IOV
291  t1 = t3;
292  for (int i = 0; i < EcalLaserCondTools::nLmes; ++i)
293  t2[i] = t1 + 1;
294  t3 = t1 + 2;
295  return true;
296  }
297 
298  if (i != 'T') {
299  if (verb_ > 1)
300  cout << "No more record or bad line type/marker (getc returned " << i << ")\n";
301  return false;
302  }
303 
305  int n = fscanf(f_, "%d %d", &t1, &t3);
306  for (int i = 0; i < EcalLaserCondTools::nLmes; ++i) {
307  int nn = fscanf(f_, "%d", &t2[i]);
308  if (nn != 1)
309  break;
310  n += nn;
311  }
312 
313  int nnn = fscanf(f_, " ");
314 
315  if (n != (2 + EcalLaserCondTools::nLmes) || nnn != 0)
316  throw cms::Exception("LasCorFile") << "File " << fnames_[ifile_] << " line " << iline_
317  << ": syntax error. Expecting 'T' marker followed by 94 values: "
318  << "t1 t2 t3(lme 1) t3(lme 2) ... t3(lme " << EcalLaserCondTools::nLmes << ")\n";
319 
320  return true;
321 }

References visDQMUpload::buf, gather_cfg::cout, Exception, EcalLaserCondTools::fnames_, mps_fire::i, dqmiodumpmetadata::n, EcalLaserCondTools::nLmes, groupFilesInBlocks::nn, alignCSCRings::s, submitPVValidationJobs::t, RandomServiceHelper::t1, RandomServiceHelper::t2, RandomServiceHelper::t3, trim(), and EcalLaserCondTools::verb_.

◆ trim()

void EcalLaserCondTools::FileReader::trim ( )
private

Definition at line 374 of file EcalLaserCondTools.cc.

374  {
375  if (f_ == nullptr)
376  return;
377  bool skipLine = false;
378  int c;
379  while ((c = fgetc(f_)) >= 0 && (c == ' ' || c == '\t' || c == '\n' || c == '#' || skipLine)) {
380  if (c == '#')
381  skipLine = true;
382  if (c == '\n') {
383  ++iline_;
384  skipLine = false;
385  }
386  }
387  ungetc(c, f_);
388 }

References HltBtagPostValidation_cff::c.

Member Data Documentation

◆ f_

FILE* EcalLaserCondTools::FileReader::f_
private

Definition at line 72 of file EcalLaserCondTools.h.

Referenced by nextFile().

◆ fnames_

std::vector<std::string> EcalLaserCondTools::FileReader::fnames_
private

Definition at line 73 of file EcalLaserCondTools.h.

Referenced by nextFile().

◆ ifile_

unsigned EcalLaserCondTools::FileReader::ifile_
private

Definition at line 74 of file EcalLaserCondTools.h.

Referenced by nextFile().

◆ iline_

int EcalLaserCondTools::FileReader::iline_
private

Definition at line 75 of file EcalLaserCondTools.h.

Referenced by nextFile().

RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
EBDetId
Definition: EBDetId.h:17
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EcalLaserCondTools::FileReader::nextFile
bool nextFile()
Definition: EcalLaserCondTools.cc:254
EcalLaserCondTools::FileReader::ifile_
unsigned ifile_
Definition: EcalLaserCondTools.h:74
EcalBarrel
Definition: EcalSubdetector.h:10
alignCSCRings.s
s
Definition: alignCSCRings.py:92
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
EcalLaserCondTools::FileReader::f_
FILE * f_
Definition: EcalLaserCondTools.h:72
alignCSCRings.corr
dictionary corr
Definition: alignCSCRings.py:124
EcalLaserCondTools::CorrReader::verb_
int verb_
Definition: EcalLaserCondTools.h:59
RandomServiceHelper.t3
t3
Definition: RandomServiceHelper.py:258
EEDetId
Definition: EEDetId.h:14
EcalEndcap
Definition: EcalSubdetector.h:10
EcalLaserCondTools::nLmes
static constexpr int nLmes
Definition: EcalLaserCondTools.h:28
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
EBDetId::validDetId
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
groupFilesInBlocks.nn
nn
Definition: groupFilesInBlocks.py:150
EcalLaserCondTools::FileReader::fnames_
std::vector< std::string > fnames_
Definition: EcalLaserCondTools.h:73
Exception
Definition: hltDiff.cc:246
EcalLaserCondTools::FileReader::trim
void trim()
Definition: EcalLaserCondTools.cc:374
EEDetId::validDetId
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
cms::Exception
Definition: Exception.h:70
SiStripCommissioningSource_FromRAW_cfg.fnames
fnames
Definition: SiStripCommissioningSource_FromRAW_cfg.py:143
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
EcalLaserAPDPNRatios::EcalLaserTimeStamp
Definition: EcalLaserAPDPNRatios.h:24
EcalLaserCondTools::FileReader::iline_
int iline_
Definition: EcalLaserCondTools.h:75