Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:32

0001 
0002 #include <fstream>
0003 #include <iostream>
0004 #include <sstream>
0005 #include <string>
0006 #include <vector>
0007 #include <cmath>
0008 #include <iomanip>
0009 
0010 int main (int argc, char *argv[]) {
0011   std::string fname1, fname2;
0012   // assume two arguments NO MATTER WHAT! crash otherwise... who cares?
0013   if ( argc == 3 ) {
0014     //    std::cout << "got two" << std::endl;
0015     fname1 = argv[1];
0016     fname2 = argv[2];
0017     //    std::cout << fname1 << " and " << fname2 << std::endl;
0018   } else {
0019     std::cout << "need two arguments (filenames) to compare dumpGeoHistory" 
0020           << std::endl;
0021       return 1;
0022   }
0023 
0024   std::ifstream f1(fname1.c_str());
0025   std::ifstream f2(fname2.c_str());
0026   std::string l1, l2, ts;
0027   std::vector<double> t1(3), t2(3), r1(9), r2(9);
0028 
0029   while ( !f1.eof() && !f2.eof() ) {
0030     getline(f1, l1, ',');
0031     getline(f2, l2, ',');
0032     if ( l1 != l2 ) {
0033       std::cout << "Lines don't match or are out of synchronization."
0034         << "  The difference is much bigger than just the numbers,"
0035         << " actual parts are missing or added.  This program "
0036         << " does not handle this at this time... use diff first."
0037         << std::endl
0038         << "["<<l1 <<"]"<< std::endl
0039         << "["<<l2 <<"]"<< std::endl
0040         << std::endl;
0041       return 1;
0042     }
0043 //     std::cout << "1================================" << std::endl;
0044 //     std::cout << "["<<l1 <<"]"<< std::endl
0045 //        << "["<<l2 <<"]"<< std::endl;
0046 //     std::cout << "================================" << std::endl;
0047 
0048     size_t i = 0;
0049     while ( i < 3 ) {
0050       ts.clear();
0051       getline(f1,ts,',');
0052       //    std::cout << ts << std::endl;
0053       std::istringstream s1 (ts);
0054       s1>>t1[i++];
0055     }
0056 
0057     i=0;
0058     while ( i < 8 ) {
0059       ts.clear();
0060       getline(f1,ts,',');
0061       //    std::cout << ts << std::endl;
0062       std::istringstream s1 (ts);
0063       s1>>r1[i++];
0064     }
0065     ts.clear();
0066     getline(f1, ts);
0067     std::istringstream s2(ts);
0068     s2>>r1[8];
0069 
0070     i=0;
0071     while ( i < 3 ) {
0072       ts.clear();
0073       getline(f2,ts,',');
0074       //    std::cout << ts << std::endl;
0075       std::istringstream s1 (ts);
0076       s1>>t2[i++];
0077     }
0078 
0079     i=0;
0080     while ( i < 8 ) {
0081       ts.clear();
0082       getline(f2,ts,',');
0083       //    std::cout << ts << std::endl;
0084       std::istringstream s1 (ts);
0085       s1>>r2[i++];
0086     }
0087     ts.clear();
0088     getline(f2, ts);
0089     std::istringstream s3(ts);
0090     s3>>r2[8];
0091 
0092 //     std::cout << "2================================" << std::endl;
0093 //     std::cout << "["<<l1 <<"]"<< std::endl
0094 //        << "["<<l2 <<"]"<< std::endl;
0095 //     std::cout << "ts = " << ts << std::endl;
0096 //     std::cout << "================================" << std::endl;
0097     //      std::cout << "l1=" << l1 << std::endl;
0098     std::vector<bool> cerrorind;
0099     cerrorind.reserve(3);
0100     for (i=0; i < 3; i++) {
0101 //       std::cout << std::setw(13)
0102 //      << std::setprecision(7) << std::fixed 
0103 //      << "t1[" << i << "] = " << t1[i]
0104 //      << " t2[" << i << "] = " << t2[i] << std::endl;
0105       if ( std::fabs(t1[i] - t2[i]) > 0.0000001 ) cerrorind[i] = true;
0106       else cerrorind[i] = false;
0107     }
0108     if ( cerrorind[0] || cerrorind[1] || cerrorind[2] ) std::cout << l1;
0109     for ( i=0; i<3; ++i ) {
0110       if ( cerrorind[i] ) {
0111     std::cout << " coordinate ";
0112     if ( i == 0 ) std::cout << "x ";
0113     else if ( i == 1 ) std::cout << "y ";
0114     else if ( i == 2 ) std::cout << "z ";
0115     std::cout << " is different by: " << std::setw(13)
0116           << std::setprecision(7) << std::fixed << t1[i] - t2[i] 
0117           << " mm ";
0118       }
0119     }
0120     bool rerror(false);
0121     for (i=0; i < 9; i++) {
0122 //       std::cout << "r1[" << i << "] = " << r1[i]
0123 //      << " r2[" << i << "] = " << r2[i] << std::endl;
0124       if ( std::fabs(r1[i] - r2[i]) > 0.0000001 ) rerror = true;
0125     }
0126     if ( rerror && !cerrorind[0] && !cerrorind[1] && !cerrorind[2] ) {
0127       std::cout << l1 << " ";
0128     }
0129     if ( rerror ) {
0130       for (i=0; i < 9; i++) {
0131     //  std::cout << "r1[" << i << "] = " << r1[i]
0132     //        << " r2[" << i << "] = " << r2[i] << std::endl;
0133     if ( std::fabs(r1[i] - r2[i]) > 0.0000001 ) {
0134       //      std::cout << std::endl;
0135       std::cout << " index " << i << " of rotation matrix differs by " 
0136             << std::setw(13) << std::setprecision(7) 
0137             << std::fixed << r1[i] - r2[i];
0138     }
0139       }
0140       std::cout << std::endl;
0141     } else if ( cerrorind[0] || cerrorind[1] || cerrorind[2]) {
0142       std::cout << std::endl;
0143     }
0144 //     std::cout << "3================================" << std::endl;
0145 //     std::cout << "["<<l1 <<"]"<< std::endl
0146 //        << "["<<l2 <<"]"<< std::endl;
0147 //     std::cout << "================================" << std::endl;
0148     //       getline(f1, l1, ',');
0149     //       getline(f2, l2, ',');
0150 //     if ( f1.peek() != 10 ) {
0151 //       std::cout << "not eol on f1 doing an extra getline()" << std::endl;
0152 //       getline(f1,ts);
0153 //       std::cout << "why this is left?" << ts << std::endl;
0154 //     }
0155 //     if ( f2.peek() != 10 ) {
0156 //       std::cout << "not eol on f2 doing an extra getline()" << std::endl;
0157 //       getline(f2,ts);
0158 //       std::cout << "why this is left?" << ts << std::endl;
0159 //     }
0160   }
0161   return 0;
0162 }