Configuration.cc
1 /*
2  * MoMEMta: a modular implementation of the Matrix Element Method
3  * Copyright (C) 2016 Universite catholique de Louvain (UCL), Belgium
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  * (at your option) 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 #include <momemta/Configuration.h>
20 #include <momemta/ConfigurationReader.h>
21 #include <momemta/ParameterSet.h>
22 
23 #include <ExecutionPath.h>
24 
25 Configuration::ModuleDecl::ModuleDecl(const Configuration::ModuleDecl& other) {
26  name = other.name;
27  type = other.type;
28 
29  if (other.parameters)
30  parameters.reset(other.parameters->clone());
31 }
32 
33 Configuration::ModuleDecl::ModuleDecl(const Configuration::ModuleDecl&& other) {
34  name = std::move(other.name);
35  type = std::move(other.type);
36  parameters = std::move(other.parameters);
37 }
38 
39 Configuration::ModuleDecl& Configuration::ModuleDecl::operator=(Configuration::ModuleDecl other) {
40  std::swap(name, other.name);
41  std::swap(type, other.type);
42  std::swap(parameters, other.parameters);
43 
44  return *this;
45 }
46 
48  modules = other.modules;
49  if (other.global_parameters)
50  global_parameters.reset(other.global_parameters->clone());
51  if (other.cuba_configuration)
52  cuba_configuration.reset(other.cuba_configuration->clone());
53  integrands = other.integrands;
54  paths = other.paths;
55  n_dimensions = other.n_dimensions;
56  inputs = other.inputs;
57 }
58 
60  modules = std::move(other.modules);
61  global_parameters = std::move(other.global_parameters);
62  cuba_configuration = std::move(other.cuba_configuration);
63  integrands = std::move(other.integrands);
64  paths = std::move(other.paths);
65  n_dimensions = other.n_dimensions;
66  inputs = std::move(other.inputs);
67 }
68 
69 Configuration& Configuration::operator=(Configuration other) {
70  std::swap(*this, other);
71  return *this;
72 }
73 
74 const std::vector<Configuration::ModuleDecl>& Configuration::getModules() const {
75  return modules;
76 }
77 
79  return *cuba_configuration;
80 }
81 
83  return *global_parameters;
84 }
85 
86 std::vector<InputTag> Configuration::getIntegrands() const {
87  return integrands;
88 }
89 
90 std::vector<std::shared_ptr<ExecutionPath>> Configuration::getPaths() const {
91  return paths;
92 }
93 
94 std::size_t Configuration::getNDimensions() const {
95  return n_dimensions;
96 }
97 
98 std::vector<std::string> Configuration::getInputs() const {
99  return inputs;
100 }
101 
102 Configuration Configuration::freeze() const {
103  Configuration c = *this;
104 
105  c.global_parameters->freeze();
106  c.cuba_configuration->freeze();
107  for (auto& module: c.modules) {
108  module.parameters->freeze();
109  // Attach global configuration to each module
110  module.parameters->setGlobalParameters(*c.global_parameters);
111  }
112 
113  // Insert internal modules inside the list of modules
114  // See the full list of internal modules in modules/InternalModules.cc
115 
116  auto insert_internal_module = [&c](const std::string& type,
117  const std::string& name,
118  const ParameterSet& parameters) {
119  Configuration::ModuleDecl internal_module;
120  internal_module.type = type;
121  internal_module.name = name;
122  internal_module.parameters = std::make_shared<ParameterSet>(parameters);
123 
124  c.modules.push_back(internal_module);
125  };
126 
127  insert_internal_module("_met", "met", ParameterSet());
128  insert_internal_module("_cuba", "cuba", ParameterSet());
129 
130  auto inputs = c.getInputs();
131  for (const auto& input: inputs) {
132  insert_internal_module("_input", input, ParameterSet());
133  }
134 
135  // Insert the MoMEMta module, fetching the integrands
136  std::vector<InputTag> integrands = c.getIntegrands();
137  ParameterSet pset;
138  pset.set("integrands", integrands);
139  insert_internal_module("_momemta", "momemta", pset);
140 
141  return c;
142 }
Configuration(const Configuration &)
Copy constructor.
size_t getNDimensions() const
std::string name
Name of the module (user-defined from the configuration file)
Definition: Configuration.h:44
const ParameterSet & getGlobalParameters() const
std::shared_ptr< ParameterSet > parameters
Module&#39;s parameters, as parsed from the configuration file.
Definition: Configuration.h:47
std::enable_if< std::is_same< T, bool >::value||std::is_same< T, InputTag >::value >::type set(const std::string &name, const T &value)
Change the value of a given parameter. If the parameter does not exist, it&#39;s first created...
Definition: ParameterSet.h:160
std::vector< std::shared_ptr< ExecutionPath > > getPaths() const
const ParameterSet & getCubaConfiguration() const
std::vector< InputTag > getIntegrands() const
std::vector< std::string > getInputs() const
A class encapsulating a lua table.
Definition: ParameterSet.h:82
A frozen snapshot of the configuration file.
Definition: Configuration.h:36
A module declaration, defined from the configuration file.
Definition: Configuration.h:43
const std::vector< ModuleDecl > & getModules() const