Skip to content

Commit 0ba66e6

Browse files
f3schalcaliva
authored andcommitted
SIM: Adding experiment versions and dynamic library loading (#13148)
* SIM: Add detectorList option: Gaining more flexibility with detector geometries. (a) Allows to select a detector list from a pre-defined list of ALICE2, ALICE2.1, ALICE3 (corresponding to Run3, Run4, Run5). Arguments for -m, --skipModules, --readoutDetectors will then be checked against that list. `o2-sim -n 1 --detectorList ALICE2.1 -m IT3 -o bar2` (b) Allows to define a custom detector list "MyList" in a JSON file, and following the notation: `o2-sim --detectorList MyList:${PWD}/myDetector.json` * SIM: Add dynamic detector library loading This commit also adds the possibility to instantiate/construct detector modules as a dynamic plugin. The benefit is that we no longer need to link all possible detector libraries into the simulation executable. (cherry picked from commit be5cdb9)
1 parent 2a1f4a3 commit 0ba66e6

File tree

20 files changed

+725
-74
lines changed

20 files changed

+725
-74
lines changed

Common/SimConfig/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
o2_add_library(SimConfig
1313
SOURCES src/SimConfig.cxx
1414
src/SimParams.cxx
15+
src/SimDLLoader.cxx
1516
src/SimUserDecay.cxx
16-
src/DigiParams.cxx src/G4Params.cxx
17+
src/DigiParams.cxx
18+
src/G4Params.cxx
19+
src/DetectorLists.cxx
1720
src/MatMapParams.cxx
1821
src/InteractionDiamondParam.cxx
1922
src/GlobalProcessCutSimParam.cxx
@@ -25,10 +28,12 @@ o2_add_library(SimConfig
2528
o2_target_root_dictionary(SimConfig
2629
HEADERS include/SimConfig/SimConfig.h
2730
include/SimConfig/SimParams.h
31+
include/SimConfig/SimDLLoader.h
2832
include/SimConfig/SimUserDecay.h
2933
include/SimConfig/InteractionDiamondParam.h
30-
include/SimConfig/DigiParams.h
34+
include/SimConfig/DigiParams.h
3135
include/SimConfig/G4Params.h
36+
include/SimConfig/DetectorLists.h
3237
include/SimConfig/GlobalProcessCutSimParam.h
3338
include/SimConfig/MatMapParams.h)
3439

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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_DETECTORLISTS_H_
13+
#define O2_DETECTORLISTS_H_
14+
15+
#include <string>
16+
#include <unordered_map>
17+
#include <vector>
18+
19+
#include "Framework/Logger.h"
20+
21+
namespace o2::conf
22+
{
23+
// Container defining different general evolutions of the ALICE experiment. Each
24+
// evolution is given a name and a list defining the names of the detectors and
25+
// passive elements present.
26+
using DetectorList_t = std::vector<std::string>;
27+
using DetectorMap_t = std::unordered_map<std::string, DetectorList_t>;
28+
29+
// Parse the detector map from a JSON file.
30+
// Return false if parsing failed.
31+
bool parseDetectorMapfromJSON(const std::string& path, DetectorMap_t& map);
32+
33+
// Print the DetetectorMap
34+
void printDetMap(const DetectorMap_t& map, const std::string& list = "");
35+
} // namespace o2::conf
36+
37+
#endif // O2_DETECTORLISTS_H_

Common/SimConfig/include/SimConfig/SimConfig.h

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,43 +48,43 @@ enum class TimeStampMode {
4848

4949
// configuration struct (which can be passed around)
5050
struct SimConfigData {
51-
std::vector<std::string> mActiveModules; // list of active modules
52-
std::vector<std::string> mReadoutDetectors; // list of readout detectors
53-
std::string mMCEngine; // chosen VMC engine
54-
std::string mGenerator; // chosen VMC generator
55-
std::string mTrigger; // chosen VMC generator trigger
56-
unsigned int mNEvents; // number of events to be simulated
57-
std::string mExtKinFileName; // file name of external kinematics file (needed for ext kinematics generator)
58-
std::string mEmbedIntoFileName; // filename containing the reference events to be used for the embedding
59-
unsigned int mStartEvent; // index of first event to be taken
60-
float mBMax; // maximum for impact parameter sampling
61-
bool mIsMT; // chosen MT mode (Geant4 only)
62-
std::string mOutputPrefix; // prefix to be used for output files
63-
std::string mLogSeverity; // severity for FairLogger
64-
std::string mLogVerbosity; // loglevel for FairLogger
65-
std::string mKeyValueTokens; // a string holding arbitrary sequence of key-value tokens
66-
// Foo.parameter1=x,Bar.parameter2=y,Baz.paramter3=hello
67-
// (can be used to **loosely** change any configuration parameter from command-line)
68-
std::string mConfigFile; // path to a JSON or INI config file (file extension is required to determine type).
69-
// values within the config file will override values set in code by the param classes
70-
// but will themselves be overridden by any values given in mKeyValueTokens.
71-
int mPrimaryChunkSize; // defining max granularity for input primaries of a sim job
72-
int mInternalChunkSize; //
73-
ULong_t mStartSeed; // base for random number seeds
74-
int mSimWorkers = 1; // number of parallel sim workers (when it applies)
75-
bool mFilterNoHitEvents = false; // whether to filter out events not leaving any response
76-
std::string mCCDBUrl; // the URL where to find CCDB
77-
uint64_t mTimestamp; // timestamp in ms to anchor transport simulation to
51+
std::vector<std::string> mActiveModules; // list of active modules
52+
std::vector<std::string> mReadoutDetectors; // list of readout detectors
53+
std::string mMCEngine; // chosen VMC engine
54+
std::string mGenerator; // chosen VMC generator
55+
std::string mTrigger; // chosen VMC generator trigger
56+
unsigned int mNEvents; // number of events to be simulated
57+
std::string mExtKinFileName; // file name of external kinematics file (needed for ext kinematics generator)
58+
std::string mEmbedIntoFileName; // filename containing the reference events to be used for the embedding
59+
unsigned int mStartEvent; // index of first event to be taken
60+
float mBMax; // maximum for impact parameter sampling
61+
bool mIsMT; // chosen MT mode (Geant4 only)
62+
std::string mOutputPrefix; // prefix to be used for output files
63+
std::string mLogSeverity; // severity for FairLogger
64+
std::string mLogVerbosity; // loglevel for FairLogger
65+
std::string mKeyValueTokens; // a string holding arbitrary sequence of key-value tokens
66+
// Foo.parameter1=x,Bar.parameter2=y,Baz.paramter3=hello
67+
// (can be used to **loosely** change any configuration parameter from command-line)
68+
std::string mConfigFile; // path to a JSON or INI config file (file extension is required to determine type).
69+
// values within the config file will override values set in code by the param classes
70+
// but will themselves be overridden by any values given in mKeyValueTokens.
71+
unsigned int mPrimaryChunkSize; // defining max granularity for input primaries of a sim job
72+
int mInternalChunkSize; //
73+
ULong_t mStartSeed; // base for random number seeds
74+
int mSimWorkers = 1; // number of parallel sim workers (when it applies)
75+
bool mFilterNoHitEvents = false; // whether to filter out events not leaving any response
76+
std::string mCCDBUrl; // the URL where to find CCDB
77+
uint64_t mTimestamp; // timestamp in ms to anchor transport simulation to
7878
TimeStampMode mTimestampMode = TimeStampMode::kNow; // telling of timestamp was given as option or defaulted to now
79-
int mRunNumber = -1; // ALICE run number (if set != -1); the timestamp should be compatible
80-
int mField; // L3 field setting in kGauss: +-2,+-5 and 0
81-
SimFieldMode mFieldMode = SimFieldMode::kDefault; // uniform magnetic field
82-
bool mAsService = false; // if simulation should be run as service/deamon (does not exit after run)
83-
bool mNoGeant = false; // if Geant transport should be turned off (when one is only interested in the generated events)
84-
bool mIsUpgrade = false; // true if the simulation is for Run 5
85-
std::string mFromCollisionContext = ""; // string denoting a collision context file; If given, this file will be used to determine number of events
86-
bool mForwardKine = false; // true if tracks and event headers are to be published on a FairMQ channel (for reading by other consumers)
87-
bool mWriteToDisc = true; // whether we write simulation products (kine, hits) to disc
79+
int mRunNumber = -1; // ALICE run number (if set != -1); the timestamp should be compatible
80+
int mField; // L3 field setting in kGauss: +-2,+-5 and 0
81+
SimFieldMode mFieldMode = SimFieldMode::kDefault; // uniform magnetic field
82+
bool mAsService = false; // if simulation should be run as service/deamon (does not exit after run)
83+
bool mNoGeant = false; // if Geant transport should be turned off (when one is only interested in the generated events)
84+
bool mIsUpgrade = false; // true if the simulation is for Run 5
85+
std::string mFromCollisionContext = ""; // string denoting a collision context file; If given, this file will be used to determine number of events
86+
bool mForwardKine = false; // true if tracks and event headers are to be published on a FairMQ channel (for reading by other consumers)
87+
bool mWriteToDisc = true; // whether we write simulation products (kine, hits) to disc
8888
VertexMode mVertexMode = VertexMode::kDiamondParam; // by default we should use die InteractionDiamond parameter
8989

9090
ClassDefNV(SimConfigData, 4);
@@ -140,6 +140,7 @@ class SimConfig
140140
// static helper functions to determine list of active / readout modules
141141
// can also be used from outside
142142
static void determineActiveModules(std::vector<std::string> const& input, std::vector<std::string> const& skipped, std::vector<std::string>& active, bool isUpgrade = false);
143+
static bool determineActiveModulesList(const std::string& version, std::vector<std::string> const& input, std::vector<std::string> const& skipped, std::vector<std::string>& active);
143144
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);
144145

145146
// helper to parse field option
@@ -179,6 +180,9 @@ class SimConfig
179180
private:
180181
SimConfigData mConfigData; //!
181182

183+
// Filter out skipped elements in the list
184+
static bool filterSkippedElements(std::vector<std::string>& elements, std::vector<std::string> const& skipped);
185+
182186
// adjust/overwrite some option settings when collision context is used
183187
void adjustFromCollContext(std::string const& collcontextfile, std::string const& prefix);
184188

@@ -206,9 +210,9 @@ struct SimReconfigData {
206210
std::string configFile; // path to a JSON or INI config file (file extension is required to determine type).
207211
// values within the config file will override values set in code by the param classes
208212
// but will themselves be overridden by any values given in mKeyValueTokens.
209-
unsigned int primaryChunkSize; // defining max granularity for input primaries of a sim job
210-
ULong_t startSeed; // base for random number seeds
211-
bool stop; // to shut down the service
213+
unsigned int primaryChunkSize; // defining max granularity for input primaries of a sim job
214+
ULong_t startSeed; // base for random number seeds
215+
bool stop; // to shut down the service
212216
std::string mFromCollisionContext = ""; // string denoting a collision context file; If given, this file will be used to determine number of events
213217

214218
ClassDefNV(SimReconfigData, 1);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 SIMDLLOADER_H_
13+
#define SIMDLLOADER_H_
14+
15+
#include "CommonUtils/DLLoaderBase.h"
16+
17+
namespace o2::conf
18+
{
19+
20+
class SimDLLoader : public o2::utils::DLLoaderBase<SimDLLoader>
21+
{
22+
O2DLLoaderDef(SimDLLoader)
23+
};
24+
25+
} // namespace o2::conf
26+
27+
#endif // SIMDLLOADER_H_
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
#include "SimConfig/DetectorLists.h"
13+
#include <fairlogger/Logger.h>
14+
#include <rapidjson/document.h>
15+
#include <rapidjson/error/en.h>
16+
#include <rapidjson/istreamwrapper.h>
17+
#include <fstream>
18+
19+
namespace o2::conf
20+
{
21+
22+
bool parseDetectorMapfromJSON(const std::string& path, DetectorMap_t& map)
23+
{
24+
// Parse JSON file to build map
25+
std::ifstream fileStream(path, std::ios::in);
26+
if (!fileStream.is_open()) {
27+
LOGP(error, "Cannot open '{}'!", path);
28+
return false;
29+
}
30+
rapidjson::IStreamWrapper isw(fileStream);
31+
rapidjson::Document doc;
32+
doc.ParseStream(isw);
33+
if (doc.HasParseError()) {
34+
LOGP(error, "Error parsing provided json file '{}':", path);
35+
LOGP(error, " - Error -> {}", rapidjson::GetParseError_En(doc.GetParseError()));
36+
LOGP(error, " - Offset -> {}", doc.GetErrorOffset());
37+
return false;
38+
}
39+
40+
// Clear and rebuild map
41+
map.clear();
42+
try {
43+
for (auto verItr = doc.MemberBegin(); verItr != doc.MemberEnd(); ++verItr) {
44+
const auto& version = verItr->name.GetString();
45+
DetectorList_t list;
46+
const auto& elements = doc[version];
47+
for (const auto& ele : elements.GetArray()) {
48+
list.emplace_back(ele.GetString());
49+
}
50+
map.emplace(version, list);
51+
}
52+
} catch (const std::exception& e) {
53+
LOGP(error, "Failed to build detector map from file '{}' with '{}'", path, e.what());
54+
return false;
55+
}
56+
57+
return true;
58+
}
59+
60+
void printDetMap(const DetectorMap_t& map, const std::string& list)
61+
{
62+
if (list.empty()) {
63+
LOGP(error, "List of all available versions including their detectors:");
64+
for (int i{0}; const auto& [version, elements] : map) {
65+
LOGP(error, " - {: >2d}. {}:", i++, version);
66+
for (int j{0}; const auto& element : elements) {
67+
LOGP(error, "\t\t* {: >2d}.\t{}", j++, element);
68+
}
69+
}
70+
} else {
71+
LOGP(error, "List of available modules for version {}:", list);
72+
for (int j{0}; const auto& element : map.at(list)) {
73+
LOGP(error, "\t* {: >2d}.\t{}", j++, element);
74+
}
75+
}
76+
}
77+
78+
} // namespace o2::conf

0 commit comments

Comments
 (0)