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

Constructor & Destructor Documentation

◆ FileReader()

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

Definition at line 65 of file EcalLaserCondTools.h.

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

◆ ~FileReader()

EcalLaserCondTools::FileReader::~FileReader ( )
inlineoverride

Definition at line 68 of file EcalLaserCondTools.h.

68 {}

Member Function Documentation

◆ nextFile()

bool EcalLaserCondTools::FileReader::nextFile ( )
private

Definition at line 445 of file EcalLaserCondTools.cc.

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

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 518 of file EcalLaserCondTools.cc.

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

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 467 of file EcalLaserCondTools.cc.

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

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 572 of file EcalLaserCondTools.cc.

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

References c.

Member Data Documentation

◆ f_

FILE* EcalLaserCondTools::FileReader::f_
private

Definition at line 73 of file EcalLaserCondTools.h.

Referenced by nextFile().

◆ fnames_

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

Definition at line 74 of file EcalLaserCondTools.h.

Referenced by nextFile().

◆ ifile_

unsigned EcalLaserCondTools::FileReader::ifile_
private

Definition at line 75 of file EcalLaserCondTools.h.

Referenced by nextFile().

◆ iline_

int EcalLaserCondTools::FileReader::iline_
private

Definition at line 76 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:445
EcalLaserCondTools::FileReader::ifile_
unsigned ifile_
Definition: EcalLaserCondTools.h:75
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:73
alignCSCRings.corr
dictionary corr
Definition: alignCSCRings.py:124
EcalLaserCondTools::CorrReader::verb_
int verb_
Definition: EcalLaserCondTools.h:60
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
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:74
Exception
Definition: hltDiff.cc:245
EcalLaserCondTools::FileReader::trim
void trim()
Definition: EcalLaserCondTools.cc:572
EEDetId::validDetId
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
cms::Exception
Definition: Exception.h:70
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
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:76