Import Geant4 5.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-08 16:57:27 +02:00
parent 330b82b769
commit 37fff30d2e
5733 changed files with 263867 additions and 74574 deletions
@@ -0,0 +1,47 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include "DefaultHepRepAction.h"
using namespace std;
using namespace HEPREP;
DefaultHepRepAction::DefaultHepRepAction(string name, string expression)
: name(name), expression(expression) {
}
DefaultHepRepAction::~DefaultHepRepAction() {
}
string DefaultHepRepAction::getName() {
return name;
}
string DefaultHepRepAction::getExpression() {
return expression;
}
HepRepAction* DefaultHepRepAction::copy() {
return NULL;
}
@@ -0,0 +1,69 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include <cstring>
#include <cctype>
#include "DefaultHepRepAttDef.h"
using namespace std;
using namespace HEPREP;
DefaultHepRepAttDef::DefaultHepRepAttDef(string name, string desc, string category, string extra)
: name(name), desc(desc), category(category), extra(extra) {
}
DefaultHepRepAttDef::~DefaultHepRepAttDef() {
}
HepRepAttDef* DefaultHepRepAttDef::copy() {
return NULL;
}
string DefaultHepRepAttDef::getName() {
return name;
}
string DefaultHepRepAttDef::getLowerCaseName() {
char* tmp = new char[strlen(name.c_str())];
strcpy(tmp, name.c_str());
int i = -1;
do {
i++;
tmp[i] = tolower(tmp[i]);
} while (tmp[i] != 0);
return tmp;
}
string DefaultHepRepAttDef::getDescription() {
return desc;
}
string DefaultHepRepAttDef::getCategory() {
return category;
}
string DefaultHepRepAttDef::getExtra() {
return extra;
}
@@ -0,0 +1,200 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <iostream>
#include "HEPREP/HepRepConstants.h"
#include "DefaultHepRepAttValue.h"
using namespace std;
using namespace HEPREP;
DefaultHepRepAttValue::DefaultHepRepAttValue(string name, string value, int showLabel)
: name(name), type(HepRepConstants::TYPE_STRING), stringValue(value), showLabelValue(showLabel) {
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string name, long value, int showLabel)
: name(name), type(HepRepConstants::TYPE_LONG), longValue(value), showLabelValue(showLabel) {
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string name, int value, int showLabel)
: name(name), type(HepRepConstants::TYPE_INT), longValue(value), showLabelValue(showLabel) {
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string name, double value, int showLabel)
: name(name), type(HepRepConstants::TYPE_DOUBLE), doubleValue(value), showLabelValue(showLabel) {
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string name, bool value, int showLabel)
: name(name), type(HepRepConstants::TYPE_BOOLEAN), booleanValue(value), showLabelValue(showLabel) {
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string name, vector<double> value, int showLabel)
: name(name), type(HepRepConstants::TYPE_COLOR), colorValue(value), showLabelValue(showLabel) {
init();
}
DefaultHepRepAttValue::~DefaultHepRepAttValue() {
}
void DefaultHepRepAttValue::init() {
labelStrings[0] = "NAME";
labelStrings[1] = "DESC";
labelStrings[2] = "VALUE";
labelStrings[3] = "EXTRA";
}
HepRepAttValue* DefaultHepRepAttValue::copy() {
return NULL;
}
string DefaultHepRepAttValue::getName() {
return name;
}
string DefaultHepRepAttValue::getLowerCaseName() {
char *tmp = new char[strlen(name.c_str())];
strcpy(tmp, name.c_str());
int i = -1;
do {
i++;
tmp[i] = tolower(tmp[i]);
} while (tmp[i] != 0);
return tmp;
}
int DefaultHepRepAttValue::getType() {
return type;
}
string DefaultHepRepAttValue::getTypeName() {
switch(type) {
case HepRepConstants::TYPE_COLOR: return("Color");
case HepRepConstants::TYPE_STRING: return("String");
case HepRepConstants::TYPE_LONG: return("long");
case HepRepConstants::TYPE_INT: return("int");
case HepRepConstants::TYPE_DOUBLE: return("double");
case HepRepConstants::TYPE_BOOLEAN: return("boolean");
default: return "Unknown type stored in HepRepAttDef";
}
}
int DefaultHepRepAttValue::showLabel() {
return showLabelValue;
}
string DefaultHepRepAttValue::getString() {
if (type != HepRepConstants::TYPE_STRING) cerr << "Trying to access AttValue as 'string'" << endl;
return stringValue;
}
long DefaultHepRepAttValue::getLong() {
if (type != HepRepConstants::TYPE_LONG) cerr << "Trying to access AttValue as 'long'" << endl;
return longValue;
}
int DefaultHepRepAttValue::getInteger() {
if (type != HepRepConstants::TYPE_INT) cerr << "Trying to access AttValue as 'int'" << endl;
return (int)longValue;
}
double DefaultHepRepAttValue::getDouble() {
if (type != HepRepConstants::TYPE_DOUBLE) cerr << "Trying to access AttValue as 'double'" << endl;
return doubleValue;
}
bool DefaultHepRepAttValue::getBoolean() {
if (type != HepRepConstants::TYPE_BOOLEAN) cerr << "Trying to access AttValue as 'boolean'" << endl;
return booleanValue;
}
vector<double> DefaultHepRepAttValue::getColor() {
if (type != HepRepConstants::TYPE_COLOR) cerr << "Trying to access AttValue as 'color'" << endl;
return colorValue;
}
string DefaultHepRepAttValue::getAsString() {
char buffer[40];
switch(type) {
case HepRepConstants::TYPE_COLOR: sprintf(buffer, "%4.2f, %4.2f, %4.2f, %4.2f",
colorValue[0],
colorValue[1],
colorValue[2],
(colorValue.size() > 3) ? colorValue[3] : 1.0);
return buffer;
case HepRepConstants::TYPE_STRING: return getString();
case HepRepConstants::TYPE_LONG: sprintf(buffer, "%ld", getLong());
return buffer;
case HepRepConstants::TYPE_INT: sprintf(buffer, "%d", getInteger());
return buffer;
case HepRepConstants::TYPE_DOUBLE: sprintf(buffer, "%f", getDouble());
return buffer;
case HepRepConstants::TYPE_BOOLEAN: return (getBoolean()) ? "true" : "false";
default: return "Unknown typecode";
}
}
string DefaultHepRepAttValue::toShowLabel() {
string label = "";
bool first = true;
if (showLabel() == HepRepConstants::SHOW_NONE) {
label = "NONE";
} else {
for (int i=0; i<16; i++) {
if (((showLabel() >> i) & 0x0001) == 0x0001) {
if (first) {
first = false;
} else {
label.append(", ");
}
if (i < LABELSTRINGS_LEN) {
label.append(labelStrings[i]);
} else {
char hex[20];
sprintf(hex, "%0x", 1 << i);
label.append(hex);
}
}
}
}
return label;
}
@@ -0,0 +1,57 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include <iostream>
#include "DefaultHepRepTreeID.h"
using namespace std;
using namespace HEPREP;
DefaultHepRepTreeID::DefaultHepRepTreeID(string name, string version, string qualifier)
: name(name), version(version), qualifier(qualifier) {
}
DefaultHepRepTreeID::~DefaultHepRepTreeID() {
}
string DefaultHepRepTreeID::getQualifier() {
return qualifier;
}
void DefaultHepRepTreeID::setQualifier(string qual) {
this->qualifier = qual;
}
string DefaultHepRepTreeID::getName() {
return name;
}
string DefaultHepRepTreeID::getVersion() {
return version;
}
HepRepTreeID* DefaultHepRepTreeID::copy() {
return NULL;
}
@@ -0,0 +1,88 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
/**
* @author Mark Donszelmann
*/
//G4
#include "G4Types.hh"
#include "G4HepRepViewer.hh"
#include "G4HepRepSceneHandler.hh"
//This
#include "G4HepRep.hh"
using namespace HEPREP;
G4HepRep::G4HepRep ()
: G4VGraphicsSystem ("G4HepRep",
"HepRepXML",
"HepRep Generic Driver for XML, RMI and CORBA",
G4VGraphicsSystem::threeD) {
}
G4HepRep::~G4HepRep () {
}
G4VSceneHandler* G4HepRep::CreateSceneHandler (const G4String& name) {
G4HepRepSceneHandler* scene = new G4HepRepSceneHandler (*this, name);
return scene;
}
G4VViewer* G4HepRep::CreateViewer (G4VSceneHandler& scene, const G4String& name) {
G4VViewer* view = new G4HepRepViewer ((G4HepRepSceneHandler&)scene, name);
if (view) {
if (view->GetViewId() < 0) {
G4cout << "G4HepRep::CreateViewer: ERROR flagged by negative view ID." << G4endl;
delete view;
view = NULL;
}
} else {
G4cout << "G4HepRep::CreateViewer: null pointer on new G4HepRepViewer." << G4endl;
}
return view;
}
@@ -21,8 +21,30 @@
// ********************************************************************
//
//
// $Id: G4HepRepFile.cc,v 1.4 2002/02/02 04:00:22 perl Exp $
// GEANT4 tag $Name: geant4-04-01 $
// ********************************************************************
// * 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.6 2002/12/13 11:18:03 gunter Exp $
// GEANT4 tag $Name: geant4-05-00 $
//
//
// Joseph Perl 1 October 2001
@@ -41,8 +63,8 @@ static HepRepXMLWriter* hepRepXMLWriter;
G4HepRepFile::G4HepRepFile():
G4VGraphicsSystem("G4HepRepFile",
"HepRepFile",
"A template graphics driver",
G4VGraphicsSystem::noFunctionality) {
"A HepRep (format 1) ascii file driver",
G4VGraphicsSystem::threeD) {
hepRepXMLWriter = new HepRepXMLWriter();
}
@@ -21,10 +21,32 @@
// ********************************************************************
//
//
// $Id: G4HepRepFileSceneHandler.cc,v 1.7 2002/02/03 22:22:58 perl Exp $
// GEANT4 tag $Name: geant4-04-01 $
// ********************************************************************
// * 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.10 2002/12/13 11:18:03 gunter Exp $
// GEANT4 tag $Name: geant4-05-00 $
//
//
//
// Joseph Perl 27th January 2002
// A base class for a scene handler to export geometry and trajectories
// to the HepRep xml file format.
@@ -45,6 +67,8 @@
#include "G4Square.hh"
#include "G4Polyhedron.hh"
#include "G4NURBS.hh"
#include "G4VTrajectory.hh"
#include "G4VHit.hh"
//HepRep
#include "HepRepXMLWriter.hh"
@@ -79,22 +103,9 @@ void G4HepRepFileSceneHandler::EstablishSpecials
void G4HepRepFileSceneHandler::BeginModeling() {
G4VSceneHandler::BeginModeling(); // Required: see G4VSceneHandler.hh.
// Force culling off...
if (fpModel) {
fpOriginalMP = fpModel->GetModelingParameters();
if (fpOriginalMP) {
fpNonCullingMP = new G4ModelingParameters(*fpOriginalMP);
fpNonCullingMP->SetCulling(false);
fpModel->SetModelingParameters(fpNonCullingMP);
}
}
}
void G4HepRepFileSceneHandler::EndModeling() {
if (fpModel && fpOriginalMP) {
fpModel->SetModelingParameters(fpOriginalMP);
delete fpNonCullingMP;
}
G4VSceneHandler::EndModeling(); // Required: see G4VSceneHandler.hh.
}
@@ -237,6 +248,19 @@ void G4HepRepFileSceneHandler::AddThis(const G4VSolid& solid) {
G4VSceneHandler::AddThis(solid); // Invoke default action.
}
void G4HepRepFileSceneHandler::AddThis (const G4VTrajectory& traj) {
#ifdef G4HEPREPFILEDEBUG
G4cout << "G4HepRepFileSceneHandler::AddThis(G4VTrajectory&) " << G4endl;
#endif
G4VSceneHandler::AddThis (traj);
}
void G4HepRepFileSceneHandler::AddThis (const G4VHit& hit) {
#ifdef G4HEPREPFILEDEBUG
G4cout << "G4HepRepFileSceneHandler::AddThis(G4VHit&) " << G4endl;
#endif
G4VSceneHandler::AddThis (hit);
}
void G4HepRepFileSceneHandler::AddPrimitive(const G4Polyline& polyline) {
#ifdef G4HEPREPFILEDEBUG
@@ -272,7 +296,7 @@ void G4HepRepFileSceneHandler::AddPrimitive (const G4Polymarker& line) {
hepRepXMLWriter->addAttValue("MarkSize", 4);
hepRepXMLWriter->addPrimitive();
for (size_t i=0; i < line.size(); i++) {
G4Point3D vertex = (*fpObjectTransformation) * line[i];
hepRepXMLWriter->addPoint(vertex.x(), vertex.y(), vertex.z());
@@ -303,7 +327,7 @@ void G4HepRepFileSceneHandler::AddPrimitive(const G4Circle& circle) {
hepRepXMLWriter->addAttValue("MarkName", "Dot");
hepRepXMLWriter->addAttValue("MarkSize", 4);
hepRepXMLWriter->addPrimitive();
G4Point3D center = (*fpObjectTransformation) * circle.GetPosition();
@@ -389,7 +413,7 @@ void G4HepRepFileSceneHandler::AddHepRepInstance(const char* primName,
length = sprintf (newFileSpec, "%s%d%s","G4Data",fileCounter,".heprep");
hepRepXMLWriter->open(newFileSpec);
fileCounter++;
hepRepXMLWriter->addAttDef("LVol", "Logical Volume", "Physics","");
hepRepXMLWriter->addAttDef("Solid", "Solid Name", "Physics","");
hepRepXMLWriter->addAttDef("EType", "Entity Type", "Physics","");
@@ -420,7 +444,7 @@ void G4HepRepFileSceneHandler::AddHepRepInstance(const char* primName,
}
hepRepXMLWriter->addInstance();
// Handle Type declaration for Detector Geometry,
// replacing G4's top geometry level name "worldPhysical" with the
// name "Detector Geometry".
@@ -435,13 +459,13 @@ void G4HepRepFileSceneHandler::AddHepRepInstance(const char* primName,
hepRepXMLWriter->addType("G4 Culled Layer", hepRepXMLWriter->typeDepth + 1);
hepRepXMLWriter->addInstance();
}
if (fCurrentDepth!=0) {
// Add the HepRepType for the current volume.
hepRepXMLWriter->addType(fpCurrentPV->GetName(),fCurrentDepth);
hepRepXMLWriter->addInstance();
}
// Additional attributes.
hepRepXMLWriter->addAttValue("LVol", fpCurrentLV->GetName());
hepRepXMLWriter->addAttValue("Solid", fpCurrentLV->GetSolid()->GetName());
@@ -451,7 +475,7 @@ void G4HepRepFileSceneHandler::AddHepRepInstance(const char* primName,
hepRepXMLWriter->addAttValue("State", fpCurrentLV->GetMaterial()->GetState());
hepRepXMLWriter->addAttValue("Radlen", fpCurrentLV->GetMaterial()->GetRadlen());
}
hepRepXMLWriter->addAttValue("DrawAs",primName);
hepRepXMLWriter->addAttValue("Layer",hepRepXMLWriter->typeDepth);
@@ -460,17 +484,17 @@ void G4HepRepFileSceneHandler::AddHepRepInstance(const char* primName,
float redness = colour.GetRed();
float greenness = colour.GetGreen();
float blueness = colour.GetBlue();
if (redness==0. && greenness==0. && blueness==0.) {
redness = 1.;
greenness = 1.;
blueness = 1.;
}
if (strcmp(primName,"Point")==0)
hepRepXMLWriter->addAttValue("MarkColor",redness,greenness,blueness);
else
hepRepXMLWriter->addAttValue("LineColor",redness,greenness,blueness);
hepRepXMLWriter->addAttValue("LineColor",redness,greenness,blueness);
// Handle visibility attribute.
const G4VisAttributes* visAtts = visible.GetVisAttributes();
@@ -21,8 +21,30 @@
// ********************************************************************
//
//
// $Id: G4HepRepFileViewer.cc,v 1.6 2002/02/02 04:00:27 perl Exp $
// GEANT4 tag $Name: geant4-04-01 $
// ********************************************************************
// * 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.8 2002/12/13 11:18:03 gunter Exp $
// GEANT4 tag $Name: geant4-05-00 $
#include "G4HepRepFileViewer.hh"
@@ -40,6 +62,9 @@ G4HepRepFileViewer::G4HepRepFileViewer
(G4VSceneHandler& sceneHandler, const G4String& name):
G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name) {
hepRepXMLWriter = ((G4HepRepFileSceneHandler*)(&sceneHandler))->GetHepRepXMLWriter();
// Make changes to view parameters for HepRep...
fVP.SetCulling(false);
fDefaultVP.SetCulling(false);
}
G4HepRepFileViewer::~G4HepRepFileViewer() {}
@@ -0,0 +1,617 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
/**
* @author Mark Donszelmann
*/
#include "globals.hh"
#include "g4std/vector"
#include "g4std/strstream"
#include "g4std/fstream"
//HepRep
#include "HEPREP/HepRep.h"
//G4
#include "G4Types.hh"
#include "G4Point3D.hh"
#include "G4Normal3D.hh"
#include "G4Polyline.hh"
#include "G4Polymarker.hh"
#include "G4Polyhedron.hh"
#include "G4Circle.hh"
#include "G4Square.hh"
#include "G4Text.hh"
#include "G4NURBS.hh"
#include "G4VPhysicalVolume.hh"
#include "G4VisAttributes.hh"
#include "G4VSolid.hh"
#include "G4VTrajectory.hh"
#include "G4VHit.hh"
#include "G4Scene.hh"
#include "G4Material.hh"
// Streamer
#include "XMLHepRepStreamerFactory.h"
// This
#include "G4HepRep.hh"
#include "G4HepRepSceneHandler.hh"
using namespace HEPREP;
G4int G4HepRepSceneHandler::sceneCount = 0;
G4int G4HepRepSceneHandler::sceneIdCount = 0;
G4HepRepSceneHandler::G4HepRepSceneHandler (G4VGraphicsSystem& system, const G4String& name)
: G4VSceneHandler (system, sceneIdCount++, name),
currentDepth (0),
currentPV (0),
currentLV (0) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::G4HepRepSceneHandler: "
<< system << " "
<< GetScene()->GetName() << G4endl;
#endif
heprepFactory = new XMLHepRepStreamerFactory();
writer = NULL;
fileNo = 0;
}
G4HepRepSceneHandler::~G4HepRepSceneHandler () {
close();
delete heprepFactory;
heprepFactory = NULL;
}
HepRepFactory* G4HepRepSceneHandler::GetHepRepFactory() {
if (writer == NULL) open();
return heprepFactory;
}
void G4HepRepSceneHandler::open() {
if (writer != NULL) return;
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::open(" << fname << ") " << G4endl;
#endif
if (strcmp(GetScene()->GetName(), "stdout") == 0) {
out = NULL;
writer = heprepFactory->createHepRepWriter(&G4cout);
} else if (strcmp(GetScene()->GetName(), "stderr") == 0) {
out = NULL;
writer = heprepFactory->createHepRepWriter(&G4cerr);
} else {
char fname [256];
G4std::ostrstream ost(fname, 256);
ost << GetScene()->GetName() << "-" << fileNo++ << ".heprep" << G4std::ends;
out = new G4std::ofstream(fname);
writer = heprepFactory->createHepRepWriter(out);
}
heprep = heprepFactory->createHepRep();
heprep->addLayer("Geometry");
heprep->addLayer("Event");
heprep->addLayer("CalHit");
heprep->addLayer("Track");
heprep->addLayer("Hit");
HepRepTreeID* treeID = heprepFactory->createHepRepTreeID("G4Types", "1.0");
HepRepTypeTree* typeTree = heprepFactory->createHepRepTypeTree(treeID);
heprep->addTypeTree(typeTree);
geometryType = heprepFactory->createHepRepType(NULL, "Detector Geometry");
geometryType->addAttDef("LVol", "Logical Volume", "Physics","");
geometryType->addAttDef("Solid", "Solid Name", "Physics","");
geometryType->addAttDef("EType", "Entity Type", "Physics","");
geometryType->addAttDef("Material", "Material Name", "Physics","");
geometryType->addAttDef("Density", "Material Density", "Physics","");
geometryType->addAttDef("State", "Material State", "Physics","");
geometryType->addAttDef("Radlen", "Material Radiation Length", "Physics","");
geometryType->addAttValue("Layer", G4String("Geometry"));
geometryType->addAttValue("HasFrame", true);
typeTree->addType(geometryType);
eventType = heprepFactory->createHepRepType(NULL, "Event");
eventType->addAttValue("Layer", G4String("Event"));
eventType->addAttValue("HasFrame", true);
typeTree->addType(eventType);
trackType = heprepFactory->createHepRepType(eventType, "Track");
trackType->addAttValue("Layer", G4String("Track"));
calHitType = heprepFactory->createHepRepType(eventType, "Calorimeter Hit");
calHitType->addAttValue("Layer", G4String("CalHit"));
calHitType->addAttValue("Fill", true);
hitType = heprepFactory->createHepRepType(eventType, "Hit");
hitType->addAttValue("Layer", G4String("Hit"));
HepRepInstanceTree* instanceTree = heprepFactory->createHepRepInstanceTree("G4Data", "1.0", typeTree);
heprep->addInstanceTree(instanceTree);
parent = heprepFactory->createHepRepInstance(instanceTree, eventType);
instanceTree->addInstance(parent);
delete treeID;
delete typeTree;
delete instanceTree;
}
void G4HepRepSceneHandler::close() {
if (writer == NULL) return;
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::close() " << G4endl;
#endif
writer->close();
delete writer;
delete out;
writer = NULL;
out = NULL;
delete heprep;
heprep = NULL;
delete geometryType;
geometryType = NULL;
delete eventType;
eventType = NULL;
delete trackType;
trackType = NULL;
delete hitType;
hitType = NULL;
delete calHitType;
calHitType = NULL;
delete parent;
parent = NULL;
}
void G4HepRepSceneHandler::EstablishSpecials(G4PhysicalVolumeModel& model) {
model.DefinePointersToWorkingSpace(&currentDepth, &currentPV, &currentLV);
}
void G4HepRepSceneHandler::BeginModeling() {
G4VSceneHandler::BeginModeling();
}
void G4HepRepSceneHandler::EndModeling() {
G4VSceneHandler::EndModeling();
}
void G4HepRepSceneHandler::AddPrimitive (const G4Polyline& line) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddPrimitive(G4Polyline&) " << line.size() << G4endl;
#endif
HepRepFactory* factory = GetHepRepFactory();
HepRepInstance* instance = CreateInstance(parent, trackType);
SetLine(instance, line);
instance->addAttValue("DrawAs", G4String("Line"));
SetColour(instance, GetColour(line));
for (size_t i=0; i < line.size(); i++) {
G4Point3D vertex = transform * line[i];
HepRepPoint* point = factory->createHepRepPoint(instance, vertex.x(), vertex.y(), vertex.z());
delete point;
}
delete instance;
}
void G4HepRepSceneHandler::AddPrimitive (const G4Polymarker& line) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddPrimitive(G4Polymarker&) " << line.size() << G4endl;
#endif
HepRepFactory* factory = GetHepRepFactory();
HepRepInstance* instance = CreateInstance(parent, hitType);
instance->addAttValue("DrawAs", G4String("Point"));
SetMarker(instance, line);
switch (line.GetMarkerType()) {
case line.dots:
instance->addAttValue("MarkName", G4String("Circle"));
instance->addAttValue("Fill", true);
SetColour(instance, GetColour(line), G4String("FillColor"));
break;
case line.circles:
instance->addAttValue("MarkName", G4String("Circle"));
break;
case line.squares:
instance->addAttValue("MarkName", G4String("Box"));
break;
case line.line:
default:
instance->addAttValue("MarkName", G4String("Plus"));
break;
}
SetColour(instance, GetColour(line));
for (size_t i=0; i < line.size(); i++) {
G4Point3D vertex = transform * line[i];
HepRepPoint* point = factory->createHepRepPoint(instance, vertex.x(), vertex.y(), vertex.z());
delete point;
}
delete instance;
}
void G4HepRepSceneHandler::AddPrimitive (const G4Circle& circle) {
G4Point3D center = transform * circle.GetPosition();
HepRepFactory* factory = GetHepRepFactory();
HepRepInstance* instance = CreateInstance(parent, hitType);
SetColour (instance, GetColour(circle));
instance->addAttValue("DrawAs", G4String("Point"));
instance->addAttValue("MarkName", G4String("Circle"));
SetMarker(instance, circle);
HepRepPoint* point = factory->createHepRepPoint(instance, center.x(), center.y(), center.z());
delete point;
delete instance;
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddPrimitive(G4Circle&) : center : "
<< " x : " << center.x()
<< " y : " << center.y()
<< " z : " << center.z()
<< " ,radius : " << size << G4endl;
#endif
}
void G4HepRepSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddPrimitive(G4Polyhedron&) " << G4endl;
#endif
G4Normal3D surfaceNormal;
G4Point3D vertex;
if (polyhedron.GetNoFacets()==0) return;
HepRepFactory* factory = GetHepRepFactory();
HepRepInstance* instance = CreateInstance(parent, calHitType);
G4bool notLastFace;
do {
HepRepInstance* face = CreateInstance(instance, calHitType);
SetLine(face, polyhedron);
face->addAttValue("DrawAs", G4String("Polygon"));
SetColour(face, GetColour(polyhedron));
if (IsEventData()) SetColour(face, GetColour(polyhedron), G4String("FillColor"));
notLastFace = polyhedron.GetNextNormal (surfaceNormal);
G4int edgeFlag = 1;
G4bool notLastEdge;
do {
notLastEdge = polyhedron.GetNextVertex (vertex, edgeFlag);
vertex = transform * vertex;
HepRepPoint* point = factory->createHepRepPoint(face, vertex.x(), vertex.y(), vertex.z());
delete point;
} while (notLastEdge);
delete face;
} while (notLastFace);
delete instance;
}
void G4HepRepSceneHandler::AddPrimitive (const G4Text& text) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddPrimitive(G4Text&) " << G4endl;
#endif
G4cout << "G4HepRepSceneHandler::AddPrimitive G4Text : not yet implemented. " << G4endl;
}
void G4HepRepSceneHandler::AddPrimitive (const G4Square& square) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddPrimitive(G4Square&) " << G4endl;
#endif
G4Point3D center = transform * square.GetPosition();
HepRepFactory* factory = GetHepRepFactory();
HepRepInstance* instance = CreateInstance(parent, hitType);
SetColour (instance, GetColour(square));
instance->addAttValue("DrawAs", G4String("Point"));
instance->addAttValue("MarkName", G4String("Box"));
SetMarker(instance, square);
HepRepPoint* point = factory->createHepRepPoint(instance, center.x(), center.y(), center.z());
delete point;
delete instance;
}
//Method for handling G4NURBS objects for drawing solids.
//Knots and Ctrl Pnts MUST be arrays of GLfloats.
void G4HepRepSceneHandler::AddPrimitive (const G4NURBS& nurb) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddPrimitive(G4NURBS&) " << G4endl;
#endif
G4cout << "G4HepRepSceneHandler::AddPrimitive G4NURBS : not yet implemented. " << G4endl;
}
void G4HepRepSceneHandler::AddThis (const G4Box& box) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4Box&) " << G4endl;
#endif
G4VSceneHandler::AddThis (box);
}
void G4HepRepSceneHandler::AddThis (const G4Cons& cons) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4Cons&) " << G4endl;
#endif
G4VSceneHandler::AddThis (cons);
}
void G4HepRepSceneHandler::AddThis (const G4Tubs& tubs) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4Tubs&) " << G4endl;
#endif
G4VSceneHandler::AddThis (tubs);
}
void G4HepRepSceneHandler::AddThis (const G4Trd& trd) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4Trd&) " << G4endl;
#endif
G4VSceneHandler::AddThis (trd);
}
void G4HepRepSceneHandler::AddThis (const G4Trap& trap) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4Trap&) " << G4endl;
#endif
G4VSceneHandler::AddThis (trap);
}
void G4HepRepSceneHandler::AddThis (const G4Sphere& sphere) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4Sphere&) " << G4endl;
#endif
G4VSceneHandler::AddThis (sphere);
}
void G4HepRepSceneHandler::AddThis (const G4Para& para) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4Para&) " << G4endl;
#endif
G4VSceneHandler::AddThis (para);
}
void G4HepRepSceneHandler::AddThis (const G4Torus& torus) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4Torus&) " << G4endl;
#endif
G4VSceneHandler::AddThis (torus);
}
void G4HepRepSceneHandler::AddThis (const G4Polycone& polycone) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4Polycone&) " << G4endl;
#endif
G4VSceneHandler::AddThis (polycone);
}
void G4HepRepSceneHandler::AddThis (const G4Polyhedra& polyhedra) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4Polyhedra&) " << G4endl;
#endif
G4VSceneHandler::AddThis (polyhedra);
}
void G4HepRepSceneHandler::AddThis (const G4VSolid& solid) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4VSolid&) " << G4endl;
#endif
G4VSceneHandler::AddThis (solid);
}
void G4HepRepSceneHandler::AddThis (const G4VTrajectory& traj) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4VTrajectory&) " << G4endl;
#endif
G4VSceneHandler::AddThis (traj);
}
void G4HepRepSceneHandler::AddThis (const G4VHit& hit) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::AddThis(G4VHit&) " << G4endl;
#endif
G4VSceneHandler::AddThis (hit);
}
void
G4HepRepSceneHandler::PreAddThis
(const G4Transform3D& objectTransformation,
const G4VisAttributes& visAttribs) {
G4VSceneHandler::PreAddThis (objectTransformation, visAttribs);
transform = objectTransformation;
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::PreAddThis : " << objectTransformation << G4endl;
G4cout << "G4HepRepSceneHandler::PreAddThis : " << visAttribs << G4endl;
#endif
}
void G4HepRepSceneHandler::PostAddThis () {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::PostAddThis" << G4endl;
#endif
G4VSceneHandler::PostAddThis();
}
void G4HepRepSceneHandler::BeginPrimitives (const G4Transform3D& objectTransformation) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::BeginPrimitives: " << G4endl;
#endif
G4VSceneHandler::BeginPrimitives (objectTransformation);
transform = objectTransformation;
}
void G4HepRepSceneHandler::EndPrimitives () {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::EndPrimitives" << G4endl;
#endif
G4VSceneHandler::EndPrimitives ();
}
void G4HepRepSceneHandler::SetColour (HepRepAttribute *attribute, const G4Colour& color, const G4String& key) {
#ifdef DEBUG
G4cout << "G4HepRepSceneHandler::SetColour : red : " << color.GetRed () <<
" green : " << color.GetGreen () <<
" blue : " << color.GetBlue () << G4endl;
#endif
attribute->addAttValue(key, color.GetRed(), color.GetGreen(), color.GetBlue(),color.GetAlpha());
}
void G4HepRepSceneHandler::SetLine (HepRepInstance *instance, const G4Visible& visible) {
G4VisAttributes atts = visible.GetVisAttributes();
instance->addAttValue("LineWidth", atts.GetLineWidth());
switch (atts.GetLineStyle()) {
case G4VisAttributes::dotted:
instance->addAttValue("LineStyle", G4String("Dotted"));
break;
case G4VisAttributes::dashed:
instance->addAttValue("LineStyle", G4String("Dashed"));
break;
case G4VisAttributes::unbroken:
default:
instance->addAttValue("LineStyle", G4String("Solid"));
break;
}
}
void G4HepRepSceneHandler::SetMarker (HepRepInstance *instance, const G4VMarker& marker) {
MarkerSizeType markerType;
G4double size = GetMarkerRadius( marker , markerType );
instance->addAttValue("MarkSize", size);
instance->addAttValue("MarkType", (markerType == screen) ? G4String("Symbol") : G4String("Real"));
if (marker.GetFillStyle() == G4VMarker::noFill) {
instance->addAttValue("Fill", false);
} else {
instance->addAttValue("Fill", true);
SetColour(instance, GetColour(marker), G4String("FillColor"));
}
}
HepRepInstance* G4HepRepSceneHandler::CreateInstance(HepRepInstance* p, HepRepType* altType) {
HepRepFactory* factory = GetHepRepFactory();
bool event = IsEventData();
HepRepType* type = (event) ? altType : geometryType;
HepRepInstance* instance = factory->createHepRepInstance(p, type);
if (!event) {
instance->addAttValue("LVol", currentLV->GetName());
instance->addAttValue("Solid", currentLV->GetSolid()->GetName());
instance->addAttValue("EType", currentLV->GetSolid()->GetEntityType());
instance->addAttValue("Material", currentLV->GetMaterial()->GetName());
instance->addAttValue("Density", currentLV->GetMaterial()->GetDensity());
instance->addAttValue("Radlen", currentLV->GetMaterial()->GetRadlen());
switch (currentLV->GetMaterial()->GetState()) {
case kStateSolid:
instance->addAttValue("State", G4String("Solid"));
break;
case kStateLiquid:
instance->addAttValue("State", G4String("Liquid"));
break;
case kStateGas:
instance->addAttValue("State", G4String("Gas"));
break;
case kStateUndefined:
default:
instance->addAttValue("State", G4String("Undefined"));
break;
}
}
return instance;
}
bool G4HepRepSceneHandler::IsEventData () {
return !currentPV || fReadyForTransients;
}
@@ -0,0 +1,131 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
/**
* @author Mark Donszelmann
*/
//HepRep
#include "HEPREP/HepRep.h"
//G4
#include "G4Types.hh"
//#include "G4VInteractorManager.hh"
#include "G4Scene.hh"
#include "G4HepRep.hh"
#include "G4HepRepSceneHandler.hh"
//This
#include "G4HepRepViewer.hh"
using namespace HEPREP;
G4HepRepViewer::G4HepRepViewer (G4VSceneHandler& scene, const G4String& name)
: G4VViewer (scene, scene.IncrementViewCount(), name),
drawn(false) {
#ifdef DEBUG
G4cout << "G4HepRepViewer::G4HepRepViewer" << G4endl;
#endif
// Make changes to view parameters for HepRep...
fVP.SetCulling(false);
fDefaultVP.SetCulling(false);
}
G4HepRepViewer::~G4HepRepViewer () {
}
void G4HepRepViewer::ClearView () {
#ifdef DEBUG
G4cout << "G4HepRepViewer::ClearView" << G4endl;
#endif
}
/***************************************************************************/
// Calculates view representation based on extent of object being
// viewed and (initial) direction of camera. (Note: it can change
// later due to user interaction via visualization system's GUI.)
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
void G4HepRepViewer::SetView () {
#ifdef DEBUG
G4cout << "G4HepRepViewer::SetView" << G4endl;
#endif
}
void G4HepRepViewer::DrawView () {
#ifdef DEBUG
G4cout << "G4HepRepViewer::DrawView" << G4endl;
#endif
NeedKernelVisit();
ProcessView();
drawn = true;
}
void G4HepRepViewer::ShowView () {
#ifdef DEBUG
G4cout << "G4HepRepViewer::ShowView" << G4endl;
#endif
G4VViewer::ShowView();
if (drawn) {
G4HepRepSceneHandler* sceneHandler = (G4HepRepSceneHandler*)GetSceneHandler();
sceneHandler->close();
drawn = false;
}
}
void G4HepRepViewer::FinishView () {
#ifdef DEBUG
G4cout << "G4HepRepViewer::FinishView" << G4endl;
#endif
G4VViewer::FinishView();
}
@@ -20,9 +20,31 @@
// * statement, and all its terms. *
// ********************************************************************
//
//
// ********************************************************************
// * 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.8 2002/02/05 19:52:01 perl Exp $
// $Id: HepRepXMLWriter.cc,v 1.9 2002/12/13 11:18:03 gunter Exp $
//
// Description:
// Create a HepRep XML File (HepRep version 1).
@@ -0,0 +1,103 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include <fstream>
#include "IndentPrintWriter.h"
using namespace std;
IndentPrintWriter::IndentPrintWriter(ostream* out, int level)
: out(out), indentLevel(level) {
indentString = " ";
indented = false;
}
IndentPrintWriter::~IndentPrintWriter() {
}
void IndentPrintWriter::close() {
out->flush();
ofstream* fout = dynamic_cast<ofstream *>(out);
if (fout != NULL) {
fout->close();
}
}
IndentPrintWriter& IndentPrintWriter::operator<< (const char* s) {
if (!indented) doIndent();
*out << s;
return *this;
}
IndentPrintWriter& IndentPrintWriter::operator<< (ostream& (*pf)(ostream&)) {
*out << endl;
indented = false;
return *this;
}
void IndentPrintWriter::println(string s) {
*this << s.c_str() << endl;
}
void IndentPrintWriter::print(string s) {
*this << s.c_str();
}
void IndentPrintWriter::println() {
*out << endl;
indented = false;
}
void IndentPrintWriter::doIndent() {
for (int i=0; i<indentLevel; i++) {
*out << indentString.c_str();
}
indented = true;
}
void IndentPrintWriter::indent() {
indentLevel++;
}
void IndentPrintWriter::outdent() {
indentLevel--;
}
int IndentPrintWriter::getIndent() {
return indentLevel;
}
void IndentPrintWriter::setIndent(int level) {
indentLevel = level;
}
string IndentPrintWriter::getIndentString() {
return indentString;
}
void IndentPrintWriter::setIndentString(string indent) {
indentString = indent;
}
+16
View File
@@ -0,0 +1,16 @@
Apart from the heprep1 files:
G4HepRepFile.cc
G4HepRepFileSceneHandler.cc
G4HepRepFileViewer.cc
HepRepXMLWriter.cc
the other sources (heprep2) are copies from the FreeHEP library
(java.freehep.org) and are maintained there.
The files starting with G4 are geant4 compliant, the others may not be.
Changes made here may be overwritten.
12 Nov 2002
Mark Donszelmann
@@ -0,0 +1,103 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include "StreamerHepRep.h"
using namespace std;
using namespace HEPREP;
StreamerHepRep::StreamerHepRep(HepRepWriter* streamer) {
streamer->write(this);
}
StreamerHepRep::~StreamerHepRep() {
}
HepRep* StreamerHepRep::copy(HepRepSelectFilter* filter) {
return NULL;
}
vector<string>* StreamerHepRep::getLayerOrder() {
return &layers;
}
bool StreamerHepRep::addLayer(string layer) {
layers.push_back(layer);
return true;
}
bool StreamerHepRep::addTypeTree(HepRepTypeTree* typeTree) {
return true;
}
void StreamerHepRep::removeTypeTree(HepRepTypeTree* typeTree) {
}
HepRepTypeTree* StreamerHepRep::getTypeTree(string name, string version) {
return NULL;
}
vector<HepRepTypeTree*>* StreamerHepRep::getTypeTrees() {
return NULL;
}
HepRepType* StreamerHepRep::getType(string name) {
return NULL;
}
bool StreamerHepRep::addInstanceTree(HepRepInstanceTree* instanceTree) {
return true;
}
void StreamerHepRep::removeInstanceTree(HepRepInstanceTree* instanceTree) {
}
HepRepInstanceTree* StreamerHepRep::getInstanceTreeTop(string name, string version) {
return NULL;
}
HepRepInstanceTree* StreamerHepRep::getInstances(string name, string version,
vector<string> typeNames) {
return NULL;
}
HepRepInstanceTree* StreamerHepRep::getInstancesAfterAction(
string name,
string version,
vector<string> typeNames,
vector<HepRepAction*> actions,
bool getPoints,
bool getDrawAtts,
bool getNonDrawAtts,
vector<string> invertAtts) {
return NULL;
}
string StreamerHepRep::checkForException() {
return NULL;
}
vector<HepRepInstanceTree*>* StreamerHepRep::getInstanceTrees() {
return NULL;
}
@@ -0,0 +1,90 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include <iostream>
#include "StreamerHepRepAttribute.h"
#include "DefaultHepRepAttValue.h"
using namespace std;
using namespace HEPREP;
StreamerHepRepAttribute::StreamerHepRepAttribute(HepRepWriter* stream) {
this->streamer = stream;
}
StreamerHepRepAttribute::~StreamerHepRepAttribute() {
}
vector<HepRepAttValue*>* StreamerHepRepAttribute::getAttValuesFromNode() {
return NULL;
}
bool StreamerHepRepAttribute::addAttValue(HepRepAttValue* hepRepAttValue) {
streamer->write(hepRepAttValue);
delete hepRepAttValue;
return true;
}
bool StreamerHepRepAttribute::addAttValue(string key, string value, int showLabel) {
return addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
bool StreamerHepRepAttribute::addAttValue(string key, int value, int showLabel) {
return addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
bool StreamerHepRepAttribute::addAttValue(string key, double value, int showLabel) {
return addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
bool StreamerHepRepAttribute::addAttValue(string key, bool value, int showLabel) {
return addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
bool StreamerHepRepAttribute::addAttValue(string key, vector<double> value, int showLabel) {
return addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
bool StreamerHepRepAttribute::addAttValue(string key, double red, double green, double blue, double alpha, int showLabel) {
vector<double> color;
color.push_back(red);
color.push_back(green);
color.push_back(blue);
color.push_back(alpha);
return addAttValue(new DefaultHepRepAttValue(key, color, showLabel));
}
HepRepAttValue* StreamerHepRepAttribute::getAttValueFromNode(string lowerCaseName) {
return NULL;
}
HepRepAttValue* StreamerHepRepAttribute::removeAttValue(string key) {
return NULL;
}
HepRepAttValue* StreamerHepRepAttribute::getAttValue(string name) {
return NULL;
}
@@ -0,0 +1,59 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include "StreamerHepRepDefinition.h"
#include "DefaultHepRepAttDef.h"
using namespace std;
using namespace HEPREP;
StreamerHepRepDefinition::StreamerHepRepDefinition(HepRepWriter* streamer)
: StreamerHepRepAttribute(streamer), streamer(streamer) {
}
StreamerHepRepDefinition::~StreamerHepRepDefinition() {
}
vector<HepRepAttDef *>* StreamerHepRepDefinition::getAttDefsFromNode() {
return NULL;
}
bool StreamerHepRepDefinition::addAttDef(HepRepAttDef* hepRepAttDef) {
streamer->write(hepRepAttDef);
delete hepRepAttDef;
return true;
}
bool StreamerHepRepDefinition::addAttDef(string name, string desc, string type, string extra) {
addAttDef(new DefaultHepRepAttDef(name, desc, type, extra));
return true;
}
HepRepAttDef* StreamerHepRepDefinition::getAttDefFromNode(string lowerCaseName) {
return NULL;
}
HepRepAttDef* StreamerHepRepDefinition::getAttDef(string name) {
return NULL;
}
@@ -0,0 +1,81 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include <iostream>
#include "StreamerHepRepInstance.h"
using namespace std;
using namespace HEPREP;
StreamerHepRepInstance::StreamerHepRepInstance(HepRepWriter* stream, HepRepInstance* instance, HepRepType* heprepType)
: StreamerHepRepAttribute(stream), parent(instance), type(heprepType) {
if (type == NULL) cerr << "HepRepInstance cannot be created without a HepRepType." << endl;
stream->write(this);
}
StreamerHepRepInstance::StreamerHepRepInstance(HepRepWriter* stream, HepRepInstanceTree* instanceTree, HepRepType* heprepType)
: StreamerHepRepAttribute(stream), parent(instanceTree), type(heprepType) {
if (type == NULL) cerr << "HepRepInstance cannot be created without a HepRepType." << endl;
stream->write(this);
}
StreamerHepRepInstance::~StreamerHepRepInstance() {
}
HepRepInstance* StreamerHepRepInstance::copy(HepRep* heprep, HepRepInstance* instance, HepRepSelectFilter* filter) {
return NULL;
}
HepRepInstance* StreamerHepRepInstance::copy(HepRep* heprep, HepRepInstanceTree* instanceTree, HepRepSelectFilter* filter) {
return NULL;
}
HepRepType* StreamerHepRepInstance::getType() {
return type;
}
bool StreamerHepRepInstance::addPoint(HepRepPoint* point) {
return true;
}
vector<HepRepPoint*>* StreamerHepRepInstance::getPoints() {
return NULL;
}
bool StreamerHepRepInstance::addInstance(HepRepInstance* instance) {
return true;
}
void StreamerHepRepInstance::removeInstance(HepRepInstance* instance) {
}
vector<HepRepInstance*>* StreamerHepRepInstance::getInstances() {
return NULL;
}
HepRepAttValue* StreamerHepRepInstance::getAttValue(string name) {
return NULL;
}
@@ -0,0 +1,69 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include "StreamerHepRepInstanceTree.h"
using namespace std;
using namespace HEPREP;
StreamerHepRepInstanceTree::StreamerHepRepInstanceTree(HepRepWriter* stream, string name, string version, HepRepTreeID* typeTree)
: DefaultHepRepTreeID(name, version), streamer(stream), typeTree(typeTree) {
stream->write(this);
}
StreamerHepRepInstanceTree::~StreamerHepRepInstanceTree() {
}
HepRepTreeID* StreamerHepRepInstanceTree::copy() {
return DefaultHepRepTreeID::copy();
}
HepRepInstanceTree* StreamerHepRepInstanceTree::copy(HepRep* heprep, HepRepSelectFilter* filter) {
return NULL;
}
bool StreamerHepRepInstanceTree::addInstance(HepRepInstance* instance) {
return true;
}
void StreamerHepRepInstanceTree::removeInstance(HepRepInstance* instance) {
}
vector<HepRepInstance*>* StreamerHepRepInstanceTree::getInstances() {
return NULL;
}
bool StreamerHepRepInstanceTree::addInstanceTree(HepRepTreeID* treeID) {
streamer->write(treeID);
return true;
}
HepRepTreeID* StreamerHepRepInstanceTree::getTypeTree() {
return typeTree;
}
vector<HepRepInstanceTree*>* StreamerHepRepInstanceTree::getInstanceTrees() {
return NULL;
}
@@ -0,0 +1,137 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include <string>
#include <iostream>
#include <cmath>
#include "StreamerHepRepPoint.h"
using namespace std;
using namespace HEPREP;
StreamerHepRepPoint::StreamerHepRepPoint(HepRepWriter* stream, HepRepInstance* inst, double x, double y, double z)
: StreamerHepRepAttribute(stream), instance(inst), x(x), y(y), z(z) {
if (instance == NULL) {
cerr << "HepRepPoints cannot be created without a HepRepInstance." << endl;
}
stream->write(this);
}
StreamerHepRepPoint::~StreamerHepRepPoint() {
}
HepRepInstance* StreamerHepRepPoint::getInstance() {
return instance;
}
HepRepAttValue* StreamerHepRepPoint::getAttValue(string lowerCaseName) {
HepRepAttValue* value = getAttValueFromNode(lowerCaseName);
return (value != NULL) ? value : instance->getAttValue(lowerCaseName);
}
HepRepPoint* StreamerHepRepPoint::copy(HepRepInstance* parent) {
return NULL;
}
double StreamerHepRepPoint::getX() {
return x;
}
double StreamerHepRepPoint::getY() {
return y;
}
double StreamerHepRepPoint::getZ() {
return z;
}
vector<double>* StreamerHepRepPoint::getXYZ(vector<double>* xyz) {
(*xyz)[0] = x;
(*xyz)[1] = y;
(*xyz)[2] = z;
return xyz;
}
double StreamerHepRepPoint::getRho() {
return sqrt(x*x + y*y);
}
double StreamerHepRepPoint::getPhi() {
return atan2(y, x);
}
double StreamerHepRepPoint::getTheta() {
return atan2(getRho(), z);
}
double StreamerHepRepPoint::getR() {
double r = getRho();
return sqrt(r*r + z*z);
}
double StreamerHepRepPoint::getEta() {
double ct = cos(getTheta());
return -0.5*log((1.-ct)/(1.+ct));
}
double StreamerHepRepPoint::getX(double xVertex, double yVertex, double zVertex) {
return x - xVertex;
}
double StreamerHepRepPoint::getY(double xVertex, double yVertex, double zVertex) {
return y - yVertex;
}
double StreamerHepRepPoint::getZ(double xVertex, double yVertex, double zVertex) {
return z - zVertex;
}
double StreamerHepRepPoint::getRho(double xVertex, double yVertex, double zVertex) {
double dx = getX(xVertex, yVertex, zVertex);
double dy = getY(xVertex, yVertex, zVertex);
return sqrt(dx*dx + dy*dy);
}
double StreamerHepRepPoint::getPhi(double xVertex, double yVertex, double zVertex) {
return atan2(getY(xVertex, yVertex, zVertex), getX(xVertex, yVertex, zVertex));
}
double StreamerHepRepPoint::getTheta(double xVertex, double yVertex, double zVertex) {
return atan2(getRho(xVertex, yVertex, zVertex), getZ(xVertex, yVertex, zVertex));
}
double StreamerHepRepPoint::getR(double xVertex, double yVertex, double zVertex) {
double dr = getRho(xVertex, yVertex, zVertex);
double dz = getZ(xVertex, yVertex, zVertex);
return sqrt(dr*dr + dz*dz);
}
double StreamerHepRepPoint::getEta(double xVertex, double yVertex, double zVertex) {
double ct = cos(getTheta(xVertex, yVertex, zVertex));
return -0.5*log((1.-ct)/(1.+ct));
}
@@ -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. *
// ********************************************************************
//
#include "StreamerHepRepType.h"
using namespace std;
using namespace HEPREP;
StreamerHepRepType::StreamerHepRepType(HepRepWriter* stream, HepRepType* parent, string name)
: StreamerHepRepDefinition(stream), parent(parent), name(name) {
this->description = "No Description";
this->infoURL = "No Info URL";
stream->write(this);
}
StreamerHepRepType::~StreamerHepRepType() {
}
HepRepType* StreamerHepRepType::getSuperType() {
return parent;
}
HepRepAttDef* StreamerHepRepType::getAttDef(string key) {
return NULL;
}
/**
* searched for a value with given name. Search up the type tree if needed.
*/
HepRepAttValue* StreamerHepRepType::getAttValue(string key) {
return NULL;
}
HepRepType* StreamerHepRepType::copy(HepRep* heprep, HepRepType* type) {
return NULL;
}
string StreamerHepRepType::getName() {
return name;
}
string StreamerHepRepType::getDescription() {
return description;
}
void StreamerHepRepType::setDescription(string desc) {
this->description = desc;
}
string StreamerHepRepType::getInfoURL() {
return infoURL;
}
void StreamerHepRepType::setInfoURL(string info) {
this->infoURL = info;
}
bool StreamerHepRepType::addType(HepRepType* type) {
return true;
}
vector<HepRepType*>* StreamerHepRepType::getTypes() {
return NULL;
}
@@ -0,0 +1,55 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include <iostream>
#include "StreamerHepRepTypeTree.h"
using namespace std;
using namespace HEPREP;
StreamerHepRepTypeTree::StreamerHepRepTypeTree(HepRepWriter* streamer, HepRepTreeID* typeTree)
: DefaultHepRepTreeID(typeTree->getName(), typeTree->getVersion()) {
streamer->write(this);
}
StreamerHepRepTypeTree::~StreamerHepRepTypeTree() {
}
HepRepTreeID* StreamerHepRepTypeTree::copy() {
return DefaultHepRepTreeID::copy();
}
HepRepTypeTree* StreamerHepRepTypeTree::copy(HepRep* heprep) {
return NULL;
}
bool StreamerHepRepTypeTree::addType(HepRepType* type) {
return true;
}
vector<HepRepType*>* StreamerHepRepTypeTree::getTypes() {
return NULL;
}
@@ -0,0 +1,225 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include "XMLHepRepStreamer.h"
#include "StreamerHepRepInstance.h"
#include "DefaultHepRepAttValue.h"
#define NAMESPACE "heprep"
using namespace std;
using namespace HEPREP;
XMLHepRepStreamer::XMLHepRepStreamer(ostream* out)
: XMLWriter(out, " ", NAMESPACE) {
this->nameSpace = NAMESPACE;
openDoc();
}
XMLHepRepStreamer::~XMLHepRepStreamer() {
}
bool XMLHepRepStreamer::close() {
while (!hepreps.empty()) {
hepreps.pop();
closeTag();
}
closeDoc();
XMLWriter::close();
return true;
}
bool XMLHepRepStreamer::write(HepRep* root) {
setAttribute("xmlns", "http://www.freehep.org/HepRep");
setAttribute("xmlns", "xsi", "http://www.w3.org/2001/XMLSchema-instance");
setAttribute("xsi", "schemaLocation", "HepRep.xsd");
openTag(nameSpace, "heprep");
writtenLayers = false;
hepreps.push(root);
this->heprep = root;
return true;
}
bool XMLHepRepStreamer::write(HepRepTypeTree* typeTree) {
while (hepreps.top() != heprep) {
if (hepreps.empty()) {
cerr << "XMLHepRepStreamer: cannot write typeTree without HepRep" << endl;
return false;
}
hepreps.pop();
closeTag();
}
if (!writtenLayers) {
writtenLayers = true;
string layerOrder = "";
bool comma = false;
vector<string> *layers = heprep->getLayerOrder();
for (vector<string>::iterator i=layers->begin(); i != layers->end(); i++) {
if (comma) {
layerOrder.append(", ");
}
layerOrder.append(*i);
comma = true;
}
setAttribute("order", layerOrder);
printTag(nameSpace, "layer");
}
setAttribute("name", typeTree->getName());
setAttribute("version", typeTree->getVersion());
openTag(nameSpace, "typetree");
hepreps.push(typeTree);
heprepTypeTree = typeTree;
return true;
}
bool XMLHepRepStreamer::write(HepRepType* type) {
HepRepType* parent = type->getSuperType();
if (parent != NULL) {
while (hepreps.top() != parent) {
if (hepreps.empty()) {
cerr << "XMLHepRepStreamer: cannot write type, parent not anymore on stack..." << endl;
return false;
}
hepreps.pop();
closeTag();
}
} else {
while (hepreps.top() != heprepTypeTree) {
if (hepreps.empty()) {
cerr << "XMLHepRepStreamer: cannot write type without parent typeTree." << endl;
return false;
}
hepreps.pop();
closeTag();
}
}
setAttribute("name", type->getName());
openTag(nameSpace, "type");
hepreps.push(type);
return true;
}
bool XMLHepRepStreamer::write(HepRepTreeID* treeID) {
setAttribute("qualifier", treeID->getQualifier());
setAttribute("name", treeID->getName());
setAttribute("version", treeID->getVersion());
printTag(nameSpace, "treeid");
return true;
}
bool XMLHepRepStreamer::write(HepRepAction* action) {
setAttribute("name", action->getName());
setAttribute("expression", action->getExpression());
printTag(nameSpace, "action");
return true;
}
bool XMLHepRepStreamer::write(HepRepInstanceTree* instanceTree) {
while (hepreps.top() != heprep) {
if (hepreps.empty()) {
cerr << "XMLHepRepStreamer cannot write instanceTree without HepRep." << endl;
return false;
}
hepreps.pop();
closeTag();
}
setAttribute("name", instanceTree->getName());
setAttribute("version", instanceTree->getVersion());
setAttribute("typetreename", instanceTree->getTypeTree()->getName());
setAttribute("typetreeversion", instanceTree->getTypeTree()->getVersion());
openTag(nameSpace, "instancetree");
hepreps.push(instanceTree);
return true;
}
bool XMLHepRepStreamer::write(HepRepInstance* instance) {
void* parent = dynamic_cast<StreamerHepRepInstance*>(instance)->getParent();
while (hepreps.top() != parent) {
if (hepreps.empty()) {
cerr << "XMLHepRepStreamer: cannot write instance, parent (instance/instanceTree) not anymore on Stack..." << endl;
return false;
}
hepreps.pop();
closeTag();
}
setAttribute("type", instance->getType()->getName());
openTag(nameSpace, "instance");
hepreps.push(instance);
return true;
}
bool XMLHepRepStreamer::write(HepRepPoint* point) {
while (hepreps.top() != point->getInstance()) {
if (hepreps.empty()) {
cerr << "XMLHepRepStreamer: cannot write point, parent instance not anymore on Stack..." << endl;
return false;
}
hepreps.pop();
closeTag();
}
setAttribute("x", point->getX());
setAttribute("y", point->getY());
setAttribute("z", point->getZ());
openTag(nameSpace, "point");
hepreps.push(point);
return true;
}
bool XMLHepRepStreamer::write(HepRepAttribute* attribute) {
return true;
}
bool XMLHepRepStreamer::write(HepRepDefinition* definition) {
return true;
}
bool XMLHepRepStreamer::write(HepRepAttValue* attValue) {
string name = attValue->getName();
setAttribute("name", name);
setAttribute("value", attValue->getAsString());
setAttribute("type", attValue->getTypeName());
string label = dynamic_cast<DefaultHepRepAttValue*>(attValue)->toShowLabel();
setAttribute("showLabel", label);
printTag(nameSpace, "attvalue");
return true;
}
bool XMLHepRepStreamer::write(HepRepAttDef* attDef) {
setAttribute("name", attDef->getName());
setAttribute("desc", attDef->getDescription());
setAttribute("category", attDef->getCategory());
setAttribute("extra", attDef->getExtra());
printTag(nameSpace, "attdef");
return true;
}
@@ -0,0 +1,91 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include <iostream>
#include <fstream>
#include "XMLHepRepStreamerFactory.h"
#include "XMLHepRepStreamer.h"
#include "StreamerHepRepPoint.h"
#include "StreamerHepRepInstance.h"
#include "StreamerHepRepInstanceTree.h"
#include "StreamerHepRepType.h"
#include "StreamerHepRepTypeTree.h"
#include "StreamerHepRep.h"
#include "DefaultHepRepAction.h"
#include "DefaultHepRepTreeID.h"
using namespace std;
using namespace HEPREP;
XMLHepRepStreamerFactory::XMLHepRepStreamerFactory() {
}
XMLHepRepStreamerFactory::~XMLHepRepStreamerFactory() {
}
HepRepWriter* XMLHepRepStreamerFactory::createHepRepWriter(ostream* out) {
this->streamer = new XMLHepRepStreamer(out);
return streamer;
}
HepRepPoint* XMLHepRepStreamerFactory::createHepRepPoint (HepRepInstance* instance,
double x, double y, double z) {
return new StreamerHepRepPoint(streamer, instance, x, y, z);
}
HepRepInstance* XMLHepRepStreamerFactory::createHepRepInstance (HepRepInstance* parent, HepRepType* type) {
return new StreamerHepRepInstance(streamer, parent, type);
}
HepRepInstance* XMLHepRepStreamerFactory::createHepRepInstance (HepRepInstanceTree* parent, HepRepType* type) {
return new StreamerHepRepInstance(streamer, parent, type);
}
HepRepTreeID* XMLHepRepStreamerFactory::createHepRepTreeID (string name, string version, string qualifier) {
return new DefaultHepRepTreeID(name, version, qualifier);
}
HepRepAction* XMLHepRepStreamerFactory::createHepRepAction (string name, string expression) {
return new DefaultHepRepAction(name, expression);
}
HepRepInstanceTree* XMLHepRepStreamerFactory::createHepRepInstanceTree (string name, string version,
HepRepTreeID* typeTreeID) {
return new StreamerHepRepInstanceTree(streamer, name, version, typeTreeID);
}
HepRepType* XMLHepRepStreamerFactory::createHepRepType (HepRepType* parent, string name) {
return new StreamerHepRepType(streamer, parent, name);
}
HepRepTypeTree* XMLHepRepStreamerFactory::createHepRepTypeTree (HepRepTreeID* treeID) {
return new StreamerHepRepTypeTree(streamer, treeID);
}
HepRep* XMLHepRepStreamerFactory::createHepRep () {
return new StreamerHepRep(streamer);
}
@@ -0,0 +1,285 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include <cstdio>
#include "XMLWriter.h"
using namespace std;
XMLWriter::XMLWriter(ostream* out, string indentString, string defaultNameSpace)
: defaultNameSpace(defaultNameSpace) {
writer = new IndentPrintWriter(out);
writer->setIndentString(" ");
closed = true;
dtdName = NULL;
}
XMLWriter::~XMLWriter() {
writer->close();
delete writer;
}
void XMLWriter::close() {
closeDoc();
writer->close();
}
void XMLWriter::openDoc(string version, string encoding, bool standalone) {
string indentString = writer->getIndentString();
writer->setIndentString(indentString);
closed = false;
// if (!XMLCharacterProperties.validVersionNum(version)) throw new RuntimeException("Invalid version number: "+version);
*writer << "<?xml version=\"" << version.c_str() << "\" ";
if (encoding.compare("") != 0) {
// if (!XMLCharacterProperties.validEncName(encoding)) throw new RuntimeException("Invalid encoding name: "+encoding);
*writer << "encoding=\"" << encoding.c_str() << "\" ";
}
if (standalone) {
*writer << "standalone=\"yes\" ";
}
*writer << "?>";
*writer << endl;
writer->setIndentString(indentString);
}
void XMLWriter::referToDTD(string name, string pid, string ref) {
if (dtdName != NULL) {
cerr << "XMLWriter::ReferToDTD cannot be called twice" << endl;
}
dtdName = &name;
*writer << "<!DOCTYPE " << name.c_str() << " PUBLIC \"" << pid.c_str() << "\" \"" << ref.c_str() << "\">" << endl;
}
void XMLWriter::referToDTD(string name, string system) {
if (dtdName != NULL) {
cerr << "XMLWriter::ReferToDTD cannot be called twice";
}
dtdName = &name;
*writer << "<!DOCTYPE " << name.c_str() << " SYSTEM \"" << system.c_str() << "\">" << endl;
}
void XMLWriter::closeDoc() {
if (!closed) {
if (!openTags.empty()) {
cerr << "Not all tags were closed before closing XML document:" << endl;
while (!openTags.empty()) {
cerr << " </" << openTags.top().c_str() << ">" << endl;
openTags.pop();
}
}
closed = true;
}
}
void XMLWriter::printComment(string comment) {
if (comment.find("--") >= 0) {
cerr << "XMLWriter::printComment '--' sequence not allowed in comment" << endl;
}
*writer << "<!--" << normalizeText(comment).c_str() << "-->" << endl;
}
void XMLWriter::print(string text) {
*writer << normalizeText(text).c_str();
}
void XMLWriter::println(string text) {
print(text);
*writer << endl;
}
void XMLWriter::openTag(string ns, string name) {
if (ns.compare(defaultNameSpace) == 0) {
openTag(name);
} else {
openTag(ns.append(":").append(name));
}
}
void XMLWriter::openTag(string name) {
checkNameValid(name);
if (openTags.empty() && dtdName != NULL && dtdName->compare(name)) {
cerr << "XMLWriter::openTag(), First tag: '" << name.c_str() << "' not equal to DTD id: '" << dtdName->c_str() << "'" << endl;
}
*writer << "<" << name.c_str();
printAttributes(name.length());
*writer << ">" << endl;
writer->indent();
openTags.push(name);
}
void XMLWriter::closeTag() {
if (openTags.empty()) {
writer->close();
cerr << "XMLWriter::closeTag(), No open tags" << endl;
}
string name = openTags.top();
openTags.pop();
writer->outdent();
*writer << "</" << name.c_str() << ">" << endl;
}
void XMLWriter::printTag(string ns, string name) {
if (ns.compare(defaultNameSpace) == 0) {
printTag(name);
} else {
printTag(ns.append(":").append(name));
}
}
void XMLWriter::printTag(string name) {
checkNameValid(name);
*writer << "<" << name.c_str();
printAttributes(name.length());
*writer << "/>" << endl;
}
void XMLWriter::setAttribute(string name, string value) {
attributes[name] = value;
}
void XMLWriter::setAttribute(string ns, string name, string value) {
attributes[ns.append(":").append(name)] = value;
}
void XMLWriter::setAttribute(string name, double value) {
char buffer[40];
sprintf(buffer, "%f", value);
attributes[name] = buffer;
}
void XMLWriter::setAttribute(string ns, string name, double value) {
char buffer[40];
sprintf(buffer, "%f", value);
attributes[ns.append(":").append(name)] = buffer;
}
void XMLWriter::printAttributes(int tagLength) {
int width = tagLength + 1;
bool extraIndent = false;
for (map<string,string>::iterator i = attributes.begin(); i != attributes.end(); i++) {
string key = i->first;
checkNameValid(key);
string value = normalize(i->second);
int length = key.length() + value.length() + 3;
if (width > 0 && width + length + 2*writer->getIndent() > 60) {
width = 0;
*writer << endl;
if (!extraIndent) {
writer->indent();
extraIndent = true;
}
} else {
width += length;
*writer << " ";
}
*writer << key.c_str() << "=\"" << value.c_str() << "\"";
}
attributes.clear();
if (extraIndent) writer->outdent();
}
string XMLWriter::normalize(string s) {
string str = "";
char buffer[20];
int len = s.length();
for (int i = 0; i < len; i++) {
char ch = s[i];
switch (ch) {
case '<': {
str.append("&lt;");
break;
}
case '>': {
str.append("&gt;");
break;
}
case '&': {
str.append("&amp;");
break;
}
case '"': {
str.append("&quot;");
break;
}
case '\r':
case '\n': {
sprintf(buffer, "&#%ud", ch);
str.append(buffer);
str.append(";");
break;
}
default: {
// if (ch > 0x00FF) {
// sprintf(buffer, "&#x%4.4x", ch);
// str.append(buffer);
// str.append(";");
// } else {
str.append(&ch, 1);
// }
}
}
}
return str;
}
string XMLWriter::normalizeText(string s) {
string str = "";
int len = s.length();
for (int i = 0; i < len; i++) {
char ch = s[i];
switch (ch) {
case '<': {
str.append("&lt;");
break;
}
case '>': {
str.append("&gt;");
break;
}
case '&': {
str.append("&amp;");
break;
}
default: {
// if (ch > 0x00FF) {
// sprintf(buffer, "&#x%4.4x", ch);
// str.append(buffer);
// str.append(";");
// } else {
str.append(&ch, 1);
// }
}
}
}
return str;
}
void XMLWriter::checkNameValid(string s) {
// Could be added.
// if (!XMLCharacterProperties.validName(s)) throw new RuntimeException("Invalid name: "+s);
}