File indexing completed on 2025-01-18 09:14:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "DD4hep/Detector.h"
0017 #include "DD4hep/Printout.h"
0018
0019
0020 #include <iostream>
0021 #include <cstdlib>
0022 #include <vector>
0023 #include <cerrno>
0024 #include <string>
0025
0026 #include "TRint.h"
0027 #include "TGeoManager.h"
0028
0029 using namespace dd4hep;
0030
0031
0032 namespace {
0033
0034 void usage_default(const char* name) {
0035 std::cout << " " << name << " -opt [-opt] \n"
0036 " -compact <file> Specify the compact geometry file \n"
0037 " [REQUIRED] At least one compact geo file is required! \n"
0038 << std::endl;
0039 std::exit(EINVAL);
0040 }
0041
0042
0043 struct Args {
0044 bool volmgr, dry_run, destroy, interpreter, ui;
0045 PrintLevel print;
0046 std::vector<const char*> geo_files, build_types;
0047 std::vector<std::vector<const char*> > plugins;
0048
0049
0050 Args() {
0051 ui = false;
0052 volmgr = false;
0053 dry_run = false;
0054 destroy = false;
0055 interpreter = true;
0056 print = INFO;
0057 }
0058
0059
0060 int handle(int& i, int argc, char** argv) {
0061 if ( ::strncmp(argv[i],"-compact",5)==0 || ::strncmp(argv[i],"-input",4)==0 ) {
0062 geo_files.push_back(argv[++i]);
0063 if ( argc>i+2 && ::strncmp(argv[i+1],"-build_type",6)==0 ) {
0064 build_types.push_back(argv[i+2]);
0065 i += 2;
0066 }
0067 else {
0068 build_types.push_back("BUILD_DEFAULT");
0069 }
0070 }
0071 else if ( ::strncmp(argv[i],"-load_only",5)==0 )
0072 dry_run = true;
0073 else if ( ::strncmp(argv[i],"-dry-run",5)==0 )
0074 dry_run = true;
0075 else if ( ::strncmp(argv[i],"-print",4)==0 )
0076 setPrintLevel(PrintLevel(print = decodePrintLevel(argv[++i])));
0077 else if ( ::strncmp(argv[i],"-destroy",5)==0 )
0078 destroy = true;
0079 else if ( ::strncmp(argv[i],"-no-destroy",8)==0 )
0080 destroy = false;
0081 else if ( ::strncmp(argv[i],"-volmgr",4)==0 )
0082 volmgr = true;
0083 else if ( ::strncmp(argv[i],"-no-volmgr",7)==0 )
0084 volmgr = false;
0085 else if ( ::strncmp(argv[i],"-interpreter",6)==0 )
0086 interpreter = true;
0087 else if ( ::strncmp(argv[i],"-no-interpreter",7)==0 )
0088 interpreter = false;
0089 else if ( ::strncmp(argv[i],"-interactive",6)==0 )
0090 interpreter = true;
0091 else if ( ::strncmp(argv[i],"-no-interactive",7)==0 )
0092 interpreter = false;
0093 else if ( ::strncmp(argv[i],"-ui",3)==0 )
0094 ui = true;
0095 else if ( ::strncmp(argv[i],"-no-ui",6)==0 )
0096 ui = false;
0097 else if ( ::strncmp(argv[i],"-plugin",5)==0 ) {
0098
0099 plugins.push_back(std::vector<const char*>());
0100 plugins.back().push_back(argv[++i]);
0101 for( ++i; i < argc; ++i ) {
0102 if ( ::strncmp(argv[i],"-plugin",5)==0 ) { --i; break; }
0103 if ( ::strncmp(argv[i],"-end-plugin",4)==0 ) { break; }
0104 plugins.back().push_back(argv[i]);
0105 }
0106 plugins.back().push_back(0);
0107 }
0108 else
0109 return 0;
0110 return 1;
0111 }
0112 };
0113 }
0114
0115
0116 int main(int argc,char** argv) {
0117 Args args;
0118 for(int i=1; i<argc;++i) {
0119 if ( argv[i][0]=='-' ) {
0120 if ( args.handle(i,argc,argv) )
0121 continue;
0122 else
0123 usage_default("Blas");
0124 }
0125 else {
0126 args.geo_files.push_back(argv[i]);
0127 args.build_types.push_back("BUILD_DEFAULT");
0128 }
0129 }
0130 std::vector<Detector*> detector_instances;
0131 TStorage::EnableStatistics(10000);
0132
0133 for(size_t i=0; i<args.geo_files.size(); ++i) {
0134 const char* arg[] = {args.geo_files[i], args.build_types[i], 0};
0135 printout(ALWAYS,"MultiGeom","=============================================================================");
0136 printout(ALWAYS,"MultiGeom","Loading geometry: %s",arg[0]);
0137 Detector& description = Detector::getInstance(arg[0]);
0138 detector_instances.push_back(&description);
0139 description.apply("DD4hep_XMLLoader",2,(char**)arg);
0140 }
0141 int cnt = 0;
0142 for(auto d : detector_instances) {
0143 char line[256];
0144 printout(ALWAYS,"MultiGeom","=============================================================================");
0145 printout(ALWAYS,"MultiGeom","Manager: %s",d->manager().GetName());
0146 printout(ALWAYS,"MultiGeom","Manager: %p",&d->manager());
0147 ::snprintf(line,sizeof(line),"TGeoManager* mgr%d = (TGeoManager*)%p",cnt,(void*)&d->manager());
0148 printout(ALWAYS,"MultiGeom","%s",line);
0149 gInterpreter->ProcessLine(line);
0150 ::snprintf(line,sizeof(line),"TGeoVolume* top%d = (TGeoVolume*)%p",cnt,(void*)d->manager().GetTopVolume());
0151 printout(ALWAYS,"MultiGeom","%s",line);
0152 gInterpreter->ProcessLine(line);
0153 printout(ALWAYS,"MultiGeom","=============================================================================");
0154 ++cnt;
0155 }
0156 if ( args.interpreter ) {
0157 std::pair<int, char**> a(0,0);
0158 gGeoManager = 0;
0159 TRint app("DD4hep", &a.first, a.second);
0160 app.Run();
0161 }
0162 for(auto d : detector_instances) {
0163 printout(ALWAYS,"MultiGeom","=============================================================================");
0164 printout(ALWAYS,"MultiGeom","DELETE Geometry: %s",d->manager().GetName());
0165 delete d;
0166 }
0167 return 0;
0168 }