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::EDAnalyzer 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::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () 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 &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > 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
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices 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_
 
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::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsInputProcessBlocks ()
 
static bool wantsProcessBlocks ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
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 ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

Definition at line 23 of file EcalLaserCondTools.h.

Constructor & Destructor Documentation

◆ EcalLaserCondTools()

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

Constructor

Parameters
psanalyser configuration

Definition at line 26 of file EcalLaserCondTools.cc.

27  : fout_(nullptr),
28  eventList_(nullptr),
29  eventListFileName_(ps.getParameter<std::string>("eventListFile")),
30  verb_(ps.getParameter<int>("verbosity")),
31  mode_(ps.getParameter<std::string>("mode")),
32  fnames_(ps.getParameter<std::vector<std::string> >("inputFiles")),
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");
41 
42  if (!eventListFileName_.empty()) {
43  eventList_ = fopen(eventListFileName_.c_str(), "r");
44  if (eventList_ == nullptr)
45  throw cms::Exception("User") << "Failed to open file " << eventListFileName_ << "\n";
46  }
47 }

References eventList_, eventListFileName_, Exception, and ferr_.

◆ ~EcalLaserCondTools()

EcalLaserCondTools::~EcalLaserCondTools ( )
override

Destructor

Definition at line 49 of file EcalLaserCondTools.cc.

49  {
50  if (ferr_)
51  fclose(ferr_);
52  if (fout_)
53  fclose(fout_);
54 }

References ferr_, and fout_.

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::EDAnalyzer.

Definition at line 56 of file EcalLaserCondTools.cc.

56  {
57  static bool done = false;
58 
59  if (done && (mode_ == "ascii_file_to_db" || mode_ == "hdf_file_to_db")) {
60  return;
61  }
62 
63  if (mode_ == "ascii_file_to_db") {
64  if (verb_ > 2)
65  std::cout << "ascii_file_to_db mode\n";
66 
67  if (!db_.isAvailable()) {
68  throw cms::Exception("CondDBAccess") << "Failed to connect to PoolDBOutputService\n";
69  }
70  FileReader corrReader(fnames_);
71  corrReader.setVerbosity(verb_);
72  fillDb(corrReader);
73  } else if (mode_ == "hdf_file_to_db") {
75  } else if (mode_ == "db_to_ascii_file") {
76  dbToAscii(es);
77  } else {
78  cms::Exception("InvalidParam") << "Value of parameter mode is not valid. Expecting ascii_file_to_db or read";
79  }
80 }

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

◆ dbToAscii()

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

Definition at line 620 of file EcalLaserCondTools.cc.

620  {
622  es.get<EcalLaserAPDPNRatiosRcd>().get(hCorr);
623 
624  const EcalLaserAPDPNRatios* corr = hCorr.product();
625 
626  const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap& p = corr->getLaserMap();
627  const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& t = corr->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  std::cout << "Processing IOV " << t1 << " - " << t3 << "(" << timeToString(t1) << " - " << timeToString(t3) << "\n";
644 
645  for (unsigned i = 0; i < t.size(); ++i) {
646  if (t[i].t1.unixTime() != t1 || t[i].t3.unixTime() != t3) {
647  throw cms::Exception("LasCor") << "Inconsitency in t1, 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()
650  << "\n";
651  }
652  fprintf(fout_, "\t%d", t[i].t2.unixTime());
653  }
654  fputc('\n', fout_);
655  fflush(fout_);
656 
657  for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
658  if (ieta == 0)
659  continue;
660  for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
661  if (EBDetId::validDetId(ieta, iphi)) {
662  EBDetId detId(ieta, iphi);
663  EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr = p.barrel(detId.hashedIndex());
664  fprintf(fout_, "P %d\t%f\t%f\t%f\n", (int)detId, corr.p1, corr.p2, corr.p3);
665  }
666  }
667  }
668 
669  for (int iZ = 1; iZ >= -1; --iZ) {
670  for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
671  for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
672  if (EEDetId::validDetId(iX, iY, iZ)) {
673  EEDetId detId(iX, iY, iZ);
674  EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr = p.endcap(detId.hashedIndex());
675  fprintf(fout_, "P %d\t%f\t%f\t%f\n", (int)detId, corr.p1, corr.p2, corr.p3);
676  }
677  }
678  }
679  }
680 }

References alignCSCRings::corr, gather_cfg::cout, Exception, fout_, edm::EventSetup::get(), get, EBDetId::hashedIndex(), EEDetId::hashedIndex(), mps_fire::i, LEDCalibrationChannels::ieta, LEDCalibrationChannels::iphi, EEDetId::IX_MAX, EEDetId::IX_MIN, EEDetId::IY_MAX, EEDetId::IY_MIN, EBDetId::MAX_IETA, EBDetId::MAX_IPHI, EBDetId::MIN_IPHI, nLmes, AlCaHLTBitMon_ParallelJobs::p, edm::ESHandle< T >::product(), submitPVValidationJobs::t, RandomServiceHelper::t1, RandomServiceHelper::t2, RandomServiceHelper::t3, timeToString(), EBDetId::validDetId(), EEDetId::validDetId(), and verb_.

Referenced by analyze().

◆ fillDb()

void EcalLaserCondTools::fillDb ( CorrReader r)
private

Definition at line 261 of file EcalLaserCondTools.cc.

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

References c, gather_cfg::cout, 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().

◆ from_hdf_to_db()

void EcalLaserCondTools::from_hdf_to_db ( )

Definition at line 82 of file EcalLaserCondTools.cc.

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

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

Referenced by analyze().

◆ processIov()

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

Definition at line 336 of file EcalLaserCondTools.cc.

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

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

Referenced by fillDb().

◆ timeToString()

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

Definition at line 611 of file EcalLaserCondTools.cc.

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

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

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

◆ toNth()

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

Definition at line 588 of file EcalLaserCondTools.cc.

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

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

Referenced by processIov().

Member Data Documentation

◆ db_

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

Definition at line 92 of file EcalLaserCondTools.h.

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

◆ eventList_

FILE* EcalLaserCondTools::eventList_
private

Definition at line 87 of file EcalLaserCondTools.h.

Referenced by EcalLaserCondTools(), and fillDb().

◆ eventListFileName_

std::string EcalLaserCondTools::eventListFileName_
private

Definition at line 88 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 86 of file EcalLaserCondTools.h.

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

◆ fromTime_

int EcalLaserCondTools::fromTime_
private

Definition at line 95 of file EcalLaserCondTools.h.

Referenced by processIov().

◆ maxP_

double EcalLaserCondTools::maxP_
private

Definition at line 97 of file EcalLaserCondTools.h.

Referenced by from_hdf_to_db(), and processIov().

◆ minP_

double EcalLaserCondTools::minP_
private

Definition at line 97 of file EcalLaserCondTools.h.

Referenced by from_hdf_to_db(), and processIov().

◆ mode_

std::string EcalLaserCondTools::mode_
private

Definition at line 90 of file EcalLaserCondTools.h.

Referenced by analyze().

◆ nIovs_

int EcalLaserCondTools::nIovs_
private

Definition at line 94 of file EcalLaserCondTools.h.

Referenced by fillDb(), and from_hdf_to_db().

◆ nLmes

constexpr int EcalLaserCondTools::nLmes = 92
staticconstexprprivate

Number of extended laser monitoring regions

Definition at line 28 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 93 of file EcalLaserCondTools.h.

Referenced by fillDb(), and from_hdf_to_db().

◆ toTime_

int EcalLaserCondTools::toTime_
private

Definition at line 96 of file EcalLaserCondTools.h.

Referenced by processIov().

◆ verb_

int EcalLaserCondTools::verb_
private
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
mps_fire.i
i
Definition: mps_fire.py:428
EcalLaserAPDPNRatiosRcd
Definition: EcalLaserAPDPNRatiosRcd.h:24
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
cond::service::PoolDBOutputService::beginOfTime
cond::Time_t beginOfTime() const
Definition: PoolDBOutputService.cc:215
EcalLaserCondTools::from_hdf_to_db
void from_hdf_to_db()
Definition: EcalLaserCondTools.cc:82
EcalLaserCondTools::verb_
int verb_
Definition: EcalLaserCondTools.h:89
mps_update.status
status
Definition: mps_update.py:69
EBDetId
Definition: EBDetId.h:17
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EcalLaserCondTools::dbToAscii
void dbToAscii(const edm::EventSetup &es)
Definition: EcalLaserCondTools.cc:620
cms::cuda::assert
assert(be >=bs)
EEDetId::IX_MIN
static const int IX_MIN
Definition: EEDetId.h:290
EEDetId::IY_MIN
static const int IY_MIN
Definition: EEDetId.h:294
EcalCondObjectContainer< EcalLaserAPDPNpair >
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
EcalBarrel
Definition: EcalSubdetector.h:10
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
EcalLaserCondTools::timeToString
static std::string timeToString(time_t t)
Definition: EcalLaserCondTools.cc:611
EcalLaserCondTools::db_
edm::Service< cond::service::PoolDBOutputService > db_
Definition: EcalLaserCondTools.h:92
DetId
Definition: DetId.h:17
EcalLaserCondTools::eventListFileName_
std::string eventListFileName_
Definition: EcalLaserCondTools.h:88
alignCSCRings.s
s
Definition: alignCSCRings.py:92
EcalLaserCondTools::mode_
std::string mode_
Definition: EcalLaserCondTools.h:90
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
EcalLaserCondTools::toTime_
int toTime_
Definition: EcalLaserCondTools.h:96
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
EcalLaserCondTools::processIov
void processIov(CorrReader &r, int t1, int t2[nLmes], int t3)
Definition: EcalLaserCondTools.cc:336
fileCollector.done
done
Definition: fileCollector.py:123
alignCSCRings.corr
dictionary corr
Definition: alignCSCRings.py:124
compare_using_db.ifile
ifile
Definition: compare_using_db.py:251
edm::ESHandle
Definition: DTSurvey.h:22
p2
double p2[4]
Definition: TauolaWrapper.h:90
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
EBDetId::MAX_IPHI
static const int MAX_IPHI
Definition: EBDetId.h:137
EEDetId::IY_MAX
static const int IY_MAX
Definition: EEDetId.h:302
RandomServiceHelper.t3
t3
Definition: RandomServiceHelper.py:258
EcalLaserCondTools::maxP_
double maxP_
Definition: EcalLaserCondTools.h:97
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
EEDetId
Definition: EEDetId.h:14
EcalLaserCondTools::fromTime_
int fromTime_
Definition: EcalLaserCondTools.h:95
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalEndcap
Definition: EcalSubdetector.h:10
EcalLaserCondTools::nIovs_
int nIovs_
Definition: EcalLaserCondTools.h:94
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
EcalLaserAPDPNRatios::EcalLaserAPDPNpair
Definition: EcalLaserAPDPNRatios.h:16
ecaldqm::nCrystals
unsigned nCrystals(unsigned)
Definition: EcalDQMCommonUtils.cc:334
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
EEDetId::IX_MAX
static const int IX_MAX
Definition: EEDetId.h:298
createfilelist.int
int
Definition: createfilelist.py:10
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
ntuplemaker.iline
iline
Definition: ntuplemaker.py:186
EcalLaserCondTools::toNth
static std::string toNth(int n)
Definition: EcalLaserCondTools.cc:588
EcalLaserCondTools::nLmes
static constexpr int nLmes
Definition: EcalLaserCondTools.h:28
p1
double p1[4]
Definition: TauolaWrapper.h:89
EcalLaserAPDPNRatios::EcalLaserTimeStampMap
std::vector< EcalLaserTimeStamp > EcalLaserTimeStampMap
Definition: EcalLaserAPDPNRatios.h:34
get
#define get
res
Definition: Electron.h:6
EcalLaserCondTools::minP_
double minP_
Definition: EcalLaserCondTools.h:97
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
alignCSCRings.r
r
Definition: alignCSCRings.py:93
EBDetId::validDetId
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
EcalLaserCondTools::ferr_
FILE * ferr_
Definition: EcalLaserCondTools.h:98
EcalLaserCondTools::skipIov_
int skipIov_
Definition: EcalLaserCondTools.h:93
Exception
Definition: hltDiff.cc:245
cond::service::PoolDBOutputService::writeOne
Hash writeOne(const T *payload, Time_t time, const std::string &recordName)
Definition: PoolDBOutputService.h:63
cond::service::PoolDBOutputService::isNewTagRequest
bool isNewTagRequest(const std::string &recordName)
Definition: PoolDBOutputService.cc:128
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
p3
double p3[4]
Definition: TauolaWrapper.h:91
EEDetId::validDetId
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
EcalLaserCondTools::fnames_
std::vector< std::string > fnames_
Definition: EcalLaserCondTools.h:91
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
cms::Exception
Definition: Exception.h:70
EcalLaserAPDPNRatios
Definition: EcalLaserAPDPNRatios.h:14
EcalLaserCondTools::eventList_
FILE * eventList_
Definition: EcalLaserCondTools.h:87
EcalLaserCondTools::fillDb
void fillDb(CorrReader &r)
Definition: EcalLaserCondTools.cc:261
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
EcalLaserCondTools::fout_
FILE * fout_
Definition: EcalLaserCondTools.h:86
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
EcalLaserAPDPNRatios::EcalLaserTimeStamp
Definition: EcalLaserAPDPNRatios.h:24
EBDetId::MAX_IETA
static const int MAX_IETA
Definition: EBDetId.h:136
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
EBDetId::MIN_IPHI
static const int MIN_IPHI
Definition: EBDetId.h:135
edm::Timestamp
Definition: Timestamp.h:30