#include <unistd.h>
#include <vector>
#include "G4NistManager.hh"
#include "G4GeometryManager.hh"
#include "BLMPI.hh"
#include "BLNTuple.hh"
#include "BLParam.hh"
#include "BLCommand.hh"
#include "BLGroup.hh"
#include "BLManager.hh"
#include "BLTime.hh"
#include "build.icc"
Functions | |
void | g4bl_exit (int value) |
int | main (int argc, char *argv[]) |
Variables | |
BLSetParam | maxStep ("maxStep","100.0","Maximum physics step size (mm)") |
BLSetParam | worldMaterial ("worldMaterial","Vacuum","Material of the World volume") |
void g4bl_exit | ( | int | value | ) |
Referenced by BLCMDprintfield::callback(), BLCMDpillbox::command(), BLCMDlist::command(), BLCMDhelp::command(), BLCMDprintfield::do_points(), BLManager::handleCallbacks(), main(), and BLManager::Notify().
00047 { 00048 //@ geant4.9.2.p01 generates malloc delete errors in ::exit(0) 00049 fflush(stdout); 00050 _exit(0); 00051 }
int main | ( | int | argc, | |
char * | argv[] | |||
) |
References BLElement::allOK(), BLNTuple::closeAll(), BLManager::delayedConstruction(), BLManager::displayVisual(), BLCommand::doCommand(), BLGroup::end(), g4bl_exit(), BLCommand::getErrorCount(), BLManager::getObject(), BLParam::getString(), BLGroup::getWorld(), BLManager::handleCallbacks(), BLMPI::init(), BLManager::initialize(), BLMPI::isMPI(), BLCommand::isValidCommand(), BLMPI::main(), BLNTuple::noOutputFiles(), BLManager::nReference(), Param, BLParam::printParam(), BLCommand::readFile(), BLGroup::setMaterial(), BLParam::setParam(), BLNTuple::summary(), BLTime::timems(), BLManager::trackBeam(), and BLManager::trackTuneAndReferenceParticles().
00054 { 00055 #ifdef WIN32 00056 int crtflg = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ) | 00057 _CRTDBG_ALLOC_MEM_DF | 00058 _CRTDBG_DELAY_FREE_MEM_DF | 00059 _CRTDBG_CHECK_ALWAYS_DF; 00060 _CrtSetDbgFlag(crtflg); 00061 #endif 00062 00063 // initialize and set up MPI, if appropriate. 00064 // Sets stderr and stdout to /dev/null except for rank 0 or non-MPI. 00065 BLMPI::init(&argc,&argv); 00066 00067 printf("*************************************************************\n"); 00068 printf(" g4beamline version: %s (%s)\n",VERSIONX,DATEX); 00069 printf(" Copyright : Tom Roberts, Muons, Inc.\n"); 00070 printf(" License : Gnu Public License\n"); 00071 printf(" WWW : http://g4beamline.muonsinc.com"); 00072 fflush(stdout); // for checking the program started up 00073 00074 if(argc < 2) { 00075 printf("USAGE: g4beamline inputfile [viewer=TYPE] [param=value...]\n"); 00076 printf(" viewer=best (any valid viewer) Display detector and events visually\n"); 00077 printf(" viewer=none (default) Track beam.\n"); 00078 printf("\n"); 00079 printf(" Commands used by each viewer are in the file viewer.def\n"); 00080 ::exit(1); 00081 } 00082 00083 // set PRNG seed from the clock. Note the seed is probably re-set 00084 // at the start of each event, according to the randomseed command 00085 // (event number if no such command). 00086 CLHEP::HepRandom::setTheSeed(BLTime::timems() & 0x7FFFFFFFL); 00087 00088 // Ensure the BLManager has been created, and do its delayed constuction 00089 BLManager *mgr = BLManager::getObject(); 00090 mgr->delayedConstruction(); 00091 00092 // Handle arguments 2 thru argc-1 as arguments to the param command 00093 // They should be of the form name=value or name="a value with spaces" 00094 // Arguments that consist of a valid command will be kept until all 00095 // parameters are defined, and then will be executed in order. 00096 // Remember the shell will eat " and ' 00097 G4String cmd("param"); 00098 std::vector<G4String> argCommands; 00099 for(int i=2; i<argc; ++i) { 00100 cmd += " "; 00101 G4String s(argv[i]); 00102 unsigned p = s.find("="); 00103 if(p == s.npos || s.find(" ") < p) { 00104 p = s.find(" "); 00105 G4String c = s.substr(0,p); 00106 if(BLCommand::isValidCommand(c)) 00107 argCommands.push_back(s); 00108 else 00109 printf("*** g4beamline: invalid arg '%s' ignored\n", 00110 s.c_str()); 00111 continue; 00112 } 00113 cmd += s.substr(0,p+1); 00114 if(s.find("'") == s.npos) { 00115 cmd += "'"; 00116 cmd += s.substr(p+1); 00117 cmd += "'"; 00118 } else if(s.find('"') == s.npos) { 00119 cmd += '"'; 00120 cmd += s.substr(p+1); 00121 cmd += '"'; 00122 } else { 00123 cmd += s; 00124 } 00125 } 00126 if(cmd.find("=") != cmd.npos) 00127 BLCommand::doCommand(cmd); 00128 for(unsigned i=0; i<argCommands.size(); ++i) 00129 BLCommand::doCommand(argCommands[i]); 00130 00131 // arrange to perform a geometry test 00132 cmd = "geometry"; 00133 BLCommand::doCommand(cmd); 00134 00135 // don't write output files in visual mode 00136 G4String viewer = Param.getString("viewer"); 00137 if(viewer != "none") { 00138 BLNTuple::noOutputFiles(); 00139 if(BLMPI::isMPI()) { 00140 G4Exception("main","Viewer and MPI",FatalException, 00141 "Visualization cannot be used in MPI mode."); 00142 } 00143 } 00144 00145 // read input file and end the World volume 00146 if(BLCommand::readFile(argv[1]) != 0) { 00147 char tmp[64]; 00148 sprintf(tmp,"There were %d errors in the input", 00149 BLCommand::getErrorCount()); 00150 G4Exception("main","Input Errors",FatalException,tmp); 00151 } 00152 BLGroup::getWorld()->end(); 00153 00154 // quit if world is empty 00155 if(BLGroup::getWorld()->getNChildren() == 0) { 00156 G4Exception("main","Empty World",FatalException, 00157 "No elements have been placed into the World"); 00158 } 00159 00160 // verify that viewer did not change from command-line 00161 if(viewer != Param.getString("viewer")) 00162 G4Exception("main","Viewer changed",FatalException, 00163 "The viewer parameter may only be set on the command-line."); 00164 00165 Param.printParam(); 00166 00167 // use the worldMaterial. 00168 BLGroup::getWorld()->setMaterial(Param.getString("worldMaterial")); 00169 00170 // initialize BLManager (construct the geometry, etc.) 00171 mgr->initialize(); 00172 00173 // handle pre-reference callbacks 00174 mgr->handleCallbacks(0); 00175 00176 // Track reference particle(s), if present 00177 if(mgr->nReference() > 0) 00178 mgr->trackTuneAndReferenceParticles(); 00179 00180 // handle post-reference callbacks 00181 mgr->handleCallbacks(1); 00182 00183 // handle MPI (never returns if in MPI mode). 00184 BLMPI::main(); 00185 00186 // handle replace main loop callbacks 00187 mgr->handleCallbacks(3); 00188 00189 if(viewer != "none") { 00190 #ifdef WIN32 00191 if(viewer == "best") Param.setParam("viewer","OIWin32"); 00192 #else 00193 if(viewer == "best") Param.setParam("viewer","OIX"); 00194 #endif 00195 if(!BLElement::allOK()) 00196 G4Exception("main","Element Error",JustWarning, 00197 "Not all BLElement-s are OK -- continuing anyway"); 00198 mgr->displayVisual(); 00199 } else { 00200 if(!BLElement::allOK()) { 00201 G4Exception("main","Element Error",FatalException, 00202 "Not all BLElement-s are OK"); 00203 } 00204 mgr->trackBeam(); 00205 BLNTuple::summary(); 00206 BLNTuple::closeAll(); 00207 } 00208 00209 // handle post-tracking callbacks 00210 mgr->handleCallbacks(2); 00211 00212 G4cout << "g4beamline: simulation complete -- exiting" << G4endl; 00213 delete mgr; 00214 00215 g4bl_exit(0); 00216 }
BLSetParam maxStep("maxStep","100.0","Maximum physics step size (mm)") |
BLSetParam worldMaterial("worldMaterial","Vacuum","Material of the World volume") |