Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:08:22

0001 #include <cstdlib>
0002 #include <exception>
0003 #include <iostream>
0004 #include <string>
0005 #include <utility>
0006 #include <vector>
0007 
0008 #include "DetectorDescription/Core/interface/DDBase.h"
0009 #include "DetectorDescription/Core/interface/DDCompactView.h"
0010 #include "DetectorDescription/Core/interface/DDConstant.h"
0011 #include "DetectorDescription/Core/interface/DDVector.h"
0012 #include "DetectorDescription/Parser/interface/DDLParser.h"
0013 #include "DetectorDescription/Parser/interface/FIPConfiguration.h"
0014 #include "DetectorDescription/RegressionTest/interface/DDErrorDetection.h"
0015 #include "FWCore/Utilities/interface/Exception.h"
0016 
0017 using namespace std;
0018 namespace DD {}
0019 using namespace DD;
0020 
0021 int main(int argc, char* argv[]) {
0022   std::string const kProgramName = argv[0];
0023   int rc = 0;
0024 
0025   try {
0026     // Initialize a DDL Schema aware parser for DDL-documents
0027     // (DDL ... Detector Description Language)
0028     cout << "initialize DDL parser" << endl;
0029     DDCompactView cpv;
0030     DDLParser myP(cpv);
0031 
0032     /* The configuration file tells the parser what to parse.
0033        The sequence of files to be parsed does not matter but for one exception:
0034        XML containing SpecPar-tags must be parsed AFTER all corresponding
0035        PosPart-tags were parsed. (Simply put all SpecPars-tags into seperate
0036        files and mention them at end of configuration.xml. Functional SW 
0037        will not suffer from this restriction).
0038     */
0039 
0040     cout << "about to start parsing" << endl;
0041     string configfile("DetectorDescription/RegressionTest/test/configuration.xml");
0042     if (argc == 2) {
0043       configfile = argv[1];
0044     }
0045 
0046     FIPConfiguration fp(cpv);
0047     fp.readConfig(configfile);
0048     int parserResult = myP.parse(fp);
0049     cout << "done parsing" << std::endl;
0050     cout.flush();
0051     if (parserResult != 0) {
0052       cout << " problem encountered during parsing. exiting ... " << endl;
0053       exit(1);
0054     }
0055     cout << "parsing completed" << endl;
0056 
0057     cout << endl << endl << "Start checking!" << endl << endl;
0058 
0059     DDErrorDetection ed(cpv);
0060     ed.report(cpv, std::cout);
0061 
0062     DDConstant::iterator<DDConstant> cit(DDConstant::begin()), ced(DDConstant::end());
0063     for (; cit != ced; ++cit) {
0064       cout << *cit << endl;
0065     }
0066 
0067     std::vector<std::string> vnames;
0068     DDVector::iterator<DDVector> vit;
0069     DDVector::iterator<DDVector> ved(DDVector::end());
0070     if (vit == ved)
0071       std::cout << "No DDVectors found." << std::endl;
0072     for (; vit != ved; ++vit) {
0073       if (vit->isDefined().second) {
0074         std::cout << vit->toString() << std::endl;
0075         {
0076           DDName vname(vit->name());
0077           vnames.emplace_back(vname.name());
0078         }
0079         const std::vector<double>& tv = *vit;
0080         std::cout << "size: " << tv.size() << std::endl;
0081         for (double i : tv) {
0082           std::cout << i << "\t";
0083         }
0084         std::cout << std::endl;
0085       }
0086     }
0087 
0088     //This forces the 'vector' to be filled
0089     cpv.lockdown();
0090     for (const auto& it : vnames) {
0091       std::cout << it << std::endl;
0092       auto v = cpv.vector(it);
0093       std::cout << "size: " << v.size() << std::endl;
0094       for (double i : v) {
0095         std::cout << i << "\t";
0096       }
0097       std::cout << std::endl;
0098     }
0099 
0100     return 0;
0101   }
0102   //  Deal with any exceptions that may have been thrown.
0103   catch (cms::Exception& e) {
0104     std::cout << "cms::Exception caught in " << kProgramName << "\n" << e.explainSelf();
0105     rc = 1;
0106   } catch (std::exception& e) {
0107     std::cout << "Standard library exception caught in " << kProgramName << "\n" << e.what();
0108     rc = 1;
0109   } catch (...) {
0110     std::cout << "Unknown exception caught in " << kProgramName;
0111     rc = 2;
0112   }
0113 
0114   return rc;
0115 }