CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

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

Definition at line 69 of file EcalLaserCondTools.h.

69 {}

Member Function Documentation

bool EcalLaserCondTools::FileReader::nextFile ( )
private

Definition at line 447 of file EcalLaserCondTools.cc.

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

447  {
448  for (;;) {
449  ++ifile_;
450  if (ifile_ >= fnames_.size()) {
451  if (verb_ > 1)
452  std::cout << "No more correction files.\n";
453 
454  return false;
455  }
456  if (verb_ > 1)
457  std::cout << "Opening file " << fnames_[ifile_] << "\n";
458 
459  f_ = fopen(fnames_[ifile_].c_str(), "r");
460  iline_ = 0;
461  if (f_ == nullptr) {
462  std::cerr << "Failed to open file " << fnames_[ifile_] << ". File skipped!\n";
463  } else {
464  return true;
465  }
466  }
467 }
std::vector< std::string > fnames_
tuple cout
Definition: gather_cfg.py:144
bool EcalLaserCondTools::FileReader::readPs ( DetId rawdetid,
EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr 
)
overridevirtual

Reimplemented from EcalLaserCondTools::CorrReader.

Definition at line 520 of file EcalLaserCondTools.cc.

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

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

Definition at line 469 of file EcalLaserCondTools.cc.

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

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

Definition at line 574 of file EcalLaserCondTools.cc.

References c.

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

Member Data Documentation

FILE* EcalLaserCondTools::FileReader::f_
private

Definition at line 74 of file EcalLaserCondTools.h.

Referenced by nextFile().

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

Definition at line 75 of file EcalLaserCondTools.h.

Referenced by nextFile().

unsigned EcalLaserCondTools::FileReader::ifile_
private

Definition at line 76 of file EcalLaserCondTools.h.

Referenced by nextFile().

int EcalLaserCondTools::FileReader::iline_
private

Definition at line 77 of file EcalLaserCondTools.h.

Referenced by nextFile().