Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4VGMMessenger.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
14
15#ifdef USE_VGM
16
17#include "TG4VGMMessenger.h"
18#include "TG4GeometryServices.h"
19
20#include <Geant4GM/volumes/Factory.h>
21#include <RootGM/volumes/Factory.h>
22#include <RootGM/volumes/Placement.h>
23#include <XmlVGM/AGDDExporter.h>
24#include <XmlVGM/GDMLExporter.h>
25
26#include <G4UIcmdWithABool.hh>
27#include <G4UIcmdWithAString.hh>
28#include <G4UIcmdWithAnInteger.hh>
29#include <G4UIcmdWithoutParameter.hh>
30#include <G4UIdirectory.hh>
31
32#include <TGeoManager.h>
33
34G4UIdirectory* TG4VGMMessenger::fgDirectory = 0;
35G4UIcmdWithoutParameter* TG4VGMMessenger::fgGenerateRootCmd = 0;
37
38//_____________________________________________________________________________
40 const G4String& xmlFormat, const G4String& userGeometry)
41 : G4UImessenger(),
42 fGeometryInput(),
43 fXmlFormat(xmlFormat),
44 fImportFactory(0),
45 fG4Factory(0),
46 fRootFactory(0),
47 fXmlVGMExporter(0),
48 fGenerateXMLCmd()
49{
51
52 if (userGeometry == "geomVMCtoGeant4" || userGeometry == "geomRootToGeant4" ||
53 userGeometry == "geomGeant4") {
54 fGeometryInput = "geant4";
55 }
56
57 if (userGeometry == "geomVMCtoRoot" || userGeometry == "geomRoot") {
58 fGeometryInput = "root";
59 }
60
61 if (!fgDirectory) {
62 fgDirectory = new G4UIdirectory("/vgm/");
63 fgDirectory->SetGuidance("XML geometry generator control commands.");
64
65 G4String cmdName("/vgm/generateRoot");
66 fgGenerateRootCmd = new G4UIcmdWithoutParameter(cmdName, this);
67 fgGenerateRootCmd->SetGuidance("Export geometry in Root file");
68 fgGenerateRootCmd->AvailableForStates(G4State_Idle);
69 }
70
71 G4String cmdName("/vgm/generate");
72 cmdName = cmdName + xmlFormat;
73 fGenerateXMLCmd = new G4UIcmdWithAString(cmdName, this);
74 fGenerateXMLCmd->SetGuidance("Generate geometry XML file");
75 fGenerateXMLCmd->SetGuidance(
76 "starting from a logical volume specified by name;");
77 fGenerateXMLCmd->SetGuidance(
78 "if no name is given - the whole world is processed.");
79 fGenerateXMLCmd->SetParameterName("lvName", true);
80 fGenerateXMLCmd->SetDefaultValue("");
81 fGenerateXMLCmd->AvailableForStates(G4State_Idle);
82
83 cmdName = G4String("/vgm/set") + xmlFormat + G4String("NumWidth");
84 fSetXMLNumWidthCmd = new G4UIcmdWithAnInteger(cmdName, this);
85 fSetXMLNumWidthCmd->SetGuidance("Set number with for XML generation");
86 fSetXMLNumWidthCmd->SetParameterName("xmlNumWidth", false);
87 fSetXMLNumWidthCmd->AvailableForStates(G4State_Idle);
88
89 cmdName = G4String("/vgm/set") + xmlFormat + G4String("NumPrecision");
90 fSetXMLNumPrecisionCmd = new G4UIcmdWithAnInteger(cmdName, this);
91 fSetXMLNumPrecisionCmd->SetGuidance(
92 "Set number precision for XML generation");
93 fSetXMLNumPrecisionCmd->SetParameterName("xmlNumPrecision", false);
94 fSetXMLNumPrecisionCmd->AvailableForStates(G4State_Idle);
95
97 new G4UIcmdWithABool("/vgm/setAssembliesInNames", this);
98 fSetAssembliesInNamesCmd->SetGuidance(
99 "Activate/inactivate including the names of Root assemblies");
100 fSetAssembliesInNamesCmd->SetGuidance(
101 "in volume names when exporting Root geometry.");
102 fSetAssembliesInNamesCmd->SetParameterName("assembliesInNames", false);
103 fSetAssembliesInNamesCmd->AvailableForStates(G4State_PreInit);
104
105 fSetNameSeparatorCmd = new G4UIcmdWithAString("/vgm/setNameSeparator", this);
106 fSetNameSeparatorCmd->SetGuidance("Set the name separator used when ");
107 fSetNameSeparatorCmd->SetGuidance(
108 "including the names of Root assemblies in volume names");
109 fSetNameSeparatorCmd->SetGuidance(
110 "when exporting Root geometry is activated .");
111 fSetNameSeparatorCmd->SetParameterName("nameSeparatoe", false);
112 fSetNameSeparatorCmd->AvailableForStates(G4State_PreInit);
113
114 fgCounter++;
115}
116
117//_____________________________________________________________________________
119{
121
122 delete fG4Factory;
123 delete fRootFactory;
124 delete fXmlVGMExporter;
125
126 fgCounter--;
127 if (fgCounter == 0) {
128 delete fgDirectory;
129 delete fgGenerateRootCmd;
130 fgDirectory = 0;
132 }
133 delete fGenerateXMLCmd;
134 delete fSetXMLNumWidthCmd;
138}
139
140// private methods
141
142//_____________________________________________________________________________
144{
146 // ---
147
148 if (!fXmlVGMExporter) {
149 // Create VGM exporter if not yet done
150 if (fXmlFormat == "AGDD") {
151 fXmlVGMExporter = new XmlVGM::AGDDExporter(fImportFactory);
152 }
153 if (fXmlFormat == "GDML") {
154 fXmlVGMExporter = new XmlVGM::GDMLExporter(fImportFactory);
155 }
156 }
157}
158
159// public methods
160
161//_____________________________________________________________________________
162void TG4VGMMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
163{
165 // ---
166
167 if (command == fSetAssembliesInNamesCmd) {
168 RootGM::Placement::SetIncludeAssembliesInNames(
169 fSetAssembliesInNamesCmd->GetNewBoolValue(newValues));
170 return;
171 }
172
173 if (command == fSetNameSeparatorCmd) {
174 RootGM::Placement::SetNameSeparator(newValues.at(0));
175 return;
176 }
177
178 if (fGeometryInput == "geant4" && (!fG4Factory)) {
179 // Import Geant4 geometry in VGM
180 fG4Factory = new Geant4GM::Factory();
182 fImportFactory->SetIgnore(true);
183 // fG4Factory->SetDebug(1);
184 fG4Factory->Import(TG4GeometryServices::Instance()->GetWorld());
185 }
186
187 if (fGeometryInput == "root" && (!fRootFactory)) {
188 // Import Root geometry in VGM
189 fRootFactory = new RootGM::Factory();
191 fImportFactory->SetIgnore(true);
192 // fRootFactory->SetDebug(1);
193 fRootFactory->Import(gGeoManager->GetTopNode());
194 }
195
196 if (command == fgGenerateRootCmd) {
197 if (!fRootFactory) {
198 fRootFactory = new RootGM::Factory();
199 fG4Factory->Export(fRootFactory);
200 gGeoManager->CloseGeometry();
201 }
202 gGeoManager->Export("geometry.root");
203 }
204
205 if (command == fGenerateXMLCmd) {
206
208
209 if (newValues == "")
210 fXmlVGMExporter->GenerateXMLGeometry();
211 else
212 fXmlVGMExporter->GenerateXMLGeometry(newValues);
213 }
214
215 if (command == fSetXMLNumWidthCmd) {
217 fXmlVGMExporter->SetNumWidth(fSetXMLNumWidthCmd->GetNewIntValue(newValues));
218 }
219
220 if (command == fSetXMLNumPrecisionCmd) {
222 fXmlVGMExporter->SetNumPrecision(
223 fSetXMLNumPrecisionCmd->GetNewIntValue(newValues));
224 }
225}
226
227#endif // USE_VGM
Definition of the TG4GeometryServices class.
Definition of the TG4VGMMessenger class.
static TG4GeometryServices * Instance()
TG4VGMMessenger()
Not implemented.
G4UIcmdWithABool * fSetAssembliesInNamesCmd
command: /xml/setAssembliesInNames
G4UIcmdWithAString * fSetNameSeparatorCmd
command: /xml/setNameSeparator
virtual void SetNewValue(G4UIcommand *command, G4String newValues)
static G4UIdirectory * fgDirectory
command directory
Geant4GM::Factory * fG4Factory
Geant4 VGM Factory.
G4UIcmdWithAnInteger * fSetXMLNumPrecisionCmd
command: /vgm/setXMLNumPrecision
XmlVGM::VExporter * fXmlVGMExporter
associated class
G4UIcmdWithAString * fGenerateXMLCmd
command: /vgm/generateXXX
static G4UIcmdWithoutParameter * fgGenerateRootCmd
command: /xml/generateRoot
G4String fGeometryInput
The geometry input type (Root/Geant4)
RootGM::Factory * fRootFactory
Root VGM Factory.
G4String fXmlFormat
The XML format.
VGM::IFactory * fImportFactory
VGM factory for import.
G4UIcmdWithAnInteger * fSetXMLNumWidthCmd
command: /vgm/setXMLNumWidth
static G4int fgCounter
instances counter