Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:35

0001 #include <cstdlib>
0002 #include <iostream>
0003 #include <string>
0004 #include <vector>
0005 
0006 #include "DetectorDescription/Core/interface/DDCompactView.h"
0007 #include "DetectorDescription/Parser/interface/DDLParser.h"
0008 #include "DetectorDescription/Parser/interface/DDLSAX2FileHandler.h"
0009 #include "DetectorDescription/Parser/interface/FIPConfiguration.h"
0010 #include "DetectorDescription/RegressionTest/interface/DDCompareTools.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/PluginManager/interface/PluginManager.h"
0013 #include "FWCore/PluginManager/interface/standard.h"
0014 #include "FWCore/Utilities/interface/Exception.h"
0015 #include <boost/program_options.hpp>
0016 #include <boost/exception/all.hpp>
0017 
0018 int main(int argc, char* argv[]) {
0019   try {
0020     edmplugin::PluginManager::configure(edmplugin::standard::config());
0021   } catch (cms::Exception& e) {
0022     edm::LogInfo("DDCompareCPV") << "Attempting to configure the plugin manager. Exception message: " << e.what();
0023     return 1;
0024   }
0025 
0026   // Process the command line arguments
0027   std::string descString("DDCompareCPV");
0028   descString += " [options] configurationFileName1 configurationFileName2 Compares two DDCompactViews\n";
0029   descString += "Allowed options";
0030   boost::program_options::options_description desc(descString);
0031   desc.add_options()("help,h", "Print this help message")(
0032       "file1,f",
0033       boost::program_options::value<std::string>(),
0034       "XML configuration file name. "
0035       "Default is DetectorDescription/RegressionTest/test/configuration.xml")(
0036       "file2,g",
0037       boost::program_options::value<std::string>(),
0038       "XML configuration file name. "
0039       "Default is DetectorDescription/RegressionTest/test/configuration.xml")(
0040       "dist-tolerance,t",
0041       boost::program_options::value<std::string>(),
0042       "Value tolerance for distances (in mm). "
0043       "Default value 0.0004 (anything larger is an error)")("rot-tolerance,r",
0044                                                             boost::program_options::value<std::string>(),
0045                                                             "Value tolerance for rotation matrix elements. "
0046                                                             "Default value is 0.0004 (anything larger is an error)")(
0047       "spec-tolerance,s",
0048       boost::program_options::value<std::string>(),
0049       "Value tolerance for rotation matrix elements. "
0050       "Default value is 0.0004 (anything larger is an error) NOT USED YET")(
0051       "user-ns,u",
0052       "Use the namespaces in each file and do NOT use the filename as namespace. "
0053       "Default is to use the filename of each file in the configuration.xml file as a filename")(
0054       "comp-rot,c",
0055       "Use the rotation name when comparing rotations. "
0056       "Default is to use the matrix only and not the name when comparing DDRotations")(
0057       "continue-on-error,e",
0058       "Continue after an error in values. "
0059       "Default is to stop at the first error. NOT IMPLEMENTED")(
0060       "attempt-resync,a",
0061       "Continue after an error in graph position, attempt to resync. "
0062       "Default is to stop at the first mis-match of the graph. NOT IMPLEMENTED");
0063 
0064   boost::program_options::positional_options_description p;
0065   p.add("file1", 1);
0066   p.add("file2", 2);
0067 
0068   boost::program_options::variables_map vm;
0069   try {
0070     store(boost::program_options::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
0071     notify(vm);
0072   } catch (boost::program_options::error const& iException) {
0073     std::cerr << "Exception from command line processing: " << iException.what() << "\n";
0074     std::cerr << desc << std::endl;
0075     return 1;
0076   }
0077   if (vm.count("help")) {
0078     std::cout << desc << std::endl;
0079     return 0;
0080   }
0081 
0082   bool fullPath = false;
0083   std::string configfile("DetectorDescription/RegressionTest/test/configuration.xml");
0084   std::string configfile2("DetectorDescription/RegressionTest/test/configuration.xml");
0085   DDCompOptions ddco;
0086   bool usrns(false);
0087   try {
0088     if (vm.count("file1")) {
0089       configfile = vm["file1"].as<std::string>();
0090       if (vm.count("file2")) {
0091         configfile2 = vm["file2"].as<std::string>();
0092       }
0093     }
0094     if (vm.count("dist-tolerance"))
0095       ddco.distTol_ = vm["dist-tolerance"].as<double>();
0096     if (vm.count("rot-tolerance"))
0097       ddco.rotTol_ = vm["rot-tolerance"].as<double>();
0098     if (vm.count("spec-tolerance"))
0099       ddco.rotTol_ = vm["spec-tolerance"].as<double>();
0100     if (vm.count("user-ns"))
0101       usrns = true;
0102     if (vm.count("comp-rot"))
0103       ddco.compRotName_ = true;
0104     if (vm.count("continue-on-error"))
0105       ddco.contOnError_ = true;
0106     if (vm.count("attempt-resync"))
0107       ddco.attResync_ = true;
0108   } catch (boost::exception& e) {
0109     edm::LogInfo("DDCompareCPV") << "Attempting to parse the options. Exception message: "
0110                                  << boost::diagnostic_information(e);
0111     return 1;
0112   }
0113 
0114   std::ios_base::fmtflags originalFlags = std::cout.flags();
0115 
0116   std::cout << "Settings are: " << std::endl;
0117   std::cout << "Configuration file 1: " << configfile << std::endl;
0118   std::cout << "Configuration file 2: " << configfile2 << std::endl;
0119   std::cout << "Length/distance tolerance: " << ddco.distTol_ << std::endl;
0120   std::cout << "Rotation matrix element tolerance: " << ddco.rotTol_ << std::endl;
0121   std::cout << "SpecPar tolerance: " << ddco.specTol_ << std::endl;
0122   std::cout << "User controlled namespace (both file sets)? " << std::boolalpha << usrns << std::endl;
0123   std::cout << "Compare Rotation names? " << ddco.compRotName_ << std::endl;
0124   std::cout << "Continue on error (data mismatch)? " << ddco.contOnError_ << std::endl;
0125   std::cout << "Attempt resyncronization of disparate graphs? " << ddco.attResync_ << std::endl;
0126 
0127   DDCompactView cpv1(DDName("CompactView1"));
0128   DDLParser myP(cpv1);
0129   myP.getDDLSAX2FileHandler()->setUserNS(usrns);
0130 
0131   /* The configuration file tells the parser what to parse.
0132        The sequence of files to be parsed does not matter but for one exception:
0133        XML containing SpecPar-tags must be parsed AFTER all corresponding
0134        PosPart-tags were parsed. (Simply put all SpecPars-tags into seperate
0135        files and mention them at end of configuration.xml. Functional SW 
0136        will not suffer from this restriction).
0137     */
0138 
0139   // Use the File-In-Path configuration document provider.
0140   FIPConfiguration fp(cpv1);
0141   try {
0142     fp.readConfig(configfile, fullPath);
0143   } catch (cms::Exception& e) {
0144     edm::LogInfo("DDCompareCPV") << "Attempting to read config. Exception message: " << e.what();
0145     return 1;
0146   }
0147 
0148   std::cout << "FILE 1: " << configfile << std::endl;
0149   if (fp.getFileList().empty()) {
0150     std::cout << "FILE 1: configuration file has no DDD xml files in it!" << std::endl;
0151     exit(1);
0152   }
0153   int parserResult = myP.parse(fp);
0154   if (parserResult != 0) {
0155     std::cout << "FILE 1: problem encountered during parsing. exiting ... " << std::endl;
0156     exit(1);
0157   }
0158   cpv1.lockdown();
0159 
0160   DDCompactView cpv2(DDName("CompactView2"));
0161   DDLParser myP2(cpv2);
0162   myP2.getDDLSAX2FileHandler()->setUserNS(usrns);
0163 
0164   /* The configuration file tells the parser what to parse.
0165        The sequence of files to be parsed does not matter but for one exception:
0166        XML containing SpecPar-tags must be parsed AFTER all corresponding
0167        PosPart-tags were parsed. (Simply put all SpecPars-tags into seperate
0168        files and mention them at end of configuration.xml. Functional SW 
0169        will not suffer from this restriction).
0170     */
0171 
0172   // Use the File-In-Path configuration document provider.
0173   FIPConfiguration fp2(cpv2);
0174   fp2.readConfig(configfile2, fullPath);
0175   std::cout << "FILE 2: " << configfile2 << std::endl;
0176   if (fp2.getFileList().empty()) {
0177     std::cout << "FILE 2: configuration file has no DDD xml files in it!" << std::endl;
0178     exit(1);
0179   }
0180   int parserResult2 = myP2.parse(fp2);
0181   if (parserResult2 != 0) {
0182     std::cout << "FILE 2: problem encountered during parsing. exiting ... " << std::endl;
0183     exit(1);
0184   }
0185   cpv2.lockdown();
0186 
0187   std::cout << "Parsing completed. Start comparing." << std::endl;
0188 
0189   bool graphmatch = DDCompareCPV(cpv1, cpv2, ddco);
0190 
0191   if (graphmatch) {
0192     std::cout << "DDCompactView graphs match" << std::endl;
0193   } else {
0194     std::cout << "DDCompactView graphs do NOT match" << std::endl;
0195   }
0196 
0197   // Now set everything back to defaults
0198   std::cout.flags(originalFlags);
0199 
0200   return 0;
0201 }