Go to the documentation of this file.00001 #include "CondTools/Ecal/interface/EcalLaser_weekly_Handler.h"
00002 #include "OnlineDB/EcalCondDB/interface/EcalLogicID.h"
00003 #include "OnlineDB/EcalCondDB/interface/LMFSextuple.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00005 #include "CondCore/DBCommon/interface/Time.h"
00006 #include "DataFormats/Provenance/interface/Timestamp.h"
00007 #include "OnlineDB/EcalCondDB/interface/Tm.h"
00008
00009 #include<iostream>
00010 #include<iomanip>
00011 #include <sstream>
00012
00013 popcon::EcalLaser_weekly_Handler::EcalLaser_weekly_Handler(const edm::ParameterSet & ps)
00014 : m_name(ps.getUntrackedParameter<std::string>("name","EcalLaser_weekly_Handler")) {
00015
00016 std::cout << "EcalLaser Source handler constructor\n" << std::endl;
00017 }
00018
00019 popcon::EcalLaser_weekly_Handler::~EcalLaser_weekly_Handler() {
00020
00021 }
00022
00023 void popcon::EcalLaser_weekly_Handler::getNewObjects() {
00024
00025
00026
00027 const size_t nLmes = 92;
00028
00029 uint64_t t1, t2, t3;
00030
00031 int iIov = 0;
00032
00033 std::cout << "------- Ecal -> getNewObjects\n";
00034
00035
00036 unsigned long long max_since= 1;
00037 Ref payload= lastPayload();
00038
00039
00040
00041 max_since=tagInfo().lastInterval.first;
00042
00043 Tm max_since_tm(max_since);
00044
00045 edm::Timestamp t_min= edm::Timestamp(18446744073709551615ULL);
00046
00047 const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap& laserRatiosMap =
00048 payload->getLaserMap();
00049 std::cout << "payload->getLaserMap(): OK " << std::endl;
00050 std::cout << "Its size is " << laserRatiosMap.size() << std::endl;
00051 const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& laserTimeMap =
00052 payload->getTimeMap();
00053 std::cout << "payload->getTimeMap(): OK " << std::endl;
00054 std::cout << "Last Object in Offline DB has SINCE = " << max_since
00055 << " -> " << max_since_tm.cmsNanoSeconds()
00056 << " (" << max_since_tm << ")"
00057 << " and SIZE = " << tagInfo().size
00058 << std::endl;
00059
00060
00061 for (int i=0; i<92; i++) {
00062 EcalLaserAPDPNRatios::EcalLaserTimeStamp timestamp = laserTimeMap[i];
00063 if( t_min > timestamp.t1) {
00064 t_min=timestamp.t1;
00065 }
00066 }
00067
00068 std::cout <<"WOW: we just retrieved the last valid record from DB "
00069 << std::endl;
00070
00071 std::cout <<"Its tmin is "<< Tm(t_min.value()) << std::endl;
00072
00073
00074 EcalLaserAPDPNRatios* corrSet = new EcalLaserAPDPNRatios;
00075
00076 EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr = {0, 0, 0};
00077 int fileIOV;
00078 std::cout << " which input IOV do you want " << std::endl;
00079 std::cin >> fileIOV;
00080 std::ifstream fWeek;
00081 std::ostringstream oss;
00082 oss << fileIOV;
00083 std::string fname = "../../../Tools/DBDump/bin/weekly_" + oss.str();
00084 fWeek.open(fname.c_str());
00085 if(!fWeek.is_open()) {
00086 std::cout << "ERROR : can't open file 'weekly_" << oss.str() << std::endl;
00087 exit(-1);
00088 }
00089 std::cout << " file weekly_" << oss.str() << " opened" << std::endl;
00090
00091
00092 std::ifstream fRunStartTime;
00093 fRunStartTime.open("RunStartTime");
00094 if(!fRunStartTime.is_open()) {
00095 std::cout << "ERROR : cannot open file RunStartTime" << std::endl;
00096 exit (1);
00097 }
00098 uint64_t iov = 0;
00099 while(!fRunStartTime.eof()) {
00100 int run;
00101 uint64_t start;
00102 fRunStartTime >> run >> start;
00103 if(run == fileIOV) {
00104 iov = start;
00105 std::cout << "run " << run << " timestamp " << start << "\n";
00106 break;
00107 }
00108 else if (run == fileIOV) {
00109 std::cout << " run " << fileIOV << " not found in RunStartTime. Let us give up" << std::endl;
00110 exit(-1);
00111 }
00112 }
00113 fRunStartTime.close();
00114 EcalLaserAPDPNRatios::EcalLaserTimeStamp t;
00115
00116 t1 = iov;
00117
00118 t3 = t1 + 7792788661862400;
00119 t2 = t1 + (t3 - t1)/2;
00120
00121 for(size_t i = 0; i < nLmes; ++i){
00122 t.t1 = edm::Timestamp(t1);
00123 t.t2 = edm::Timestamp(t2);
00124 t.t3 = edm::Timestamp(t3);
00125 corrSet->setTime(i, t);
00126 }
00127
00128 int rawId;
00129 float corrp;
00130 for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
00131 EBDetId ebId = EBDetId::unhashIndex(iChannel);
00132 fWeek >> rawId >> corrp;
00133 corr.p1=corr.p2=corr.p3 = corrp;
00134 corrSet->setValue((int)ebId, corr );
00135 }
00136 for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
00137 EEDetId eeId = EEDetId::unhashIndex(iChannel);
00138 fWeek >> rawId >> corrp;
00139 corr.p1=corr.p2=corr.p3 = corrp;
00140 corrSet->setValue((int)eeId, corr );
00141 }
00142 fWeek.close();
00143
00144 std::cout << "Write IOV " << iIov << " starting from " << fileIOV << "... "<< std::endl;
00145
00146 m_to_transfer.push_back(std::make_pair(corrSet, fileIOV));
00147 iIov++;
00148
00149 std::cout << "Ecal -> end of getNewObjects -----------\n";
00150 }