File indexing completed on 2024-04-06 12:15:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <fstream>
0020 #include <iostream>
0021 #include <sstream>
0022 #include <string>
0023 #include <vector>
0024 #include <cmath>
0025 #include <iomanip>
0026
0027 #include "FWCore/Framework/interface/Frameworkfwd.h"
0028 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/EventSetup.h"
0031 #include "FWCore/Framework/interface/MakerMacros.h"
0032
0033 class TestCompareDDDumpFiles : public edm::one::EDAnalyzer<> {
0034 public:
0035 explicit TestCompareDDDumpFiles(const edm::ParameterSet&);
0036 ~TestCompareDDDumpFiles() override;
0037
0038 void beginJob() override {}
0039 void analyze(edm::Event const&, edm::EventSetup const&) override;
0040 void endJob() override {}
0041
0042 private:
0043 std::string fname1_;
0044 std::string fname2_;
0045 double tol_;
0046 std::ifstream f1_;
0047 std::ifstream f2_;
0048 };
0049
0050 TestCompareDDDumpFiles::TestCompareDDDumpFiles(const edm::ParameterSet& ps)
0051 : fname1_(ps.getParameter<std::string>("dumpFile1")),
0052 fname2_(ps.getParameter<std::string>("dumpFile2")),
0053 tol_(ps.getUntrackedParameter<double>("tolerance", 0.000001)),
0054 f1_(fname1_.c_str(), std::ios::in),
0055 f2_(fname2_.c_str(), std::ios::in) {
0056 if (!f1_ || !f2_) {
0057 throw cms::Exception("MissingFileDDTest") << fname1_ << " and/or " << fname2_ << " do not exist.";
0058 }
0059 }
0060
0061 TestCompareDDDumpFiles::~TestCompareDDDumpFiles() {
0062 f1_.close();
0063 f2_.close();
0064 }
0065
0066 void TestCompareDDDumpFiles::analyze(const edm::Event&, const edm::EventSetup&) {
0067 std::string l1, l2, ts;
0068 std::vector<double> t1(3), t2(3), r1(9), r2(9);
0069 double diffv;
0070 while (!f1_.eof() && !f2_.eof()) {
0071 getline(f1_, l1, ',');
0072 getline(f2_, l2, ',');
0073 if (l1 != l2) {
0074 std::cout << "Lines don't match or are out of synchronization."
0075 << " The difference is much bigger than just the numbers,"
0076 << " actual parts are missing or added. This program "
0077 << " does not handle this at this time... use diff first." << std::endl
0078 << "[" << l1 << "]" << std::endl
0079 << "[" << l2 << "]" << std::endl
0080 << std::endl;
0081 break;
0082 }
0083
0084
0085
0086
0087
0088 size_t i = 0;
0089 while (i < 3) {
0090 ts.clear();
0091 getline(f1_, ts, ',');
0092
0093 std::istringstream s1(ts);
0094 s1 >> t1[i++];
0095 }
0096
0097 i = 0;
0098 while (i < 8) {
0099 ts.clear();
0100 getline(f1_, ts, ',');
0101
0102 std::istringstream s1(ts);
0103 s1 >> r1[i++];
0104 }
0105 ts.clear();
0106 getline(f1_, ts);
0107 std::istringstream s2(ts);
0108 s2 >> r1[8];
0109
0110 i = 0;
0111 while (i < 3) {
0112 ts.clear();
0113 getline(f2_, ts, ',');
0114
0115 std::istringstream s1(ts);
0116 s1 >> t2[i++];
0117 }
0118
0119 i = 0;
0120 while (i < 8) {
0121 ts.clear();
0122 getline(f2_, ts, ',');
0123
0124 std::istringstream s1(ts);
0125 s1 >> r2[i++];
0126 }
0127 ts.clear();
0128 getline(f2_, ts);
0129 std::istringstream s3(ts);
0130 s3 >> r2[8];
0131
0132
0133
0134
0135
0136
0137
0138 std::vector<bool> cerrorind;
0139 cerrorind.reserve(3);
0140 for (i = 0; i < 3; i++) {
0141
0142
0143
0144
0145 diffv = std::fabs(t1[i] - t2[i]);
0146 if (diffv > tol_)
0147 cerrorind[i] = true;
0148 else
0149 cerrorind[i] = false;
0150 }
0151 if (cerrorind[0] || cerrorind[1] || cerrorind[2])
0152 std::cout << l1;
0153 for (i = 0; i < 3; ++i) {
0154 diffv = std::fabs(t1[i] - t2[i]);
0155 if (cerrorind[i] && diffv > tol_) {
0156 std::cout << " coordinate ";
0157 if (i == 0)
0158 std::cout << "x ";
0159 else if (i == 1)
0160 std::cout << "y ";
0161 else if (i == 2)
0162 std::cout << "z ";
0163 std::cout << " is different by: " << std::setw(13) << std::setprecision(7) << std::fixed << diffv << " mm ";
0164 }
0165 }
0166 bool rerror(false);
0167 for (i = 0; i < 9; i++) {
0168
0169
0170 diffv = std::fabs(r1[i] - r2[i]);
0171 if (diffv > tol_)
0172 rerror = true;
0173 }
0174 if (rerror && !cerrorind[0] && !cerrorind[1] && !cerrorind[2]) {
0175 std::cout << l1 << " ";
0176 }
0177 if (rerror) {
0178 for (i = 0; i < 9; i++) {
0179
0180
0181 diffv = std::fabs(r1[i] - r2[i]);
0182 if (diffv > tol_) {
0183
0184 std::cout << " index " << i << " of rotation matrix differs by " << std::setw(13) << std::setprecision(7)
0185 << std::fixed << r1[i] - r2[i];
0186 }
0187 }
0188 std::cout << std::endl;
0189 } else if (cerrorind[0] || cerrorind[1] || cerrorind[2]) {
0190 std::cout << std::endl;
0191 }
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208 }
0209 }
0210
0211 DEFINE_FWK_MODULE(TestCompareDDDumpFiles);