Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 /// \file persistency/gdml/G01/load_gdml.cc 26 /// \file persistency/gdml/G01/load_gdml.cc 27 /// \brief Main program of the persistency/gdm 27 /// \brief Main program of the persistency/gdml/G01 example 28 // 28 // 29 // 29 // >> 30 // $Id: load_gdml.cc 89264 2015-03-30 08:18:11Z gcosmo $ 30 // 31 // 31 // 32 // 32 // ------------------------------------------- 33 // -------------------------------------------------------------- 33 // GEANT 4 - load_gdml 34 // GEANT 4 - load_gdml 34 // 35 // 35 // ------------------------------------------- 36 // -------------------------------------------------------------- 36 37 37 #include "FTFP_BERT.hh" << 38 #include <vector> 38 #include "G01ActionInitialization.hh" << 39 39 #include "G01DetectorConstruction.hh" << 40 #include "G4RunManager.hh" 40 #include "G01PrimaryGeneratorAction.hh" << 41 #include "G4UImanager.hh" 41 42 42 #include "G4GDMLParser.hh" << 43 #include "G4LogicalVolumeStore.hh" 43 #include "G4LogicalVolumeStore.hh" 44 #include "G4RunManagerFactory.hh" << 45 #include "G4TransportationManager.hh" 44 #include "G4TransportationManager.hh" 46 #include "G4Types.hh" << 45 47 #include "G4UIExecutive.hh" << 46 #include "G01PrimaryGeneratorAction.hh" 48 #include "G4UImanager.hh" << 47 #include "G01DetectorConstruction.hh" >> 48 #include "FTFP_BERT.hh" >> 49 >> 50 #ifdef G4VIS_USE 49 #include "G4VisExecutive.hh" 51 #include "G4VisExecutive.hh" >> 52 #endif 50 53 51 #include <vector> << 54 #ifdef G4UI_USE >> 55 #include "G4UIExecutive.hh" >> 56 #endif 52 57 53 void print_aux(const G4GDMLAuxListType* auxInf << 58 #include "G4GDMLParser.hh" 54 { << 55 for (std::vector<G4GDMLAuxStructType>::const << 56 iaux != auxInfoList->end(); iaux++) << 57 { << 58 G4String str = iaux->type; << 59 G4String val = iaux->value; << 60 G4String unit = iaux->unit; << 61 59 62 G4cout << prepend << str << " : " << val < << 60 void print_aux(const G4GDMLAuxListType* auxInfoList, G4String prepend="|") >> 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; 63 70 64 if (iaux->auxList) print_aux(iaux->auxList << 71 if (iaux->auxList) print_aux(iaux->auxList, prepend + "|"); 65 } << 72 } 66 return; 73 return; 67 } 74 } 68 75 69 // ------------------------------------------- << 70 76 71 int main(int argc, char** argv) << 77 int main(int argc,char **argv) 72 { 78 { 73 G4cout << G4endl; << 79 G4cout << G4endl; 74 G4cout << "Usage: load_gdml <intput_gdml_fil << 80 G4cout << "Usage: load_gdml <intput_gdml_file:mandatory>" 75 << " <output_gdml_file:optional>" << << 81 << " <output_gdml_file:optional>" << G4endl; 76 G4cout << G4endl; << 82 G4cout << G4endl; 77 << 83 78 if (argc < 2) { << 84 if (argc<2) 79 G4cout << "Error! Mandatory input file is << 85 { 80 G4cout << G4endl; << 86 G4cout << "Error! Mandatory input file is not specified!" << G4endl; 81 return -1; << 87 G4cout << G4endl; 82 } << 88 return -1; 83 << 89 } 84 G4GDMLParser parser; << 90 85 << 91 G4GDMLParser parser; 86 // Uncomment the following if wish to avoid << 92 87 // parser.SetStripFlag(false); << 93 // Uncomment the following if wish to avoid names stripping 88 << 94 // parser.SetStripFlag(false); 89 // Uncomment the following and set a string << 95 90 // schema filename if wishing to use alterna << 96 parser.Read(argv[1]); 91 // parser.SetImportSchema(""); << 97 92 << 98 if (argc>4) 93 parser.SetOverlapCheck(true); << 99 { 94 parser.Read(argv[1]); << 100 G4cout << "Error! Too many arguments!" << G4endl; 95 << 101 G4cout << G4endl; 96 if (argc > 4) { << 102 return -1; 97 G4cout << "Error! Too many arguments!" << << 103 } 98 G4cout << G4endl; << 104 99 return -1; << 105 G4RunManager* runManager = new G4RunManager; 100 } << 106 101 << 107 runManager->SetUserInitialization(new G01DetectorConstruction( 102 auto* runManager = G4RunManagerFactory::Crea << 108 parser.GetWorldVolume())); 103 << 109 runManager->SetUserInitialization(new FTFP_BERT); 104 runManager->SetUserInitialization(new G01Det << 110 runManager->SetUserAction(new G01PrimaryGeneratorAction); 105 runManager->SetUserInitialization(new FTFP_B << 111 106 runManager->SetUserInitialization(new G01Act << 112 runManager->Initialize(); 107 << 113 108 runManager->Initialize(); << 114 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 109 << 115 110 // Initialize visualization << 116 /////////////////////////////////////////////////////////////////////// 111 G4VisManager* visManager = new G4VisExecutiv << 117 // 112 visManager->Initialize(); << 118 // Example how to retrieve Auxiliary Information 113 << 119 // 114 // Get the pointer to the User Interface man << 120 115 G4UImanager* UImanager = G4UImanager::GetUIp << 121 std::cout << std::endl; 116 << 122 117 //////////////////////////////////////////// << 123 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance(); 118 // << 124 std::vector<G4LogicalVolume*>::const_iterator lvciter; 119 // Example how to retrieve Auxiliary Informa << 125 for( lvciter = lvs->begin(); lvciter != lvs->end(); lvciter++ ) 120 // << 126 { 121 << 127 G4GDMLAuxListType auxInfo = parser.GetVolumeAuxiliaryInformation(*lvciter); 122 G4cout << std::endl; << 128 123 << 129 if (auxInfo.size()>0) 124 const G4LogicalVolumeStore* lvs = G4LogicalV << 130 G4cout << "Auxiliary Information is found for Logical Volume : " 125 std::vector<G4LogicalVolume*>::const_iterato << 131 << (*lvciter)->GetName() << G4endl; 126 for (lvciter = lvs->begin(); lvciter != lvs- << 132 127 G4GDMLAuxListType auxInfo = parser.GetVolu << 133 print_aux(&auxInfo); 128 << 134 } 129 if (auxInfo.size() > 0) << 135 130 G4cout << "Auxiliary Information is foun << 136 // now the 'global' auxiliary info 131 << G4endl; << 137 std::cout << std::endl; 132 << 138 std::cout << "Global auxiliary info:" << std::endl; 133 print_aux(&auxInfo); << 139 std::cout << std::endl; 134 } << 140 135 << 141 print_aux(parser.GetAuxList()); 136 // now the 'global' auxiliary info << 142 137 G4cout << std::endl; << 143 std::cout << std::endl; 138 G4cout << "Global auxiliary info:" << std::e << 144 139 G4cout << std::endl; << 145 // 140 << 146 // End of Auxiliary Information block 141 print_aux(parser.GetAuxList()); << 147 // 142 << 148 //////////////////////////////////////////////////////////////////////// 143 G4cout << std::endl; << 149 144 << 150 // example of writing out 145 // << 151 146 // End of Auxiliary Information block << 152 if (argc>=3) 147 // << 153 { 148 //////////////////////////////////////////// << 154 /* 149 << 155 G4GDMLAuxStructType mysubaux = {"mysubtype", "mysubvalue", "mysubunit", 0}; 150 runManager->BeamOn(0); << 156 G4GDMLAuxListType* myauxlist = new G4GDMLAuxListType(); 151 << 157 myauxlist->push_back(mysubaux); 152 // example of writing out << 158 153 << 159 G4GDMLAuxStructType myaux = {"mytype", "myvalue", "myunit", myauxlist}; 154 if (argc >= 3) { << 160 parser.AddAuxiliary(myaux); 155 /* << 161 156 G4GDMLAuxStructType mysubaux = {"mysu << 162 157 G4GDMLAuxListType* myauxlist = new G4 << 163 // example of setting auxiliary info for world volume (can be set for any volume) 158 myauxlist->push_back(mysubaux); << 164 159 << 165 G4GDMLAuxStructType mylocalaux = {"sometype", "somevalue", "someunit", 0}; 160 G4GDMLAuxStructType myaux = {"mytype" << 166 161 parser.AddAuxiliary(myaux); << 167 parser.AddVolumeAuxiliary(mylocalaux, G4TransportationManager::GetTransportationManager() 162 << 168 ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume()); 163 << 169 */ 164 // example of setting auxiliary info << 170 parser.SetRegionExport(true); 165 // (can be set for any volume) << 171 parser.Write(argv[2], G4TransportationManager::GetTransportationManager() 166 << 172 ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume()); 167 G4GDMLAuxStructType mylocalaux = {"so << 173 } 168 << 174 169 parser.AddVolumeAuxiliary(mylocalaux, << 175 170 G4TransportationManager::GetTranspo << 176 if (argc==4) // batch mode 171 ->GetNavigatorForTracking()->GetWor << 177 { 172 */ << 178 G4String command = "/control/execute "; 173 << 179 G4String fileName = argv[3]; 174 parser.SetRegionExport(true); << 180 UImanager->ApplyCommand(command+fileName); 175 // parser.SetEnergyCutsExport(true); << 181 } 176 // parser.SetOutputFileOverwrite(true) << 182 else // interactive mode 177 parser.Write(argv[2], G4TransportationMana << 183 { 178 ->GetNavigatorForT << 184 #ifdef G4UI_USE 179 ->GetWorldVolume() << 185 G4UIExecutive* ui = new G4UIExecutive(argc, argv); 180 ->GetLogicalVolume << 186 #ifdef G4VIS_USE 181 } << 187 G4VisManager* visManager = new G4VisExecutive; 182 << 188 visManager->Initialize(); 183 if (argc == 4) // batch mode << 189 UImanager->ApplyCommand("/control/execute vis.mac"); 184 { << 190 #endif 185 G4String command = "/control/execute "; << 191 ui->SessionStart(); 186 G4String fileName = argv[3]; << 192 #ifdef G4VIS_USE 187 UImanager->ApplyCommand(command + fileName << 193 delete visManager; 188 } << 194 #endif 189 else // interactive mode << 195 delete ui; 190 { << 196 #endif 191 G4UIExecutive* ui = new G4UIExecutive(argc << 197 } 192 UImanager->ApplyCommand("/control/execute << 193 ui->SessionStart(); << 194 delete ui; << 195 } << 196 198 197 delete visManager; << 199 delete runManager; 198 delete runManager; << 199 200 200 return 0; << 201 return 0; 201 } 202 } >> 203 >> 204 202 205