DynExp
Highly flexible laboratory automation for dynamically changing experiments.
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 
13 namespace DynExpInstr
14 {
15  class Spectrometer;
16 
20  namespace SpectrometerTasks
21  {
26  {
28 
33  };
34 
39  {
41 
46  };
47 
52  {
54 
59  };
60  }
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 
110  enum class CapturingStateType {
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 
212  bool IsCapturing() const noexcept { return GetCapturingStateChild() == CapturingStateType::Capturing; }
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 
266  double CurrentLowerFrequency = 0.0;
267  double CurrentUpperFrequency = 0.0;
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 
305  {
306  public:
309 
311  virtual ~SpectrometerConfigurator() = 0;
312  };
313 
318  {
319  public:
323 
332 
333  constexpr static auto Name() noexcept { return "Spectrometer"; }
334  constexpr static auto Category() noexcept { return "Image Capturing"; }
335 
340  : InstrumentBase(OwnerThreadID, std::move(Params)) {}
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.
Definition: Spectrometer.h:305
Type describing a spectrum as acquired by the Spectrometer instrument.
Definition: Spectrometer.h:121
auto GetFrequencyUnit() const noexcept
Getter for FrequencyUnit.
Definition: Spectrometer.h:164
SpectrumType & operator=(const SpectrumType &Other)
Copies a SpectrumType instance's content to this instance.
auto GetIntensityUnit() const noexcept
Getter for IntensityUnit.
Definition: Spectrometer.h:165
SpectrumType(FrequencyUnitType FrequencyUnit, IntensityUnitType IntensityUnit)
Constructs a SpectrumType instance with the specified units.
Definition: Spectrometer.h:134
bool HasSpectrum() const noexcept
Indicates whether the spectrum is empty.
Definition: Spectrometer.h:173
std::map< double, double > Samples
Samples of the spectrum as tuples in units (FrequencyUnit, IntensityUnit)
Definition: Spectrometer.h:179
SpectrumType(const SpectrumType &Other)
Copy-constructs a SpectrumType instance.
Definition: Spectrometer.h:140
SpectrumType()
Constructs a SpectrumType instance with FrequencyUnit set to FrequencyUnitType::Hz and IntensityUnit ...
Definition: Spectrometer.h:127
IntensityUnitType IntensityUnit
The spectrum's intensity (y-axis) unit.
Definition: Spectrometer.h:177
FrequencyUnitType FrequencyUnit
The spectrum's frequency (x-axis) unit.
Definition: Spectrometer.h:176
auto & GetSpectrum() const noexcept
Getter for Samples.
Definition: Spectrometer.h:166
auto & GetSpectrum() noexcept
Getter for Samples.
Definition: Spectrometer.h:167
void Reset()
Removes all samples from the spectrum (clears Samples).
Data class for Spectrometer.
Definition: Spectrometer.h:66
virtual void ResetImpl(dispatch_tag< SpectrometerData >)
Definition: Spectrometer.h:253
void SetMinExposureTime(double MinExposureTime) noexcept
Setter for MinExposureTime.
Definition: Spectrometer.h:186
auto GetCapturingState() const noexcept
Returns the spectrometer's current capturing state.
Definition: Spectrometer.h:205
SpectrumType GetSpectrumCopy() const
Copying getter for CurrentSpectrum. This function is more expensive than GetSpectrum().
auto GetMaxExposureTime() const noexcept
Getter for MaxExposureTime.
Definition: Spectrometer.h:188
auto GetSilentModeEnabled() const noexcept
Getter for SilentModeEnabled.
Definition: Spectrometer.h:198
void SetCurrentExposureTime(TimeType CurrentExposureTime) noexcept
Setter for CurrentExposureTime.
Definition: Spectrometer.h:193
virtual double GetCapturingProgressChild() const noexcept
Determines the progress of a spectrum acquisition.
Definition: Spectrometer.h:260
void SetCurrentLowerFrequency(double CurrentLowerFrequency) noexcept
Setter for CurrentLowerFrequency.
Definition: Spectrometer.h:195
double CurrentUpperFrequency
Current upper frequency limit where the spectrum acquisition ends.
Definition: Spectrometer.h:267
TimeType MaxExposureTime
Maximal exposure time the spectrometer supports.
Definition: Spectrometer.h:264
SpectrumType CurrentSpectrum
Current spectrum acquired by the spectrometer. Logical const-ness: allow const member function GetSpe...
Definition: Spectrometer.h:275
CapturingStateType
Possible spectrometer states.
Definition: Spectrometer.h:110
@ 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.
Definition: Spectrometer.h:187
void SetCurrentExposureTime(double CurrentExposureTime) noexcept
Setter for CurrentExposureTime.
Definition: Spectrometer.h:192
virtual ~SpectrometerData()=default
auto GetCurrentExposureTime() const noexcept
Getter for CurrentExposureTime.
Definition: Spectrometer.h:191
auto GetCurrentLowerFrequency() const noexcept
Getter for CurrentLowerFrequency.
Definition: Spectrometer.h:194
TimeType MinExposureTime
Minimal exposure time the spectrometer supports.
Definition: Spectrometer.h:263
auto GetCapturingProgress() const noexcept
Determines the progress of a spectrum acquisition.
Definition: Spectrometer.h:219
std::chrono::milliseconds TimeType
Time type describing the spectrometer's times like its exposure time.
Definition: Spectrometer.h:71
void SetCurrentUpperFrequency(double CurrentUpperFrequency) noexcept
Setter for CurrentUpperFrequency.
Definition: Spectrometer.h:197
void SetMaxExposureTime(TimeType MaxExposureTime) noexcept
Setter for MaxExposureTime.
Definition: Spectrometer.h:190
static const char * FrequencyUnitTypeToStr(const FrequencyUnitType &Unit)
Returns a descriptive string of a respective frequency unit to be e.g. used in plots.
Definition: Spectrometer.cpp:8
bool HasSpectrum() const noexcept
Indicates whether the spectrum is empty.
Definition: Spectrometer.h:224
void SetMaxExposureTime(double MaxExposureTime) noexcept
Setter for MaxExposureTime.
Definition: Spectrometer.h:189
double CurrentLowerFrequency
Current lower frequency limit where the spectrum acquisition begins.
Definition: Spectrometer.h:266
auto GetCurrentUpperFrequency() const noexcept
Getter for CurrentUpperFrequency.
Definition: Spectrometer.h:196
bool IsCapturing() const noexcept
Determines whether the spectrometer is currently acquiring a spectrum.
Definition: Spectrometer.h:212
virtual CapturingStateType GetCapturingStateChild() const noexcept=0
Returns the spectrometer's current capturing state.
auto GetMinExposureTime() const noexcept
Getter for MinExposureTime.
Definition: Spectrometer.h:185
FrequencyUnitType
Supported spectrometer frequency units.
Definition: Spectrometer.h:78
IntensityUnitType
Supported spectrometer intensity units.
Definition: Spectrometer.h:89
@ Counts
Number of counts (arbitrary unit)
TimeType CurrentExposureTime
Current exposure time of the spectrometer.
Definition: Spectrometer.h:265
bool SilentModeEnabled
Indicates whether the spectrometer's silent mode is turned on, i.e. the spectrometer's fans are turne...
Definition: Spectrometer.h:268
void SetSilentModeEnabled(bool Enable) noexcept
Setter for SilentModeEnabled.
Definition: Spectrometer.h:199
Parameter class for Spectrometer.
Definition: Spectrometer.h:282
virtual void ConfigureParamsImpl(dispatch_tag< SpectrometerParams >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Definition: Spectrometer.h:296
SpectrometerParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Constructs the parameters for a Spectrometer instance.
Definition: Spectrometer.h:288
DummyParam Dummy
Dummy parameter which is to be owned once by parameter classes that do not contain any other paramete...
Definition: Spectrometer.h:298
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...
Definition: Spectrometer.h:292
void ConfigureParamsImpl(dispatch_tag< InstrumentParamsBase >) override final
Definition: Spectrometer.h:295
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Definition: Spectrometer.h:39
void ExitFuncImpl(dispatch_tag< ExitTaskBase >, DynExp::InstrumentInstance &Instance) override final
Definition: Spectrometer.h:40
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Definition: Spectrometer.h:45
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Definition: Spectrometer.h:26
virtual void InitFuncImpl(dispatch_tag< InitTask >, DynExp::InstrumentInstance &Instance)
Initializes the respective instrument within the instrument inheritance hierarchy....
Definition: Spectrometer.h:32
void InitFuncImpl(dispatch_tag< InitTaskBase >, DynExp::InstrumentInstance &Instance) override final
Definition: Spectrometer.h:27
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Definition: Spectrometer.h:52
void UpdateFuncImpl(dispatch_tag< UpdateTaskBase >, DynExp::InstrumentInstance &Instance) override final
Definition: Spectrometer.h:53
virtual void UpdateFuncImpl(dispatch_tag< UpdateTask >, DynExp::InstrumentInstance &Instance)
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
Definition: Spectrometer.h:58
Meta instrument for a spectrometer.
Definition: Spectrometer.h:318
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.
Definition: Spectrometer.h:344
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.
Definition: Spectrometer.h:339
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.
Definition: Spectrometer.h:347
constexpr static auto Category() noexcept
Every derived class has to redefine this function.
Definition: Spectrometer.h:334
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.
constexpr static auto Name() noexcept
Every derived class has to redefine this function.
Definition: Spectrometer.h:333
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.
Definition: Spectrometer.h:345
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....
Definition: Instrument.h:1144
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1151
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Definition: Instrument.h:1113
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1120
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.
Definition: Instrument.cpp:210
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....
Definition: Instrument.h:1175
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1182
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
Definition: Instrument.h:1254
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.