-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathSimSetup.cxx
More file actions
63 lines (58 loc) · 1.84 KB
/
SimSetup.cxx
File metadata and controls
63 lines (58 loc) · 1.84 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
// 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 <cstring>
#include "SimSetup/SimSetup.h"
#include "FairLogger.h"
#include "SetCuts.h"
#include <dlfcn.h>
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <cassert>
#include <sstream>
namespace o2
{
typedef void (*setup_fnc)();
void setupFromPlugin(const char* libname, const char* setupfuncname)
{
LOG(INFO) << "Loading simulation plugin " << libname;
auto libHandle = dlopen(libname, RTLD_NOW);
// try to make the library loading a bit more portable:
if (!libHandle) {
// try appending *.so
std::stringstream stream;
stream << libname << ".so";
libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
}
if (!libHandle) {
// try appending *.dylib
std::stringstream stream;
stream << libname << ".dylib";
libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
}
assert(libHandle);
auto setup = (setup_fnc)dlsym(libHandle, setupfuncname);
assert(setup);
setup();
}
void SimSetup::setup(const char* engine)
{
if (strcmp(engine, "TGeant3") == 0) {
setupFromPlugin("libO2G3Setup", "_ZN2o28g3config8G3ConfigEv");
} else if (strcmp(engine, "TGeant4") == 0) {
setupFromPlugin("libO2G4Setup", "_ZN2o28g4config8G4ConfigEv");
} else if (strcmp(engine, "TFluka") == 0) {
setupFromPlugin("libO2FLUKASetup", "_ZN2o211flukaconfig11FlukaConfigEv");
} else {
LOG(FATAL) << "Unsupported engine " << engine;
}
o2::SetCuts();
}
} // namespace o2