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