15 #include "G4Material.hh"
17 #include "G4LogicalVolume.hh"
18 #include "G4PVPlacement.hh"
19 #include "G4PVReplica.hh"
20 #include "G4GeometryManager.hh"
21 #include "G4PhysicalVolumeStore.hh"
22 #include "G4LogicalVolumeStore.hh"
23 #include "G4SolidStore.hh"
24 #include "G4VisAttributes.hh"
25 #include "G4Colour.hh"
27 #include "G4GDMLParser.hh"
29 #include "G4TransportationManager.hh"
30 #include "G4RunManager.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";
77 std::cout <<
" -gd, --geo-data-card FILE data card filename for geometry configuration [default: not set]\n";
78 std::cout <<
" -t, --output-type TYPE output type (possible values: "
85 "default: " << GGSWolowitz::outputType <<
")\n";
86 std::cout <<
" -i, --input-file FILE file containing input arguments [default: not set]\n";
88 <<
" -u, --gdml-schema-location url of schema location [default: http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd]\n";
89 std::cout <<
" -v, --verbose be verbose [default: false]\n";
90 std::cout <<
" -V, --version displays software version and exit\n";
91 std::cout <<
" -h, --help display this help and exit\n";
92 std::cout <<
"\nFor bug reporting instructions, please see for example:\n";
93 std::cout <<
" <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
94 std::cout <<
"Report bugs to: mori@fi.infn.it" << std::endl;
98 std::cout <<
"GGSWolowitz geometry software\n";
99 std::cout <<
"Using GGS " << GGSVERSION << std::endl;
102 using namespace GGSWolowitz;
104 int HandleInputPar(
int argc,
const char **argv) {
105 static const std::string routineName(
"HandleInputPar");
107 GGSSmartLog::verboseLevel = GGSSmartLog::WARNING;
108 int vLevel = GGSSmartLog::INFO;
112 if (!strcmp(argv[i],
"-h") || !strcmp(argv[i],
"--help")) {
117 if (!strcmp(argv[i],
"-V") || !strcmp(argv[i],
"--version")) {
122 else if (!strcmp(argv[i],
"-v") || !strcmp(argv[i],
"--verbose")) {
123 std::string vLevStr(argv[++i]);
124 if (vLevStr ==
"error")
125 vLevel = GGSSmartLog::ERROR;
126 else if (vLevStr ==
"warning")
127 vLevel = GGSSmartLog::WARNING;
128 else if (vLevStr ==
"normal" || vLevStr ==
"info")
129 vLevel = GGSSmartLog::INFO;
130 else if (vLevStr ==
"debug")
131 vLevel = GGSSmartLog::DEBUG;
132 else if (vLevStr ==
"deepdeb")
133 vLevel = GGSSmartLog::DEEPDEB;
135 COUT(WARNING) <<
"Unrecognized verbosity level: " << vLevStr <<
". Ignoring." <<
ENDL;
139 else if (!strcmp(argv[i],
"-o") || !strcmp(argv[i],
"--output-file")) {
144 outputFile = argv[i];
147 else if (!strcmp(argv[i],
"-t") || !strcmp(argv[i],
"--output-type")) {
152 if (strcmp(argv[i],
"gdml") && strcmp(argv[i],
"vgm")) {
153 COUT(ERROR) <<
"Unknown output type: " << argv[i] <<
ENDL;
157 if (!strcmp(argv[i],
"gdml")) {
158 COUT(ERROR) <<
"Converting to gdml requires Geant4 version compiled with Xerces-C" <<
ENDL;
163 if (!strcmp(argv[i],
"vgm")) {
164 COUT(ERROR) <<
"Converting to vgm requires Virtual Geometry Model" <<
ENDL;
169 outputType = argv[i];
172 else if (!strcmp(argv[i],
"-g") || !strcmp(argv[i],
"--geometry")) {
177 geometryFile = argv[i];
180 else if (!strcmp(argv[i],
"-gd") || !strcmp(argv[i],
"--geo-data-card")) {
185 geoDataCard = argv[i];
188 else if (!strcmp(argv[i],
"-i") || !strcmp(argv[i],
"--input-file")) {
196 else if (!strcmp(argv[i],
"-u") || !strcmp(argv[i],
"--gdml-schema-location")) {
201 schemaLocation = argv[i];
205 COUT(WARNING) <<
"Unidentified input argument \"" << argv[i] <<
"\". Ignoring." <<
ENDL;
211 GGSSmartLog::verboseLevel = vLevel;
215 int main(
int argc,
const char** argv) {
216 static const std::string routineName(
"GGSWolowitz");
218 if (HandleInputPar(argc, argv))
223 if (strcmp(inputFile.c_str(),
"")) {
225 std::string mych[1000];
228 const char **fileArgv;
229 fileArgv =
new const char*[nPar];
232 fileArgv[i] = (mych[i]).c_str();
235 if (HandleInputPar(nPar, fileArgv))
240 COUT(DEBUG) <<
"Start run manager " <<
ENDL;
241 G4RunManager* runManager =
new G4RunManager();
244 COUT(ERROR) <<
"Impossible to load geometry library " << geometryFile <<
". Exit." <<
ENDL;
251 COUT(ERROR) <<
"Can't create the geometry. Exit." <<
ENDL;
257 COUT(DEBUG) <<
"Construct the geometry." <<
ENDL;
260 G4VPhysicalVolume *physVolume = geometry->
Construct();
263 if (GGSWolowitz::outputType ==
"gdml") {
264 COUT(DEBUG) <<
"Write the GDML file." <<
ENDL;
266 parser.SetAddPointerToName(
true);
267 if (outputFile.length() < 6 || outputFile.substr(outputFile.length()-5) !=
".gdml") {
268 COUT(DEBUG) <<
"Append .gdml extension to output file name" <<
ENDL;
269 outputFile.append(
".gdml");
271 parser.Write(outputFile, physVolume,
true, schemaLocation);
275 if (GGSWolowitz::outputType ==
"vgm") {
276 COUT(DEBUG) <<
"Write the VGM file." <<
ENDL;
277 Geant4GM::Factory* g4Factory =
new Geant4GM::Factory();
278 if(GGSSmartLog::verboseLevel >= GGSSmartLog::DEBUG)
279 g4Factory->SetDebug(1);
280 g4Factory->Import(physVolume);
283 RootGM::Factory* rtFactory =
new RootGM::Factory();
284 if(GGSSmartLog::verboseLevel >= GGSSmartLog::DEBUG)
285 rtFactory->SetDebug(1);
286 g4Factory->Export(rtFactory);
287 gGeoManager->CloseGeometry();
288 if (outputFile.length() < 6 || outputFile.substr(outputFile.length()-5) !=
".root") {
289 COUT(DEBUG) <<
"Append .root extension to output file name" <<
ENDL;
290 outputFile.append(
".root");
292 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.