00001 #include "BDSExecOptions.hh"
00002
00003 BDSExecOptions* BDSExecOptions::_instance=0;
00004
00005 BDSExecOptions* BDSExecOptions::Instance(){
00006 if(_instance==0) {
00007 _instance = new BDSExecOptions();
00008 }
00009 return _instance;
00010 }
00011
00012 BDSExecOptions::BDSExecOptions() {
00013 inputFilename = "optics.mad";
00014 visMacroFilename = "vis.mac";
00015 outputFilename = "output";
00016 outputFormat = _ASCII;
00017 outline = false;
00018 outlineFilename = "outline.dat";
00019 outlineFormat = "";
00020
00021 gflash = 0;
00022 gflashemax = 10000;
00023 gflashemin = 0.1;
00024
00025 nptwiss = 200;
00026
00027 verbose = false;
00028 verboseEvent = false;
00029 verboseStep = false;
00030 verboseEventNumber = -1;
00031 batch = false;
00032 listMaterials = false;
00033
00034 verboseRunLevel = 0;
00035 verboseEventLevel = 0;
00036 verboseTrackingLevel = 0;
00037 verboseSteppingLevel = 0;
00038 }
00039
00040 BDSExecOptions::~BDSExecOptions() {
00041 }
00042
00047 void BDSExecOptions::Parse(int argc, char **argv) {
00048 static struct option LongOptions[] = {{ "help" , 0, 0, 0 },
00049 { "outline", 1, 0, 0 },
00050 { "outline_type", 1, 0, 0 },
00051 { "verbose", 0, 0, 0 },
00052 { "verbose_step", 0, 0, 0 },
00053 { "verbose_event", 0, 0, 0 },
00054 { "verbose_event_num", 1, 0, 0 },
00055 { "verbose_G4run", 1, 0, 0 },
00056 { "verbose_G4event", 1, 0, 0 },
00057 { "verbose_G4tracking", 1, 0, 0 },
00058 { "verbose_G4stepping", 1, 0, 0 },
00059 { "file", 1, 0, 0 },
00060 { "vis_mac", 1, 0, 0 },
00061 { "gflash", 1, 0, 0 },
00062 { "gflashemax", 1, 0, 0 },
00063 { "gflashemin", 1, 0, 0 },
00064 { "output", 1, 0, 0 },
00065 { "outfile", 1, 0, 0 },
00066 { "batch", 0, 0, 0 },
00067 { "materials", 0, 0, 0 },
00068 { 0, 0, 0, 0 }};
00069
00070 int OptionIndex = 0;
00071 int c;
00072
00073 for(;;) {
00074 OptionIndex = 0;
00075
00076 c = getopt_long(argc, argv, "Vv",
00077 LongOptions, &OptionIndex );
00078
00079 if ( c == -1 )
00080 break;
00081
00082 switch (c) {
00083 case 0:
00084 if( !strcmp(LongOptions[OptionIndex].name , "help") ) {
00085 Usage();
00086 exit(0);
00087 }
00088 if( !strcmp(LongOptions[OptionIndex].name , "batch") ) {
00089 batch = true;
00090 }
00091 if( !strcmp(LongOptions[OptionIndex].name , "verbose") ) {
00092 verbose = true;
00093 }
00094 if( !strcmp(LongOptions[OptionIndex].name , "verbose_step") ) {
00095 verboseStep = true;
00096
00097 verboseEvent = true;
00098 }
00099 if( !strcmp(LongOptions[OptionIndex].name , "verbose_event") ) {
00100 verboseEvent = true;
00101 }
00102 if( !strcmp(LongOptions[OptionIndex].name , "verbose_event_num") ){
00103 if(optarg)
00104 verboseEventNumber = atoi(optarg);
00105 }
00106 if( !strcmp(LongOptions[OptionIndex].name , "verbose_G4run") ) {
00107 if(optarg)
00108 verboseRunLevel = atoi(optarg);
00109 }
00110 if( !strcmp(LongOptions[OptionIndex].name , "verbose_G4event") ) {
00111 if(optarg)
00112 verboseEventLevel = atoi(optarg);
00113 }
00114 if( !strcmp(LongOptions[OptionIndex].name , "verbose_G4tracking") ) {
00115 if(optarg)
00116 verboseTrackingLevel = atoi(optarg);
00117 }
00118 if( !strcmp(LongOptions[OptionIndex].name , "verbose_G4stepping") ) {
00119 if(optarg)
00120 verboseSteppingLevel = atoi(optarg);
00121 }
00122 if( !strcmp(LongOptions[OptionIndex].name , "output") ) {
00123 if(optarg) {
00124 if(!strcmp(optarg,"ascii") || !strcmp(optarg,"ASCII")) outputFormat=_ASCII;
00125 else if (!strcmp(optarg,"root") || !strcmp(optarg,"ROOT")) outputFormat=_ROOT;
00126 else {
00127 G4cerr<<"unknown output format "<<optarg<<G4endl;
00128 exit(1);
00129 }
00130 #ifndef USE_ROOT
00131 if (outputFormat == _ROOT) {
00132 G4cerr << "ERROR outputFormat root, but BDSIM not configured with ROOT support!" << G4endl;
00133 G4cerr << "Use ascii instead, or recompile with ROOT!" << G4endl;
00134 exit(1);
00135 }
00136 #endif
00137 }
00138 }
00139 if( !strcmp(LongOptions[OptionIndex].name , "outfile") ) {
00140 if(optarg) {
00141 outputFilename=optarg;
00142 }
00143 }
00144 if( !strcmp(LongOptions[OptionIndex].name , "outline") ) {
00145 if(optarg) outlineFilename = optarg;
00146 outline=true;
00147 }
00148 if( !strcmp(LongOptions[OptionIndex].name , "outline_type") ) {
00149 if(optarg) outlineFormat = optarg;
00150 outline=true;
00151 }
00152 if( !strcmp(LongOptions[OptionIndex].name , "file") ) {
00153 if(optarg) {
00154 inputFilename=optarg;
00155 }
00156 else {
00157 G4cout<<"please specify the lattice filename"<<G4endl;
00158 }
00159 }
00160 if( !strcmp(LongOptions[OptionIndex].name , "vis_mac") ) {
00161 if(optarg) {
00162 visMacroFilename=optarg;
00163 }
00164 else {
00165 G4cout<<"please specify the visualization macro file"<<G4endl;
00166 }
00167 }
00168 if( !strcmp(LongOptions[OptionIndex].name , "gflash") ) {
00169 if(optarg)
00170 gflash = atoi(optarg);
00171 }
00172 if( !strcmp(LongOptions[OptionIndex].name , "gflashemax") ) {
00173 if(optarg)
00174 gflashemax = atof(optarg);
00175 }
00176 if( !strcmp(LongOptions[OptionIndex].name , "gflashemin") ) {
00177 if(optarg)
00178 gflashemin = atof(optarg);
00179 }
00180 if( !strcmp(LongOptions[OptionIndex].name, "materials") ) {
00181 BDSMaterials::ListMaterials();
00182 }
00183 break;
00184
00185 default:
00186 break;
00187 }
00188 }
00189 }
00190
00191 void BDSExecOptions::Usage() {
00192 G4cout<<"bdsim : version 0.6.0"<<G4endl;
00193 G4cout<<" (C) 2001-2013 Royal Holloway University London"<<G4endl;
00194 G4cout<<" http://www.ph.rhul.ac.uk/twiki/bin/view/PP/JAI/BdSim"<<G4endl;
00195 G4cout<<G4endl;
00196
00197 G4cout<<"Usage: bdsim [options]"<<G4endl;
00198 G4cout<<"Options:"<<G4endl;
00199 G4cout<<"--file=<filename> : specify the lattice file "<<G4endl
00200 <<"--output=<fmt> : output format (root|ascii), default ascii"<<G4endl
00201 <<"--outfile=<file> : output file name. Will be appended with _N"<<G4endl
00202 <<" where N = 0, 1, 2, 3... etc."<<G4endl
00203 <<"--vis_mac=<file> : file with the visualization macro script, default vis.mac"<<G4endl
00204 <<"--gflash=N : whether or not to turn on gFlash fast shower parameterisation. Default 0."<<G4endl
00205 <<"--gflashemax=N : maximum energy for gflash shower parameterisation in GeV. Default 10000."<<G4endl
00206 <<"--gflashemin=N : minimum energy for gflash shower parameterisation in GeV. Default 0.1."<<G4endl
00207 <<"--help : display this message"<<G4endl
00208 <<"--verbose : display general parameters before run"<<G4endl
00209 <<"--verbose_event : display information for every event "<<G4endl
00210 <<"--verbose_step : display tracking information after each step"<<G4endl
00211 <<"--verbose_event_num=N : display tracking information for event number N"<<G4endl
00212 <<"--batch : batch mode - no graphics"<<G4endl
00213 <<"--outline=<file> : print geometry info to <file>"<<G4endl
00214 <<"--outline_type=<fmt> : type of outline format"<<G4endl
00215 <<" where fmt = optics | survey"<<G4endl
00216 <<"--materials : list materials included in bdsim by default"<<G4endl;
00217 }
00218
00219 void BDSExecOptions::Print() {
00220 G4cout << __METHOD_NAME__ << G4endl;
00221 G4cout << __METHOD_NAME__ << std::setw(23) << " inputFilename: " << std::setw(15) << inputFilename << G4endl;
00222 G4cout << __METHOD_NAME__ << std::setw(23) << " visMacroFilename: " << std::setw(15) << visMacroFilename << G4endl;
00223 G4cout << __METHOD_NAME__ << std::setw(23) << " outputFilename: " << std::setw(15) << outputFilename << G4endl;
00224 G4cout << __METHOD_NAME__ << std::setw(23) << " outputFormat: " << std::setw(15) << outputFormat << G4endl;
00225 G4cout << __METHOD_NAME__ << std::setw(23) << " outlineFilename: " << std::setw(15) << outlineFilename << G4endl;
00226 G4cout << __METHOD_NAME__ << std::setw(23) << " gflash: " << std::setw(15) << gflash << G4endl;
00227 G4cout << __METHOD_NAME__ << std::setw(23) << " gflashemin: " << std::setw(15) << gflashemin << G4endl;
00228 G4cout << __METHOD_NAME__ << std::setw(23) << " gflashemax: " << std::setw(15) << gflashemax << G4endl;
00229 G4cout << __METHOD_NAME__ << std::setw(23) << " verbose: " << std::setw(15) << verbose << G4endl;
00230 G4cout << __METHOD_NAME__ << std::setw(23) << " verboseEvent: " << std::setw(15) << verboseEvent << G4endl;
00231 G4cout << __METHOD_NAME__ << std::setw(23) << " verboseStep: " << std::setw(15) << verboseStep << G4endl;
00232 G4cout << __METHOD_NAME__ << std::setw(23) << " batch: " << std::setw(15) << batch << G4endl;
00233 G4cout << __METHOD_NAME__ << std::setw(23) << " outline: " << std::setw(15) << outline << G4endl;
00234 G4cout << __METHOD_NAME__ << std::setw(23) << " listMaterials: " << std::setw(15) << listMaterials << G4endl;
00235 G4cout << __METHOD_NAME__ << std::setw(23) << " verboseRunLevel: " << std::setw(15) << verboseRunLevel << G4endl;
00236 G4cout << __METHOD_NAME__ << std::setw(23) << " verboseEventLevel: " << std::setw(15) << verboseEventLevel << G4endl;
00237 G4cout << __METHOD_NAME__ << std::setw(23) << " verboseTrackingLevel: "<< std::setw(15) << verboseTrackingLevel<< G4endl;
00238 G4cout << __METHOD_NAME__ << std::setw(23) << " verboseSteppingLevel: "<< std::setw(15) << verboseSteppingLevel<< G4endl;
00239
00240 return;
00241 }