DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
converter.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifdef __GNUC__
14 #pragma GCC diagnostic ignored "-Wunused-function"
15 #endif
16 
17 // Framework include files
18 #include "run_plugin.h"
19 
20 //______________________________________________________________________________
21 namespace {
22  void usage() {
23  std::cout <<
24  "geoConverter -opt [-opt] \n"
25  " Action flags: Usage is exclusive, 1 required! \n"
26  " -compact2description Convert compact xml geometry to description.\n"
27  " -compact2gdml Convert compact xml geometry to gdml. \n"
28  " -compact2pandora Convert compact xml to pandora xml. \n"
29  " -compact2tgeo Convert compact xml to TGeo in ROOT file. \n"
30  " -compact2vis Convert compact xml to visualisation attrs\n\n"
31  " -input <file> [REQUIRED] Specify input file. \n"
32  " -output <file> [OPTIONAL] Specify output file. \n"
33  " if no output file is specified, the output \n"
34  " device is stdout. \n"
35  " -ascii [OPTIONAL] Dump visualisation attrs in csv format. \n"
36  " [Only valid for -compact2vis] \n"
37  " -destroy [OPTIONAL] Force destruction of the Detector instance \n"
38  " before exiting the application \n"
39  " -volmgr [OPTIONAL] Load and populate phys.volume manager to \n"
40  " check the volume ids for duplicates etc. \n"
41  << std::endl;
42  ::exit(EINVAL);
43  }
44 
45 
46  //______________________________________________________________________________
47  int invoke_converter(int argc,char** argv) {
48  bool ascii = false;
49  bool volmgr = false;
50  bool destroy = false;
51  bool compact2description = false;
52  bool compact2gdml = false;
53  bool compact2pand = false;
54  bool compact2tgeo = false;
55  bool compact2vis = false;
56  int output = 0;
57  std::vector<char*> geo_files;
58  for(int i=1; i<argc;++i) {
59  if ( argv[i][0]=='-' ) {
60  if ( strncmp(argv[i],"-compact2description",12)==0 )
61  compact2description = true;
62  else if ( strncmp(argv[i],"-compact2gdml",12)==0 )
63  compact2gdml = true;
64  else if ( strncmp(argv[i],"-compact2pandora",12)==0 )
65  compact2pand = true;
66  else if ( strncmp(argv[i],"-compact2tgeo",12)==0 )
67  compact2tgeo = true;
68  else if ( strncmp(argv[i],"-compact2vis",12)==0 )
69  compact2vis = true;
70  else if ( strncmp(argv[i],"-input",2)==0 )
71  geo_files.emplace_back(argv[++i]);
72  else if ( strncmp(argv[i],"-output",2)==0 )
73  output = ++i;
74  else if ( strncmp(argv[i],"-ascii",5)==0 )
75  ascii = true;
76  else if ( strncmp(argv[i],"-destroy",2)==0 )
77  destroy = true;
78  else if ( strncmp(argv[i],"-volmgr",2)==0 )
79  volmgr = true;
80  else
81  usage();
82  }
83  else {
84  usage();
85  }
86  }
87  if ( geo_files.empty() || (!compact2description && !compact2gdml && !compact2pand && !compact2tgeo && !compact2vis))
88  usage();
89 
90  dd4hep::Detector& description = dd4hep_instance();
91  // Load compact files
92  for(size_t i=0; i<geo_files.size(); ++i) {
93  const char* plugin_argv[] = {geo_files[i], 0};
94  run_plugin(description,"DD4hep_CompactLoader",1,(char**)plugin_argv);
95  }
96  // Create volume manager and populate it required
97  if ( volmgr ) run_plugin(description,"DD4hepVolumeManager",0,0);
98  // Execute data converter.
99  if ( compact2description )
100  run_plugin(description,"DD4hepGeometry2Detector",output,&argv[output]);
101  else if ( compact2gdml )
102  run_plugin(description,"DD4hepGeometry2GDML",output,&argv[output]);
103  else if ( compact2pand )
104  run_plugin(description,"DD4hepGeometry2PANDORA",output,&argv[output]);
105  else if ( compact2tgeo )
106  run_plugin(description,"DD4hepGeometry2TGeo",argc-output,&argv[output]);
107  else if ( compact2vis && ascii )
108  run_plugin(description,"DD4hepGeometry2VISASCII",output,&argv[output]);
109  else if ( compact2vis )
110  run_plugin(description,"DD4hepGeometry2VIS",output,&argv[output]);
111  if ( destroy ) delete &description;
112  return 0;
113  }
114 }
115 
117 int main(int argc, char** argv) {
118  try {
119  return invoke_converter(argc, argv);
120  }
121  catch(const std::exception& e) {
122  std::cout << "Got uncaught exception: " << e.what() << std::endl;
123  }
124  catch (...) {
125  std::cout << "Got UNKNOWN uncaught exception." << std::endl;
126  }
127  return EINVAL;
128 }
dd4hep::exception
void exception(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:69
run_plugin.h
dd4hep::sim::HepMC::ascii
@ ascii
Definition: Geant4EventReaderHepMC.cpp:138
main
int main(int argc, char **argv)
Main entry point as a program.
Definition: converter.cpp:117
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
usage
void usage(std::string argv0)
Definition: listcomponents.cpp:41