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