ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
Pipe.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#include "ScalarAccessor.h"
8
9namespace ChimeraTK {
10
16 template<typename Type>
17 struct ScalarPipe : public ApplicationModule {
18 ScalarPipe(ModuleGroup* owner, const std::string& name, const std::string& unit, const std::string& description,
19 const std::unordered_set<std::string>& tagsInput = {}, const std::unordered_set<std::string>& tagsOutput = {})
20 : ApplicationModule(owner, ".", "") {
21 input.replace(ScalarPushInput<Type>(this, name, unit, description, tagsInput));
22 output.replace(ScalarOutput<Type>(this, name, unit, description, tagsOutput));
23 }
24
25 ScalarPipe(ModuleGroup* owner, const std::string& inputName, const std::string& outputName, const std::string& unit,
26 const std::string& description, const std::unordered_set<std::string>& tagsInput = {},
27 const std::unordered_set<std::string>& tagsOutput = {})
28 : ApplicationModule(owner, ".", "") {
29 input.replace(ScalarPushInput<Type>(this, inputName, unit, description, tagsInput));
30 output.replace(ScalarOutput<Type>(this, outputName, unit, description, tagsOutput));
31 }
32
33 ScalarPipe() = default;
34
37
38 void mainLoop() override {
39 while(true) {
40 output = static_cast<Type>(input);
41 output.write();
42 input.read();
43 }
44 }
45 };
46
52 template<typename Type>
53 struct ArrayPipe : public ApplicationModule {
54 ArrayPipe(ModuleGroup* owner, const std::string& name, const std::string& unit, size_t nElements,
55 const std::string& description, const std::unordered_set<std::string>& tagsInput = {},
56 const std::unordered_set<std::string>& tagsOutput = {})
57 : ApplicationModule(owner, ".", description) {
58 input.replace(ArrayPushInput<Type>(this, name, unit, nElements, description, tagsInput));
59 output.replace(ArrayOutput<Type>(this, name, unit, nElements, description, tagsOutput));
60 }
61
62 ArrayPipe(ModuleGroup* owner, const std::string& inputName, const std::string& outputName, const std::string& unit,
63 size_t nElements, const std::string& description, const std::unordered_set<std::string>& tagsInput = {},
64 const std::unordered_set<std::string>& tagsOutput = {})
65 : ApplicationModule(owner, ".", description) {
66 input.replace(ArrayPushInput<Type>(this, inputName, unit, nElements, description, tagsInput));
67 output.replace(ArrayOutput<Type>(this, outputName, unit, nElements, description, tagsOutput));
68 }
69
70 ArrayPipe() = default;
71
74
75 void mainLoop() override {
76 std::vector<Type> temp(input.getNElements());
77 while(true) {
78 input.swap(temp);
79 output.swap(temp);
80 input.swap(temp);
81 output.write();
82 input.read();
83 }
84 }
85 };
86
87} // namespace ChimeraTK
ApplicationModule()=default
Default constructor: Allows late initialisation of modules (e.g.
void replace(const ChimeraTK::NDRegisterAccessorAbstractor< UserType > &newAccessor)=delete
bool write(ChimeraTK::VersionNumber versionNumber)=delete
Convenience class for input array accessors with UpdateMode::push.
bool write(ChimeraTK::VersionNumber versionNumber)=delete
void replace(const ChimeraTK::NDRegisterAccessorAbstractor< UserType > &newAccessor)=delete
Convenience class for input scalar accessors with UpdateMode::push.
InvalidityTracer application module.
Convenience class for output array accessors (always UpdateMode::push)
Generic module to pipe through a scalar value without altering it.
Definition Pipe.h:53
ArrayPipe(ModuleGroup *owner, const std::string &name, const std::string &unit, size_t nElements, const std::string &description, const std::unordered_set< std::string > &tagsInput={}, const std::unordered_set< std::string > &tagsOutput={})
Definition Pipe.h:54
ArrayPipe(ModuleGroup *owner, const std::string &inputName, const std::string &outputName, const std::string &unit, size_t nElements, const std::string &description, const std::unordered_set< std::string > &tagsInput={}, const std::unordered_set< std::string > &tagsOutput={})
Definition Pipe.h:62
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
Definition Pipe.h:75
ArrayOutput< Type > output
Definition Pipe.h:73
ArrayPushInput< Type > input
Definition Pipe.h:72
Convenience class for output scalar accessors (always UpdateMode::push)
Generic module to pipe through a scalar value without altering it.
Definition Pipe.h:17
ScalarPipe(ModuleGroup *owner, const std::string &name, const std::string &unit, const std::string &description, const std::unordered_set< std::string > &tagsInput={}, const std::unordered_set< std::string > &tagsOutput={})
Definition Pipe.h:18
ScalarPipe(ModuleGroup *owner, const std::string &inputName, const std::string &outputName, const std::string &unit, const std::string &description, const std::unordered_set< std::string > &tagsInput={}, const std::unordered_set< std::string > &tagsOutput={})
Definition Pipe.h:25
ScalarPushInput< Type > input
Definition Pipe.h:35
ScalarOutput< Type > output
Definition Pipe.h:36
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
Definition Pipe.h:38