File indexing completed on 2024-04-06 12:30:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <algorithm>
0014 #include <cstdlib>
0015 #include <fstream>
0016 #include <iomanip>
0017 #include <iostream>
0018 #include <map>
0019 #include <sstream>
0020 #include <string>
0021 #include <vector>
0022 #include <cstdint>
0023
0024 std::pair<std::string, std::string> splitInto2(const std::string& list) {
0025 std::string list1, list2;
0026 uint32_t first = (list.find(":") == std::string::npos) ? 0 : (list.find(":") + 1);
0027 uint32_t last(list.size() + 1);
0028 if (first > 0) {
0029 list2 = list.substr(first, last - first - 1);
0030 list1 = list.substr(0, first - 1);
0031 } else {
0032 list1 = list;
0033 list2 = "";
0034 }
0035 return std::make_pair(list1, list2);
0036 }
0037
0038 void CompareFiles(const char* fileFile1, const char* fileFile2, int debug) {
0039 std::map<std::string, std::string> solidFile1;
0040 std::map<std::string, std::string> solidFile2;
0041 std::map<std::string, int> solidFile1Dup;
0042 std::map<std::string, int> solidFile2Dup;
0043 char buffer[1000];
0044 std::string name;
0045 std::ifstream fInput1(fileFile1);
0046 unsigned int sizeFile1(0), sizeFile2(0);
0047 if (!fInput1.good()) {
0048 std::cout << "Cannot open file " << fileFile1 << std::endl;
0049 } else {
0050 while (fInput1.getline(buffer, 1000)) {
0051 std::pair<std::string, std::string> items = splitInto2(std::string(buffer));
0052 if (solidFile1.find(items.first) == solidFile1.end())
0053 solidFile1[items.first] = items.second;
0054 else if (solidFile1Dup.find(items.first) == solidFile1Dup.end())
0055 solidFile1Dup[items.first] = 1;
0056 else
0057 ++solidFile1Dup[items.first];
0058 }
0059 fInput1.close();
0060 sizeFile1 = solidFile1.size();
0061 }
0062 std::ifstream fInput2(fileFile2);
0063 if (!fInput2.good()) {
0064 std::cout << "Cannot open file " << fileFile2 << std::endl;
0065 } else {
0066 while (fInput2.getline(buffer, 1000)) {
0067 std::pair<std::string, std::string> items = splitInto2(std::string(buffer));
0068 if (solidFile2.find(items.first) == solidFile2.end())
0069 solidFile2[items.first] = items.second;
0070 else if (solidFile2Dup.find(items.first) == solidFile2Dup.end())
0071 solidFile2Dup[items.first] = 1;
0072 else
0073 ++solidFile2Dup[items.first];
0074 }
0075 fInput2.close();
0076 sizeFile2 = solidFile2.size();
0077 }
0078 std::cout << "Reads " << sizeFile1 << " names from " << fileFile1 << " and " << sizeFile2 << " names from "
0079 << fileFile2 << std::endl;
0080
0081 std::cout << "\n" << solidFile1Dup.size() << " more than one entry for a given name in " << fileFile1 << std::endl;
0082 int i1(0);
0083 for (std::map<std::string, int>::iterator itr = solidFile1Dup.begin(); itr != solidFile1Dup.end(); ++itr, ++i1)
0084 std::cout << "[" << i1 << "] " << itr->first << " # " << itr->second << std::endl;
0085
0086 std::cout << "\n" << solidFile1Dup.size() << " more than one entry for a given name in " << fileFile2 << std::endl;
0087 int i2(0);
0088 for (std::map<std::string, int>::iterator itr = solidFile2Dup.begin(); itr != solidFile2Dup.end(); ++itr, ++i2)
0089 std::cout << "[" << i2 << "] " << itr->first << " # " << itr->second << std::endl;
0090
0091 std::cout << "\nEntry in " << fileFile1 << " vs entry in " << fileFile2 << std::endl;
0092 int k3(0);
0093 std::vector<std::string> v1;
0094 for (std::map<std::string, std::string>::iterator ktr = solidFile1.begin(); ktr != solidFile1.end(); ++ktr) {
0095 if (solidFile2.find(ktr->first) == solidFile2.end())
0096 v1.emplace_back(ktr->first);
0097 else if (solidFile2[ktr->first] == ktr->second)
0098 ++k3;
0099 else
0100 std::cout << ktr->first << " in File1 " << ktr->second << "\n in File2 " << solidFile2[ktr->first]
0101 << std::endl;
0102 }
0103 std::cout << "\n" << k3 << " entries match between " << fileFile1 << " and " << fileFile2 << std::endl;
0104 std::cout << v1.size() << " entries in " << fileFile1 << " are not in " << fileFile2 << std::endl;
0105 for (auto const& it : v1) {
0106 std::cout << it << std::endl;
0107 }
0108
0109 int k4(0);
0110 std::vector<std::string> v2;
0111 for (std::map<std::string, std::string>::iterator ktr = solidFile2.begin(); ktr != solidFile2.end(); ++ktr) {
0112 if (solidFile1.find(ktr->first) == solidFile1.end())
0113 v2.emplace_back(ktr->first);
0114 else if (solidFile1[ktr->first] == ktr->second)
0115 ++k4;
0116 }
0117 std::cout << "\n" << k4 << " entries match between " << fileFile2 << " and " << fileFile1 << std::endl;
0118 std::cout << v2.size() << " entries in " << fileFile2 << " are not in " << fileFile1 << std::endl;
0119 for (auto const& it : v2) {
0120 std::cout << it << std::endl;
0121 }
0122 }
0123
0124 int main(int argc, char* argv[]) {
0125 if (argc <= 3) {
0126 std::cout << "Please give a minimum of 3 arguments \n"
0127 << "name of the first input file (dd4hep) \n"
0128 << "name of the second input file (ddd) \n"
0129 << "debug flag (0 for minimum printout)\n"
0130 << std::endl;
0131 return 0;
0132 }
0133
0134 const char* infile1 = argv[1];
0135 const char* infile2 = argv[2];
0136 const int debug = std::atoi(argv[3]);
0137 CompareFiles(infile1, infile2, debug);
0138 return 0;
0139 }