Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/HepRep/src/G4HepRepFileXMLWriter.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/HepRep/src/G4HepRepFileXMLWriter.cc (Version 11.3.0) and /visualization/HepRep/src/G4HepRepFileXMLWriter.cc (Version 9.3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //--------------------------------------------     26 //--------------------------------------------------------------------------
 27 // File and Version Information:                   27 // File and Version Information:
                                                   >>  28 //  $Id: G4HepRepFileXMLWriter.cc,v 1.3 2006/06/29 21:17:28 gunter Exp $
 28 //                                                 29 //
 29 // Description:                                    30 // Description:
 30 //  Create a HepRep XML File (HepRep version 1     31 //  Create a HepRep XML File (HepRep version 1).
 31 //                                                 32 //
 32 // Environment:                                    33 // Environment:
 33 //  Software developed for the general High En     34 //  Software developed for the general High Energy Physics community.
 34 //                                                 35 //
 35 // Author :                                        36 // Author :
 36 //       J. Perl                    Original A     37 //       J. Perl                    Original Author
 37 //                                                 38 //
 38 // Copyright Information:                          39 // Copyright Information:
 39 //      Copyright (C) 2001          Stanford L     40 //      Copyright (C) 2001          Stanford Linear Accelerator Center
 40 //--------------------------------------------     41 //------------------------------------------------------------------------
 41                                                    42 
 42 #include "G4HepRepFileXMLWriter.hh"                43 #include "G4HepRepFileXMLWriter.hh"
 43                                                    44 
 44 #include "G4HepRepMessenger.hh"                << 
 45 #include "G4ios.hh"                                45 #include "G4ios.hh"
 46                                                    46 
 47 G4HepRepFileXMLWriter::G4HepRepFileXMLWriter()     47 G4HepRepFileXMLWriter::G4HepRepFileXMLWriter()
 48 {                                                  48 {
 49   isOpen = false;                                  49   isOpen = false;
 50   init();                                          50   init();
 51 }                                                  51 }
 52                                                    52 
 53 void G4HepRepFileXMLWriter::init()                 53 void G4HepRepFileXMLWriter::init()
 54 {                                                  54 {
 55   typeDepth = -1;                                  55   typeDepth = -1;
 56                                                    56 
 57   int i = -1;                                      57   int i = -1;
 58   while(i++ < 49)                              <<  58   while (i++<49) {
 59   {                                            << 
 60     prevTypeName[i] = new char[1];                 59     prevTypeName[i] = new char[1];
 61     strcpy(prevTypeName[i], "");               <<  60     strcpy(prevTypeName[i],"");
 62                                                    61 
 63     inType[i]     = false;                     <<  62     inType[i] = false;
 64     inInstance[i] = false;                         63     inInstance[i] = false;
 65   }                                                64   }
 66                                                    65 
 67   inPrimitive = false;                             66   inPrimitive = false;
 68   inPoint     = false;                         <<  67   inPoint = false;
 69 }                                                  68 }
 70                                                    69 
 71 void G4HepRepFileXMLWriter::addType(const char <<  70 void G4HepRepFileXMLWriter::addType(const char* name,int newTypeDepth)
 72 {                                                  71 {
 73   if(fout.good())                              <<  72   if (fout.good())
 74   {                                                73   {
 75     // Flatten structure if it exceeds maximum     74     // Flatten structure if it exceeds maximum allowed typeDepth of 49.
 76     if(newTypeDepth > 49)                      <<  75     if (newTypeDepth > 49)
 77       newTypeDepth = 49;                           76       newTypeDepth = 49;
 78                                                    77 
 79     if(newTypeDepth < 0)                       <<  78     if (newTypeDepth < 0)
 80       newTypeDepth = 0;                            79       newTypeDepth = 0;
 81                                                    80 
 82     // Insert any layers that are missing from     81     // Insert any layers that are missing from the hierarchy (protects against
 83     // callers that skip from, say, layer 1 to     82     // callers that skip from, say, layer 1 to layer 3 with no layer 2).
 84     while(typeDepth < (newTypeDepth - 1))      <<  83     while (typeDepth < (newTypeDepth-1)) {
 85     {                                          << 
 86       addType("Layer Inserted by G4HepRepFileX     84       addType("Layer Inserted by G4HepRepFileXMLWriter", typeDepth + 1);
 87       addInstance();                               85       addInstance();
 88     }                                              86     }
 89                                                    87 
 90     // If moving closer to the root, close pre     88     // If moving closer to the root, close previously open types.
 91     while(newTypeDepth < typeDepth)            <<  89     while (newTypeDepth<typeDepth)
 92       endType();                                   90       endType();
 93                                                    91 
 94     // Close any remaining primitives of the c     92     // Close any remaining primitives of the current instance.
 95     endPrimitive();                                93     endPrimitive();
 96                                                    94 
 97     // If this is a new type name for the curr     95     // If this is a new type name for the current depth, declare the
 98     // new Type.  Otherwise, it is just anothe     96     // new Type.  Otherwise, it is just another Instance of the current Type.
 99     if(strcmp(name, prevTypeName[newTypeDepth] <<  97     if (strcmp(name,prevTypeName[newTypeDepth])!=0)
100     {                                              98     {
101       if(inType[newTypeDepth])                 <<  99       if (inType[newTypeDepth])
102         endType();                             << 100   endType();
103                                                   101 
104       prevTypeName[newTypeDepth] = new char[st << 102       prevTypeName[newTypeDepth] = new char[strlen(name)+1];
105       strcpy(prevTypeName[newTypeDepth], name) << 103       strcpy(prevTypeName[newTypeDepth],name);
106                                                   104 
107       inType[newTypeDepth] = true;                105       inType[newTypeDepth] = true;
108       indent();                                   106       indent();
109       fout << "<heprep:type version=\"null\" n    107       fout << "<heprep:type version=\"null\" name=\"" << name << "\">"
110            << G4endl;                          << 108    << G4endl;
111                                                   109 
112       typeDepth = newTypeDepth;                   110       typeDepth = newTypeDepth;
113     }                                             111     }
114   }                                            << 112   } else {
115   else                                         << 
116   {                                            << 
117 #ifdef G4HEPREPFILEDEBUG                          113 #ifdef G4HEPREPFILEDEBUG
118     G4cout << "G4HepRepFileXMLWriter:addType N << 114     G4cout << "G4HepRepFileXMLWriter:addType No file is currently open." << G4endl;
119            << G4endl;                          << 
120 #endif                                            115 #endif
121   }                                               116   }
122 }                                                 117 }
123                                                   118 
124 void G4HepRepFileXMLWriter::addInstance()         119 void G4HepRepFileXMLWriter::addInstance()
125 {                                                 120 {
126   if(fout.good())                              << 121   if (fout.good())
127   {                                               122   {
128     if(inType[typeDepth])                      << 123     if (inType[typeDepth])
129     {                                             124     {
130       endInstance();                              125       endInstance();
131       inInstance[typeDepth] = true;               126       inInstance[typeDepth] = true;
132       indent();                                   127       indent();
133       fout << "<heprep:instance>" << G4endl;      128       fout << "<heprep:instance>" << G4endl;
134     }                                          << 129     } else {
135     else                                       << 
136     {                                          << 
137 #ifdef G4HEPREPFILEDEBUG                          130 #ifdef G4HEPREPFILEDEBUG
138       G4cout                                   << 131       G4cout << "G4HepRepFileXMLWriter:addInstance No HepRep Type is currently open" << G4endl;
139         << "G4HepRepFileXMLWriter:addInstance  << 
140         << G4endl;                             << 
141 #endif                                            132 #endif
142     }                                             133     }
143   }                                            << 134   } else {
144   else                                         << 
145   {                                            << 
146 #ifdef G4HEPREPFILEDEBUG                          135 #ifdef G4HEPREPFILEDEBUG
147     G4cout << "G4HepRepFileXMLWriter:addInstan << 136     G4cout << "G4HepRepFileXMLWriter:addInstance No file is currently open" << G4endl;
148            << G4endl;                          << 
149 #endif                                            137 #endif
150   }                                               138   }
151 }                                                 139 }
152                                                   140 
153 void G4HepRepFileXMLWriter::addPrimitive()        141 void G4HepRepFileXMLWriter::addPrimitive()
154 {                                                 142 {
155   if(fout.good())                              << 143   if (fout.good())
156   {                                               144   {
157     if(inInstance[typeDepth])                  << 145     if (inInstance[typeDepth])
158     {                                             146     {
159       endPrimitive();                             147       endPrimitive();
160       inPrimitive = true;                         148       inPrimitive = true;
161       indent();                                   149       indent();
162       fout << "<heprep:primitive>" << G4endl;     150       fout << "<heprep:primitive>" << G4endl;
163     }                                          << 151     } else {
164     else                                       << 
165     {                                          << 
166 #ifdef G4HEPREPFILEDEBUG                          152 #ifdef G4HEPREPFILEDEBUG
167       G4cout << "G4HepRepFileXMLWriter:addPrim << 153       G4cout << "G4HepRepFileXMLWriter:addPrimitive No HepRep Instance is currently open" << G4endl; 
168                 "currently open"               << 
169              << G4endl;                        << 
170 #endif                                            154 #endif
171     }                                             155     }
172   }                                            << 156   } else {
173   else                                         << 
174   {                                            << 
175 #ifdef G4HEPREPFILEDEBUG                          157 #ifdef G4HEPREPFILEDEBUG
176     G4cout << "G4HepRepFileXMLWriter:addPrimit << 158     G4cout << "G4HepRepFileXMLWriter:addPrimitive No file is currently open" << G4endl;
177            << G4endl;                          << 
178 #endif                                            159 #endif
179   }                                               160   }
180 }                                                 161 }
181                                                   162 
182 void G4HepRepFileXMLWriter::addPoint(double x,    163 void G4HepRepFileXMLWriter::addPoint(double x, double y, double z)
183 {                                                 164 {
184   if(fout.good())                              << 165   if (fout.good())
185   {                                               166   {
186     if(inPrimitive)                            << 167     if (inPrimitive)
187     {                                             168     {
188       endPoint();                                 169       endPoint();
189       inPoint = true;                             170       inPoint = true;
190       indent();                                   171       indent();
191                                                << 172       fout << "<heprep:point x=\"" << x << "\" y=\"" << y << "\" z=\"" << z << "\">" << G4endl;
192       // Include scale and center values       << 173     } else {
193       G4HepRepMessenger* messenger = G4HepRepM << 
194       G4double scale               = messenger << 
195       G4ThreeVector center         = messenger << 
196       G4double xNew                = scale * ( << 
197       G4double yNew                = scale * ( << 
198       G4double zNew                = scale * ( << 
199                                                << 
200       fout << "<heprep:point x=\"" << xNew <<  << 
201            << zNew << "\">" << G4endl;         << 
202     }                                          << 
203     else                                       << 
204     {                                          << 
205 #ifdef G4HEPREPFILEDEBUG                          174 #ifdef G4HEPREPFILEDEBUG
206       G4cout << "G4HepRepFileXMLWriter:addPoin << 175       G4cout << "G4HepRepFileXMLWriter:addPoint No HepRep Primitive is currently open" << G4endl;
207                 "currently open"               << 
208              << G4endl;                        << 
209 #endif                                            176 #endif
210     }                                             177     }
211   }                                            << 178   } else {
212   else                                         << 
213   {                                            << 
214 #ifdef G4HEPREPFILEDEBUG                          179 #ifdef G4HEPREPFILEDEBUG
215     G4cout << "G4HepRepFileXMLWriter:addPoint  << 180     G4cout << "G4HepRepFileXMLWriter:addPoint No file is currently open" << G4endl;
216            << G4endl;                          << 
217 #endif                                            181 #endif
218   }                                               182   }
219 }                                                 183 }
220                                                   184 
221 void G4HepRepFileXMLWriter::addAttDef(const ch << 185 void G4HepRepFileXMLWriter::addAttDef(const char* name,
222                                       const ch << 186          const char* desc,
                                                   >> 187          const char* type,
                                                   >> 188          const char* extra)
223 {                                                 189 {
224   if(fout.good())                              << 190   if (fout.good())
225   {                                               191   {
226     indent();                                     192     indent();
227     fout << "  <heprep:attdef extra=\"" << ext << 193     fout << "  <heprep:attdef extra=\"" << extra << "\" name=\"" << name << "\" type=\"" << type << "\"" << G4endl;
228          << "\" type=\"" << type << "\"" << G4 << 
229     indent();                                     194     indent();
230     fout << "  desc=\"" << desc << "\"/>" << G    195     fout << "  desc=\"" << desc << "\"/>" << G4endl;
231   }                                            << 196   } else {
232   else                                         << 
233   {                                            << 
234 #ifdef G4HEPREPFILEDEBUG                          197 #ifdef G4HEPREPFILEDEBUG
235     G4cout << "G4HepRepFileXMLWriter:addAttDef << 198     G4cout << "G4HepRepFileXMLWriter:addAttDef No file is currently open" << G4endl;
236            << G4endl;                          << 
237 #endif                                            199 #endif
238   }                                               200   }
239 }                                                 201 }
240                                                   202 
241 // Four methods to fill attValues                 203 // Four methods to fill attValues
242 void G4HepRepFileXMLWriter::addAttValue(const  << 204 void G4HepRepFileXMLWriter::addAttValue (const char* name,
                                                   >> 205       const char* value)
243 {                                                 206 {
244   if(fout.good())                              << 207   if (fout.good())
245   {                                               208   {
246     indent();                                     209     indent();
247     fout << "  <heprep:attvalue showLabel=\"NO << 210     fout << "  <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
248          << G4endl;                            << 
249     indent();                                     211     indent();
250     fout << "    value=\"" << value << "\"/>"     212     fout << "    value=\"" << value << "\"/>" << G4endl;
251   }                                            << 213   } else {
252   else                                         << 
253   {                                            << 
254 #ifdef G4HEPREPFILEDEBUG                          214 #ifdef G4HEPREPFILEDEBUG
255     G4cout << "G4HepRepFileXMLWriter:addAttVal << 215     G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
256            << G4endl;                          << 
257 #endif                                            216 #endif
258   }                                               217   }
259 }                                                 218 }
260                                                   219 
261 void G4HepRepFileXMLWriter::addAttValue(const  << 220 void G4HepRepFileXMLWriter::addAttValue (const char* name,
                                                   >> 221       double value)
262 {                                                 222 {
263   if(fout.good())                              << 223   if (fout.good())
264   {                                               224   {
265     indent();                                     225     indent();
266     fout << "  <heprep:attvalue showLabel=\"NO << 226     fout << "  <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
267          << G4endl;                            << 
268     indent();                                     227     indent();
269     fout << "    value=\"" << value << "\"/>"     228     fout << "    value=\"" << value << "\"/>" << G4endl;
270   }                                            << 229   } else {
271   else                                         << 
272   {                                            << 
273 #ifdef G4HEPREPFILEDEBUG                          230 #ifdef G4HEPREPFILEDEBUG
274     G4cout << "G4HepRepFileXMLWriter:addAttVal << 231     G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
275            << G4endl;                          << 
276 #endif                                            232 #endif
277   }                                               233   }
278 }                                                 234 }
279                                                   235 
280 void G4HepRepFileXMLWriter::addAttValue(const  << 236 void G4HepRepFileXMLWriter::addAttValue (const char* name,
                                                   >> 237       int value)
281 {                                                 238 {
282   if(fout.good())                              << 239   if (fout.good())
283   {                                               240   {
284     indent();                                     241     indent();
285     fout << "  <heprep:attvalue showLabel=\"NO << 242     fout << "  <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
286          << G4endl;                            << 
287     indent();                                     243     indent();
288     fout << "    value=\"" << value << "\"/>"     244     fout << "    value=\"" << value << "\"/>" << G4endl;
289   }                                            << 245   } else {
290   else                                         << 
291   {                                            << 
292 #ifdef G4HEPREPFILEDEBUG                          246 #ifdef G4HEPREPFILEDEBUG
293     G4cout << "G4HepRepFileXMLWriter:addAttVal << 247     G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
294            << G4endl;                          << 
295 #endif                                            248 #endif
296   }                                               249   }
297 }                                                 250 }
298                                                   251 
299 void G4HepRepFileXMLWriter::addAttValue(const  << 252 void G4HepRepFileXMLWriter::addAttValue (const char* name,
                                                   >> 253       bool value)
300 {                                                 254 {
301   if(fout.good())                              << 255   if (fout.good())
302   {                                               256   {
303     indent();                                     257     indent();
304     fout << "  <heprep:attvalue showLabel=\"NO << 258     fout << "  <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
305          << G4endl;                            << 
306     indent();                                     259     indent();
307     if(value)                                  << 260     if (value)
308       fout << "    value=\"True\"/>" << G4endl    261       fout << "    value=\"True\"/>" << G4endl;
309     else                                          262     else
310       fout << "    value=\"False\"/>" << G4end    263       fout << "    value=\"False\"/>" << G4endl;
311   }                                            << 264   } else {
312   else                                         << 
313   {                                            << 
314 #ifdef G4HEPREPFILEDEBUG                          265 #ifdef G4HEPREPFILEDEBUG
315     G4cout << "G4HepRepFileXMLWriter:addAttVal << 266     G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
316            << G4endl;                          << 
317 #endif                                            267 #endif
318   }                                               268   }
319 }                                                 269 }
320                                                   270 
321 void G4HepRepFileXMLWriter::addAttValue(const  << 271 void G4HepRepFileXMLWriter::addAttValue (const char* name,
322                                         double << 272            double value1,
                                                   >> 273            double value2,
                                                   >> 274            double value3)
323 {                                                 275 {
324   if(fout.good())                              << 276   if (fout.good())
325   {                                               277   {
326     int redness   = int(value1 * 255.);        << 278     int redness = int(value1*255.);
327     int greenness = int(value2 * 255.);        << 279     int greenness = int(value2*255.);
328     int blueness  = int(value3 * 255.);        << 280     int blueness = int(value3*255.);
329     indent();                                     281     indent();
330     fout << "  <heprep:attvalue showLabel=\"NO << 282     fout << "  <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
331          << G4endl;                            << 
332     indent();                                     283     indent();
333     fout << "    value=\"" << redness << "," < << 284     fout << "    value=\"" << redness << "," << greenness << "," << blueness << "\"/>" << G4endl;
334          << "\"/>" << G4endl;                  << 285   } else {
335   }                                            << 
336   else                                         << 
337   {                                            << 
338 #ifdef G4HEPREPFILEDEBUG                          286 #ifdef G4HEPREPFILEDEBUG
339     G4cout << "G4HepRepFileXMLWriter:addAttVal << 287     G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
340            << G4endl;                          << 
341 #endif                                            288 #endif
342   }                                               289   }
343 }                                                 290 }
344                                                   291 
345 void G4HepRepFileXMLWriter::open(const char* f    292 void G4HepRepFileXMLWriter::open(const char* fileSpec)
346 {                                                 293 {
347   if(isOpen)                                   << 294   if (isOpen)
348     close();                                      295     close();
349                                                << 296   
350   fout.open(fileSpec);                            297   fout.open(fileSpec);
351                                                << 298     
352   if(fout.good())                              << 299   if (fout.good()) {
353   {                                            << 
354     fout << "<?xml version=\"1.0\" ?>" << G4en    300     fout << "<?xml version=\"1.0\" ?>" << G4endl;
355     fout << "<heprep:heprep "                  << 301     fout << "<heprep:heprep xmlns:heprep=\"http://www.slac.stanford.edu/~perl/heprep/\"" << G4endl;
356             "xmlns:heprep=\"http://www.slac.st << 302     fout << "  xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" xsi:schemaLocation=\"HepRep.xsd\">" << G4endl;
357          << G4endl;                            << 303     
358     fout << "  xmlns:xsi=\"http://www.w3.org/1 << 
359             "xsi:schemaLocation=\"HepRep.xsd\" << 
360          << G4endl;                            << 
361                                                << 
362     isOpen = true;                                304     isOpen = true;
363     init();                                       305     init();
364   }                                            << 306   } else {
365   else                                         << 307     G4cout << "G4HepRepFileXMLWriter:open Unable to write to file " << fileSpec << G4endl;
366   {                                            << 
367     G4cout << "G4HepRepFileXMLWriter:open Unab << 
368            << G4endl;                          << 
369   }                                               308   }
370 }                                                 309 }
371                                                   310 
372 void G4HepRepFileXMLWriter::close()               311 void G4HepRepFileXMLWriter::close()
373 {                                                 312 {
374   // Close any remaining open Types               313   // Close any remaining open Types
375   endTypes();                                     314   endTypes();
376                                                   315 
377   if(fout.good())                              << 316   if (fout.good()) {      
378   {                                            << 
379     fout << "</heprep:heprep>" << G4endl;         317     fout << "</heprep:heprep>" << G4endl;
380     fout.close();                              << 318     fout.close( );
381     isOpen = false;                               319     isOpen = false;
382   }                                            << 320   } else {
383   else                                         << 
384   {                                            << 
385     G4cout << "G4HepRepFileXMLWriter:close No     321     G4cout << "G4HepRepFileXMLWriter:close No file is currently open" << G4endl;
386   }                                               322   }
387 }                                                 323 }
388                                                   324 
389 void G4HepRepFileXMLWriter::endTypes()            325 void G4HepRepFileXMLWriter::endTypes()
390 {                                                 326 {
391   // Close any remaining open Types               327   // Close any remaining open Types
392   while(typeDepth > -1)                        << 328     while(typeDepth>-1)
393     endType();                                 << 329       endType();
394 }                                                 330 }
395                                                   331 
396 void G4HepRepFileXMLWriter::endType()             332 void G4HepRepFileXMLWriter::endType()
397 {                                                 333 {
398   endInstance();                                  334   endInstance();
399   indent();                                       335   indent();
400   fout << "</heprep:type>" << G4endl;             336   fout << "</heprep:type>" << G4endl;
401   inType[typeDepth] = false;                      337   inType[typeDepth] = false;
402   delete[] prevTypeName[typeDepth];            << 338   delete [] prevTypeName[typeDepth];
403   prevTypeName[typeDepth] = new char[1];          339   prevTypeName[typeDepth] = new char[1];
404   strcpy(prevTypeName[typeDepth], "");         << 340   strcpy(prevTypeName[typeDepth],"");
405   typeDepth--;                                    341   typeDepth--;
406 }                                                 342 }
407                                                   343 
408 void G4HepRepFileXMLWriter::endInstance()         344 void G4HepRepFileXMLWriter::endInstance()
409 {                                                 345 {
410   if(inInstance[typeDepth])                    << 346   if (inInstance[typeDepth])
411   {                                               347   {
412     endPrimitive();                               348     endPrimitive();
413     indent();                                     349     indent();
414     fout << "</heprep:instance>" << G4endl;       350     fout << "</heprep:instance>" << G4endl;
415     inInstance[typeDepth] = false;                351     inInstance[typeDepth] = false;
416   }                                               352   }
417 }                                                 353 }
418                                                   354 
419 void G4HepRepFileXMLWriter::endPrimitive()        355 void G4HepRepFileXMLWriter::endPrimitive()
420 {                                                 356 {
421   if(inPrimitive)                              << 357   if (inPrimitive)
422   {                                               358   {
423     endPoint();                                   359     endPoint();
424     indent();                                     360     indent();
425     fout << "</heprep:primitive>" << G4endl;      361     fout << "</heprep:primitive>" << G4endl;
426     inPrimitive = false;                          362     inPrimitive = false;
427   }                                               363   }
428 }                                                 364 }
429                                                   365 
430 void G4HepRepFileXMLWriter::endPoint()            366 void G4HepRepFileXMLWriter::endPoint()
431 {                                                 367 {
432   if(inPoint)                                  << 368   if (inPoint)
433   {                                               369   {
434     indent();                                     370     indent();
435     fout << "</heprep:point>" << G4endl;          371     fout << "</heprep:point>" << G4endl;
436     inPoint = false;                              372     inPoint = false;
437   }                                               373   }
438 }                                                 374 }
439                                                   375 
440 void G4HepRepFileXMLWriter::indent()              376 void G4HepRepFileXMLWriter::indent()
441 {                                                 377 {
442   if(fout.good())                              << 378   if (fout.good())
443   {                                               379   {
444     int i = 0;                                    380     int i = 0;
445     while(inType[i] && i < 12)                 << 381     while (inType[i] && i<12) {
446     {                                          << 
447       fout << "  ";                               382       fout << "  ";
448       if(inInstance[i])                        << 383       if (inInstance[i])
449         fout << "  ";                             384         fout << "  ";
450       i++;                                        385       i++;
451     }                                             386     }
452                                                   387 
453     if(inPrimitive)                            << 388     if (inPrimitive)
454       fout << "  ";                               389       fout << "  ";
455     if(inPoint)                                << 390     if (inPoint)
456       fout << "  ";                               391       fout << "  ";
457   }                                               392   }
458 }                                                 393 }
459                                                   394