File indexing completed on 2023-10-25 10:04:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <algorithm>
0018 #include <cstdlib>
0019 #include <fstream>
0020 #include <iostream>
0021 #include <map>
0022 #include <string>
0023 #include <vector>
0024
0025 std::vector<std::string> splitString(const std::string& fLine) {
0026 std::vector<std::string> result;
0027 int start = 0;
0028 bool empty = true;
0029 for (unsigned i = 0; i <= fLine.size(); i++) {
0030 if (fLine[i] == ' ' || i == fLine.size()) {
0031 if (!empty) {
0032 std::string item(fLine, start, i - start);
0033 result.push_back(item);
0034 empty = true;
0035 }
0036 start = i + 1;
0037 } else {
0038 if (empty)
0039 empty = false;
0040 }
0041 }
0042 return result;
0043 }
0044
0045 std::string noNameSpace(std::string& name) {
0046 std::size_t found = name.find(":");
0047 std::string nam = (found == std::string::npos) ? name : name.substr(found + 1, (name.size() - found));
0048 return nam;
0049 }
0050
0051 void CompareFiles(const char* sdFileDDD,
0052 const char* sdFileDD4hep,
0053 const char* touchFileDDD,
0054 const char* touchFileDD4hep,
0055 const char* mbFile,
0056 int debug) {
0057 std::vector<std::string> sdDDD, sdDD4hep, touchDDD, touchDD4hep, mbVol;
0058 char buffer[1000];
0059 std::ifstream fInput1(sdFileDDD);
0060 int all(0), good(0), ee(0), hesil(0), hesci(0);
0061 if (!fInput1.good()) {
0062 std::cout << "Cannot open file " << sdFileDDD << std::endl;
0063 } else {
0064 while (fInput1.getline(buffer, 1000)) {
0065 std::vector<std::string> items = splitString(std::string(buffer));
0066 ++all;
0067 if (items.size() > 0) {
0068 sdDDD.emplace_back(items[0]);
0069 if (((debug / 10) % 10) > 0)
0070 std::cout << "[" << good << "] " << sdDDD.back() << std::endl;
0071 ++good;
0072 if (sdDDD.back().find("EE") != std::string::npos) {
0073 ++ee;
0074 } else if (sdDDD.back().find("HESil") != std::string::npos) {
0075 ++hesil;
0076 } else if (sdDDD.back().find("HESci") != std::string::npos) {
0077 ++hesci;
0078 }
0079 }
0080 }
0081 fInput1.close();
0082 std::cout << "Reads " << all << ":" << good << " names from " << sdFileDDD << " with " << ee << ":" << hesil << ":"
0083 << hesci << " for EE:HESilicon:HEScintillator" << std::endl;
0084 }
0085 std::ifstream fInput2(sdFileDD4hep);
0086 all = good = ee = hesil = hesci = 0;
0087 if (!fInput2.good()) {
0088 std::cout << "Cannot open file " << sdFileDD4hep << std::endl;
0089 } else {
0090 while (fInput2.getline(buffer, 1000)) {
0091 std::vector<std::string> items = splitString(std::string(buffer));
0092 ++all;
0093 if (items.size() > 0) {
0094 sdDD4hep.emplace_back(noNameSpace(items[0]));
0095 if (((debug / 10) % 10) > 0)
0096 std::cout << "[" << good << "] " << sdDD4hep.back() << std::endl;
0097 ++good;
0098 if (sdDD4hep.back().find("EE") != std::string::npos) {
0099 ++ee;
0100 } else if (sdDD4hep.back().find("HESil") != std::string::npos) {
0101 ++hesil;
0102 } else if (sdDD4hep.back().find("HESci") != std::string::npos) {
0103 ++hesci;
0104 }
0105 }
0106 }
0107 fInput2.close();
0108 std::cout << "Reads " << all << ":" << good << " names from " << sdFileDD4hep << " with " << ee << ":" << hesil
0109 << ":" << hesci << " for EE:HESilicon:HEScintillator" << std::endl;
0110 }
0111 std::ifstream fInput3(touchFileDDD);
0112 all = good = 0;
0113 if (!fInput3.good()) {
0114 std::cout << "Cannot open file " << touchFileDDD << std::endl;
0115 } else {
0116 while (fInput3.getline(buffer, 1000)) {
0117 std::vector<std::string> items = splitString(std::string(buffer));
0118 ++all;
0119 if (items.size() > 0) {
0120 touchDDD.emplace_back(items[0]);
0121 if (((debug / 100) % 10) > 0)
0122 std::cout << "[" << good << "] " << touchDDD.back() << std::endl;
0123 ++good;
0124 }
0125 }
0126 fInput3.close();
0127 std::cout << "Reads " << all << ":" << good << " names from " << touchFileDDD << std::endl;
0128 }
0129 std::ifstream fInput4(touchFileDD4hep);
0130 all = good = 0;
0131 if (!fInput4.good()) {
0132 std::cout << "Cannot open file " << touchFileDD4hep << std::endl;
0133 } else {
0134 while (fInput4.getline(buffer, 1000)) {
0135 std::vector<std::string> items = splitString(std::string(buffer));
0136 ++all;
0137 if (items.size() > 0) {
0138 touchDD4hep.emplace_back(items[0]);
0139 if (((debug / 100) % 10) > 0)
0140 std::cout << "[" << good << "] " << touchDD4hep.back() << std::endl;
0141 ++good;
0142 }
0143 }
0144 fInput4.close();
0145 std::cout << "Reads " << all << ":" << good << " names from " << touchFileDD4hep << std::endl;
0146 }
0147 std::ifstream fInput5(mbFile);
0148 all = good = 0;
0149 if (!fInput5.good()) {
0150 std::cout << "Cannot open file " << mbFile << std::endl;
0151 } else {
0152 while (fInput5.getline(buffer, 1000)) {
0153 std::vector<std::string> items = splitString(std::string(buffer));
0154 ++all;
0155 if (items.size() > 1) {
0156 mbVol.emplace_back(items[1]);
0157 if (((debug / 1000) % 10) > 0)
0158 std::cout << "[" << good << "] " << mbVol.back() << std::endl;
0159 ++good;
0160 }
0161 }
0162 fInput5.close();
0163 std::cout << "Reads " << all << ":" << good << " names from " << mbFile << std::endl;
0164 }
0165 all = ee = hesil = hesci = 0;
0166 std::vector<std::string> extraSD;
0167 for (const auto& sd : sdDDD) {
0168 if (std::find(sdDD4hep.begin(), sdDD4hep.end(), sd) == sdDD4hep.end()) {
0169 extraSD.emplace_back(sd);
0170 if (((debug / 10000) % 10) > 0)
0171 std::cout << "[" << all << "] " << extraSD.back() << std::endl;
0172 ++all;
0173 if (extraSD.back().find("EE") != std::string::npos) {
0174 ++ee;
0175 } else if (extraSD.back().find("HESil") != std::string::npos) {
0176 ++hesil;
0177 } else if (extraSD.back().find("HESci") != std::string::npos) {
0178 ++hesci;
0179 }
0180 }
0181 }
0182 std::cout << "Additional " << all << " names in " << sdFileDDD << " with " << ee << ":" << hesil << ":" << hesci
0183 << " for EE:HESilicon:HEScintillator" << std::endl;
0184 all = 0;
0185 std::vector<int> ddd(extraSD.size(), 0), dd4hep(extraSD.size(), 0), mb(extraSD.size(), 0);
0186 for (unsigned int k = 0; k < extraSD.size(); ++k) {
0187 bool t1 = (std::find(touchDDD.begin(), touchDDD.end(), extraSD[k]) != touchDDD.end());
0188 bool t2 = (std::find(touchDD4hep.begin(), touchDD4hep.end(), extraSD[k]) != touchDD4hep.end());
0189 bool t3 = (std::find(mbVol.begin(), mbVol.end(), extraSD[k]) != mbVol.end());
0190 if (t1)
0191 ++ddd[k];
0192 if (t2)
0193 ++dd4hep[k];
0194 if (t3)
0195 ++mb[k];
0196 if (t1 || t2 || t3) {
0197 ++all;
0198 std::cout << "Extra SD " << extraSD[k] << " in DDD|DD4Touch|MB File " << t1 << ":" << t2 << ":" << t3
0199 << std::endl;
0200 }
0201 }
0202 std::cout << all << " extra SD's appear in some touchable or MB file " << std::endl;
0203 if (((debug / 1) % 10) > 0) {
0204 for (unsigned int k = 0; k < extraSD.size(); ++k)
0205 std::cout << "[" << k << "] " << extraSD[k] << " Find count " << ddd[k] << ":" << dd4hep[k] << ":" << mb[k]
0206 << std::endl;
0207 }
0208
0209 char fname[100];
0210 std::sort(touchDDD.begin(), touchDDD.end());
0211 sprintf(fname, "sorted%s", touchFileDDD);
0212 std::ofstream fOut1(fname);
0213 all = 0;
0214 for (const auto& touch : touchDDD) {
0215 fOut1 << " " << touch << "\n";
0216 ++all;
0217 }
0218 fOut1.close();
0219 std::cout << "Writes " << all << " Touchables in " << fname << " from " << touchFileDDD << std::endl;
0220
0221 all = 0;
0222 std::sort(touchDD4hep.begin(), touchDD4hep.end());
0223 sprintf(fname, "sorted%s", touchFileDD4hep);
0224 std::ofstream fOut2(fname);
0225 for (const auto& touch : touchDD4hep) {
0226 fOut2 << " " << touch << "\n";
0227 ++all;
0228 }
0229 fOut2.close();
0230 std::cout << "Writes " << all << " Touchables in " << fname << " from " << touchFileDD4hep << std::endl;
0231 }
0232
0233 int main(int argc, char* argv[]) {
0234 if (argc <= 6) {
0235 std::cout << "Please give a minimum of 6 arguments \n"
0236 << "name of the SD file corresponding to DDD \n"
0237 << "name of the SD file corresponding to DD4hep \n"
0238 << "name of the Touch file corresponding to DDD \n"
0239 << "name of the Touch file corresponding to DD4hep \n"
0240 << "name of the sMnimumBias file \n"
0241 << "debug flag (0 for minimum printout)\n"
0242 << std::endl;
0243 return 0;
0244 }
0245
0246 const char* sdFileDDD = argv[1];
0247 const char* sdFileDD4hep = argv[2];
0248 const char* touchFileDDD = argv[3];
0249 const char* touchFileDD4hep = argv[4];
0250 const char* mbFile = argv[5];
0251 const int debug = std::atoi(argv[6]);
0252 CompareFiles(sdFileDDD, sdFileDD4hep, touchFileDDD, touchFileDD4hep, mbFile, debug);
0253 return 0;
0254 }