VGM
Version 5.5
Toggle main menu visibility
Loading...
Searching...
No Matches
packages
XmlVGM
source
GDMLExporter.cxx
Go to the documentation of this file.
1
// $Id$
2
3
// -----------------------------------------------------------------------
4
// The XmlVGM package of the Virtual Geometry Model
5
// Copyright (C) 2007, Ivana Hrivnacova
6
// All rights reserved.
7
//
8
// For the licensing terms see vgm/LICENSE.
9
// Contact: ivana@ipno.in2p3.fr
10
// -----------------------------------------------------------------------
11
12
//
13
// Author: I. Hrivnacova, 31.03.2004
14
//
15
// Class GDMLExporter
16
// ------------------------------
17
// See the class description in the header file.
18
19
#include "
VGM/volumes/IFactory.h
"
20
#include "
VGM/volumes/IPlacement.h
"
21
#include "
VGM/volumes/IVolume.h
"
22
23
#include "
ClhepVGM/transform.h
"
24
25
#include "
XmlVGM/GDMLExporter.h
"
26
#include "
XmlVGM/GDMLWriter.h
"
27
28
//_____________________________________________________________________________
29
XmlVGM::GDMLExporter::GDMLExporter
(
const
VGM::IFactory
* factory)
30
:
VExporter
(factory, new
GDMLWriter
())
31
{
33
34
dynamic_cast<
GDMLWriter
*
>
(
fWriter
)->
SetMaps
(&
fMaps
);
35
}
36
37
//_____________________________________________________________________________
38
XmlVGM::GDMLExporter::GDMLExporter
() :
VExporter
()
39
{
41
}
42
43
//_____________________________________________________________________________
44
XmlVGM::GDMLExporter::GDMLExporter
(
const
GDMLExporter
& right) :
VExporter
(right)
45
{
47
}
48
49
//_____________________________________________________________________________
50
XmlVGM::GDMLExporter::~GDMLExporter
()
51
{
52
//
53
}
54
55
// operators
56
57
//_____________________________________________________________________________
58
XmlVGM::GDMLExporter
&
XmlVGM::GDMLExporter::operator=
(
const
GDMLExporter
& right)
59
{
61
62
// check assignement to self
63
if
(
this
== &right)
return
*
this
;
64
65
// call assignement of the base class
66
VExporter::operator=
(right);
67
68
return
*
this
;
69
}
70
71
//
72
// protected methods
73
//
74
75
//_____________________________________________________________________________
76
void
XmlVGM::GDMLExporter::GenerateGeometry
(
VGM::IVolume
* volume)
77
{
78
// Generate XML geometry file for the geometry tree
79
// starting from the specified VGM volume.
80
81
// Compose filename
82
std::string fileName;
83
if
(
fFileName
==
fgkUndefinedFileName
) {
84
fileName = volume->
Name
();
85
fileName = fileName +
".gdml"
;
86
}
87
else
88
fileName =
fFileName
;
89
90
// Open XML file and document
91
fWriter
->OpenFile(fileName);
92
fWriter
->OpenDocument();
93
94
// Generate volumes tree
95
GenerateSection
(volume);
96
97
// Close XML file and document
98
fWriter
->CloseDocument();
99
fWriter
->CloseFile();
100
101
if
(
fDebug
> 0)
102
std::cout <<
"File "
<< fileName <<
" has been generated."
<< std::endl;
103
}
104
105
//_____________________________________________________________________________
106
void
XmlVGM::GDMLExporter::GenerateSection
(
VGM::IVolume
* volume)
107
{
111
112
// Create section
113
fWriter
->OpenSection(volume->
Name
());
114
fWriter
->WriteEmptyLine();
115
116
// Process basic elements needed by geometry tree
117
GeneratePositions
(volume);
118
GenerateRotations
(volume);
119
GenerateMaterials
(volume);
120
GenerateSolids
(volume);
121
122
// Process geometry tree
123
fWriter
->OpenStructure();
124
ProcessVolume
(volume);
125
fWriter
->CloseStructure();
126
fWriter
->WriteEmptyLine();
127
ClearVolumeNames
();
128
129
// Close section
130
fWriter
->CloseSection(volume->
Name
());
131
}
132
133
//_____________________________________________________________________________
134
void
XmlVGM::GDMLExporter::ProcessVolume
(
VGM::IVolume
* volume)
135
{
137
138
int
nofDaughters = volume->
NofDaughters
();
139
140
if
(nofDaughters == 0) {
141
// Open composition
142
fWriter
->OpenComposition(volume->
Name
(), volume->
MaterialName
());
143
}
144
else
{
145
146
// Recursively process daughters
147
//
148
for
(
int
i = 0; i < nofDaughters; i++) {
149
150
VGM::IVolume
* dVolume = volume->
Daughter
(i)->
Volume
();
151
152
if
(
fVolumeNames
.find(dVolume->
Name
()) ==
fVolumeNames
.end())
153
ProcessVolume
(dVolume);
154
155
// process parameterised element volumes if parameterised volume
156
if
(volume->
Daughter
(i)->
Type
() ==
VGM::kParameterised
) {
157
std::vector<VGM::Transform> transforms;
158
std::vector<VGM::IVolume*> volumes;
159
volume->
Daughter
(i)->
ParameterisedPlacementData
(transforms, volumes);
160
161
for
(
auto
parVolume : volumes) {
162
if
(
fVolumeNames
.find(parVolume->Name()) ==
fVolumeNames
.end()) {
163
ProcessVolume
(parVolume);
164
}
165
}
166
}
167
}
168
169
// Write the volume with its childs now
170
//
171
// Open composition
172
fWriter
->OpenComposition(volume->
Name
(), volume->
MaterialName
());
173
174
// Write positions
175
for
(
int
j = 0; j < nofDaughters; j++) {
176
177
if
(
fDebug
> 1) {
178
std::cout <<
"processing "
<< j <<
"th daughter of "
<< volume->
Name
()
179
<< std::endl;
180
}
181
182
fWriter
->WritePlacement(*volume->
Daughter
(j));
183
}
184
}
185
186
// Close composition
187
fWriter
->CloseComposition();
188
fWriter
->WriteEmptyLine();
189
190
// store the name of logical volume in the set
191
fVolumeNames
.insert(
fVolumeNames
.begin(), volume->
Name
());
192
}
transform.h
GDMLExporter.h
GDMLWriter.h
IFactory.h
IPlacement.h
IVolume.h
VGM::IFactory
The VGM interface to geometry factory providing functions for geometry construction and conversions.
Definition
IFactory.h:50
VGM::IPlacement::Type
virtual PlacementType Type() const =0
Return the type of this placement.
VGM::IPlacement::ParameterisedPlacementData
virtual bool ParameterisedPlacementData(std::vector< VGM::Transform > &transforms, std::vector< VGM::IVolume * > &volumes) const =0
Fill the parameterised placement data if relevant and return true; return false if not parameterised ...
VGM::IPlacement::Volume
virtual IVolume * Volume() const =0
Return the associated volume.
VGM::IVolume
The VGM interface to volumes.
Definition
IVolume.h:32
VGM::IVolume::MaterialName
virtual std::string MaterialName() const =0
Return the name of the associated material.
VGM::IVolume::Name
virtual std::string Name() const =0
Return the name of this volume.
VGM::IVolume::Daughter
virtual IPlacement * Daughter(int i) const =0
Return the i-th daughter.
VGM::IVolume::NofDaughters
virtual int NofDaughters() const =0
Return the number of volume daughters.
XmlVGM::GDMLExporter
Class for generation of geometry data files in XML, in the GDML format.
Definition
GDMLExporter.h:34
XmlVGM::GDMLExporter::GenerateSection
virtual void GenerateSection(VGM::IVolume *volume)
Definition
GDMLExporter.cxx:106
XmlVGM::GDMLExporter::GDMLExporter
GDMLExporter(const VGM::IFactory *factory)
Definition
GDMLExporter.cxx:29
XmlVGM::GDMLExporter::ProcessVolume
virtual void ProcessVolume(VGM::IVolume *volume)
Definition
GDMLExporter.cxx:134
XmlVGM::GDMLExporter::GenerateGeometry
virtual void GenerateGeometry(VGM::IVolume *volume)
Generate XML geometry file for the geometry tree starting from the specified VGM volume.
Definition
GDMLExporter.cxx:76
XmlVGM::GDMLExporter::GDMLExporter
GDMLExporter()
Definition
GDMLExporter.cxx:38
XmlVGM::GDMLExporter::operator=
GDMLExporter & operator=(const GDMLExporter &right)
Definition
GDMLExporter.cxx:58
XmlVGM::GDMLExporter::~GDMLExporter
virtual ~GDMLExporter()
Definition
GDMLExporter.cxx:50
XmlVGM::GDMLWriter
The implementation of the interface for the XML writer that writes VGM geometry objects to XML define...
Definition
GDMLWriter.h:64
XmlVGM::GDMLWriter::SetMaps
virtual void SetMaps(Maps *maps)
Definition
GDMLWriter.h:254
XmlVGM::VExporter::fDebug
int fDebug
Definition
VExporter.h:107
XmlVGM::VExporter::VExporter
VExporter(const VGM::IFactory *factory, IWriter *writer)
Definition
VExporter.cxx:44
XmlVGM::VExporter::fWriter
IWriter * fWriter
Definition
VExporter.h:104
XmlVGM::VExporter::GeneratePositions
void GeneratePositions(VGM::IVolume *volume)
Definition
VExporter.cxx:507
XmlVGM::VExporter::GenerateMaterials
void GenerateMaterials(VGM::IVolume *volume)
Definition
VExporter.cxx:556
XmlVGM::VExporter::operator=
VExporter & operator=(const VExporter &)
Definition
VExporter.cxx:102
XmlVGM::VExporter::GenerateRotations
void GenerateRotations(VGM::IVolume *volume)
Definition
VExporter.cxx:529
XmlVGM::VExporter::fMaps
Maps fMaps
Definition
VExporter.h:108
XmlVGM::VExporter::fVolumeNames
StringSet fVolumeNames
Definition
VExporter.h:106
XmlVGM::VExporter::ClearVolumeNames
void ClearVolumeNames()
Definition
VExporter.cxx:634
XmlVGM::VExporter::fFileName
std::string fFileName
Definition
VExporter.h:105
XmlVGM::VExporter::GenerateSolids
void GenerateSolids(VGM::IVolume *volume)
Definition
VExporter.cxx:621
XmlVGM::VExporter::fgkUndefinedFileName
static const std::string fgkUndefinedFileName
Definition
VExporter.h:99
VGM::kParameterised
@ kParameterised
Definition
IPlacement.h:35
Generated on
for VGM by
1.17.0