forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimConfig.h
More file actions
189 lines (163 loc) · 9.7 KB
/
SimConfig.h
File metadata and controls
189 lines (163 loc) · 9.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
// 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>
#include <boost/program_options.hpp>
namespace o2
{
namespace conf
{
enum SimFieldMode {
kDefault = 0,
kUniform = 1,
kCCDB = 2
};
enum 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.
int mPrimaryChunkSize; // defining max granularity for input primaries of a sim job
int mInternalChunkSize; //
int 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 = 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 = 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)
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;
}
static void initOptions(boost::program_options::options_description&);
// 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);
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);
// 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; }
int 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; }
private:
SimConfigData mConfigData; //!
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
int startSeed; // base for random number seeds
bool stop; // to shut down the service
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