goptions
Loading...
Searching...
No Matches
define_options.cc
Go to the documentation of this file.
1
20// goptions
21#include "goptions.h"
22
23// c++
24#include <iostream>
25
26using namespace std;
27
57 string help;
58
59 // command line switch
60 goptions.defineSwitch("log", "a switch, this is just an example.");
61
62 // runno: 12,
63 help = "Example: -runno=12\n";
64 goptions.defineOption(GVariable("runno", 1, "sets the run number"), help);
65
66 // nthreads: 8
67 help = "Maximum number of threads to use.\n";
68 help += "If the number of cores available ncores is less then nthreads, use ncores instead.\n";
69 help += "If not set, use all available threads. 0: use all threads\n";
70 help += "Example: -nthreads=12 : . \n";
71 goptions.defineOption(GVariable("nthreads", 0, "maximum number of threads to use"), help);
72
73 vector<GVariable> gparticle = {
74 {"name", goptions::NODFLT, "particle name"},
75 {"multiplicity", 1, "number of particles per event"},
76 {"p", goptions::NODFLT, "momentum"},
77 {"theta", "0*degrees", "polar angle"},
78 {"delta_theta", 0, "Particle polar angle range, centered on theta. Default: 0"},
79 };
80
81 help = "Example to add three particles, one electron and two protons, identical except spread in theta : \n \n";
82 help +=
83 "-gparticle=\"[{pname: e-, p: 2300, theta: 23.0}, {pname: proton, multiplicity: 2, p: 1200, delta_theta: 10}]\"\n";
84 goptions.defineOption("gparticle", "define the generator particle(s)", gparticle, help);
85
86 return goptions;
87}
88
116int main(int argc, char* argv[]) {
117 // Construct a parsing instance: this will parse YAML files and command-line arguments immediately.
118 auto gopts = std::make_shared<GOptions>(argc, argv, defineOptions());
119
120 // Typed access: retrieve a scalar integer option.
121 cout << " > Nthreads: " << gopts->getScalarInt("nthreads") << endl;
122
123 return EXIT_SUCCESS;
124}
125
Parses, stores, and exposes command-line options and YAML configuration values.
Definition goptions.h:46
GOptions defineOptions()
Builds and returns a set of example options (definitions only).
Public interface for GOptions : the YAML + command-line configuration manager.
const std::string NODFLT
Marker literal indicating "no default value" for a structured option key.
int main(int argc, char *argv[])
Describes a schema entry: key name, default value, and user-facing description.
Definition goption.h:34