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
79 enum class FrequencyUnitType {
80 Hz,
81 nm,
82 Inv_cm
83 };
84
91 enum class IntensityUnitType {
92 Counts
93 };
94
100 static const char* FrequencyUnitTypeToStr(const FrequencyUnitType& Unit);
101
107 static const char* IntensityUnitTypeToStr(const IntensityUnitType& Unit);
108
113 Ready,
114 Warning,
115 Error,
116 Capturing
117 };
118
123 {
124 public:
130
137
143
148 SpectrumType(SpectrumType&& Other);
149
155 SpectrumType& operator=(const SpectrumType& Other);
156
163
164 void Reset();
165
166 auto GetFrequencyUnit() const noexcept { return FrequencyUnit; }
167 auto GetIntensityUnit() const noexcept { return IntensityUnit; }
168 auto& GetSpectrum() const noexcept { return Samples; }
169 auto& GetSpectrum() noexcept { return Samples; }
170
175 bool HasSpectrum() const noexcept { return !Samples.empty(); }
176
177 private:
180
181 std::map<double, double> Samples;
182 };
183
184 SpectrometerData() = default;
185 virtual ~SpectrometerData() = default;
186
187 auto GetMinExposureTime() const noexcept { return MinExposureTime; }
188 void SetMinExposureTime(double MinExposureTime) noexcept { this->MinExposureTime = TimeType(Util::NumToT<int>(MinExposureTime)); }
190 auto GetMaxExposureTime() const noexcept { return MaxExposureTime; }
191 void SetMaxExposureTime(double MaxExposureTime) noexcept { this->MaxExposureTime = TimeType(Util::NumToT<int>(MaxExposureTime)); }
193 auto GetCurrentExposureTime() const noexcept { return CurrentExposureTime; }
194 void SetCurrentExposureTime(double CurrentExposureTime) noexcept { this->CurrentExposureTime = TimeType(Util::NumToT<int>(CurrentExposureTime)); }
196 auto GetCurrentLowerFrequency() const noexcept { return CurrentLowerFrequency; }
198 auto GetCurrentUpperFrequency() const noexcept { return CurrentUpperFrequency; }
200 auto GetSilentModeEnabled() const noexcept { return SilentModeEnabled; }
201 void SetSilentModeEnabled(bool Enable) noexcept { SilentModeEnabled = Enable; }
202
207 auto GetCapturingState() const noexcept { return GetCapturingStateChild(); }
208
215
221 auto GetCapturingProgress() const noexcept { return GetCapturingProgressChild(); }
222
226 bool HasSpectrum() const noexcept { return CurrentSpectrum.HasSpectrum(); }
227
233 SpectrumType GetSpectrum() const;
234
240 SpectrumType GetSpectrumCopy() const;
241
246 void SetSpectrum(SpectrumType&& Other);
247
251 void ClearSpectrum() const;
252
253 private:
254 void ResetImpl(dispatch_tag<InstrumentDataBase>) override final;
256
261 virtual CapturingStateType GetCapturingStateChild() const noexcept = 0;
262 virtual double GetCapturingProgressChild() const noexcept { return 0; }
264
270 bool SilentModeEnabled = false;
271
278 };
279
284 {
285 public:
291
292 virtual ~SpectrometerParams() = 0;
293
294 virtual const char* GetParamClassTag() const noexcept override { return "SpectrometerParams"; }
295
296 private:
299
300 DummyParam Dummy = { *this };
301 };
302
315
320 {
321 public:
325
334
335 constexpr static auto Name() noexcept { return "Spectrometer"; }
336 constexpr static auto Category() noexcept { return "Image Capturing"; }
337
343
344 virtual ~Spectrometer() = 0;
345
346 virtual std::string GetName() const override { return Name(); }
347 virtual std::string GetCategory() const override { return Category(); }
348
349 virtual std::chrono::milliseconds GetTaskQueueDelay() const override { return std::chrono::milliseconds(50); }
350
355
360
366
371 virtual double GetMinFrequency() const = 0;
372
377 virtual double GetMaxFrequency() const = 0;
379
386
391 virtual void SetExposureTime(SpectrometerData::TimeType ExposureTime, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
392
400 virtual void SetFrequencyRange(double LowerFrequency, double UpperFrequency, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
401
409 virtual void SetSilentMode(bool Enable, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
410
415 virtual void Record(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
416
423 virtual void Abort(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
425
426 private:
427 void ResetImpl(dispatch_tag<InstrumentBase>) override final;
429 };
430}
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: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: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
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...
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.