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 // 30 // 31 // 31 // 32 // ------------------------------------------- 32 // -------------------------------------------------------------- 33 // GEANT 4 - load_gdml 33 // GEANT 4 - load_gdml 34 // 34 // 35 // ------------------------------------------- 35 // -------------------------------------------------------------- 36 36 37 #include "FTFP_BERT.hh" << 37 #include <vector> 38 #include "G01ActionInitialization.hh" << 38 39 #include "G01DetectorConstruction.hh" << 39 #ifdef G4MULTITHREADED 40 #include "G01PrimaryGeneratorAction.hh" << 40 #include "G4MTRunManager.hh" >> 41 #else >> 42 #include "G4RunManager.hh" >> 43 #endif >> 44 >> 45 #include "G4UImanager.hh" 41 46 42 #include "G4GDMLParser.hh" << 43 #include "G4LogicalVolumeStore.hh" 47 #include "G4LogicalVolumeStore.hh" 44 #include "G4RunManagerFactory.hh" << 45 #include "G4TransportationManager.hh" 48 #include "G4TransportationManager.hh" 46 #include "G4Types.hh" << 47 #include "G4UIExecutive.hh" << 48 #include "G4UImanager.hh" << 49 #include "G4VisExecutive.hh" << 50 49 51 #include <vector> << 50 #include "G01PrimaryGeneratorAction.hh" >> 51 #include "G01DetectorConstruction.hh" >> 52 #include "G01ActionInitialization.hh" 52 53 53 void print_aux(const G4GDMLAuxListType* auxInf << 54 #include "FTFP_BERT.hh" 54 { << 55 55 for (std::vector<G4GDMLAuxStructType>::const << 56 #include "G4VisExecutive.hh" 56 iaux != auxInfoList->end(); iaux++) << 57 #include "G4UIExecutive.hh" 57 { << 58 58 G4String str = iaux->type; << 59 #include "G4GDMLParser.hh" 59 G4String val = iaux->value; << 60 G4String unit = iaux->unit; << 61 60 62 G4cout << prepend << str << " : " << val < << 61 void print_aux(const G4GDMLAuxListType* auxInfoList, G4String prepend="|") >> 62 { >> 63 for(std::vector<G4GDMLAuxStructType>::const_iterator >> 64 iaux = auxInfoList->begin(); iaux != auxInfoList->end(); iaux++ ) >> 65 { >> 66 G4String str=iaux->type; >> 67 G4String val=iaux->value; >> 68 G4String unit=iaux->unit; >> 69 >> 70 G4cout << prepend << str << " : " << val << " " << unit << G4endl; 63 71 64 if (iaux->auxList) print_aux(iaux->auxList << 72 if (iaux->auxList) print_aux(iaux->auxList, prepend + "|"); 65 } << 73 } 66 return; 74 return; 67 } 75 } 68 76 69 // ------------------------------------------- 77 // -------------------------------------------------------------- 70 78 71 int main(int argc, char** argv) << 79 int main(int argc,char **argv) 72 { 80 { 73 G4cout << G4endl; << 81 G4cout << G4endl; 74 G4cout << "Usage: load_gdml <intput_gdml_fil << 82 G4cout << "Usage: load_gdml <intput_gdml_file:mandatory>" 75 << " <output_gdml_file:optional>" << << 83 << " <output_gdml_file:optional>" << G4endl; 76 G4cout << G4endl; << 84 G4cout << G4endl; 77 << 85 78 if (argc < 2) { << 86 if (argc<2) 79 G4cout << "Error! Mandatory input file is << 87 { 80 G4cout << G4endl; << 88 G4cout << "Error! Mandatory input file is not specified!" << G4endl; 81 return -1; << 89 G4cout << G4endl; 82 } << 90 return -1; 83 << 91 } 84 G4GDMLParser parser; << 92 85 << 93 G4GDMLParser parser; 86 // Uncomment the following if wish to avoid << 94 87 // parser.SetStripFlag(false); << 95 // Uncomment the following if wish to avoid names stripping 88 << 96 // parser.SetStripFlag(false); 89 // Uncomment the following and set a string << 97 90 // schema filename if wishing to use alterna << 98 parser.Read(argv[1]); 91 // parser.SetImportSchema(""); << 99 92 << 100 if (argc>4) 93 parser.SetOverlapCheck(true); << 101 { 94 parser.Read(argv[1]); << 102 G4cout << "Error! Too many arguments!" << G4endl; 95 << 103 G4cout << G4endl; 96 if (argc > 4) { << 104 return -1; 97 G4cout << "Error! Too many arguments!" << << 105 } 98 G4cout << G4endl; << 106 99 return -1; << 107 #ifdef G4MULTITHREADED 100 } << 108 G4MTRunManager* runManager = new G4MTRunManager; 101 << 109 #else 102 auto* runManager = G4RunManagerFactory::Crea << 110 G4RunManager* runManager = new G4RunManager; 103 << 111 #endif 104 runManager->SetUserInitialization(new G01Det << 112 105 runManager->SetUserInitialization(new FTFP_B << 113 runManager->SetUserInitialization(new G01DetectorConstruction( 106 runManager->SetUserInitialization(new G01Act << 114 parser.GetWorldVolume())); 107 << 115 runManager->SetUserInitialization(new FTFP_BERT); 108 runManager->Initialize(); << 116 runManager->SetUserInitialization(new G01ActionInitialization()); 109 << 117 110 // Initialize visualization << 118 runManager->Initialize(); 111 G4VisManager* visManager = new G4VisExecutiv << 119 112 visManager->Initialize(); << 120 // Initialize visualization 113 << 121 G4VisManager* visManager = new G4VisExecutive; 114 // Get the pointer to the User Interface man << 122 visManager->Initialize(); 115 G4UImanager* UImanager = G4UImanager::GetUIp << 123 116 << 124 // Get the pointer to the User Interface manager 117 //////////////////////////////////////////// << 125 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 118 // << 126 119 // Example how to retrieve Auxiliary Informa << 127 /////////////////////////////////////////////////////////////////////// 120 // << 128 // 121 << 129 // Example how to retrieve Auxiliary Information 122 G4cout << std::endl; << 130 // 123 << 131 124 const G4LogicalVolumeStore* lvs = G4LogicalV << 132 G4cout << std::endl; 125 std::vector<G4LogicalVolume*>::const_iterato << 133 126 for (lvciter = lvs->begin(); lvciter != lvs- << 134 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance(); 127 G4GDMLAuxListType auxInfo = parser.GetVolu << 135 std::vector<G4LogicalVolume*>::const_iterator lvciter; 128 << 136 for( lvciter = lvs->begin(); lvciter != lvs->end(); lvciter++ ) 129 if (auxInfo.size() > 0) << 137 { 130 G4cout << "Auxiliary Information is foun << 138 G4GDMLAuxListType auxInfo = parser.GetVolumeAuxiliaryInformation(*lvciter); 131 << G4endl; << 139 132 << 140 if (auxInfo.size()>0) 133 print_aux(&auxInfo); << 141 G4cout << "Auxiliary Information is found for Logical Volume : " 134 } << 142 << (*lvciter)->GetName() << G4endl; 135 << 143 136 // now the 'global' auxiliary info << 144 print_aux(&auxInfo); 137 G4cout << std::endl; << 145 } 138 G4cout << "Global auxiliary info:" << std::e << 146 139 G4cout << std::endl; << 147 // now the 'global' auxiliary info 140 << 148 G4cout << std::endl; 141 print_aux(parser.GetAuxList()); << 149 G4cout << "Global auxiliary info:" << std::endl; 142 << 150 G4cout << std::endl; 143 G4cout << std::endl; << 151 144 << 152 print_aux(parser.GetAuxList()); 145 // << 153 146 // End of Auxiliary Information block << 154 G4cout << std::endl; 147 // << 155 148 //////////////////////////////////////////// << 156 // 149 << 157 // End of Auxiliary Information block 150 runManager->BeamOn(0); << 158 // 151 << 159 //////////////////////////////////////////////////////////////////////// 152 // example of writing out << 160 153 << 161 // example of writing out 154 if (argc >= 3) { << 162 155 /* << 163 if (argc>=3) 156 G4GDMLAuxStructType mysubaux = {"mysu << 164 { 157 G4GDMLAuxListType* myauxlist = new G4 << 165 /* 158 myauxlist->push_back(mysubaux); << 166 G4GDMLAuxStructType mysubaux = {"mysubtype", "mysubvalue", "mysubunit", 0}; 159 << 167 G4GDMLAuxListType* myauxlist = new G4GDMLAuxListType(); 160 G4GDMLAuxStructType myaux = {"mytype" << 168 myauxlist->push_back(mysubaux); 161 parser.AddAuxiliary(myaux); << 169 162 << 170 G4GDMLAuxStructType myaux = {"mytype", "myvalue", "myunit", myauxlist}; 163 << 171 parser.AddAuxiliary(myaux); 164 // example of setting auxiliary info << 172 165 // (can be set for any volume) << 173 166 << 174 // example of setting auxiliary info for world volume 167 G4GDMLAuxStructType mylocalaux = {"so << 175 // (can be set for any volume) 168 << 176 169 parser.AddVolumeAuxiliary(mylocalaux, << 177 G4GDMLAuxStructType mylocalaux = {"sometype", "somevalue", "someunit", 0}; 170 G4TransportationManager::GetTranspo << 178 171 ->GetNavigatorForTracking()->GetWor << 179 parser.AddVolumeAuxiliary(mylocalaux, 172 */ << 180 G4TransportationManager::GetTransportationManager() 173 << 181 ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume()); 174 parser.SetRegionExport(true); << 182 */ 175 // parser.SetEnergyCutsExport(true); << 183 parser.SetRegionExport(true); 176 // parser.SetOutputFileOverwrite(true) << 184 parser.Write(argv[2], G4TransportationManager::GetTransportationManager() 177 parser.Write(argv[2], G4TransportationMana << 185 ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume()); 178 ->GetNavigatorForT << 186 } 179 ->GetWorldVolume() << 187 180 ->GetLogicalVolume << 188 181 } << 189 if (argc==4) // batch mode 182 << 190 { 183 if (argc == 4) // batch mode << 191 G4String command = "/control/execute "; 184 { << 192 G4String fileName = argv[3]; 185 G4String command = "/control/execute "; << 193 UImanager->ApplyCommand(command+fileName); 186 G4String fileName = argv[3]; << 194 } 187 UImanager->ApplyCommand(command + fileName << 195 else // interactive mode 188 } << 196 { 189 else // interactive mode << 197 G4UIExecutive* ui = new G4UIExecutive(argc, argv); 190 { << 198 UImanager->ApplyCommand("/control/execute vis.mac"); 191 G4UIExecutive* ui = new G4UIExecutive(argc << 199 ui->SessionStart(); 192 UImanager->ApplyCommand("/control/execute << 200 delete ui; 193 ui->SessionStart(); << 201 } 194 delete ui; << 195 } << 196 202 197 delete visManager; << 203 delete visManager; 198 delete runManager; << 204 delete runManager; 199 205 200 return 0; << 206 return 0; 201 } 207 } 202 208