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"
18#include <dlfcn.h>
19#include <string>
20
21namespace o2
22{
23
24typedef void (*setup_fnc)();
25
26void execFromPlugin(const char* libname, const char* funcname)
27{
28 const std::string filename = std::string(libname) + DLLOADER_MAC_LINUX(".dylib", ".so");
29 auto libHandle = dlopen(filename.c_str(), RTLD_NOW);
30 if (!libHandle) {
31 const char* error = dlerror();
32 LOG(fatal) << "Cannot load " << filename << ": " << (error ? error : "unknown error");
33 // LOG(fatal) ends the process only when a fatal handler is installed
34 throw fair::FatalException("Cannot load " + filename);
35 }
36 dlerror(); // clear any pending error before dlsym
37 auto func = (setup_fnc)dlsym(libHandle, funcname);
38 if (!func) {
39 const char* error = dlerror();
40 LOG(fatal) << "Cannot find " << funcname << " in " << filename << ": " << (error ? error : "the symbol is null");
41 throw fair::FatalException("Cannot find " + std::string(funcname) + " in " + filename);
42 }
43 func();
44}
45
46void execSetupFromPlugin(const char* libname, const char* funcname)
47{
48 LOG(info) << "Setting up transport engine from library " << libname;
49 execFromPlugin(libname, funcname);
50}
51
52void SimSetup::setup(const char* engine)
53{
54 if (strcmp(engine, "TGeant3") == 0) {
55 execSetupFromPlugin("libO2G3Setup", "_ZN2o28g3config8G3ConfigEv");
56 } else if (strcmp(engine, "TGeant4") == 0) {
57 execSetupFromPlugin("libO2G4Setup", "_ZN2o28g4config8G4ConfigEv");
58 } else if (strcmp(engine, "TFluka") == 0) {
59 execSetupFromPlugin("libO2FLUKASetup", "_ZN2o211flukaconfig11FlukaConfigEv");
60 } else if (strcmp(engine, "MCReplay") == 0) {
61 execSetupFromPlugin("libO2MCReplaySetup", "_ZN2o214mcreplayconfig14MCReplayConfigEv");
62 } else if (strcmp(engine, "O2TrivialMCEngine") == 0) {
63 execSetupFromPlugin("libO2O2TrivialMCEngineSetup", "_ZN2o223o2trivialmcengineconfig23O2TrivialMCEngineConfigEv");
64 } else {
65 LOG(fatal) << "Unsupported engine " << engine;
66 }
68}
69
70// function to shutdown the engines and do some necessary
71// finalisation work
73{
74 auto vmc = TVirtualMC::GetMC();
75 if (strcmp(vmc->GetName(), "TGeant4") == 0) {
76 execFromPlugin("libO2G4Setup", "_ZN2o28g4config11G4TerminateEv");
77 }
78}
79
80} // namespace o2
#define DLLOADER_MAC_LINUX(mac, linux)
char error[CURL_ERROR_SIZE]
GLenum func
Definition glcorearb.h:778
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
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:26
void SetCuts()
Definition SetCuts.cxx:22
void(* setup_fnc)()
Definition SimSetup.cxx:24
void execSetupFromPlugin(const char *libname, const char *funcname)
Definition SimSetup.cxx:46
std::string filename()
static void shutdown()
Definition SimSetup.cxx:72
static void setup(const char *engine)
Definition SimSetup.cxx:52
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"