File indexing completed on 2025-12-17 09:21:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "PHG4GDMLUtility.hh"
0012 #include "PHG4GDMLConfig.hh"
0013 #include "PHG4GDMLWriteStructure.hh"
0014
0015 #include <fun4all/Fun4AllServer.h>
0016
0017 #include <phool/PHCompositeNode.h>
0018 #include <phool/PHDataNode.h>
0019 #include <phool/PHNodeIterator.h>
0020 #include <phool/PHObject.h> // for PHObject
0021 #include <phool/getClass.h>
0022
0023 #include <Geant4/G4VPhysicalVolume.hh>
0024 #include <Geant4/G4GDMLWriteStructure.hh>
0025
0026 #include <cassert>
0027 #include <iostream> // for operator<<, stringstream
0028 #include <sstream>
0029 #include <stdexcept>
0030
0031 void PHG4GDMLUtility::Dump_GDML(const std::string &filename, G4VPhysicalVolume *vol, PHCompositeNode *topNode)
0032 {
0033 if (topNode == nullptr)
0034 {
0035 Fun4AllServer *se = Fun4AllServer::instance();
0036 topNode = se->topNode();
0037 }
0038
0039 const PHG4GDMLConfig *config =
0040 GetOrMakeConfigNode(topNode);
0041 assert(config);
0042
0043 PHG4GDMLWriteStructure gdml_parser(config);
0044 assert(vol);
0045 assert(vol->GetLogicalVolume());
0046
0047 xercesc::XMLPlatformUtils::Initialize();
0048 gdml_parser.Write(filename, vol->GetLogicalVolume(), get_PHG4GDML_Schema(), 0, true);
0049 xercesc::XMLPlatformUtils::Terminate();
0050 }
0051
0052 void PHG4GDMLUtility::Dump_G4_GDML(const std::string &filename, G4VPhysicalVolume *vol)
0053 {
0054
0055 G4GDMLWriteStructure gdml_parser;
0056 assert(vol);
0057 assert(vol->GetLogicalVolume());
0058
0059 xercesc::XMLPlatformUtils::Initialize();
0060 gdml_parser.Write(filename, vol->GetLogicalVolume(), get_PHG4GDML_Schema(), 0, true);
0061 xercesc::XMLPlatformUtils::Terminate();
0062 }
0063
0064 PHG4GDMLConfig *PHG4GDMLUtility::GetOrMakeConfigNode(PHCompositeNode *topNode, bool build_new)
0065 {
0066 PHNodeIterator iter(topNode);
0067
0068
0069 PHCompositeNode *parNode = static_cast<PHCompositeNode *>(iter.findFirst(
0070 "PHCompositeNode", "PAR"));
0071 if (!parNode)
0072 {
0073 std::stringstream serr;
0074 serr << __PRETTY_FUNCTION__ << ": PAR Node missing, request aborting.";
0075 std::cout << serr.str() << std::endl;
0076
0077 throw std::runtime_error(serr.str());
0078
0079 return nullptr;
0080 }
0081
0082 PHG4GDMLConfig *config = findNode::getClass<PHG4GDMLConfig>(parNode,
0083 getDSTNodeName());
0084 if (!config && build_new)
0085 {
0086 config = new PHG4GDMLConfig();
0087 PHDataNode<PHObject> *node = new PHDataNode<PHObject>(config,
0088 getDSTNodeName(), "PHObject");
0089 parNode->addNode(node);
0090 }
0091
0092 return config;
0093 }