Geant4  10.02.p03
load_gdml.cc File Reference

Main program of the persistency/gdml/G01 example. More...

#include <vector>
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4TransportationManager.hh"
#include "G01PrimaryGeneratorAction.hh"
#include "G01DetectorConstruction.hh"
#include "FTFP_BERT.hh"
#include "G4GDMLParser.hh"
Include dependency graph for load_gdml.cc:

Go to the source code of this file.

Functions

void print_aux (const G4GDMLAuxListType *auxInfoList, G4String prepend="|")
 
int main (int argc, char **argv)
 

Detailed Description

Main program of the persistency/gdml/G01 example.

Definition in file load_gdml.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 77 of file load_gdml.cc.

78 {
79  G4cout << G4endl;
80  G4cout << "Usage: load_gdml <intput_gdml_file:mandatory>"
81  << " <output_gdml_file:optional>" << G4endl;
82  G4cout << G4endl;
83 
84  if (argc<2)
85  {
86  G4cout << "Error! Mandatory input file is not specified!" << G4endl;
87  G4cout << G4endl;
88  return -1;
89  }
90 
92 
93 // Uncomment the following if wish to avoid names stripping
94 // parser.SetStripFlag(false);
95 
96  parser.Read(argv[1]);
97 
98  if (argc>4)
99  {
100  G4cout << "Error! Too many arguments!" << G4endl;
101  G4cout << G4endl;
102  return -1;
103  }
104 
105  G4RunManager* runManager = new G4RunManager;
106 
108  parser.GetWorldVolume()));
109  runManager->SetUserInitialization(new FTFP_BERT);
110  runManager->SetUserAction(new G01PrimaryGeneratorAction);
111 
112  runManager->Initialize();
113 
114  G4UImanager* UImanager = G4UImanager::GetUIpointer();
115 
117  //
118  // Example how to retrieve Auxiliary Information
119  //
120 
121  std::cout << std::endl;
122 
124  std::vector<G4LogicalVolume*>::const_iterator lvciter;
125  for( lvciter = lvs->begin(); lvciter != lvs->end(); lvciter++ )
126  {
127  G4GDMLAuxListType auxInfo = parser.GetVolumeAuxiliaryInformation(*lvciter);
128 
129  if (auxInfo.size()>0)
130  G4cout << "Auxiliary Information is found for Logical Volume : "
131  << (*lvciter)->GetName() << G4endl;
132 
133  print_aux(&auxInfo);
134  }
135 
136  // now the 'global' auxiliary info
137  std::cout << std::endl;
138  std::cout << "Global auxiliary info:" << std::endl;
139  std::cout << std::endl;
140 
141  print_aux(parser.GetAuxList());
142 
143  std::cout << std::endl;
144 
145  //
146  // End of Auxiliary Information block
147  //
149 
150  // example of writing out
151 
152  if (argc>=3)
153  {
154 /*
155  G4GDMLAuxStructType mysubaux = {"mysubtype", "mysubvalue", "mysubunit", 0};
156  G4GDMLAuxListType* myauxlist = new G4GDMLAuxListType();
157  myauxlist->push_back(mysubaux);
158 
159  G4GDMLAuxStructType myaux = {"mytype", "myvalue", "myunit", myauxlist};
160  parser.AddAuxiliary(myaux);
161 
162 
163  // example of setting auxiliary info for world volume (can be set for any volume)
164 
165  G4GDMLAuxStructType mylocalaux = {"sometype", "somevalue", "someunit", 0};
166 
167  parser.AddVolumeAuxiliary(mylocalaux, G4TransportationManager::GetTransportationManager()
168  ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
169 */
170  parser.SetRegionExport(true);
172  ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
173  }
174 
175 
176  if (argc==4) // batch mode
177  {
178  G4String command = "/control/execute ";
179  G4String fileName = argv[3];
180  UImanager->ApplyCommand(command+fileName);
181  }
182  else // interactive mode
183  {
184 #ifdef G4UI_USE
185  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
186 #ifdef G4VIS_USE
187  G4VisManager* visManager = new G4VisExecutive;
188  visManager->Initialize();
189  UImanager->ApplyCommand("/control/execute vis.mac");
190 #endif
191  ui->SessionStart();
192 #ifdef G4VIS_USE
193  delete visManager;
194 #endif
195  delete ui;
196 #endif
197  }
198 
199  delete runManager;
200 
201  return 0;
202 }
Minimal primary generator action to demonstrate the use of GDML geometries.
const G4GDMLAuxListType * GetAuxList() const
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
G4GDMLAuxListType GetVolumeAuxiliaryInformation(G4LogicalVolume *lvol) const
Detector construction allowing to use the geometry read from the GDML file.
void SetRegionExport(G4bool)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
static G4LogicalVolumeStore * GetInstance()
void Write(const G4String &filename, const G4VPhysicalVolume *pvol=0, G4bool storeReferences=true, const G4String &SchemaLocation=G4GDML_DEFAULT_SCHEMALOCATION)
CommandLineParser * parser(0)
void print_aux(const G4GDMLAuxListType *auxInfoList, G4String prepend="|")
Definition: load_gdml.cc:60
G4VPhysicalVolume * GetWorldVolume(const G4String &setupName="Default") const
static G4TransportationManager * GetTransportationManager()
void Initialize()
std::vector< G4GDMLAuxStructType > G4GDMLAuxListType
void Read(const G4String &filename, G4bool Validate=true)
virtual void Initialize()
#define G4endl
Definition: G4ios.hh:61
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:446
virtual void SetUserAction(G4UserRunAction *userAction)
Here is the call graph for this function:

◆ print_aux()

void print_aux ( const G4GDMLAuxListType auxInfoList,
G4String  prepend = "|" 
)

Definition at line 60 of file load_gdml.cc.

61 {
62  for(std::vector<G4GDMLAuxStructType>::const_iterator iaux = auxInfoList->begin();
63  iaux != auxInfoList->end(); iaux++ )
64  {
65  G4String str=iaux->type;
66  G4String val=iaux->value;
67  G4String unit=iaux->unit;
68 
69  G4cout << prepend << str << " : " << val << " " << unit << G4endl;
70 
71  if (iaux->auxList) print_aux(iaux->auxList, prepend + "|");
72  }
73  return;
74 }
G4GLOB_DLL std::ostream G4cout
void print_aux(const G4GDMLAuxListType *auxInfoList, G4String prepend="|")
Definition: load_gdml.cc:60
#define G4endl
Definition: G4ios.hh:61
Here is the caller graph for this function: