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 64 of file EcalLaserCondTools.h.

Constructor & Destructor Documentation

◆ FileReader()

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

◆ ~FileReader()

EcalLaserCondTools::FileReader::~FileReader ( )
inlineoverride

Definition at line 69 of file EcalLaserCondTools.h.

69 {}

Member Function Documentation

◆ nextFile()

bool EcalLaserCondTools::FileReader::nextFile ( )
private

Definition at line 448 of file EcalLaserCondTools.cc.

References DMR_cfg::cerr, f_, fnames_, ifile_, iline_, and EcalLaserCondTools::CorrReader::verb_.

448  {
449  for (;;) {
450  ++ifile_;
451  if (ifile_ >= fnames_.size()) {
452  if (verb_ > 1)
453  edm::LogPrint("EcalLaserCondTools") << "No more correction files.\n";
454 
455  return false;
456  }
457  if (verb_ > 1)
458  edm::LogPrint("EcalLaserCondTools") << "Opening file " << fnames_[ifile_] << "\n";
459 
460  f_ = fopen(fnames_[ifile_].c_str(), "r");
461  iline_ = 0;
462  if (f_ == nullptr) {
463  std::cerr << "Failed to open file " << fnames_[ifile_] << ". File skipped!\n";
464  } else {
465  return true;
466  }
467  }
468 }
Log< level::Warning, true > LogPrint
std::vector< std::string > fnames_

◆ readPs()

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

Reimplemented from EcalLaserCondTools::CorrReader.

Definition at line 521 of file EcalLaserCondTools.cc.

References alignCSCRings::corr, 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().

521  {
522  if (f_ == nullptr) {
523  if (verb_)
524  edm::LogPrint("EcalLaserCondTools") << "Requested to read p1..p3 parameter line while no file is closed.\n";
525 
526  return false;
527  }
528 
529  trim();
530  int i = fgetc(f_);
531 
532  if (i != 'P') {
533  if (verb_ && i >= 0)
534  edm::LogPrint("EcalLaserCondTools") << "File " << fnames_[ifile_] << " line " << iline_
535  << ": unexpected line type, '" << (char)i << "' while expecting 'P'\n";
536 
537  if (verb_ && i < 0)
538  edm::LogPrint("EcalLaserCondTools") << "Failed to read p1..p3 parameter line\n";
539 
540  return false;
541  }
542 
543  int rawdetid;
544  int n = fscanf(f_, "%d %f %f %f\n", &rawdetid, &corr.p1, &corr.p2, &corr.p3);
545  ++iline_;
546 
547  if (n != 4) {
548  // corr.p2=corr.p1;
549  // corr.p3=corr.p1;
550  throw cms::Exception("I/O") << "Syntax error at line " << iline_ << "of file " << fnames_[ifile_] << " read " << n
551  << " values,"
552  << " raw id" << rawdetid << ": " << corr.p1 << ", " << corr.p2;
553  }
554  detid = rawdetid;
555  constexpr int ECALID = 3;
556  if (detid.det() != ECALID)
557  throw cms::Exception("InvalidValue") << "Line " << iline_ << "of file " << fnames_[ifile_]
558  << " contains an invalid det ID (detector code is not ECAL!)\n";
559  if (detid.subdetId() == EcalBarrel) {
560  EBDetId ebDetId(detid);
561  if (!EBDetId::validDetId(ebDetId.ietaAbs(), ebDetId.iphi()))
562  throw cms::Exception("InvalidValue") << "Line " << iline_ << "of file " << fnames_[ifile_]
563  << " contains an invalid det ID (detector code is not ECAL!)\n";
564  }
565  if (detid.subdetId() == EcalEndcap) {
566  EEDetId eeDetId(detid);
567  if (!EEDetId::validDetId(eeDetId.ix(), eeDetId.iy(), eeDetId.zside()))
568  throw cms::Exception("InvalidValue") << "Line " << iline_ << "of file " << fnames_[ifile_]
569  << " contains an invalid det ID (detector code is not ECAL!)\n";
570  }
571  ++iline_;
572  return true;
573 }
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
dictionary corr
Log< level::Warning, true > LogPrint
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
std::vector< std::string > fnames_

◆ readTime()

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

Definition at line 470 of file EcalLaserCondTools.cc.

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

470  {
471  trim();
472  if ((f_ == nullptr || feof(f_)) && !nextFile()) {
473  if (verb_ > 1)
474  edm::LogPrint("EcalLaserCondTools") << "No more record\n";
475 
476  return false;
477  }
478  int i;
479  char* buf = nullptr;
480  size_t s = 0;
481  while ((i = fgetc(f_)) != 'T' && i != 'L' && i >= 0)
482  getline(&buf, &s, f_);
483  if (buf)
484  free(buf);
485  buf = nullptr;
486 
487  if (i == 'L') { //last record put 3 consecutive times starting from end of prev. IOV
488  t1 = t3;
489  for (int i = 0; i < EcalLaserCondTools::nLmes; ++i)
490  t2[i] = t1 + 1;
491  t3 = t1 + 2;
492  return true;
493  }
494 
495  if (i != 'T') {
496  if (verb_ > 1)
497  edm::LogPrint("EcalLaserCondTools") << "No more record or bad line type/marker (getc returned " << i << ")\n";
498 
499  return false;
500  }
501 
503  int n = fscanf(f_, "%d %d", &t1, &t3);
504  for (int i = 0; i < EcalLaserCondTools::nLmes; ++i) {
505  int nn = fscanf(f_, "%d", &t2[i]);
506  if (nn != 1)
507  break;
508  n += nn;
509  }
510 
511  int nnn = fscanf(f_, " ");
512 
513  if (n != (2 + EcalLaserCondTools::nLmes) || nnn != 0)
514  throw cms::Exception("LasCorFile") << "File " << fnames_[ifile_] << " line " << iline_
515  << ": syntax error. Expecting 'T' marker followed by 94 values: "
516  << "t1 t2 t3(lme 1) t3(lme 2) ... t3(lme " << EcalLaserCondTools::nLmes << ")\n";
517 
518  return true;
519 }
void free(void *ptr) noexcept
static constexpr int nLmes
Log< level::Warning, true > LogPrint
std::vector< std::string > fnames_

◆ trim()

void EcalLaserCondTools::FileReader::trim ( )
private

Definition at line 575 of file EcalLaserCondTools.cc.

References HltBtagPostValidation_cff::c.

575  {
576  if (f_ == nullptr)
577  return;
578  bool skipLine = false;
579  int c;
580  while ((c = fgetc(f_)) >= 0 && (c == ' ' || c == '\t' || c == '\n' || c == '#' || skipLine)) {
581  if (c == '#')
582  skipLine = true;
583  if (c == '\n') {
584  ++iline_;
585  skipLine = false;
586  }
587  }
588  ungetc(c, f_);
589 }

Member Data Documentation

◆ f_

FILE* EcalLaserCondTools::FileReader::f_
private

Definition at line 74 of file EcalLaserCondTools.h.

Referenced by nextFile().

◆ fnames_

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

Definition at line 75 of file EcalLaserCondTools.h.

Referenced by nextFile().

◆ ifile_

unsigned EcalLaserCondTools::FileReader::ifile_
private

Definition at line 76 of file EcalLaserCondTools.h.

Referenced by nextFile().

◆ iline_

int EcalLaserCondTools::FileReader::iline_
private

Definition at line 77 of file EcalLaserCondTools.h.

Referenced by nextFile().