Skip to content

Commit 5a763d1

Browse files
committed
Decouple VMC libs from o2-sim
This is going back to loading VMC engines as real plugins **while** retaining the advantage of compiling the configuration templates and avoiding ROOT macros execution during startup. This brings the advantage that not all engine libs are loaded at startup simultaneously.
1 parent be0e415 commit 5a763d1

File tree

6 files changed

+77
-61
lines changed

6 files changed

+77
-61
lines changed

Detectors/gconfig/CMakeLists.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
# granted to it by virtue of its status as an Intergovernmental Organization or
99
# submit itself to any jurisdiction.
1010

11+
o2_add_library(G3Setup
12+
SOURCES src/G3Config.cxx
13+
PUBLIC_LINK_LIBRARIES MC::Geant3 FairRoot::Base O2::SimulationDataFormat O2::Generators
14+
)
15+
16+
o2_add_library(G4Setup
17+
SOURCES src/G4Config.cxx
18+
PUBLIC_LINK_LIBRARIES MC::Geant4VMC MC::Geant4 FairRoot::Base O2::SimulationDataFormat O2::Generators ROOT::EGPythia6
19+
)
20+
1121
o2_add_library(SimSetup
12-
SOURCES src/G3Config.cxx src/G4Config.cxx
13-
src/GlobalProcessCutSimParam.cxx src/SimSetup.cxx
14-
PUBLIC_LINK_LIBRARIES MC::Geant3
15-
MC::Geant4VMC
16-
MC::Geant4
17-
O2::SimulationDataFormat
18-
O2::DetectorsPassive
19-
O2::Generators
20-
MC::Pythia6 # this is needed by Geant3 and
21-
# EGPythia6
22-
ROOT::EGPythia6 # this is needed by Geant4
23-
# (TPythia6Decayer)
24-
)
22+
SOURCES src/GlobalProcessCutSimParam.cxx src/SimSetup.cxx src/SetCuts.cxx
23+
PUBLIC_LINK_LIBRARIES O2::CommonUtils O2::DetectorsBase
24+
)
2525

2626
o2_target_root_dictionary(SimSetup
2727
HEADERS include/SimSetup/SimSetup.h

Detectors/gconfig/src/G3Config.cxx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,23 @@
1313
#include "TGeant3TGeo.h"
1414
#include "SimulationDataFormat/Stack.h"
1515
#include "SimulationDataFormat/StackParam.h"
16-
#include <iostream>
1716
#include "FairLogger.h"
1817
#include "FairModule.h"
19-
#include <DetectorsPassive/Cave.h>
20-
#include "DetectorsBase/MaterialManager.h"
21-
#include "SimSetup/GlobalProcessCutSimParam.h"
2218
#include "Generators/DecayerPythia8.h"
2319

24-
//using declarations here since SetCuts.C and g3Config.C are included within namespace
25-
// these are needed for SetCuts.C inclusion
26-
using o2::GlobalProcessCutSimParam;
27-
using o2::base::ECut;
28-
using o2::base::EProc;
29-
using o2::base::MaterialManager;
30-
// these are used in g3Config.C
31-
using std::cout;
32-
using std::endl;
3320
// these are used in commonConfig.C
3421
using o2::eventgen::DecayerPythia8;
35-
#include <SimSetup/SimSetup.h>
3622

3723
namespace o2
3824
{
3925
namespace g3config
4026
{
4127
#include "../g3Config.C"
42-
#include "../SetCuts.h"
4328

4429
void G3Config()
4530
{
4631
LOG(INFO) << "Setting up G3 sim from library code";
4732
Config();
48-
SetCuts();
4933
}
5034
} // namespace g3config
5135
} // namespace o2

Detectors/gconfig/src/G4Config.cxx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,10 @@
1717
#include "TG4RunConfiguration.h"
1818
#include "TPythia6Decayer.h"
1919
#include "FairModule.h"
20-
#include <DetectorsPassive/Cave.h>
21-
#include "DetectorsBase/MaterialManager.h"
22-
#include "SimSetup/GlobalProcessCutSimParam.h"
2320
#include "SimConfig/G4Params.h"
2421
#include "Generators/DecayerPythia8.h"
2522

2623
//using declarations here since SetCuts.C and g4Config.C are included within namespace
27-
// these are needed for SetCuts.C inclusion
28-
using o2::GlobalProcessCutSimParam;
29-
using o2::base::ECut;
30-
using o2::base::EProc;
31-
using o2::base::MaterialManager;
3224
// these are used in g4Config.C
3325
using std::cout;
3426
using std::endl;
@@ -40,13 +32,11 @@ namespace o2
4032
namespace g4config
4133
{
4234
#include "../g4Config.C"
43-
#include "../SetCuts.h"
4435

4536
void G4Config()
4637
{
4738
LOG(INFO) << "Setting up G4 sim from library code";
4839
Config();
49-
SetCuts();
5040
}
5141
} // namespace g4config
5242
} // namespace o2
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,19 @@
88
// granted to it by virtue of its status as an Intergovernmental Organization
99
// or submit itself to any jurisdiction.
1010

11-
/********************************************************************************
12-
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
13-
* *
14-
* This software is distributed under the terms of the *
15-
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
16-
* copied verbatim in the file "LICENSE" *
17-
********************************************************************************/
11+
#include "SetCuts.h"
12+
#include "SimSetup/GlobalProcessCutSimParam.h"
13+
#include "DetectorsBase/MaterialManager.h"
14+
#include "FairLogger.h"
1815

19-
/** Configuration macro for setting common cuts and processes for G3, G4 and Fluka (M. Al-Turany 27.03.2008)
20-
specific cuts and processes to g3 or g4 should be set in the g3Config.C, g4Config.C or flConfig.C
16+
using namespace o2::base;
2117

22-
*/
18+
namespace o2
19+
{
2320

2421
void SetCuts()
2522
{
26-
cout << "SetCuts Macro: Setting Processes.." << endl;
23+
LOG(INFO) << "Setup global cuts and processes";
2724

2825
// ------>>>> IMPORTANT!!!!
2926
// For a correct comparison between GEANE and MC (pull distributions)
@@ -38,8 +35,8 @@ void SetCuts()
3835

3936
// \note All following settings could also be set in Cave since it is always loaded.
4037
// Use MaterialManager to set processes and cuts
41-
auto& mgr = MaterialManager::Instance();
42-
auto& params = GlobalProcessCutSimParam::Instance();
38+
auto& mgr = o2::base::MaterialManager::Instance();
39+
auto& params = o2::GlobalProcessCutSimParam::Instance();
4340

4441
LOG(INFO) << "Set default settings for processes and cuts.";
4542
mgr.DefaultProcesses({{EProc::kPAIR, params.PAIR}, /** pair production */
@@ -73,3 +70,5 @@ void SetCuts()
7370
LOG(INFO) << "Special process settings are " << settingProc << ".";
7471
LOG(INFO) << "Special cut settings are " << settingCut << ".";
7572
}
73+
74+
} // namespace o2

Detectors/gconfig/src/SetCuts.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef O2_SIMSETUP_SETCUTS_H
12+
#define O2_SIMSETUP_SETCUTS_H
13+
14+
namespace o2
15+
{
16+
void SetCuts();
17+
}
18+
19+
#endif

Detectors/gconfig/src/SimSetup.cxx

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,51 @@
1111
#include <cstring>
1212
#include "SimSetup/SimSetup.h"
1313
#include "FairLogger.h"
14+
#include "SetCuts.h"
15+
#include <dlfcn.h>
16+
#ifdef NDEBUG
17+
#undef NDEBUG
18+
#endif
19+
#include <cassert>
20+
#include <sstream>
1421

1522
namespace o2
1623
{
17-
// forward declarations of functions
18-
namespace g3config
19-
{
20-
void G3Config();
21-
}
22-
namespace g4config
24+
25+
typedef void (*setup_fnc)();
26+
27+
void setupFromPlugin(const char* libname, const char* setupfuncname)
2328
{
24-
void G4Config();
29+
LOG(INFO) << "Loading simulation plugin " << libname;
30+
auto libHandle = dlopen(libname, RTLD_NOW);
31+
// try to make the library loading a bit more portable:
32+
if (!libHandle) {
33+
// try appending *.so
34+
std::stringstream stream;
35+
stream << libname << ".so";
36+
libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
37+
}
38+
if (!libHandle) {
39+
// try appending *.dylib
40+
std::stringstream stream;
41+
stream << libname << ".dylib";
42+
libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
43+
}
44+
assert(libHandle);
45+
auto setup = (setup_fnc)dlsym(libHandle, setupfuncname);
46+
assert(setup);
47+
setup();
2548
}
2649

2750
void SimSetup::setup(const char* engine)
2851
{
2952
if (strcmp(engine, "TGeant3") == 0) {
30-
g3config::G3Config();
53+
setupFromPlugin("libO2G3Setup", "_ZN2o28g3config8G3ConfigEv");
3154
} else if (strcmp(engine, "TGeant4") == 0) {
32-
g4config::G4Config();
55+
setupFromPlugin("libO2G4Setup", "_ZN2o28g4config8G4ConfigEv");
3356
} else {
3457
LOG(FATAL) << "Unsupported engine " << engine;
3558
}
59+
o2::SetCuts();
3660
}
3761
} // namespace o2

0 commit comments

Comments
 (0)