|
12 | 12 | #include <TRestRun.h>
|
13 | 13 |
|
14 | 14 | #include <csignal>
|
| 15 | +#include <regex> |
15 | 16 | #ifndef GEANT4_WITHOUT_G4RunManagerFactory
|
16 | 17 | #include <G4RunManagerFactory.hh>
|
17 | 18 | #endif
|
@@ -124,6 +125,17 @@ int GetSecondsFromFullTimeExpression(const char* expression) {
|
124 | 125 | return seconds;
|
125 | 126 | }
|
126 | 127 |
|
| 128 | +int GetNumberFromStringScientific(string& s) { |
| 129 | + // Allows to parse inputs of the form 1E5, 1.5E10 etc. |
| 130 | + regex rgx("^([0-9]+.?([0-9]+)?)E([0-9]+)"); |
| 131 | + std::smatch matches; |
| 132 | + if (std::regex_search(s, matches, rgx)) { |
| 133 | + return int(stod(matches[1].str()) * TMath::Power(10, stoi(matches[3].str()))); |
| 134 | + } else { |
| 135 | + return stoi(s); |
| 136 | + } |
| 137 | +} |
| 138 | + |
127 | 139 | Options ProcessCommandLineOptions(int argc, char* const argv[]) {
|
128 | 140 | Options options;
|
129 | 141 | options.argc = argc;
|
@@ -183,21 +195,22 @@ Options ProcessCommandLineOptions(int argc, char* const argv[]) {
|
183 | 195 | exit(1);
|
184 | 196 | }
|
185 | 197 | } else if ((arg == "-n") || (arg == "--events")) {
|
186 |
| - if (i + 1 < argc) { // Make sure we aren't at the end of argv! |
187 |
| - options.nEvents = |
188 |
| - stoi(argv[++i]); // Increment 'i' so we don't get the argument as the next argv[i]. |
| 198 | + if (i + 1 < argc) { // Make sure we aren't at the end of argv! |
| 199 | + string s = argv[++i]; // Increment 'i' so we don't get the argument as the next argv[i]. |
| 200 | + options.nEvents = GetNumberFromStringScientific(s); |
189 | 201 | if (options.nEvents <= 0) {
|
190 |
| - cout << "--events option error: number of events must be > 0" << endl; |
| 202 | + cout << "--events option error: number of events must be > 0 (input: " << s << ")" |
| 203 | + << endl; |
191 | 204 | exit(1);
|
192 | 205 | }
|
193 | 206 | } else {
|
194 | 207 | cerr << "--events option requires one argument." << endl;
|
195 | 208 | exit(1);
|
196 | 209 | }
|
197 | 210 | } else if ((arg == "-e") || (arg == "--entries")) {
|
198 |
| - if (i + 1 < argc) { // Make sure we aren't at the end of argv! |
199 |
| - options.nRequestedEntries = |
200 |
| - stoi(argv[++i]); // Increment 'i' so we don't get the argument as the next argv[i]. |
| 211 | + if (i + 1 < argc) { // Make sure we aren't at the end of argv! |
| 212 | + string s = argv[++i]; // Increment 'i' so we don't get the argument as the next argv[i]. |
| 213 | + options.nRequestedEntries = GetNumberFromStringScientific(s); |
201 | 214 | if (options.nRequestedEntries <= 0) {
|
202 | 215 | cout << "--entries option error: number of entries must be > 0" << endl;
|
203 | 216 | exit(1);
|
|
0 commit comments