DynExp
Highly flexible laboratory automation for dynamically changing experiments.
ArbitraryFunctionFromCSV.h
Go to the documentation of this file.
1 // This file is part of DynExp.
2 
9 #pragma once
10 
11 #include "stdafx.h"
12 #include "DynExpCore.h"
13 #include "../MetaInstruments/FunctionGenerator.h"
14 
15 namespace DynExpModule
16 {
17  class ArbitraryFunctionFromCSV;
18 
20  {
21  public:
23  virtual ~ArbitraryFunctionFromCSVData() = default;
24 
26 
27  private:
28  void ResetImpl(dispatch_tag<ModuleDataBase>) override final;
30 
31  void Init();
32  };
33 
35  {
36  public:
38  virtual ~ArbitraryFunctionFromCSVParams() = default;
39 
40  virtual const char* GetParamClassTag() const noexcept override { return "ArbitraryFunctionFromCSVParams"; }
41 
43  "FunctionGenerator", "Function generator", "Underlying data stream instrument to be used as a function generator", DynExpUI::Icons::Instrument };
44  Param<ParamsConfigDialog::TextType> CSVDataPath = { *this, "CSVDataPath", "CSV data path",
45  "Path to a CSV file containing the arbitrary function data as a single column (values) or as two columns (times;values)", true, "", DynExp::TextUsageType::Code };
46  Param<ParamsConfigDialog::NumberType> SkipLines = { *this, "SkipLines", "Skip lines",
47  "Number of (header) lines to skip at the beginning of the file", true,
48  0, 0, std::numeric_limits<ParamsConfigDialog::NumberType>::max(), 1, 0 };
49  Param<ParamsConfigDialog::NumberType> TimeStretch = { *this, "TimeStretch", "Time stretch",
50  "Factor to multiply all times with", true,
51  1, std::numeric_limits<ParamsConfigDialog::NumberType>::lowest(), std::numeric_limits<ParamsConfigDialog::NumberType>::max(), .1, 3 };
52  Param<ParamsConfigDialog::NumberType> TimeOffset = { *this, "TimeOffset", "Time offset",
53  "Offset to add to all times", true,
54  0, std::numeric_limits<ParamsConfigDialog::NumberType>::lowest(), std::numeric_limits<ParamsConfigDialog::NumberType>::max(), .1, 3 };
55  Param<ParamsConfigDialog::NumberType> ValueStretch = { *this, "ValueStretch", "Value stretch",
56  "Factor to multiply all values with", true,
57  1, std::numeric_limits<ParamsConfigDialog::NumberType>::lowest(), std::numeric_limits<ParamsConfigDialog::NumberType>::max(), .1, 3 };
58  Param<ParamsConfigDialog::NumberType> ValueOffset = { *this, "ValueOffset", "Value offset",
59  "Offset to add to all values", true,
60  0, std::numeric_limits<ParamsConfigDialog::NumberType>::lowest(), std::numeric_limits<ParamsConfigDialog::NumberType>::max(), .1, 3 };
61 
62  private:
64  };
65 
67  {
68  public:
71 
74 
75  private:
76  virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override final { return DynExp::MakeParams<ArbitraryFunctionFromCSVConfigurator>(ID, Core); }
77  };
78 
80  {
81  public:
85 
86  constexpr static auto Name() noexcept { return "Arbitrary Function from CSV"; }
87  constexpr static auto Category() noexcept { return "I/O"; }
88 
90  : ModuleBase(OwnerThreadID, std::move(Params)) {}
91  virtual ~ArbitraryFunctionFromCSV() = default;
92 
93  virtual std::string GetName() const override { return Name(); }
94  virtual std::string GetCategory() const override { return Category(); }
95 
96  bool TreatModuleExceptionsAsWarnings() const override { return false; }
97 
98  // Only run main loop in case of an event.
99  std::chrono::milliseconds GetMainLoopDelay() const override final { return decltype(ModuleBase::GetMainLoopDelay())::max(); }
100 
101  private:
103 
104  void ResetImpl(dispatch_tag<ModuleBase>) override final;
105 
106  // Events, run in module thread
107  void OnInit(DynExp::ModuleInstance* Instance) const override final;
108  void OnExit(DynExp::ModuleInstance* Instance) const override final;
109  };
110 }
Defines DynExp's core module as an interface between the UI and DynExp objects.
virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core) const override final
Override to make derived classes call DynExp::MakeParams with the correct configurator type derived f...
virtual void ResetImpl(dispatch_tag< ArbitraryFunctionFromCSVData >)
DynExp::LinkedObjectWrapperContainer< DynExpInstr::FunctionGenerator > FunctionGenerator
void ResetImpl(dispatch_tag< ModuleDataBase >) override final
ArbitraryFunctionFromCSVParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
void ConfigureParamsImpl(dispatch_tag< ModuleParamsBase >) override final
Param< ParamsConfigDialog::NumberType > ValueOffset
Param< ParamsConfigDialog::NumberType > ValueStretch
Param< ParamsConfigDialog::NumberType > SkipLines
Param< ParamsConfigDialog::NumberType > TimeOffset
virtual const char * GetParamClassTag() const noexcept override
This function is intended to be overridden once in each derived class returning the name of the respe...
Param< ParamsConfigDialog::TextType > CSVDataPath
Param< DynExp::ObjectLink< DynExpInstr::FunctionGenerator > > FunctionGenerator
Param< ParamsConfigDialog::NumberType > TimeStretch
ArbitraryFunctionFromCSV(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
bool TreatModuleExceptionsAsWarnings() const override
Determines whether this module should be terminated if an exception leaves the module's main loop or ...
void ResetImpl(dispatch_tag< ModuleBase >) override final
constexpr static auto Category() noexcept
void OnExit(DynExp::ModuleInstance *Instance) const override final
This event is triggered right before the module thread terminates (not due to an exception,...
void OnInit(DynExp::ModuleInstance *Instance) const override final
This event is triggered right before the module thread starts. Override it to lock instruments this m...
Util::DynExpErrorCodes::DynExpErrorCodes ModuleMainLoop(DynExp::ModuleInstance &Instance) override final
Module main loop. The function is executed periodically by the module thread. Also refer to GetMainLo...
std::chrono::milliseconds GetMainLoopDelay() const override final
Specifies in which time intervals the module's event queue runs to handle pending events.
virtual std::string GetCategory() const override
Returns the category of this Object type.
virtual std::string GetName() const override
Returns the name of this Object type.
constexpr static auto Name() noexcept
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition: DynExpCore.h:127
Base class for modules. Modules implement programs on their own (e.g. measurement protocols or server...
Definition: Module.h:392
ModuleBase(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Constructs a ModuleBase instance.
Definition: Module.cpp:189
Configurator class for ModuleBase.
Definition: Module.h:374
Data structure to contain data which is synchronized in between different threads....
Definition: Module.h:171
Refer to ParamsBase::dispatch_tag.
Definition: Module.h:189
Defines data for a thread belonging to a ModuleBase instance. Refer to RunnableInstance.
Definition: Module.h:793
Parameter class for ModuleBase.
Definition: Module.h:337
ModuleParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a ModuleBase instance.
Definition: Module.h:348
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
Definition: Object.h:2302
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Definition: Object.h:2303
const ItemIDType ID
ID of the Object this parameter class instance belongs to.
Definition: Object.h:1779
const auto & GetCore() const noexcept
Returns a reference to DynExp's core.
Definition: Object.h:1677
const DynExpCore & Core
Reference to DynExp's core.
Definition: Object.h:1780
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
Definition: Object.h:349
DynExp's module namespace contains the implementation of DynExp modules which extend DynExp's core fu...
constexpr auto Instrument
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
Definition: Object.h:1807
size_t ItemIDType
ID type of objects/items managed by DynExp.
DynExpErrorCodes
DynExp's error codes
Definition: Exception.h:22
Accumulates include statements to provide a precompiled header.