Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
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),
engine_
(engine) {
30
if
(t) {
31
t->setRandomEngine(engine);
32
}
33
}
34
35
explicit
RandomEngineSentry
(
T
*
t
,
StreamID
const
& streamID):
t_
(t),
engine_
(
nullptr
) {
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
engine_
= &rng->getEngine(streamID);
44
t->setRandomEngine(
engine_
);
45
}
46
}
47
48
explicit
RandomEngineSentry
(
T
*
t
,
LuminosityBlockIndex
const
&
lumi
):
t_
(t),
engine_
(
nullptr
) {
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
engine_
= &rng->getEngine(lumi);
57
t->setRandomEngine(
engine_
);
58
}
59
}
60
61
~RandomEngineSentry
() {
if
(
t_
)
t_
->setRandomEngine(
nullptr
); }
62
63
CLHEP::HepRandomEngine*
randomEngine
()
const
{
return
engine_
; }
64
65
private
:
66
T
*
t_
;
67
CLHEP::HepRandomEngine*
engine_
;
68
};
69
}
70
#endif
tree.t
tuple t
Definition:
tree.py:139
edm::RandomEngineSentry::t_
T * t_
Definition:
RandomEngineSentry.h:66
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
Exception
Definition:
hltDiff.cc:318
RandomNumberGenerator.h
fjr2json.lumi
tuple lumi
Definition:
fjr2json.py:35
edm::LuminosityBlockIndex
Definition:
LuminosityBlockIndex.h:33
edm::StreamID
Definition:
StreamID.h:30
nullptr
#define nullptr
edm::RandomEngineSentry::randomEngine
CLHEP::HepRandomEngine * randomEngine() const
Definition:
RandomEngineSentry.h:63
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::RandomEngineSentry
Definition:
RandomEngineSentry.h:26
edm::RandomEngineSentry::engine_
CLHEP::HepRandomEngine * engine_
Definition:
RandomEngineSentry.h:67
T
long double T
Definition:
Basic3DVectorLD.h:57
Generated for CMSSW Reference Manual by
1.8.5