83 using namespace HEPREP;
84 using namespace cheprep;
96 geometryLayer (
"Geometry"),
98 calHitLayer (
"CalHit"),
99 trajectoryLayer (
"Trajectory"),
101 rootVolumeName (
"Geometry"),
103 eventNumberPrefix (
""),
104 eventNumberSuffix (
""),
106 eventNumberWidth (-1),
111 writeMultipleFiles (false),
115 _heprepGeometry (NULL)
119 cout <<
"G4HepRepSceneHandler::G4HepRepSceneHandler: " << system << endl;
137 cout <<
"G4HepRepSceneHandler::~G4HepRepSceneHandler() " << endl;
150 if (
writer != NULL)
return;
152 if (name ==
"stdout") {
154 cout <<
"G4HepRepSceneHandler::Open() stdout" << endl;
168 }
else if (name ==
"stderr") {
170 cout <<
"G4HepRepSceneHandler::Open() stderr" << endl;
186 cout <<
"G4HepRepSceneHandler::Open() " << name << endl;
191 const unsigned int numberOfExtensions = 8;
192 string ext[numberOfExtensions] = {
".heprep",
".heprep.xml",
".heprep.zip",
".heprep.gz",
193 ".bheprep",
".bheprep.xml",
".bheprep.zip",
".bheprep.gz"};
195 while (i < numberOfExtensions) {
196 int dot = name.size() - ext[i].size();
198 (name.substr(dot, ext[i].size()) == ext[i]))
break;
202 if (i != numberOfExtensions) {
206 writeGZ = (i == 3) || (i == 7);
208 int dot = name.length() -
extension.length();
209 baseName = (dot >= 0) ? name.substr(0, dot) :
"";
221 int startDigit = -1;
int endDigit = -1;
228 endDigit = suffix.length()-1;
229 while (endDigit >= 0) {
230 if (isdigit(suffix.at(endDigit)))
break;
234 cerr <<
"/vis/heprep/appendEventNumberSuffix contains no digits" << endl;
237 startDigit = endDigit;
238 while (startDigit >= 0) {
239 if (!isdigit(suffix.at(startDigit)))
break;
248 eventNumber = atoi(suffix.substr(startDigit, endDigit).c_str());
267 cout <<
"G4HepRepSceneHandler::OpenHepRep() " << endl;
296 if (
_heprep == NULL)
return true;
299 cout <<
"G4HepRepSceneHandler::CloseHepRep() start" << endl;
305 cerr <<
"WARNING: you probably used '/vis/viewer/endOfEventAction accumulate' and "
306 <<
"forgot to call /vis/viewer/update before exit. No event written." << endl;
327 sprintf(name,
"%s%s%s#%s",
baseName.c_str(),
"-geometry",
extension.c_str(),
"G4GeometryData");
329 sprintf(name,
"%s%s#%s",
"geometry", (
writeBinary ?
".bheprep" :
".heprep"),
"G4GeometryData");
363 sprintf(name,
"%s%s",
"geometry", (
writeBinary ?
".bheprep" :
".heprep"));
383 char fileFormat[128];
396 char eventFormat[128];
416 cout <<
"G4HepRepSceneHandler::Close() " << endl;
419 if (
writer == NULL)
return;
431 out =
new ofstream(name.c_str(), std::ios::out | std::ios::binary );
445 if (heprep == NULL)
return;
455 cout <<
"G4HepRepSceneHandler::BeginModeling() " << endl;
463 cout <<
"G4HepRepSceneHandler::EndModeling() " << endl;
470 cout <<
"G4HepRepSceneHandler::AddSolid(const G4Box& box)" << endl;
526 cout <<
"G4HepRepSceneHandler::AddSolid(const G4Cons& cons)" << endl;
567 outer->addAttValue(
"showParentAttributes",
true);
590 cout <<
"G4HepRepSceneHandler::AddSolid(const G4Tubs& tubs)" << endl;
631 outer->addAttValue(
"pickParent",
true);
632 outer->addAttValue(
"showParentAttributes",
true);
650 cout <<
"G4HepRepSceneHandler::AddSolid(const G4Trd& trd)" << endl;
754 cout <<
"G4HepRepSceneHandler::AddPrimitive(G4Polyline&) " << line.size() << endl;
759 static G4bool warned =
false;
763 (
"G4HepRepSceneHandler::AddPrimitive (const G4Polyline&)",
765 "2D polylines not implemented. Ignored.");
781 for (
size_t i=0; i < line.size(); i++) {
791 cout <<
"G4HepRepSceneHandler::AddPrimitive(G4Polymarker&) " << line.size() << endl;
796 static G4bool warned =
false;
800 (
"G4HepRepSceneHandler::AddPrimitive (const G4Polymarker&)",
802 "2D polymarkers not implemented. Ignored.");
822 if (mtype == line.
dots) {
825 }
else if (mtype == line.
circles) {
826 }
else if (mtype == line.
squares) {
833 for (
size_t i=0; i < line.size(); i++) {
842 cout <<
"G4HepRepSceneHandler::AddPrimitive(G4Circle&) " << endl;
847 static G4bool warned =
false;
851 (
"G4HepRepSceneHandler::AddPrimitive (const G4Circle&)",
853 "2D circles not implemented. Ignored.");
878 cout <<
"G4HepRepSceneHandler::AddPrimitive(G4Polyhedron&) " << endl;
883 static G4bool warned =
false;
887 (
"G4HepRepSceneHandler::AddPrimitive (const G4Polyhedron&)",
889 "2D polyhedra not implemented. Ignored.");
905 G4int currentDepth = 0;
934 }
while (notLastEdge);
935 }
while (notLastFace);
941 cout <<
"G4HepRepSceneHandler::AddPrimitive(G4Text&) " << endl;
959 cout <<
"G4HepRepSceneHandler::AddPrimitive G4Text : not yet implemented. " << endl;
965 cout <<
"G4HepRepSceneHandler::AddPrimitive(G4Square&) " << endl;
970 static G4bool warned =
false;
974 (
"G4HepRepSceneHandler::AddPrimitive (const G4Square&)",
976 "2D squares not implemented. Ignored.");
1003 cout <<
"G4HepRepSceneHandler::AddCompound(G4VTrajectory&) " << endl;
1015 cout <<
"G4HepRepSceneHandler::AddCompound(G4VHit&) " << endl;
1031 cout <<
"G4HepRepSceneHandler::PreAddSolid(G4Transform3D&, G4VisAttributes&)" << endl;
1038 cout <<
"G4HepRepSceneHandler::PostAddSolid()" << endl;
1046 cout <<
"G4HepRepSceneHandler::BeginPrimitives(G4Transform3D&)" << endl;
1056 cout <<
"G4HepRepSceneHandler::EndPrimitives" << endl;
1071 cout <<
"G4HepRepSceneHandler::setColor : red : " << color.
GetRed () <<
1072 " green : " << color.
GetGreen () <<
1073 " blue : " << color.
GetBlue () << endl;
1154 addAttVals(instance, hitAttDefs, hitAttValues);
1156 delete hitAttValues;
1174 addAttVals(instance, trajectoryAttDefs, trajectoryAttValues);
1176 delete trajectoryAttValues;
1185 if (point != NULL) {
1192 if (instance != NULL) {
1195 attribute = instance->
getType();
1207 if (point != NULL) {
1214 if (instance != NULL) {
1217 attribute = instance->
getType();
1229 if (point != NULL) {
1236 if (instance != NULL) {
1239 attribute = instance->
getType();
1251 if (point != NULL) {
1258 if (instance != NULL) {
1261 attribute = instance->
getType();
1271 vector<double> color;
1272 if (attValue != NULL) color = attValue->
getColor();
1273 if ((color.size() == 0) ||
1274 (color[0] != red) ||
1275 (color[1] != green) ||
1276 (color[2] != blue) ||
1277 ((color.size() > 3) && (color[3] != alpha))) {
1280 if (point != NULL) {
1287 if (instance != NULL) {
1290 attribute = instance->
getType();
1294 attribute->
addAttValue(name, red, green, blue, alpha);
1299 if (attDefs == NULL)
return;
1302 map<G4String,G4AttDef>::const_iterator attDefIterator = attDefs->begin();
1303 while (attDefIterator != attDefs->end()) {
1304 definition->
addAttDef(attDefIterator->first, attDefIterator->second.GetDesc(),
1305 attDefIterator->second.GetCategory(), attDefIterator->second.GetExtra());
1311 if (attValues == NULL)
return;
1314 for (vector<G4AttValue>::iterator attValIterator = attValues->begin(); attValIterator != attValues->end(); attValIterator++) {
1318 if ((name ==
"Pos") && (point != NULL)) {
1325 for (
unsigned int i=0; i<pos.length(); i++) {
1326 if (pos[i] ==
' ') {
1329 double factor = atof(pos.substr(is, i-is).c_str())/point->
getX();
1330 im = (
int)(std::log10(factor)+((factor < 1) ? -0.5 : 0.5));
1332 }
else if (in == 3) {
1334 unit = pos.substr(is, i-is);
1337 }
else if (unit ==
G4String(
"mm")) {
1339 }
else if (unit ==
G4String(
"cm")) {
1341 }
else if (unit ==
G4String(
"m")) {
1343 }
else if (unit ==
G4String(
"km")) {
1346 cerr <<
"HepRepSceneHandler: Unrecognized Unit: '" << unit <<
"'" << endl;
1370 cerr <<
"HepRepSceneHandler: No valid unit found for im: " << im << endl;
1380 if (name ==
"NTP")
continue;
1383 const map<G4String,G4AttDef>::const_iterator attDefIterator = attDefs->find(name);
1384 G4String type = attDefIterator->second.GetValueType();
1387 if ((type ==
"G4double") || (type ==
"double")) {
1388 setAttribute(attribute, attValIterator->GetName(), atof(attValIterator->GetValue()));
1389 }
else if ((type ==
"G4int") || (type ==
"int")) {
1390 setAttribute(attribute, attValIterator->GetName(), atoi(attValIterator->GetValue()));
1392 setAttribute(attribute, attValIterator->GetName(), attValIterator->GetValue());
1407 type->
addAttDef(
"Generator",
"Generator of the file",
"General",
"");
1410 type->
addAttDef(
"GeneratorVersion",
"Version of the Generator",
"General",
"");
1412 versionString = versionString.substr(1,versionString.size()-2);
1413 versionString =
" Geant4 version " + versionString +
" " +
G4Date;
1414 type->
addAttValue(
"GeneratorVersion", versionString);
1418 type->
addAttDef(
"ViewTheta",
"Theta of initial suggested viewpoint",
"Draw",
"rad");
1421 type->
addAttDef(
"ViewPhi",
"Phi of initial suggested viewpoint",
"Draw",
"rad");
1424 type->
addAttDef(
"ViewScale",
"Scale of initial suggested viewpoint",
"Draw",
"");
1428 type->
addAttDef(
"ViewTranslateX",
"Translate in X of initial suggested viewpoint",
"Draw",
"");
1431 type->
addAttDef(
"ViewTranslateY",
"Translate in Y of initial suggested viewpoint",
"Draw",
"");
1434 type->
addAttDef(
"ViewTranslateZ",
"Translate in Z of initial suggested viewpoint",
"Draw",
"");
1437 type->
addAttDef(
"PointUnit",
"Length",
"Physics",
"");
1442 type->
addAttDef(
"UseSolids",
"Use HepRep Solids rather than Geant4 Primitives",
"Draw",
"");
1445 type->
addAttDef(
"WriteInvisibles",
"Write Invisible Objects",
"Draw",
"");
1632 G4String problem =
"HierarchyProblem";
1638 return "/" + problem +
"/" + volumeName;
1648 name = name +
"/" + volumeName;
const G4String & GetName() const
void AddCompound(const G4VTrajectory &)
HEPREP::HepRepType * _eventType
HEPREP::HepRepInstance * getGeometryInstance(G4LogicalVolume *volume, G4Material *material, int depth)
void setMarker(HEPREP::HepRepAttribute *attribute, const G4VMarker &marker)
G4double GetYHalfLength() const
G4double GetInnerRadiusMinusZ() const
virtual HepRepPoint * createHepRepPoint(HepRepInstance *instance, double x, double y, double z)=0
const G4Colour & GetColor()
virtual std::vector< G4AttValue > * CreateAttValues() const
HEPREP::HepRepType * getCalHitType()
system("rm -rf microbeam.root")
HEPREP::HepRep * getHepRep()
static const G4double pos
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
void addAttDefs(HEPREP::HepRepDefinition *definition, const std::map< G4String, G4AttDef > *attDefs)
virtual HepRepAttValue * getAttValue(std::string name)=0
virtual void addTypeTree(HepRepTypeTree *typeTree)=0
G4VViewer * GetCurrentViewer() const
G4bool fReadyForTransients
const XML_Char const XML_Char ** atts
virtual int getInteger()=0
const G4VisAttributes * GetVisAttributes() const
void removeSceneHandler()
virtual HepRepAttValue * getAttValueFromNode(std::string lowerCaseName)=0
G4double GetRadlen() const
HEPREP::HepRepInstance * _geometryRootInstance
void setVisibility(HEPREP::HepRepAttribute *attribute, const G4VSolid &solid)
virtual void addInstanceTree(HepRepInstanceTree *instanceTree)=0
virtual std::string getName()=0
virtual std::vector< G4AttValue > * CreateAttValues() const
static G4int sceneIdCount
G4HepRepSceneHandler(G4VGraphicsSystem &system, const G4String &name="")
std::vector< G4String > _geometryTypeName
virtual HepRepType * createHepRepType(HepRepTypeTree *parent, std::string name)=0
G4Color getColorFor(const G4Visible &visible)
const G4ViewParameters & GetViewParameters() const
virtual void addLayer(std::string layer)=0
G4double GetOuterRadiusMinusZ() const
G4double GetDeltaPhiAngle() const
G4double GetOuterRadiusPlusZ() const
HEPREP::HepRepType * _calHitFaceType
virtual void DrawView()=0
G4double GetZHalfLength() const
G4double GetYHalfLength2() const
G4double GetZHalfLength() const
virtual HepRepInstance * createHepRepInstance(HepRepInstance *parent, HepRepType *type)=0
void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &visAttribs)
G4double GetXHalfLength1() const
virtual G4bool writeInvisibles()
static const G4String G4Date
const G4String & GetName() const
G4double GetZoomFactor() const
G4String getFullTypeName(G4String volumeName, int depth)
const G4Vector3D & GetViewpointDirection() const
virtual void AddCompound(const G4VTrajectory &)
std::vector< HEPREP::HepRepInstance * > _geometryInstance
void openFile(G4String name)
const G4VTrajectory * currentTrack
HEPREP::HepRepInstanceTree * _eventInstanceTree
virtual G4bool useSolids()
virtual HepRepTreeID * createHepRepTreeID(std::string name, std::string version, std::string qualifier="top-level")=0
const XML_Char int const XML_Char * value
virtual void PostAddSolid()
HEPREP::HepRepInstanceTree * getEventInstanceTree()
G4double GetInnerRadius() const
HEPREP::HepRep * _heprepGeometry
virtual void BeginModeling()
G4String getParentTypeName(int currentDepth)
void addAttVals(HEPREP::HepRepAttribute *attribute, const std::map< G4String, G4AttDef > *attDefs, std::vector< G4AttValue > *attValues)
virtual HepRepInstanceTree * createHepRepInstanceTree(std::string name, std::string version, HepRepTreeID *typeTree)=0
HEPREP::HepRepTypeTree * _geometryTypeTree
static const G4double alpha
static constexpr double twopi
HEPREP::HepRepType * getCalHitFaceType()
static const G4String G4Version
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
virtual G4String getEventNumberSuffix()
G4double GetLineWidth() const
bool closeHepRep(bool final=false)
HEPREP::HepRepType * _trajectoryType
HEPREP::HepRepType * getGeometryRootType()
HEPREP::HepRepTypeTree * _eventTypeTree
void addTopLevelAttributes(HEPREP::HepRepType *type)
virtual std::string getString()=0
G4bool GetNextVertex(G4Point3D &vertex, G4int &edgeFlag) const
virtual void addAttValue(HepRepAttValue *attValue)=0
G4double GetInnerRadiusPlusZ() const
virtual HepRepTypeTree * createHepRepTypeTree(HepRepTreeID *treeID)=0
G4double GetZHalfLength() const
HEPREP::HepRep * getHepRepGeometry()
HEPREP::HepRepType * getGeometryType(G4String volumeName, int depth)
void setAttribute(HEPREP::HepRepAttribute *attribute, G4String name, char *value)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
G4double GetXHalfLength() const
virtual void EndModeling()
void AddPrimitive(const G4Polyline &)
G4double GetYHalfLength1() const
const G4VHit * currentHit
G4LogicalVolume * GetCurrentLV() const
G4bool IsRootRegion() const
virtual G4bool appendGeometry()
HEPREP::HepRepInstanceTree * getGeometryInstanceTree()
void setLine(HEPREP::HepRepAttribute *attribute, const G4VSolid &solid)
const G4VisAttributes * fpVisAttribs
virtual HepRepWriter * createHepRepWriter(std::ostream *out, bool randomAccess, bool compress)=0
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
HEPREP::HepRepTypeTree * getGeometryTypeTree()
G4Material * GetCurrentMaterial() const
G4int GetCurrentDepth() const
HEPREP::HepRepInstance * getEventInstance()
static G4HepRepMessenger * GetInstance()
virtual void AddSolid(const G4Box &)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
virtual void addAttDef(std::string name, std::string desc, std::string category, std::string extra)=0
void addAttributes(HEPREP::HepRepInstance *instance, HEPREP::HepRepType *type)
G4bool GetNextNormal(G4Normal3D &normal) const
G4double GetMarkerRadius(const G4VMarker &, MarkerSizeType &)
G4String eventNumberSuffix
HEPREP::HepRepType * getTrajectoryType()
HEPREP::HepRepWriter * writer
virtual ~G4HepRepSceneHandler()
HEPREP::HepRepInstance * _eventInstance
virtual void AddPrimitive(const G4Polyline &)=0
HEPREP::HepRepType * _calHitType
HEPREP::HepRepTypeTree * getEventTypeTree()
G4VGraphicsSystem * GetGraphicsSystem() const
static MCTruthManager * instance
G4double GetXHalfLength2() const
G4double GetDeltaPhiAngle() const
HEPREP::HepRepType * getEventType()
void BeginPrimitives(const G4Transform3D &objectTransformation)
G4double GetAlpha() const
std::map< int, G4String > materialState
HEPREP::HepRepInstanceTree * _geometryInstanceTree
virtual bool addProperty(std::string key, std::string value)=0
G4double GetOuterRadius() const
G4VSolid * GetSolid() const
FillStyle GetFillStyle() const
virtual std::vector< double > getColor()=0
G4Point3D GetPosition() const
G4double GetGreen() const
void setColor(HEPREP::HepRepAttribute *attribute, const G4Color &color, const G4String &key=G4String("Color"))
HEPREP::HepRepFactory * factory
virtual HepRepInstance * getInstance()=0
HEPREP::HepRepInstance * getGeometryRootInstance()
virtual bool write(HepRep *heprep, std::string name)=0
G4int GetNoFacets() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual HepRepType * getType()=0
virtual HepRep * createHepRep()=0
virtual void addInstanceTree(HepRepTreeID *instanceTree)=0
virtual G4GeometryType GetEntityType() const =0
std::map< G4String, HEPREP::HepRepType * > _geometryType
HEPREP::HepRepType * getHitType()
HEPREP::HepRepType * _geometryRootType
void AddSolid(const G4Box &box)
HepGeom::Point3D< G4double > G4Point3D
LineStyle GetLineStyle() const
virtual double getDouble()=0
MarkerType GetMarkerType() const
G4double GetZHalfLength() const
G4String eventNumberPrefix
G4Region * GetRegion() const
HEPREP::HepRepInstance * getGeometryOrEventInstance(HEPREP::HepRepType *type)
G4bool writeMultipleFiles
void writeLayers(HEPREP::HepRep *heprep)
virtual void EndPrimitives()
G4Scene * GetScene() const
const G4String & GetName() const
G4double GetDensity() const
virtual bool getBoolean()=0
HEPREP::HepRepType * _hitType