ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
load_gdml.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file load_gdml.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 //
30 //
31 //
32 // --------------------------------------------------------------
33 // GEANT 4 - load_gdml
34 //
35 // --------------------------------------------------------------
36 
37 #include <vector>
38 
39 #include "G4Types.hh"
40 
41 #ifdef G4MULTITHREADED
42 #include "G4MTRunManager.hh"
43 #else
44 #include "G4RunManager.hh"
45 #endif
46 
47 #include "G4UImanager.hh"
48 
49 #include "G4LogicalVolumeStore.hh"
51 
55 
56 #include "FTFP_BERT.hh"
57 
58 #include "G4VisExecutive.hh"
59 #include "G4UIExecutive.hh"
60 
61 #include "G4GDMLParser.hh"
62 
63 void print_aux(const G4GDMLAuxListType* auxInfoList, G4String prepend="|")
64 {
65  for(std::vector<G4GDMLAuxStructType>::const_iterator
66  iaux = auxInfoList->begin(); iaux != auxInfoList->end(); iaux++ )
67  {
68  G4String str=iaux->type;
69  G4String val=iaux->value;
70  G4String unit=iaux->unit;
71 
72  G4cout << prepend << str << " : " << val << " " << unit << G4endl;
73 
74  if (iaux->auxList) print_aux(iaux->auxList, prepend + "|");
75  }
76  return;
77 }
78 
79 // --------------------------------------------------------------
80 
81 int main(int argc,char **argv)
82 {
83  G4cout << G4endl;
84  G4cout << "Usage: load_gdml <intput_gdml_file:mandatory>"
85  << " <output_gdml_file:optional>" << G4endl;
86  G4cout << G4endl;
87 
88  if (argc<2)
89  {
90  G4cout << "Error! Mandatory input file is not specified!" << G4endl;
91  G4cout << G4endl;
92  return -1;
93  }
94 
96 
97 // Uncomment the following if wish to avoid names stripping
98 // parser.SetStripFlag(false);
99 
100  parser.SetOverlapCheck(true);
101  parser.Read(argv[1]);
102 
103  if (argc>4)
104  {
105  G4cout << "Error! Too many arguments!" << G4endl;
106  G4cout << G4endl;
107  return -1;
108  }
109 
110 #ifdef G4MULTITHREADED
111  G4MTRunManager* runManager = new G4MTRunManager;
112 #else
113  G4RunManager* runManager = new G4RunManager;
114 #endif
115 
117  parser.GetWorldVolume()));
118  runManager->SetUserInitialization(new FTFP_BERT);
120 
121  runManager->Initialize();
122 
123  // Initialize visualization
124  G4VisManager* visManager = new G4VisExecutive;
125  visManager->Initialize();
126 
127  // Get the pointer to the User Interface manager
128  G4UImanager* UImanager = G4UImanager::GetUIpointer();
129 
131  //
132  // Example how to retrieve Auxiliary Information
133  //
134 
135  G4cout << std::endl;
136 
138  std::vector<G4LogicalVolume*>::const_iterator lvciter;
139  for( lvciter = lvs->begin(); lvciter != lvs->end(); lvciter++ )
140  {
141  G4GDMLAuxListType auxInfo = parser.GetVolumeAuxiliaryInformation(*lvciter);
142 
143  if (auxInfo.size()>0)
144  G4cout << "Auxiliary Information is found for Logical Volume : "
145  << (*lvciter)->GetName() << G4endl;
146 
147  print_aux(&auxInfo);
148  }
149 
150  // now the 'global' auxiliary info
151  G4cout << std::endl;
152  G4cout << "Global auxiliary info:" << std::endl;
153  G4cout << std::endl;
154 
155  print_aux(parser.GetAuxList());
156 
157  G4cout << std::endl;
158 
159  //
160  // End of Auxiliary Information block
161  //
163 
164 
165  runManager->BeamOn(0);
166 
167  // example of writing out
168 
169  if (argc>=3)
170  {
171 /*
172  G4GDMLAuxStructType mysubaux = {"mysubtype", "mysubvalue", "mysubunit", 0};
173  G4GDMLAuxListType* myauxlist = new G4GDMLAuxListType();
174  myauxlist->push_back(mysubaux);
175 
176  G4GDMLAuxStructType myaux = {"mytype", "myvalue", "myunit", myauxlist};
177  parser.AddAuxiliary(myaux);
178 
179 
180  // example of setting auxiliary info for world volume
181  // (can be set for any volume)
182 
183  G4GDMLAuxStructType mylocalaux = {"sometype", "somevalue", "someunit", 0};
184 
185  parser.AddVolumeAuxiliary(mylocalaux,
186  G4TransportationManager::GetTransportationManager()
187  ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
188 */
189 
190  parser.SetRegionExport(true);
191  // parser.SetEnergyCutsExport(true);
193  ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
194  }
195 
196 
197  if (argc==4) // batch mode
198  {
199  G4String command = "/control/execute ";
200  G4String fileName = argv[3];
201  UImanager->ApplyCommand(command+fileName);
202  }
203  else // interactive mode
204  {
205  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
206  UImanager->ApplyCommand("/control/execute vis.mac");
207  ui->SessionStart();
208  delete ui;
209  }
210 
211  delete visManager;
212  delete runManager;
213 
214  return 0;
215 }