CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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::one::EDAnalyzer<> edm::one::EDAnalyzerBase 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::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () 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 const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
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
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
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::PoolDBOutputService
db_
 
FILE * eventList_
 
std::string eventListFileName_
 
FILE * ferr_
 
std::vector< std::string > fnames_
 
FILE * fout_
 
int fromTime_
 
edm::ESGetToken
< EcalLaserAPDPNRatios,
EcalLaserAPDPNRatiosRcd
laserAPDPNRatiosToken_
 
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::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
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<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
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...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 24 of file EcalLaserCondTools.h.

Constructor & Destructor Documentation

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

Constructor

Parameters
psanalyser configuration

Definition at line 24 of file EcalLaserCondTools.cc.

References edm::EDConsumerBase::esConsumes(), eventList_, eventListFileName_, Exception, ferr_, laserAPDPNRatiosToken_, and mode_.

25  : fout_(nullptr),
26  eventList_(nullptr),
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") {
39  }
40 
41  ferr_ = fopen("corr_errors.txt", "w");
42  fprintf(ferr_, "#t1\tdetid\tp1\tp2\tp3");
43 
44  if (!eventListFileName_.empty()) {
45  eventList_ = fopen(eventListFileName_.c_str(), "r");
46  if (eventList_ == nullptr)
47  throw cms::Exception("User") << "Failed to open file " << eventListFileName_ << "\n";
48  }
49 }
std::vector< std::string > fnames_
std::string eventListFileName_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESGetToken< EcalLaserAPDPNRatios, EcalLaserAPDPNRatiosRcd > laserAPDPNRatiosToken_
EcalLaserCondTools::~EcalLaserCondTools ( )
override

Destructor

Definition at line 51 of file EcalLaserCondTools.cc.

References ferr_, and fout_.

51  {
52  if (ferr_)
53  fclose(ferr_);
54  if (fout_)
55  fclose(fout_);
56 }

Member Function Documentation

void EcalLaserCondTools::analyze ( const edm::Event evt,
const edm::EventSetup es 
)
overridevirtual

Called by CMSSW event loop

Parameters
evtthe event
esevents setup

Implements edm::one::EDAnalyzerBase.

Definition at line 58 of file EcalLaserCondTools.cc.

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_.

58  {
59  static bool done = false;
60 
61  if (done && (mode_ == "ascii_file_to_db" || mode_ == "hdf_file_to_db")) {
62  return;
63  }
64 
65  if (mode_ == "ascii_file_to_db") {
66  if (verb_ > 2)
67  std::cout << "ascii_file_to_db mode\n";
68 
69  if (!db_.isAvailable()) {
70  throw cms::Exception("CondDBAccess") << "Failed to connect to PoolDBOutputService\n";
71  }
72  FileReader corrReader(fnames_);
73  corrReader.setVerbosity(verb_);
74  fillDb(corrReader);
75  } else if (mode_ == "hdf_file_to_db") {
77  } else if (mode_ == "db_to_ascii_file") {
78  dbToAscii(es);
79  } else {
80  cms::Exception("InvalidParam") << "Value of parameter mode is not valid. Expecting ascii_file_to_db or read";
81  }
82 }
std::vector< std::string > fnames_
void fillDb(CorrReader &r)
edm::Service< cond::service::PoolDBOutputService > db_
void dbToAscii(const edm::EventSetup &es)
bool isAvailable() const
Definition: Service.h:40
tuple cout
Definition: gather_cfg.py:144
void EcalLaserCondTools::dbToAscii ( const edm::EventSetup es)
private

Definition at line 622 of file EcalLaserCondTools.cc.

References EcalCondObjectContainer< T >::barrel(), alignCSCRings::corr, gather_cfg::cout, EcalCondObjectContainer< T >::endcap(), Exception, fout_, edm::EventSetup::getData(), EBDetId::hashedIndex(), EEDetId::hashedIndex(), mps_fire::i, EEDetId::IX_MAX, EEDetId::IX_MIN, EEDetId::IY_MAX, EEDetId::IY_MIN, laserAPDPNRatiosToken_, EBDetId::MAX_IETA, EBDetId::MAX_IPHI, EBDetId::MIN_IPHI, nLmes, AlCaHLTBitMon_ParallelJobs::p, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p1, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p2, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p3, submitPVValidationJobs::t, timeToString(), EBDetId::validDetId(), EEDetId::validDetId(), and verb_.

Referenced by analyze().

622  {
623  const auto& laserAPDPNRatios = es.getData(laserAPDPNRatiosToken_);
624 
625  const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap& p = laserAPDPNRatios.getLaserMap();
626  const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& t = laserAPDPNRatios.getTimeMap();
627 
628  if (t.size() != EcalLaserCondTools::nLmes)
629  throw cms::Exception("LasCor") << "Unexpected number time parameter triplets\n";
630 
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";
635  }
636 
637  unsigned t1 = t[0].t1.unixTime();
638  unsigned t3 = t[0].t3.unixTime();
639  fprintf(fout_, "T %d\t%d", t1, t3);
640 
641  if (verb_)
642  std::cout << "Processing IOV " << t1 << " - " << t3 << "(" << timeToString(t1) << " - " << timeToString(t3) << "\n";
643 
644  for (unsigned i = 0; i < t.size(); ++i) {
645  if (t[i].t1.unixTime() != t1 || t[i].t3.unixTime() != t3) {
646  throw cms::Exception("LasCor") << "Inconsitency in t1, 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()
649  << "\n";
650  }
651  fprintf(fout_, "\t%d", t[i].t2.unixTime());
652  }
653  fputc('\n', fout_);
654  fflush(fout_);
655 
656  for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
657  if (ieta == 0)
658  continue;
659  for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
660  if (EBDetId::validDetId(ieta, iphi)) {
661  EBDetId detId(ieta, iphi);
662  EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr = p.barrel(detId.hashedIndex());
663  fprintf(fout_, "P %d\t%f\t%f\t%f\n", (int)detId, corr.p1, corr.p2, corr.p3);
664  }
665  }
666  }
667 
668  for (int iZ = 1; iZ >= -1; --iZ) {
669  for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
670  for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
671  if (EEDetId::validDetId(iX, iY, iZ)) {
672  EEDetId detId(iX, iY, iZ);
673  EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr = p.endcap(detId.hashedIndex());
674  fprintf(fout_, "P %d\t%f\t%f\t%f\n", (int)detId, corr.p1, corr.p2, corr.p3);
675  }
676  }
677  }
678  }
679 }
static const int MIN_IPHI
Definition: EBDetId.h:135
static std::string timeToString(time_t t)
static const int IX_MIN
Definition: EEDetId.h:290
static const int IY_MIN
Definition: EEDetId.h:294
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
bool getData(T &iHolder) const
Definition: EventSetup.h:128
static constexpr int nLmes
static const int IX_MAX
Definition: EEDetId.h:298
static const int MAX_IPHI
Definition: EBDetId.h:137
std::vector< EcalLaserTimeStamp > EcalLaserTimeStampMap
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static const int MAX_IETA
Definition: EBDetId.h:136
edm::ESGetToken< EcalLaserAPDPNRatios, EcalLaserAPDPNRatiosRcd > laserAPDPNRatiosToken_
tuple cout
Definition: gather_cfg.py:144
static const int IY_MAX
Definition: EEDetId.h:302
const Item & barrel(size_t hashedIndex) const
const Item & endcap(size_t hashedIndex) const
void EcalLaserCondTools::fillDb ( CorrReader r)
private

Definition at line 263 of file EcalLaserCondTools.cc.

References c, gather_cfg::cout, eventList_, eventListFileName_, Exception, ntuplemaker::iline, dqmiodumpmetadata::n, nIovs_, nLmes, processIov(), EcalLaserCondTools::CorrReader::readTime(), skipIov_, submitPVValidationJobs::t, timeToString(), and verb_.

Referenced by analyze().

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

Definition at line 84 of file EcalLaserCondTools.cc.

References cms::cuda::assert(), alignCSCRings::corr, submitPVResolutionJobs::count, gather_cfg::cout, db_, alignCSCRings::e, Exception, ferr_, mergeVDriftHistosByStation::file, fnames_, compare_using_db::ifile, maxP_, minP_, ecaldqm::nCrystals(), nIovs_, nLmes, hltrates_dqm_sourceclient-live_cfg::offset, fireworks::p1, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p1, fireworks::p2, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p2, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p3, EcalLaserAPDPNRatios::setTime(), EcalLaserAPDPNRatios::setValue(), skipIov_, mps_update::status, submitPVValidationJobs::t, EcalLaserAPDPNRatios::EcalLaserTimeStamp::t1, EcalLaserAPDPNRatios::EcalLaserTimeStamp::t2, EcalLaserAPDPNRatios::EcalLaserTimeStamp::t3, timeToString(), verb_, cms::Exception::what(), and cond::service::PoolDBOutputService::writeOneIOV().

Referenced by analyze().

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

Definition at line 338 of file EcalLaserCondTools.cc.

References cond::service::PoolDBOutputService::beginOfTime(), alignCSCRings::corr, gather_cfg::cout, db_, alignCSCRings::e, EcalBarrel, EcalEndcap, Exception, ferr_, fromTime_, mps_fire::i, cond::service::PoolDBOutputService::isNewTagRequest(), maxP_, minP_, nLmes, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p1, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p2, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p3, EcalLaserCondTools::CorrReader::readPs(), EcalLaserAPDPNRatios::setTime(), EcalLaserAPDPNRatios::setValue(), DetId::subdetId(), submitPVValidationJobs::t, EcalLaserAPDPNRatios::EcalLaserTimeStamp::t1, EcalLaserAPDPNRatios::EcalLaserTimeStamp::t2, EcalLaserAPDPNRatios::EcalLaserTimeStamp::t3, timeToString(), toNth(), toTime_, verb_, cms::Exception::what(), and cond::service::PoolDBOutputService::writeOneIOV().

Referenced by fillDb().

338  {
339  static int iIov = 0;
340  ++iIov;
341 
342  // FILE* fdebug = 0;
343  // if(i==) fdebug = fopen("debug.txt", "w");
344 
345  // if(iIov <= skipIov_) { std::cout << "Skipping IOV " << iIov << "\n"; return; }
346 
347  cond::Time_t iovStart = 0;
348 
349  if (verb_ > 1) {
350  std::cout << "t1:" << t1 << "(" << timeToString(t1) << ") \n"
351  << "t3: " << t3 << "(" << timeToString(t3) << ")\nt2-t1: ";
352  for (int i = 0; i < EcalLaserCondTools::nLmes; ++i)
353  std::cout << t2[i] - t1 << "\t";
354 
355  std::cout << "\n";
356  }
357  if (t1 < fromTime_) {
358  std::cout << "Skipping IOV " << iIov << ", "
359  << ", which is before 'fromTime'," << timeToString(fromTime_) << "(" << fromTime_ << ").\n";
360  return;
361  }
362 
363  if (toTime_ != -1 && t3 < toTime_) {
364  std::cout << "Skipping IOV " << iIov << ", "
365  << ", which is beyond 'toTime'," << timeToString(toTime_) << "(" << toTime_ << ").\n";
366  return;
367  }
368 
369  if (t1 == 0) {
370  std::cout << "Skipping IOV with t1 = 0"
371  << "\n";
372  return;
373  }
374 
375  EcalLaserAPDPNRatios corrSet;
376 
378  iovStart = uint64_t(t1) << 32;
379  for (size_t i = 0; i < EcalLaserCondTools::nLmes; ++i) {
380  t.t1 = edm::Timestamp(uint64_t(t1) << 32);
381  t.t2 = edm::Timestamp(uint64_t(t2[i]) << 32);
382  t.t3 = edm::Timestamp(uint64_t(t3) << 32);
383  corrSet.setTime(i, t);
384  }
385 
386  constexpr int ncrystals = 75848;
387  std::set<int> detidList;
388  for (int i = 0; i < ncrystals; ++i) {
389  DetId detid;
390  //EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr = {0, 0, 0};
392  if (verb_ > 2)
393  std::cout << "Reading " << toNth(i + 1) << " crystal\n";
394  if (!r.readPs(detid, corr)) {
395  throw cms::Exception("LasCor") << "Failed to read " << toNth(i + 1) << " crystal correction.\n";
396  }
397 
398  std::pair<std::set<int>::iterator, bool> res = detidList.insert(int(detid));
399 
400  if (!res.second) { //detid already processed
401  std::cout << "Duplicate det id, for IOV " << iIov << " t1 = " << t1 << " detid = " << int(detid) << "\n";
402  }
403 
404  if (!isfinite(corr.p1) || !isfinite(corr.p2) || !isfinite(corr.p3) || corr.p1 < minP_ || corr.p1 > maxP_ ||
405  corr.p2 < minP_ || corr.p2 > maxP_ || corr.p3 < minP_ || corr.p3 > 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;
408  }
409 
410  if (verb_ > 2) {
411  if (detid.subdetId() == EcalBarrel) {
412  std::cout << EBDetId(detid);
413  } else if (detid.subdetId() == EcalEndcap) {
414  std::cout << EEDetId(detid);
415  } else {
416  std::cout << (int)detid;
417  }
418  std::cout << ": "
419  << "p1 = " << corr.p1 << "\t"
420  << "p2 = " << corr.p2 << "\t"
421  << "p3 = " << corr.p3 << "\n";
422  }
423 
424  corrSet.setValue((int)detid, corr);
425  }
426 
427  try {
428  //Write correction set in DB (one IOV):
429  if (db_->isNewTagRequest("EcalLaserAPDPNRatiosRcd")) {
430  if (verb_)
431  std::cout << "First IOV, extending starting time.\n";
432 
433  iovStart = db_->beginOfTime();
434  }
435  timeval t;
436  gettimeofday(&t, nullptr);
437  if (verb_ > 1)
438  std::cout << "[" << timeToString(t.tv_sec) << "] "
439  << "Write IOV " << iIov << " starting from " << timeToString(iovStart >> 32) << "... ";
440  db_->writeOneIOV(corrSet, iovStart, "EcalLaserAPDPNRatiosRcd");
441  } catch (const cms::Exception& e) {
442  std::cout << "Failed.\nException cathed while writting to cond DB" << e.what() << "\n";
443  }
444  std::cout << "Suceeded.\n";
445 }
static std::string timeToString(time_t t)
edm::Service< cond::service::PoolDBOutputService > db_
void setTime(int hashedIndex, const EcalLaserTimeStamp &value)
unsigned long long Time_t
Definition: Time.h:14
bool isNewTagRequest(const std::string &recordName)
static constexpr int nLmes
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
char const * what() const noexceptoverride
Definition: Exception.cc:103
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
Definition: DetId.h:17
unsigned long long uint64_t
Definition: Time.h:13
void setValue(uint32_t rawId, const EcalLaserAPDPNpair &value)
static std::string toNth(int n)
tuple cout
Definition: gather_cfg.py:144
std::string EcalLaserCondTools::timeToString ( time_t  t)
staticprivate

Definition at line 613 of file EcalLaserCondTools.cc.

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

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

613  {
614  char buf[256];
615  struct tm lt;
616  localtime_r(&t, &lt);
617  strftime(buf, sizeof(buf), "%F %R:%S", &lt);
618  buf[sizeof(buf) - 1] = 0;
619  return std::string(buf);
620 }
< trclass="colgroup">< tdclass="colgroup"colspan=5 > DT local reconstruction</td ></tr >< tr >< td >< ahref="classDTRecHit1DPair.html"> DTRecHit1DPair</a ></td >< td >< ahref="DataFormats_DTRecHit.html"> edm::RangeMap & lt
std::string EcalLaserCondTools::toNth ( int  n)
staticprivate

Definition at line 590 of file EcalLaserCondTools.cc.

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

Referenced by processIov().

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

Member Data Documentation

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

Definition at line 94 of file EcalLaserCondTools.h.

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

FILE* EcalLaserCondTools::eventList_
private

Definition at line 89 of file EcalLaserCondTools.h.

Referenced by EcalLaserCondTools(), and fillDb().

std::string EcalLaserCondTools::eventListFileName_
private

Definition at line 90 of file EcalLaserCondTools.h.

Referenced by EcalLaserCondTools(), and fillDb().

FILE* EcalLaserCondTools::ferr_
private
std::vector<std::string> EcalLaserCondTools::fnames_
private
FILE* EcalLaserCondTools::fout_
private

Definition at line 88 of file EcalLaserCondTools.h.

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

int EcalLaserCondTools::fromTime_
private

Definition at line 97 of file EcalLaserCondTools.h.

Referenced by processIov().

edm::ESGetToken<EcalLaserAPDPNRatios, EcalLaserAPDPNRatiosRcd> EcalLaserCondTools::laserAPDPNRatiosToken_
private

Definition at line 87 of file EcalLaserCondTools.h.

Referenced by dbToAscii(), and EcalLaserCondTools().

double EcalLaserCondTools::maxP_
private

Definition at line 99 of file EcalLaserCondTools.h.

Referenced by from_hdf_to_db(), and processIov().

double EcalLaserCondTools::minP_
private

Definition at line 99 of file EcalLaserCondTools.h.

Referenced by from_hdf_to_db(), and processIov().

std::string EcalLaserCondTools::mode_
private

Definition at line 92 of file EcalLaserCondTools.h.

Referenced by analyze(), and EcalLaserCondTools().

int EcalLaserCondTools::nIovs_
private

Definition at line 96 of file EcalLaserCondTools.h.

Referenced by fillDb(), and from_hdf_to_db().

constexpr int EcalLaserCondTools::nLmes = 92
staticprivate

Number of extended laser monitoring regions

Definition at line 29 of file EcalLaserCondTools.h.

Referenced by dbToAscii(), fillDb(), from_hdf_to_db(), processIov(), and EcalLaserCondTools::FileReader::readTime().

int EcalLaserCondTools::skipIov_
private

Definition at line 95 of file EcalLaserCondTools.h.

Referenced by fillDb(), and from_hdf_to_db().

int EcalLaserCondTools::toTime_
private

Definition at line 98 of file EcalLaserCondTools.h.

Referenced by processIov().

int EcalLaserCondTools::verb_
private