27 eventListFileName_(ps.getParameter<std::
string>(
"eventListFile")),
28 verb_(ps.getParameter<int>(
"verbosity")),
29 mode_(ps.getParameter<std::
string>(
"mode")),
30 fnames_(ps.getParameter<std::
vector<std::
string> >(
"inputFiles")),
31 skipIov_(ps.getParameter<int>(
"skipIov")),
32 nIovs_(ps.getParameter<int>(
"nIovs")),
33 fromTime_(ps.getParameter<int>(
"fromTime")),
34 toTime_(ps.getParameter<int>(
"toTime")),
35 minP_(ps.getParameter<double>(
"transparencyMin")),
36 maxP_(ps.getParameter<double>(
"transparencyMax")) {
37 if (
mode_ ==
"db_to_ascii_file") {
41 ferr_ = fopen(
"corr_errors.txt",
"w");
42 fprintf(
ferr_,
"#t1\tdetid\tp1\tp2\tp3");
59 static bool done =
false;
61 if (done && (
mode_ ==
"ascii_file_to_db" ||
mode_ ==
"hdf_file_to_db")) {
65 if (
mode_ ==
"ascii_file_to_db") {
70 throw cms::Exception(
"CondDBAccess") <<
"Failed to connect to PoolDBOutputService\n";
75 }
else if (
mode_ ==
"hdf_file_to_db") {
77 }
else if (
mode_ ==
"db_to_ascii_file") {
80 cms::Exception(
"InvalidParam") <<
"Value of parameter mode is not valid. Expecting ascii_file_to_db or read";
87 hid_t
file, space, memspace;
88 hid_t dset_rawid, dset_t2, dset;
97 file = H5Fopen(
fnames_[
ifile].c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
99 dset_rawid = H5Dopen(file,
"cmssw_id", H5P_DEFAULT);
100 space = H5Dget_space(dset_rawid);
101 H5Sget_simple_extent_dims(space, dims,
nullptr);
107 status = H5Dread(dset_rawid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rawid);
109 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
111 H5Dclose(dset_rawid);
114 dset_t2 = H5Dopen(file,
"t2", H5P_DEFAULT);
115 space = H5Dget_space(dset_t2);
116 H5Sget_simple_extent_dims(space, dims,
nullptr);
118 unsigned int nIovs = dims[0];
119 unsigned int nLME = dims[1];
122 std::cout <<
"Number of crystals: " << nCrystals <<
"\n";
123 std::cout <<
"Number of IOVs: " << nIovs <<
"\n";
124 std::cout <<
"Number of Monitoring regions: " << nLME <<
"\n";
127 int t1[nIovs], t3[nIovs], t2[nIovs][nLME];
133 status = H5Dread(dset_t2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, t2[0]);
135 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
143 dset = H5Dopen(file,
"t1", H5P_DEFAULT);
144 status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, t1);
146 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
153 dset = H5Dopen(file,
"t3", H5P_DEFAULT);
154 status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, t3);
156 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
164 hsize_t iov_dim[1] = {nCrystals};
165 memspace = H5Screate_simple(1, iov_dim,
nullptr);
168 for (
unsigned int iIov =
skipIov_; iIov < nIovs && iIov < unsigned(
nIovs_); ++iIov) {
170 iovStart =
uint64_t(t1[iIov]) << 32;
178 hsize_t
offset[2] = {iIov, 0};
179 hsize_t
count[2] = {1, nCrystals};
181 dset = H5Dopen(file,
"p1", H5P_DEFAULT);
182 space = H5Dget_space(dset);
183 status = H5Sselect_hyperslab(space, H5S_SELECT_SET, offset,
nullptr, count,
nullptr);
185 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
187 status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT, p1);
189 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
194 dset = H5Dopen(file,
"p2", H5P_DEFAULT);
195 space = H5Dget_space(dset);
196 status = H5Sselect_hyperslab(space, H5S_SELECT_SET, offset,
nullptr, count,
nullptr);
198 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
200 status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT, p2);
202 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
207 dset = H5Dopen(file,
"p3", H5P_DEFAULT);
208 space = H5Dget_space(dset);
209 status = H5Sselect_hyperslab(space, H5S_SELECT_SET, offset,
nullptr, count,
nullptr);
211 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
213 status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT, p3);
215 throw cms::Exception(
"EcalLaserCondTool:HDF") <<
"Error while reading HD file.";
219 for (
size_t iXtal = 0; iXtal <
nCrystals; ++iXtal) {
220 DetId detid = rawid[iXtal];
227 if (!isfinite(corr.
p1) || !isfinite(corr.
p2) || !isfinite(corr.
p3) || corr.
p1 <
minP_ || corr.
p1 >
maxP_ ||
229 fprintf(
ferr_,
"%d %d %f %f %f\n", t1[iIov], (
int)detid, corr.
p1, corr.
p2, corr.
p3);
230 corr.
p1 = corr.
p2 = corr.
p3 = 1;
243 gettimeofday(&t,
nullptr);
246 <<
"Write IOV " << iIov <<
" starting from " <<
timeToString(iovStart >> 32) <<
"... ";
251 std::cout <<
"Exception catched while writting to cond DB" << e.
what() <<
"\n";
265 int processedIovs = 0;
281 while (fscanf(
eventList_,
" %1[#]%*[^\n]\n", &c) == 1)
284 int n = fscanf(
eventList_,
"%*d %*d %*d %d%*[^\n]\n", &t);
294 <<
" are not ordered in increased time as required! See line " << iline <<
"\n";
296 throw cms::Exception(
"User") <<
"Found an unexpected t = 0 time value "
297 "in the event list file"
300 bool iovFound =
true;
303 std::cout <<
"Event in same IOV than previous one.\n";
307 while ((iovFound = r.
readTime(t1, t2, t3)) && t3 < t)
311 if (t1 < prevT1 && t3 < prevT3)
313 <<
"IOVs in the correction ascii file are not ordered in increased time as required!\n";
314 else if (t1 < prevT1 || t3 < prevT3)
315 throw cms::Exception(
"User") <<
"Found interleaved IOVs in the correction ascii file!\n";
326 std::cout <<
"Skipping IOV " << iIov <<
"\n";
328 }
else if (processedIovs >=
nIovs_) {
329 std::cout <<
"Requested number of IOVs, " <<
nIovs_ <<
", processed.\n";
351 <<
"t3: " << t3 <<
"(" <<
timeToString(t3) <<
")\nt2-t1: ";
358 std::cout <<
"Skipping IOV " << iIov <<
", "
364 std::cout <<
"Skipping IOV " << iIov <<
", "
386 constexpr
int ncrystals = 75848;
387 std::set<int> detidList;
388 for (
int i = 0;
i < ncrystals; ++
i) {
394 if (!r.
readPs(detid, corr)) {
395 throw cms::Exception(
"LasCor") <<
"Failed to read " <<
toNth(
i + 1) <<
" crystal correction.\n";
398 std::pair<std::set<int>::iterator,
bool> res = detidList.insert(
int(detid));
401 std::cout <<
"Duplicate det id, for IOV " << iIov <<
" t1 = " << t1 <<
" detid = " << int(detid) <<
"\n";
404 if (!isfinite(corr.
p1) || !isfinite(corr.
p2) || !isfinite(corr.
p3) || corr.
p1 <
minP_ || corr.
p1 >
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;
419 <<
"p1 = " << corr.
p1 <<
"\t"
420 <<
"p2 = " << corr.
p2 <<
"\t"
421 <<
"p3 = " << corr.
p3 <<
"\n";
431 std::cout <<
"First IOV, extending starting time.\n";
436 gettimeofday(&t,
nullptr);
439 <<
"Write IOV " << iIov <<
" starting from " <<
timeToString(iovStart >> 32) <<
"... ";
442 std::cout <<
"Failed.\nException cathed while writting to cond DB" << e.
what() <<
"\n";
452 std::cout <<
"No more correction files.\n";
459 f_ = fopen(fnames_[
ifile_].c_str(),
"r");
462 std::cerr <<
"Failed to open file " << fnames_[
ifile_] <<
". File skipped!\n";
471 if ((f_ ==
nullptr || feof(f_)) && !nextFile()) {
480 while ((i = fgetc(f_)) !=
'T' && i !=
'L' && i >= 0)
481 getline(&buf, &s, f_);
496 std::cout <<
"No more record or bad line type/marker (getc returned " << i <<
")\n";
502 int n = fscanf(f_,
"%d %d", &t1, &t3);
504 int nn = fscanf(f_,
"%d", &t2[i]);
510 int nnn = fscanf(f_,
" ");
512 if (n != (2 + EcalLaserCondTools::nLmes) || nnn != 0)
514 <<
": syntax error. Expecting 'T' marker followed by 94 values: "
515 <<
"t1 t2 t3(lme 1) t3(lme 2) ... t3(lme " << EcalLaserCondTools::nLmes <<
")\n";
523 std::cout <<
"Requested to read p1..p3 parameter line while no file is closed.\n";
533 std::cout <<
"File " <<
fnames_[ifile_] <<
" line " << iline_ <<
": unexpected line type, '" << (char)i
534 <<
"' while expecting 'P'\n";
537 std::cout <<
"Failed to read p1..p3 parameter line\n";
543 int n = fscanf(f_,
"%d %f %f %f\n", &rawdetid, &corr.
p1, &corr.
p2, &corr.
p3);
549 throw cms::Exception(
"I/O") <<
"Syntax error at line " << iline_ <<
"of file " <<
fnames_[ifile_] <<
" read " << n
551 <<
" raw id" << rawdetid <<
": " << corr.
p1 <<
", " << corr.
p2;
554 constexpr
int ECALID = 3;
555 if (detid.
det() != ECALID)
557 <<
" contains an invalid det ID (detector code is not ECAL!)\n";
561 throw cms::Exception(
"InvalidValue") <<
"Line " << iline_ <<
"of file " << fnames_[ifile_]
562 <<
" contains an invalid det ID (detector code is not ECAL!)\n";
567 throw cms::Exception(
"InvalidValue") <<
"Line " << iline_ <<
"of file " << fnames_[ifile_]
568 <<
" contains an invalid det ID (detector code is not ECAL!)\n";
577 bool skipLine =
false;
579 while ((c = fgetc(f_)) >= 0 && (c ==
' ' || c ==
'\t' || c ==
'\n' || c ==
'#' || skipLine)) {
593 if (n % 100 < 10 || n % 100 > 20) {
616 localtime_r(&t, <);
617 strftime(buf,
sizeof(buf),
"%F %R:%S", <);
618 buf[
sizeof(
buf) - 1] = 0;
629 throw cms::Exception(
"LasCor") <<
"Unexpected number time parameter triplets\n";
631 if (
fout_ ==
nullptr) {
632 fout_ = fopen(
"corr_dump.txt",
"w");
633 if (
fout_ ==
nullptr)
634 throw cms::Exception(
"LasCor") <<
"Failed to create file corr_dump.txt\n";
637 unsigned t1 = t[0].t1.unixTime();
638 unsigned t3 = t[0].t3.unixTime();
639 fprintf(
fout_,
"T %d\t%d", t1, t3);
644 for (
unsigned i = 0;
i < t.size(); ++
i) {
645 if (t[
i].t1.unixTime() != t1 || t[
i].t3.unixTime() != t3) {
647 <<
"t1(lme 1) =" << t1 <<
", t1(lme " << (
i + 1) <<
") = " << t[
i].t1.unixTime()
648 <<
", t3(lme 1) =" << t3 <<
", t3(lme " << (
i + 1) <<
") = " << t[
i].t3.unixTime()
651 fprintf(
fout_,
"\t%d", t[
i].t2.unixTime());
663 fprintf(
fout_,
"P %d\t%f\t%f\t%f\n", (
int)detId, corr.
p1, corr.
p2, corr.
p3);
668 for (
int iZ = 1; iZ >= -1; --iZ) {
674 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)
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