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[nLmes], int &t3) override
 
 ~FileReader () override
 
- Public Member Functions inherited from EcalLaserCondTools::CorrReader
 CorrReader ()
 
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 266 of file EcalLaserCondTools.cc.

266  {
267  for (;;) {
268  ++ifile_;
269  if (ifile_ >= fnames_.size()) {
270  if (verb_ > 1)
271  cout << "No more correction files.\n";
272  return false;
273  }
274  if (verb_ > 1)
275  cout << "Opening file " << fnames_[ifile_] << "\n";
276  f_ = fopen(fnames_[ifile_].c_str(), "r");
277  iline_ = 0;
278  if (f_ == nullptr) {
279  std::cerr << "Failed to open file " << fnames_[ifile_] << ". File skipped!\n";
280  } else {
281  return true;
282  }
283  }
284 }

References beam_dqm_sourceclient-live_cfg::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 335 of file EcalLaserCondTools.cc.

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

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[nLmes],
int &  t3 
)
overridevirtual

Reimplemented from EcalLaserCondTools::CorrReader.

Definition at line 286 of file EcalLaserCondTools.cc.

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

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

◆ trim()

void EcalLaserCondTools::FileReader::trim ( )
private

Definition at line 386 of file EcalLaserCondTools.cc.

386  {
387  if (f_ == nullptr)
388  return;
389  bool skipLine = false;
390  int c;
391  while ((c = fgetc(f_)) >= 0 && (c == ' ' || c == '\t' || c == '\n' || c == '#' || skipLine)) {
392  if (c == '#')
393  skipLine = true;
394  if (c == '\n') {
395  ++iline_;
396  skipLine = false;
397  }
398  }
399  ungetc(c, f_);
400 }

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:355
EcalLaserCondTools::nLmes
static const int nLmes
Definition: EcalLaserCondTools.h:28
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:266
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
OrderedSet.t
t
Definition: OrderedSet.py:90
RandomServiceHelper.t3
t3
Definition: RandomServiceHelper.py:258
EEDetId
Definition: EEDetId.h:14
EcalEndcap
Definition: EcalSubdetector.h:10
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
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:386
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
EcalLaserAPDPNRatios::EcalLaserTimeStamp
Definition: EcalLaserAPDPNRatios.h:24
EcalLaserCondTools::FileReader::iline_
int iline_
Definition: EcalLaserCondTools.h:75