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)",
84 cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *additional_error);
87 gengetopt_strdup (
const char *
s);
142 args_info->
lumitag_arg = gengetopt_strdup (
"OflLumi-8TeV-002");
154 args_info->
lartag_arg = gengetopt_strdup (
"LARBadChannelsOflEventVeto-UPD4-01");
157 args_info->
beamspottag_arg = gengetopt_strdup (
"IndetBeamposOnl-HLT-UPD1-001-00");
227 static void print_help_common(
void) {
254 clear_given (args_info);
255 clear_args (args_info);
256 init_args_info (args_info);
266 params->check_required = 1;
267 params->check_ambiguity = 0;
282 free_string_field (
char **
s)
322 free_multiple_field(
unsigned int len,
void *
arg,
char ***
orig)
326 for (
i = 0;
i < len; ++
i)
328 free_string_field(&((*
orig)[
i]));
338 free_multiple_string_field(
unsigned int len,
char ***
arg,
char ***
orig)
342 for (
i = 0;
i < len; ++
i)
344 free_string_field(&((*
arg)[
i]));
345 free_string_field(&((*
orig)[
i]));
347 free_string_field(&((*
arg)[0]));
370 free_string_field (&(args_info->
tree_arg));
371 free_string_field (&(args_info->
tree_orig));
392 clear_given (args_info);
397 write_into_file(FILE *
outfile,
const char *
opt,
const char *
arg,
const char *[])
407 write_multiple_into_file(FILE *
outfile,
int len,
const char *
opt,
char **
arg,
const char *
values[])
411 for (
i = 0;
i < len; ++
i)
427 write_into_file(
outfile,
"help", 0, 0 );
429 write_into_file(
outfile,
"version", 0, 0 );
445 write_into_file(
outfile,
"online", 0, 0 );
454 write_into_file(
outfile,
"lar", 0, 0 );
458 write_into_file(
outfile,
"beamspot", 0, 0 );
466 write_into_file(
outfile,
"xml_collisionlist", 0, 0 );
468 write_into_file(
outfile,
"plots", 0, 0 );
470 write_into_file(
outfile,
"verbose", 0, 0 );
472 write_into_file(
outfile,
"quiet", 0, 0 );
502 cmdline_parser_release (args_info);
507 gengetopt_strdup (
const char *
s)
521 get_multiple_arg_token(
const char *
arg)
525 size_t len, num_of_escape,
i, j;
530 tok = strchr (
arg,
',');
536 if (*(tok-1) ==
'\\')
539 tok = strchr (tok+1,
',');
547 len = (size_t)(tok -
arg + 1);
549 len = strlen (
arg) + 1;
551 len -= num_of_escape;
553 ret = (
char *)
malloc (len);
557 while (
arg[
i] && (j < len-1))
559 if (
arg[
i] ==
'\\' &&
573 get_multiple_arg_token_next(
const char *
arg)
580 tok = strchr (
arg,
',');
585 if (*(tok-1) ==
'\\')
588 tok = strchr (tok+1,
',');
594 if (! tok || strlen(tok) == 1)
601 check_multiple_option_occurrences(
const char *prog_name,
unsigned int option_given,
unsigned int min,
unsigned int max,
const char *option_desc);
604 check_multiple_option_occurrences(
const char *prog_name,
unsigned int option_given,
unsigned int min,
unsigned int max,
const char *option_desc)
608 if (option_given && (
min > 0 ||
max > 0))
615 if (option_given != (
unsigned int)
min)
617 fprintf (
stderr,
"%s: %s option occurrences must be %u\n",
618 prog_name, option_desc,
min);
622 else if (option_given < (
unsigned int)
min
623 || option_given > (
unsigned int)
max)
626 fprintf (
stderr,
"%s: %s option occurrences must be between %u and %u\n",
627 prog_name, option_desc,
min,
max);
634 if (option_given <
min)
636 fprintf (
stderr,
"%s: %s option occurrences must be at least %u\n",
637 prog_name, option_desc,
min);
644 if (option_given >
max)
646 fprintf (
stderr,
"%s: %s option occurrences must be at most %u\n",
647 prog_name, option_desc,
max);
668 if (
result == EXIT_FAILURE)
683 params.override =
override;
686 params.check_ambiguity = 0;
691 if (
result == EXIT_FAILURE)
703 int result = EXIT_SUCCESS;
705 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
708 if (
result == EXIT_FAILURE)
718 cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *)
732 if (check_multiple_option_occurrences(prog_name, args_info->
xml_given, args_info->
xml_min, args_info->
xml_max,
"'--xml' ('-x')"))
735 if (check_multiple_option_occurrences(prog_name, args_info->
tag_given, args_info->
tag_min, args_info->
tag_max,
"'--tag' ('-T')"))
738 if (check_multiple_option_occurrences(prog_name, args_info->
root_given, args_info->
root_min, args_info->
root_max,
"'--root'"))
751 static char *package_name = 0;
772 int update_arg(
void *
field,
char **orig_field,
773 unsigned int *field_given,
unsigned int *prev_given,
774 char *
value,
const char *possible_values[],
778 int no_free,
int multiple_option,
779 const char *long_opt,
char short_opt,
780 const char *additional_error)
790 if (!multiple_option && field_given && prev_given && (*prev_given || (
check_ambiguity && *field_given)))
792 if (short_opt !=
'-')
793 fprintf (
stderr,
"%s: `--%s' (`-%c') option given more than once%s\n",
794 package_name, long_opt, short_opt,
795 (additional_error ? additional_error :
""));
797 fprintf (
stderr,
"%s: `--%s' option given more than once%s\n",
798 package_name, long_opt,
799 (additional_error ? additional_error :
""));
803 if (field_given && *field_given && !
override)
817 if (
val) *((
int *)
field) = strtol (
val, &stop_char, 0);
820 if (
val) *((
double *)
field) = strtod (
val, &stop_char);
824 string_field = (
char **)
field;
825 if (!no_free && *string_field)
826 free (*string_field);
827 *string_field = gengetopt_strdup (
val);
838 if (
val && !(stop_char && *stop_char ==
'\0')) {
839 fprintf(
stderr,
"%s: invalid numeric value: %s\n", package_name,
val);
853 if (
value && orig_field) {
859 *orig_field = gengetopt_strdup (
value);
873 unsigned int *prev_given,
const char *
val,
874 const char *possible_values[],
const char *default_value,
876 const char *long_opt,
char short_opt,
877 const char *additional_error)
881 const char *multi_next;
888 multi_token = get_multiple_arg_token(
val);
889 multi_next = get_multiple_arg_token_next (
val);
894 if (update_arg((
void *)&((*list)->arg), &((*list)->orig), 0,
895 prev_given, multi_token, possible_values, default_value,
896 arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {
897 if (multi_token) free(multi_token);
903 multi_token = get_multiple_arg_token(multi_next);
904 multi_next = get_multiple_arg_token_next (multi_next);
924 if (string_arg &&
list->arg.string_arg)
925 free (
list->arg.string_arg);
938 void update_multiple_arg(
void *
field,
char ***orig_field,
939 unsigned int field_given,
unsigned int prev_given,
union generic_value *default_value,
946 if (prev_given &&
list) {
947 *orig_field = (
char **) realloc (*orig_field, (field_given + prev_given) *
sizeof (
char *));
951 *((
int **)
field) = (
int *)realloc (*((
int **)
field), (field_given + prev_given) *
sizeof (
int));
break;
953 *((
double **)
field) = (
double *)realloc (*((
double **)
field), (field_given + prev_given) *
sizeof (
double));
break;
955 *((
char ***)
field) = (
char **)realloc (*((
char ***)
field), (field_given + prev_given) *
sizeof (
char *));
break;
960 for (
i = (prev_given - 1);
i >= 0; --
i)
966 (*((
int **)
field))[
i + field_given] =
tmp->arg.int_arg;
break;
968 (*((
double **)
field))[
i + field_given] =
tmp->arg.double_arg;
break;
970 (*((
char ***)
field))[
i + field_given] =
tmp->arg.string_arg;
break;
974 (*orig_field) [
i + field_given] =
list->orig;
979 if (default_value && ! field_given) {
982 if (! *((
int **)
field)) {
988 if (! *((
double **)
field)) {
989 *((
double **)
field) = (
double *)
malloc (
sizeof (
double));
994 if (! *((
char ***)
field)) {
995 *((
char ***)
field) = (
char **)
malloc (
sizeof (
char *));
1001 if (!(*orig_field)) {
1002 *orig_field = (
char **)
malloc (
sizeof (
char *));
1003 (*orig_field)[0] = 0;
1010 cmdline_parser_internal (
1029 int check_ambiguity;
1031 package_name =
argv[0];
1033 override =
params->override;
1035 check_required =
params->check_required;
1036 check_ambiguity =
params->check_ambiguity;
1045 opterr =
params->print_errors;
1050 int option_index = 0;
1053 {
"help", 0, NULL,
'h' },
1054 {
"version", 0, NULL, 0 },
1055 {
"runnumber", 1, NULL,
'r' },
1056 {
"lbstart", 1, NULL, 0 },
1057 {
"lbend", 1, NULL, 0 },
1058 {
"xml", 1, NULL,
'x' },
1059 {
"xml_blacklist", 1, NULL, 0 },
1060 {
"tag", 1, NULL,
'T' },
1061 {
"root", 1, NULL, 0 },
1062 {
"tree", 1, NULL, 0 },
1063 {
"d3pd_dir", 1, NULL, 0 },
1064 {
"lumitag", 1, NULL, 0 },
1065 {
"online", 0, NULL, 0 },
1066 {
"lumichannel", 1, NULL, 0 },
1067 {
"lumimethod", 1, NULL, 0 },
1068 {
"trigger", 1, NULL,
't' },
1069 {
"livetrigger", 1, NULL, 0 },
1070 {
"lar", 0, NULL, 0 },
1071 {
"lartag", 1, NULL, 0 },
1072 {
"beamspot", 0, NULL, 0 },
1073 {
"beamspottag", 1, NULL, 0 },
1074 {
"scale_lumi", 1, NULL, 0 },
1075 {
"xml_out", 1, NULL, 0 },
1076 {
"xml_collisionlist", 0, NULL, 0 },
1077 {
"plots", 0, NULL, 0 },
1078 {
"verbose", 0, NULL,
'V' },
1079 {
"quiet", 0, NULL, 0 },
1092 exit (EXIT_SUCCESS);
1096 if (update_multiple_arg_temp(&runnumber_list,
1097 &(local_args_info.runnumber_given), optarg, 0, 0,
ARG_STRING,
1105 if (update_multiple_arg_temp(&xml_list,
1106 &(local_args_info.xml_given), optarg, 0, 0,
ARG_STRING,
1114 if (update_multiple_arg_temp(&
tag_list,
1115 &(local_args_info.tag_given), optarg, 0, 0,
ARG_STRING,
1123 if (update_multiple_arg_temp(&trigger_list,
1124 &(local_args_info.trigger_given), optarg, 0, 0,
ARG_STRING,
1134 &(local_args_info.verbose_given), optarg, 0, 0,
ARG_FLAG,
1135 check_ambiguity,
override, 1, 0,
"verbose",
'V',
1145 exit (EXIT_SUCCESS);
1152 if (update_multiple_arg_temp(&lbstart_list,
1153 &(local_args_info.lbstart_given), optarg, 0, 0,
ARG_INT,
1163 if (update_multiple_arg_temp(&lbend_list,
1164 &(local_args_info.lbend_given), optarg, 0, 0,
ARG_INT,
1177 &(local_args_info.xml_blacklist_given), optarg, 0, 0,
ARG_STRING,
1178 check_ambiguity,
override, 0, 0,
1179 "xml_blacklist",
'-',
1188 if (update_multiple_arg_temp(&root_list,
1189 &(local_args_info.root_given), optarg, 0, 0,
ARG_STRING,
1200 if (update_arg( (
void *)&(args_info->
tree_arg),
1202 &(local_args_info.tree_given), optarg, 0, 0,
ARG_STRING,
1203 check_ambiguity,
override, 0, 0,
1216 &(local_args_info.d3pd_dir_given), optarg, 0, 0,
ARG_STRING,
1217 check_ambiguity,
override, 0, 0,
1228 if (update_arg( (
void *)&(args_info->
lumitag_arg),
1230 &(local_args_info.lumitag_given), optarg, 0,
"OflLumi-8TeV-002",
ARG_STRING,
1231 check_ambiguity,
override, 0, 0,
1243 &(local_args_info.online_given), optarg, 0, 0,
ARG_FLAG,
1244 check_ambiguity,
override, 1, 0,
"online",
'-',
1256 &(local_args_info.lumichannel_given), optarg, 0,
"0",
ARG_INT,
1257 check_ambiguity,
override, 0, 0,
1270 &(local_args_info.lumimethod_given), optarg, 0,
"ATLAS_PREFERRED",
ARG_STRING,
1271 check_ambiguity,
override, 0, 0,
1284 &(local_args_info.livetrigger_given), optarg, 0,
"L1_EM30",
ARG_STRING,
1285 check_ambiguity,
override, 0, 0,
1297 &(local_args_info.lar_given), optarg, 0, 0,
ARG_FLAG,
1298 check_ambiguity,
override, 1, 0,
"lar",
'-',
1308 if (update_arg( (
void *)&(args_info->
lartag_arg),
1310 &(local_args_info.lartag_given), optarg, 0,
"LARBadChannelsOflEventVeto-UPD4-01",
ARG_STRING,
1311 check_ambiguity,
override, 0, 0,
1323 &(local_args_info.beamspot_given), optarg, 0, 0,
ARG_FLAG,
1324 check_ambiguity,
override, 1, 0,
"beamspot",
'-',
1336 &(local_args_info.beamspottag_given), optarg, 0,
"IndetBeamposOnl-HLT-UPD1-001-00",
ARG_STRING,
1337 check_ambiguity,
override, 0, 0,
1350 &(local_args_info.scale_lumi_given), optarg, 0,
"1.0",
ARG_DOUBLE,
1351 check_ambiguity,
override, 0, 0,
1362 if (update_arg( (
void *)&(args_info->
xml_out_arg),
1364 &(local_args_info.xml_out_given), optarg, 0, 0,
ARG_STRING,
1365 check_ambiguity,
override, 0, 0,
1372 else if (strcmp (
long_options[option_index].
name,
"xml_collisionlist") == 0)
1377 &(local_args_info.xml_collisionlist_given), optarg, 0, 0,
ARG_FLAG,
1378 check_ambiguity,
override, 1, 0,
"xml_collisionlist",
'-',
1389 &(local_args_info.plots_given), optarg, 0, 0,
ARG_FLAG,
1390 check_ambiguity,
override, 1, 0,
"plots",
'-',
1401 &(local_args_info.quiet_given), optarg, 0, 0,
ARG_FLAG,
1402 check_ambiguity,
override, 1, 0,
"quiet",
'-',
1422 local_args_info.runnumber_given, 0,
1424 update_multiple_arg((
void *)&(args_info->
lbstart_arg),
1426 local_args_info.lbstart_given, 0,
1428 update_multiple_arg((
void *)&(args_info->
lbend_arg),
1430 local_args_info.lbend_given, 0,
1432 update_multiple_arg((
void *)&(args_info->
xml_arg),
1434 local_args_info.xml_given, 0,
1436 update_multiple_arg((
void *)&(args_info->
tag_arg),
1438 local_args_info.tag_given, 0,
1440 update_multiple_arg((
void *)&(args_info->
root_arg),
1442 local_args_info.root_given, 0,
1444 update_multiple_arg((
void *)&(args_info->
trigger_arg),
1446 local_args_info.trigger_given, 0,
1450 local_args_info.runnumber_given = 0;
1452 local_args_info.lbstart_given = 0;
1453 args_info->
lbend_given += local_args_info.lbend_given;
1454 local_args_info.lbend_given = 0;
1455 args_info->
xml_given += local_args_info.xml_given;
1456 local_args_info.xml_given = 0;
1457 args_info->
tag_given += local_args_info.tag_given;
1458 local_args_info.tag_given = 0;
1459 args_info->
root_given += local_args_info.root_given;
1460 local_args_info.root_given = 0;
1462 local_args_info.trigger_given = 0;
1466 error += cmdline_parser_required2 (args_info,
argv[0], additional_error);
1469 cmdline_parser_release (&local_args_info);
1472 return (EXIT_FAILURE);
1477 free_list (runnumber_list, 1 );
1478 free_list (lbstart_list, 0 );
1479 free_list (lbend_list, 0 );
1480 free_list (xml_list, 1 );
1482 free_list (root_list, 1 );
1483 free_list (trigger_list, 1 );
1485 cmdline_parser_release (&local_args_info);
1486 return (EXIT_FAILURE);