-
Notifications
You must be signed in to change notification settings - Fork 453
/
Copy pathSimConfig.cxx
580 lines (539 loc) · 26.3 KB
/
SimConfig.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include <SimConfig/SimConfig.h>
#include <SimConfig/DetectorLists.h>
#include <DetectorsCommonDataFormats/DetID.h>
#include <SimulationDataFormat/DigitizationContext.h>
#include <boost/program_options.hpp>
#include <iostream>
#include <fairlogger/Logger.h>
#include <thread>
#include <cmath>
#include <chrono>
#include <regex>
using namespace o2::conf;
namespace bpo = boost::program_options;
void SimConfig::initOptions(boost::program_options::options_description& options, bool isUpgrade)
{
// some default args might depend on whether Run3 or Run5
// can be updated here:
std::string defaultGeomList{"ALICE2"};
if (isUpgrade == true) {
defaultGeomList = "ALICE3";
}
int nsimworkersdefault = std::max(1u, std::thread::hardware_concurrency() / 2);
options.add_options()(
"mcEngine,e", bpo::value<std::string>()->default_value("TGeant4"), "VMC backend to be used.")(
"generator,g", bpo::value<std::string>()->default_value("boxgen"), "Event generator to be used.")(
"trigger,t", bpo::value<std::string>()->default_value(""), "Event generator trigger to be used.")(
"modules,m", bpo::value<std::vector<std::string>>()->multitoken()->default_value(std::vector<std::string>({"all"}), "all modules"), "list of modules included in geometry")(
"skipModules", bpo::value<std::vector<std::string>>()->multitoken()->default_value(std::vector<std::string>({""}), ""), "list of modules excluded in geometry (precendence over -m")(
"readoutDetectors", bpo::value<std::vector<std::string>>()->multitoken()->default_value(std::vector<std::string>(), ""), "list of detectors creating hits, all if not given; added to to active modules")(
"skipReadoutDetectors", bpo::value<std::vector<std::string>>()->multitoken()->default_value(std::vector<std::string>(), ""), "list of detectors to skip hit creation (precendence over --readoutDetectors")(
"detectorList", bpo::value<std::string>()->default_value(defaultGeomList),
"Use a specific version of ALICE, e.g., a predefined list."
"There is an 'official' list provided with:"
"\nALICE2 : The default configuration for Run 3"
"\nALICE2.1: The future configuration for Run 4"
"\nALICE3 : The far-future configuration for Run 5-6"
"\nAdditionally one can provide their own custom list of modules which should be included in the geometry."
"\nBy specifiying LIST:JSONFILE where LIST is a list present in JSONFILE.")(
"nEvents,n", bpo::value<unsigned int>()->default_value(0), "number of events")(
"startEvent", bpo::value<unsigned int>()->default_value(0), "index of first event to be used (when applicable)")(
"extKinFile", bpo::value<std::string>()->default_value("Kinematics.root"),
"name of kinematics file for event generator from file (when applicable)")(
"embedIntoFile", bpo::value<std::string>()->default_value(""),
"filename containing the reference events to be used for the embedding")(
"bMax,b", bpo::value<float>()->default_value(0.), "maximum value for impact parameter sampling (when applicable)")(
"isMT", bpo::value<bool>()->default_value(false), "multi-threaded mode (Geant4 only")(
"outPrefix,o", bpo::value<std::string>()->default_value("o2sim"), "prefix of output files")(
"logseverity", bpo::value<std::string>()->default_value("INFO"), "severity level for FairLogger")(
"logverbosity", bpo::value<std::string>()->default_value("medium"), "level of verbosity for FairLogger (low, medium, high, veryhigh)")(
"configKeyValues", bpo::value<std::string>()->default_value(""), "semicolon separated key=value strings (e.g.: 'TPC.gasDensity=1;...")(
"configFile", bpo::value<std::string>()->default_value(""), "Path to an INI or JSON configuration file")(
"chunkSize", bpo::value<unsigned int>()->default_value(500), "max size of primary chunk (subevent) distributed by server")(
"chunkSizeI", bpo::value<int>()->default_value(-1), "internalChunkSize")(
"seed", bpo::value<ULong_t>()->default_value(0), "initial seed as ULong_t (default: 0 == random)")(
"field", bpo::value<std::string>()->default_value("-5"), "L3 field rounded to kGauss, allowed values +-2,+-5 and 0; +-<intKGaus>U for uniform field; \"ccdb\" for taking it from CCDB ")("vertexMode", bpo::value<std::string>()->default_value("kDiamondParam"), "Where the beam-spot vertex should come from. Must be one of kNoVertex, kDiamondParam, kCCDB")(
"nworkers,j", bpo::value<int>()->default_value(nsimworkersdefault), "number of parallel simulation workers (only for parallel mode)")(
"noemptyevents", "only writes events with at least one hit")(
"CCDBUrl", bpo::value<std::string>()->default_value("http://alice-ccdb.cern.ch"), "URL for CCDB to be used.")(
"timestamp", bpo::value<uint64_t>(), "global timestamp value in ms (for anchoring) - default is now ... or beginning of run if ALICE run number was given")(
"run", bpo::value<int>()->default_value(-1), "ALICE run number")(
"asservice", bpo::value<bool>()->default_value(false), "run in service/server mode")(
"noGeant", bpo::bool_switch(), "prohibits any Geant transport/physics (by using tight cuts)")(
"forwardKine", bpo::bool_switch(), "forward kinematics on a FairMQ channel")(
"noDiscOutput", bpo::bool_switch(), "switch off writing sim results to disc (useful in combination with forwardKine)");
options.add_options()("fromCollContext", bpo::value<std::string>()->default_value(""), "Use a pregenerated collision context to infer number of events to simulate, how to embedd them, the vertex position etc. Takes precedence of other options such as \"--nEvents\". The format is COLLISIONCONTEXTFILE.root[:SIGNALNAME] where SIGNALNAME is the event part in the context which is relevant.");
}
void SimConfig::determineActiveModules(std::vector<std::string> const& inputargs, std::vector<std::string> const& skippedModules, std::vector<std::string>& activeModules, bool isUpgrade)
{
using o2::detectors::DetID;
// input args is a vector of module strings as obtained from the -m,--modules options
// of SimConfig
activeModules = inputargs;
#ifdef ENABLE_UPGRADES
if (activeModules[0] != "all") {
if (isUpgrade) {
for (int i = 0; i < activeModules.size(); ++i) {
if (activeModules[i] != "A3IP" &&
activeModules[i] != "IT3" &&
activeModules[i] != "TRK" &&
activeModules[i] != "FT3" &&
activeModules[i] != "FCT" &&
activeModules[i] != "TF3" &&
activeModules[i] != "RCH" &&
activeModules[i] != "MI3" &&
activeModules[i] != "ECL" &&
activeModules[i] != "FD") {
LOGP(fatal, "List of active modules contains {}, which is not a module from the upgrades.", activeModules[i]);
}
}
}
if (!isUpgrade) {
for (int i = 0; i < activeModules.size(); ++i) {
if (activeModules[i] == "A3IP" ||
activeModules[i] == "TRK" ||
activeModules[i] == "FT3" ||
activeModules[i] == "FCT" ||
activeModules[i] == "TF3" ||
activeModules[i] == "RCH" ||
activeModules[i] == "MI3" ||
activeModules[i] == "ECL" ||
activeModules[i] == "FD") {
LOGP(fatal, "List of active modules contains {}, which is not a run 3 module", activeModules[i]);
}
}
}
}
#endif
if (activeModules.size() == 1 && activeModules[0] == "all") {
activeModules.clear();
#ifdef ENABLE_UPGRADES
if (isUpgrade) {
for (int d = DetID::First; d <= DetID::Last; ++d) {
if (d == DetID::TRK ||
d == DetID::FT3 ||
d == DetID::FCT ||
d == DetID::TF3 ||
d == DetID::RCH ||
d == DetID::ECL ||
d == DetID::FD ||
d == DetID::MI3) {
activeModules.emplace_back(DetID::getName(d));
}
}
activeModules.emplace_back("A3IP");
activeModules.emplace_back("A3ABSO");
activeModules.emplace_back("A3MAG");
} else {
#endif
// add passive components manually (make a PassiveDetID for them!)
activeModules.emplace_back("HALL");
activeModules.emplace_back("MAG");
activeModules.emplace_back("DIPO");
activeModules.emplace_back("COMP");
activeModules.emplace_back("PIPE");
activeModules.emplace_back("ABSO");
activeModules.emplace_back("SHIL");
for (int d = DetID::First; d <= DetID::Last; ++d) {
#ifdef ENABLE_UPGRADES
if (d != DetID::IT3 && d != DetID::TRK && d != DetID::FT3 && d != DetID::FCT && d != DetID::TF3 && d != DetID::RCH && d != DetID::ECL && d != DetID::FD && d != DetID::MI3) {
activeModules.emplace_back(DetID::getName(d));
}
}
#else
activeModules.emplace_back(DetID::getName(d));
#endif
}
}
filterSkippedElements(activeModules, skippedModules);
}
bool SimConfig::determineActiveModulesList(const std::string& version, std::vector<std::string> const& inputargs, std::vector<std::string> const& skippedModules, std::vector<std::string>& activeModules)
{
DetectorList_t modules;
DetectorMap_t map;
if (auto pos = version.find(':'); pos != std::string::npos) {
auto pversion = version.substr(0, pos);
auto ppath = version.substr(pos + 1);
if (!parseDetectorMapfromJSON(ppath, map)) {
LOGP(error, "Could not parse {}; check errors above!", ppath);
return false;
}
if (map.find(pversion) == map.end()) {
LOGP(error, "List {} is not defined in custom JSON file!", pversion);
printDetMap(map);
return false;
}
modules = map[pversion];
LOGP(info, "Running with version {} from custom detector list '{}'", pversion, ppath);
} else {
// Otherwise check 'official' versions which provided in config
auto o2env = std::getenv("O2_ROOT");
if (!o2env) {
LOGP(error, "O2_ROOT environment not defined");
return false;
}
const std::string rootpath(fmt::format("{}/share/config/o2simdefaultdetectorlist.json", o2env));
if (!parseDetectorMapfromJSON(rootpath, map)) {
LOGP(error, "Could not parse {} -> check errors above!", rootpath);
return false;
}
if (map.find(version) == map.end()) {
LOGP(error, "List {} is not defined in 'official' JSON file!", version);
printDetMap(map);
return false;
}
modules = map[version];
LOGP(info, "Running with official detector version '{}'", version);
}
// check if specified modules are in list
if (inputargs.size() != 1 || inputargs[0] != "all") {
std::vector<std::string> diff;
for (const auto& in : inputargs) {
if (std::find(modules.begin(), modules.end(), in) == std::end(modules)) {
diff.emplace_back(in);
}
}
if (!diff.empty()) {
LOGP(error, "Modules specified that are not present in detector list {}", version);
for (int j{0}; const auto& m : diff) {
LOGP(info, " - {: <2}. {}", j++, m);
}
printDetMap(map, version);
return false;
}
}
// Insert into active modules if module is built buy -m or insert all if default for -m is used ("all")
std::copy_if(modules.begin(), modules.end(), std::back_inserter(activeModules),
[&inputargs](const auto& e) { return (inputargs.size() == 1 && inputargs[0] == "all") || (std::find(inputargs.begin(), inputargs.end(), e) != inputargs.end()); });
return filterSkippedElements(activeModules, skippedModules);
}
void SimConfig::determineReadoutDetectors(std::vector<std::string> const& activeModules, std::vector<std::string> const& enableReadout, std::vector<std::string> const& disableReadout, std::vector<std::string>& readoutDetectors)
{
using o2::detectors::DetID;
readoutDetectors.clear();
auto isDet = [](std::string const& s) {
return DetID::nameToID(s.c_str()) >= DetID::First;
};
if (enableReadout.empty()) {
// if no readout explicitly given, use all detectors from active modules
for (auto& am : activeModules) {
if (!isDet(am)) {
// either we found a passive module or one with disabled readout ==> skip
continue;
}
readoutDetectors.emplace_back(am);
}
} else {
for (auto& er : enableReadout) {
if (!isDet(er)) {
// either we found a passive module or one with disabled readout ==> skip
LOG(fatal) << "Enabled readout for " << er << " which is not a detector.";
}
if (std::find(activeModules.begin(), activeModules.end(), er) == activeModules.end()) {
// add to active modules if not yet there
LOG(fatal) << "Module " << er << " not constructed and cannot be used for readout (make sure it is contained in -m option).";
}
readoutDetectors.emplace_back(er);
}
}
for (auto& dr : disableReadout) {
if (!isDet(dr)) {
// either we found a passive module or one with disabled readout ==> skip
LOG(fatal) << "Disabled readout for " << dr << " which is not a detector.";
}
if (std::find(activeModules.begin(), activeModules.end(), dr) == activeModules.end()) {
// add to active modules if not yet there
LOG(fatal) << "Module " << dr << " not constructed, makes no sense to disable its readout (make sure it is contained in -m option).";
}
auto iter = std::find(readoutDetectors.begin(), readoutDetectors.end(), dr);
if (iter != readoutDetectors.end()) {
readoutDetectors.erase(iter);
}
}
}
std::pair<std::string, std::string> SimConfig::getCollContextFilenameAndEventPrefix() const
{
// we decompose the argument to fetch
// (a) collision contextfilename
// (b) sim prefix to use from the context
auto pos = mConfigData.mFromCollisionContext.find(':');
std::string collcontextfile{mConfigData.mFromCollisionContext};
std::string simprefix{mConfigData.mOutputPrefix};
if (pos != std::string::npos) {
collcontextfile = mConfigData.mFromCollisionContext.substr(0, pos);
simprefix = mConfigData.mFromCollisionContext.substr(pos + 1);
}
return std::make_pair(collcontextfile, simprefix);
}
bool SimConfig::resetFromParsedMap(boost::program_options::variables_map const& vm)
{
using o2::detectors::DetID;
mConfigData.mMCEngine = vm["mcEngine"].as<std::string>();
mConfigData.mNoGeant = vm["noGeant"].as<bool>();
// Reset modules and detectors as they are anyway re-parsed
mConfigData.mReadoutDetectors.clear();
mConfigData.mActiveModules.clear();
// Get final set of active Modules
if (!determineActiveModulesList(vm["detectorList"].as<std::string>(), vm["modules"].as<std::vector<std::string>>(), vm["skipModules"].as<std::vector<std::string>>(), mConfigData.mActiveModules)) {
return false;
}
if (mConfigData.mNoGeant) {
// CAVE is all that's needed (and that will be built either way), so clear all modules and set the O2TrivialMCEngine
mConfigData.mActiveModules.clear();
// force usage of O2TrivialMCEngine, no overhead from actual transport engine initialisation
mConfigData.mMCEngine = "O2TrivialMCEngine";
} else if (mConfigData.mMCEngine.compare("O2TrivialMCEngine") == 0) {
LOG(error) << "The O2TrivialMCEngine engine can only be used with --noGeant option";
return false;
}
const auto& activeModules = mConfigData.mActiveModules;
// get final set of detectors which are readout
determineReadoutDetectors(activeModules, vm["readoutDetectors"].as<std::vector<std::string>>(), vm["skipReadoutDetectors"].as<std::vector<std::string>>(), mConfigData.mReadoutDetectors);
mConfigData.mGenerator = vm["generator"].as<std::string>();
mConfigData.mTrigger = vm["trigger"].as<std::string>();
mConfigData.mNEvents = vm["nEvents"].as<unsigned int>();
mConfigData.mExtKinFileName = vm["extKinFile"].as<std::string>();
mConfigData.mEmbedIntoFileName = vm["embedIntoFile"].as<std::string>();
mConfigData.mStartEvent = vm["startEvent"].as<unsigned int>();
mConfigData.mBMax = vm["bMax"].as<float>();
mConfigData.mIsMT = vm["isMT"].as<bool>();
mConfigData.mOutputPrefix = vm["outPrefix"].as<std::string>();
mConfigData.mLogSeverity = vm["logseverity"].as<std::string>();
mConfigData.mLogVerbosity = vm["logverbosity"].as<std::string>();
mConfigData.mKeyValueTokens = vm["configKeyValues"].as<std::string>();
mConfigData.mConfigFile = vm["configFile"].as<std::string>();
mConfigData.mPrimaryChunkSize = vm["chunkSize"].as<unsigned int>();
mConfigData.mInternalChunkSize = vm["chunkSizeI"].as<int>();
mConfigData.mStartSeed = vm["seed"].as<ULong_t>();
mConfigData.mSimWorkers = vm["nworkers"].as<int>();
if (vm.count("timestamp")) {
mConfigData.mTimestamp = vm["timestamp"].as<uint64_t>();
mConfigData.mTimestampMode = TimeStampMode::kManual;
} else {
mConfigData.mTimestamp = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
mConfigData.mTimestampMode = TimeStampMode::kNow;
}
mConfigData.mRunNumber = vm["run"].as<int>();
mConfigData.mCCDBUrl = vm["CCDBUrl"].as<std::string>();
mConfigData.mAsService = vm["asservice"].as<bool>();
mConfigData.mForwardKine = vm["forwardKine"].as<bool>();
mConfigData.mWriteToDisc = !vm["noDiscOutput"].as<bool>();
if (vm.count("noemptyevents")) {
mConfigData.mFilterNoHitEvents = true;
}
mConfigData.mFromCollisionContext = vm["fromCollContext"].as<std::string>();
auto collcontext_simprefix = getCollContextFilenameAndEventPrefix();
adjustFromCollContext(collcontext_simprefix.first, collcontext_simprefix.second);
// analyse vertex options
if (!parseVertexModeString(vm["vertexMode"].as<std::string>(), mConfigData.mVertexMode)) {
return false;
}
// analyse field options
// either: "ccdb" or +-2[U],+-5[U] and 0[U]; +-<intKGaus>U
auto& fieldstring = vm["field"].as<std::string>();
std::regex re("(ccdb)|([+-]?(0|[2-9]|[12][0-9]|20)U?)");
if (!std::regex_match(fieldstring, re)) {
LOG(error) << "Invalid field option " << fieldstring;
return false;
}
if (fieldstring == "ccdb") {
mConfigData.mFieldMode = SimFieldMode::kCCDB;
} else if (fieldstring.find("U") != std::string::npos) {
mConfigData.mFieldMode = SimFieldMode::kUniform;
}
if (fieldstring != "ccdb") {
mConfigData.mField = std::stoi((vm["field"].as<std::string>()).substr(0, (vm["field"].as<std::string>()).rfind("U")));
}
if (!parseFieldString(fieldstring, mConfigData.mField, mConfigData.mFieldMode)) {
return false;
}
return true;
}
bool SimConfig::parseVertexModeString(std::string const& vertexstring, VertexMode& mode)
{
// vertexstring must be either kNoVertex, kDiamondParam, kCCDB
if (vertexstring == "kNoVertex") {
mode = VertexMode::kNoVertex;
return true;
} else if (vertexstring == "kDiamondParam") {
mode = VertexMode::kDiamondParam;
return true;
} else if (vertexstring == "kCCDB") {
mode = VertexMode::kCCDB;
return true;
} else if (vertexstring == "kCollContext") {
mode = VertexMode::kCollCxt;
return true;
}
LOG(error) << "Vertex mode must be one of kNoVertex, kDiamondParam, kCCDB, kCollContext";
return false;
}
bool SimConfig::parseFieldString(std::string const& fieldstring, int& fieldvalue, SimFieldMode& mode)
{
// analyse field options
// either: "ccdb" or +-2[U],+-5[U] and 0[U]; +-<intKGaus>U
std::regex re("(ccdb)|([+-]?(0|[2-9]|[12][0-9]|20)U?)");
if (!std::regex_match(fieldstring, re)) {
LOG(error) << "Invalid field option " << fieldstring;
return false;
}
if (fieldstring == "ccdb") {
mode = SimFieldMode::kCCDB;
} else if (fieldstring.find("U") != std::string::npos) {
mode = SimFieldMode::kUniform;
}
if (fieldstring != "ccdb") {
fieldvalue = std::stoi(fieldstring.substr(0, fieldstring.rfind("U")));
}
return true;
}
bool SimConfig::filterSkippedElements(std::vector<std::string>& elements, std::vector<std::string> const& skipped)
{
for (auto& s : skipped) {
if (s.empty()) { // nothing to skip here
continue;
}
auto iter = std::find(elements.begin(), elements.end(), s);
if (iter != elements.end()) {
// take it out
elements.erase(iter);
} else {
LOGP(error, "Skipped modules specified that are not present in built modules!");
LOGP(error, "Built modules:");
for (int j{0}; const auto& m : elements) {
LOGP(error, " + {: <2}. {}", j++, m);
}
std::vector<std::string> diff;
for (const auto& skip : skipped) {
if (std::find(elements.begin(), elements.end(), skip) == std::end(elements)) {
diff.emplace_back(skip);
}
}
LOGP(error, "Specified skipped modules not present in built modules:");
for (int j{0}; const auto& m : diff) {
LOGP(error, " - {: <2}. {}", j++, m);
}
return false;
}
}
return true;
}
void SimConfig::adjustFromCollContext(std::string const& collcontextfile, std::string const& prefix)
{
// When we use pregenerated collision contexts, some options
// need to be auto-adjusted. Do so and inform about this in the logs.
if (collcontextfile == "") {
return;
}
auto context = o2::steer::DigitizationContext::loadFromFile(collcontextfile);
if (context) {
// find the events belonging to a source that corresponds to a sim prefix
LOG(info) << "Looking up simprefixes " << prefix;
int sourceid = context->findSimPrefix(prefix);
if (sourceid == -1) {
LOG(error) << "Could not find collisions with sim prefix " << prefix << " in the collision context. The collision context specifies the following prefixes:";
for (auto& sp : context->getSimPrefixes()) {
LOG(info) << sp;
}
LOG(fatal) << "Aborting due to prefix error";
} else {
auto collisionmap = context->getCollisionIndicesForSource(sourceid);
LOG(info) << "Found " << collisionmap.size() << " events in the collisioncontext for prefix " << prefix;
// check if collisionmap is dense (otherwise it will get screwed up with order/indexing in ROOT output)
bool good = true;
for (auto index = 0; index < collisionmap.size(); ++index) {
if (collisionmap.find(index) == collisionmap.end()) {
good = false;
}
}
if (!good) {
LOG(fatal) << "events in collisioncontext are non-compact ";
}
// do some adjustments based on the number of events to be simulated
if (mConfigData.mNEvents == 0 || mConfigData.mNEvents == collisionmap.size()) {
// we take what is specified in the context
mConfigData.mNEvents = collisionmap.size();
} else {
LOG(warning) << "The number of events on the command line " << mConfigData.mNEvents << " and in the collision context differ. We take the one from collision context " << collisionmap.size();
mConfigData.mNEvents = collisionmap.size();
}
LOG(info) << "Setting number of events to simulate to " << mConfigData.mNEvents;
}
} else {
LOG(fatal) << "Could not open collision context file " << collcontextfile;
}
}
bool SimConfig::resetFromArguments(int argc, char* argv[])
{
// Arguments parsing
bpo::variables_map vm;
bpo::options_description desc("Allowed options");
desc.add_options()("help,h", "Produce help message.");
initOptions(desc, mConfigData.mIsUpgrade);
try {
bpo::store(parse_command_line(argc, argv, desc), vm);
// help
if (vm.count("help")) {
std::cout << desc << std::endl;
return false;
}
bpo::notify(vm);
} catch (const bpo::error& e) {
std::cerr << e.what() << "\n\n";
std::cerr << "Error parsing command line arguments; Available options:\n";
std::cerr << desc << std::endl;
return false;
}
return resetFromParsedMap(vm);
}
namespace o2::conf
{
// returns a reconfig struct given a configuration string (boost program options format)
bool parseSimReconfigFromString(std::string const& argumentstring, SimReconfigData& data)
{
namespace bpo = boost::program_options;
bpo::options_description options("Allowed options");
options.add_options()(
"nEvents,n", bpo::value<unsigned int>(&data.nEvents)->default_value(0), "number of events")(
"generator,g", bpo::value<std::string>(&data.generator)->default_value("boxgen"), "Event generator to be used.")(
"trigger,t", bpo::value<std::string>(&data.trigger)->default_value(""), "Event generator trigger to be used.")(
"startEvent", bpo::value<unsigned int>(&data.startEvent)->default_value(0), "index of first event to be used (when applicable)")(
"extKinFile", bpo::value<std::string>(&data.extKinfileName)->default_value("Kinematics.root"),
"name of kinematics file for event generator from file (when applicable)")(
"embedIntoFile", bpo::value<std::string>(&data.embedIntoFileName)->default_value(""),
"filename containing the reference events to be used for the embedding")(
"bMax,b", bpo::value<float>(&data.mBMax)->default_value(0.), "maximum value for impact parameter sampling (when applicable)")(
"outPrefix,o", bpo::value<std::string>(&data.outputPrefix)->default_value("o2sim"), "prefix of output files")(
"outDir,d", bpo::value<std::string>(&data.outputDir), "directory where to put simulation output (created when non-existant")(
"configKeyValues", bpo::value<std::string>(&data.keyValueTokens)->default_value(""), "semicolon separated key=value strings (e.g.: 'TPC.gasDensity=1;...")(
"configFile", bpo::value<std::string>(&data.configFile)->default_value(""), "Path to an INI or JSON configuration file")(
"chunkSize", bpo::value<unsigned int>(&data.primaryChunkSize)->default_value(500), "max size of primary chunk (subevent) distributed by server")(
"seed", bpo::value<ULong_t>(&data.startSeed)->default_value(0L), "initial seed as ULong_t (default: 0 == random)")(
"stop", bpo::value<bool>(&data.stop)->default_value(false), "control command to shut down daemon");
bpo::variables_map vm;
try {
bpo::store(bpo::command_line_parser(bpo::split_unix(argumentstring))
.options(options)
.run(),
vm);
bpo::notify(vm);
} catch (const bpo::error& e) {
std::cerr << e.what() << "\n\n";
std::cerr << "Error parsing ReConfig data; Available options:\n";
std::cerr << options << std::endl;
return false;
}
return true;
}
} // namespace o2::conf
ClassImp(o2::conf::SimConfig);