|
|
Go to the documentation of this file.
27 eventListFileName_(ps.getParameter<
string>(
"eventListFile")),
28 verb_(ps.getParameter<
int>(
"verbosity")),
29 mode_(ps.getParameter<
string>(
"mode")),
30 fnames_(ps.getParameter<vector<
string> >(
"laserCorrectionAsciiFiles")),
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 ferr_ = fopen(
"corr_errors.txt",
"w");
36 fprintf(
ferr_,
"#t1\tdetid\tp1\tp2\tp3");
53 static bool done =
false;
55 if (
mode_ ==
"ascii_file_to_db") {
59 cout <<
"ascii_file_to_db mode" << endl;
61 throw cms::Exception(
"CondDBAccess") <<
"Failed to connect to PoolDBOutputService\n";
66 }
else if (
mode_ ==
"db_to_ascii_file") {
69 cms::Exception(
"InvalidParam") <<
"Value of parameter mode is not valid. Expecting ascii_file_to_db or read";
75 int processedIovs = 0;
77 cout <<
"Starting filling DB...\n";
91 while (fscanf(
eventList_,
" %1[#]%*[^\n]\n", &
c) == 1)
94 int n = fscanf(
eventList_,
"%*d %*d %*d %d%*[^\n]\n", &
t);
104 <<
" are not ordered in increased time as required! See line " <<
iline <<
"\n";
106 throw cms::Exception(
"User") <<
"Found an unexpected t = 0 time value "
107 "in the event list file"
110 bool iovFound =
true;
113 cout <<
"Event in same IOV than previous one.\n";
117 while ((iovFound =
r.readTime(
t1,
t2,
t3)) &&
t3 <
t)
121 if (
t1 < prevT1 &&
t3 < prevT3)
123 <<
"IOVs in the correction ascii file are not ordered in increased time as required!\n";
124 else if (
t1 < prevT1 ||
t3 < prevT3)
125 throw cms::Exception(
"User") <<
"Found interleaved IOVs in the correction ascii file!\n";
133 while (
r.readTime(
t1,
t2,
t3)) {
136 std::cout <<
"Skipping IOV " << iIov <<
"\n";
138 }
else if (processedIovs >=
nIovs_) {
139 std::cout <<
"Requested number of IOVs, " <<
nIovs_ <<
", processed.\n";
167 std::cout <<
"Skipping IOV " << iIov <<
", "
192 constexpr
int ncrystals = 75848;
193 std::set<int> detidList;
194 for (
int i = 0;
i < ncrystals; ++
i) {
199 cout <<
"Reading " <<
toNth(
i + 1) <<
" crystal\n";
200 if (!
r.readPs(detid,
corr)) {
201 throw cms::Exception(
"LasCor") <<
"Failed to read " <<
toNth(
i + 1) <<
" crystal correction.\n";
204 pair<std::set<int>::iterator,
bool>
res = detidList.insert(
int(detid));
207 std::cout <<
"Duplicate det id, for IOV " << iIov <<
" t1 = " <<
t1 <<
" detid = " <<
int(detid) << endl;
212 constexpr
float minp = 0.00001;
213 constexpr
float maxp = 1.8;
217 if (!isfinite(
corr.p1) || !isfinite(
corr.p2) || !isfinite(
corr.p3) ||
corr.p1 < minp ||
corr.p1 > maxp ||
232 <<
"p1 = " <<
corr.p1 <<
"\t"
233 <<
"p2 = " <<
corr.p2 <<
"\t"
234 <<
"p3 = " <<
corr.p3 <<
"\n";
251 cout <<
"First IOV, extending starting time." << endl;
255 gettimeofday(&
t,
nullptr);
258 <<
"Write IOV " << iIov <<
" starting from " <<
timeToString(iovStart >> 32) <<
"... ";
259 db_->
writeOne(corrSet, iovStart,
"EcalLaserAPDPNRatiosRcd");
261 std::cout <<
"Failed.\nException cathed while writting to cond DB" <<
e.what() <<
"\n";
271 cout <<
"No more correction files.\n";
288 if ((f_ ==
nullptr || feof(f_)) && !nextFile()) {
290 cout <<
"No more record\n";
296 while ((
i = fgetc(f_)) !=
'T' &&
i !=
'L' &&
i >= 0)
297 getline(&
buf, &
s, f_);
312 cout <<
"No more record or bad line type/marker (getc returned " <<
i <<
")\n";
317 int n = fscanf(f_,
"%d %d", &
t1, &
t3);
319 int nn = fscanf(f_,
"%d", &
t2[
i]);
325 int nnn = fscanf(f_,
" ");
329 <<
": syntax error. Expecting 'T' marker followed by 94 values: "
338 cout <<
"Requested to read p1..p3 parameter line while no file is closed.\n";
347 cout <<
"File " <<
fnames_[ifile_] <<
" line " << iline_ <<
": unexpected line type, '" << (char)
i
348 <<
"' while expecting 'P'\n";
350 cout <<
"Failed to read p1..p3 parameter line\n";
355 int n = fscanf(f_,
"%d %f %f %f\n", &rawdetid, &
corr.p1, &
corr.p2, &
corr.p3);
361 throw cms::Exception(
"I/O") <<
"Syntax error at line " << iline_ <<
"of file " <<
fnames_[ifile_] <<
" read " <<
n
363 <<
" raw id" << rawdetid <<
": " <<
corr.p1 <<
", " <<
corr.p2;
366 constexpr
int ECALID = 3;
367 if (detid.
det() != ECALID)
369 <<
" contains an invalid det ID (detector code is not ECAL!)\n";
374 <<
" contains an invalid det ID (detector code is not ECAL!)\n";
380 <<
" contains an invalid det ID (detector code is not ECAL!)\n";
389 bool skipLine =
false;
391 while ((
c = fgetc(f_)) >= 0 && (
c ==
' ' ||
c ==
'\t' ||
c ==
'\n' ||
c ==
'#' || skipLine)) {
405 if (
n % 100 < 10 ||
n % 100 > 20) {
428 localtime_r(&
t, <);
429 strftime(
buf,
sizeof(
buf),
"%F %R:%S", <);
444 throw cms::Exception(
"LasCor") <<
"Unexpected number time parameter triplets\n";
446 if (
fout_ ==
nullptr) {
447 fout_ = fopen(
"corr_dump.txt",
"w");
448 if (
fout_ ==
nullptr)
449 throw cms::Exception(
"LasCor") <<
"Failed to create file corr_dump.txt\n";
452 unsigned t1 =
t[0].t1.unixTime();
453 unsigned t3 =
t[0].t3.unixTime();
459 for (
unsigned i = 0;
i <
t.size(); ++
i) {
460 if (
t[
i].
t1.unixTime() !=
t1 ||
t[
i].t3.unixTime() !=
t3) {
462 <<
"t1(lme 1) =" <<
t1 <<
", t1(lme " << (
i + 1) <<
") = " <<
t[
i].
t1.unixTime()
463 <<
", t3(lme 1) =" <<
t3 <<
", t3(lme " << (
i + 1) <<
") = " <<
t[
i].
t3.unixTime()
466 fprintf(
fout_,
"\t%d",
t[
i].
t2.unixTime());
483 for (
int iZ = 1; iZ >= -1; --iZ) {
int hashedIndex() const
get a compact index for arrays
T const * product() const
cond::Time_t beginOfTime() const
constexpr Detector det() const
get the detector field from this detid
static const int MAX_IPHI
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
unsigned long long Time_t
void setValue(uint32_t rawId, const EcalLaserAPDPNpair &value)
std::vector< EcalLaserTimeStamp > EcalLaserTimeStampMap
static bool validDetId(int i, int j)
check if a valid index combination
Hash writeOne(const T *payload, Time_t time, const std::string &recordName)
int ietaAbs() const
get the absolute value of the crystal ieta
bool isNewTagRequest(const std::string &recordName)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
unsigned long long uint64_t
int iphi() const
get the crystal iphi
void setTime(int hashedIndex, const EcalLaserTimeStamp &value)
static void trim(std::string &s)
static const int MAX_IETA
static const int MIN_IPHI