00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00026
00027 #include "options.h"
00028 #include <string.h>
00029 #include <getopt.h>
00030 #include <iostream>
00031
00032 using namespace std;
00033 using namespace siscone;
00034
00035 #define N_DEFAULT -1
00036 #define R_DEFAULT 0.7
00037 #define THRESHOLD_DEFAULT 0.5
00038 #define PTMIN_DEFAULT 0.0
00039 #define NPASS_DEFAULT 0
00040 #define DEFAULT_EVENT "events/single-event.dat"
00041 #define SM_DEFAULT SM_pttilde
00042
00043
00044
00045
00046
00047
00048
00049
00050 Coptions::Coptions(){
00051
00052 help_flag=0;
00053 version_flag=0;
00054 verbose_flag=1;
00055
00056
00057 N_stop = N_DEFAULT;
00058 R = R_DEFAULT;
00059 f = THRESHOLD_DEFAULT;
00060 npass = NPASS_DEFAULT;
00061 ev_name = NULL;
00062 SM_var = SM_DEFAULT;
00063 }
00064
00065
00066
00067
00068 Coptions::~Coptions(){
00069 if (ev_name!=NULL)
00070 delete[] ev_name;
00071 }
00072
00073
00074
00075
00076
00077
00078
00079 int Coptions::parse_options(int argc, char **argv){
00080 int opt_param;
00081 int option_index;
00082 bool stop=false;
00083
00084
00085 static struct option siscone_options[]={
00086
00087 {"verbose", no_argument, &verbose_flag, 1},
00088 {"quiet", no_argument, &verbose_flag, 0},
00089 {"help", no_argument, &help_flag , 1},
00090 {"version", no_argument, &version_flag, 1},
00091
00092 {"number", required_argument, NULL, 'N'},
00093 {"radius", required_argument, NULL, 'R'},
00094 {"fraction", required_argument, NULL, 'f'},
00095 {"ptmin", required_argument, NULL, 'p'},
00096 {"npass", required_argument, NULL, 'n'},
00097 {"event", required_argument, NULL, 'e'},
00098 {"sm", required_argument, NULL, 's'},
00099 {0,0,0,0}
00100 };
00101
00102
00103 do{
00104
00105 option_index=0;
00106
00107
00108 opt_param = getopt_long(argc, argv, "hvqN:R:f:p:n:e:s:",
00109 siscone_options, &option_index);
00110
00111
00112 if (opt_param == -1)
00113 stop=true;
00114
00115
00116 switch (opt_param){
00117 case 'h': help_flag = 1; break;
00118 case 'v': verbose_flag = 1; break;
00119 case 'q': verbose_flag = 0; break;
00120 case 'N':
00121 sscanf(optarg, "%d", &N_stop);
00122 if (N_stop<=0){
00123 cout << "Warning: the specified number of particles must be positive. Using default one" << endl;
00124 N_stop = N_DEFAULT;
00125 }
00126 break;
00127 case 'R':
00128 sscanf(optarg, "%lf", &R);
00129 if (R<=0){
00130 cout << "Warning: the specified cone radius must be positive. Using default one" << endl;
00131 R = R_DEFAULT;
00132 }
00133 break;
00134 case 'f':
00135 sscanf(optarg, "%lf", &f);
00136 if ((f<0) || (f>1)){
00137 cout << "Warning: the specified split/merge threshold must be in [0,1]. Using default one" << endl;
00138 f = THRESHOLD_DEFAULT;
00139 }
00140 break;
00141 case 'p':
00142 sscanf(optarg, "%lf", &ptmin);
00143 if (ptmin<0){
00144 cout << "Warning: the specified minimal pT must be non-negative. Using default one" << endl;
00145 ptmin = PTMIN_DEFAULT;
00146 }
00147 break;
00148 case 'n':
00149 sscanf(optarg, "%d", &npass);
00150 if (npass<0){
00151 cout << "Warning: the specified number of passes must be non negative. Using default one" << endl;
00152 npass = NPASS_DEFAULT;
00153 }
00154 break;
00155 case 'e':
00156 if (ev_name==NULL){
00157 ev_name = new char[strlen(optarg)+1];
00158 strcpy(ev_name, optarg);
00159 }
00160 break;
00161 case 's':
00162 char tmp[512];
00163 strcpy(tmp, optarg);
00164 if (strcmp(tmp, "pttilde")==0){
00165 SM_var = SM_pttilde;
00166 } else if (strcmp(tmp, "mt")==0){
00167 SM_var = SM_mt;
00168 } else if (strcmp(tmp, "pt")==0){
00169 SM_var = SM_pt;
00170 } else if (strcmp(tmp, "Et")==0){
00171 SM_var = SM_Et;
00172 } else {
00173 cout << "Warning: the specified varible for split--merge is not valid (should be pttilde, pt, mt or Et). Using pttilde as the default one." << endl;
00174 SM_var = SM_pttilde;
00175 }
00176 break;
00177 case 0:
00178 case -1:
00179 break;
00180 case '?':
00181 fprintf(stderr, "Giving up.\n");
00182 return 1;
00183 break;
00184 default:
00185 if (!help_flag){
00186 fprintf(stderr, "unrecognized option %c. Giving up.\n", opt_param);
00187 return 1;
00188 }
00189 }
00190 } while (!stop);
00191
00192 if (ev_name==NULL){
00193 ev_name = new char[strlen(DEFAULT_EVENT)+1];
00194 strcpy(ev_name, DEFAULT_EVENT);
00195 }
00196
00197 return 0;
00198 }
00199
00200
00201
00202
00203 int Coptions::print_help(){
00204 cout << siscone_package_name() << " " << siscone_version() << endl;
00205 cout << "Usage: " << siscone_package_name() << " <args>" << endl;
00206 cout << endl;
00207 cout << "Here is an exhaustive list of the arguments:" << endl;
00208 cout << "Parameters control (with default values):" << endl;
00209 cout << " -n <val>, --number=<val> : set the maximum number of particles allowed (all)" << endl;
00210 cout << " -R <val>, --radius=<val> : set the radius (" << R_DEFAULT << ")" << endl;
00211 cout << " -f <val>, --fraction=<val>: set the overlap parameter (" << THRESHOLD_DEFAULT << ")" << endl;
00212 cout << " -p <val>, --ptmin=<val> : set the minimal pT for protojets (" << PTMIN_DEFAULT << ")" << endl;
00213 cout << " -n <val>, --npass=<val> : set the maximal number of passes (0 for no limit) (" << NPASS_DEFAULT << ")" << endl;
00214 cout << " -e <val>, --event=<val> : set the event filename (" << DEFAULT_EVENT << ")" << endl;
00215 cout << " -s <val>, --sm=<val> : variable for split--merge: pttilde, mt, pt or Et (pttilde)" << endl;
00216 cout << endl;
00217 cout << "Output flags" << endl;
00218 cout << " --version : show version information" << endl;
00219 cout << " -h, --help : show this message" << endl;
00220 cout << " -v, --verbose: be verbose (on by default)" << endl;
00221 cout << " -q, --quiet : be quiet" << endl;
00222 cout << endl;
00223
00224 return 0;
00225 }
00226
00227
00228
00229
00230 int Coptions::print_version(){
00231 cout << siscone_package_name() << " " << siscone_version() << endl;
00232 cout << "Copyright (C) 2006." << endl;
00233 cout << siscone_package_name() << " comes with NO WARRANTY," << endl;
00234 cout << "to the extent permitted by law." << endl;
00235 cout << "You may redistribute copies of " << siscone_package_name() << endl;
00236 cout << "under the terms of the GNU General Public License." << endl;
00237 cout << "For more information about these matters," << endl;
00238 cout << "see the files named COPYING." << endl;
00239 cout << "Please send bugs or comments to AUTHORS" << endl;
00240
00241 return 0;
00242 }