File indexing completed on 2024-04-06 12:02:56
0001 #include "CondTools/Ecal/interface/EcalLaser_weekly_Handler.h"
0002 #include "OnlineDB/EcalCondDB/interface/EcalLogicID.h"
0003 #include "OnlineDB/EcalCondDB/interface/LMFSextuple.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0005 #include "CondCore/CondDB/interface/Time.h"
0006 #include "DataFormats/Provenance/interface/Timestamp.h"
0007 #include "OnlineDB/EcalCondDB/interface/Tm.h"
0008
0009 #include <iostream>
0010 #include <iomanip>
0011 #include <sstream>
0012
0013 popcon::EcalLaser_weekly_Handler::EcalLaser_weekly_Handler(const edm::ParameterSet& ps)
0014 : m_name(ps.getUntrackedParameter<std::string>("name", "EcalLaser_weekly_Handler")) {
0015
0016 std::cout << "EcalLaser Source handler constructor\n" << std::endl;
0017 }
0018
0019 popcon::EcalLaser_weekly_Handler::~EcalLaser_weekly_Handler() {
0020
0021 }
0022
0023 void popcon::EcalLaser_weekly_Handler::getNewObjects() {
0024
0025
0026
0027 const size_t nLmes = 92;
0028
0029 uint64_t t1, t2, t3;
0030
0031 int iIov = 0;
0032
0033 std::cout << "------- Ecal -> getNewObjects\n";
0034
0035 unsigned long long max_since = 1;
0036 Ref payload = lastPayload();
0037
0038
0039
0040 max_since = tagInfo().lastInterval.since;
0041
0042 Tm max_since_tm(max_since);
0043
0044 edm::Timestamp t_min = edm::Timestamp(18446744073709551615ULL);
0045
0046 const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap& laserRatiosMap = payload->getLaserMap();
0047 std::cout << "payload->getLaserMap(): OK " << std::endl;
0048 std::cout << "Its size is " << laserRatiosMap.size() << std::endl;
0049 const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& laserTimeMap = payload->getTimeMap();
0050 std::cout << "payload->getTimeMap(): OK " << std::endl;
0051 std::cout << "Last Object in Offline DB has SINCE = " << max_since << " -> " << max_since_tm.cmsNanoSeconds() << " ("
0052 << max_since_tm << ")"
0053 << " and SIZE = " << tagInfo().size << std::endl;
0054
0055
0056 for (int i = 0; i < 92; i++) {
0057 EcalLaserAPDPNRatios::EcalLaserTimeStamp timestamp = laserTimeMap[i];
0058 if (t_min > timestamp.t1) {
0059 t_min = timestamp.t1;
0060 }
0061 }
0062
0063 std::cout << "WOW: we just retrieved the last valid record from DB " << std::endl;
0064
0065 std::cout << "Its tmin is " << Tm(t_min.value()) << std::endl;
0066
0067
0068 EcalLaserAPDPNRatios* corrSet = new EcalLaserAPDPNRatios;
0069
0070 EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr;
0071 int fileIOV;
0072 std::cout << " which input IOV do you want " << std::endl;
0073 std::cin >> fileIOV;
0074 std::ifstream fWeek;
0075 std::ostringstream oss;
0076 oss << fileIOV;
0077 std::string fname = "../../../Tools/DBDump/bin/weekly_" + oss.str();
0078 fWeek.open(fname.c_str());
0079 if (!fWeek.is_open()) {
0080 std::cout << "ERROR : can't open file 'weekly_" << oss.str() << std::endl;
0081 exit(-1);
0082 }
0083 std::cout << " file weekly_" << oss.str() << " opened" << std::endl;
0084
0085
0086 std::ifstream fRunStartTime;
0087 fRunStartTime.open("RunStartTime");
0088 if (!fRunStartTime.is_open()) {
0089 std::cout << "ERROR : cannot open file RunStartTime" << std::endl;
0090 exit(1);
0091 }
0092 uint64_t iov = 0;
0093 while (!fRunStartTime.eof()) {
0094 int run;
0095 uint64_t start;
0096 fRunStartTime >> run >> start;
0097 if (run == fileIOV) {
0098 iov = start;
0099 std::cout << "run " << run << " timestamp " << start << "\n";
0100 break;
0101 } else if (run == fileIOV) {
0102 std::cout << " run " << fileIOV << " not found in RunStartTime. Let us give up" << std::endl;
0103 exit(-1);
0104 }
0105 }
0106 fRunStartTime.close();
0107 EcalLaserAPDPNRatios::EcalLaserTimeStamp t;
0108
0109 t1 = iov;
0110
0111 t3 = t1 + 7792788661862400;
0112 t2 = t1 + (t3 - t1) / 2;
0113
0114 for (size_t i = 0; i < nLmes; ++i) {
0115 t.t1 = edm::Timestamp(t1);
0116 t.t2 = edm::Timestamp(t2);
0117 t.t3 = edm::Timestamp(t3);
0118 corrSet->setTime(i, t);
0119 }
0120
0121 int rawId;
0122 float corrp;
0123 for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
0124 EBDetId ebId = EBDetId::unhashIndex(iChannel);
0125 fWeek >> rawId >> corrp;
0126 corr.p1 = corr.p2 = corr.p3 = corrp;
0127 corrSet->setValue((int)ebId, corr);
0128 }
0129 for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
0130 EEDetId eeId = EEDetId::unhashIndex(iChannel);
0131 fWeek >> rawId >> corrp;
0132 corr.p1 = corr.p2 = corr.p3 = corrp;
0133 corrSet->setValue((int)eeId, corr);
0134 }
0135 fWeek.close();
0136
0137 std::cout << "Write IOV " << iIov << " starting from " << fileIOV << "... " << std::endl;
0138
0139 m_to_transfer.push_back(std::make_pair(corrSet, fileIOV));
0140 iIov++;
0141
0142 std::cout << "Ecal -> end of getNewObjects -----------\n";
0143 }