/scratch0/jsnuveri/BDSIM/BDSIMgit/bdsim/src/BDSExecOptions.cc

00001 #include "BDSExecOptions.hh"
00002 
00003 #include <iomanip>
00004 #include <unistd.h>
00005 
00006 #include "globals.hh"
00007 
00008 #include "BDSDebug.hh"
00009 #include "BDSMaterials.hh"
00010 #include "BDSOutputFormat.hh"
00011 #include "BDSUtilities.hh"
00012 
00013 #include "parser/getEnv.h"
00014 
00015 BDSExecOptions* BDSExecOptions::_instance=0;
00016 
00017 const BDSExecOptions* BDSExecOptions::Instance(int argc, char **argv){
00018   if(_instance==0) {
00019     _instance = new BDSExecOptions(argc, argv);
00020     return _instance;
00021   } else {
00022     G4Exception("BDSExecOptions::Instance is already initialized. Return pointer to singleton with BDSExecOptions::Instance()", "-1", FatalException, "");
00023     return NULL;
00024   }
00025 }
00026 
00027 const BDSExecOptions* BDSExecOptions::Instance(){
00028   if(_instance==0) {
00029     G4Exception("BDSExecOptions::Instance was not initialised. Initialize first with BDSExecOptions::Instance(int argc, char **argv).", "-1", FatalException, "");
00030     return NULL;
00031   } else 
00032     return _instance;
00033 }
00034 
00035 BDSExecOptions::BDSExecOptions(int argc, char **argv){
00036   inputFilename       = "optics.mad";
00037   visMacroFilename    = "vis.mac";
00038   visDebug            = false;
00039   outputFilename      = "output";
00040   outputFormat        = BDSOutputFormat::_ASCII;
00041   outline             = false;
00042   outlineFilename     = "outline.dat";
00043   outlineFormat       = "";
00044 
00045   gflash      = false;
00046   gflashemax  = 10000;
00047   gflashemin  = 0.1;
00048 
00049   verbose       = false;
00050   verboseEvent  = false;
00051   verboseStep   = false;
00052   verboseEventNumber   = -1;
00053   batch         = false; 
00054   
00055   verboseRunLevel      = 0;
00056   verboseEventLevel    = 0;
00057   verboseTrackingLevel = 0;
00058   verboseSteppingLevel = 0;
00059   
00060   circular      = false;
00061   
00062   seed              = -1;
00063   setSeed           = false;
00064   seedStateFilename = "";
00065   setSeedState      = false;
00066 
00067   Parse(argc, argv);
00069   itsBDSIMPATH = BDS::GetFullPath(inputFilename);
00070 #ifdef BDSDEBUG
00071   G4cout << __METHOD_NAME__ << "BDSIMPATH set to: " << itsBDSIMPATH << G4endl;
00072 #endif
00073 }
00074 
00075 BDSExecOptions::~BDSExecOptions() {
00076   _instance = 0;
00077 }
00078 
00083 void BDSExecOptions::Parse(int argc, char **argv) {
00084   static struct option LongOptions[] = {{ "help" , 0, 0, 0 },
00085                                         { "outline", 1, 0, 0 },
00086                                         { "outline_type", 1, 0, 0 },
00087                                         { "verbose", 0, 0, 0 },
00088                                         { "verbose_step", 0, 0, 0 },
00089                                         { "verbose_event", 0, 0, 0 },
00090                                         { "verbose_event_num", 1, 0, 0 },
00091                                         { "verbose_G4run", 1, 0, 0 },
00092                                         { "verbose_G4event", 1, 0, 0 },
00093                                         { "verbose_G4tracking", 1, 0, 0 },
00094                                         { "verbose_G4stepping", 1, 0, 0 },
00095                                         { "file", 1, 0, 0 },
00096                                         { "vis_debug", 0, 0, 0 },
00097                                         { "vis_mac", 1, 0, 0 },
00098                                         { "gflash", 0, 0, 0 },
00099                                         { "gflashemax", 1, 0, 0 },
00100                                         { "gflashemin", 1, 0, 0 },
00101                                         { "output", 1, 0, 0 },
00102                                         { "outfile", 1, 0, 0 },
00103                                         { "batch", 0, 0, 0 },
00104                                         { "materials", 0, 0, 0 },
00105                                         { "circular", 0, 0, 0},
00106                                         { "seed", 1, 0, 0},
00107                                         { "seedstate",1,0,0},
00108                                         { 0, 0, 0, 0 }};
00109   
00110   int OptionIndex = 0;
00111   int c;
00112  
00113   for(;;) {
00114     OptionIndex = 0;
00115   
00116     // see e.g. http://linux.die.net/man/3/getopt
00117     c = getopt_long(argc, argv, "Vv",
00118                     LongOptions, &OptionIndex );
00119     
00120     if ( c == -1 ) // end of options list
00121       break;
00122     
00123     switch (c) {
00124     case '?': // unrecognised option
00125       G4cout << "invalid option for command " << argv[0] << G4endl << G4endl << G4endl;
00126       Usage();
00127       exit(1);
00128       break;
00129     case 0:
00130       if( !strcmp(LongOptions[OptionIndex].name , "help") ) {
00131         Usage();
00132         exit(0);
00133       }
00134       if( !strcmp(LongOptions[OptionIndex].name , "batch") ) {
00135         batch = true;
00136       }
00137       if( !strcmp(LongOptions[OptionIndex].name , "verbose") ) {
00138         verbose = true; 
00139       }
00140       if( !strcmp(LongOptions[OptionIndex].name , "verbose_step") ) {
00141         verboseStep = true; 
00142         // we shouldn't have verbose steps without verbose events etc.
00143         verboseEvent = true;
00144       }
00145       if( !strcmp(LongOptions[OptionIndex].name , "verbose_event") ) {
00146         verboseEvent = true; 
00147       }
00148       if( !strcmp(LongOptions[OptionIndex].name , "verbose_event_num") ){
00149         verboseEventNumber = atoi(optarg);
00150       }
00151       if( !strcmp(LongOptions[OptionIndex].name , "verbose_G4run") ) {
00152         verboseRunLevel = atoi(optarg);
00153       }
00154       if( !strcmp(LongOptions[OptionIndex].name , "verbose_G4event") ) {
00155         verboseEventLevel = atoi(optarg);
00156       }
00157       if( !strcmp(LongOptions[OptionIndex].name , "verbose_G4tracking") )  {
00158         verboseTrackingLevel = atoi(optarg);
00159       }
00160       if( !strcmp(LongOptions[OptionIndex].name , "verbose_G4stepping") ) {
00161         verboseSteppingLevel = atoi(optarg);
00162       }
00163       if( !strcmp(LongOptions[OptionIndex].name , "output") ) {
00164         if(!strcmp(optarg,"none") || !strcmp(optarg,"NONE")) outputFormat=BDSOutputFormat::_NONE;
00165         else if(!strcmp(optarg,"ascii") || !strcmp(optarg,"ASCII")) outputFormat=BDSOutputFormat::_ASCII;
00166         else if (!strcmp(optarg,"root") || !strcmp(optarg,"ROOT")) outputFormat=BDSOutputFormat::_ROOT;
00167         else if (!strcmp(optarg,"combined") || !strcmp(optarg,"COMBINED")) outputFormat=BDSOutputFormat::_COMBINED;
00168         else {
00169           G4cerr<<"unknown output format "<<optarg<<G4endl;
00170           exit(1);
00171         }
00172 #ifndef USE_ROOT
00173         if (outputFormat == BDSOutputFormat::_ROOT || outputFormat == BDSOutputFormat::_COMBINED) {
00174           G4cerr << "ERROR outputFormat root, but BDSIM not configured with ROOT support!" << G4endl;
00175           G4cerr << "Use ascii instead, or recompile with ROOT!" << G4endl;
00176           exit(1);
00177         }
00178 #endif
00179       }
00180       if( !strcmp(LongOptions[OptionIndex].name , "outfile") ) {
00181         outputFilename=optarg;
00182       }
00183       if( !strcmp(LongOptions[OptionIndex].name , "outline") ) {
00184         outlineFilename = optarg; 
00185         outline=true;
00186       }
00187       if( !strcmp(LongOptions[OptionIndex].name , "outline_type") ) {
00188         outlineFormat = optarg; 
00189         outline=true;  // can't have outline type without turning on outline!
00190       }
00191       if( !strcmp(LongOptions[OptionIndex].name , "file") ) {
00192         inputFilename=optarg;
00193       }
00194       if( !strcmp(LongOptions[OptionIndex].name , "vis_debug") ) {
00195         visDebug = true;
00196       }
00197       if( !strcmp(LongOptions[OptionIndex].name , "vis_mac") ) {
00198         visMacroFilename=optarg;
00199       }
00200       if( !strcmp(LongOptions[OptionIndex].name , "gflash") ) {
00201         gflash = true;
00202       }
00203       if( !strcmp(LongOptions[OptionIndex].name , "gflashemax") ) {
00204         gflashemax = atof(optarg);
00205       }
00206       if( !strcmp(LongOptions[OptionIndex].name , "gflashemin") ) {
00207         gflashemin = atof(optarg);
00208       }
00209       if( !strcmp(LongOptions[OptionIndex].name, "materials") ) {
00210         BDSMaterials::ListMaterials();
00211         exit(0);
00212       }
00213       if( !strcmp(LongOptions[OptionIndex].name, "circular")  ) {
00214         circular = true;
00215       }
00216       if( !strcmp(LongOptions[OptionIndex].name, "seed")  ){
00217         seed = atoi(optarg);
00218         setSeed = true;
00219       }
00220       if( !strcmp(LongOptions[OptionIndex].name, "seedstate") ){
00221         seedStateFilename = optarg;
00222         setSeedState = true;
00223       }
00224       break;
00225       
00226     default:
00227       break;
00228     }
00229   } 
00230 }
00231 
00232 void BDSExecOptions::Usage()const {
00233   G4cout<<"bdsim : version 0.6.develop"<<G4endl;
00234   G4cout<<"        (C) 2001-2015 Royal Holloway University London"<<G4endl;
00235   G4cout<<"        http://www.ph.rhul.ac.uk/twiki/bin/view/PP/JAI/BdSim"<<G4endl;
00236   G4cout<<G4endl;
00237 
00238   G4cout<<"Usage: bdsim [options]"<<G4endl;
00239   G4cout<<"Options:"<<G4endl;
00240   G4cout<<"--file=<filename>      : specify the lattice and options file "<<G4endl
00241         <<"--batch                : batch mode - no graphics"<<G4endl
00242         <<"--circular             : assume circular machine - turn control"<<G4endl
00243         <<"--gflash               : turn on gFlash fast shower parameterisation. Default false."<<G4endl
00244         <<"--gflashemax=N         : maximum energy for gflash shower parameterisation in GeV. Default 10000."<<G4endl
00245         <<"--gflashemin=N         : minimum energy for gflash shower parameterisation in GeV. Default 0.1."<<G4endl
00246         <<"--help                 : display this message"<<G4endl
00247         <<"--materials            : list materials included in bdsim by default"<<G4endl
00248         <<"--outline=<file>       : print geometry info to <file>"<<G4endl
00249         <<"--outline_type=<fmt>   : type of outline format"<<G4endl
00250         <<"                         where fmt = optics | survey"<<G4endl
00251         <<"--output=<fmt>         : output format (root|ascii|combined), default ascii"<<G4endl
00252         <<"--outfile=<file>       : output file name. Will be appended with _N"<<G4endl
00253         <<"                         where N = 0, 1, 2, 3... etc."<<G4endl
00254         <<"--seed=N               : the seed to use for the random number generator" <<G4endl
00255         <<"--seedstate=<file>     : file containing CLHEP::Random seed state - overrides other seed options"<<G4endl
00256         <<"--verbose              : display general parameters before run"<<G4endl
00257         <<"--verbose_event        : display information for every event "<<G4endl
00258         <<"--verbose_event_num=N  : display tracking information for event number N"<<G4endl
00259         <<"--verbose_step         : display tracking information after each step"<<G4endl
00260         <<"--verbose_G4event=N    : set Geant4 Event manager verbosity level"<<G4endl
00261         <<"--verbose_G4run=N      : set Geant4 verbosity level (see Geant4 manual for details)"<<G4endl
00262         <<"--verbose_G4stepping=N : set Geant4 Stepping manager verbosity level"<<G4endl
00263         <<"--verbose_G4tracking=N : set Geant4 Tracking manager verbosity level [-1:5]"<<G4endl
00264         <<"--vis_debug            : display all volumes in visualiser"<<G4endl
00265         <<"--vis_mac=<file>       : file with the visualization macro script, default vis.mac"<<G4endl;
00266 }
00267 
00268 void BDSExecOptions::Print()const {
00269   G4cout << __METHOD_NAME__ << G4endl;
00270   G4cout << __METHOD_NAME__ << std::setw(23) << " inputFilename: "       << std::setw(15) << inputFilename       << G4endl;
00271   G4cout << __METHOD_NAME__ << std::setw(23) << " visMacroFilename: "    << std::setw(15) << visMacroFilename    << G4endl;
00272   G4cout << __METHOD_NAME__ << std::setw(23) << " visDebug: "            << std::setw(15) << visDebug            << G4endl;
00273   G4cout << __METHOD_NAME__ << std::setw(23) << " outputFilename: "      << std::setw(15) << outputFilename      << G4endl;
00274   G4cout << __METHOD_NAME__ << std::setw(23) << " outputFormat: "        << std::setw(15) << outputFormat        << G4endl;
00275   G4cout << __METHOD_NAME__ << std::setw(23) << " outlineFilename: "     << std::setw(15) << outlineFilename     << G4endl;
00276   G4cout << __METHOD_NAME__ << std::setw(23) << " gflash: "              << std::setw(15) << gflash              << G4endl;
00277   G4cout << __METHOD_NAME__ << std::setw(23) << " gflashemin: "          << std::setw(15) << gflashemin          << G4endl;  
00278   G4cout << __METHOD_NAME__ << std::setw(23) << " gflashemax: "          << std::setw(15) << gflashemax          << G4endl;
00279   G4cout << __METHOD_NAME__ << std::setw(23) << " verbose: "             << std::setw(15) << verbose             << G4endl;
00280   G4cout << __METHOD_NAME__ << std::setw(23) << " verboseEvent: "        << std::setw(15) << verboseEvent        << G4endl;  
00281   G4cout << __METHOD_NAME__ << std::setw(23) << " verboseStep: "         << std::setw(15) << verboseStep         << G4endl;  
00282   G4cout << __METHOD_NAME__ << std::setw(23) << " batch: "               << std::setw(15) << batch               << G4endl;
00283   G4cout << __METHOD_NAME__ << std::setw(23) << " outline: "             << std::setw(15) << outline             << G4endl;
00284   G4cout << __METHOD_NAME__ << std::setw(23) << " verboseRunLevel: "     << std::setw(15) << verboseRunLevel     << G4endl;  
00285   G4cout << __METHOD_NAME__ << std::setw(23) << " verboseEventLevel: "   << std::setw(15) << verboseEventLevel   << G4endl;
00286   G4cout << __METHOD_NAME__ << std::setw(23) << " verboseTrackingLevel: "<< std::setw(15) << verboseTrackingLevel<< G4endl;  
00287   G4cout << __METHOD_NAME__ << std::setw(23) << " verboseSteppingLevel: "<< std::setw(15) << verboseSteppingLevel<< G4endl;
00288   G4cout << __METHOD_NAME__ << std::setw(23) << " circular: "            << std::setw(15) << circular            << G4endl;
00289   G4cout << __METHOD_NAME__ << std::setw(23) << " seed: "                << std::setw(15) << seed                << G4endl;
00290   G4cout << __METHOD_NAME__ << std::setw(23) << " seedStateFilename: "   << std::setw(15) << seedStateFilename   << G4endl;
00291   return;
00292 }

Generated on 28 Jun 2015 for BDSIM by  doxygen 1.4.7