NAIA  1.0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
cli_options.h
Go to the documentation of this file.
1 #include <TROOT.h>
2 #include <argp.h>
3 
4 #ifndef _PARSER_
5 #define _PARSER_
6 
7 static int parse_opt(int key, char *arg, struct argp_state *state);
8 
9 // -- Global variables
10 struct argp_option options[] = {{"overwrite", 'w', 0, 0, "Overwrite results"},
11  {"verbosity", 'v', "LEVEL", 0, "Verbosity level [Info, Debug, Trace]"},
12  {"input-file", 'i', "FILE", 0, "Input file"},
13  {"output-file", 'o', "FILE", 0, "Output file"},
14  {"event", 'E', "INT", 0, "Process Single Event"},
15  {"from-event", 'e', "INT", 0, "Process from Event"},
16  {"nevents", 'n', "INT", 0, "Process # events"},
17  {0}};
18 struct argp argp = {options, parse_opt, 0, 0};
19 
20 struct arguments {
21  const char *infilename;
22  const char *outfilename;
23  const char *recotype;
24  const char *debug_level;
26  bool flag_input;
28  int event;
30  int nevents;
31 };
32 
33 static int parse_opt(int key, char *arg, struct argp_state *state) {
34 
35  struct arguments *a = (struct arguments *)state->input;
36 
37  switch (key) {
38  case 'w': {
39  a->flag_overwrite = kTRUE;
40  break;
41  }
42  case 'v': {
43  a->debug_level = arg;
44  break;
45  }
46  case 'i': {
47  a->flag_input = kTRUE;
48  a->infilename = arg;
49  break;
50  }
51  case 'o': {
52  a->flag_output = kTRUE;
53  a->outfilename = arg;
54  break;
55  }
56  case 'E': {
57  a->event = atoi(arg);
58  break;
59  }
60  case 'e': {
61  a->from_event = atoi(arg);
62  break;
63  }
64  case 'n': {
65  a->nevents = atoi(arg);
66  break;
67  }
68  case ARGP_KEY_ARG: {
69  argp_failure(state, 1, 0, "No arguments requested");
70  break;
71  }
72  case ARGP_KEY_INIT: {
73  a->infilename = nullptr;
74  a->outfilename = nullptr;
75  a->debug_level = "Info";
76  a->flag_overwrite = kFALSE;
77  a->flag_input = kFALSE;
78  a->flag_output = kFALSE;
79  a->event = -1;
80  a->from_event = -1;
81  a->nevents = -1;
82  break;
83  }
84  case ARGP_KEY_END: {
85  break;
86  }
87  }
88 
89  return 0;
90 }
91 
92 #endif
const char * recotype
Definition: cli_options.h:23
struct argp argp
Definition: cli_options.h:18
bool flag_overwrite
Definition: cli_options.h:25
static int parse_opt(int key, char *arg, struct argp_state *state)
Definition: cli_options.h:33
const char * debug_level
Definition: cli_options.h:24
const char * infilename
Definition: cli_options.h:21
int from_event
Definition: cli_options.h:29
struct argp_option options[]
Definition: cli_options.h:10
bool flag_output
Definition: cli_options.h:27
const char * outfilename
Definition: cli_options.h:22
int nevents
Definition: cli_options.h:30
bool flag_input
Definition: cli_options.h:26