Geant4 VMC
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
source
geometry
src
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
34
G4UIdirectory*
TG4VGMMessenger::fgDirectory
= 0;
35
G4UIcmdWithoutParameter*
TG4VGMMessenger::fgGenerateRootCmd
= 0;
36
G4int
TG4VGMMessenger::fgCounter
= 0;
37
38
//_____________________________________________________________________________
39
TG4VGMMessenger::TG4VGMMessenger
(
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
96
fSetAssembliesInNamesCmd
=
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
//_____________________________________________________________________________
118
TG4VGMMessenger::~TG4VGMMessenger
()
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;
131
fgGenerateRootCmd
= 0;
132
}
133
delete
fGenerateXMLCmd
;
134
delete
fSetXMLNumWidthCmd
;
135
delete
fSetXMLNumPrecisionCmd
;
136
delete
fSetAssembliesInNamesCmd
;
137
delete
fSetNameSeparatorCmd
;
138
}
139
140
// private methods
141
142
//_____________________________________________________________________________
143
void
TG4VGMMessenger::CreateVGMExporter
()
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
//_____________________________________________________________________________
162
void
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();
181
fImportFactory
=
fG4Factory
;
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();
190
fImportFactory
=
fRootFactory
;
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
207
CreateVGMExporter
();
208
209
if
(newValues ==
""
)
210
fXmlVGMExporter
->GenerateXMLGeometry();
211
else
212
fXmlVGMExporter
->GenerateXMLGeometry(newValues);
213
}
214
215
if
(command ==
fSetXMLNumWidthCmd
) {
216
CreateVGMExporter
();
217
fXmlVGMExporter
->SetNumWidth(
fSetXMLNumWidthCmd
->GetNewIntValue(newValues));
218
}
219
220
if
(command ==
fSetXMLNumPrecisionCmd
) {
221
CreateVGMExporter
();
222
fXmlVGMExporter
->SetNumPrecision(
223
fSetXMLNumPrecisionCmd
->GetNewIntValue(newValues));
224
}
225
}
226
227
#endif
// USE_VGM
TG4GeometryServices.h
Definition of the TG4GeometryServices class.
TG4VGMMessenger.h
Definition of the TG4VGMMessenger class.
G4UIcommand
G4UImessenger
TG4GeometryServices::Instance
static TG4GeometryServices * Instance()
Definition
TG4GeometryServices.h:169
TG4VGMMessenger::~TG4VGMMessenger
virtual ~TG4VGMMessenger()
Definition
TG4VGMMessenger.cxx:118
TG4VGMMessenger::TG4VGMMessenger
TG4VGMMessenger()
Not implemented.
TG4VGMMessenger::fSetAssembliesInNamesCmd
G4UIcmdWithABool * fSetAssembliesInNamesCmd
command: /xml/setAssembliesInNames
Definition
TG4VGMMessenger.h:91
TG4VGMMessenger::fSetNameSeparatorCmd
G4UIcmdWithAString * fSetNameSeparatorCmd
command: /xml/setNameSeparator
Definition
TG4VGMMessenger.h:92
TG4VGMMessenger::CreateVGMExporter
void CreateVGMExporter()
Definition
TG4VGMMessenger.cxx:143
TG4VGMMessenger::SetNewValue
virtual void SetNewValue(G4UIcommand *command, G4String newValues)
Definition
TG4VGMMessenger.cxx:162
TG4VGMMessenger::fgDirectory
static G4UIdirectory * fgDirectory
command directory
Definition
TG4VGMMessenger.h:68
TG4VGMMessenger::fG4Factory
Geant4GM::Factory * fG4Factory
Geant4 VGM Factory.
Definition
TG4VGMMessenger.h:83
TG4VGMMessenger::fSetXMLNumPrecisionCmd
G4UIcmdWithAnInteger * fSetXMLNumPrecisionCmd
command: /vgm/setXMLNumPrecision
Definition
TG4VGMMessenger.h:89
TG4VGMMessenger::fXmlVGMExporter
XmlVGM::VExporter * fXmlVGMExporter
associated class
Definition
TG4VGMMessenger.h:85
TG4VGMMessenger::fGenerateXMLCmd
G4UIcmdWithAString * fGenerateXMLCmd
command: /vgm/generateXXX
Definition
TG4VGMMessenger.h:86
TG4VGMMessenger::fgGenerateRootCmd
static G4UIcmdWithoutParameter * fgGenerateRootCmd
command: /xml/generateRoot
Definition
TG4VGMMessenger.h:71
TG4VGMMessenger::fGeometryInput
G4String fGeometryInput
The geometry input type (Root/Geant4).
Definition
TG4VGMMessenger.h:80
TG4VGMMessenger::fRootFactory
RootGM::Factory * fRootFactory
Root VGM Factory.
Definition
TG4VGMMessenger.h:84
TG4VGMMessenger::fXmlFormat
G4String fXmlFormat
The XML format.
Definition
TG4VGMMessenger.h:81
TG4VGMMessenger::fImportFactory
VGM::IFactory * fImportFactory
VGM factory for import.
Definition
TG4VGMMessenger.h:82
TG4VGMMessenger::fSetXMLNumWidthCmd
G4UIcmdWithAnInteger * fSetXMLNumWidthCmd
command: /vgm/setXMLNumWidth
Definition
TG4VGMMessenger.h:87
TG4VGMMessenger::fgCounter
static G4int fgCounter
instances counter
Definition
TG4VGMMessenger.h:74
Generated on
for Geant4 VMC by
1.17.0