29 eventListFileName_(ps.getParameter<
std::
string>(
"eventListFile")),
30 verb_(ps.getParameter<
int>(
"verbosity")),
31 mode_(ps.getParameter<
std::
string>(
"mode")),
33 skipIov_(ps.getParameter<
int>(
"skipIov")),
34 nIovs_(ps.getParameter<
int>(
"nIovs")),
35 fromTime_(ps.getParameter<
int>(
"fromTime")),
36 toTime_(ps.getParameter<
int>(
"toTime")),
37 minP_(ps.getParameter<double>(
"transparencyMin")),
38 maxP_(ps.getParameter<double>(
"transparencyMax")) {
39 ferr_ = fopen(
"corr_errors.txt",
"w");
40 fprintf(
ferr_,
"#t1\tdetid\tp1\tp2\tp3");
57 static bool done =
false;
59 if (
done && (
mode_ ==
"ascii_file_to_db" ||
mode_ ==
"hdf_file_to_db")) {
63 if (
mode_ ==
"ascii_file_to_db") {
68 throw cms::Exception(
"CondDBAccess") <<
"Failed to connect to PoolDBOutputService\n";
73 }
else if (
mode_ ==
"hdf_file_to_db") {
75 }
else if (
mode_ ==
"db_to_ascii_file") {
78 cms::Exception(
"InvalidParam") <<
"Value of parameter mode is not valid. Expecting ascii_file_to_db or read";
85 hid_t
file, space, memspace;
86 hid_t dset_rawid, dset_t2, dset;
97 dset_rawid = H5Dopen(
file,
"cmssw_id", H5P_DEFAULT);
98 space = H5Dget_space(dset_rawid);
99 H5Sget_simple_extent_dims(space, dims,
nullptr);
105 status = H5Dread(dset_rawid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rawid);
107 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
109 H5Dclose(dset_rawid);
112 dset_t2 = H5Dopen(
file,
"t2", H5P_DEFAULT);
113 space = H5Dget_space(dset_t2);
114 H5Sget_simple_extent_dims(space, dims,
nullptr);
116 unsigned int nIovs = dims[0];
117 unsigned int nLME = dims[1];
121 std::cout <<
"Number of IOVs: " << nIovs <<
"\n";
122 std::cout <<
"Number of Monitoring regions: " << nLME <<
"\n";
125 int t1[nIovs],
t3[nIovs],
t2[nIovs][nLME];
131 status = H5Dread(dset_t2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
t2[0]);
133 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
141 dset = H5Dopen(
file,
"t1", H5P_DEFAULT);
142 status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
t1);
144 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
151 dset = H5Dopen(
file,
"t3", H5P_DEFAULT);
152 status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
t3);
154 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
163 memspace = H5Screate_simple(1, iov_dim,
nullptr);
165 auto corrSet = std::make_unique<EcalLaserAPDPNRatios>();
166 for (
unsigned int iIov =
skipIov_; iIov < nIovs && iIov < unsigned(
nIovs_); ++iIov) {
173 corrSet->setTime(iLme,
t);
176 hsize_t
offset[2] = {iIov, 0};
179 dset = H5Dopen(
file,
"p1", H5P_DEFAULT);
180 space = H5Dget_space(dset);
181 status = H5Sselect_hyperslab(space, H5S_SELECT_SET,
offset,
nullptr,
count,
nullptr);
183 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
185 status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT,
p1);
187 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
192 dset = H5Dopen(
file,
"p2", H5P_DEFAULT);
193 space = H5Dget_space(dset);
194 status = H5Sselect_hyperslab(space, H5S_SELECT_SET,
offset,
nullptr,
count,
nullptr);
196 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
198 status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT,
p2);
200 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
205 dset = H5Dopen(
file,
"p3", H5P_DEFAULT);
206 space = H5Dget_space(dset);
207 status = H5Sselect_hyperslab(space, H5S_SELECT_SET,
offset,
nullptr,
count,
nullptr);
209 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
211 status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT,
p3);
213 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
217 for (
size_t iXtal = 0; iXtal <
nCrystals; ++iXtal) {
218 DetId detid = rawid[iXtal];
230 corrSet->setValue((
int)detid,
corr);
241 gettimeofday(&
t,
nullptr);
244 <<
"Write IOV " << iIov <<
" starting from " <<
timeToString(iovStart >> 32) <<
"... ";
245 db_->
writeOne(corrSet.get(), iovStart,
"EcalLaserAPDPNRatiosRcd");
249 std::cout <<
"Exception catched while writting to cond DB" <<
e.what() <<
"\n";
263 int processedIovs = 0;
279 while (fscanf(
eventList_,
" %1[#]%*[^\n]\n", &
c) == 1)
282 int n = fscanf(
eventList_,
"%*d %*d %*d %d%*[^\n]\n", &
t);
292 <<
" are not ordered in increased time as required! See line " <<
iline <<
"\n";
294 throw cms::Exception(
"User") <<
"Found an unexpected t = 0 time value "
295 "in the event list file"
298 bool iovFound =
true;
301 std::cout <<
"Event in same IOV than previous one.\n";
305 while ((iovFound =
r.readTime(
t1,
t2,
t3)) &&
t3 <
t)
309 if (
t1 < prevT1 &&
t3 < prevT3)
311 <<
"IOVs in the correction ascii file are not ordered in increased time as required!\n";
312 else if (
t1 < prevT1 ||
t3 < prevT3)
313 throw cms::Exception(
"User") <<
"Found interleaved IOVs in the correction ascii file!\n";
321 while (
r.readTime(
t1,
t2,
t3)) {
324 std::cout <<
"Skipping IOV " << iIov <<
"\n";
326 }
else if (processedIovs >=
nIovs_) {
327 std::cout <<
"Requested number of IOVs, " <<
nIovs_ <<
", processed.\n";
356 std::cout <<
"Skipping IOV " << iIov <<
", "
362 std::cout <<
"Skipping IOV " << iIov <<
", "
373 auto corrSet = std::make_unique<EcalLaserAPDPNRatios>();
381 corrSet->setTime(
i,
t);
384 constexpr
int ncrystals = 75848;
385 std::set<int> detidList;
386 for (
int i = 0;
i < ncrystals; ++
i) {
392 if (!
r.readPs(detid,
corr)) {
393 throw cms::Exception(
"LasCor") <<
"Failed to read " <<
toNth(
i + 1) <<
" crystal correction.\n";
396 std::pair<std::set<int>::iterator,
bool>
res = detidList.insert(
int(detid));
399 std::cout <<
"Duplicate det id, for IOV " << iIov <<
" t1 = " <<
t1 <<
" detid = " <<
int(detid) <<
"\n";
417 <<
"p1 = " <<
corr.p1 <<
"\t"
418 <<
"p2 = " <<
corr.p2 <<
"\t"
419 <<
"p3 = " <<
corr.p3 <<
"\n";
422 corrSet->setValue((
int)detid,
corr);
429 std::cout <<
"First IOV, extending starting time.\n";
434 gettimeofday(&
t,
nullptr);
437 <<
"Write IOV " << iIov <<
" starting from " <<
timeToString(iovStart >> 32) <<
"... ";
438 db_->
writeOne(corrSet.get(), iovStart,
"EcalLaserAPDPNRatiosRcd");
440 std::cout <<
"Failed.\nException cathed while writting to cond DB" <<
e.what() <<
"\n";
450 std::cout <<
"No more correction files.\n";
469 if ((f_ ==
nullptr || feof(f_)) && !nextFile()) {
478 while ((
i = fgetc(f_)) !=
'T' &&
i !=
'L' &&
i >= 0)
479 getline(&
buf, &
s, f_);
494 std::cout <<
"No more record or bad line type/marker (getc returned " <<
i <<
")\n";
500 int n = fscanf(f_,
"%d %d", &
t1, &
t3);
502 int nn = fscanf(f_,
"%d", &
t2[
i]);
508 int nnn = fscanf(f_,
" ");
512 <<
": syntax error. Expecting 'T' marker followed by 94 values: "
521 std::cout <<
"Requested to read p1..p3 parameter line while no file is closed.\n";
531 std::cout <<
"File " <<
fnames_[ifile_] <<
" line " << iline_ <<
": unexpected line type, '" << (char)
i
532 <<
"' while expecting 'P'\n";
535 std::cout <<
"Failed to read p1..p3 parameter line\n";
541 int n = fscanf(f_,
"%d %f %f %f\n", &rawdetid, &
corr.p1, &
corr.p2, &
corr.p3);
547 throw cms::Exception(
"I/O") <<
"Syntax error at line " << iline_ <<
"of file " <<
fnames_[ifile_] <<
" read " <<
n
549 <<
" raw id" << rawdetid <<
": " <<
corr.p1 <<
", " <<
corr.p2;
552 constexpr
int ECALID = 3;
553 if (detid.
det() != ECALID)
555 <<
" contains an invalid det ID (detector code is not ECAL!)\n";
560 <<
" contains an invalid det ID (detector code is not ECAL!)\n";
566 <<
" contains an invalid det ID (detector code is not ECAL!)\n";
575 bool skipLine =
false;
577 while ((
c = fgetc(f_)) >= 0 && (
c ==
' ' ||
c ==
'\t' ||
c ==
'\n' ||
c ==
'#' || skipLine)) {
591 if (
n % 100 < 10 ||
n % 100 > 20) {
614 localtime_r(&
t, <);
615 strftime(
buf,
sizeof(
buf),
"%F %R:%S", <);
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();
645 for (
unsigned i = 0;
i <
t.size(); ++
i) {
646 if (
t[
i].
t1.unixTime() !=
t1 ||
t[
i].t3.unixTime() !=
t3) {
648 <<
"t1(lme 1) =" <<
t1 <<
", t1(lme " << (
i + 1) <<
") = " <<
t[
i].
t1.unixTime()
649 <<
", t3(lme 1) =" <<
t3 <<
", t3(lme " << (
i + 1) <<
") = " <<
t[
i].
t3.unixTime()
652 fprintf(
fout_,
"\t%d",
t[
i].
t2.unixTime());
669 for (
int iZ = 1; iZ >= -1; --iZ) {