geopm  3.1.1.dev214+gba4f9f6d
GEOPM - Global Extensible Open Power Manager
DerivativeSignal.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef DERIVATIVESIGNAL_HPP_INCLUDE
7 #define DERIVATIVESIGNAL_HPP_INCLUDE
8 
9 #include <memory>
10 
11 #include "Signal.hpp"
12 #include "geopm/CircularBuffer.hpp"
13 
14 namespace geopm
15 {
16  class DerivativeSignal : public Signal
17  {
18  public:
19  DerivativeSignal(std::shared_ptr<Signal> time_sig,
20  std::shared_ptr<Signal> y_sig,
21  int read_loops, double sleep_time);
22  DerivativeSignal(std::shared_ptr<Signal> time_sig,
23  std::shared_ptr<Signal> y_sig,
24  int read_loops, double sleep_time,
25  double nan_replace);
26  DerivativeSignal(const DerivativeSignal &other) = delete;
27  DerivativeSignal &operator=(const DerivativeSignal &other) = delete;
28  virtual ~DerivativeSignal() = default;
29  void setup_batch(void) override;
30  double sample(void) override;
31  double read(void) const override;
32  private:
33  struct m_sample_s {
34  double time;
35  double sample;
36  };
37 
40  static double compute_next(CircularBuffer<m_sample_s> &history,
41  int &num_fit,
42  double time, double signal,
43  double nan_replace);
44 
45  std::shared_ptr<Signal> m_time_sig;
46  std::shared_ptr<Signal> m_y_sig;
47 
48  const int M_NUM_SAMPLE_HISTORY;
50  int m_derivative_num_fit;
51  bool m_is_batch_ready;
52  double m_sleep_time;
53  double m_last_result;
54  double m_nan_replace;
55  };
56 }
57 
58 #endif
Definition: DerivativeSignal.hpp:17
double sample(void) override
Apply any conversions necessary to interpret the latest stored value as a double.
Definition: DerivativeSignal.cpp:97
double read(void) const override
Read directly the value of the signal without affecting any pushed batch signals.
Definition: DerivativeSignal.cpp:115
DerivativeSignal & operator=(const DerivativeSignal &other)=delete
virtual ~DerivativeSignal()=default
DerivativeSignal(const DerivativeSignal &other)=delete
DerivativeSignal(std::shared_ptr< Signal > time_sig, std::shared_ptr< Signal > y_sig, int read_loops, double sleep_time)
Definition: DerivativeSignal.cpp:17
void setup_batch(void) override
Prepare the signal for being updated through side effects by the owner's read_batch step....
Definition: DerivativeSignal.cpp:45
Definition: Signal.hpp:16
Definition: Agg.cpp:20