-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathSimConfig.cxx
More file actions
158 lines (145 loc) · 7.65 KB
/
SimConfig.cxx
File metadata and controls
158 lines (145 loc) · 7.65 KB
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
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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 <DetectorsCommonDataFormats/DetID.h>
#include <boost/program_options.hpp>
#include <iostream>
#include <FairLogger.h>
#include <thread>
#include <cmath>
using namespace o2::conf;
namespace bpo = boost::program_options;
void SimConfig::initOptions(boost::program_options::options_description& options)
{
int nsimworkersdefault = std::max(1u, std::thread::hardware_concurrency() / 2);
options.add_options()(
"mcEngine,e", bpo::value<std::string>()->default_value("TGeant3"), "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 detectors")(
"skipModules", bpo::value<std::vector<std::string>>()->multitoken()->default_value(std::vector<std::string>({""}), ""), "list of detectors to skip (precendence over -m")("nEvents,n", bpo::value<unsigned int>()->default_value(1), "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)")(
"extGenFile", bpo::value<std::string>()->default_value("extgen.C"),
"name of .C file with definition of external event generator")(
"extGenFunc", bpo::value<std::string>()->default_value(""),
"function call to load the definition of external event generator")(
"extTrgFile", bpo::value<std::string>()->default_value("exttrg.C"),
"name of .C file with definition of external event generator trigger")(
"extTrgFunc", bpo::value<std::string>()->default_value(""),
"function call to load the definition of external event generator trigger")(
"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<int>()->default_value(-1), "initial seed (default: -1 random)")(
"field", bpo::value<int>()->default_value(-5), "L3 field rounded to kGauss, allowed values +-2,+-5 and 0")(
"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("ccdb-test.cern.ch:8080"), "URL for CCDB to be used.")(
"timestamp", bpo::value<long>()->default_value(-1), "global timestamp value (for anchoring) - default is now");
}
bool SimConfig::resetFromParsedMap(boost::program_options::variables_map const& vm)
{
using o2::detectors::DetID;
mConfigData.mMCEngine = vm["mcEngine"].as<std::string>();
mConfigData.mActiveDetectors = vm["modules"].as<std::vector<std::string>>();
auto& active = mConfigData.mActiveDetectors;
if (active.size() == 1 && active[0] == "all") {
active.clear();
for (int d = DetID::First; d <= DetID::Last; ++d) {
#ifdef ENABLE_UPGRADES
if (d != DetID::IT3 && d != DetID::IT4) {
active.emplace_back(DetID::getName(d));
}
#else
active.emplace_back(DetID::getName(d));
#endif
}
// add passive components manually (make a PassiveDetID for them!)
active.emplace_back("HALL");
active.emplace_back("MAG");
active.emplace_back("DIPO");
active.emplace_back("COMP");
active.emplace_back("PIPE");
active.emplace_back("ABSO");
active.emplace_back("SHIL");
}
// now we take out detectors listed as skipped
auto& skipped = vm["skipModules"].as<std::vector<std::string>>();
for (auto& s : skipped) {
auto iter = std::find(active.begin(), active.end(), s);
if (iter != active.end()) {
// take it out
active.erase(iter);
}
}
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.mExtGenFileName = vm["extGenFile"].as<std::string>();
mConfigData.mExtGenFuncName = vm["extGenFunc"].as<std::string>();
mConfigData.mExtTrgFileName = vm["extTrgFile"].as<std::string>();
mConfigData.mExtTrgFuncName = vm["extTrgFunc"].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<int>();
mConfigData.mSimWorkers = vm["nworkers"].as<int>();
mConfigData.mTimestamp = vm["timestamp"].as<long>();
mConfigData.mCCDBUrl = vm["CCDBUrl"].as<std::string>();
if (vm.count("noemptyevents")) {
mConfigData.mFilterNoHitEvents = true;
}
mConfigData.mField = vm["field"].as<int>();
return true;
}
bool SimConfig::resetFromArguments(int argc, char* argv[])
{
namespace bpo = boost::program_options;
// Arguments parsing
bpo::variables_map vm;
bpo::options_description desc("Allowed options");
desc.add_options()("help,h", "Produce help message.");
initOptions(desc);
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);
}
ClassImp(o2::conf::SimConfig);