ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Generators
Pythia8_i
src
UserHooks
UserSetting.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef PYTHIA8_USERHOOKS_USERSETTING_H
6
#define PYTHIA8_USERHOOKS_USERSETTING_H
7
8
#include "Pythia8/Settings.h"
9
#include "
Pythia8_i/UserHooksFactory.h
"
10
#include <string>
11
#include <stdexcept>
12
13
14
namespace
Pythia8_UserHooks
{
15
16
template
<
class
T>
17
class
UserSetting
{
18
19
public
:
20
21
UserSetting
(
const
std::string & name,
const
T & defaultValue):
22
m_paramName
(name),
23
m_param
(defaultValue),
24
m_settingsPtr
(0),
25
m_retrieved
(false){
26
27
typename
std::map<std::string, T>::const_iterator test =
UserHooksFactory::userSettings<T>
().find(
m_paramName
);
28
if
(test !=
UserHooksFactory::userSettings<T>
().end())
throw
std::runtime_error(
"Duplicate user-defined setting already exists: "
+
m_paramName
);
29
UserHooksFactory::userSettings<T>
()[
m_paramName
] = defaultValue;
30
31
}
32
33
T
operator()
(Pythia8::Settings *settingsPtr){
34
35
if
(
m_settingsPtr
== 0 && settingsPtr == 0)
throw
std::runtime_error(
"settingsPtr is not yet initialised!"
);
36
37
if
(
m_retrieved
&&
m_settingsPtr
== settingsPtr)
return
m_param
;
38
39
m_settingsPtr
= settingsPtr;
40
m_param
=
uncachedRetrieve
();
41
m_retrieved
=
true
;
42
return
m_param
;
43
};
44
45
protected
:
46
47
std::string
m_paramName
;
48
T
m_param
;
49
Pythia8::Settings *
m_settingsPtr
;
50
bool
m_retrieved
;
51
52
private
:
53
54
T
uncachedRetrieve
();
55
56
};
57
58
template
<>
59
inline
double
UserSetting<double>::uncachedRetrieve
(){
60
auto
result =
m_param
;
61
if
(not
m_settingsPtr
->isParm(
m_paramName
)){
62
throw
std::runtime_error(
"UserSetting "
+
m_paramName
+
" does not exist!"
);
63
}
64
result =
m_settingsPtr
->parm(
m_paramName
);
65
return
result;
66
}
67
68
template
<>
69
inline
int
UserSetting<int>::uncachedRetrieve
(){
70
if
(not
m_settingsPtr
->isMode(
m_paramName
)){
71
throw
std::runtime_error(
"UserSetting "
+
m_paramName
+
" does not exist!"
);
72
}
73
return
m_settingsPtr
->mode(
m_paramName
);
74
}
75
76
template
<>
77
inline
bool
UserSetting<bool>::uncachedRetrieve
(){
78
if
(not
m_settingsPtr
->isFlag(
m_paramName
)){
79
throw
std::runtime_error(
"UserSetting "
+
m_paramName
+
" does not exist!"
);
80
}
81
return
m_settingsPtr
->flag(
m_paramName
);
82
}
83
84
85
template
<>
86
inline
std::string
UserSetting<std::string>::uncachedRetrieve
(){
87
if
(not
m_settingsPtr
->isWord(
m_paramName
)){
88
throw
std::runtime_error(
"UserSetting "
+
m_paramName
+
" does not exist!"
);
89
}
90
return
m_settingsPtr
->word(
m_paramName
);
91
}
92
93
}
94
#endif
UserHooksFactory.h
Pythia8_UserHooks::UserHooksFactory::userSettings
static std::map< std::string, T > & userSettings()
Pythia8_UserHooks::UserSetting::uncachedRetrieve
T uncachedRetrieve()
Pythia8_UserHooks::UserSetting::m_param
T m_param
Definition
UserSetting.h:48
Pythia8_UserHooks::UserSetting::m_paramName
std::string m_paramName
Definition
UserSetting.h:47
Pythia8_UserHooks::UserSetting::m_settingsPtr
Pythia8::Settings * m_settingsPtr
Definition
UserSetting.h:49
Pythia8_UserHooks::UserSetting::m_retrieved
bool m_retrieved
Definition
UserSetting.h:50
Pythia8_UserHooks::UserSetting::operator()
T operator()(Pythia8::Settings *settingsPtr)
Definition
UserSetting.h:33
Pythia8_UserHooks::UserSetting::UserSetting
UserSetting(const std::string &name, const T &defaultValue)
Definition
UserSetting.h:21
Pythia8_UserHooks
Some common functions for determining pTs and navigating event records for the PoWHEG + Pythia user h...
Definition
UserHooksFactory.h:30
Generated on
for ATLAS Offline Software by
1.17.0