goptions
define_options.cc
Go to the documentation of this file.
1 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2 
3 // goptions
4 #include "goptions.h"
5 
6 // c++
7 #include <iostream>
8 
9 using namespace std;
10 
11 // returns this example options
12 GOptions defineOptions() {
13 
15  string help;
16 
17  // command line switch
18  goptions.defineSwitch("log", "a switch, this is just an example.");
19 
20  // runno: 12,
21  help = "Example: -runno=12\n";
22  goptions.defineOption(GVariable("runno", 1, "sets the run number"), help);
23 
24  // nthreads: 8
25  help = "If not set, use all available threads. 0: use all threads\n";
26  help = "Example: -nthreads=12\n";
27  goptions.defineOption(GVariable("nthreads", 0, "number of threads"), help);
28 
29  vector <GVariable> gparticle = {
30  {"name", goptions::NODFLT, "particle name"},
31  {"multiplicity", 1, "number of particles per event"},
32  {"p", goptions::NODFLT, "momentum"},
33  {"theta", "0*degrees", "polar angle"},
34  {"delta_theta", 0, "Particle polar angle range, centered on theta. Default: 0"},
35 
36  };
37 
38  help = "Example to add three particles, one electron and two protons, identical except spread in theta: \n \n";
39  help += "-gparticle=\"[{pname: e-, multiplicity: 1, p: 2300, theta: 23.0}, {pname: proton, multiplicity: 2, p: 1200, theta: 14.0, delta_theta: 10}]\"\n";
40  goptions.defineOption("gparticle", "define the generator particle(s)", gparticle, help);
41 
42  return goptions;
43 }
44 
45 // Define options
46 int main(int argc, char *argv[]) {
47 
48  GOptions *gopts = new GOptions(argc, argv, defineOptions());
49 
50  cout << " > Nthreads: " << gopts->getScalarInt("nthreads") << endl;
51 
52  return EXIT_SUCCESS;
53 }
54 
55 #endif
The GOptions class manages command-line options and switches.
Definition: goptions.h:20
int getScalarInt(const string &tag) const
Retrieves the value of a scalar integer option.
Definition: goptions.cc:211
const std::string NODFLT
def main()
Definition: version.py:35
Encapsulates a variable with a name, value, and description.
Definition: goption.h:30