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)
324 free_multiple_field(
unsigned int len,
void *
arg,
char ***
orig)
328 for (
i = 0;
i < len; ++
i)
330 free_string_field(&((*
orig)[
i]));
340 free_multiple_string_field(
unsigned int len,
char ***
arg,
char ***
orig)
344 for (
i = 0;
i < len; ++
i)
346 free_string_field(&((*
arg)[
i]));
347 free_string_field(&((*
orig)[
i]));
349 free_string_field(&((*
arg)[0]));
372 free_string_field (&(args_info->
tree_arg));
373 free_string_field (&(args_info->
tree_orig));
394 clear_given (args_info);
399 write_into_file(FILE *
outfile,
const char *
opt,
const char *
arg,
const char *[])
409 write_multiple_into_file(FILE *
outfile,
int len,
const char *
opt,
char **
arg,
const char *
values[])
413 for (
i = 0;
i < len; ++
i)
429 write_into_file(
outfile,
"help", 0, 0 );
431 write_into_file(
outfile,
"version", 0, 0 );
447 write_into_file(
outfile,
"online", 0, 0 );
456 write_into_file(
outfile,
"lar", 0, 0 );
460 write_into_file(
outfile,
"beamspot", 0, 0 );
468 write_into_file(
outfile,
"xml_collisionlist", 0, 0 );
470 write_into_file(
outfile,
"plots", 0, 0 );
472 write_into_file(
outfile,
"verbose", 0, 0 );
474 write_into_file(
outfile,
"quiet", 0, 0 );
504 cmdline_parser_release (args_info);
509 gengetopt_strdup (
const char *
s)
523 get_multiple_arg_token(
const char *
arg)
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] ==
'\\' &&
576 get_multiple_arg_token_next(
const char *
arg)
583 tok = strchr (
arg,
',');
588 if (*(tok-1) ==
'\\')
591 tok = strchr (tok+1,
',');
597 if (! tok || strlen(tok) == 1)
604 check_multiple_option_occurrences(
const char *prog_name,
unsigned int option_given,
unsigned int min,
unsigned int max,
const char *option_desc);
607 check_multiple_option_occurrences(
const char *prog_name,
unsigned int option_given,
unsigned int min,
unsigned int max,
const char *option_desc)
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;
694 if (
result == EXIT_FAILURE)
706 int result = EXIT_SUCCESS;
708 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
711 if (
result == EXIT_FAILURE)
721 cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *)
735 if (check_multiple_option_occurrences(prog_name, args_info->
xml_given, args_info->
xml_min, args_info->
xml_max,
"'--xml' ('-x')"))
738 if (check_multiple_option_occurrences(prog_name, args_info->
tag_given, args_info->
tag_min, args_info->
tag_max,
"'--tag' ('-T')"))
741 if (check_multiple_option_occurrences(prog_name, args_info->
root_given, args_info->
root_min, args_info->
root_max,
"'--root'"))
754 static char *package_name = 0;
775 int update_arg(
void *
field,
char **orig_field,
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)
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",
797 package_name, long_opt, short_opt,
798 (additional_error ? additional_error :
""));
800 fprintf (
stderr,
"%s: `--%s' option given more than once%s\n",
801 package_name, long_opt,
802 (additional_error ? additional_error :
""));
806 if (field_given && *field_given && !
override)
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);
830 *string_field = gengetopt_strdup (
val);
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) {
862 *orig_field = gengetopt_strdup (
value);
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;
891 multi_token = get_multiple_arg_token(
val);
892 multi_next = get_multiple_arg_token_next (
val);
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);
906 multi_token = get_multiple_arg_token(multi_next);
907 multi_next = get_multiple_arg_token_next (multi_next);
927 if (string_arg &&
list->arg.string_arg)
928 free (
list->arg.string_arg);
941 void update_multiple_arg(
void *
field,
char ***orig_field,
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));
994 if (! *((
double **)
field)) {
995 double *
pd = (
double *)
malloc (
sizeof (
double));
1003 if (! *((
char ***)
field)) {
1004 char **
pc = (
char **)
malloc (
sizeof (
char *));
1007 (*((
char ***)
field))[0] = gengetopt_strdup(default_value->
string_arg);
1013 if (!(*orig_field)) {
1014 char **
pc = (
char **)
malloc (
sizeof (
char *));
1017 (*orig_field)[0] = 0;
1025 cmdline_parser_internal (
1044 int check_ambiguity;
1046 package_name =
argv[0];
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;
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 },
1107 exit (EXIT_SUCCESS);
1111 if (update_multiple_arg_temp(&runnumber_list,
1112 &(local_args_info.runnumber_given), optarg, 0, 0,
ARG_STRING,
1120 if (update_multiple_arg_temp(&xml_list,
1121 &(local_args_info.xml_given), optarg, 0, 0,
ARG_STRING,
1129 if (update_multiple_arg_temp(&
tag_list,
1130 &(local_args_info.tag_given), optarg, 0, 0,
ARG_STRING,
1138 if (update_multiple_arg_temp(&trigger_list,
1139 &(local_args_info.trigger_given), optarg, 0, 0,
ARG_STRING,
1149 &(local_args_info.verbose_given), optarg, 0, 0,
ARG_FLAG,
1150 check_ambiguity,
override, 1, 0,
"verbose",
'V',
1160 exit (EXIT_SUCCESS);
1167 if (update_multiple_arg_temp(&lbstart_list,
1168 &(local_args_info.lbstart_given), optarg, 0, 0,
ARG_INT,
1178 if (update_multiple_arg_temp(&lbend_list,
1179 &(local_args_info.lbend_given), optarg, 0, 0,
ARG_INT,
1192 &(local_args_info.xml_blacklist_given), optarg, 0, 0,
ARG_STRING,
1193 check_ambiguity,
override, 0, 0,
1194 "xml_blacklist",
'-',
1203 if (update_multiple_arg_temp(&root_list,
1204 &(local_args_info.root_given), optarg, 0, 0,
ARG_STRING,
1215 if (update_arg( (
void *)&(args_info->
tree_arg),
1217 &(local_args_info.tree_given), optarg, 0, 0,
ARG_STRING,
1218 check_ambiguity,
override, 0, 0,
1231 &(local_args_info.d3pd_dir_given), optarg, 0, 0,
ARG_STRING,
1232 check_ambiguity,
override, 0, 0,
1243 if (update_arg( (
void *)&(args_info->
lumitag_arg),
1245 &(local_args_info.lumitag_given), optarg, 0,
"OflLumi-8TeV-002",
ARG_STRING,
1246 check_ambiguity,
override, 0, 0,
1258 &(local_args_info.online_given), optarg, 0, 0,
ARG_FLAG,
1259 check_ambiguity,
override, 1, 0,
"online",
'-',
1271 &(local_args_info.lumichannel_given), optarg, 0,
"0",
ARG_INT,
1272 check_ambiguity,
override, 0, 0,
1285 &(local_args_info.lumimethod_given), optarg, 0,
"ATLAS_PREFERRED",
ARG_STRING,
1286 check_ambiguity,
override, 0, 0,
1299 &(local_args_info.livetrigger_given), optarg, 0,
"L1_EM30",
ARG_STRING,
1300 check_ambiguity,
override, 0, 0,
1312 &(local_args_info.lar_given), optarg, 0, 0,
ARG_FLAG,
1313 check_ambiguity,
override, 1, 0,
"lar",
'-',
1323 if (update_arg( (
void *)&(args_info->
lartag_arg),
1325 &(local_args_info.lartag_given), optarg, 0,
"LARBadChannelsOflEventVeto-UPD4-01",
ARG_STRING,
1326 check_ambiguity,
override, 0, 0,
1338 &(local_args_info.beamspot_given), optarg, 0, 0,
ARG_FLAG,
1339 check_ambiguity,
override, 1, 0,
"beamspot",
'-',
1351 &(local_args_info.beamspottag_given), optarg, 0,
"IndetBeamposOnl-HLT-UPD1-001-00",
ARG_STRING,
1352 check_ambiguity,
override, 0, 0,
1365 &(local_args_info.scale_lumi_given), optarg, 0,
"1.0",
ARG_DOUBLE,
1366 check_ambiguity,
override, 0, 0,
1377 if (update_arg( (
void *)&(args_info->
xml_out_arg),
1379 &(local_args_info.xml_out_given), optarg, 0, 0,
ARG_STRING,
1380 check_ambiguity,
override, 0, 0,
1387 else if (strcmp (
long_options[option_index].
name,
"xml_collisionlist") == 0)
1392 &(local_args_info.xml_collisionlist_given), optarg, 0, 0,
ARG_FLAG,
1393 check_ambiguity,
override, 1, 0,
"xml_collisionlist",
'-',
1404 &(local_args_info.plots_given), optarg, 0, 0,
ARG_FLAG,
1405 check_ambiguity,
override, 1, 0,
"plots",
'-',
1416 &(local_args_info.quiet_given), optarg, 0, 0,
ARG_FLAG,
1417 check_ambiguity,
override, 1, 0,
"quiet",
'-',
1437 local_args_info.runnumber_given, 0,
1439 update_multiple_arg((
void *)&(args_info->
lbstart_arg),
1441 local_args_info.lbstart_given, 0,
1443 update_multiple_arg((
void *)&(args_info->
lbend_arg),
1445 local_args_info.lbend_given, 0,
1447 update_multiple_arg((
void *)&(args_info->
xml_arg),
1449 local_args_info.xml_given, 0,
1451 update_multiple_arg((
void *)&(args_info->
tag_arg),
1453 local_args_info.tag_given, 0,
1455 update_multiple_arg((
void *)&(args_info->
root_arg),
1457 local_args_info.root_given, 0,
1459 update_multiple_arg((
void *)&(args_info->
trigger_arg),
1461 local_args_info.trigger_given, 0,
1465 local_args_info.runnumber_given = 0;
1467 local_args_info.lbstart_given = 0;
1468 args_info->
lbend_given += local_args_info.lbend_given;
1469 local_args_info.lbend_given = 0;
1470 args_info->
xml_given += local_args_info.xml_given;
1471 local_args_info.xml_given = 0;
1472 args_info->
tag_given += local_args_info.tag_given;
1473 local_args_info.tag_given = 0;
1474 args_info->
root_given += local_args_info.root_given;
1475 local_args_info.root_given = 0;
1477 local_args_info.trigger_given = 0;
1481 error += cmdline_parser_required2 (args_info,
argv[0], additional_error);
1484 cmdline_parser_release (&local_args_info);
1487 return (EXIT_FAILURE);
1492 free_list (runnumber_list, 1 );
1493 free_list (lbstart_list, 0 );
1494 free_list (lbend_list, 0 );
1495 free_list (xml_list, 1 );
1497 free_list (root_list, 1 );
1498 free_list (trigger_list, 1 );
1500 cmdline_parser_release (&local_args_info);
1501 return (EXIT_FAILURE);