Skip to content

Commit 3ff152d

Browse files
committed
better options and remove root in b2 yaml
1 parent 9220975 commit 3ff152d

12 files changed

Lines changed: 130 additions & 35 deletions

File tree

examples/basic/b2/b2.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,3 @@ gmultipoles:
2828
rotaxis: z
2929
rotation_angle: "30*deg"
3030

31-
root: G4Box, 12*cm, 12*cm, 18*cm, G4_WATER

gemc/eventDispenser/eventDispenser_options.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ GOptions defineOptions() {
2424
goptions.defineOption(GVariable("n", 1, "number of events to process"), help);
2525

2626
// Option: run number
27-
// Clarify that this is the *conditions run number* (constants/TT selection), not the Geant4 internal run id.
28-
help = "Not to be confused with the geant4 run number - g4runno is set automatically \n \n";
27+
// Clarify that this is the *event* run number, distinct from -runno (geometry selection)
28+
// and from the Geant4 internal run id (g4runno, set automatically).
29+
help = "Run number assigned to the generated events; it is also the key looked up in the\n";
30+
help += "-run_weights file. This is distinct from -runno, which selects the geometry/conditions\n";
31+
help += "variation from the database, and from the Geant4 run id g4runno, set automatically.\n \n";
2932
help += "Example: -run=12\n";
30-
goptions.defineOption(GVariable("run", 1, "sets run number"), help);
33+
goptions.defineOption(GVariable("run", 1, "event run number"), help);
3134

3235
// Option: run weights file
3336
help = "Text file with run number and their weights.\n \n";

gemc/g4display/g4display_options.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ GOptions defineOptions() {
161161
goptions.defineOption("g4light", "Defines the geant4 light source direction", g4light, help);
162162

163163
// dawn
164-
help = "Defines the dawn camera view point and take a dawn screenshot \n \n ";
164+
help = "Defines the dawn camera view point and takes a dawn screenshot \n \n ";
165165
help += "Example: -dawn=\"[{phi: 20*deg, theta: 15*deg}]\" \n ";
166166

167167
std::vector<GVariable> dawn = {
168-
{"phi", 30, "dawn phi"},
169-
{"theta", 30, "dawn theta"}
168+
{"phi", "30*deg", "dawn camera phi"},
169+
{"theta", "30*deg", "dawn camera theta"}
170170
};
171171

172172
goptions.defineOption("dawn", "Defines the dawn view point", dawn, help);

gemc/g4system/g4systemDoxy.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@
8282
* - Type: boolean (switch)
8383
* - Meaning: print the materials used by the loaded systems in this simulation
8484
*
85-
* - `checkOverlaps`
86-
* - Type: boolean (switch)
87-
* - Meaning: enable Geant4 overlap checks at construction time (human-readable switch)
88-
* - Note: some code paths use `check_overlaps` (integer) for mode selection; keep these consistent in applications.
85+
* Overlap checking is controlled solely by the integer `check_overlaps` option above.
8986
*
9087
* This module’s option schema is composed by \c g4system::defineOptions(), which aggregates:
9188
* - \c gsystem::defineOptions()

gemc/g4system/g4system_options.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ GOptions defineOptions() {
3737
// Human-readable switches used for diagnostics and validation.
3838
goptions.defineSwitch("showPredefinedMaterials", "log GEMC Predefined Materials");
3939
goptions.defineSwitch("printSystemsMaterials", "print the materials used in this simulation");
40-
goptions.defineSwitch("checkOverlaps", "check geant4 volume overlaps at construction time");
4140

42-
// Overlap checking mode:
41+
// Overlap checking mode (the integer "check_overlaps" option below is the single control):
4342
// - 0 disables overlap checks
4443
// - 1 enables overlap checking at placement time
4544
// - 2 uses Geant4 overlap validator with default surface sampling
4645
// - N>100 uses Geant4 overlap validator with N surface points
4746
help = "Check for overlaps at physical volume construction.\n\n";
4847
help += "Possible values are:\n";
4948
help += " - 0 (default): no check.\n";
50-
help += " - 1: check for overlaps at physical volume construction.\n";
49+
help += " - 1: enable the G4PVPlacement surface overlap check (pSurfChk) at volume placement.\n";
5150
help += " - 2: use the geant4 overlap validator with the default number of points on the surface\n";
52-
help += " - Any N greater than 100: use the geant4 overlap validator with N points on the surface\n";
51+
help += " - Any N greater than 100: use the geant4 overlap validator with N points on the surface\n \n";
52+
help += "Example: -check_overlaps=1\n";
5353
goptions.defineOption(GVariable("check_overlaps", 0, "check overlaps"), help);
5454

5555
return goptions;

gemc/gfields/gfield_options.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ GOptions defineOptions() {
5252
goptions += gfactory::defineOptions();
5353

5454
std::string help;
55-
help = "Adds gmultipoles field(s) to the simulation \n ";
55+
help = "Adds electromagnetic multipole field(s) to the simulation. \n \n";
56+
help += "Mandatory keys: name, pole_number, rotaxis, strength. \n \n";
57+
help += "Example (a quadrupole centered 30 cm downstream): \n";
58+
help += "-gmultipoles=\"[{name: q1, pole_number: 4, rotaxis: Z, strength: 1.2, vz: 30*cm}]\"\n";
5659
std::vector<GVariable> gmultipoles = {
5760
{"name", goptions::NODFLT, "Field name (unique key used by GMagneto maps)"},
5861
{"integration_stepper", GFIELD_DEFAULT_INTEGRATION_STEPPER, "Geant4 integration stepper name (string)"},

gemc/goptions/goptions.cc

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// c++
2323
#include <iostream>
2424
#include <cstring>
25+
#include <cctype>
2526

2627
using namespace std;
2728

@@ -45,15 +46,19 @@ GOptions::GOptions(int argc, char* argv[], const GOptions& user_defined_options)
4546
addGOptions(user_defined_options);
4647

4748
// switches for all everyone
48-
defineSwitch("gui", "use Graphical User Interface");
49-
defineSwitch("i", "use interactive batch mode");
49+
defineSwitch("gui", "run with the graphical user interface (Qt window)");
50+
defineSwitch("i", "drop into the interactive Geant4 terminal session (non-GUI mode)");
5051
defineOption(
51-
GVariable("conf_yaml", "saved_configuration", "the prefix for filename that store the used options"),
52-
"The default value appends \"_saved_configuration\" to the executable name.");
52+
GVariable("conf_yaml", "saved_configuration", "infix for the YAML file that records the resolved options"),
53+
"On exit the resolved configuration is written to <executable>.<conf_yaml>.yaml,\n"
54+
"so the default value produces, for example, gemc.saved_configuration.yaml.\n \n"
55+
"Example: -conf_yaml=run12 -> saves to gemc.run12.yaml\n \n");
5356

5457
// add test timeout for the tests
55-
defineOption(GVariable("tt", 500, "tests timeout (ms)"),
56-
"Timeout in milliseconds for the code tests that have GUI. ");
58+
defineOption(GVariable("tt", 500, "GUI test timeout (ms)"),
59+
"Milliseconds a GUI-based test waits before it auto-closes, so the module\n"
60+
"example/test programs can run unattended in CI.\n \n"
61+
"Example: -tt=1000\n \n");
5762

5863
// version is a special option, not settable by the user
5964
// it is set by the gversion.h file
@@ -72,16 +77,25 @@ GOptions::GOptions(int argc, char* argv[], const GOptions& user_defined_options)
7277
help += " - 0: (default) = shush\n";
7378
help += " - 1: log detailed information\n";
7479
help += " - 2: log extra detailed information\n \n";
75-
help += "Example: -verbosity.gemc=1 \n \n";
76-
help += "The YAML value can include multiple logger keys.\n \n";
80+
help += "Each key names a class or module; run 'help verbosity' to list the available keys.\n \n";
81+
help += "Example (one key): -verbosity.gemc=1\n";
82+
help += "Example (several keys): -verbosity=\"[{gemc: 1}, {<another_key>: 2}]\"\n \n";
83+
help += "Equivalent YAML:\n";
84+
help += " verbosity:\n";
85+
help += " - gemc: 1\n";
86+
help += " - <another_key>: 2\n \n";
7787
defineOption("verbosity", "Sets the log verbosity for various classes", option_verbosity_names, help);
7888

7989
// debug option: boolean or integer, depending on consumer expectations
8090
help = "Debug information Types: \n \n";
8191
help += " - false: (default): do not print debug information\n";
8292
help += " - true: print debug information\n\n";
83-
help += "Example: -debug=\"[{gemc: true}]\" \n \n";
84-
help += "The YAML value can include multiple logger keys.\n \n";
93+
help += "Each key names a class or module; run 'help debug' to list the available keys.\n \n";
94+
help += "Example (on/off): -debug.gemc=true\n";
95+
help += "Example (several keys): -debug=\"[{gemc: true}, {<another_key>: 1}]\"\n \n";
96+
help += "Equivalent YAML:\n";
97+
help += " debug:\n";
98+
help += " - gemc: true\n \n";
8599
defineOption("debug", "Sets the debug level for various classes", option_verbosity_names, help);
86100

87101
// Process help/version command-line arguments.
@@ -105,6 +119,12 @@ GOptions::GOptions(int argc, char* argv[], const GOptions& user_defined_options)
105119
else { printHelp(); }
106120
exit(EXIT_SUCCESS);
107121
}
122+
else if (strcmp(argv[i], "search") == 0) {
123+
// "gemc search <value>" lists options/switches whose name or description contains <value>.
124+
if (i + 1 < argc) { printSearch(argv[i + 1]); }
125+
else { printHelp(); }
126+
exit(EXIT_SUCCESS);
127+
}
108128
}
109129

110130
// finds and parse the yaml files
@@ -295,6 +315,42 @@ void GOptions::printOptionOrSwitchHelp(const std::string& tag) const {
295315
exit(EC__NOOPTIONFOUND);
296316
}
297317

318+
// Private method: see header. Kept undocumented here to avoid duplicate param docs.
319+
void GOptions::printSearch(const std::string& tag) const {
320+
// Case-insensitive substring match against switch/option names and descriptions.
321+
auto to_lower = [](string s) {
322+
transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
323+
return s;
324+
};
325+
const string needle = to_lower(tag);
326+
auto matches = [&](const string& a, const string& b) {
327+
return to_lower(a).find(needle) != string::npos || to_lower(b).find(needle) != string::npos;
328+
};
329+
330+
long int fill_width = string(HELPFILLSPACE).size() + 1;
331+
cout.fill('.');
332+
cout << KGRN << KBOLD << " Options and switches matching \"" << tag << "\":" << RST << endl << endl;
333+
334+
bool found = false;
335+
for (auto& s : switches) {
336+
if (matches(s.first, s.second.getDescription())) {
337+
found = true;
338+
cout << KGRN << " " << left;
339+
cout.width(fill_width);
340+
cout << "-" + s.first + RST + " " << ": " << s.second.getDescription() << endl;
341+
}
342+
}
343+
for (auto& option : goptions) {
344+
if (option.name != GVERSION_STRING && matches(option.name, option.description)) {
345+
found = true;
346+
option.printHelp(false);
347+
}
348+
}
349+
if (!found) { cout << TPOINTITEM << "no match found." << endl; }
350+
cout << endl << " Use " << KGRN << "help <value>" << RST << " for the detailed help of a single option." << endl
351+
<< endl;
352+
}
353+
298354
// Private method: see header. Kept undocumented here to avoid duplicate param docs.
299355
vector<string> GOptions::findYamls(int argc, char* argv[]) {
300356
vector<string> yaml_files;
@@ -523,7 +579,7 @@ void GOptions::printHelp() const {
523579
string("help <value>") + RST,
524580
string("print detailed help for option <value> and exit"),
525581
string("search <value>") + RST,
526-
string("list all options containing <value> in the description and exit\n")
582+
string("list all options/switches whose name or description contains <value> and exit\n")
527583
};
528584
unsigned half_help = helps.size() / 2;
529585
for (unsigned i = 0; i < half_help; i++) {

gemc/goptions/goptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ class GOptions
397397
std::vector<GOption>::iterator getOptionIterator(const std::string& name);
398398
[[nodiscard]] std::vector<GOption>::const_iterator getOptionIterator(const std::string& name) const;
399399
void printOptionOrSwitchHelp(const std::string& tag) const;
400+
void printSearch(const std::string& tag) const;
400401
void printHelp() const;
401402
void printWebHelp() const;
402403
void saveOptions() const;

gemc/gphysics/gphysics_options.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ GOptions defineOptions() {
6060
physicsListHelp += string(HELPFILLSPACE) + " - _PEN to use G4EmPenelopePhysics\n";
6161
physicsListHelp += string(HELPFILLSPACE) + " - _SS to use G4EmStandardPhysicsSS\n";
6262
physicsListHelp += string(HELPFILLSPACE) + " - _WVI to use G4EmStandardPhysicsWVI\n";
63-
physicsListHelp += "\n" + string(HELPFILLSPACE) + "For example, FTFP_BERT_LIV would replace the default e.m. physics with the Livermode model \n\n";
64-
physicsListHelp += "\n" + string(HELPFILLSPACE) + "Additional physics can be loaded by adding its constructor name to the list using the " + " sign\n";
63+
physicsListHelp += "\n" + string(HELPFILLSPACE) + "For example, FTFP_BERT_LIV would replace the default e.m. physics with the Livermore model \n\n";
64+
physicsListHelp += "\n" + string(HELPFILLSPACE) + "Additional physics can be loaded by adding its constructor name to the list using the + sign\n";
6565
physicsListHelp += "\n" + string(HELPFILLSPACE) + "For example: FTFP_BERT + G4OpticalPhysics. The available constructors are: \n\n";
6666
physicsListHelp += string(HELPFILLSPACE) + " - G4ChargeExchangePhysics\n";
6767
physicsListHelp += string(HELPFILLSPACE) + " - G4DecayPhysics\n";
@@ -142,6 +142,9 @@ GOptions defineOptions() {
142142
physicsListHelp += string(HELPFILLSPACE) + " - G4StoppingPhysicsFritiofWithBinaryCascade\n";
143143
physicsListHelp += string(HELPFILLSPACE) + " - G4UnknownDecayPhysics\n";
144144
physicsListHelp += string(HELPFILLSPACE) + " - G4WeightWindowBiasing\n";
145+
physicsListHelp += "\n" + string(HELPFILLSPACE) + "Command-line examples:\n";
146+
physicsListHelp += string(HELPFILLSPACE) + " -phys_list=FTFP_BERT\n";
147+
physicsListHelp += string(HELPFILLSPACE) + " -phys_list=\"FTFP_BERT_EMZ + G4OpticalPhysics\"\n";
145148
goptions.defineOption(GVariable("phys_list", DEFAULTPHYSICSLIST, "Select Physics List"), physicsListHelp);
146149

147150
goptions.defineSwitch("showPhysics", "Log Geant4 Physics Available Modules that can be used with the \"phys_list\" option and exit");

gemc/gstreamer/gstreamer_options.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ GOptions defineOptions() {
6767
// Buffer flush limit:
6868
// controls how many events each streamer instance may retain in memory
6969
// before the base class forces a flush to the backend.
70+
string ebuffer_help = "Number of events each streamer keeps in memory before flushing them to the\n";
71+
ebuffer_help += "output file. Larger values reduce I/O frequency at the cost of more memory.\n \n";
72+
ebuffer_help += "Example: -ebuffer=100\n";
7073
goptions.defineOption(GVariable("ebuffer", DEFAULT_GSTREAMER_BUFFER_FLUSH_LIMIT,
71-
"number of events kept in memory before flushing them to the filestream"), help);
74+
"number of events kept in memory before flushing them to the filestream"), ebuffer_help);
7275

7376
// Schema of each object in the -gstreamer array.
7477
vector<GVariable> gstreamer = {
@@ -77,7 +80,7 @@ GOptions defineOptions() {
7780
{"type", "event", "type of output file"},
7881
};
7982

80-
goptions.defineOption(GSTREAMER_LOGGER, "define a gstreamer output", gstreamer, help);
83+
goptions.defineOption("gstreamer", "define a gstreamer output", gstreamer, help);
8184

8285
// Merge dependent-module options so callers can build a single composite
8386
// GOptions definition for applications and examples.

0 commit comments

Comments
 (0)