34 " -h, --help Print help and exit",
35 " --version Print version and exit",
36 "\nFlags to specify data sample:",
37 " -r, --runnumber=STRING Run number, range, or comma separated list, e.g. \n 177986-178109,179710",
38 " --lbstart=INT LumiBlock number begin",
39 " --lbend=INT LumiBlock number end",
40 " -x, --xml=STRING Input XML file name",
41 " --xml_blacklist=STRING Input XML file of blacklist",
42 " -T, --tag=STRING Input TAG file name",
43 " --root=STRING Input ROOT file name",
44 " --tree=STRING Name of TTree in input ROOT file to which Lumi \n string is attached",
45 " --d3pd_dir=STRING Name of TDirectory in input ROOT file where Lumi \n string is stored",
46 "\nFlags to control luminosity calculation:",
47 " --lumitag=STRING Offline luminosity database tag \n (default=`OflLumi-8TeV-002')",
48 " --online Use online luminosity estimates instead of \n offline database (default=off)",
49 " --lumichannel=INT Luminosity estimate method by value \n (default=`0')",
50 " --lumimethod=STRING Luminosity estimate method by string \n (default=`ATLAS_PREFERRED')",
51 " -t, --trigger=STRING Trigger chain name used for prescale calculation",
52 " --livetrigger=STRING L1 Trigger used for livetime calculation \n (default=`L1_EM30')",
53 " --lar Calculate LAr defect fraction (default=off)",
54 " --lartag=STRING LAr noise burst database tag \n (default=`LARBadChannelsOflEventVeto-UPD4-01')",
55 " --beamspot Require online beamspot valid in trigger \n livefraction (default=off)",
56 " --beamspottag=STRING Online beamspot database tag \n (default=`IndetBeamposOnl-HLT-UPD1-001-00')",
57 " --scale_lumi=DOUBLE Scale luminosity with a constant value \n (default=`1.0')",
58 "\nFlags to control output:",
59 " --xml_out=STRING Output XML file name",
60 " --xml_collisionlist Output XML file of lists of collision candidates \n (default=off)",
61 " --plots Create some plots on demand (default=off)",
62 " -V, --verbose Verbose output level (default=off)",
63 " --quiet Quiet output level (default=off)",
264 params->override = 0;
265 params->initialize = 1;
266 params->check_required = 1;
267 params->check_ambiguity = 0;
268 params->print_errors = 1;
313 new_node->
next = *list;
328 for (i = 0; i < len; ++i)
344 for (i = 0; i < len; ++i)
402 fprintf(outfile,
"%s=\"%s\"\n", opt,
arg);
404 fprintf(outfile,
"%s\n", opt);
413 for (i = 0; i < len; ++i)
487 outfile = fopen(filename,
"w");
515 result = (
char*)malloc(strlen(s) + 1);
527 size_t len, num_of_escape, i, j;
532 tok = strchr (
arg,
',');
538 if (*(tok-1) ==
'\\')
541 tok = strchr (tok+1,
',');
549 len = (size_t)(tok -
arg + 1);
551 len = strlen (
arg) + 1;
553 len -= num_of_escape;
555 ret = (
char *) malloc (len);
560 while (
arg[i] && (j < len-1))
562 if (
arg[i] ==
'\\' &&
583 tok = strchr (
arg,
',');
588 if (*(tok-1) ==
'\\')
591 tok = strchr (tok+1,
',');
597 if (! tok || strlen(tok) == 1)
611 if (option_given && (
min > 0 ||
max > 0))
618 if (option_given != (
unsigned int)
min)
620 fprintf (stderr,
"%s: %s option occurrences must be %u\n",
621 prog_name, option_desc,
min);
625 else if (option_given < (
unsigned int)
min
626 || option_given > (
unsigned int)
max)
629 fprintf (stderr,
"%s: %s option occurrences must be between %u and %u\n",
630 prog_name, option_desc,
min,
max);
637 if (option_given <
min)
639 fprintf (stderr,
"%s: %s option occurrences must be at least %u\n",
640 prog_name, option_desc,
min);
647 if (option_given >
max)
649 fprintf (stderr,
"%s: %s option occurrences must be at most %u\n",
650 prog_name, option_desc,
max);
671 if (
result == EXIT_FAILURE)
686 params.override =
override;
689 params.check_ambiguity = 0;
690 params.print_errors = 1;
694 if (
result == EXIT_FAILURE)
706 int result = EXIT_SUCCESS;
711 if (
result == EXIT_FAILURE)
776 unsigned int *field_given,
unsigned int *prev_given,
777 char *value,
const char *possible_values[],
781 int no_free,
int multiple_option,
782 const char *long_opt,
char short_opt,
783 const char *additional_error)
786 const char *val = value;
793 if (!multiple_option && field_given && prev_given && (*prev_given || (
check_ambiguity && *field_given)))
795 if (short_opt !=
'-')
796 fprintf (stderr,
"%s: `--%s' (`-%c') option given more than once%s\n",
798 (additional_error ? additional_error :
""));
800 fprintf (stderr,
"%s: `--%s' option given more than once%s\n",
802 (additional_error ? additional_error :
""));
806 if (field_given && *field_given && !
override)
813 val = possible_values[found];
817 *((
int *)field) = !*((
int *)field);
820 if (val) *((
int *)field) = strtol (val, &stop_char, 0);
823 if (val) *((
double *)field) = strtod (val, &stop_char);
827 string_field = (
char **)field;
828 if (!no_free && *string_field)
829 free (*string_field);
841 if (val && !(stop_char && *stop_char ==
'\0')) {
842 fprintf(stderr,
"%s: invalid numeric value: %s\n",
package_name, val);
856 if (value && orig_field) {
876 unsigned int *prev_given,
const char *val,
877 const char *possible_values[],
const char *default_value,
879 const char *long_opt,
char short_opt,
880 const char *additional_error)
884 const char *multi_next;
897 if (
update_arg((
void *)&((*list)->arg), &((*list)->orig), 0,
898 prev_given, multi_token, possible_values, default_value,
899 arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {
900 if (multi_token) free(multi_token);
927 if (string_arg && list->arg.string_arg)
928 free (list->arg.string_arg);
942 unsigned int field_given,
unsigned int prev_given,
union generic_value *default_value,
949 if (prev_given && list) {
950 *orig_field = (
char **) realloc (*orig_field, (field_given + prev_given) *
sizeof (
char *));
954 *((
int **)field) = (
int *)realloc (*((
int **)field), (field_given + prev_given) *
sizeof (
int));
break;
956 *((
double **)field) = (
double *)realloc (*((
double **)field), (field_given + prev_given) *
sizeof (
double));
break;
958 *((
char ***)field) = (
char **)realloc (*((
char ***)field), (field_given + prev_given) *
sizeof (
char *));
break;
963 for (i = (prev_given - 1); i >= 0; --i)
969 (*((
int **)field))[i + field_given] = tmp->arg.int_arg;
break;
971 (*((
double **)field))[i + field_given] = tmp->arg.double_arg;
break;
973 (*((
char ***)field))[i + field_given] = tmp->arg.string_arg;
break;
977 (*orig_field) [i + field_given] = list->orig;
982 if (default_value && ! field_given) {
985 if (! *((
int **)field)) {
986 int*
pi = (
int *)malloc (
sizeof (
int));
988 *((
int **)field) =
pi;
989 (*((
int **)field))[0] = default_value->
int_arg;
994 if (! *((
double **)field)) {
995 double * pd = (
double *)malloc (
sizeof (
double));
997 *((
double **)field) = pd;
998 (*((
double **)field))[0] = default_value->
double_arg;
1003 if (! *((
char ***)field)) {
1004 char ** pc = (
char **)malloc (
sizeof (
char *));
1006 *((
char ***)field) = pc;
1013 if (!(*orig_field)) {
1014 char ** pc = (
char **)malloc (
sizeof (
char *));
1017 (*orig_field)[0] = 0;
1044 int check_ambiguity;
1048 override = params->override;
1050 check_required = params->check_required;
1051 check_ambiguity = params->check_ambiguity;
1060 opterr = params->print_errors;
1065 int option_index = 0;
1067 static struct option long_options[] = {
1068 {
"help", 0, NULL,
'h' },
1069 {
"version", 0, NULL, 0 },
1070 {
"runnumber", 1, NULL,
'r' },
1071 {
"lbstart", 1, NULL, 0 },
1072 {
"lbend", 1, NULL, 0 },
1073 {
"xml", 1, NULL,
'x' },
1074 {
"xml_blacklist", 1, NULL, 0 },
1075 {
"tag", 1, NULL,
'T' },
1076 {
"root", 1, NULL, 0 },
1077 {
"tree", 1, NULL, 0 },
1078 {
"d3pd_dir", 1, NULL, 0 },
1079 {
"lumitag", 1, NULL, 0 },
1080 {
"online", 0, NULL, 0 },
1081 {
"lumichannel", 1, NULL, 0 },
1082 {
"lumimethod", 1, NULL, 0 },
1083 {
"trigger", 1, NULL,
't' },
1084 {
"livetrigger", 1, NULL, 0 },
1085 {
"lar", 0, NULL, 0 },
1086 {
"lartag", 1, NULL, 0 },
1087 {
"beamspot", 0, NULL, 0 },
1088 {
"beamspottag", 1, NULL, 0 },
1089 {
"scale_lumi", 1, NULL, 0 },
1090 {
"xml_out", 1, NULL, 0 },
1091 {
"xml_collisionlist", 0, NULL, 0 },
1092 {
"plots", 0, NULL, 0 },
1093 {
"verbose", 0, NULL,
'V' },
1094 {
"quiet", 0, NULL, 0 },
1098 c = getopt_long (argc, argv,
"hr:x:T:t:V", long_options, &option_index);
1107 exit (EXIT_SUCCESS);
1150 check_ambiguity,
override, 1, 0,
"verbose",
'V',
1157 if (strcmp (long_options[option_index].name,
"version") == 0) {
1160 exit (EXIT_SUCCESS);
1164 if (strcmp (long_options[option_index].name,
"lbstart") == 0)
1175 else if (strcmp (long_options[option_index].name,
"lbend") == 0)
1186 else if (strcmp (long_options[option_index].name,
"xml_blacklist") == 0)
1193 check_ambiguity,
override, 0, 0,
1194 "xml_blacklist",
'-',
1200 else if (strcmp (long_options[option_index].name,
"root") == 0)
1211 else if (strcmp (long_options[option_index].name,
"tree") == 0)
1218 check_ambiguity,
override, 0, 0,
1225 else if (strcmp (long_options[option_index].name,
"d3pd_dir") == 0)
1232 check_ambiguity,
override, 0, 0,
1239 else if (strcmp (long_options[option_index].name,
"lumitag") == 0)
1246 check_ambiguity,
override, 0, 0,
1253 else if (strcmp (long_options[option_index].name,
"online") == 0)
1259 check_ambiguity,
override, 1, 0,
"online",
'-',
1265 else if (strcmp (long_options[option_index].name,
"lumichannel") == 0)
1272 check_ambiguity,
override, 0, 0,
1279 else if (strcmp (long_options[option_index].name,
"lumimethod") == 0)
1286 check_ambiguity,
override, 0, 0,
1293 else if (strcmp (long_options[option_index].name,
"livetrigger") == 0)
1300 check_ambiguity,
override, 0, 0,
1307 else if (strcmp (long_options[option_index].name,
"lar") == 0)
1313 check_ambiguity,
override, 1, 0,
"lar",
'-',
1319 else if (strcmp (long_options[option_index].name,
"lartag") == 0)
1326 check_ambiguity,
override, 0, 0,
1333 else if (strcmp (long_options[option_index].name,
"beamspot") == 0)
1339 check_ambiguity,
override, 1, 0,
"beamspot",
'-',
1345 else if (strcmp (long_options[option_index].name,
"beamspottag") == 0)
1352 check_ambiguity,
override, 0, 0,
1359 else if (strcmp (long_options[option_index].name,
"scale_lumi") == 0)
1366 check_ambiguity,
override, 0, 0,
1373 else if (strcmp (long_options[option_index].name,
"xml_out") == 0)
1380 check_ambiguity,
override, 0, 0,
1387 else if (strcmp (long_options[option_index].name,
"xml_collisionlist") == 0)
1393 check_ambiguity,
override, 1, 0,
"xml_collisionlist",
'-',
1399 else if (strcmp (long_options[option_index].name,
"plots") == 0)
1405 check_ambiguity,
override, 1, 0,
"plots",
'-',
1411 else if (strcmp (long_options[option_index].name,
"quiet") == 0)
1417 check_ambiguity,
override, 1, 0,
"quiet",
'-',
1429 fprintf (stderr,
"%s: option unknown: %c%s\n",
CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error :
""));
1487 return (EXIT_FAILURE);
1501 return (EXIT_FAILURE);
Define macros for attributes used to control the static checker.
#define ATLAS_NO_CHECK_FILE_THREAD_SAFETY
static int update_multiple_arg_temp(struct generic_list **list, unsigned int *prev_given, const char *val, const char *possible_values[], const char *default_value, cmdline_parser_arg_type arg_type, const char *long_opt, char short_opt, const char *additional_error)
store information about a multiple option in a temporary list
static char * get_multiple_arg_token(const char *arg)
static char * package_name
static char * gengetopt_strdup(const char *s)
replacement of strdup, which is not standard
int cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
Save the contents of the option struct into an already open FILE stream.
static void free_multiple_string_field(unsigned int len, char ***arg, char ***orig)
static void add_node(struct generic_list **list)
add a node at the head of the list
static void free_string_field(char **s)
int cmdline_parser(int argc, char **argv, struct gengetopt_args_info *args_info)
The command line parser.
static void clear_given(struct gengetopt_args_info *args_info)
static void update_multiple_arg(void *field, char ***orig_field, unsigned int field_given, unsigned int prev_given, union generic_value *default_value, cmdline_parser_arg_type arg_type, struct generic_list *list)
updates a multiple option starting from the passed list
static void clear_args(struct gengetopt_args_info *args_info)
static void init_args_info(struct gengetopt_args_info *args_info)
static void free_multiple_field(unsigned int len, void *arg, char ***orig)
The passed arg parameter is NOT set to 0 from this function.
int cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
Save the contents of the option struct into a (text) file.
const char * gengetopt_args_info_purpose
the purpose string of the program
static void write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[])
const char * gengetopt_args_info_help[]
all the lines making the help output
int cmdline_parser2(int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
The command line parser (version with additional parameters - deprecated)
int cmdline_parser_required(struct gengetopt_args_info *args_info, const char *prog_name)
Checks that all the required options were specified.
static void free_list(struct generic_list *list, short string_arg)
free the passed list (including possible string argument)
static int check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc)
void cmdline_parser_print_version(void)
Print the version.
struct cmdline_parser_params * cmdline_parser_params_create(void)
Allocates dynamically a cmdline_parser_params structure and initializes all its fields to their defau...
const char * gengetopt_args_info_usage
the usage string of the program
int cmdline_parser_ext(int argc, char **argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params)
The command line parser (version with additional parameters)
void cmdline_parser_init(struct gengetopt_args_info *args_info)
Initializes the passed gengetopt_args_info structure's fields (also set default values for options th...
const char * gengetopt_args_info_description
static void cmdline_parser_release(struct gengetopt_args_info *args_info)
static int cmdline_parser_internal(int argc, char **argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params, const char *additional_error)
void cmdline_parser_print_help(void)
Print the help.
static void print_help_common(void)
static int cmdline_parser_required2(struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
static const char * get_multiple_arg_token_next(const char *arg)
static void write_into_file(FILE *outfile, const char *opt, const char *arg, const char *[])
static int update_arg(void *field, char **orig_field, unsigned int *field_given, unsigned int *prev_given, char *value, const char *possible_values[], const char *, cmdline_parser_arg_type arg_type, int check_ambiguity, int override, int no_free, int multiple_option, const char *long_opt, char short_opt, const char *additional_error)
updates an option
void cmdline_parser_free(struct gengetopt_args_info *args_info)
Deallocates the string fields of the gengetopt_args_info structure (but does not deallocate the struc...
void cmdline_parser_params_init(struct cmdline_parser_params *params)
Initializes all the fields a cmdline_parser_params structure to their default values.
The header file for the command line option parser generated by GNU Gengetopt version 2....
#define CMDLINE_PARSER_VERSION
the program version
#define CMDLINE_PARSER_PACKAGE_NAME
the complete program name (used for help and version)
#define CMDLINE_PARSER_PACKAGE
the program name (used for printing errors)
The additional parameters to pass to parser functions.
int check_required
whether to check that all required options were provided (default 1)
int check_ambiguity
whether to check for options already specified in the option structure gengetopt_args_info (default 0...
holds temporary values for multiple options
struct generic_list * next
Where the command line options are stored.
char * lumimethod_arg
Luminosity estimate method by string (default='ATLAS_PREFERRED').
char * lumichannel_orig
Luminosity estimate method by value original value given at command line.
int lar_flag
Calculate LAr defect fraction (default=off).
char * lumitag_orig
Offline luminosity database tag original value given at command line.
char ** lbend_orig
LumiBlock number end original value given at command line.
char * lartag_orig
LAr noise burst database tag original value given at command line.
unsigned int runnumber_min
Run number, range, or comma separated list, e.g.
const char * xml_collisionlist_help
Output XML file of lists of collision candidates help description.
const char * lumitag_help
Offline luminosity database tag help description.
char ** runnumber_arg
Run number, range, or comma separated list, e.g.
const char * lartag_help
LAr noise burst database tag help description.
const char * plots_help
Create some plots on demand help description.
const char * verbose_help
Verbose output level help description.
char * tree_orig
Name of TTree in input ROOT file to which Lumi string is attached original value given at command lin...
char * livetrigger_orig
L1 Trigger used for livetime calculation original value given at command line.
char * lumitag_arg
Offline luminosity database tag (default='OflLumi-8TeV-002').
char * lumimethod_orig
Luminosity estimate method by string original value given at command line.
int online_flag
Use online luminosity estimates instead of offline database (default=off).
char ** root_arg
Input ROOT file name.
unsigned int lbstart_min
LumiBlock number begin's minimum occurreces.
char * tree_arg
Name of TTree in input ROOT file to which Lumi string is attached.
const char * lumichannel_help
Luminosity estimate method by value help description.
const char * tree_help
Name of TTree in input ROOT file to which Lumi string is attached help description.
int quiet_flag
Quiet output level (default=off).
unsigned int lar_given
Whether lar was given.
unsigned int xml_max
Input XML file name's maximum occurreces.
char ** xml_arg
Input XML file name.
unsigned int root_given
Whether root was given.
char * d3pd_dir_arg
Name of TDirectory in input ROOT file where Lumi string is stored.
unsigned int xml_out_given
Whether xml_out was given.
const char * lumimethod_help
Luminosity estimate method by string help description.
unsigned int tree_given
Whether tree was given.
const char * runnumber_help
Run number, range, or comma separated list, e.g.
char ** lbstart_orig
LumiBlock number begin original value given at command line.
char * lartag_arg
LAr noise burst database tag (default='LARBadChannelsOflEventVeto-UPD4-01').
double scale_lumi_arg
Scale luminosity with a constant value (default='1.0').
int * lbstart_arg
LumiBlock number begin.
unsigned int beamspottag_given
Whether beamspottag was given.
char * xml_out_arg
Output XML file name.
unsigned int lbend_given
Whether lbend was given.
const char * lbstart_help
LumiBlock number begin help description.
const char * beamspot_help
Require online beamspot valid in trigger livefraction help description.
unsigned int livetrigger_given
Whether livetrigger was given.
unsigned int lbend_min
LumiBlock number end's minimum occurreces.
int lumichannel_arg
Luminosity estimate method by value (default='0').
unsigned int xml_given
Whether xml was given.
unsigned int lumimethod_given
Whether lumimethod was given.
const char * root_help
Input ROOT file name help description.
unsigned int scale_lumi_given
Whether scale_lumi was given.
unsigned int plots_given
Whether plots was given.
int * lbend_arg
LumiBlock number end.
unsigned int xml_collisionlist_given
Whether xml_collisionlist was given.
unsigned int lbend_max
LumiBlock number end's maximum occurreces.
unsigned int lbstart_max
LumiBlock number begin's maximum occurreces.
char ** runnumber_orig
Run number, range, or comma separated list, e.g.
const char * d3pd_dir_help
Name of TDirectory in input ROOT file where Lumi string is stored help description.
const char * scale_lumi_help
Scale luminosity with a constant value help description.
const char * lbend_help
LumiBlock number end help description.
const char * beamspottag_help
Online beamspot database tag help description.
char * xml_out_orig
Output XML file name original value given at command line.
char ** trigger_arg
Trigger chain name used for prescale calculation.
const char * quiet_help
Quiet output level help description.
char ** tag_arg
Input TAG file name.
unsigned int xml_blacklist_given
Whether xml_blacklist was given.
int verbose_flag
Verbose output level (default=off).
unsigned int lumichannel_given
Whether lumichannel was given.
const char * trigger_help
Trigger chain name used for prescale calculation help description.
char * beamspottag_arg
Online beamspot database tag (default='IndetBeamposOnl-HLT-UPD1-001-00').
const char * lar_help
Calculate LAr defect fraction help description.
unsigned int trigger_given
Whether trigger was given.
unsigned int lbstart_given
Whether lbstart was given.
unsigned int runnumber_given
Whether runnumber was given.
char * livetrigger_arg
L1 Trigger used for livetime calculation (default='L1_EM30').
unsigned int runnumber_max
Run number, range, or comma separated list, e.g.
unsigned int tag_max
Input TAG file name's maximum occurreces.
unsigned int help_given
Whether help was given.
const char * online_help
Use online luminosity estimates instead of offline database help description.
char ** root_orig
Input ROOT file name original value given at command line.
const char * xml_help
Input XML file name help description.
unsigned int trigger_min
Trigger chain name used for prescale calculation's minimum occurreces.
int xml_collisionlist_flag
Output XML file of lists of collision candidates (default=off).
unsigned int tag_min
Input TAG file name's minimum occurreces.
unsigned int lartag_given
Whether lartag was given.
int plots_flag
Create some plots on demand (default=off).
unsigned int xml_min
Input XML file name's minimum occurreces.
unsigned int quiet_given
Whether quiet was given.
unsigned int tag_given
Whether tag was given.
unsigned int trigger_max
Trigger chain name used for prescale calculation's maximum occurreces.
int beamspot_flag
Require online beamspot valid in trigger livefraction (default=off).
unsigned int root_min
Input ROOT file name's minimum occurreces.
unsigned int d3pd_dir_given
Whether d3pd_dir was given.
char * d3pd_dir_orig
Name of TDirectory in input ROOT file where Lumi string is stored original value given at command lin...
unsigned int version_given
Whether version was given.
unsigned int lumitag_given
Whether lumitag was given.
unsigned int root_max
Input ROOT file name's maximum occurreces.
char * scale_lumi_orig
Scale luminosity with a constant value original value given at command line.
char ** tag_orig
Input TAG file name original value given at command line.
char ** xml_orig
Input XML file name original value given at command line.
const char * version_help
Print version and exit help description.
unsigned int verbose_given
Whether verbose was given.
const char * xml_blacklist_help
Input XML file of blacklist help description.
const char * tag_help
Input TAG file name help description.
char ** trigger_orig
Trigger chain name used for prescale calculation original value given at command line.
char * xml_blacklist_orig
Input XML file of blacklist original value given at command line.
const char * livetrigger_help
L1 Trigger used for livetime calculation help description.
unsigned int beamspot_given
Whether beamspot was given.
unsigned int online_given
Whether online was given.
const char * xml_out_help
Output XML file name help description.
const char * help_help
Print help and exit help description.
char * xml_blacklist_arg
Input XML file of blacklist.
char * beamspottag_orig
Online beamspot database tag original value given at command line.
const char * default_string_arg