Constant.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/Module.h>
20 
21 #include <momemta/ParameterSet.h>
22 
28 template<typename T>
29 class Constant: public Module {
30  public:
31 
32  Constant(PoolPtr pool, const ParameterSet& parameters): Module(pool, parameters.getModuleName()) {
33  value = parameters.get<T>("value");
34  };
35 
36  virtual void beginIntegration() override {
37  *constant = value;
38  };
39 
40  private:
41  T value;
42 
43  // Outputs
44  std::shared_ptr<T> constant = produce<T>("value");
45 };
46 
47 REGISTER_MODULE_NAME("IntConstant", Constant<int64_t>)
48  .Output("value")
49  .Attr("value:int");
50 
51 REGISTER_MODULE_NAME("DoubleConstant", Constant<double>)
52  .Output("value")
53  .Attr("value:double");
virtual void beginIntegration() override
Called once at the beginning of the integration.
Definition: Constant.cc:36
Parent class for all the modules.
Definition: Module.h:37
A class encapsulating a lua table.
Definition: ParameterSet.h:82
Module(PoolPtr pool, const std::string &name)
Constructor.
Definition: Module.h:61
A module declaring a constant.
Definition: Constant.cc:29