ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
AverageCurrent.cc
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
4#include "AverageCurrent.h"
5
6/*
7 * This example is explained as part of the \ref conceptualOverview. Please refere there for step-by-step explanations.
8 * Reading the full example might not be a good starting point for learning ApplicationCore as it can be overwelming
9 * and lacks important background information.
10 *
11 * Please ignore all comments of the format "//! [some name]", those are used for Doxygen to include code snippets in
12 * the documentation pages.
13 */
14
15/**********************************************************************************************************************/
16
18void AverageCurrent::mainLoop() {
19 const float coeff = 0.1;
20 currentAveraged.setAndWrite(current); // initialise currentAveraged with initial value
21
22 while(true) {
23 current.read();
24
25 // Often, it can be considered a good practise to only write values if they have actually changed. This will
26 // prevent subsequent computations from running unneccessarily. On the other hand, it may prevent receivers from
27 // getting a consistent "snapshot" for each trigger. This has to be decided case by case.
28 currentAveraged.writeIfDifferent((1 - coeff) * currentAveraged + coeff * current);
29 }
30}
32
33/**********************************************************************************************************************/
void writeIfDifferent(UserType newValue, VersionNumber versionNumber, DataValidity validity)=delete
void setAndWrite(UserType newValue, VersionNumber versionNumber)=delete