16 #include "G4Colour.hh"
17 #include "G4GeometryManager.hh"
18 #include "G4LogicalVolume.hh"
19 #include "G4LogicalVolumeStore.hh"
20 #include "G4Material.hh"
21 #include "G4PVPlacement.hh"
22 #include "G4PVReplica.hh"
23 #include "G4PhysicalVolumeStore.hh"
24 #include "G4SolidStore.hh"
25 #include "G4VisAttributes.hh"
27 #include "G4GDMLParser.hh"
29 #include "G4RunManager.hh"
30 #include "G4TransportationManager.hh"
34 #include "Geant4GM/volumes/Factory.h"
35 #include "RootGM/volumes/Factory.h"
36 #include "TGeoManager.h"
40 #include "GGSVersion.h"
46 namespace GGSWolowitz {
47 G4String outputFile =
"GGSGeometry";
48 G4String geoDataCard =
"";
49 G4String geometryFile =
"";
51 G4String outputType =
"gdml";
53 G4String outputType =
"vgm";
55 G4String inputFile =
"";
56 G4String schemaLocation =
"http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd";
57 G4String detectorFlag =
"";
61 std::cout <<
"This program is used to convert GGS detector geometry into other geometry formats.\n";
62 std::cout <<
"Built with support for "
73 std::cout <<
"\nUsage: GGSWolowitz [options] \n";
74 std::cout <<
"\nOptions:\n";
75 std::cout <<
" -o, --output-file FILE output filename [default: output.gdml]\n";
76 std::cout <<
" -g, --geometry FILE full path and name of the geometry .so file\n";
78 <<
" -gd, --geo-data-card FILE data card filename for geometry configuration [default: not set]\n";
79 std::cout <<
" -t, --output-type TYPE output type (possible values: "
87 << GGSWolowitz::outputType <<
")\n";
88 std::cout <<
" -i, --input-file FILE file containing input arguments [default: not set]\n";
89 std::cout <<
" -u, --gdml-schema-location url of schema location [default: "
90 "http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd]\n";
91 std::cout <<
" -v, --verbose be verbose [default: false]\n";
92 std::cout <<
" -V, --version displays software version and exit\n";
93 std::cout <<
" -h, --help display this help and exit\n";
94 std::cout <<
"\nFor bug reporting instructions, please see for example:\n";
95 std::cout <<
" <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
96 std::cout <<
"Report bugs to: mori@fi.infn.it" << std::endl;
100 std::cout <<
"GGSWolowitz geometry software\n";
101 std::cout <<
"Using GGS " << GGSVERSION << std::endl;
104 using namespace GGSWolowitz;
106 int HandleInputPar(
int argc,
const char **argv) {
107 static const std::string routineName(
"HandleInputPar");
109 GGSSmartLog::verboseLevel = GGSSmartLog::WARNING;
110 int vLevel = GGSSmartLog::INFO;
114 if (!strcmp(argv[i],
"-h") || !strcmp(argv[i],
"--help")) {
119 if (!strcmp(argv[i],
"-V") || !strcmp(argv[i],
"--version")) {
124 else if (!strcmp(argv[i],
"-v") || !strcmp(argv[i],
"--verbose")) {
125 std::string vLevStr(argv[++i]);
126 if (vLevStr ==
"error")
127 vLevel = GGSSmartLog::ERROR;
128 else if (vLevStr ==
"warning")
129 vLevel = GGSSmartLog::WARNING;
130 else if (vLevStr ==
"normal" || vLevStr ==
"info")
131 vLevel = GGSSmartLog::INFO;
132 else if (vLevStr ==
"debug")
133 vLevel = GGSSmartLog::DEBUG;
134 else if (vLevStr ==
"deepdeb")
135 vLevel = GGSSmartLog::DEEPDEB;
137 COUT(WARNING) <<
"Unrecognized verbosity level: " << vLevStr <<
". Ignoring." <<
ENDL;
141 else if (!strcmp(argv[i],
"-o") || !strcmp(argv[i],
"--output-file")) {
146 outputFile = argv[i];
149 else if (!strcmp(argv[i],
"-t") || !strcmp(argv[i],
"--output-type")) {
154 if (strcmp(argv[i],
"gdml") && strcmp(argv[i],
"vgm")) {
155 COUT(ERROR) <<
"Unknown output type: " << argv[i] <<
ENDL;
159 if (!strcmp(argv[i],
"gdml")) {
160 COUT(ERROR) <<
"Converting to gdml requires Geant4 version compiled with Xerces-C" <<
ENDL;
165 if (!strcmp(argv[i],
"vgm")) {
166 COUT(ERROR) <<
"Converting to vgm requires Virtual Geometry Model" <<
ENDL;
171 outputType = argv[i];
174 else if (!strcmp(argv[i],
"-g") || !strcmp(argv[i],
"--geometry")) {
179 geometryFile = argv[i];
182 else if (!strcmp(argv[i],
"-gd") || !strcmp(argv[i],
"--geo-data-card")) {
187 geoDataCard = argv[i];
190 else if (!strcmp(argv[i],
"-i") || !strcmp(argv[i],
"--input-file")) {
198 else if (!strcmp(argv[i],
"-u") || !strcmp(argv[i],
"--gdml-schema-location")) {
203 schemaLocation = argv[i];
207 COUT(WARNING) <<
"Unidentified input argument \"" << argv[i] <<
"\". Ignoring." <<
ENDL;
213 GGSSmartLog::verboseLevel = vLevel;
217 int main(
int argc,
const char **argv) {
218 static const std::string routineName(
"GGSWolowitz");
220 if (HandleInputPar(argc, argv))
225 if (strcmp(inputFile.c_str(),
"")) {
227 std::string mych[1000];
230 const char **fileArgv;
231 fileArgv =
new const char *[nPar];
234 fileArgv[i] = (mych[i]).c_str();
237 if (HandleInputPar(nPar, fileArgv))
242 COUT(DEBUG) <<
"Start run manager " <<
ENDL;
243 G4RunManager *runManager =
new G4RunManager();
246 COUT(ERROR) <<
"Impossible to load geometry library " << geometryFile <<
". Exit." <<
ENDL;
253 COUT(ERROR) <<
"Can't create the geometry. Exit." <<
ENDL;
259 COUT(DEBUG) <<
"Construct the geometry." <<
ENDL;
262 G4VPhysicalVolume *physVolume = geometry->
Construct();
265 if (GGSWolowitz::outputType ==
"gdml") {
266 COUT(DEBUG) <<
"Write the GDML file." <<
ENDL;
268 parser.SetAddPointerToName(
true);
269 if (outputFile.length() < 6 || outputFile.substr(outputFile.length() - 5) !=
".gdml") {
270 COUT(DEBUG) <<
"Append .gdml extension to output file name" <<
ENDL;
271 outputFile.append(
".gdml");
273 parser.Write(outputFile, physVolume,
true, schemaLocation);
277 if (GGSWolowitz::outputType ==
"vgm") {
278 COUT(DEBUG) <<
"Write the VGM file." <<
ENDL;
279 Geant4GM::Factory *g4Factory =
new Geant4GM::Factory();
280 if (GGSSmartLog::verboseLevel >= GGSSmartLog::DEBUG)
281 g4Factory->SetDebug(1);
282 g4Factory->Import(physVolume);
285 RootGM::Factory *rtFactory =
new RootGM::Factory();
286 if (GGSSmartLog::verboseLevel >= GGSSmartLog::DEBUG)
287 rtFactory->SetDebug(1);
288 g4Factory->Export(rtFactory);
289 gGeoManager->CloseGeometry();
290 if (outputFile.length() < 6 || outputFile.substr(outputFile.length() - 5) !=
".root") {
291 COUT(DEBUG) <<
"Append .root extension to output file name" <<
ENDL;
292 outputFile.append(
".root");
294 gGeoManager->Export(outputFile.data());
Abstract class needed to load GGS geometry.
static GGSGeoPluginManager & GetInstance()
Get the singleton instance.
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
virtual G4VPhysicalVolume * Construct()=0
Construct the detector - virtual method.
GGSVGeometryConstruction * GetGeoConstruction()
Returns the geometry construction object.
void SetGeoDataCard(const G4String &dataCard)
Sets the geometry configuration datacard.