Project
Loading...
Searching...
No Matches
VMCSeederService.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
13#include "TVirtualMC.h"
14#include <fairlogger/Logger.h> // for FairLogger
15#include <CommonUtils/ConfigurationMacroHelper.h> // for ROOT JIT helpers
16
17using namespace o2::base;
18
19void VMCSeederService::initSeederFunction(TVirtualMC const* vmc)
20{
21 if (strcmp(vmc->GetName(), "TGeant3TGeo") == 0) {
22 // Geant3 doesn't need anything special in our context
23 mSeederFcn = []() {};
24 } else if (strcmp(vmc->GetName(), "TGeant4") == 0) {
25 // dynamically get access to the Geant4_VMC seeding function (without this function linking against Geant4)
26 std::string G4func("std::function<void()> G4func() { gSystem->Load(\"libgeant4vmc\"); return [](){ ((TGeant4*)TVirtualMC::GetMC())->SetRandomSeed(); };}");
27 mSeederFcn = o2::conf::JITAndEvalFunction<SeederFcn>(G4func, "G4func()", "std::function<void()>", "VMCSEEDERFUNC123");
28 } else {
29 LOG(warn) << "Unknown VMC engine or unimplemented VMC seeding function";
30 mSeederFcn = []() {};
31 }
32}
33
34// constructor
35VMCSeederService::VMCSeederService()
36{
37 auto vmc = TVirtualMC::GetMC();
38 if (vmc) {
39 LOG(info) << "Seeder initializing for " << vmc->GetName();
40 initSeederFunction(vmc);
41 } else {
42 LOG(fatal) << " Seeder could not be initialized (no VMC instance found)";
43 }
44}
45
47{
48 // Make sure gRandom is sufficiently well initialized
49 // by calling Rndm() once.
50 // This is ok since in any case gRandom->SetSeed(seed); gRandom->GetSeed() != seed;
51 gRandom->Rndm();
52 mSeederFcn();
53}
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"