DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
Spectrometer.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 "Instrument.h"
12
13namespace DynExpInstr
14{
15 class Spectrometer;
16
61
66 {
67 public:
71 using TimeType = std::chrono::milliseconds;
72
76 enum class CapturingStateType {
77 Ready,
78 Warning,
79 Error,
81 };
82
87 {
88 public:
93 SpectrumType() : FrequencyUnit(DynExp::Units::UnitType::Freq_Hz), IntensityUnit(DynExp::Units::UnitType::Counts) {}
94
101
107
112 SpectrumType(SpectrumType&& Other);
113
119 SpectrumType& operator=(const SpectrumType& Other);
120
127
128 void Reset();
129
130 auto GetFrequencyUnit() const noexcept { return FrequencyUnit; }
131 auto GetIntensityUnit() const noexcept { return IntensityUnit; }
132 auto& GetSpectrum() const noexcept { return Samples; }
133 auto& GetSpectrum() noexcept { return Samples; }
134
139 bool HasSpectrum() const noexcept { return !Samples.empty(); }
140
141 private:
144
145 std::map<double, double> Samples;
146 };
147
148 SpectrometerData() = default;
149 virtual ~SpectrometerData() = default;
150
151 auto GetMinExposureTime() const noexcept { return MinExposureTime; }
152 void SetMinExposureTime(double MinExposureTime) noexcept { this->MinExposureTime = TimeType(Util::NumToT<int>(MinExposureTime)); }
154 auto GetMaxExposureTime() const noexcept { return MaxExposureTime; }
155 void SetMaxExposureTime(double MaxExposureTime) noexcept { this->MaxExposureTime = TimeType(Util::NumToT<int>(MaxExposureTime)); }
157 auto GetCurrentExposureTime() const noexcept { return CurrentExposureTime; }
158 void SetCurrentExposureTime(double CurrentExposureTime) noexcept { this->CurrentExposureTime = TimeType(Util::NumToT<int>(CurrentExposureTime)); }
160 auto GetCurrentLowerFrequency() const noexcept { return CurrentLowerFrequency; }
162 auto GetCurrentUpperFrequency() const noexcept { return CurrentUpperFrequency; }
164 auto GetSilentModeEnabled() const noexcept { return SilentModeEnabled; }
165 void SetSilentModeEnabled(bool Enable) noexcept { SilentModeEnabled = Enable; }
166
171 auto GetCapturingState() const noexcept { return GetCapturingStateChild(); }
172
179
185 auto GetCapturingProgress() const noexcept { return GetCapturingProgressChild(); }
186
190 bool HasSpectrum() const noexcept { return CurrentSpectrum.HasSpectrum(); }
191
197 SpectrumType GetSpectrum() const;
198
204 SpectrumType GetSpectrumCopy() const;
205
210 void SetSpectrum(SpectrumType&& Other);
211
215 void ClearSpectrum() const;
216
217 private:
218 void ResetImpl(dispatch_tag<InstrumentDataBase>) override final;
220
225 virtual CapturingStateType GetCapturingStateChild() const noexcept = 0;
226 virtual double GetCapturingProgressChild() const noexcept { return 0; }
228
234 bool SilentModeEnabled = false;
235
242 };
243
248 {
249 public:
255
256 virtual ~SpectrometerParams() = 0;
257
258 virtual const char* GetParamClassTag() const noexcept override { return "SpectrometerParams"; }
259
260 private:
263
264 DummyParam Dummy = { *this };
265 };
266
279
284 {
285 public:
289
298
299 constexpr static auto Name() noexcept { return "Spectrometer"; }
300 constexpr static auto Category() noexcept { return "Image Capturing"; }
301
307
308 virtual ~Spectrometer() = 0;
309
310 virtual std::string GetName() const override { return Name(); }
311 virtual std::string GetCategory() const override { return Category(); }
312
313 virtual std::chrono::milliseconds GetTaskQueueDelay() const override { return std::chrono::milliseconds(50); }
314
319
324
330
335 virtual double GetMinFrequency() const = 0;
336
341 virtual double GetMaxFrequency() const = 0;
343
350
355 virtual void SetExposureTime(SpectrometerData::TimeType ExposureTime, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
356
364 virtual void SetFrequencyRange(double LowerFrequency, double UpperFrequency, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
365
373 virtual void SetSilentMode(bool Enable, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
374
379 virtual void Record(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
380
387 virtual void Abort(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
389
390 private:
391 void ResetImpl(dispatch_tag<InstrumentBase>) override final;
393 };
394}
Implementation of DynExp instrument objects.
Configurator class for Spectrometer.
Type describing a spectrum as acquired by the Spectrometer instrument.
auto GetFrequencyUnit() const noexcept
Getter for FrequencyUnit.
SpectrumType & operator=(const SpectrumType &Other)
Copies a SpectrumType instance's content to this instance.
auto GetIntensityUnit() const noexcept
Getter for IntensityUnit.
bool HasSpectrum() const noexcept
Indicates whether the spectrum is empty.
std::map< double, double > Samples
Samples of the spectrum as tuples in units (FrequencyUnit, IntensityUnit)
SpectrumType(DynExp::Units::UnitType FrequencyUnit, DynExp::Units::UnitType IntensityUnit)
Constructs a SpectrumType instance with the specified units.
SpectrumType(const SpectrumType &Other)
Copy-constructs a SpectrumType instance.
SpectrumType()
Constructs a SpectrumType instance with FrequencyUnit set to DynExp::Units::UnitType::Freq_Hz and Int...
DynExp::Units::UnitType FrequencyUnit
The spectrum's frequency (x-axis) unit.
DynExp::Units::UnitType IntensityUnit
The spectrum's intensity (y-axis) unit.
auto & GetSpectrum() const noexcept
Getter for Samples.
auto & GetSpectrum() noexcept
Getter for Samples.
void Reset()
Removes all samples from the spectrum (clears Samples).
Data class for Spectrometer.
virtual void ResetImpl(dispatch_tag< SpectrometerData >)
void SetMinExposureTime(double MinExposureTime) noexcept
Setter for MinExposureTime.
auto GetCapturingState() const noexcept
Returns the spectrometer's current capturing state.
SpectrumType GetSpectrumCopy() const
Copying getter for CurrentSpectrum. This function is more expensive than GetSpectrum().
auto GetMaxExposureTime() const noexcept
Getter for MaxExposureTime.
auto GetSilentModeEnabled() const noexcept
Getter for SilentModeEnabled.
void SetCurrentExposureTime(TimeType CurrentExposureTime) noexcept
Setter for CurrentExposureTime.
virtual double GetCapturingProgressChild() const noexcept
Determines the progress of a spectrum acquisition.
void SetCurrentLowerFrequency(double CurrentLowerFrequency) noexcept
Setter for CurrentLowerFrequency.
double CurrentUpperFrequency
Current upper frequency limit where the spectrum acquisition ends.
TimeType MaxExposureTime
Maximal exposure time the spectrometer supports.
SpectrumType CurrentSpectrum
Current spectrum acquired by the spectrometer. Logical const-ness: allow const member function GetSpe...
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.
void SetSpectrum(SpectrumType &&Other)
Setter for CurrentSpectrum.
void ClearSpectrum() const
Resets CurrentSpectrum by calling SpectrumType::Reset().
void ResetImpl(dispatch_tag< InstrumentDataBase >) override final
SpectrumType GetSpectrum() const
Moving getter for CurrentSpectrum.
void SetMinExposureTime(TimeType MinExposureTime) noexcept
Setter for MinExposureTime.
void SetCurrentExposureTime(double CurrentExposureTime) noexcept
Setter for CurrentExposureTime.
virtual ~SpectrometerData()=default
auto GetCurrentExposureTime() const noexcept
Getter for CurrentExposureTime.
auto GetCurrentLowerFrequency() const noexcept
Getter for CurrentLowerFrequency.
TimeType MinExposureTime
Minimal exposure time the spectrometer supports.
auto GetCapturingProgress() const noexcept
Determines the progress of a spectrum acquisition.
std::chrono::milliseconds TimeType
Time type describing the spectrometer's times like its exposure time.
void SetCurrentUpperFrequency(double CurrentUpperFrequency) noexcept
Setter for CurrentUpperFrequency.
void SetMaxExposureTime(TimeType MaxExposureTime) noexcept
Setter for MaxExposureTime.
bool HasSpectrum() const noexcept
Indicates whether the spectrum is empty.
void SetMaxExposureTime(double MaxExposureTime) noexcept
Setter for MaxExposureTime.
double CurrentLowerFrequency
Current lower frequency limit where the spectrum acquisition begins.
auto GetCurrentUpperFrequency() const noexcept
Getter for CurrentUpperFrequency.
bool IsCapturing() const noexcept
Determines whether the spectrometer is currently acquiring a spectrum.
virtual CapturingStateType GetCapturingStateChild() const noexcept=0
Returns the spectrometer's current capturing state.
auto GetMinExposureTime() const noexcept
Getter for MinExposureTime.
TimeType CurrentExposureTime
Current exposure time of the spectrometer.
bool SilentModeEnabled
Indicates whether the spectrometer's silent mode is turned on, i.e. the spectrometer's fans are turne...
void SetSilentModeEnabled(bool Enable) noexcept
Setter for SilentModeEnabled.
Parameter class for Spectrometer.
virtual void ConfigureParamsImpl(dispatch_tag< SpectrometerParams >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
SpectrometerParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Constructs the parameters for a Spectrometer instance.
DummyParam Dummy
Dummy parameter which is to be owned once by parameter classes that do not contain any other paramete...
void ConfigureParamsImpl(dispatch_tag< InstrumentParamsBase >) override final
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...
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
void ExitFuncImpl(dispatch_tag< ExitTaskBase >, DynExp::InstrumentInstance &Instance) override final
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
virtual void InitFuncImpl(dispatch_tag< InitTask >, DynExp::InstrumentInstance &Instance)
Initializes the respective instrument within the instrument inheritance hierarchy....
void InitFuncImpl(dispatch_tag< InitTaskBase >, DynExp::InstrumentInstance &Instance) override final
Defines a task for updating an instrument within an instrument inheritance hierarchy....
void UpdateFuncImpl(dispatch_tag< UpdateTaskBase >, DynExp::InstrumentInstance &Instance) override final
virtual void UpdateFuncImpl(dispatch_tag< UpdateTask >, DynExp::InstrumentInstance &Instance)
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
Meta instrument for a spectrometer.
static constexpr auto Category() noexcept
Every derived class has to redefine this function.
virtual DynExp::Units::UnitType GetIntensityUnit() const =0
Determines the intensity (y-axis) unit of the spectra acquired by the derived instrument.
virtual void Record(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const =0
Starts the acquisition of a single spectrum.
virtual std::string GetName() const override
Returns the name of this Object type.
virtual DynExp::Units::UnitType GetFrequencyUnit() const =0
Determines the frequency (x-axis) unit of the spectra acquired by the derived instrument.
virtual double GetMinFrequency() const =0
Determines the minimal lower frequency limit where the spectrum acquisition can begin.
Spectrometer(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
Constructs an instrument instance.
virtual void SetSilentMode(bool Enable, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Enables or disables the spectrometer's silent mode, i.e. disables or enables e.g. the spectrometer's ...
virtual void ResetImpl(dispatch_tag< Spectrometer >)=0
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
void ResetImpl(dispatch_tag< InstrumentBase >) override final
virtual std::chrono::milliseconds GetTaskQueueDelay() const override
Specifies in which time intervals the instrument's task queue runs to handle pending tasks.
virtual void Abort(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Aborts a currently running spectrum acquisition.
static constexpr auto Name() noexcept
Every derived class has to redefine this function.
virtual void SetFrequencyRange(double LowerFrequency, double UpperFrequency, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const =0
Sets the spectrometer's frequency range where the spectrum acquisition begins and ends.
virtual double GetMaxFrequency() const =0
Determines the maximal upper frequency limit where the spectrum acquisition can end.
virtual std::string GetCategory() const override
Returns the category of this Object type.
virtual void SetExposureTime(SpectrometerData::TimeType ExposureTime, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const =0
Sets the spectrometer's exposure time.
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition DynExpCore.h:127
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Refer to DynExp::ParamsBase::dispatch_tag.
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Refer to DynExp::ParamsBase::dispatch_tag.
Base class for instruments. Instruments comprise virtual devices (meta instruments) and physial devic...
Definition Instrument.h:480
InstrumentBase(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Constructs an instrument instance.
Configurator class for InstrumentBase.
Definition Instrument.h:464
Data structure to contain data which is synchronized in between different threads....
Definition Instrument.h:135
Refer to ParamsBase::dispatch_tag.
Definition Instrument.h:146
Defines data for a thread belonging to a InstrumentBase instance. Refer to RunnableInstance.
Definition Instrument.h:813
Parameter class for InstrumentBase.
Definition Instrument.h:430
InstrumentParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a InstrumentBase instance.
Definition Instrument.h:441
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
Definition Object.h:2310
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Definition Object.h:2311
Refer to ParamsBase::dispatch_tag.
Definition Object.h:2026
Dummy parameter which is to be owned once by parameter classes that do not contain any other paramete...
Definition Object.h:522
const ItemIDType ID
ID of the Object this parameter class instance belongs to.
Definition Object.h:1779
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
Type owning a callback function which is invoked when a task has finished, failed,...
Definition Instrument.h:978
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Refer to DynExp::ParamsBase::dispatch_tag.
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
UnitType
Units which can be used with DynExp instruments.
Definition Units.h:28
DynExp's main namespace contains the implementation of DynExp including classes to manage resources (...
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.