Project
Loading...
Searching...
No Matches
VMCSeederService.h
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#ifndef ALICEO2_VMC_SEEDERSERVICE_H
13#define ALICEO2_VMC_SEEDERSERVICE_H
14
15class TVirtualMC;
16class TRandom;
17
18#include <atomic>
19#include <functional>
20
21namespace o2
22{
23namespace base
24{
25
26// A simple (singleton) service to propagate random number seeding
27// to VMC engines in a loosely-coupled, just-in-time way (without needing to compile against these libraries).
29{
30
31 public:
32 static VMCSeederService const& instance()
33 {
34 static VMCSeederService inst;
35 return inst;
36 }
37
38 void setSeed() const; // will propagate the seed of o2::base::simRandom() to the VMC engine of this thread
39
41 unsigned long long getSeedCount() const { return mSeedCount; }
42
43 typedef std::function<void(TRandom*)> SeederFcn;
44
46 static void setGeant4Seeder(SeederFcn fcn) { geant4Seeder() = std::move(fcn); }
47
48 private:
50 static SeederFcn& geant4Seeder()
51 {
52 static SeederFcn fcn;
53 return fcn;
54 }
55 void initSeederFunction(TVirtualMC const*);
56
57 SeederFcn mSeederFcn; // the function talking to the VMC engine
58 mutable std::atomic<unsigned long long> mSeedCount{0}; // number of setSeed() calls
59};
60
61} // namespace base
62} // namespace o2
63
64#endif
static void setGeant4Seeder(SeederFcn fcn)
installs the function that seeds Geant4 from a generator; called by the Geant4 configuration,...
unsigned long long getSeedCount() const
how often a seed was propagated; lets callers detect a silent no-op
std::function< void(TRandom *)> SeederFcn
static VMCSeederService const & instance()
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...