Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 51 of file G4HepRepFileXMLWriter.hh.

Constructor & Destructor Documentation

G4HepRepFileXMLWriter::G4HepRepFileXMLWriter ( )

Definition at line 48 of file G4HepRepFileXMLWriter.cc.

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

Member Function Documentation

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

Definition at line 195 of file G4HepRepFileXMLWriter.cc.

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

Here is the caller graph for this function:

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

Definition at line 214 of file G4HepRepFileXMLWriter.cc.

216 {
217  if (fout.good())
218  {
219  indent();
220  fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
221  indent();
222  fout << " value=\"" << value << "\"/>" << G4endl;
223  } else {
224 #ifdef G4HEPREPFILEDEBUG
225  G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
226 #endif
227  }
228 }
const XML_Char * name
Definition: expat.h:151
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
Definition: expat.h:331
#define G4endl
Definition: G4ios.hh:61

Here is the caller graph for this function:

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

Definition at line 230 of file G4HepRepFileXMLWriter.cc.

232 {
233  if (fout.good())
234  {
235  indent();
236  fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
237  indent();
238  fout << " value=\"" << value << "\"/>" << G4endl;
239  } else {
240 #ifdef G4HEPREPFILEDEBUG
241  G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
242 #endif
243  }
244 }
const XML_Char * name
Definition: expat.h:151
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
Definition: expat.h:331
#define G4endl
Definition: G4ios.hh:61
void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
int  value 
)

Definition at line 246 of file G4HepRepFileXMLWriter.cc.

248 {
249  if (fout.good())
250  {
251  indent();
252  fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
253  indent();
254  fout << " value=\"" << value << "\"/>" << G4endl;
255  } else {
256 #ifdef G4HEPREPFILEDEBUG
257  G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
258 #endif
259  }
260 }
const XML_Char * name
Definition: expat.h:151
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
Definition: expat.h:331
#define G4endl
Definition: G4ios.hh:61
void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
bool  value 
)

Definition at line 262 of file G4HepRepFileXMLWriter.cc.

264 {
265  if (fout.good())
266  {
267  indent();
268  fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
269  indent();
270  if (value)
271  fout << " value=\"True\"/>" << G4endl;
272  else
273  fout << " value=\"False\"/>" << G4endl;
274  } else {
275 #ifdef G4HEPREPFILEDEBUG
276  G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
277 #endif
278  }
279 }
const XML_Char * name
Definition: expat.h:151
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
Definition: expat.h:331
#define G4endl
Definition: G4ios.hh:61
void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
double  value1,
double  value2,
double  value3 
)

Definition at line 281 of file G4HepRepFileXMLWriter.cc.

285 {
286  if (fout.good())
287  {
288  int redness = int(value1*255.);
289  int greenness = int(value2*255.);
290  int blueness = int(value3*255.);
291  indent();
292  fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
293  indent();
294  fout << " value=\"" << redness << "," << greenness << "," << blueness << "\"/>" << G4endl;
295  } else {
296 #ifdef G4HEPREPFILEDEBUG
297  G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
298 #endif
299  }
300 }
const XML_Char * name
Definition: expat.h:151
G4GLOB_DLL std::ostream G4cout
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

void G4HepRepFileXMLWriter::addInstance ( )

Definition at line 120 of file G4HepRepFileXMLWriter.cc.

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

Here is the caller graph for this function:

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

Definition at line 164 of file G4HepRepFileXMLWriter.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

void G4HepRepFileXMLWriter::addPrimitive ( )

Definition at line 142 of file G4HepRepFileXMLWriter.cc.

143 {
144  if (fout.good())
145  {
146  if (inInstance[typeDepth])
147  {
148  endPrimitive();
149  inPrimitive = true;
150  indent();
151  fout << "<heprep:primitive>" << G4endl;
152  } else {
153 #ifdef G4HEPREPFILEDEBUG
154  G4cout << "G4HepRepFileXMLWriter:addPrimitive No HepRep Instance is currently open" << G4endl;
155 #endif
156  }
157  } else {
158 #ifdef G4HEPREPFILEDEBUG
159  G4cout << "G4HepRepFileXMLWriter:addPrimitive No file is currently open" << G4endl;
160 #endif
161  }
162 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61

Here is the caller graph for this function:

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

Definition at line 71 of file G4HepRepFileXMLWriter.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

void G4HepRepFileXMLWriter::close ( )

Definition at line 321 of file G4HepRepFileXMLWriter.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

void G4HepRepFileXMLWriter::endTypes ( )

Definition at line 335 of file G4HepRepFileXMLWriter.cc.

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

Here is the caller graph for this function:

void G4HepRepFileXMLWriter::open ( const char *  filespec)

Definition at line 302 of file G4HepRepFileXMLWriter.cc.

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

Here is the call graph for this function:

Member Data Documentation

bool G4HepRepFileXMLWriter::inInstance[50]

Definition at line 91 of file G4HepRepFileXMLWriter.hh.

bool G4HepRepFileXMLWriter::inType[50]

Definition at line 90 of file G4HepRepFileXMLWriter.hh.

bool G4HepRepFileXMLWriter::isOpen

Definition at line 88 of file G4HepRepFileXMLWriter.hh.

char* G4HepRepFileXMLWriter::prevTypeName[50]

Definition at line 92 of file G4HepRepFileXMLWriter.hh.

int G4HepRepFileXMLWriter::typeDepth

Definition at line 89 of file G4HepRepFileXMLWriter.hh.


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