File indexing completed on 2024-04-06 12:02:49
0001
0002
0003
0004
0005
0006
0007
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include <cmath>
0013 #include <fstream>
0014 #include <iostream>
0015 #include <map>
0016 #include <sstream>
0017 #include <stdexcept>
0018 #include <string>
0019
0020 #include "FWCore/Framework/interface/EventSetup.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022
0023 #include "CondTools/DT/test/validate/DTT0ValidateDBRead.h"
0024 #include "CondFormats/DTObjects/interface/DTT0.h"
0025 #include "CondFormats/DataRecord/interface/DTT0Rcd.h"
0026
0027 DTT0ValidateDBRead::DTT0ValidateDBRead(edm::ParameterSet const& p)
0028 : dataFileName(p.getParameter<std::string>("chkFile")),
0029 elogFileName(p.getParameter<std::string>("logFile")),
0030 dtT0Token_(esConsumes()) {}
0031
0032 DTT0ValidateDBRead::DTT0ValidateDBRead(int i) : dtT0Token_(esConsumes()) {}
0033
0034 void DTT0ValidateDBRead::analyze(const edm::Event& e, const edm::EventSetup& context) {
0035 using namespace edm::eventsetup;
0036
0037 std::cout << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
0038 std::cout << " ---EVENT NUMBER " << e.id().event() << std::endl;
0039 std::stringstream run_fn;
0040 run_fn << "run" << e.id().run() << dataFileName;
0041 std::ifstream chkFile(run_fn.str().c_str());
0042 std::ofstream logFile(elogFileName.c_str(), std::ios_base::app);
0043 auto t0 = context.getHandle(dtT0Token_);
0044 std::cout << t0->version() << std::endl;
0045 std::cout << std::distance(t0->begin(), t0->end()) << " data in the container" << std::endl;
0046 int whe;
0047 int sta;
0048 int sec;
0049 int qua;
0050 int lay;
0051 int cel;
0052 float t0mean;
0053 float t0rms;
0054 float ckmean;
0055 float ckrms;
0056 int status;
0057 DTT0::const_iterator iter = t0->begin();
0058 DTT0::const_iterator iend = t0->end();
0059 while (iter != iend) {
0060 const DTT0Data& t0Data = *iter++;
0061 int channelId = t0Data.channelId;
0062 if (channelId == 0)
0063 continue;
0064 DTWireId id(channelId);
0065 status = t0->get(id, t0mean, t0rms, DTTimeUnits::counts);
0066 if (status)
0067 logFile << "ERROR while getting cell T0 " << id.wheel() << " " << id.station() << " " << id.sector() << " "
0068 << id.superlayer() << " " << id.layer() << " " << id.wire() << " , status = " << status << std::endl;
0069 if ((fabs(t0Data.t0mean - t0mean) > 0.0001) || (fabs(t0Data.t0rms - t0rms) > 0.0001))
0070 logFile << "MISMATCH WHEN READING cell T0 " << id.wheel() << " " << id.station() << " " << id.sector() << " "
0071 << id.superlayer() << " " << id.layer() << " " << id.wire() << " : " << t0Data.t0mean << " "
0072 << t0Data.t0rms << " -> " << t0mean << " " << t0rms << std::endl;
0073 }
0074
0075 while (chkFile >> whe >> sta >> sec >> qua >> lay >> cel >> ckmean >> ckrms) {
0076 status = t0->get(whe, sta, sec, qua, lay, cel, t0mean, t0rms, DTTimeUnits::counts);
0077 if ((fabs(ckmean - t0mean) > 0.0001) || (fabs(ckrms - t0rms) > 0.0001))
0078 logFile << "MISMATCH IN WRITING AND READING cell T0 " << whe << " " << sta << " " << sec << " " << qua << " "
0079 << lay << " " << cel << " : " << ckmean << " " << ckrms << " -> " << t0mean << " " << t0rms << std::endl;
0080 }
0081 }
0082
0083 void DTT0ValidateDBRead::endJob() {
0084 std::ifstream logFile(elogFileName.c_str());
0085 char* line = new char[1000];
0086 int errors = 0;
0087 std::cout << "T0 validation result:" << std::endl;
0088 while (logFile.getline(line, 1000)) {
0089 std::cout << line << std::endl;
0090 errors++;
0091 }
0092 if (!errors) {
0093 std::cout << " ********************************* " << std::endl;
0094 std::cout << " *** *** " << std::endl;
0095 std::cout << " *** NO ERRORS FOUND *** " << std::endl;
0096 std::cout << " *** *** " << std::endl;
0097 std::cout << " ********************************* " << std::endl;
0098 }
0099 return;
0100 }
0101
0102 DEFINE_FWK_MODULE(DTT0ValidateDBRead);