File indexing completed on 2025-01-18 09:14:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifdef __GNUC__
0014 #pragma GCC diagnostic ignored "-Wunused-function"
0015 #endif
0016
0017
0018 #include "run_plugin.h"
0019
0020
0021 namespace {
0022 void usage() {
0023 std::cout <<
0024 "geoConverter -opt [-opt] \n"
0025 " Action flags: Usage is exclusive, 1 required! \n"
0026 " -compact2description Convert compact xml geometry to description.\n"
0027 " -compact2gdml Convert compact xml geometry to gdml. \n"
0028 " -compact2pandora Convert compact xml to pandora xml. \n"
0029 " -compact2tgeo Convert compact xml to TGeo in ROOT file. \n"
0030 " -compact2vis Convert compact xml to visualisation attrs\n\n"
0031 " -input <file> [REQUIRED] Specify input file. \n"
0032 " -output <file> [OPTIONAL] Specify output file. \n"
0033 " if no output file is specified, the output \n"
0034 " device is stdout. \n"
0035 " -ascii [OPTIONAL] Dump visualisation attrs in csv format. \n"
0036 " [Only valid for -compact2vis] \n"
0037 " -destroy [OPTIONAL] Force destruction of the Detector instance \n"
0038 " before exiting the application \n"
0039 " -volmgr [OPTIONAL] Load and populate phys.volume manager to \n"
0040 " check the volume ids for duplicates etc. \n"
0041 << std::endl;
0042 ::exit(EINVAL);
0043 }
0044
0045
0046
0047 int invoke_converter(int argc,char** argv) {
0048 bool ascii = false;
0049 bool volmgr = false;
0050 bool destroy = false;
0051 bool compact2description = false;
0052 bool compact2gdml = false;
0053 bool compact2pand = false;
0054 bool compact2tgeo = false;
0055 bool compact2vis = false;
0056 int output = 0;
0057 std::vector<char*> geo_files;
0058 for(int i=1; i<argc;++i) {
0059 if ( argv[i][0]=='-' ) {
0060 if ( strncmp(argv[i],"-compact2description",12)==0 )
0061 compact2description = true;
0062 else if ( strncmp(argv[i],"-compact2gdml",12)==0 )
0063 compact2gdml = true;
0064 else if ( strncmp(argv[i],"-compact2pandora",12)==0 )
0065 compact2pand = true;
0066 else if ( strncmp(argv[i],"-compact2tgeo",12)==0 )
0067 compact2tgeo = true;
0068 else if ( strncmp(argv[i],"-compact2vis",12)==0 )
0069 compact2vis = true;
0070 else if ( strncmp(argv[i],"-input",2)==0 )
0071 geo_files.emplace_back(argv[++i]);
0072 else if ( strncmp(argv[i],"-output",2)==0 )
0073 output = ++i;
0074 else if ( strncmp(argv[i],"-ascii",5)==0 )
0075 ascii = true;
0076 else if ( strncmp(argv[i],"-destroy",2)==0 )
0077 destroy = true;
0078 else if ( strncmp(argv[i],"-volmgr",2)==0 )
0079 volmgr = true;
0080 else
0081 usage();
0082 }
0083 else {
0084 usage();
0085 }
0086 }
0087 if ( geo_files.empty() || (!compact2description && !compact2gdml && !compact2pand && !compact2tgeo && !compact2vis))
0088 usage();
0089
0090 dd4hep::Detector& description = dd4hep_instance();
0091
0092 for(size_t i=0; i<geo_files.size(); ++i) {
0093 const char* plugin_argv[] = {geo_files[i], 0};
0094 run_plugin(description,"DD4hep_CompactLoader",1,(char**)plugin_argv);
0095 }
0096
0097 if ( volmgr ) run_plugin(description,"DD4hepVolumeManager",0,0);
0098
0099 if ( compact2description )
0100 run_plugin(description,"DD4hepGeometry2Detector",output,&argv[output]);
0101 else if ( compact2gdml )
0102 run_plugin(description,"DD4hepGeometry2GDML",output,&argv[output]);
0103 else if ( compact2pand )
0104 run_plugin(description,"DD4hepGeometry2PANDORA",output,&argv[output]);
0105 else if ( compact2tgeo )
0106 run_plugin(description,"DD4hepGeometry2TGeo",argc-output,&argv[output]);
0107 else if ( compact2vis && ascii )
0108 run_plugin(description,"DD4hepGeometry2VISASCII",output,&argv[output]);
0109 else if ( compact2vis )
0110 run_plugin(description,"DD4hepGeometry2VIS",output,&argv[output]);
0111 if ( destroy ) delete &description;
0112 return 0;
0113 }
0114 }
0115
0116
0117 int main(int argc, char** argv) {
0118 try {
0119 return invoke_converter(argc, argv);
0120 }
0121 catch(const std::exception& e) {
0122 std::cout << "Got uncaught exception: " << e.what() << std::endl;
0123 }
0124 catch (...) {
0125 std::cout << "Got UNKNOWN uncaught exception." << std::endl;
0126 }
0127 return EINVAL;
0128 }