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") {
42 ferr_ = fopen(
"corr_errors.txt",
"w");
43 fprintf(
ferr_,
"#t1\tdetid\tp1\tp2\tp3");
60 if (
mode_ ==
"ascii_file_to_db") {
62 edm::LogPrint(
"EcalLaserCondTools") <<
"ascii_file_to_db mode\n";
65 throw cms::Exception(
"CondDBAccess") <<
"Failed to connect to PoolDBOutputService\n";
70 }
else if (
mode_ ==
"hdf_file_to_db") {
72 }
else if (
mode_ ==
"db_to_ascii_file") {
75 cms::Exception(
"InvalidParam") <<
"Value of parameter mode is not valid. Expecting ascii_file_to_db or read";
82 hid_t
file, space, memspace;
83 hid_t dset_rawid, dset_t2, dset;
92 file = H5Fopen(
fnames_[
ifile].c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
94 dset_rawid = H5Dopen(file,
"cmssw_id", H5P_DEFAULT);
95 space = H5Dget_space(dset_rawid);
96 H5Sget_simple_extent_dims(space, dims,
nullptr);
102 status = H5Dread(dset_rawid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rawid);
104 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
106 H5Dclose(dset_rawid);
109 dset_t2 = H5Dopen(file,
"t2", H5P_DEFAULT);
110 space = H5Dget_space(dset_t2);
111 H5Sget_simple_extent_dims(space, dims,
nullptr);
113 unsigned int nIovs = dims[0];
114 unsigned int nLME = dims[1];
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";
122 int t1[nIovs], t3[nIovs], t2[nIovs][nLME];
126 edm::LogPrint(
"EcalLaserCondTools") <<
" * reading t2 table "
128 status = H5Dread(dset_t2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, t2[0]);
130 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
136 edm::LogPrint(
"EcalLaserCondTools") <<
" * reading t1 table "
138 dset = H5Dopen(file,
"t1", H5P_DEFAULT);
139 status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, t1);
141 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
146 edm::LogPrint(
"EcalLaserCondTools") <<
" * reading t3 table "
148 dset = H5Dopen(file,
"t3", H5P_DEFAULT);
149 status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, t3);
151 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
159 hsize_t iov_dim[1] = {nCrystals};
160 memspace = H5Screate_simple(1, iov_dim,
nullptr);
163 for (
unsigned int iIov =
skipIov_; iIov < nIovs && iIov < unsigned(
nIovs_); ++iIov) {
165 iovStart =
uint64_t(t1[iIov]) << 32;
173 hsize_t
offset[2] = {iIov, 0};
174 hsize_t
count[2] = {1, nCrystals};
176 dset = H5Dopen(file,
"p1", H5P_DEFAULT);
177 space = H5Dget_space(dset);
178 status = H5Sselect_hyperslab(space, H5S_SELECT_SET, offset,
nullptr, count,
nullptr);
180 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
182 status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT, p1);
184 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
189 dset = H5Dopen(file,
"p2", H5P_DEFAULT);
190 space = H5Dget_space(dset);
191 status = H5Sselect_hyperslab(space, H5S_SELECT_SET, offset,
nullptr, count,
nullptr);
193 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
195 status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT, p2);
197 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
202 dset = H5Dopen(file,
"p3", H5P_DEFAULT);
203 space = H5Dget_space(dset);
204 status = H5Sselect_hyperslab(space, H5S_SELECT_SET, offset,
nullptr, count,
nullptr);
206 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
208 status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT, p3);
210 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
214 for (
size_t iXtal = 0; iXtal <
nCrystals; ++iXtal) {
215 DetId detid = rawid[iXtal];
222 if (!std::isfinite(corr.
p1) || !std::isfinite(corr.
p2) || !std::isfinite(corr.
p3) || corr.
p1 <
minP_ ||
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;
238 gettimeofday(&t,
nullptr);
242 <<
"Write IOV " << iIov <<
" starting from " <<
timeToString(iovStart >> 32) <<
"... ";
247 edm::LogPrint(
"EcalLaserCondTools") <<
"Exception catched while writting to cond DB" << e.
what() <<
"\n";
261 int processedIovs = 0;
263 edm::LogPrint(
"EcalLaserCondTools") <<
"Starting filling DB...\n";
277 while (fscanf(
eventList_,
" %1[#]%*[^\n]\n", &c) == 1)
280 int n = fscanf(
eventList_,
"%*d %*d %*d %d%*[^\n]\n", &t);
290 <<
" are not ordered in increased time as required! See line " << iline <<
"\n";
292 throw cms::Exception(
"User") <<
"Found an unexpected t = 0 time value "
293 "in the event list file"
296 bool iovFound =
true;
299 edm::LogPrint(
"EcalLaserCondTools") <<
"Event in same IOV than previous one.\n";
303 while ((iovFound = r.
readTime(t1, t2, t3)) && t3 < t)
307 if (t1 < prevT1 && t3 < prevT3)
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";
322 edm::LogPrint(
"EcalLaserCondTools") <<
"Skipping IOV " << iIov <<
"\n";
325 edm::LogPrint(
"EcalLaserCondTools") <<
"Requested number of IOVs, " <<
nIovs_ <<
", processed.\n";
347 <<
"t3: " << t3 <<
"(" <<
timeToString(t3) <<
")\nt2-t1: ";
355 edm::LogPrint(
"EcalLaserCondTools") <<
"Skipping IOV " << iIov <<
", "
362 edm::LogPrint(
"EcalLaserCondTools") <<
"Skipping IOV " << iIov <<
", "
369 edm::LogPrint(
"EcalLaserCondTools") <<
"Skipping IOV with t1 = 0"
385 constexpr
int ncrystals = 75848;
386 std::set<int> detidList;
387 for (
int i = 0;
i < ncrystals; ++
i) {
393 if (!r.
readPs(detid, corr)) {
394 throw cms::Exception(
"LasCor") <<
"Failed to read " <<
toNth(
i + 1) <<
" crystal correction.\n";
397 std::pair<std::set<int>::iterator,
bool> res = detidList.insert(
int(detid));
401 <<
"Duplicate det id, for IOV " << iIov <<
" t1 = " << t1 <<
" detid = " << int(detid) <<
"\n";
404 if (!std::isfinite(corr.
p1) || !std::isfinite(corr.
p2) || !std::isfinite(corr.
p3) || corr.
p1 <
minP_ ||
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;
419 <<
"p1 = " << corr.
p1 <<
"\t"
420 <<
"p2 = " << corr.
p2 <<
"\t"
421 <<
"p3 = " << corr.
p3 <<
"\n";
431 edm::LogPrint(
"EcalLaserCondTools") <<
"First IOV, extending starting time.\n";
436 gettimeofday(&t,
nullptr);
440 <<
"Write IOV " << iIov <<
" starting from " <<
timeToString(iovStart >> 32) <<
"... ";
443 edm::LogPrint(
"EcalLaserCondTools") <<
"Failed.\nException cathed while writting to cond DB" << e.
what() <<
"\n";
453 edm::LogPrint(
"EcalLaserCondTools") <<
"No more correction files.\n";
472 if ((f_ ==
nullptr || feof(f_)) && !nextFile()) {
481 while ((i = fgetc(f_)) !=
'T' && i !=
'L' && i >= 0)
482 getline(&buf, &s, f_);
497 edm::LogPrint(
"EcalLaserCondTools") <<
"No more record or bad line type/marker (getc returned " << i <<
")\n";
503 int n = fscanf(f_,
"%d %d", &t1, &t3);
505 int nn = fscanf(f_,
"%d", &t2[i]);
511 int nnn = fscanf(f_,
" ");
513 if (n != (2 + EcalLaserCondTools::nLmes) || nnn != 0)
515 <<
": syntax error. Expecting 'T' marker followed by 94 values: "
516 <<
"t1 t2 t3(lme 1) t3(lme 2) ... t3(lme " << EcalLaserCondTools::nLmes <<
")\n";
524 edm::LogPrint(
"EcalLaserCondTools") <<
"Requested to read p1..p3 parameter line while no file is closed.\n";
535 <<
": unexpected line type, '" << (char)i <<
"' while expecting 'P'\n";
538 edm::LogPrint(
"EcalLaserCondTools") <<
"Failed to read p1..p3 parameter line\n";
544 int n = fscanf(f_,
"%d %f %f %f\n", &rawdetid, &corr.
p1, &corr.
p2, &corr.
p3);
550 throw cms::Exception(
"I/O") <<
"Syntax error at line " << iline_ <<
"of file " <<
fnames_[ifile_] <<
" read " << n
552 <<
" raw id" << rawdetid <<
": " << corr.
p1 <<
", " << corr.
p2;
555 constexpr
int ECALID = 3;
556 if (detid.
det() != ECALID)
558 <<
" contains an invalid det ID (detector code is not ECAL!)\n";
562 throw cms::Exception(
"InvalidValue") <<
"Line " << iline_ <<
"of file " << fnames_[ifile_]
563 <<
" contains an invalid det ID (detector code is not ECAL!)\n";
568 throw cms::Exception(
"InvalidValue") <<
"Line " << iline_ <<
"of file " << fnames_[ifile_]
569 <<
" contains an invalid det ID (detector code is not ECAL!)\n";
578 bool skipLine =
false;
580 while ((c = fgetc(f_)) >= 0 && (c ==
' ' || c ==
'\t' || c ==
'\n' || c ==
'#' || skipLine)) {
594 if (n % 100 < 10 || n % 100 > 20) {
617 localtime_r(&t, <);
618 strftime(buf,
sizeof(buf),
"%F %R:%S", <);
619 buf[
sizeof(
buf) - 1] = 0;
630 throw cms::Exception(
"LasCor") <<
"Unexpected number time parameter triplets\n";
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";
638 unsigned t1 = t[0].t1.unixTime();
639 unsigned t3 = t[0].t3.unixTime();
640 fprintf(
fout_,
"T %d\t%d", t1, t3);
646 for (
unsigned i = 0;
i < t.size(); ++
i) {
647 if (t[
i].t1.unixTime() != t1 || t[
i].t3.unixTime() != 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()
653 fprintf(
fout_,
"\t%d", t[
i].t2.unixTime());
665 fprintf(
fout_,
"P %d\t%f\t%f\t%f\n", (
int)detId, corr.
p1, corr.
p2, corr.
p3);
670 for (
int iZ = 1; iZ >= -1; --iZ) {
676 fprintf(
fout_,
"P %d\t%f\t%f\t%f\n", (
int)detId, corr.
p1, corr.
p2, corr.
p3);
int hashedIndex() const
get a compact index for arrays
static const int MIN_IPHI
const edm::EventSetup & c
static void trim(std::string &s)
static bool validDetId(int i, int j)
check if a valid index combination
int iphi() const
get the crystal iphi
bool getData(T &iHolder) const
unsigned nCrystals(unsigned)
void setTime(int hashedIndex, const EcalLaserTimeStamp &value)
unsigned long long Time_t
bool isNewTagRequest(const std::string &recordName)
cond::Time_t beginOfTime() const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
char const * what() const noexceptoverride
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
Log< level::Warning, true > LogPrint
static const int MAX_IPHI
unsigned long long uint64_t
std::vector< EcalLaserTimeStamp > EcalLaserTimeStampMap
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
static const int MAX_IETA
void setValue(uint32_t rawId, const EcalLaserAPDPNpair &value)
const Item & barrel(size_t hashedIndex) const
const Item & endcap(size_t hashedIndex) const
int ietaAbs() const
get the absolute value of the crystal ieta
constexpr Detector det() const
get the detector field from this detid