File indexing completed on 2025-08-06 08:19:14
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 using namespace std;
0032
0033 void PHG4GDMLUtility::Dump_GDML(const std::string &filename, G4VPhysicalVolume *vol, PHCompositeNode *topNode)
0034 {
0035 if (topNode == nullptr)
0036 {
0037 Fun4AllServer *se = Fun4AllServer::instance();
0038 topNode = se->topNode();
0039 }
0040
0041 const PHG4GDMLConfig *config =
0042 GetOrMakeConfigNode(topNode);
0043 assert(config);
0044
0045 PHG4GDMLWriteStructure gdml_parser(config);
0046 assert(vol);
0047 assert(vol->GetLogicalVolume());
0048
0049 xercesc::XMLPlatformUtils::Initialize();
0050 gdml_parser.Write(filename, vol->GetLogicalVolume(), get_PHG4GDML_Schema(), 0, true);
0051 xercesc::XMLPlatformUtils::Terminate();
0052 }
0053
0054 void PHG4GDMLUtility::Dump_G4_GDML(const std::string &filename, G4VPhysicalVolume *vol)
0055 {
0056
0057 G4GDMLWriteStructure gdml_parser;
0058 assert(vol);
0059 assert(vol->GetLogicalVolume());
0060
0061 xercesc::XMLPlatformUtils::Initialize();
0062 gdml_parser.Write(filename, vol->GetLogicalVolume(), get_PHG4GDML_Schema(), 0, true);
0063 xercesc::XMLPlatformUtils::Terminate();
0064 }
0065
0066 PHG4GDMLConfig *PHG4GDMLUtility::GetOrMakeConfigNode(PHCompositeNode *topNode, bool build_new)
0067 {
0068 PHNodeIterator iter(topNode);
0069
0070
0071 PHCompositeNode *parNode = static_cast<PHCompositeNode *>(iter.findFirst(
0072 "PHCompositeNode", "PAR"));
0073 if (!parNode)
0074 {
0075 stringstream serr;
0076 serr << __PRETTY_FUNCTION__ << ": PAR Node missing, request aborting.";
0077 cout << serr.str() << endl;
0078
0079 throw runtime_error(serr.str());
0080
0081 return nullptr;
0082 }
0083
0084 PHG4GDMLConfig *config = findNode::getClass<PHG4GDMLConfig>(parNode,
0085 getDSTNodeName());
0086 if (!config and build_new)
0087 {
0088 config = new PHG4GDMLConfig();
0089 PHDataNode<PHObject> *node = new PHDataNode<PHObject>(config,
0090 getDSTNodeName(), "PHObject");
0091 parNode->addNode(node);
0092 }
0093
0094 return config;
0095 }