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
78 enum class FrequencyUnitType {
79 Hz,
80 nm,
81 Inv_cm
82 };
83
89 enum class IntensityUnitType {
90 Counts
91 };
92
98 static const char* FrequencyUnitTypeToStr(const FrequencyUnitType& Unit);
99
105 static const char* IntensityUnitTypeToStr(const IntensityUnitType& Unit);
106
111 Ready,
112 Warning,
113 Error,
114 Capturing
115 };
116
121 {
122 public:
128
135
141
146 SpectrumType(SpectrumType&& Other);
147
153 SpectrumType& operator=(const SpectrumType& Other);
154
161
162 void Reset();
163
164 auto GetFrequencyUnit() const noexcept { return FrequencyUnit; }
165 auto GetIntensityUnit() const noexcept { return IntensityUnit; }
166 auto& GetSpectrum() const noexcept { return Samples; }
167 auto& GetSpectrum() noexcept { return Samples; }
168
173 bool HasSpectrum() const noexcept { return !Samples.empty(); }
174
175 private:
178
179 std::map<double, double> Samples;
180 };
181
182 SpectrometerData() = default;
183 virtual ~SpectrometerData() = default;
184
185 auto GetMinExposureTime() const noexcept { return MinExposureTime; }
186 void SetMinExposureTime(double MinExposureTime) noexcept { this->MinExposureTime = TimeType(Util::NumToT<int>(MinExposureTime)); }
188 auto GetMaxExposureTime() const noexcept { return MaxExposureTime; }
189 void SetMaxExposureTime(double MaxExposureTime) noexcept { this->MaxExposureTime = TimeType(Util::NumToT<int>(MaxExposureTime)); }
191 auto GetCurrentExposureTime() const noexcept { return CurrentExposureTime; }
192 void SetCurrentExposureTime(double CurrentExposureTime) noexcept { this->CurrentExposureTime = TimeType(Util::NumToT<int>(CurrentExposureTime)); }
194 auto GetCurrentLowerFrequency() const noexcept { return CurrentLowerFrequency; }
196 auto GetCurrentUpperFrequency() const noexcept { return CurrentUpperFrequency; }
198 auto GetSilentModeEnabled() const noexcept { return SilentModeEnabled; }
199 void SetSilentModeEnabled(bool Enable) noexcept { SilentModeEnabled = Enable; }
200
205 auto GetCapturingState() const noexcept { return GetCapturingStateChild(); }
206
213
219 auto GetCapturingProgress() const noexcept { return GetCapturingProgressChild(); }
220
224 bool HasSpectrum() const noexcept { return CurrentSpectrum.HasSpectrum(); }
225
231 SpectrumType GetSpectrum() const;
232
238 SpectrumType GetSpectrumCopy() const;
239
244 void SetSpectrum(SpectrumType&& Other);
245
249 void ClearSpectrum() const;
250
251 private:
252 void ResetImpl(dispatch_tag<InstrumentDataBase>) override final;
254
259 virtual CapturingStateType GetCapturingStateChild() const noexcept = 0;
260 virtual double GetCapturingProgressChild() const noexcept { return 0; }
262
268 bool SilentModeEnabled = false;
269
276 };
277
282 {
283 public:
289
290 virtual ~SpectrometerParams() = 0;
291
292 virtual const char* GetParamClassTag() const noexcept override { return "SpectrometerParams"; }
293
294 private:
297
298 DummyParam Dummy = { *this };
299 };
300
313
318 {
319 public:
323
332
333 constexpr static auto Name() noexcept { return "Spectrometer"; }
334 constexpr static auto Category() noexcept { return "Image Capturing"; }
335
341
342 virtual ~Spectrometer() = 0;
343
344 virtual std::string GetName() const override { return Name(); }
345 virtual std::string GetCategory() const override { return Category(); }
346
347 virtual std::chrono::milliseconds GetTaskQueueDelay() const override { return std::chrono::milliseconds(50); }
348
353
358
364
369 virtual double GetMinFrequency() const = 0;
370
375 virtual double GetMaxFrequency() const = 0;
377
384
389 virtual void SetExposureTime(SpectrometerData::TimeType ExposureTime, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
390
398 virtual void SetFrequencyRange(double LowerFrequency, double UpperFrequency, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
399
407 virtual void SetSilentMode(bool Enable, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
408
413 virtual void Record(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
414
421 virtual void Abort(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
423
424 private:
425 void ResetImpl(dispatch_tag<InstrumentBase>) override final;
427 };
428}
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.
SpectrumType(FrequencyUnitType FrequencyUnit, IntensityUnitType IntensityUnit)
Constructs a SpectrumType instance with the specified units.
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(const SpectrumType &Other)
Copy-constructs a SpectrumType instance.
SpectrumType()
Constructs a SpectrumType instance with FrequencyUnit set to FrequencyUnitType::Hz and IntensityUnit ...
IntensityUnitType IntensityUnit
The spectrum's intensity (y-axis) unit.
FrequencyUnitType FrequencyUnit
The spectrum's frequency (x-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.
static const char * IntensityUnitTypeToStr(const IntensityUnitType &Unit)
Returns a descriptive string of a respective intensity unit to be e.g. used in plots.
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.
static const char * FrequencyUnitTypeToStr(const FrequencyUnitType &Unit)
Returns a descriptive string of a respective frequency unit to be e.g. used in plots.
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.
FrequencyUnitType
Supported spectrometer frequency units.
IntensityUnitType
Supported spectrometer intensity units.
@ Counts
Number of counts (arbitrary unit)
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 void Record(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const =0
Starts the acquisition of a single spectrum.
virtual SpectrometerData::FrequencyUnitType GetFrequencyUnit() const =0
Determines the frequency (x-axis) unit of the spectra acquired by the derived instrument.
virtual std::string GetName() const override
Returns the name of this Object type.
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.
virtual SpectrometerData::IntensityUnitType GetIntensityUnit() const =0
Determines the intensity (y-axis) unit of the spectra acquired by the derived instrument.
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:451
InstrumentBase(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Constructs an instrument instance.
Configurator class for InstrumentBase.
Definition Instrument.h:435
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:772
Parameter class for InstrumentBase.
Definition Instrument.h:401
InstrumentParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a InstrumentBase instance.
Definition Instrument.h:412
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
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
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
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...
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.