ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
RngComps
src
AthRNGSvc.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
AthRNGSvc.h
"
6
#include "
AthenaKernel/RNGWrapper.h
"
7
#include "
AthenaKernel/SlotSpecificObj.h
"
8
9
#include "
AtlasCLHEP_RandomGenerators/dSFMTEngine.h
"
10
#include "CLHEP/Random/MixMaxRng.h"
11
#include "CLHEP/Random/Ranlux64Engine.h"
12
#include "CLHEP/Random/RanecuEngine.h"
13
14
15
AthRNGSvc::AthRNGSvc
(
const
std::string& name, ISvcLocator* svc)
16
: base_class(name, svc),
17
m_rngType
(
"dSFMT"
)
18
{
19
declareProperty(
"EngineType"
,
m_rngType
,
"CLHEP RandomEngine type"
);
20
}
21
22
StatusCode
AthRNGSvc::initialize
()
23
{
24
if
(
m_rngType
==
"dSFMT"
) {
25
m_fact
= [](void)->CLHEP::HepRandomEngine*{
26
return
new
CLHEP::dSFMTEngine
();
27
};
28
}
else
if
(
m_rngType
==
"Ranlux64"
) {
29
m_fact
= [](void)->CLHEP::HepRandomEngine*{
30
return
new
CLHEP::Ranlux64Engine();
31
};
32
}
else
if
(
m_rngType
==
"Ranecu"
) {
33
m_fact
= [](void)->CLHEP::HepRandomEngine*{
34
return
new
CLHEP::RanecuEngine();
35
};
36
}
else
if
(
m_rngType
==
"MixMax"
) {
37
m_fact
= [](void)->CLHEP::HepRandomEngine*{
38
return
new
CLHEP::MixMaxRng();
39
};
40
}
else
{
41
ATH_MSG_WARNING
(
"Supported Generator types are 'dSFMT', 'Ranlux64', 'Ranecu', 'MixMax'"
);
42
ATH_MSG_FATAL
(
"Generator type \""
<<
m_rngType
<<
"\" is not known. Check Joboptions"
);
43
return
StatusCode::FAILURE;
44
}
45
46
return
StatusCode::SUCCESS;
47
}
48
49
ATHRNG::RNGWrapper
*
AthRNGSvc::getEngine
(
const
INamedInterface* client,
50
const
std::string& streamName)
51
{
52
// Retrieve number of event slots
53
size_t
numSlots =
SG::getNSlots
();
54
55
// The name key combines the client name and optional stream name
56
std::string rngName = client->name();
57
if
(!streamName.empty()) rngName +=
"/"
+ streamName;
58
59
// Look for an existing RNG stream
60
std::lock_guard<std::mutex>
lock
(
m_mutex
);
61
auto
it =
m_wrappers
.find(rngName);
62
63
// Construct a new RNGWrapper if none exists
64
if
(it ==
m_wrappers
.end()){
65
ATH_MSG_INFO
(
"Creating engine "
<< rngName);
66
auto
wrp =
new
ATHRNG::RNGWrapper
(
m_fact
, numSlots);
67
m_wrappers
.insert( std::make_pair(rngName, wrp) );
68
return
wrp;
69
}
70
71
ATH_MSG_DEBUG
(
"Returning engine "
<< rngName);
72
return
it->second;
73
}
74
75
void
AthRNGSvc::printEngineState
(
const
INamedInterface* client,
76
const
std::string& streamName)
77
{
78
// Retrieve the current slot's engine
79
ATHRNG::RNGWrapper
* wrapper =
getEngine
(client, streamName);
80
CLHEP::HepRandomEngine* engine( *wrapper );
81
82
// Extract the engine state numbers
83
std::vector<unsigned long> rngStates = engine->put();
84
85
// Print the state numbers
86
std::string rngName = client->name();
87
if
(!streamName.empty()) rngName +=
"/"
+ streamName;
88
std::lock_guard<std::mutex>
lock
(
m_mutex
);
89
msg
(MSG::ALWAYS) << rngName <<
" "
;
90
// We mask 32 bits because the other bits are garbage and unused
91
for
(
const
unsigned
long
s : rngStates) {
92
msg
() << (s & 0xffffffffu) <<
" "
;
93
}
94
msg
() <<
endmsg
;
95
}
96
97
AthRNGSvc::~AthRNGSvc
()
98
{
99
// Clean up the RNGWrappers and HepRandomEngines
100
for
(
auto
& wrapperPair :
m_wrappers
) {
101
delete
wrapperPair.second;
102
}
103
}
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
AthRNGSvc.h
SlotSpecificObj.h
Maintain a set of objects, one per slot.
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
RNGWrapper.h
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition
RNGWrapper.h:56
AthRNGSvc::printEngineState
virtual void printEngineState(const INamedInterface *client, const std::string &streamName="") override final
Print engine state.
Definition
AthRNGSvc.cxx:75
AthRNGSvc::m_mutex
std::mutex m_mutex
Mutex for protecting access to the wrapper structure.
Definition
AthRNGSvc.h:66
AthRNGSvc::AthRNGSvc
AthRNGSvc(const std::string &name, ISvcLocator *svc)
Standard constructor.
Definition
AthRNGSvc.cxx:15
AthRNGSvc::m_wrappers
std::unordered_map< std::string, ATHRNG::RNGWrapper * > m_wrappers
The structure for storing the RNGWrappers.
Definition
AthRNGSvc.h:59
AthRNGSvc::m_fact
factoryFunc m_fact
Definition
AthRNGSvc.h:63
AthRNGSvc::m_rngType
std::string m_rngType
Random number engine type (e.g. dSFMT, ranecu).
Definition
AthRNGSvc.h:56
AthRNGSvc::~AthRNGSvc
virtual ~AthRNGSvc()
Definition
AthRNGSvc.cxx:97
AthRNGSvc::initialize
StatusCode initialize() override final
Initialize the service.
Definition
AthRNGSvc.cxx:22
AthRNGSvc::getEngine
virtual ATHRNG::RNGWrapper * getEngine(const INamedInterface *client, const std::string &streamName="") override final
IAthRNGSvc method to retrieve the random number wrapper.
Definition
AthRNGSvc.cxx:49
CLHEP::dSFMTEngine
Definition
dSFMTEngine.h:31
dSFMTEngine.h
SG::getNSlots
size_t getNSlots()
Return the number of event slots.
Definition
SlotSpecificObj.cxx:64
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.17.0