Project
Loading...
Searching...
No Matches
SimConfig.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_SIM_CONFIGURATION
13#define O2_SIM_CONFIGURATION
14
15#include <Rtypes.h>
16#ifndef __CLING__
17#include <boost/program_options.hpp>
18#else
20{
21class variables_map;
23} // namespace boost::program_options
24#endif
25
26namespace o2
27{
28namespace conf
29{
30
31enum class SimFieldMode {
32 kDefault = 0,
33 kUniform = 1,
34 kCCDB = 2
35};
36
37enum class VertexMode {
38 kNoVertex = 0, // no vertexing should be applied in the generator
39 kDiamondParam = 1, // Diamond param will influence vertexing
40 kCCDB = 2, // vertex should be taken from CCDB (Calib/MeanVertex object)
41 kCollCxt = 3 // vertex should be taken from collision context
42};
43
44enum class TimeStampMode {
45 kNow = 0,
46 kManual = 1,
47 kRun = 2
48};
49
50// configuration struct (which can be passed around)
52 std::vector<std::string> mActiveModules; // list of active modules
53 std::vector<std::string> mReadoutDetectors; // list of readout detectors
54 std::string mMCEngine; // chosen VMC engine
55 std::string mGenerator; // chosen VMC generator
56 std::string mTrigger; // chosen VMC generator trigger
57 unsigned int mNEvents; // number of events to be simulated
58 std::string mExtKinFileName; // file name of external kinematics file (needed for ext kinematics generator)
59 std::string mEmbedIntoFileName; // filename containing the reference events to be used for the embedding
60 unsigned int mStartEvent; // index of first event to be taken
61 float mBMax; // maximum for impact parameter sampling
62 bool mIsMT; // chosen MT mode (Geant4 only)
63 std::string mOutputPrefix; // prefix to be used for output files
64 std::string mLogSeverity; // severity for FairLogger
65 std::string mLogVerbosity; // loglevel for FairLogger
66 std::string mKeyValueTokens; // a string holding arbitrary sequence of key-value tokens
67 // Foo.parameter1=x,Bar.parameter2=y,Baz.paramter3=hello
68 // (can be used to **loosely** change any configuration parameter from command-line)
69 std::string mConfigFile; // path to a JSON or INI config file (file extension is required to determine type).
70 // values within the config file will override values set in code by the param classes
71 // but will themselves be overridden by any values given in mKeyValueTokens.
72 unsigned int mPrimaryChunkSize; // defining max granularity for input primaries of a sim job
74 ULong_t mStartSeed; // base for random number seeds
75 int mSimWorkers = 1; // number of parallel sim workers (when it applies)
76 bool mFilterNoHitEvents = false; // whether to filter out events not leaving any response
77 std::string mCCDBUrl; // the URL where to find CCDB
78 uint64_t mTimestamp; // timestamp in ms to anchor transport simulation to
79 TimeStampMode mTimestampMode = TimeStampMode::kNow; // telling of timestamp was given as option or defaulted to now
80 int mRunNumber = -1; // ALICE run number (if set != -1); the timestamp should be compatible
81 int mField; // L3 field setting in kGauss: +-2,+-5 and 0
82 SimFieldMode mFieldMode = SimFieldMode::kDefault; // uniform magnetic field
83 bool mAsService = false; // if simulation should be run as service/deamon (does not exit after run)
84 bool mNoGeant = false; // if Geant transport should be turned off (when one is only interested in the generated events)
85 bool mIsUpgrade = false; // true if the simulation is for Run 5
86 std::string mFromCollisionContext = ""; // string denoting a collision context file; If given, this file will be used to determine number of events
87 //
88 bool mForwardKine = false; // true if tracks and event headers are to be published on a FairMQ channel (for reading by other consumers)
89 bool mWriteToDisc = true; // whether we write simulation products (kine, hits) to disc
90 VertexMode mVertexMode = VertexMode::kDiamondParam; // by default we should use die InteractionDiamond parameter
91
93};
94
95// A singleton class which can be used
96// to centrally parse command line arguments and which can be queried
97// from the various algorithms that need access to this information
98// This is a quick/dirty solution allowing for some external configurability; A proper configuration scheme is currently
99// being worked out;
101{
102 private:
103 SimConfig()
104 {
105 // activate from default parameters
106 char* argv[] = {};
107 resetFromArguments(1, argv);
108 };
109
110 public:
112 {
113 static SimConfig conf;
114 return conf;
115 }
116
117 // makes a new instance that can be used as a local object
119 {
120 return SimConfig();
121 }
122
123 static void initOptions(boost::program_options::options_description&, bool isUpgrade = false);
124
125 // initializes the configuration from command line arguments
126 // returns true of correctly initialized and not --help called
127 bool resetFromArguments(int argc, char* argv[]);
128
129 // initializes from existing parsed map
130 bool resetFromParsedMap(boost::program_options::variables_map const&);
131
132 void resetFromConfigData(SimConfigData const& data) { mConfigData = data; }
133 SimConfigData const& getConfigData() const { return mConfigData; }
134 SimConfigData& getConfigData() { return mConfigData; }
135
136 // get MC engine
137 std::string getMCEngine() const { return mConfigData.mMCEngine; }
138 // get selected active detectors
139 std::vector<std::string> const& getActiveModules() const { return mConfigData.mActiveModules; }
140 std::vector<std::string> const& getReadoutDetectors() const { return mConfigData.mReadoutDetectors; }
141
142 // static helper functions to determine list of active / readout modules
143 // can also be used from outside
144 static void determineActiveModules(std::vector<std::string> const& input, std::vector<std::string> const& skipped, std::vector<std::string>& active, bool isUpgrade = false);
145 static bool determineActiveModulesList(const std::string& version, std::vector<std::string> const& input, std::vector<std::string> const& skipped, std::vector<std::string>& active);
146 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);
147
148 // helper to parse field option
149 static bool parseFieldString(std::string const& fieldstring, int& fieldvalue, o2::conf::SimFieldMode& mode);
150 // helper to parse vertex option; returns true if parsing ok, false if failure
151 static bool parseVertexModeString(std::string const& vertexstring, o2::conf::VertexMode& mode);
152
153 // get selected generator (to be used to select a genconfig)
154 std::string getGenerator() const { return mConfigData.mGenerator; }
155 std::string getTrigger() const { return mConfigData.mTrigger; }
156 unsigned int getNEvents() const { return mConfigData.mNEvents; }
157
158 std::string getExtKinematicsFileName() const { return mConfigData.mExtKinFileName; }
159 std::string getEmbedIntoFileName() const { return mConfigData.mEmbedIntoFileName; }
160 unsigned int getStartEvent() const { return mConfigData.mStartEvent; }
161 float getBMax() const { return mConfigData.mBMax; }
162 bool getIsMT() const { return mConfigData.mIsMT; }
163 std::string getOutPrefix() const { return mConfigData.mOutputPrefix; }
164 std::string getLogVerbosity() const { return mConfigData.mLogVerbosity; }
165 std::string getLogSeverity() const { return mConfigData.mLogSeverity; }
166 std::string getKeyValueString() const { return mConfigData.mKeyValueTokens; }
167 std::string getConfigFile() const { return mConfigData.mConfigFile; }
168 int getPrimChunkSize() const { return mConfigData.mPrimaryChunkSize; }
169 int getInternalChunkSize() const { return mConfigData.mInternalChunkSize; }
170 ULong_t getStartSeed() const { return mConfigData.mStartSeed; }
171 int getNSimWorkers() const { return mConfigData.mSimWorkers; }
172 bool isFilterOutNoHitEvents() const { return mConfigData.mFilterNoHitEvents; }
173 bool asService() const { return mConfigData.mAsService; }
174 uint64_t getTimestamp() const { return mConfigData.mTimestamp; }
175 int getRunNumber() const { return mConfigData.mRunNumber; }
176 bool isNoGeant() const { return mConfigData.mNoGeant; }
177 void setRun5(bool value = true) { mConfigData.mIsUpgrade = value; }
178 bool forwardKine() const { return mConfigData.mForwardKine; }
179 bool writeToDisc() const { return mConfigData.mWriteToDisc; }
180 VertexMode getVertexMode() const { return mConfigData.mVertexMode; }
181
182 // returns the pair of collision context filename as well as event prefix encoded
183 // in the mFromCollisionContext string. Returns empty string if information is not available or set.
184 std::pair<std::string, std::string> getCollContextFilenameAndEventPrefix() const;
185
186 private:
187 SimConfigData mConfigData;
188
189 // Filter out skipped elements in the list
190 static bool filterSkippedElements(std::vector<std::string>& elements, std::vector<std::string> const& skipped);
191
192 // adjust/overwrite some option settings when collision context is used
193 void adjustFromCollContext(std::string const& collcontextfile, std::string const& prefix);
194
195 ClassDefNV(SimConfig, 1);
196};
197
198// Configuration struct used for simulation reconfig (when processing
199// in batches and in "deamonized" mode. Note that in comparison to SimConfig,
200// fewer fields are offered (because many things are not easy to reconfigure).
202
204 std::string generator; // chosen VMC generator
205 std::string trigger; // chosen VMC generator trigger
206 unsigned int nEvents; // number of events to be simulated
207 std::string extKinfileName; // file name of external kinematics file (needed for ext kinematics generator)
208 std::string embedIntoFileName; // filename containing the reference events to be used for the embedding
209 unsigned int startEvent = 0; // index of first event to be taken
210 float mBMax; // maximum for impact parameter sampling
211 std::string outputPrefix; // prefix to be used for output files
212 std::string outputDir; // output directory
213 std::string keyValueTokens; // a string holding arbitrary sequence of key-value tokens (for ConfigurableParams)
214 // ** WE NEED TO BE CAREFUL: NOT EVERYTHING MAY BE RECONFIGURABLE VIA PARAMETER CHANGE **
215 // Foo.parameter1=x,Bar.parameter2=y,Baz.paramter3=hello
216 std::string configFile; // path to a JSON or INI config file (file extension is required to determine type).
217 // values within the config file will override values set in code by the param classes
218 // but will themselves be overridden by any values given in mKeyValueTokens.
219 unsigned int primaryChunkSize; // defining max granularity for input primaries of a sim job
220 ULong_t startSeed; // base for random number seeds
221 bool stop; // to shut down the service
222 std::string mFromCollisionContext = ""; // string denoting a collision context file; If given, this file will be used to determine number of events
223
225};
226
227// construct reconfig struct given a configuration string (boost program options format)
228// returns true if successful/ false otherwise
229bool parseSimReconfigFromString(std::string const& argumentstring, SimReconfigData& config);
230
231} // namespace conf
232} // namespace o2
233
234#endif
uint32_t version
Definition RawData.h:8
bool getIsMT() const
Definition SimConfig.h:162
std::string getConfigFile() const
Definition SimConfig.h:167
std::string getMCEngine() const
Definition SimConfig.h:137
static SimConfig make()
Definition SimConfig.h:118
std::string getEmbedIntoFileName() const
Definition SimConfig.h:159
std::string getExtKinematicsFileName() const
Definition SimConfig.h:158
std::string getKeyValueString() const
Definition SimConfig.h:166
void resetFromConfigData(SimConfigData const &data)
Definition SimConfig.h:132
bool resetFromParsedMap(boost::program_options::variables_map const &)
bool resetFromArguments(int argc, char *argv[])
bool writeToDisc() const
Definition SimConfig.h:179
unsigned int getStartEvent() const
Definition SimConfig.h:160
void setRun5(bool value=true)
Definition SimConfig.h:177
int getRunNumber() const
Definition SimConfig.h:175
std::string getTrigger() const
Definition SimConfig.h:155
static void determineActiveModules(std::vector< std::string > const &input, std::vector< std::string > const &skipped, std::vector< std::string > &active, bool isUpgrade=false)
Definition SimConfig.cxx:82
int getInternalChunkSize() const
Definition SimConfig.h:169
int getNSimWorkers() const
Definition SimConfig.h:171
static bool parseVertexModeString(std::string const &vertexstring, o2::conf::VertexMode &mode)
int getPrimChunkSize() const
Definition SimConfig.h:168
bool isNoGeant() const
Definition SimConfig.h:176
uint64_t getTimestamp() const
Definition SimConfig.h:174
std::vector< std::string > const & getActiveModules() const
Definition SimConfig.h:139
ULong_t getStartSeed() const
Definition SimConfig.h:170
VertexMode getVertexMode() const
Definition SimConfig.h:180
static bool parseFieldString(std::string const &fieldstring, int &fieldvalue, o2::conf::SimFieldMode &mode)
SimConfigData const & getConfigData() const
Definition SimConfig.h:133
bool isFilterOutNoHitEvents() const
Definition SimConfig.h:172
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)
static bool determineActiveModulesList(const std::string &version, std::vector< std::string > const &input, std::vector< std::string > const &skipped, std::vector< std::string > &active)
bool asService() const
Definition SimConfig.h:173
std::pair< std::string, std::string > getCollContextFilenameAndEventPrefix() const
float getBMax() const
Definition SimConfig.h:161
SimConfigData & getConfigData()
Definition SimConfig.h:134
unsigned int getNEvents() const
Definition SimConfig.h:156
static void initOptions(boost::program_options::options_description &, bool isUpgrade=false)
Definition SimConfig.cxx:27
std::string getLogVerbosity() const
Definition SimConfig.h:164
bool forwardKine() const
Definition SimConfig.h:178
static SimConfig & Instance()
Definition SimConfig.h:111
std::string getLogSeverity() const
Definition SimConfig.h:165
std::string getOutPrefix() const
Definition SimConfig.h:163
std::string getGenerator() const
Definition SimConfig.h:154
std::vector< std::string > const & getReadoutDetectors() const
Definition SimConfig.h:140
GLenum mode
Definition glcorearb.h:266
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLboolean * data
Definition glcorearb.h:298
bool parseSimReconfigFromString(std::string const &argumentstring, SimReconfigData &config)
boost::program_options::options_description options_description
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string mFromCollisionContext
Definition SimConfig.h:86
std::vector< std::string > mActiveModules
Definition SimConfig.h:52
std::string mOutputPrefix
Definition SimConfig.h:63
std::string mExtKinFileName
Definition SimConfig.h:58
unsigned int mPrimaryChunkSize
Definition SimConfig.h:72
std::vector< std::string > mReadoutDetectors
Definition SimConfig.h:53
std::string mKeyValueTokens
Definition SimConfig.h:66
TimeStampMode mTimestampMode
Definition SimConfig.h:79
unsigned int mNEvents
Definition SimConfig.h:57
std::string mGenerator
Definition SimConfig.h:55
SimFieldMode mFieldMode
Definition SimConfig.h:82
std::string mLogSeverity
Definition SimConfig.h:64
std::string mConfigFile
Definition SimConfig.h:69
std::string mEmbedIntoFileName
Definition SimConfig.h:59
ClassDefNV(SimConfigData, 4)
std::string mLogVerbosity
Definition SimConfig.h:65
unsigned int mStartEvent
Definition SimConfig.h:60
std::string mMCEngine
Definition SimConfig.h:54
TODO: Make this a base class of SimConfigData?
Definition SimConfig.h:203
std::string mFromCollisionContext
Definition SimConfig.h:222
ClassDefNV(SimReconfigData, 1)
std::string embedIntoFileName
Definition SimConfig.h:208
unsigned int primaryChunkSize
Definition SimConfig.h:219