-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathSimConfig.h
More file actions
234 lines (203 loc) · 12.7 KB
/
SimConfig.h
File metadata and controls
234 lines (203 loc) · 12.7 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
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
// 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.
#ifndef O2_SIM_CONFIGURATION
#define O2_SIM_CONFIGURATION
#include <Rtypes.h>
#ifndef __CLING__
#include <boost/program_options.hpp>
#else
namespace boost::program_options
{
class variables_map;
class options_description;
} // namespace boost::program_options
#endif
namespace o2
{
namespace conf
{
enum class SimFieldMode {
kDefault = 0,
kUniform = 1,
kCCDB = 2
};
enum class VertexMode {
kNoVertex = 0, // no vertexing should be applied in the generator
kDiamondParam = 1, // Diamond param will influence vertexing
kCCDB = 2, // vertex should be taken from CCDB (Calib/MeanVertex object)
kCollCxt = 3 // vertex should be taken from collision context
};
enum class TimeStampMode {
kNow = 0,
kManual = 1,
kRun = 2
};
// configuration struct (which can be passed around)
struct SimConfigData {
std::vector<std::string> mActiveModules; // list of active modules
std::vector<std::string> mReadoutDetectors; // list of readout detectors
std::string mMCEngine; // chosen VMC engine
std::string mGenerator; // chosen VMC generator
std::string mTrigger; // chosen VMC generator trigger
unsigned int mNEvents; // number of events to be simulated
std::string mExtKinFileName; // file name of external kinematics file (needed for ext kinematics generator)
std::string mEmbedIntoFileName; // filename containing the reference events to be used for the embedding
unsigned int mStartEvent; // index of first event to be taken
float mBMax; // maximum for impact parameter sampling
bool mIsMT; // chosen MT mode (Geant4 only)
std::string mOutputPrefix; // prefix to be used for output files
std::string mLogSeverity; // severity for FairLogger
std::string mLogVerbosity; // loglevel for FairLogger
std::string mKeyValueTokens; // a string holding arbitrary sequence of key-value tokens
// Foo.parameter1=x,Bar.parameter2=y,Baz.paramter3=hello
// (can be used to **loosely** change any configuration parameter from command-line)
std::string mConfigFile; // path to a JSON or INI config file (file extension is required to determine type).
// values within the config file will override values set in code by the param classes
// but will themselves be overridden by any values given in mKeyValueTokens.
unsigned int mPrimaryChunkSize; // defining max granularity for input primaries of a sim job
int mInternalChunkSize; //
ULong_t mStartSeed; // base for random number seeds
int mSimWorkers = 1; // number of parallel sim workers (when it applies)
bool mFilterNoHitEvents = false; // whether to filter out events not leaving any response
std::string mCCDBUrl; // the URL where to find CCDB
uint64_t mTimestamp; // timestamp in ms to anchor transport simulation to
TimeStampMode mTimestampMode = TimeStampMode::kNow; // telling of timestamp was given as option or defaulted to now
int mRunNumber = -1; // ALICE run number (if set != -1); the timestamp should be compatible
int mField; // L3 field setting in kGauss: +-2,+-5 and 0
SimFieldMode mFieldMode = SimFieldMode::kDefault; // uniform magnetic field
bool mAsService = false; // if simulation should be run as service/deamon (does not exit after run)
bool mNoGeant = false; // if Geant transport should be turned off (when one is only interested in the generated events)
bool mIsUpgrade = false; // true if the simulation is for Run 5
std::string mFromCollisionContext = ""; // string denoting a collision context file; If given, this file will be used to determine number of events
//
bool mForwardKine = false; // true if tracks and event headers are to be published on a FairMQ channel (for reading by other consumers)
bool mWriteToDisc = true; // whether we write simulation products (kine, hits) to disc
VertexMode mVertexMode = VertexMode::kDiamondParam; // by default we should use die InteractionDiamond parameter
ClassDefNV(SimConfigData, 4);
};
// A singleton class which can be used
// to centrally parse command line arguments and which can be queried
// from the various algorithms that need access to this information
// This is a quick/dirty solution allowing for some external configurability; A proper configuration scheme is currently
// being worked out;
class SimConfig
{
private:
SimConfig()
{
// activate from default parameters
char* argv[] = {};
resetFromArguments(1, argv);
};
public:
static SimConfig& Instance()
{
static SimConfig conf;
return conf;
}
// makes a new instance that can be used as a local object
static SimConfig make()
{
return SimConfig();
}
static void initOptions(boost::program_options::options_description&, bool isUpgrade = false);
// initializes the configuration from command line arguments
// returns true of correctly initialized and not --help called
bool resetFromArguments(int argc, char* argv[]);
// initializes from existing parsed map
bool resetFromParsedMap(boost::program_options::variables_map const&);
void resetFromConfigData(SimConfigData const& data) { mConfigData = data; }
SimConfigData const& getConfigData() const { return mConfigData; }
SimConfigData& getConfigData() { return mConfigData; }
// get MC engine
std::string getMCEngine() const { return mConfigData.mMCEngine; }
// get selected active detectors
std::vector<std::string> const& getActiveModules() const { return mConfigData.mActiveModules; }
std::vector<std::string> const& getReadoutDetectors() const { return mConfigData.mReadoutDetectors; }
// static helper functions to determine list of active / readout modules
// can also be used from outside
static void determineActiveModules(std::vector<std::string> const& input, std::vector<std::string> const& skipped, std::vector<std::string>& active, bool isUpgrade = false);
static bool determineActiveModulesList(const std::string& version, std::vector<std::string> const& input, std::vector<std::string> const& skipped, std::vector<std::string>& active);
static void determineReadoutDetectors(std::vector<std::string> const& active, std::vector<std::string> const& enabledRO, std::vector<std::string> const& skippedRO, std::vector<std::string>& finalRO);
// helper to parse field option
static bool parseFieldString(std::string const& fieldstring, int& fieldvalue, o2::conf::SimFieldMode& mode);
// helper to parse vertex option; returns true if parsing ok, false if failure
static bool parseVertexModeString(std::string const& vertexstring, o2::conf::VertexMode& mode);
// get selected generator (to be used to select a genconfig)
std::string getGenerator() const { return mConfigData.mGenerator; }
std::string getTrigger() const { return mConfigData.mTrigger; }
unsigned int getNEvents() const { return mConfigData.mNEvents; }
std::string getExtKinematicsFileName() const { return mConfigData.mExtKinFileName; }
std::string getEmbedIntoFileName() const { return mConfigData.mEmbedIntoFileName; }
unsigned int getStartEvent() const { return mConfigData.mStartEvent; }
float getBMax() const { return mConfigData.mBMax; }
bool getIsMT() const { return mConfigData.mIsMT; }
std::string getOutPrefix() const { return mConfigData.mOutputPrefix; }
std::string getLogVerbosity() const { return mConfigData.mLogVerbosity; }
std::string getLogSeverity() const { return mConfigData.mLogSeverity; }
std::string getKeyValueString() const { return mConfigData.mKeyValueTokens; }
std::string getConfigFile() const { return mConfigData.mConfigFile; }
int getPrimChunkSize() const { return mConfigData.mPrimaryChunkSize; }
int getInternalChunkSize() const { return mConfigData.mInternalChunkSize; }
ULong_t getStartSeed() const { return mConfigData.mStartSeed; }
int getNSimWorkers() const { return mConfigData.mSimWorkers; }
bool isFilterOutNoHitEvents() const { return mConfigData.mFilterNoHitEvents; }
bool asService() const { return mConfigData.mAsService; }
uint64_t getTimestamp() const { return mConfigData.mTimestamp; }
int getRunNumber() const { return mConfigData.mRunNumber; }
bool isNoGeant() const { return mConfigData.mNoGeant; }
void setRun5(bool value = true) { mConfigData.mIsUpgrade = value; }
bool forwardKine() const { return mConfigData.mForwardKine; }
bool writeToDisc() const { return mConfigData.mWriteToDisc; }
VertexMode getVertexMode() const { return mConfigData.mVertexMode; }
// returns the pair of collision context filename as well as event prefix encoded
// in the mFromCollisionContext string. Returns empty string if information is not available or set.
std::pair<std::string, std::string> getCollContextFilenameAndEventPrefix() const;
private:
SimConfigData mConfigData; //!
// Filter out skipped elements in the list
static bool filterSkippedElements(std::vector<std::string>& elements, std::vector<std::string> const& skipped);
// adjust/overwrite some option settings when collision context is used
void adjustFromCollContext(std::string const& collcontextfile, std::string const& prefix);
ClassDefNV(SimConfig, 1);
};
// Configuration struct used for simulation reconfig (when processing
// in batches and in "deamonized" mode. Note that in comparison to SimConfig,
// fewer fields are offered (because many things are not easy to reconfigure).
//! TODO: Make this a base class of SimConfigData?
struct SimReconfigData {
std::string generator; // chosen VMC generator
std::string trigger; // chosen VMC generator trigger
unsigned int nEvents; // number of events to be simulated
std::string extKinfileName; // file name of external kinematics file (needed for ext kinematics generator)
std::string embedIntoFileName; // filename containing the reference events to be used for the embedding
unsigned int startEvent = 0; // index of first event to be taken
float mBMax; // maximum for impact parameter sampling
std::string outputPrefix; // prefix to be used for output files
std::string outputDir; // output directory
std::string keyValueTokens; // a string holding arbitrary sequence of key-value tokens (for ConfigurableParams)
// ** WE NEED TO BE CAREFUL: NOT EVERYTHING MAY BE RECONFIGURABLE VIA PARAMETER CHANGE **
// Foo.parameter1=x,Bar.parameter2=y,Baz.paramter3=hello
std::string configFile; // path to a JSON or INI config file (file extension is required to determine type).
// values within the config file will override values set in code by the param classes
// but will themselves be overridden by any values given in mKeyValueTokens.
unsigned int primaryChunkSize; // defining max granularity for input primaries of a sim job
ULong_t startSeed; // base for random number seeds
bool stop; // to shut down the service
std::string mFromCollisionContext = ""; // string denoting a collision context file; If given, this file will be used to determine number of events
ClassDefNV(SimReconfigData, 1);
};
// construct reconfig struct given a configuration string (boost program options format)
// returns true if successful/ false otherwise
bool parseSimReconfigFromString(std::string const& argumentstring, SimReconfigData& config);
} // namespace conf
} // namespace o2
#endif