Project
Loading...
Searching...
No Matches
SimSetup.cxx
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#include <cstring>
13#include "SimSetup/SimSetup.h"
14#include "TVirtualMC.h"
15#include <fairlogger/Logger.h>
16#include "SetCuts.h"
17#include <dlfcn.h>
18#ifdef NDEBUG
19#undef NDEBUG
20#endif
21#include <cassert>
22#include <sstream>
23
24namespace o2
25{
26
27typedef void (*setup_fnc)();
28
29void execFromPlugin(const char* libname, const char* funcname)
30{
31 auto libHandle = dlopen(libname, RTLD_NOW);
32 // try to make the library loading a bit more portable:
33 if (!libHandle) {
34 // try appending *.so
35 std::stringstream stream;
36 stream << libname << ".so";
37 libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
38 }
39 if (!libHandle) {
40 // try appending *.dylib
41 std::stringstream stream;
42 stream << libname << ".dylib";
43 libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
44 }
45 assert(libHandle);
46 auto func = (setup_fnc)dlsym(libHandle, funcname);
47 assert(func);
48 func();
49}
50
51void execSetupFromPlugin(const char* libname, const char* funcname)
52{
53 LOG(info) << "Setting up transport engine from library " << libname;
54 execFromPlugin(libname, funcname);
55}
56
57void SimSetup::setup(const char* engine)
58{
59 if (strcmp(engine, "TGeant3") == 0) {
60 execSetupFromPlugin("libO2G3Setup", "_ZN2o28g3config8G3ConfigEv");
61 } else if (strcmp(engine, "TGeant4") == 0) {
62 execSetupFromPlugin("libO2G4Setup", "_ZN2o28g4config8G4ConfigEv");
63 } else if (strcmp(engine, "TFluka") == 0) {
64 execSetupFromPlugin("libO2FLUKASetup", "_ZN2o211flukaconfig11FlukaConfigEv");
65 } else if (strcmp(engine, "MCReplay") == 0) {
66 execSetupFromPlugin("libO2MCReplaySetup", "_ZN2o214mcreplayconfig14MCReplayConfigEv");
67 } else if (strcmp(engine, "O2TrivialMCEngine") == 0) {
68 execSetupFromPlugin("libO2O2TrivialMCEngineSetup", "_ZN2o223o2trivialmcengineconfig23O2TrivialMCEngineConfigEv");
69 } else {
70 LOG(fatal) << "Unsupported engine " << engine;
71 }
73}
74
75// function to shutdown the engines and do some necessary
76// finalisation work
78{
79 auto vmc = TVirtualMC::GetMC();
80 if (strcmp(vmc->GetName(), "TGeant4") == 0) {
81 execFromPlugin("libO2G4Setup", "_ZN2o28g4config11G4TerminateEv");
82 }
83}
84
85} // namespace o2
GLenum func
Definition glcorearb.h:778
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLuint stream
Definition glcorearb.h:1806
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
void execFromPlugin(const char *libname, const char *funcname)
Definition SimSetup.cxx:29
void SetCuts()
Definition SetCuts.cxx:22
void(* setup_fnc)()
Definition SimSetup.cxx:27
void execSetupFromPlugin(const char *libname, const char *funcname)
Definition SimSetup.cxx:51
static void shutdown()
Definition SimSetup.cxx:77
static void setup(const char *engine)
Definition SimSetup.cxx:57
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"