ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4GDMLUtility.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4GDMLUtility.cc
1 // $Id: $
2 
11 #include "PHG4GDMLUtility.hh"
12 #include "PHG4GDMLConfig.hh"
14 
15 #include <fun4all/Fun4AllServer.h>
16 
17 #include <phool/PHCompositeNode.h>
18 #include <phool/PHDataNode.h>
19 #include <phool/PHNodeIterator.h>
20 #include <phool/PHObject.h> // for PHObject
21 #include <phool/getClass.h>
22 
23 #include <Geant4/G4VPhysicalVolume.hh>
24 #include <Geant4/G4GDMLWriteStructure.hh>
25 
26 #include <cassert>
27 #include <iostream> // for operator<<, stringstream
28 #include <sstream>
29 #include <stdexcept>
30 
31 using namespace std;
32 
33 void PHG4GDMLUtility::Dump_GDML(const std::string &filename, G4VPhysicalVolume *vol, PHCompositeNode *topNode)
34 {
35  if (topNode == nullptr)
36  {
38  topNode = se->topNode();
39  }
40 
41  const PHG4GDMLConfig *config =
42  GetOrMakeConfigNode(topNode);
43  assert(config);
44 
46  assert(vol);
47  assert(vol->GetLogicalVolume());
48 
50  gdml_parser.Write(filename, vol->GetLogicalVolume(), get_PHG4GDML_Schema(), 0, true);
51  xercesc::XMLPlatformUtils::Terminate();
52 }
53 
55 {
56 
58  assert(vol);
59  assert(vol->GetLogicalVolume());
60 
62  gdml_parser.Write(filename, vol->GetLogicalVolume(), get_PHG4GDML_Schema(), 0, true);
63  xercesc::XMLPlatformUtils::Terminate();
64 }
65 
67 {
68  PHNodeIterator iter(topNode);
69 
70  // Looking for the RUN node
71  PHCompositeNode *parNode = static_cast<PHCompositeNode *>(iter.findFirst(
72  "PHCompositeNode", "PAR"));
73  if (!parNode)
74  {
75  stringstream serr;
76  serr << __PRETTY_FUNCTION__ << ": PAR Node missing, request aborting.";
77  cout << serr.str() << endl;
78 
79  throw runtime_error(serr.str());
80 
81  return nullptr;
82  }
83 
84  PHG4GDMLConfig *config = findNode::getClass<PHG4GDMLConfig>(parNode,
85  getDSTNodeName());
86  if (!config and build_new)
87  {
88  config = new PHG4GDMLConfig();
90  getDSTNodeName(), "PHObject");
91  parNode->addNode(node);
92  }
93 
94  return config;
95 }