ValueProxy.h
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 #pragma once
20 
21 #include <momemta/impl/ValueProxy_fwd.h>
22 
23 #include <momemta/InputTag.h>
24 #include <momemta/Pool.h>
25 
26 template <typename T> template <typename U> std::shared_ptr<const U> ValueProxy<T>::get_from_pool(const Pool* pool, const InputTag& tag) {
27  return pool->raw_get<U>(tag);
28 }
29 
30 template <typename T>
32  raw_value = this->template get_from_pool<container_t>(pool, tag);
33 }
34 
35 template <typename T>
37  return *raw_value;
38 }
39 
40 template <typename T>
42  return get();
43 }
44 
45 template <typename T>
47  return raw_value.get();
48 }
49 
50 template <typename T>
51 IndexedValueProxy<T>::IndexedValueProxy(const Pool* pool, const InputTag& tag) {
52  raw_value = this->template get_from_pool<container_t>(pool, tag);
53  index = tag.index;
54 }
55 
56 template <typename T>
58  return raw_value->operator[](index);
59 }
60 
61 template <typename T>
63  return get();
64 }
65 
66 template <typename T>
68  return &raw_value->operator[](index);
69 }
70 
71 template <typename T>
72 std::shared_ptr<ValueProxy<T>> ValueProxy<T>::create(const Pool* pool, const InputTag& tag) {
73  if (tag.isIndexed()) {
74  return std::make_shared<IndexedValueProxy<T>>(pool, tag);
75  } else
76  return std::make_shared<NonIndexedValueProxy<T>>(pool, tag);
77 }
bool isIndexed() const
Definition: InputTag.cc:93
An identifier of a module&#39;s output.
Definition: InputTag_fwd.h:37
size_t index
The index. Only meaningful if isIndexed() returns true.
Definition: InputTag_fwd.h:109
Definition: Pool.h:40