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