LooperSummer.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 #include <momemta/Types.h>
23 
29 template<typename T>
30 class LooperSummer: public Module {
31  public:
32 
33  LooperSummer(PoolPtr pool, const ParameterSet& parameters): Module(pool, parameters.getModuleName()) {
34  input = pool->get<T>(parameters.get<InputTag>("input"));
35  };
36 
37  virtual void beginPoint() override {
38  *result = 0;
39  }
40 
41  virtual Status work() override {
42  *result += *input;
43 
44  return Status::OK;
45  }
46 
47  private:
48 
49  // Inputs
50  Value<T> input;
51 
52  // Outputs
53  std::shared_ptr<T> result = produce<T>("sum");
54 
55 };
56 
60 template<>
62  result->SetXYZT(0, 0, 0, 0);
63 }
64 
65 REGISTER_MODULE_NAME("IntLooperSummer", LooperSummer<int64_t>)
66  .Input("input")
67  .Output("sum");
68 
69 REGISTER_MODULE_NAME("DoubleLooperSummer", LooperSummer<double>)
70  .Input("input")
71  .Output("sum");
72 
73 REGISTER_MODULE_NAME("P4LooperSummer", LooperSummer<LorentzVector>)
74  .Input("input")
75  .Output("sum");
virtual void beginPoint() override
Called once when a new PS point is started.
Definition: LooperSummer.cc:37
An identifier of a module&#39;s output.
Definition: InputTag_fwd.h:37
Parent class for all the modules.
Definition: Module.h:37
A class encapsulating a lua table.
Definition: ParameterSet.h:82
A class representing a value produced by a module.
Definition: Value.h:30
Module(PoolPtr pool, const std::string &name)
Constructor.
Definition: Module.h:61
virtual Status work() override
Main function.
Definition: LooperSummer.cc:41
A module performing a sum over a set of values.
Definition: LooperSummer.cc:30