ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
SplitArray.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include "ApplicationModule.h"
6#include "ArrayAccessor.h"
7
8namespace ChimeraTK {
9
25 template<typename TYPE>
27 WriteSplitArrayModule(EntityOwner* owner, const std::string& name, const std::string& description, size_t nGroups,
28 size_t nElemsPerGroup = 1);
29
31
38 std::vector<ArrayPushInput<TYPE>> input;
39
43
44 void mainLoop();
45
46 private:
47 size_t _nGroups;
48 size_t _nElemsPerGroup;
49 };
50
51 /********************************************************************************************************************/
52
68 template<typename TYPE>
70 ReadSplitArrayModule(EntityOwner* owner, const std::string& name, const std::string& description, size_t nGroups,
71 size_t nElemsPerGroup = 1);
72
74
81 std::vector<ArrayOutput<TYPE>> output;
82
86
87 void mainLoop();
88
89 private:
90 size_t _nGroups;
91 size_t _nElemsPerGroup;
92 };
93
94 /********************************************************************************************************************/
95 /********************************************************************************************************************/
96
97 template<typename TYPE>
99 const std::string& description, size_t nGroups, size_t nElemsPerGroup)
100 : ApplicationModule(owner, name, description), output(this, "output", "", nGroups * nElemsPerGroup, "Output array"),
101 _nGroups(nGroups), _nElemsPerGroup(nElemsPerGroup) {
102 for(size_t i = 0; i < _nGroups; ++i) {
103 std::string comment;
104 if(_nElemsPerGroup == 1) {
105 comment = "The element " + std::to_string(i) + " of the output array";
106 }
107 else {
108 comment = "The elements " + std::to_string(i * _nElemsPerGroup) + " to " +
109 std::to_string((i + 1) * _nElemsPerGroup - 1) + " of the output array";
110 }
111 input.push_back(ArrayPushInput<TYPE>(this, "input" + std::to_string(i), "", _nElemsPerGroup, comment));
112 }
113 }
114
115 /********************************************************************************************************************/
116
117 template<typename TYPE>
119 auto readGroup = readAnyGroup();
120 while(true) {
121 // write the array from the individual elements
122 for(size_t i = 0; i < _nGroups; ++i) {
123 for(size_t k = 0; k < _nElemsPerGroup; ++k) {
124 output[i * _nElemsPerGroup + k] = input[i][k];
125 }
126 }
127 output.write();
128
129 // wait for new input values (at the end, since we want to process the
130 // initial values first)
131 readGroup.readAny();
132 }
133 }
134
135 /********************************************************************************************************************/
136
137 template<typename TYPE>
139 const std::string& description, size_t nGroups, size_t nElemsPerGroup)
140 : ApplicationModule(owner, name, description), input(this, "input", "", nGroups * nElemsPerGroup, "Input array"),
141 _nGroups(nGroups), _nElemsPerGroup(nElemsPerGroup) {
142 for(size_t i = 0; i < _nGroups; ++i) {
143 std::string comment;
144 if(_nElemsPerGroup == 1) {
145 comment = "The element " + std::to_string(i) + " of the input array";
146 }
147 else {
148 comment = "The elements " + std::to_string(i * _nElemsPerGroup) + " to " +
149 std::to_string((i + 1) * _nElemsPerGroup - 1) + " of the input array";
150 }
151 output.push_back(ArrayOutput<TYPE>(this, "output" + std::to_string(i), "", _nElemsPerGroup, comment));
152 }
153 }
154
155 /********************************************************************************************************************/
156
157 template<typename TYPE>
159 while(true) {
160 // write the array from the individual elements
161 for(size_t i = 0; i < _nGroups; ++i) {
162 for(size_t k = 0; k < _nElemsPerGroup; ++k) {
163 input[i][k] = output[i * _nElemsPerGroup + k];
164 }
165 }
166 writeAll();
167
168 // wait for new input values (at the end, since we want to process the
169 // initial values first)
170 input.read();
171 }
172 }
173
174} // namespace ChimeraTK
Convenience class for input array accessors with UpdateMode::push.
Base class for owners of other EntityOwners (e.g.
Definition EntityOwner.h:38
InvalidityTracer application module.
Convenience class for output array accessors (always UpdateMode::push)
Split an array of the data type TYPE into nGroups with each nElemsPerGroup elements.
Definition SplitArray.h:69
void mainLoop()
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
Definition SplitArray.h:158
std::vector< ArrayOutput< TYPE > > output
Vector of output arrays, each with a length of nElemsPerGroup.
Definition SplitArray.h:81
ArrayPushInput< TYPE > input
Input array.
Definition SplitArray.h:85
Split an array of the data type TYPE into nGroups with each nElemsPerGroup elements.
Definition SplitArray.h:26
void mainLoop()
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
Definition SplitArray.h:118
std::vector< ArrayPushInput< TYPE > > input
Vector of input arrays, each with a length of nElemsPerGroup.
Definition SplitArray.h:38
ArrayOutput< TYPE > output
Output array.
Definition SplitArray.h:42