goptions
Loading...
Searching...
No Matches
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
9using namespace std;
10
11// returns this example options
12GOptions 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 = "Maximum number of threads to use.\n";
26 help += "If the number of cores available ncores is less then nthreads, use ncores instead.\n";
27 help += "If not set, use all available threads. 0: use all threads\n";
28 help += "Example: -nthreads=12 : . \n";
29 goptions.defineOption(GVariable("nthreads", 0, "maximum number of threads to use"), help);
30
31 vector <GVariable> gparticle = {
32 {"name", goptions::NODFLT, "particle name"},
33 {"multiplicity", 1, "number of particles per event"},
34 {"p", goptions::NODFLT, "momentum"},
35 {"theta", "0*degrees", "polar angle"},
36 {"delta_theta", 0, "Particle polar angle range, centered on theta. Default: 0"},
37
38 };
39
40 help = "Example to add three particles, one electron and two protons, identical except spread in theta: \n \n";
41 help += "-gparticle=\"[{pname: e-, multiplicity: 1, p: 2300, theta: 23.0}, {pname: proton, multiplicity: 2, p: 1200, theta: 14.0, delta_theta: 10}]\"\n";
42 goptions.defineOption("gparticle", "define the generator particle(s)", gparticle, help);
43
44 return goptions;
45}
46
47// Define options
48int main(int argc, char *argv[]) {
49
50 auto gopts = std::make_shared<GOptions>(argc, argv, defineOptions());
51
52 cout << " > Nthreads: " << gopts->getScalarInt("nthreads") << endl;
53
54 return EXIT_SUCCESS;
55}
56
57#endif
The GOptions class manages command-line options and switches.
Definition goptions.h:24
const std::string NODFLT
main()
Definition version.py:33
Encapsulates a variable with a name, value, and description.
Definition goption.h:24