cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
N/A
Central exclusive processes event generator
Toggle main menu visibility
Main Page
Related Pages
Packages
Package List
Package Members
All
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
x
y
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
x
y
Variables
Typedefs
Enumerations
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
p
q
r
s
t
u
v
w
x
y
z
Typedefs
Enumerations
Enumerator
b
c
d
e
g
h
i
l
m
n
p
r
t
u
w
x
y
z
Related Symbols
d
g
h
o
u
v
Files
File List
File Members
All
_
a
b
c
d
e
h
o
p
r
s
Functions
Variables
Macros
_
b
c
d
e
p
r
s
▼
CepGen
Reference manual
Bibliography
►
Packages
►
Classes
▼
Files
▼
File List
▼
include
▼
CepGen
►
Cards
►
Core
►
Event
►
EventFilter
►
FormFactors
►
Integration
▼
Modules
►
CardsHandlerFactory.h
►
CouplingFactory.h
►
DerivatorFactory.h
►
DocumentationGeneratorFactory.h
►
DrawerFactory.h
►
EventExporterFactory.h
►
EventImporterFactory.h
►
EventModifierFactory.h
►
FormFactorsFactory.h
►
FunctionalFactory.h
►
GeneratorWorkerFactory.h
►
IntegratorFactory.h
►
ModuleFactory.h
ModuleFactoryImpl.h
►
NamedModule.h
►
PartonFluxFactory.h
►
PartonsPhaseSpaceGeneratorFactory.h
►
PhaseSpaceGeneratorFactory.h
►
ProcessFactory.h
►
RandomGeneratorFactory.h
►
StructureFunctionsFactory.h
►
PartonFluxes
►
Physics
►
Process
►
StructureFunctions
►
Utils
►
Generator.h
►
Version.h
►
CepGenBoost
►
CepGenHepMC2
►
CepGenHepMC3
►
CepGenHerwig6
►
CepGenMadGraph
►
CepGenPythia6
►
CepGenPythia8
►
CepGenPython
►
CepGenRoot
►
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Loading...
Searching...
No Matches
ModuleFactory.h
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2018-2025 Laurent Forthomme
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef CepGen_Modules_ModuleFactory_h
20
#define CepGen_Modules_ModuleFactory_h
21
22
#include <memory>
23
#include <sstream>
24
25
#include "
CepGen/Core/ParametersDescription.h
"
26
28
#define BUILDER_NAME(obj) obj##Builder
30
#define DEFINE_FACTORY(name, obj_type, description) \
31
struct name : public ModuleFactory<obj_type> { \
32
explicit name() : ModuleFactory(description) {} \
33
inline static name& get() { \
34
static name instance; \
35
return instance; \
36
} \
37
inline name& addIndex(int index, const std::string& mod_name) { \
38
indices_[index] = mod_name; \
39
return *this; \
40
} \
41
}; \
42
static_assert(true, "")
30
#define DEFINE_FACTORY(name, obj_type, description) \
…
43
44
namespace
cepgen
{
47
template
<
typename
T>
48
class
ModuleFactory
{
49
public
:
50
ModuleFactory
(
const
ModuleFactory
&) =
delete
;
51
virtual
~ModuleFactory
() =
default
;
52
void
operator=
(
const
ModuleFactory
&) =
delete
;
53
54
inline
const
std::string&
description
()
const
{
return
description_; }
55
58
template
<
typename
U>
59
void
registerModule
(
const
std::string& name,
const
ParametersList
& def_params =
ParametersList
()) {
60
static_assert
(std::is_base_of_v<T, U>,
61
"\n\n *** Failed to register an object with improper inheritance into the factory. ***\n"
);
62
if
(
has
(name)) {
63
std::ostringstream oss;
64
oss <<
"\n\n *** "
<< description_ <<
" detected a duplicate module registration for index/name \""
<< name
65
<<
"\"! ***\n"
;
66
throw
std::invalid_argument(oss.str());
67
}
68
map_.insert(std::make_pair(name, &buildModule<U>));
69
auto
desc = U::description();
70
if
(!def_params.empty())
71
desc.parameters() += def_params;
72
desc.parameters().setName(name);
73
params_map_[name] = desc;
74
}
59
void
registerModule
(
const
std::string& name,
const
ParametersList
& def_params =
ParametersList
()) {
…
}
77
virtual
std::unique_ptr<T>
build
(
const
ParametersList
& params)
const
;
81
std::unique_ptr<T>
build
(
const
std::string& name,
const
ParametersList
& params =
ParametersList
())
const
;
85
std::unique_ptr<T>
build
(
int
index,
const
ParametersList
& params =
ParametersList
())
const
;
86
87
typedef
std::unique_ptr<T> (*
Builder
)(
const
ParametersList
&);
88
89
std::string
describe
(
const
std::string& name)
const
;
92
ParametersDescription
describeParameters
(
const
ParametersList
& parameters)
const
;
96
ParametersDescription
describeParameters
(
const
std::string& name,
97
const
ParametersList
& params =
ParametersList
())
const
;
101
ParametersDescription
describeParameters
(
int
index,
const
ParametersList
& params =
ParametersList
())
const
;
102
103
std::vector<std::string>
modules
()
const
;
104
inline
bool
empty
()
const
{
return
map_.empty(); }
105
inline
size_t
size
()
const
{
return
map_.size(); }
106
108
inline
const
std::unordered_map<int, std::string>&
indices
()
const
{
return
indices_
; }
109
111
inline
bool
has
(
const
std::string& name)
const
{
return
map_.count(name) > 0; }
112
113
private
:
115
template
<
typename
U>
116
static
std::unique_ptr<T> buildModule(
const
ParametersList
& params) {
117
return
std::make_unique<U>(params);
118
}
119
const
std::string description_;
120
std::unordered_map<std::string, Builder> map_;
121
std::unordered_map<std::string, ParametersDescription> params_map_;
122
const
ParametersDescription empty_params_desc_;
123
124
protected
:
125
explicit
ModuleFactory
(
const
std::string&);
126
std::unordered_map<int, std::string>
indices_
;
127
};
128
}
// namespace cepgen
129
130
#endif
105
inline
size_t
size
()
const
{
return
map_.size(); } {
…
}
48
class
ModuleFactory
{
…
};
ParametersDescription.h
cepgen::ModuleFactory
A generic factory to build modules.
Definition
ModuleFactory.h:48
cepgen::ModuleFactory::Builder
std::unique_ptr< T >(* Builder)(const ParametersList &)
Constructor type for a module.
Definition
ModuleFactory.h:87
cepgen::ModuleFactory::describeParameters
ParametersDescription describeParameters(int index, const ParametersList ¶ms=ParametersList()) const
Describe the parameters of one named module.
cepgen::ModuleFactory::ModuleFactory
ModuleFactory(const ModuleFactory &)=delete
Disabled copy constructor.
cepgen::ModuleFactory::build
virtual std::unique_ptr< T > build(const ParametersList ¶ms) const
Build one instance of a named module.
cepgen::ModuleFactory::size
size_t size() const
Multiplicity of modules registered in the database.
Definition
ModuleFactory.h:105
cepgen::ModuleFactory::describe
std::string describe(const std::string &name) const
Describe one named module Describe the parameters of one named module.
cepgen::ModuleFactory::~ModuleFactory
virtual ~ModuleFactory()=default
Default destructor.
cepgen::ModuleFactory::empty
bool empty() const
Is the database empty?
Definition
ModuleFactory.h:104
cepgen::ModuleFactory::modules
std::vector< std::string > modules() const
List of modules registered in the database.
cepgen::ModuleFactory::operator=
void operator=(const ModuleFactory &)=delete
Disabled assignment operator.
cepgen::ModuleFactory::has
bool has(const std::string &name) const
Check if a named module is registered.
Definition
ModuleFactory.h:109
cepgen::ModuleFactory::description
const std::string & description() const
Describe the modules factory.
Definition
ModuleFactory.h:54
cepgen::ModuleFactory::build
std::unique_ptr< T > build(const std::string &name, const ParametersList ¶ms=ParametersList()) const
Build one instance of a named module.
cepgen::ModuleFactory::registerModule
void registerModule(const std::string &name, const ParametersList &def_params=ParametersList())
Register a named module in the database.
Definition
ModuleFactory.h:59
cepgen::ModuleFactory::indices_
std::unordered_map< int, std::string > indices_
Index-to-map association map.
Definition
ModuleFactory.h:124
cepgen::ModuleFactory::describeParameters
ParametersDescription describeParameters(const ParametersList ¶meters) const
cepgen::ModuleFactory::describeParameters
ParametersDescription describeParameters(const std::string &name, const ParametersList ¶ms=ParametersList()) const
Describe the parameters of one named module.
cepgen::ModuleFactory::indices
const std::unordered_map< int, std::string > & indices() const
Definition
ModuleFactory.h:106
cepgen::ModuleFactory::build
std::unique_ptr< T > build(int index, const ParametersList ¶ms=ParametersList()) const
Build one instance of a named module.
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen
Common namespace for this Monte Carlo generator.
Definition
Handler.h:26
include
CepGen
Modules
ModuleFactory.h
Generated on Tue Apr 22 2025 for CepGen by
1.10.0