Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
src
FWCore
ServiceRegistry
interface
RandomEngineSentry.h
Go to the documentation of this file.
1
#ifndef FWCore_ServiceRegistry_RandomEngineSentry_h
2
#define FWCore_ServiceRegistry_RandomEngineSentry_h
3
9
//
10
// Original Author: W. David Dagenhart
11
// Created: 11/26/2013
12
13
#include "
FWCore/ServiceRegistry/interface/Service.h
"
14
#include "
FWCore/Utilities/interface/Exception.h
"
15
#include "
FWCore/Utilities/interface/RandomNumberGenerator.h
"
16
17
namespace
CLHEP {
18
class
HepRandomEngine;
19
}
20
21
namespace
edm {
22
23
class
LuminosityBlockIndex;
24
class
StreamID;
25
26
template
<
class
T>
class
RandomEngineSentry
{
27
public
:
28
29
explicit
RandomEngineSentry
(
T
*
t
, CLHEP::HepRandomEngine* engine):
t_
(t) {
30
if
(t) {
31
t->setRandomEngine(engine);
32
}
33
}
34
35
explicit
RandomEngineSentry
(
T
*
t
,
StreamID
const
& streamID):
t_
(t) {
36
if
(t) {
37
Service<RandomNumberGenerator>
rng;
38
if
(!rng.
isAvailable
()) {
39
throw
cms::Exception
(
"Configuration"
)
40
<<
"Attempt to get a random engine when the RandomNumberGeneratorService is not configured.\n"
41
"You must configure the service if you want an engine.\n"
;
42
}
43
CLHEP::HepRandomEngine& engine = rng->getEngine(streamID);
44
t->setRandomEngine(&engine);
45
}
46
}
47
48
explicit
RandomEngineSentry
(
T
*
t
,
LuminosityBlockIndex
const
&
lumi
):
t_
(t) {
49
if
(t) {
50
Service<RandomNumberGenerator>
rng;
51
if
(!rng.
isAvailable
()) {
52
throw
cms::Exception
(
"Configuration"
)
53
<<
"Attempt to get a random engine when the RandomNumberGeneratorService is not configured.\n"
54
"You must configure the service if you want an engine.\n"
;
55
}
56
CLHEP::HepRandomEngine& engine = rng->getEngine(lumi);
57
t->setRandomEngine(&engine);
58
}
59
}
60
61
~RandomEngineSentry
() {
if
(
t_
)
t_
->setRandomEngine(
nullptr
); }
62
63
private
:
64
T
*
t_
;
65
};
66
}
67
#endif
edm::RandomEngineSentry::t_
T * t_
Definition:
RandomEngineSentry.h:64
edm::Service
Definition:
Service.h:30
edm::RandomEngineSentry::RandomEngineSentry
RandomEngineSentry(T *t, LuminosityBlockIndex const &lumi)
Definition:
RandomEngineSentry.h:48
edm::RandomEngineSentry::~RandomEngineSentry
~RandomEngineSentry()
Definition:
RandomEngineSentry.h:61
RandomNumberGenerator.h
lumiQTWidget.t
tuple t
Definition:
lumiQTWidget.py:50
fjr2json.lumi
tuple lumi
Definition:
fjr2json.py:35
edm::LuminosityBlockIndex
Definition:
LuminosityBlockIndex.h:33
edm::StreamID
Definition:
StreamID.h:30
edm::RandomEngineSentry::RandomEngineSentry
RandomEngineSentry(T *t, StreamID const &streamID)
Definition:
RandomEngineSentry.h:35
edm::Service::isAvailable
bool isAvailable() const
Definition:
Service.h:46
Service.h
edm::RandomEngineSentry::RandomEngineSentry
RandomEngineSentry(T *t, CLHEP::HepRandomEngine *engine)
Definition:
RandomEngineSentry.h:29
Exception.h
edm::hlt::Exception
error
Definition:
HLTenums.h:21
edm::RandomEngineSentry
Definition:
RandomEngineSentry.h:26
T
long double T
Definition:
Basic3DVectorLD.h:59
Generated for CMSSW Reference Manual by
1.8.5