CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
EcalLaserCondTools Class Reference

#include <EcalLaserCondTools.h>

Inheritance diagram for EcalLaserCondTools:
edm::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Classes

class  CorrReader
 
class  FileReader
 

Public Member Functions

void analyze (const edm::Event &evt, const edm::EventSetup &es) override
 
 EcalLaserCondTools (const edm::ParameterSet &)
 
void from_hdf_to_db ()
 
 ~EcalLaserCondTools () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void dbToAscii (const edm::EventSetup &es)
 
void fillDb (CorrReader &r)
 
void processIov (CorrReader &r, int t1, int t2[nLmes], int t3)
 

Static Private Member Functions

static std::string timeToString (time_t t)
 
static std::string toNth (int n)
 

Private Attributes

edm::Service< cond::service::PoolDBOutputServicedb_
 
FILE * eventList_
 
std::string eventListFileName_
 
FILE * ferr_
 
std::vector< std::string > fnames_
 
FILE * fout_
 
int fromTime_
 
edm::ESGetToken< EcalLaserAPDPNRatios, EcalLaserAPDPNRatiosRcdlaserAPDPNRatiosToken_
 
double maxP_
 
double minP_
 
std::string mode_
 
int nIovs_
 
int skipIov_
 
int toTime_
 
int verb_
 

Static Private Attributes

static constexpr int nLmes = 92
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 24 of file EcalLaserCondTools.h.

Constructor & Destructor Documentation

◆ EcalLaserCondTools()

EcalLaserCondTools::EcalLaserCondTools ( const edm::ParameterSet ps)

Constructor

Parameters
psanalyser configuration

Definition at line 25 of file EcalLaserCondTools.cc.

References edm::EDConsumerBase::esConsumes(), eventList_, eventListFileName_, Exception, ferr_, laserAPDPNRatiosToken_, and mode_.

26  : fout_(nullptr),
27  eventList_(nullptr),
28  eventListFileName_(ps.getParameter<std::string>("eventListFile")),
29  verb_(ps.getParameter<int>("verbosity")),
30  mode_(ps.getParameter<std::string>("mode")),
31  fnames_(ps.getParameter<std::vector<std::string> >("inputFiles")),
32  skipIov_(ps.getParameter<int>("skipIov")),
33  nIovs_(ps.getParameter<int>("nIovs")),
34  fromTime_(ps.getParameter<int>("fromTime")),
35  toTime_(ps.getParameter<int>("toTime")),
36  minP_(ps.getParameter<double>("transparencyMin")),
37  maxP_(ps.getParameter<double>("transparencyMax")) {
38  if (mode_ == "db_to_ascii_file") {
40  }
41 
42  ferr_ = fopen("corr_errors.txt", "w");
43  fprintf(ferr_, "#t1\tdetid\tp1\tp2\tp3");
44 
45  if (!eventListFileName_.empty()) {
46  eventList_ = fopen(eventListFileName_.c_str(), "r");
47  if (eventList_ == nullptr)
48  throw cms::Exception("User") << "Failed to open file " << eventListFileName_ << "\n";
49  }
50 }
std::vector< std::string > fnames_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::string eventListFileName_
edm::ESGetToken< EcalLaserAPDPNRatios, EcalLaserAPDPNRatiosRcd > laserAPDPNRatiosToken_

◆ ~EcalLaserCondTools()

EcalLaserCondTools::~EcalLaserCondTools ( )
override

Destructor

Definition at line 52 of file EcalLaserCondTools.cc.

References ferr_, and fout_.

52  {
53  if (ferr_)
54  fclose(ferr_);
55  if (fout_)
56  fclose(fout_);
57 }

Member Function Documentation

◆ analyze()

void EcalLaserCondTools::analyze ( const edm::Event evt,
const edm::EventSetup es 
)
overridevirtual

Called by CMSSW event loop

Parameters
evtthe event
esevents setup

Implements edm::one::EDAnalyzerBase.

Definition at line 59 of file EcalLaserCondTools.cc.

References db_, dbToAscii(), Exception, fillDb(), fnames_, from_hdf_to_db(), edm::Service< T >::isAvailable(), mode_, EcalLaserCondTools::CorrReader::setVerbosity(), and verb_.

59  {
60  if (mode_ == "ascii_file_to_db") {
61  if (verb_ > 2)
62  edm::LogPrint("EcalLaserCondTools") << "ascii_file_to_db mode\n";
63 
64  if (!db_.isAvailable()) {
65  throw cms::Exception("CondDBAccess") << "Failed to connect to PoolDBOutputService\n";
66  }
67  FileReader corrReader(fnames_);
68  corrReader.setVerbosity(verb_);
69  fillDb(corrReader);
70  } else if (mode_ == "hdf_file_to_db") {
72  } else if (mode_ == "db_to_ascii_file") {
73  dbToAscii(es);
74  } else {
75  cms::Exception("InvalidParam") << "Value of parameter mode is not valid. Expecting ascii_file_to_db or read";
76  }
77 }
std::vector< std::string > fnames_
void fillDb(CorrReader &r)
edm::Service< cond::service::PoolDBOutputService > db_
void dbToAscii(const edm::EventSetup &es)
Log< level::Warning, true > LogPrint
bool isAvailable() const
Definition: Service.h:40

◆ dbToAscii()

void EcalLaserCondTools::dbToAscii ( const edm::EventSetup es)
private

Definition at line 623 of file EcalLaserCondTools.cc.

References alignCSCRings::corr, hcalRecHitTable_cff::detId, Exception, fout_, edm::EventSetup::getData(), mps_fire::i, hcalRecHitTable_cff::ieta, hcalRecHitTable_cff::iphi, EEDetId::IX_MAX, EEDetId::IX_MIN, EEDetId::IY_MAX, EEDetId::IY_MIN, laserAPDPNRatiosToken_, EBDetId::MAX_IETA, EBDetId::MAX_IPHI, EBDetId::MIN_IPHI, nLmes, AlCaHLTBitMon_ParallelJobs::p, submitPVValidationJobs::t, RandomServiceHelper::t1, RandomServiceHelper::t2, RandomServiceHelper::t3, timeToString(), EBDetId::validDetId(), EEDetId::validDetId(), and verb_.

Referenced by analyze().

623  {
624  const auto& laserAPDPNRatios = es.getData(laserAPDPNRatiosToken_);
625 
626  const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap& p = laserAPDPNRatios.getLaserMap();
627  const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& t = laserAPDPNRatios.getTimeMap();
628 
629  if (t.size() != EcalLaserCondTools::nLmes)
630  throw cms::Exception("LasCor") << "Unexpected number time parameter triplets\n";
631 
632  if (fout_ == nullptr) {
633  fout_ = fopen("corr_dump.txt", "w");
634  if (fout_ == nullptr)
635  throw cms::Exception("LasCor") << "Failed to create file corr_dump.txt\n";
636  }
637 
638  unsigned t1 = t[0].t1.unixTime();
639  unsigned t3 = t[0].t3.unixTime();
640  fprintf(fout_, "T %d\t%d", t1, t3);
641 
642  if (verb_)
643  edm::LogPrint("EcalLaserCondTools") << "Processing IOV " << t1 << " - " << t3 << "(" << timeToString(t1) << " - "
644  << timeToString(t3) << "\n";
645 
646  for (unsigned i = 0; i < t.size(); ++i) {
647  if (t[i].t1.unixTime() != t1 || t[i].t3.unixTime() != t3) {
648  throw cms::Exception("LasCor") << "Inconsitency in t1, t3: "
649  << "t1(lme 1) =" << t1 << ", t1(lme " << (i + 1) << ") = " << t[i].t1.unixTime()
650  << ", t3(lme 1) =" << t3 << ", t3(lme " << (i + 1) << ") = " << t[i].t3.unixTime()
651  << "\n";
652  }
653  fprintf(fout_, "\t%d", t[i].t2.unixTime());
654  }
655  fputc('\n', fout_);
656  fflush(fout_);
657 
658  for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
659  if (ieta == 0)
660  continue;
661  for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
662  if (EBDetId::validDetId(ieta, iphi)) {
664  EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr = p.barrel(detId.hashedIndex());
665  fprintf(fout_, "P %d\t%f\t%f\t%f\n", (int)detId, corr.p1, corr.p2, corr.p3);
666  }
667  }
668  }
669 
670  for (int iZ = 1; iZ >= -1; --iZ) {
671  for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
672  for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
673  if (EEDetId::validDetId(iX, iY, iZ)) {
674  EEDetId detId(iX, iY, iZ);
675  EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr = p.endcap(detId.hashedIndex());
676  fprintf(fout_, "P %d\t%f\t%f\t%f\n", (int)detId, corr.p1, corr.p2, corr.p3);
677  }
678  }
679  }
680  }
681 }
static const int MIN_IPHI
Definition: EBDetId.h:135
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
static std::string timeToString(time_t t)
static const int IX_MIN
Definition: EEDetId.h:290
static const int IY_MIN
Definition: EEDetId.h:294
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
dictionary corr
static constexpr int nLmes
Log< level::Warning, true > LogPrint
static const int IX_MAX
Definition: EEDetId.h:298
static const int MAX_IPHI
Definition: EBDetId.h:137
std::vector< EcalLaserTimeStamp > EcalLaserTimeStampMap
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static const int MAX_IETA
Definition: EBDetId.h:136
edm::ESGetToken< EcalLaserAPDPNRatios, EcalLaserAPDPNRatiosRcd > laserAPDPNRatiosToken_
static const int IY_MAX
Definition: EEDetId.h:302

◆ fillDb()

void EcalLaserCondTools::fillDb ( CorrReader r)
private

Definition at line 259 of file EcalLaserCondTools.cc.

References HltBtagPostValidation_cff::c, eventList_, eventListFileName_, Exception, ntuplemaker::iline, dqmiodumpmetadata::n, nIovs_, nLmes, processIov(), alignCSCRings::r, skipIov_, submitPVValidationJobs::t, RandomServiceHelper::t1, RandomServiceHelper::t2, RandomServiceHelper::t3, timeToString(), and verb_.

Referenced by analyze().

259  {
260  int iIov = 0;
261  int processedIovs = 0;
262  if (verb_ > 2)
263  edm::LogPrint("EcalLaserCondTools") << "Starting filling DB...\n";
264  int t1 = 0;
265  int t3 = 0;
266  int t2[nLmes];
267 
268  int prevT1 = 0;
269  int prevT3 = 0;
270  int prevT = 0;
271  int t = 0;
272  if (eventList_) {
273  int iline = 0;
274  while (!feof(eventList_)) {
275  //skips comment lines:
276  char c[2];
277  while (fscanf(eventList_, " %1[#]%*[^\n]\n", &c[0]) == 1)
278  ++iline;
279 
280  int n = fscanf(eventList_, "%*d %*d %*d %d%*[^\n]\n", &t);
281  if (verb_ > 1)
282  edm::LogPrint("EcalLaserCondTools") << "Event time: t = " << t << ", " << timeToString(t) << "\n";
283  ++iline;
284  if (n != 1)
285  throw cms::Exception("User") << "Syntax error in event list file " << eventListFileName_ << " at line " << iline
286  << " " << n << " "
287  << ".\n";
288  if (t < prevT)
289  throw cms::Exception("User") << "Events in the event list file " << eventListFileName_
290  << " are not ordered in increased time as required! See line " << iline << "\n";
291  if (t == 0)
292  throw cms::Exception("User") << "Found an unexpected t = 0 time value "
293  "in the event list file"
294  << eventListFileName_ << " at line " << iline << "!\n";
295  //Look for IOV:
296  bool iovFound = true;
297  if (t <= t3) { //IOV already inserted for previous event.
298  if (verb_ > 1)
299  edm::LogPrint("EcalLaserCondTools") << "Event in same IOV than previous one.\n";
300  continue;
301  }
302 
303  while ((iovFound = r.readTime(t1, t2, t3)) && t3 < t) /*NOP*/
304  ;
305 
306  if (iovFound) {
307  if (t1 < prevT1 && t3 < prevT3)
308  throw cms::Exception("User")
309  << "IOVs in the correction ascii file are not ordered in increased time as required!\n";
310  else if (t1 < prevT1 || t3 < prevT3)
311  throw cms::Exception("User") << "Found interleaved IOVs in the correction ascii file!\n";
312  processIov(r, t1, t2, t3);
313  } else {
314  edm::LogPrint("EcalLaserCondTools") << "Warning: event beyond last IOV t3. Event time: " << timeToString(t)
315  << ". Last IOV t3: " << timeToString(t3) << "\n";
316  }
317  }
318  } else
319  while (r.readTime(t1, t2, t3)) {
320  ++iIov;
321  if (iIov <= skipIov_) {
322  edm::LogPrint("EcalLaserCondTools") << "Skipping IOV " << iIov << "\n";
323  continue;
324  } else if (processedIovs >= nIovs_ && nIovs_ >= 0) {
325  edm::LogPrint("EcalLaserCondTools") << "Requested number of IOVs, " << nIovs_ << ", processed.\n";
326  return;
327  } else {
328  processIov(r, t1, t2, t3);
329  ++processedIovs;
330  }
331  }
332 }
static std::string timeToString(time_t t)
void processIov(CorrReader &r, int t1, int t2[nLmes], int t3)
static constexpr int nLmes
std::string eventListFileName_
Log< level::Warning, true > LogPrint

◆ from_hdf_to_db()

void EcalLaserCondTools::from_hdf_to_db ( )

Definition at line 79 of file EcalLaserCondTools.cc.

References cms::cuda::assert(), alignCSCRings::corr, submitPVResolutionJobs::count, db_, MillePedeFileConverter_cfg::e, Exception, ferr_, geometryDiff::file, fnames_, compare_using_db::ifile, maxP_, minP_, ecaldqm::nCrystals(), nIovs_, nLmes, hltrates_dqm_sourceclient-live_cfg::offset, LaserDQM_cfg::p1, SiStripOfflineCRack_cfg::p2, chargedHadronTrackResolutionFilter_cfi::p3, EcalLaserAPDPNRatios::setTime(), EcalLaserAPDPNRatios::setValue(), skipIov_, mps_update::status, submitPVValidationJobs::t, RandomServiceHelper::t1, RandomServiceHelper::t2, RandomServiceHelper::t3, timeToString(), verb_, and cond::service::PoolDBOutputService::writeOneIOV().

Referenced by analyze().

79  {
80  cond::Time_t iovStart = 0;
81 
82  hid_t file, space, memspace;
83  hid_t dset_rawid, dset_t2, dset;
84 
85  hsize_t dims[2] = {};
86 
87  for (unsigned int ifile = 0; ifile < fnames_.size(); ++ifile) {
88  if (verb_) {
89  edm::LogPrint("EcalLaserCondTools") << " - converting file: " << fnames_[ifile] << "\n";
90  }
91 
92  file = H5Fopen(fnames_[ifile].c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
93 
94  dset_rawid = H5Dopen(file, "cmssw_id", H5P_DEFAULT);
95  space = H5Dget_space(dset_rawid);
96  H5Sget_simple_extent_dims(space, dims, nullptr);
97 
98  unsigned int nCrystals = dims[0];
99  int rawid[nCrystals];
100  herr_t status;
101 
102  status = H5Dread(dset_rawid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rawid);
103  if (status < 0)
104  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
105 
106  H5Dclose(dset_rawid);
107  H5Sclose(space);
108 
109  dset_t2 = H5Dopen(file, "t2", H5P_DEFAULT);
110  space = H5Dget_space(dset_t2);
111  H5Sget_simple_extent_dims(space, dims, nullptr);
112 
113  unsigned int nIovs = dims[0];
114  unsigned int nLME = dims[1];
115 
116  if (verb_) {
117  edm::LogPrint("EcalLaserCondTools") << "Number of crystals: " << nCrystals << "\n";
118  edm::LogPrint("EcalLaserCondTools") << "Number of IOVs: " << nIovs << "\n";
119  edm::LogPrint("EcalLaserCondTools") << "Number of Monitoring regions: " << nLME << "\n";
120  }
121 
122  int t1[nIovs], t3[nIovs], t2[nIovs][nLME];
123 
124  // -- reading data (cmsswid, t2, t1, t3, p2, p1, p3
125  if (verb_ > 1)
126  edm::LogPrint("EcalLaserCondTools") << " * reading t2 table "
127  << "\n";
128  status = H5Dread(dset_t2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, t2[0]);
129  if (status < 0)
130  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
131 
132  H5Dclose(dset_t2);
133  //H5Sclose(space);
134 
135  if (verb_ > 1)
136  edm::LogPrint("EcalLaserCondTools") << " * reading t1 table "
137  << "\n";
138  dset = H5Dopen(file, "t1", H5P_DEFAULT);
139  status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, t1);
140  if (status < 0)
141  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
142 
143  H5Dclose(dset);
144 
145  if (verb_ > 1)
146  edm::LogPrint("EcalLaserCondTools") << " * reading t3 table "
147  << "\n";
148  dset = H5Dopen(file, "t3", H5P_DEFAULT);
149  status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, t3);
150  if (status < 0)
151  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
152 
153  H5Dclose(dset);
154 
156 
157  // read crystal info IOV by IOV (otherwise too large)
158  float p1[nCrystals], p2[nCrystals], p3[nCrystals];
159  hsize_t iov_dim[1] = {nCrystals};
160  memspace = H5Screate_simple(1, iov_dim, nullptr);
161 
162  EcalLaserAPDPNRatios corrSet;
163  for (unsigned int iIov = skipIov_; iIov < nIovs && iIov < unsigned(nIovs_); ++iIov) {
165  iovStart = uint64_t(t1[iIov]) << 32;
166  for (size_t iLme = 0; iLme < EcalLaserCondTools::nLmes; ++iLme) {
167  t.t1 = edm::Timestamp(uint64_t(t1[iIov]) << 32);
168  t.t2 = edm::Timestamp(uint64_t(t2[iIov][iLme]) << 32);
169  t.t3 = edm::Timestamp(uint64_t(t3[iIov]) << 32);
170  corrSet.setTime(iLme, t);
171  }
172 
173  hsize_t offset[2] = {iIov, 0}; // shift rows: iIov, columns: 0
174  hsize_t count[2] = {1, nCrystals}; // 1 row, nXtal columns
175 
176  dset = H5Dopen(file, "p1", H5P_DEFAULT);
177  space = H5Dget_space(dset);
178  status = H5Sselect_hyperslab(space, H5S_SELECT_SET, offset, nullptr, count, nullptr);
179  if (status < 0)
180  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
181 
182  status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT, p1);
183  if (status < 0)
184  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
185 
186  H5Dclose(dset);
187  //H5Sclose(space);
188 
189  dset = H5Dopen(file, "p2", H5P_DEFAULT);
190  space = H5Dget_space(dset);
191  status = H5Sselect_hyperslab(space, H5S_SELECT_SET, offset, nullptr, count, nullptr);
192  if (status < 0)
193  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
194 
195  status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT, p2);
196  if (status < 0)
197  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
198 
199  H5Dclose(dset);
200  // H5Sclose(space);
201 
202  dset = H5Dopen(file, "p3", H5P_DEFAULT);
203  space = H5Dget_space(dset);
204  status = H5Sselect_hyperslab(space, H5S_SELECT_SET, offset, nullptr, count, nullptr);
205  if (status < 0)
206  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
207 
208  status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT, p3);
209  if (status < 0)
210  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
211  H5Dclose(dset);
212  H5Sclose(space);
213 
214  for (size_t iXtal = 0; iXtal < nCrystals; ++iXtal) {
215  DetId detid = rawid[iXtal];
216 
218  corr.p1 = p1[iXtal];
219  corr.p2 = p2[iXtal];
220  corr.p3 = p3[iXtal];
221 
222  if (!std::isfinite(corr.p1) || !std::isfinite(corr.p2) || !std::isfinite(corr.p3) || corr.p1 < minP_ ||
223  corr.p1 > maxP_ || corr.p2 < minP_ || corr.p2 > maxP_ || corr.p3 < minP_ || corr.p3 > maxP_) {
224  fprintf(ferr_, "%d %d %f %f %f\n", t1[iIov], (int)detid, corr.p1, corr.p2, corr.p3);
225  corr.p1 = corr.p2 = corr.p3 = 1;
226  }
227  corrSet.setValue((int)detid, corr);
228  }
229 
230  try {
231  //Write correction set in DB (one IOV):
232  //if (db_->isNewTagRequest("EcalLaserAPDPNRatiosRcd")) {
233  // if (verb_)
234  // edm::LogPrint("EcalLaserCondTools") << "First IOV, extending starting time.\n";
235  // iovStart = db_->beginOfTime();
236  //}
237  timeval t;
238  gettimeofday(&t, nullptr);
239  if (verb_ > 1)
240  edm::LogPrint("EcalLaserCondTools")
241  << "[" << timeToString(t.tv_sec) << "] "
242  << "Write IOV " << iIov << " starting from " << timeToString(iovStart >> 32) << "... ";
243  db_->writeOneIOV(corrSet, iovStart, "EcalLaserAPDPNRatiosRcd");
244  } catch (const cms::Exception& e) {
245  if (verb_ > 1)
246  edm::LogPrint("EcalLaserCondTools") << "Failed. ";
247  edm::LogPrint("EcalLaserCondTools") << "Exception catched while writting to cond DB" << e.what() << "\n";
248  }
249  if (verb_ > 1)
250  edm::LogPrint("EcalLaserCondTools") << "Suceeded.\n";
251 
252  } // loop over IOVs
253 
254  H5Sclose(memspace);
255  H5Fclose(file);
256  } // loop over input files
257 }
std::vector< std::string > fnames_
static std::string timeToString(time_t t)
edm::Service< cond::service::PoolDBOutputService > db_
assert(be >=bs)
unsigned nCrystals(unsigned)
void setTime(int hashedIndex, const EcalLaserTimeStamp &value)
unsigned long long Time_t
Definition: Time.h:14
dictionary corr
static constexpr int nLmes
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
Log< level::Warning, true > LogPrint
Definition: DetId.h:17
unsigned long long uint64_t
Definition: Time.h:13
void setValue(uint32_t rawId, const EcalLaserAPDPNpair &value)

◆ processIov()

void EcalLaserCondTools::processIov ( CorrReader r,
int  t1,
int  t2[nLmes],
int  t3 
)
private

Definition at line 334 of file EcalLaserCondTools.cc.

References cond::service::PoolDBOutputService::beginOfTime(), alignCSCRings::corr, db_, MillePedeFileConverter_cfg::e, EcalBarrel, EcalEndcap, Exception, ferr_, fromTime_, mps_fire::i, createfilelist::int, cond::service::PoolDBOutputService::isNewTagRequest(), maxP_, minP_, nLmes, alignCSCRings::r, EcalLaserAPDPNRatios::setTime(), EcalLaserAPDPNRatios::setValue(), DetId::subdetId(), submitPVValidationJobs::t, RandomServiceHelper::t1, RandomServiceHelper::t2, RandomServiceHelper::t3, timeToString(), toNth(), toTime_, verb_, and cond::service::PoolDBOutputService::writeOneIOV().

Referenced by fillDb().

334  {
335  static int iIov = 0;
336  ++iIov;
337 
338  // FILE* fdebug = 0;
339  // if(i==) fdebug = fopen("debug.txt", "w");
340 
341  // if(iIov <= skipIov_) { std::cout << "Skipping IOV " << iIov << "\n"; return; }
342 
343  cond::Time_t iovStart = 0;
344 
345  if (verb_ > 1) {
346  edm::LogPrint("EcalLaserCondTools") << "t1:" << t1 << "(" << timeToString(t1) << ") \n"
347  << "t3: " << t3 << "(" << timeToString(t3) << ")\nt2-t1: ";
348  for (int i = 0; i < EcalLaserCondTools::nLmes; ++i) {
349  edm::LogPrint("EcalLaserCondTools") << t2[i] - t1 << "\t";
350  }
351 
352  edm::LogPrint("EcalLaserCondTools") << "\n";
353  }
354  if (t1 < fromTime_) {
355  edm::LogPrint("EcalLaserCondTools") << "Skipping IOV " << iIov << ", "
356  << ", which is before 'fromTime'," << timeToString(fromTime_) << "("
357  << fromTime_ << ").\n";
358  return;
359  }
360 
361  if (toTime_ != -1 && t3 < toTime_) {
362  edm::LogPrint("EcalLaserCondTools") << "Skipping IOV " << iIov << ", "
363  << ", which is beyond 'toTime'," << timeToString(toTime_) << "(" << toTime_
364  << ").\n";
365  return;
366  }
367 
368  if (t1 == 0) {
369  edm::LogPrint("EcalLaserCondTools") << "Skipping IOV with t1 = 0"
370  << "\n";
371  return;
372  }
373 
374  EcalLaserAPDPNRatios corrSet;
375 
377  iovStart = uint64_t(t1) << 32;
378  for (size_t i = 0; i < EcalLaserCondTools::nLmes; ++i) {
379  t.t1 = edm::Timestamp(uint64_t(t1) << 32);
380  t.t2 = edm::Timestamp(uint64_t(t2[i]) << 32);
381  t.t3 = edm::Timestamp(uint64_t(t3) << 32);
382  corrSet.setTime(i, t);
383  }
384 
385  constexpr int ncrystals = 75848;
386  std::set<int> detidList;
387  for (int i = 0; i < ncrystals; ++i) {
388  DetId detid;
389  //EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr = {0, 0, 0};
391  if (verb_ > 2)
392  edm::LogPrint("EcalLaserCondTools") << "Reading " << toNth(i + 1) << " crystal\n";
393  if (!r.readPs(detid, corr)) {
394  throw cms::Exception("LasCor") << "Failed to read " << toNth(i + 1) << " crystal correction.\n";
395  }
396 
397  std::pair<std::set<int>::iterator, bool> res = detidList.insert(int(detid));
398 
399  if (!res.second) { //detid already processed
400  edm::LogPrint("EcalLaserCondTools")
401  << "Duplicate det id, for IOV " << iIov << " t1 = " << t1 << " detid = " << int(detid) << "\n";
402  }
403 
404  if (!std::isfinite(corr.p1) || !std::isfinite(corr.p2) || !std::isfinite(corr.p3) || corr.p1 < minP_ ||
405  corr.p1 > maxP_ || corr.p2 < minP_ || corr.p2 > maxP_ || corr.p3 < minP_ || corr.p3 > maxP_) {
406  fprintf(ferr_, "%d %d %f %f %f\n", t1, (int)detid, corr.p1, corr.p2, corr.p3);
407  corr.p1 = corr.p2 = corr.p3 = 1;
408  }
409 
410  if (verb_ > 2) {
411  if (detid.subdetId() == EcalBarrel) {
412  edm::LogPrint("EcalLaserCondTools") << EBDetId(detid);
413  } else if (detid.subdetId() == EcalEndcap) {
414  edm::LogPrint("EcalLaserCondTools") << EEDetId(detid);
415  } else {
416  edm::LogPrint("EcalLaserCondTools") << (int)detid;
417  }
418  edm::LogPrint("EcalLaserCondTools") << ": "
419  << "p1 = " << corr.p1 << "\t"
420  << "p2 = " << corr.p2 << "\t"
421  << "p3 = " << corr.p3 << "\n";
422  }
423 
424  corrSet.setValue((int)detid, corr);
425  }
426 
427  try {
428  //Write correction set in DB (one IOV):
429  if (db_->isNewTagRequest("EcalLaserAPDPNRatiosRcd")) {
430  if (verb_)
431  edm::LogPrint("EcalLaserCondTools") << "First IOV, extending starting time.\n";
432 
433  iovStart = db_->beginOfTime();
434  }
435  timeval t;
436  gettimeofday(&t, nullptr);
437  if (verb_ > 1)
438  edm::LogPrint("EcalLaserCondTools")
439  << "[" << timeToString(t.tv_sec) << "] "
440  << "Write IOV " << iIov << " starting from " << timeToString(iovStart >> 32) << "... ";
441  db_->writeOneIOV(corrSet, iovStart, "EcalLaserAPDPNRatiosRcd");
442  } catch (const cms::Exception& e) {
443  edm::LogPrint("EcalLaserCondTools") << "Failed.\nException cathed while writting to cond DB" << e.what() << "\n";
444  }
445  edm::LogPrint("EcalLaserCondTools") << "Suceeded.\n";
446 }
static std::string timeToString(time_t t)
edm::Service< cond::service::PoolDBOutputService > db_
Definition: Electron.h:6
void setTime(int hashedIndex, const EcalLaserTimeStamp &value)
unsigned long long Time_t
Definition: Time.h:14
dictionary corr
bool isNewTagRequest(const std::string &recordName)
static constexpr int nLmes
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Log< level::Warning, true > LogPrint
Definition: DetId.h:17
unsigned long long uint64_t
Definition: Time.h:13
void setValue(uint32_t rawId, const EcalLaserAPDPNpair &value)
static std::string toNth(int n)

◆ timeToString()

std::string EcalLaserCondTools::timeToString ( time_t  t)
staticprivate

Definition at line 614 of file EcalLaserCondTools.cc.

References visDQMUpload::buf, AlCaHLTBitMon_QueryRunRegistry::string, and submitPVValidationJobs::t.

Referenced by dbToAscii(), fillDb(), from_hdf_to_db(), and processIov().

614  {
615  char buf[256];
616  struct tm lt;
617  localtime_r(&t, &lt);
618  strftime(buf, sizeof(buf), "%F %R:%S", &lt);
619  buf[sizeof(buf) - 1] = 0;
620  return std::string(buf);
621 }

◆ toNth()

std::string EcalLaserCondTools::toNth ( int  n)
staticprivate

Definition at line 591 of file EcalLaserCondTools.cc.

References dqmiodumpmetadata::n, and alignCSCRings::s.

Referenced by processIov().

591  {
592  std::stringstream s;
593  s << n;
594  if (n % 100 < 10 || n % 100 > 20) {
595  switch (n % 10) {
596  case 1:
597  s << "st";
598  break;
599  case 2:
600  s << "nd";
601  break;
602  case 3:
603  s << "rd";
604  break;
605  default:
606  s << "th";
607  }
608  } else {
609  s << "th";
610  }
611  return s.str();
612 }

Member Data Documentation

◆ db_

edm::Service<cond::service::PoolDBOutputService> EcalLaserCondTools::db_
private

Definition at line 94 of file EcalLaserCondTools.h.

Referenced by analyze(), from_hdf_to_db(), and processIov().

◆ eventList_

FILE* EcalLaserCondTools::eventList_
private

Definition at line 89 of file EcalLaserCondTools.h.

Referenced by EcalLaserCondTools(), and fillDb().

◆ eventListFileName_

std::string EcalLaserCondTools::eventListFileName_
private

Definition at line 90 of file EcalLaserCondTools.h.

Referenced by EcalLaserCondTools(), and fillDb().

◆ ferr_

FILE* EcalLaserCondTools::ferr_
private

◆ fnames_

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

◆ fout_

FILE* EcalLaserCondTools::fout_
private

Definition at line 88 of file EcalLaserCondTools.h.

Referenced by dbToAscii(), and ~EcalLaserCondTools().

◆ fromTime_

int EcalLaserCondTools::fromTime_
private

Definition at line 97 of file EcalLaserCondTools.h.

Referenced by processIov().

◆ laserAPDPNRatiosToken_

edm::ESGetToken<EcalLaserAPDPNRatios, EcalLaserAPDPNRatiosRcd> EcalLaserCondTools::laserAPDPNRatiosToken_
private

Definition at line 87 of file EcalLaserCondTools.h.

Referenced by dbToAscii(), and EcalLaserCondTools().

◆ maxP_

double EcalLaserCondTools::maxP_
private

Definition at line 99 of file EcalLaserCondTools.h.

Referenced by from_hdf_to_db(), and processIov().

◆ minP_

double EcalLaserCondTools::minP_
private

Definition at line 99 of file EcalLaserCondTools.h.

Referenced by from_hdf_to_db(), and processIov().

◆ mode_

std::string EcalLaserCondTools::mode_
private

Definition at line 92 of file EcalLaserCondTools.h.

Referenced by analyze(), and EcalLaserCondTools().

◆ nIovs_

int EcalLaserCondTools::nIovs_
private

Definition at line 96 of file EcalLaserCondTools.h.

Referenced by fillDb(), and from_hdf_to_db().

◆ nLmes

constexpr int EcalLaserCondTools::nLmes = 92
staticprivate

Number of extended laser monitoring regions

Definition at line 29 of file EcalLaserCondTools.h.

Referenced by dbToAscii(), fillDb(), from_hdf_to_db(), processIov(), and EcalLaserCondTools::FileReader::readTime().

◆ skipIov_

int EcalLaserCondTools::skipIov_
private

Definition at line 95 of file EcalLaserCondTools.h.

Referenced by fillDb(), and from_hdf_to_db().

◆ toTime_

int EcalLaserCondTools::toTime_
private

Definition at line 98 of file EcalLaserCondTools.h.

Referenced by processIov().

◆ verb_

int EcalLaserCondTools::verb_
private