Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4HepRepFileXMLWriter Class Reference

#include <G4HepRepFileXMLWriter.hh>

Public Member Functions

 G4HepRepFileXMLWriter ()
 
void addType (const char *name, int newTypeDepth)
 
void addInstance ()
 
void addPrimitive ()
 
void addPoint (double x, double y, double z)
 
void addAttDef (const char *name, const char *desc, const char *type, const char *extra)
 
void addAttValue (const char *name, const char *value)
 
void addAttValue (const char *name, double value)
 
void addAttValue (const char *name, int value)
 
void addAttValue (const char *name, bool value)
 
void addAttValue (const char *name, double value1, double value2, double value3)
 
void open (const char *filespec)
 
void close ()
 
void endTypes ()
 

Public Attributes

bool isOpen
 
int typeDepth
 
bool inType [50]
 
bool inInstance [50]
 
char * prevTypeName [50]
 

Detailed Description

Definition at line 50 of file G4HepRepFileXMLWriter.hh.

Constructor & Destructor Documentation

◆ G4HepRepFileXMLWriter()

G4HepRepFileXMLWriter::G4HepRepFileXMLWriter ( )

Definition at line 47 of file G4HepRepFileXMLWriter.cc.

48{
49 isOpen = false;
50 init();
51}

Member Function Documentation

◆ addAttDef()

void G4HepRepFileXMLWriter::addAttDef ( const char *  name,
const char *  desc,
const char *  type,
const char *  extra 
)

Definition at line 194 of file G4HepRepFileXMLWriter.cc.

198{
199 if (fout.good())
200 {
201 indent();
202 fout << " <heprep:attdef extra=\"" << extra << "\" name=\"" << name << "\" type=\"" << type << "\"" << G4endl;
203 indent();
204 fout << " desc=\"" << desc << "\"/>" << G4endl;
205 } else {
206#ifdef G4HEPREPFILEDEBUG
207 G4cout << "G4HepRepFileXMLWriter:addAttDef No file is currently open" << G4endl;
208#endif
209 }
210}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
const char * name(G4int ptype)

Referenced by G4HepRepFileSceneHandler::AddCompound().

◆ addAttValue() [1/5]

void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
bool  value 
)

Definition at line 261 of file G4HepRepFileXMLWriter.cc.

263{
264 if (fout.good())
265 {
266 indent();
267 fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
268 indent();
269 if (value)
270 fout << " value=\"True\"/>" << G4endl;
271 else
272 fout << " value=\"False\"/>" << G4endl;
273 } else {
274#ifdef G4HEPREPFILEDEBUG
275 G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
276#endif
277 }
278}

◆ addAttValue() [2/5]

void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
const char *  value 
)

Definition at line 213 of file G4HepRepFileXMLWriter.cc.

215{
216 if (fout.good())
217 {
218 indent();
219 fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
220 indent();
221 fout << " value=\"" << value << "\"/>" << G4endl;
222 } else {
223#ifdef G4HEPREPFILEDEBUG
224 G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
225#endif
226 }
227}

Referenced by G4HepRepFileSceneHandler::AddCompound(), G4HepRepFileSceneHandler::AddPrimitive(), G4HepRepFileSceneHandler::AddSolid(), G4HepRepFileSceneHandler::InitHit(), and G4HepRepFileSceneHandler::InitTrajectory().

◆ addAttValue() [3/5]

void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
double  value 
)

Definition at line 229 of file G4HepRepFileXMLWriter.cc.

231{
232 if (fout.good())
233 {
234 indent();
235 fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
236 indent();
237 fout << " value=\"" << value << "\"/>" << G4endl;
238 } else {
239#ifdef G4HEPREPFILEDEBUG
240 G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
241#endif
242 }
243}

◆ addAttValue() [4/5]

void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
double  value1,
double  value2,
double  value3 
)

Definition at line 280 of file G4HepRepFileXMLWriter.cc.

284{
285 if (fout.good())
286 {
287 int redness = int(value1*255.);
288 int greenness = int(value2*255.);
289 int blueness = int(value3*255.);
290 indent();
291 fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
292 indent();
293 fout << " value=\"" << redness << "," << greenness << "," << blueness << "\"/>" << G4endl;
294 } else {
295#ifdef G4HEPREPFILEDEBUG
296 G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
297#endif
298 }
299}

◆ addAttValue() [5/5]

void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
int  value 
)

Definition at line 245 of file G4HepRepFileXMLWriter.cc.

247{
248 if (fout.good())
249 {
250 indent();
251 fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
252 indent();
253 fout << " value=\"" << value << "\"/>" << G4endl;
254 } else {
255#ifdef G4HEPREPFILEDEBUG
256 G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
257#endif
258 }
259}

◆ addInstance()

void G4HepRepFileXMLWriter::addInstance ( )

Definition at line 119 of file G4HepRepFileXMLWriter.cc.

120{
121 if (fout.good())
122 {
123 if (inType[typeDepth])
124 {
125 endInstance();
126 inInstance[typeDepth] = true;
127 indent();
128 fout << "<heprep:instance>" << G4endl;
129 } else {
130#ifdef G4HEPREPFILEDEBUG
131 G4cout << "G4HepRepFileXMLWriter:addInstance No HepRep Type is currently open" << G4endl;
132#endif
133 }
134 } else {
135#ifdef G4HEPREPFILEDEBUG
136 G4cout << "G4HepRepFileXMLWriter:addInstance No file is currently open" << G4endl;
137#endif
138 }
139}

Referenced by G4HepRepFileSceneHandler::AddCompound(), addType(), G4HepRepFileSceneHandler::InitHit(), and G4HepRepFileSceneHandler::InitTrajectory().

◆ addPoint()

void G4HepRepFileXMLWriter::addPoint ( double  x,
double  y,
double  z 
)

Definition at line 163 of file G4HepRepFileXMLWriter.cc.

164{
165 if (fout.good())
166 {
167 if (inPrimitive)
168 {
169 endPoint();
170 inPoint = true;
171 indent();
172
173 // Include scale and center values
175 G4double scale = messenger->getScale();
176 G4ThreeVector center = messenger->getCenter();
177 G4double xNew = scale * ( x - center.x());
178 G4double yNew = scale * ( y - center.y());
179 G4double zNew = scale * ( z - center.z());
180
181 fout << "<heprep:point x=\"" << xNew << "\" y=\"" << yNew << "\" z=\"" << zNew << "\">" << G4endl;
182 } else {
183#ifdef G4HEPREPFILEDEBUG
184 G4cout << "G4HepRepFileXMLWriter:addPoint No HepRep Primitive is currently open" << G4endl;
185#endif
186 }
187 } else {
188#ifdef G4HEPREPFILEDEBUG
189 G4cout << "G4HepRepFileXMLWriter:addPoint No file is currently open" << G4endl;
190#endif
191 }
192}
double G4double
Definition: G4Types.hh:83
double z() const
double x() const
double y() const
virtual G4double getScale()
static G4HepRepMessenger * GetInstance()
virtual G4ThreeVector getCenter()

Referenced by G4HepRepFileSceneHandler::AddCompound(), G4HepRepFileSceneHandler::AddPrimitive(), and G4HepRepFileSceneHandler::AddSolid().

◆ addPrimitive()

void G4HepRepFileXMLWriter::addPrimitive ( )

Definition at line 141 of file G4HepRepFileXMLWriter.cc.

142{
143 if (fout.good())
144 {
146 {
147 endPrimitive();
148 inPrimitive = true;
149 indent();
150 fout << "<heprep:primitive>" << G4endl;
151 } else {
152#ifdef G4HEPREPFILEDEBUG
153 G4cout << "G4HepRepFileXMLWriter:addPrimitive No HepRep Instance is currently open" << G4endl;
154#endif
155 }
156 } else {
157#ifdef G4HEPREPFILEDEBUG
158 G4cout << "G4HepRepFileXMLWriter:addPrimitive No file is currently open" << G4endl;
159#endif
160 }
161}

Referenced by G4HepRepFileSceneHandler::AddCompound(), G4HepRepFileSceneHandler::AddPrimitive(), and G4HepRepFileSceneHandler::AddSolid().

◆ addType()

void G4HepRepFileXMLWriter::addType ( const char *  name,
int  newTypeDepth 
)

Definition at line 70 of file G4HepRepFileXMLWriter.cc.

71{
72 if (fout.good())
73 {
74 // Flatten structure if it exceeds maximum allowed typeDepth of 49.
75 if (newTypeDepth > 49)
76 newTypeDepth = 49;
77
78 if (newTypeDepth < 0)
79 newTypeDepth = 0;
80
81 // Insert any layers that are missing from the hierarchy (protects against
82 // callers that skip from, say, layer 1 to layer 3 with no layer 2).
83 while (typeDepth < (newTypeDepth-1)) {
84 addType("Layer Inserted by G4HepRepFileXMLWriter", typeDepth + 1);
86 }
87
88 // If moving closer to the root, close previously open types.
89 while (newTypeDepth<typeDepth)
90 endType();
91
92 // Close any remaining primitives of the current instance.
93 endPrimitive();
94
95 // If this is a new type name for the current depth, declare the
96 // new Type. Otherwise, it is just another Instance of the current Type.
97 if (strcmp(name,prevTypeName[newTypeDepth])!=0)
98 {
99 if (inType[newTypeDepth])
100 endType();
101
102 prevTypeName[newTypeDepth] = new char[strlen(name)+1];
103 strcpy(prevTypeName[newTypeDepth],name);
104
105 inType[newTypeDepth] = true;
106 indent();
107 fout << "<heprep:type version=\"null\" name=\"" << name << "\">"
108 << G4endl;
109
110 typeDepth = newTypeDepth;
111 }
112 } else {
113#ifdef G4HEPREPFILEDEBUG
114 G4cout << "G4HepRepFileXMLWriter:addType No file is currently open." << G4endl;
115#endif
116 }
117}
void addType(const char *name, int newTypeDepth)

Referenced by G4HepRepFileSceneHandler::AddCompound(), and addType().

◆ close()

void G4HepRepFileXMLWriter::close ( )

Definition at line 320 of file G4HepRepFileXMLWriter.cc.

321{
322 // Close any remaining open Types
323 endTypes();
324
325 if (fout.good()) {
326 fout << "</heprep:heprep>" << G4endl;
327 fout.close( );
328 isOpen = false;
329 } else {
330 G4cout << "G4HepRepFileXMLWriter:close No file is currently open" << G4endl;
331 }
332}

Referenced by open(), and G4HepRepFileViewer::ShowView().

◆ endTypes()

void G4HepRepFileXMLWriter::endTypes ( )

Definition at line 334 of file G4HepRepFileXMLWriter.cc.

335{
336 // Close any remaining open Types
337 while(typeDepth>-1)
338 endType();
339}

Referenced by close().

◆ open()

void G4HepRepFileXMLWriter::open ( const char *  filespec)

Definition at line 301 of file G4HepRepFileXMLWriter.cc.

302{
303 if (isOpen)
304 close();
305
306 fout.open(fileSpec);
307
308 if (fout.good()) {
309 fout << "<?xml version=\"1.0\" ?>" << G4endl;
310 fout << "<heprep:heprep xmlns:heprep=\"http://www.slac.stanford.edu/~perl/heprep/\"" << G4endl;
311 fout << " xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" xsi:schemaLocation=\"HepRep.xsd\">" << G4endl;
312
313 isOpen = true;
314 init();
315 } else {
316 G4cout << "G4HepRepFileXMLWriter:open Unable to write to file " << fileSpec << G4endl;
317 }
318}

Member Data Documentation

◆ inInstance

bool G4HepRepFileXMLWriter::inInstance[50]

Definition at line 90 of file G4HepRepFileXMLWriter.hh.

Referenced by addInstance(), and addPrimitive().

◆ inType

bool G4HepRepFileXMLWriter::inType[50]

Definition at line 89 of file G4HepRepFileXMLWriter.hh.

Referenced by addInstance(), and addType().

◆ isOpen

bool G4HepRepFileXMLWriter::isOpen

◆ prevTypeName

char* G4HepRepFileXMLWriter::prevTypeName[50]

Definition at line 91 of file G4HepRepFileXMLWriter.hh.

Referenced by G4HepRepFileSceneHandler::AddCompound(), and addType().

◆ typeDepth

int G4HepRepFileXMLWriter::typeDepth

Definition at line 88 of file G4HepRepFileXMLWriter.hh.

Referenced by addInstance(), addPrimitive(), addType(), and endTypes().


The documentation for this class was generated from the following files: