DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
NetworkSpectrometer.h
Go to the documentation of this file.
1// This file is part of DynExp.
2
8#pragma once
9
10#include "stdafx.h"
11#include "DynExpCore.h"
14
15#include "NetworkSpectrometer.pb.h"
16#include "NetworkSpectrometer.grpc.pb.h"
17
18namespace DynExpInstr
19{
20 class NetworkSpectrometer;
21
22 constexpr DynExpProto::Common::FrequencyUnitType ToPrototUnitType(SpectrometerData::FrequencyUnitType Unit)
23 {
24 switch (Unit)
25 {
26 case SpectrometerData::FrequencyUnitType::Hz: return DynExpProto::Common::FrequencyUnitType::Hz;
27 case SpectrometerData::FrequencyUnitType::nm: return DynExpProto::Common::FrequencyUnitType::nm;
28 case SpectrometerData::FrequencyUnitType::Inv_cm: return DynExpProto::Common::FrequencyUnitType::Inv_cm;
29 default: throw Util::InvalidDataException("The given unit does not exist in the SpectrometerData::FrequencyUnitType enumeration. Did you forget to adjust the FrequencyUnitType enumeration in class \"SpectrometerData\"?");
30 }
31 }
32
33 constexpr SpectrometerData::FrequencyUnitType ToSpectrometerUnitType(DynExpProto::Common::FrequencyUnitType Unit)
34 {
35 switch (Unit)
36 {
37 case DynExpProto::Common::FrequencyUnitType::Hz: return SpectrometerData::FrequencyUnitType::Hz;
38 case DynExpProto::Common::FrequencyUnitType::nm: return SpectrometerData::FrequencyUnitType::nm;
39 case DynExpProto::Common::FrequencyUnitType::Inv_cm: return SpectrometerData::FrequencyUnitType::Inv_cm;
40 default: throw Util::InvalidDataException("The given unit does not exist in the DynExpProto::Common::FrequencyUnitType enumeration. Did you forget to adjust the FrequencyUnitType enumeration in file \"Common.proto\"?");
41 }
42 }
43
44 constexpr DynExpProto::Common::IntensityUnitType ToPrototUnitType(SpectrometerData::IntensityUnitType Unit)
45 {
46 switch (Unit)
47 {
48 case SpectrometerData::IntensityUnitType::Counts: return DynExpProto::Common::IntensityUnitType::IntensityCounts;
49 default: throw Util::InvalidDataException("The given unit does not exist in the SpectrometerData::IntensityUnitType enumeration. Did you forget to adjust the IntensityUnitType enumeration in class \"SpectrometerData\"?");
50 }
51 }
52
53 constexpr SpectrometerData::IntensityUnitType ToSpectrometerUnitType(DynExpProto::Common::IntensityUnitType Unit)
54 {
55 switch (Unit)
56 {
57 case DynExpProto::Common::IntensityUnitType::IntensityCounts: return SpectrometerData::IntensityUnitType::Counts;
58 default: throw Util::InvalidDataException("The given unit does not exist in the DynExpProto::Common::IntensityUnitType enumeration. Did you forget to adjust the IntensityUnitType enumeration in file \"Common.proto\"?");
59 }
60 }
61
62 constexpr SpectrometerData::CapturingStateType ToSpectrometerStateType(DynExpProto::NetworkSpectrometer::StateType State)
63 {
64 switch (State)
65 {
66 case DynExpProto::NetworkSpectrometer::StateType::Ready: return SpectrometerData::CapturingStateType::Ready;
67 case DynExpProto::NetworkSpectrometer::StateType::WarningState: return SpectrometerData::CapturingStateType::Warning;
68 case DynExpProto::NetworkSpectrometer::StateType::ErrorState: return SpectrometerData::CapturingStateType::Error;
69 case DynExpProto::NetworkSpectrometer::StateType::Recording: return SpectrometerData::CapturingStateType::Capturing;
70 default: throw Util::InvalidDataException("The given state does not exist in the DynExpProto::NetworkSpectrometer::StateType enumeration.");
71 }
72 }
73
74 namespace NetworkSpectrometerTasks
75 {
76 class InitTask : public gRPCInstrumentTasks::InitTask<Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer>
77 {
79
80 virtual void InitFuncImpl(dispatch_tag<InitTask>, DynExp::InstrumentInstance& Instance) {}
81 };
82
83 class ExitTask : public gRPCInstrumentTasks::ExitTask<Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer>
84 {
86
87 virtual void ExitFuncImpl(dispatch_tag<ExitTask>, DynExp::InstrumentInstance& Instance) {}
88 };
89
90 class UpdateTask : public gRPCInstrumentTasks::UpdateTask<Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer>
91 {
93
94 virtual void UpdateFuncImpl(dispatch_tag<UpdateTask>, DynExp::InstrumentInstance& Instance) {}
95 };
96
107
119
121 {
122 public:
124
125 private:
127
128 bool Enable;
129 };
130
131 class RecordTask final : public DynExp::TaskBase
132 {
133 public:
135
136 private:
138 };
139
140 class AbortTask final : public DynExp::TaskBase
141 {
142 public:
144
145 private:
147 };
148 }
149
150 class NetworkSpectrometerData : public gRPCInstrumentData<Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer>
151 {
154
155 public:
157 virtual ~NetworkSpectrometerData() = default;
158
159 auto GetFrequencyUnit() const noexcept { return FrequencyUnit; }
160 auto GetIntensityUnit() const noexcept { return IntensityUnit; }
161 auto GetMinFrequency() const noexcept { return MinFrequency; }
162 auto GetMaxFrequency() const noexcept { return MaxFrequency; }
163
164 private:
166 virtual void ResetImpl(dispatch_tag<NetworkSpectrometerData>) {};
167
168 virtual CapturingStateType GetCapturingStateChild() const noexcept override { return CapturingState; }
169 virtual double GetCapturingProgressChild() const noexcept override { return CapturingProgress; }
170
171 FrequencyUnitType FrequencyUnit = FrequencyUnitType::Hz;
172 IntensityUnitType IntensityUnit = IntensityUnitType::Counts;
173 double MinFrequency = 0.0;
174 double MaxFrequency = 0.0;
175
176 CapturingStateType CapturingState = CapturingStateType::Ready;
177 double CapturingProgress = 0.0;
178 };
179
180 class NetworkSpectrometerParams : public gRPCInstrumentParams<Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer>
181 {
182 public:
184 virtual ~NetworkSpectrometerParams() = default;
185
186 virtual const char* GetParamClassTag() const noexcept override { return "NetworkSpectrometerParams"; }
187
188 private:
190 virtual void ConfigureParamsImpl(dispatch_tag<NetworkSpectrometerParams>) {}
191
192 DummyParam Dummy = { *this };
193 };
194
195 class NetworkSpectrometerConfigurator : public gRPCInstrumentConfigurator<Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer>
196 {
197 public:
200
203
204 private:
205 virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override { return DynExp::MakeParams<NetworkSpectrometerConfigurator>(ID, Core); }
206 };
207
208 class NetworkSpectrometer : public gRPCInstrument<Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer>
209 {
210 public:
214
215 constexpr static auto Name() noexcept { return "Network Spectrometer"; }
216
219
220 virtual std::string GetName() const override { return Name(); }
221
224 virtual double GetMinFrequency() const;
225 virtual double GetMaxFrequency() const;
226
227 // Logical const-ness: const member functions to allow inserting tasks into task queue.
228 virtual void SetExposureTime(SpectrometerData::TimeType ExposureTime, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkSpectrometerTasks::SetExposureTimeTask>(ExposureTime, CallbackFunc); }
229 virtual void SetFrequencyRange(double LowerFrequency, double UpperFrequency, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkSpectrometerTasks::SetFrequencyRangeTask>(LowerFrequency, UpperFrequency, CallbackFunc); }
230 virtual void SetSilentMode(bool Enable, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkSpectrometerTasks::SetSetSilentModeTask>(Enable, CallbackFunc); }
231
232 virtual void Record(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkSpectrometerTasks::RecordTask>(CallbackFunc); }
233 virtual void Abort(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<NetworkSpectrometerTasks::AbortTask>(CallbackFunc); }
234
235 private:
238
239 virtual std::unique_ptr<DynExp::InitTaskBase> MakeInitTask() const override { return DynExp::MakeTask<NetworkSpectrometerTasks::InitTask>(); }
240 virtual std::unique_ptr<DynExp::ExitTaskBase> MakeExitTask() const override { return DynExp::MakeTask<NetworkSpectrometerTasks::ExitTask>(); }
241 virtual std::unique_ptr<DynExp::UpdateTaskBase> MakeUpdateTask() const override { return DynExp::MakeTask<NetworkSpectrometerTasks::UpdateTask>(); }
242 };
243}
Defines DynExp's core module as an interface between the UI and DynExp objects.
Defines a meta instrument for a spectrometer.
virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core) const override
Override to make derived classes call DynExp::MakeParams with the correct configurator type derived f...
void ResetImpl(dispatch_tag< gRPCInstrumentData< Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer > >) override final
virtual double GetCapturingProgressChild() const noexcept override
virtual CapturingStateType GetCapturingStateChild() const noexcept override
virtual ~NetworkSpectrometerData()=default
virtual ~NetworkSpectrometerParams()=default
virtual void ConfigureParamsImpl(dispatch_tag< NetworkSpectrometerParams >)
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...
void ConfigureParamsImpl(dispatch_tag< gRPCInstrumentParams< Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer > >) override final
NetworkSpectrometerParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
AbortTask(CallbackType CallbackFunc) noexcept
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
void ExitFuncImpl(dispatch_tag< gRPCInstrumentTasks::ExitTask< Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer > >, DynExp::InstrumentInstance &Instance) override final
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
virtual void InitFuncImpl(dispatch_tag< InitTask >, DynExp::InstrumentInstance &Instance)
void InitFuncImpl(dispatch_tag< gRPCInstrumentTasks::InitTask< Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer > >, DynExp::InstrumentInstance &Instance) override final
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
SetExposureTimeTask(SpectrometerData::TimeType ExposureTime, CallbackType CallbackFunc) noexcept
SetFrequencyRangeTask(double LowerFrequency, double UpperFrequency, CallbackType CallbackFunc) noexcept
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
SetSetSilentModeTask(bool Enable, CallbackType CallbackFunc) noexcept
virtual void UpdateFuncImpl(dispatch_tag< UpdateTask >, DynExp::InstrumentInstance &Instance)
void UpdateFuncImpl(dispatch_tag< gRPCInstrumentTasks::UpdateTask< Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer > >, DynExp::InstrumentInstance &Instance) override final
virtual void Abort(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Aborts a currently running spectrum acquisition.
virtual SpectrometerData::IntensityUnitType GetIntensityUnit() const
Determines the intensity (y-axis) unit of the spectra acquired by the derived instrument.
virtual void SetFrequencyRange(double LowerFrequency, double UpperFrequency, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Sets the spectrometer's frequency range where the spectrum acquisition begins and ends.
virtual SpectrometerData::FrequencyUnitType GetFrequencyUnit() const
Determines the frequency (x-axis) unit of the spectra acquired by the derived instrument.
virtual double GetMinFrequency() const
Determines the minimal lower frequency limit where the spectrum acquisition can begin.
virtual void Record(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Starts the acquisition of a single spectrum.
virtual std::unique_ptr< DynExp::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
virtual std::unique_ptr< DynExp::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
virtual void SetSilentMode(bool Enable, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Enables or disables the spectrometer's silent mode, i.e. disables or enables e.g. the spectrometer's ...
virtual void SetExposureTime(SpectrometerData::TimeType ExposureTime, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Sets the spectrometer's exposure time.
virtual std::string GetName() const override
Returns the name of this Object type.
static constexpr auto Name() noexcept
virtual double GetMaxFrequency() const
Determines the maximal upper frequency limit where the spectrum acquisition can end.
void ResetImpl(dispatch_tag< gRPCInstrument< Spectrometer, 0, DynExpProto::NetworkSpectrometer::NetworkSpectrometer > >) override final
virtual std::unique_ptr< DynExp::UpdateTaskBase > MakeUpdateTask() const override
Factory function for an update task (UpdateTaskBase). Override to define the desired update task in d...
CapturingStateType
Possible spectrometer states.
@ Warning
The spectrometer is in a warning state, but still ready to acquire a spectrum.
@ Capturing
The spectrometer is currently acquiring a spectrum.
@ Error
The spectrometer is in an error state.
@ Ready
The spectrometer is ready to acquire a spectrum.
std::chrono::milliseconds TimeType
Time type describing the spectrometer's times like its exposure time.
FrequencyUnitType
Supported spectrometer frequency units.
IntensityUnitType
Supported spectrometer intensity units.
@ Counts
Number of counts (arbitrary unit)
Meta instrument for a spectrometer.
Configurator class for gRPCInstrument.
Data class for gRPCInstrument.
Parameter class for gRPCInstrument.
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
DynExp::ExitTaskBase::dispatch_tag< Type > dispatch_tag
Refer to DynExp::ParamsBase::dispatch_tag.
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
DynExp::InitTaskBase::dispatch_tag< Type > dispatch_tag
Refer to DynExp::ParamsBase::dispatch_tag.
Defines a task for updating an instrument within an instrument inheritance hierarchy....
DynExp::UpdateTaskBase::dispatch_tag< Type > dispatch_tag
Refer to DynExp::ParamsBase::dispatch_tag.
Meta instrument template for transforming meta instruments into network instruments,...
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition DynExpCore.h:127
Defines data for a thread belonging to a InstrumentBase instance. Refer to RunnableInstance.
Definition Instrument.h:772
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
Refer to ParamsBase::dispatch_tag.
Definition Object.h:2018
Base class for all tasks being processed by instruments. The class must not contain public virtual fu...
Definition Instrument.h:892
std::function< void(const TaskBase &, ExceptionContainer &)> CallbackType
Type of a callback function which is invoked when a task has finished, failed or has been aborted....
Definition Instrument.h:939
TaskBase(CallbackType CallbackFunc=nullptr) noexcept
Constructs an instrument task.
Definition Instrument.h:979
const CallbackType CallbackFunc
This callback function is called after the task has finished (either successfully or not) with a refe...
Defines the return type of task functions.
Definition Instrument.h:824
Data to operate on is invalid for a specific purpose. This indicates a corrupted data structure or fu...
Definition Exception.h:163
Defines a meta instrument template for transforming meta instruments into network instruments,...
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
constexpr DynExpProto::Common::UnitType ToPrototUnitType(DataStreamInstrumentData::UnitType Unit)
constexpr SpectrometerData::FrequencyUnitType ToSpectrometerUnitType(DynExpProto::Common::FrequencyUnitType Unit)
constexpr SpectrometerData::CapturingStateType ToSpectrometerStateType(DynExpProto::NetworkSpectrometer::StateType State)
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.
Accumulates include statements to provide a precompiled header.