VGM Version 5.3
Loading...
Searching...
No Matches
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
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//_____________________________________________________________________________
30 : VExporter(factory, new GDMLWriter())
31{
33
34 dynamic_cast<GDMLWriter*>(fWriter)->SetMaps(&fMaps);
35}
36
37//_____________________________________________________________________________
42
43//_____________________________________________________________________________
48
49//_____________________________________________________________________________
54
55// operators
56
57//_____________________________________________________________________________
59{
61
62 // check assignement to self
63 if (this == &right) return *this;
64
65 // call assignement of the base class
67
68 return *this;
69}
70
71//
72// protected methods
73//
74
75//_____________________________________________________________________________
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//_____________________________________________________________________________
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//_____________________________________________________________________________
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}
The VGM interface to geometry factory providing functions for geometry construction and conversions.
Definition IFactory.h:50
virtual PlacementType Type() const =0
Return the type of this placement.
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 ...
virtual IVolume * Volume() const =0
Return the associated volume.
The VGM interface to volumes.
Definition IVolume.h:32
virtual std::string MaterialName() const =0
Return the name of the associated material.
virtual std::string Name() const =0
Return the name of this volume.
virtual IPlacement * Daughter(int i) const =0
Return the i-th daughter.
virtual int NofDaughters() const =0
Return the number of volume daughters.
Class for generation of geometry data files in XML, in the GDML format.
virtual void GenerateSection(VGM::IVolume *volume)
virtual void ProcessVolume(VGM::IVolume *volume)
virtual void GenerateGeometry(VGM::IVolume *volume)
Generate XML geometry file for the geometry tree starting from the specified VGM volume.
GDMLExporter & operator=(const GDMLExporter &right)
The implementation of the interface for the XML writer that writes VGM geometry objects to XML define...
Definition GDMLWriter.h:64
virtual void SetMaps(Maps *maps)
Definition GDMLWriter.h:252
Class for generation of geometry data files in XML, the XML format is independent from the geometry o...
Definition VExporter.h:48
IWriter * fWriter
Definition VExporter.h:104
VExporter & operator=(const VExporter &)
@ kParameterised
Definition IPlacement.h:35