Import Geant4 4.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-08 16:18:25 +02:00
parent 36c080dca6
commit 921d3b1cda
3990 changed files with 185376 additions and 82884 deletions
@@ -0,0 +1,83 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4HepRepFile.cc,v 1.1 2001/11/06 11:48:07 johna Exp $
// GEANT4 tag $Name: geant4-04-00 $
//
//
// Joseph Perl 1 October 2001
// A graphics system to dump geometry hierarchy to the
// HepRep graphics format (HepRep version 1).
//HepRep
#include "HepRepXMLWriter.hh"
#include "G4HepRepFile.hh"
#include "G4HepRepFileSceneHandler.hh"
#include "G4HepRepFileViewer.hh"
static HepRepXMLWriter* hepRepXMLWriter;
G4HepRepFile::G4HepRepFile():
G4VGraphicsSystem("G4HepRepFile",
"HepRepFile",
"A template graphics driver",
G4VGraphicsSystem::noFunctionality) {
hepRepXMLWriter = new HepRepXMLWriter();
}
G4HepRepFile::~G4HepRepFile() {}
G4VSceneHandler* G4HepRepFile::CreateSceneHandler(const G4String& name) {
G4VSceneHandler* pScene = new G4HepRepFileSceneHandler(*this, name);
G4cout << G4HepRepFileSceneHandler::GetSceneCount()
<< ' ' << fName << " scene handlers extanct." << G4endl;
return pScene;
}
G4VViewer* G4HepRepFile::CreateViewer(G4VSceneHandler& scene,
const G4String& name) {
G4VViewer* pView =
new G4HepRepFileViewer((G4HepRepFileSceneHandler&) scene, name);
if (pView) {
if (pView->GetViewId() < 0) {
G4cout <<
"G4HepRepFile::CreateViewer: ERROR flagged by negative"
" view id in G4HepRepFileViewer creation."
"\n Destroying view and returning null pointer."
<< G4endl;
delete pView;
pView = 0;
}
}
else {
G4cout <<
"G4HepRepFile::CreateViewer: ERROR: null pointer on new G4HepRepFileViewer."
<< G4endl;
}
return pView;
}
HepRepXMLWriter* G4HepRepFile::GetHepRepXMLWriter () {
return hepRepXMLWriter;
}
@@ -0,0 +1,397 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4HepRepFileSceneHandler.cc,v 1.3 2001/11/19 15:07:28 johna Exp $
// GEANT4 tag $Name: geant4-04-00 $
//
//
// John Allison 5th April 2001
// A base class for a scene handler to dump geometry hierarchy.
// Based on a provisional G4HepRepFileGraphicsScene (was in modeling).
#include "G4HepRepFileSceneHandler.hh"
#include "G4HepRepFile.hh"
#include "G4VSolid.hh"
#include "G4PhysicalVolumeModel.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Material.hh"
#include "G4ModelingParameters.hh"
#include "G4Polymarker.hh"
#include "G4Polyline.hh"
#include "G4Text.hh"
#include "G4Circle.hh"
#include "G4Square.hh"
#include "G4Polyhedron.hh"
#include "G4NURBS.hh"
//HepRep
#include "HepRepXMLWriter.hh"
G4int G4HepRepFileSceneHandler::fSceneIdCount = 0;
// Counter for HepRep scene handlers.
G4int G4HepRepFileSceneHandler::fSceneCount = 0;
// No. of extanct scene handlers.
G4HepRepFileSceneHandler::G4HepRepFileSceneHandler(G4VGraphicsSystem& system,
const G4String& name):
G4VSceneHandler(system, fSceneIdCount++, name),
fCurrentDepth (0),
fpCurrentPV (0),
fpCurrentLV (0)
{
fSceneCount++;
hepRepXMLWriter = ((G4HepRepFile*)(&system))->GetHepRepXMLWriter();
G4cout << " From scene handler const: opening file, G4HepRepFile.xml"
<< G4endl;
}
G4HepRepFileSceneHandler::~G4HepRepFileSceneHandler() {}
#ifdef G4HEPREPFILEDEBUG
void G4HepRepFileSceneHandler::PrintThings() {
G4cout <<
" with transformation "
<< (void*)fpObjectTransformation;
if (fpCurrentPV) {
G4cout <<
"\n current physical volume: "
<< fpCurrentPV->GetName() <<
"\n current logical volume: "
<< fpCurrentLV->GetName() <<
"\n current depth of geometry tree: "
<< fCurrentDepth;
}
G4cout << G4endl;
}
#endif
void G4HepRepFileSceneHandler::AddThis(const G4Box& box) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddThis(const G4Box& box) called for "
<< box.GetName()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(box); // Invoke default action.
}
void G4HepRepFileSceneHandler::AddThis(const G4Cons& cons) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddThis(const G4Cons& cons) called for "
<< cons.GetName()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(cons); // Invoke default action.
}
void G4HepRepFileSceneHandler::AddThis(const G4Tubs& tubs) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddThis(const G4Tubs& tubs) called for "
<< tubs.GetName()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(tubs); // Invoke default action.
}
void G4HepRepFileSceneHandler::AddThis(const G4Trd& trd) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddThis(const G4Trd& trd) called for "
<< trd.GetName()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(trd); // Invoke default action.
}
void G4HepRepFileSceneHandler::AddThis(const G4Trap& trap) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddThis(const G4Trap& trap) called for "
<< trap.GetName()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(trap); // Invoke default action.
}
void G4HepRepFileSceneHandler::AddThis(const G4Sphere& sphere) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddThis(const G4Sphere& sphere) called for "
<< sphere.GetName()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(sphere); // Invoke default action.
}
void G4HepRepFileSceneHandler::AddThis(const G4Para& para) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddThis(const G4Para& para) called for "
<< para.GetName()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(para); // Invoke default action.
}
void G4HepRepFileSceneHandler::AddThis(const G4Torus& torus) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddThis(const G4Torus& torus) called for "
<< torus.GetName()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(torus); // Invoke default action.
}
void G4HepRepFileSceneHandler::AddThis(const G4Polycone& polycone) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddThis(const G4Polycone& polycone) called for "
<< polycone.GetName()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(polycone); // Invoke default action.
}
void G4HepRepFileSceneHandler::AddThis(const G4Polyhedra& polyhedra) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddThis(const G4Polyhedra& polyhedra) called for "
<< polyhedra.GetName()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(polyhedra); // Invoke default action.
}
void G4HepRepFileSceneHandler::AddThis(const G4VSolid& solid) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddThis(const G4Solid& solid) called for "
<< solid.GetName()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(solid); // Invoke default action.
}
void G4HepRepFileSceneHandler::AddPrimitive(const G4Polyline& polyline) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddPrimitive(const G4Polyline& polyline) called:"
"\n polyline: " << polyline
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addInstance();
hepRepXMLWriter->addAttValue("DrawAs","Line");
G4Colour color = GetColour(polyline);
hepRepXMLWriter->addAttValue("LineColor", color.GetRed(), color.GetGreen(), color.GetBlue());
hepRepXMLWriter->addPrimitive();
for (size_t i=0; i < polyline.size(); i++) {
G4Point3D vertex = (*fpObjectTransformation) * polyline[i];
hepRepXMLWriter->addPoint(vertex.x(), vertex.y(), vertex.z());
}
}
void G4HepRepFileSceneHandler::AddPrimitive (const G4Polymarker& line) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddPrimitive(const G4Polymarker& line) called"
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addInstance();
hepRepXMLWriter->addAttValue("DrawAs","Point");
// FIXME: should be taken from G4
hepRepXMLWriter->addAttValue("MarkName", "Square");
hepRepXMLWriter->addAttValue("MarkSize", 5);
G4Colour color = GetColour(line);
hepRepXMLWriter->addAttValue("LineColor", color.GetRed(), color.GetGreen(), color.GetBlue());
hepRepXMLWriter->addPrimitive();
for (size_t i=0; i < line.size(); i++) {
G4Point3D vertex = (*fpObjectTransformation) * line[i];
hepRepXMLWriter->addPoint(vertex.x(), vertex.y(), vertex.z());
}
}
void G4HepRepFileSceneHandler::AddPrimitive(const G4Text& text) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddPrimitive(const G4Text& text) called:"
"\n text: " << text.GetText()
<< G4endl;
PrintThings();
#endif
G4cout << "G4HepRepFileSceneHandler::AddPrimitive G4Text : not yet implemented. " << G4endl;
}
void G4HepRepFileSceneHandler::AddPrimitive(const G4Circle& circle) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddPrimitive(const G4Circle& circle) called:"
"\n radius: " << circle.GetWorldRadius()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addInstance();
hepRepXMLWriter->addAttValue("DrawAs","Point");
hepRepXMLWriter->addAttValue("MarkName", "Dot");
G4Colour color = GetColour(circle);
hepRepXMLWriter->addAttValue("LineColor", color.GetRed(), color.GetGreen(), color.GetBlue());
hepRepXMLWriter->addPrimitive();
G4double radius = circle.GetWorldSize();
hepRepXMLWriter->addAttValue("MarkSize", radius);
G4Point3D center = (*fpObjectTransformation) * circle.GetPosition();
hepRepXMLWriter->addPoint(center.x(), center.y(), center.z());
}
void G4HepRepFileSceneHandler::AddPrimitive(const G4Square& square) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddPrimitive(const G4Square& square) called:"
"\n side: " << square.GetWorldRadius()
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addInstance();
hepRepXMLWriter->addAttValue("DrawAs","Point");
hepRepXMLWriter->addAttValue("MarkName", "Square");
G4Colour color = GetColour(square);
hepRepXMLWriter->addAttValue("LineColor", color.GetRed(), color.GetGreen(), color.GetBlue());
hepRepXMLWriter->addPrimitive();
G4double size = square.GetWorldSize();
hepRepXMLWriter->addAttValue("MarkSize", size);
G4Point3D center = (*fpObjectTransformation) * square.GetPosition();
hepRepXMLWriter->addPoint(center.x(), center.y(), center.z());
}
void G4HepRepFileSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called."
<< G4endl;
PrintThings();
#endif
if(polyhedron.GetNoFacets()==0)return;
G4Normal3D surfaceNormal;
G4Point3D vertex;
hepRepXMLWriter->addInstance();
hepRepXMLWriter->addAttValue("DrawAs","Polygon");
G4Colour color = GetColour(polyhedron);
hepRepXMLWriter->addAttValue("LineColor", color.GetRed(), color.GetGreen(), color.GetBlue());
// Additional attributes.
hepRepXMLWriter->addAttValue("LVol", fpCurrentLV->GetName());
hepRepXMLWriter->addAttValue("Solid", fpCurrentLV->GetSolid()->GetName());
hepRepXMLWriter->addAttValue("EType", fpCurrentLV->GetSolid()->GetEntityType());
hepRepXMLWriter->addAttValue("Material", fpCurrentLV->GetMaterial()->GetName());
hepRepXMLWriter->addAttValue("Density", fpCurrentLV->GetMaterial()->GetDensity());
hepRepXMLWriter->addAttValue("State", fpCurrentLV->GetMaterial()->GetState());
hepRepXMLWriter->addAttValue("Radlen", fpCurrentLV->GetMaterial()->GetRadlen());
G4bool notLastFace;
do {
hepRepXMLWriter->addPrimitive();
notLastFace = polyhedron.GetNextNormal (surfaceNormal);
G4int edgeFlag = 1;
G4bool notLastEdge;
do {
notLastEdge = polyhedron.GetNextVertex (vertex, edgeFlag);
vertex = (*fpObjectTransformation) * vertex;
hepRepXMLWriter->addPoint(vertex.x(), vertex.y(), vertex.z());
} while (notLastEdge);
} while (notLastFace);
}
void G4HepRepFileSceneHandler::AddPrimitive(const G4NURBS& nurbs) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddPrimitive(const G4NURBS& nurbs) called."
<< G4endl;
PrintThings();
#endif
G4cout << "G4HepRepFileSceneHandler::AddPrimitive G4NURBS : not implemented. " << G4endl;
}
void G4HepRepFileSceneHandler::EstablishSpecials
(G4PhysicalVolumeModel& pvModel) {
pvModel.DefinePointersToWorkingSpace(&fCurrentDepth,
&fpCurrentPV,
&fpCurrentLV);
}
HepRepXMLWriter *G4HepRepFileSceneHandler::GetHepRepXMLWriter() {
return hepRepXMLWriter;
}
@@ -0,0 +1,86 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4HepRepFileViewer.cc,v 1.3 2001/11/19 15:07:28 johna Exp $
// GEANT4 tag $Name: geant4-04-00 $
#include "G4HepRepFileViewer.hh"
#include "G4ios.hh"
#include "g4std/strstream"
#include "G4VSceneHandler.hh"
#include "G4HepRepFileSceneHandler.hh"
//HepRep
#include "HepRepXMLWriter.hh"
G4HepRepFileViewer::G4HepRepFileViewer
(G4VSceneHandler& sceneHandler, const G4String& name):
G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name) {
hepRepXMLWriter = ((G4HepRepFileSceneHandler*)(&sceneHandler))->GetHepRepXMLWriter();
}
G4HepRepFileViewer::~G4HepRepFileViewer() {}
void G4HepRepFileViewer::SetView() {
#ifdef G4HEPREPFILEDEBUG
G4cout << "G4HepRepFileViewer::SetView() called." << G4endl;
#endif
hepRepXMLWriter->open("G4HepRepFile.xml");
hepRepXMLWriter->addAttDef("LVol", "Logical Volume", "Physics","");
hepRepXMLWriter->addAttDef("Solid", "Solid Name", "Physics","");
hepRepXMLWriter->addAttDef("EType", "Entity Type", "Physics","");
hepRepXMLWriter->addAttDef("Material", "Material Name", "Physics","");
hepRepXMLWriter->addAttDef("Density", "Material Density", "Physics","");
hepRepXMLWriter->addAttDef("State", "Material State", "Physics","");
hepRepXMLWriter->addAttDef("Radlen", "Material Radiation Length", "Physics","");
}
void G4HepRepFileViewer::ClearView() {
#ifdef G4HEPREPFILEDEBUG
G4cout << "G4HepRepFileViewer::ClearView() called." << G4endl;
#endif
}
void G4HepRepFileViewer::DrawView() {
#ifdef G4HEPREPFILEDEBUG
G4cout << "G4HepRepFileViewer::DrawView() called." << G4endl;
#endif
NeedKernelVisit (); // Always need to visit G4 kernel.
ProcessView ();
}
void G4HepRepFileViewer::ShowView () {
#ifdef G4HEPREPFILEDEBUG
G4cout << "G4HepRepFileViewer::ShowView" << G4endl;
#endif
G4VViewer::ShowView();
hepRepXMLWriter->close();
}
@@ -0,0 +1,297 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//--------------------------------------------------------------------------
// File and Version Information:
// $Id: HepRepXMLWriter.cc,v 1.3 2001/12/13 12:04:26 gunter Exp $
//
// Description:
// Create a HepRep XML File (HepRep version 1).
//
// Environment:
// Software developed for the general High Energy Physics community.
//
// Author :
// J. Perl Original Author
//
// Copyright Information:
// Copyright (C) 2001 Stanford Linear Accelerator Center
//------------------------------------------------------------------------
#include "HepRepXMLWriter.hh"
#include "G4ios.hh"
HepRepXMLWriter::HepRepXMLWriter()
{
}
void HepRepXMLWriter::addType(const char* name)
{
if (fout.good())
{
endType();
fout << " <heprep:type version=\"null\" name=\"" << name << "\">"
<< G4endl;
inType = true;
} else {
G4cout << "HepRepXMLWriter:addType No file is currently open." << G4endl;
}
}
void HepRepXMLWriter::addInstance()
{
if (fout.good())
{
if (inType)
{
endInstance();
fout << " <heprep:instance>" << G4endl;
inInstance = true;
} else {
G4cout << "HepRepXMLWriter:addInstance No HepRep Type is currently open"
<< G4endl;
}
} else {
G4cout << "HepRepXMLWriter:addInstance No file is currently open"
<< G4endl;
}
}
void HepRepXMLWriter::addPrimitive()
{
if (fout.good())
{
if (inInstance)
{
endPrimitive();
fout << " <heprep:primitive>" << G4endl;
inPrimitive = true;
} else {
G4cout <<
"HepRepXMLWriter:addPrimitive No HepRep Instance is currently open"
<< G4endl;
}
} else {
G4cout << "HepRepXMLWriter:addPrimitive No file is currently open"
<< G4endl;
}
}
void HepRepXMLWriter::addPoint(double x, double y, double z)
{
if (fout.good())
{
if (inPrimitive)
{
endPoint();
fout << " <heprep:point x=\"" << x << "\" y=\"" << y << "\" z=\"" << z << "\">" << G4endl;
inPoint = true;
} else {
G4cout <<
"HepRepXMLWriter:addPoint No HepRep Primitive is currently open"
<< G4endl;
}
} else {
G4cout << "HepRepXMLWriter:addPoint No file is currently open" << G4endl;
}
}
void HepRepXMLWriter::addAttDef(const char* name,
const char* desc,
const char* type,
const char* extra)
{
if (fout.good())
{
indent();
fout << " <heprep:attdef extra=\"" << extra << "\" name=\"" << name << "\" type=\"" << type << "\"" << G4endl;
indent();
fout << " desc=\"" << desc << "\"/>" << G4endl;
} else {
G4cout << "HepRepXMLWriter:addAttDef No file is currently open" << G4endl;
}
}
// Four methods to fill attValues
void HepRepXMLWriter::addAttValue (const char* name,
const char* value)
{
if (fout.good())
{
indent();
fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
indent();
fout << " value=\"" << value << "\"/>" << G4endl;
} else {
G4cout << "HepRepXMLWriter:addAttValue No file is currently open" << G4endl;
}
}
void HepRepXMLWriter::addAttValue (const char* name,
double value)
{
if (fout.good())
{
indent();
fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
indent();
fout << " value=\"" << value << "\"/>" << G4endl;
} else {
G4cout << "HepRepXMLWriter:addAttValue No file is currently open" << G4endl;
}
}
void HepRepXMLWriter::addAttValue (const char* name,
int value)
{
if (fout.good())
{
indent();
fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
indent();
fout << " value=\"" << value << "\"/>" << G4endl;
} else {
G4cout << "HepRepXMLWriter:addAttValue No file is currently open" << G4endl;
}
}
void HepRepXMLWriter::addAttValue (const char* name,
bool value)
{
if (fout.good())
{
indent();
fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
indent();
fout << " value=\"" << value << "\"/>" << G4endl;
} else {
G4cout << "HepRepXMLWriter:addAttValue No file is currently open" << G4endl;
}
}
void HepRepXMLWriter::addAttValue (const char* name,
double value1,
double value2,
double value3)
{
if (fout.good())
{
indent();
int redness = int(value1*255.);
int greenness = int(value2*255.);
int blueness = int(value3*255.);
fout << " <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
indent();
fout << " value=\"" << redness << "," << greenness << "," << blueness << "\"/>" << G4endl;
} else {
G4cout << "HepRepXMLWriter:addAttValue No file is currently open" << G4endl;
}
}
void HepRepXMLWriter::open(const char* filespec)
{
if (fout.good())
fout.close();
fout.open(filespec);
if (fout.good())
{
fout << "<?xml version=\"1.0\" ?>" << G4endl;
fout << "<heprep:heprep xmlns:heprep=\"http://www.freehep.org/HepRep\"" << G4endl;
fout << " xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" xsi:schemaLocation=\"HepRep.xsd\">" << G4endl;
inType = false;
inInstance = false;
inPrimitive = false;
inPoint = false;
} else {
G4cout << "HepRepXMLWriter:open Unable to write to file " << filespec << G4endl;
}
}
void HepRepXMLWriter::close()
{
if (fout.good())
{
endType();
fout << "</heprep:heprep>" << G4endl;
fout.close( );
} else {
G4cout << "HepRepXMLWriter:close No file is currently open" << G4endl;
}
}
void HepRepXMLWriter::endType()
{
if (inType)
{
endInstance();
fout << " </heprep:type>" << G4endl;
inType = false;
}
}
void HepRepXMLWriter::endInstance()
{
if (inInstance)
{
endPrimitive();
fout << " </heprep:instance>" << G4endl;
inInstance = false;
}
}
void HepRepXMLWriter::endPrimitive()
{
if (inPrimitive)
{
endPoint();
fout << " </heprep:primitive>" << G4endl;
inPrimitive = false;
}
}
void HepRepXMLWriter::endPoint()
{
if (inPoint)
{
fout << " </heprep:point>" << G4endl;
inPoint = false;
}
}
void HepRepXMLWriter::indent()
{
if (fout.good())
{
if (inType)
fout << " ";
if (inInstance)
fout << " ";
if (inPrimitive)
fout << " ";
if (inPoint)
fout << " ";
}
}