DynExp
Highly flexible laboratory automation for dynamically changing experiments.
TimeTagger.h
Go to the documentation of this file.
1 // This file is part of DynExp.
2 
9 #pragma once
10 
11 #include "stdafx.h"
12 #include "DataStreamInstrument.h"
13 
14 namespace DynExpInstr
15 {
16  class TimeTagger;
17 
21  namespace TimeTaggerTasks
22  {
27  {
29 
34 
39 
46  virtual bool ApplyDataStreamSizeFromParams() const noexcept { return true; }
48  };
49 
54  {
56 
61  };
62 
67  {
69 
74  };
75 
81  {
82  public:
88 
89  private:
91  };
92  }
93 
98  {
99  public:
104  {
108  using ResultVectorType = std::vector<BasicSample>;
109 
114 
119  void Reset();
120 
121  bool Enabled;
122  long long EventCounts;
123  std::chrono::microseconds IntegrationTime;
124 
126  };
127 
136  Events
137  };
138 
140 
147  TimeTaggerData(size_t BufferSizeInSamples = 1)
148  : DataStreamInstrumentData(std::make_unique<SampleStreamType>(BufferSizeInSamples)),
150 
158 
159  virtual ~TimeTaggerData() = default;
160 
161  auto GetStreamMode() const noexcept { return StreamMode; }
162  void SetStreamMode(StreamModeType StreamMode) const noexcept;
163  bool GetStreamModeChanged() const noexcept { return StreamModeChanged; }
164  void ResetStreamMode() const noexcept { StreamModeChanged = true; }
165  void ClearStreamModeChanged() noexcept { StreamModeChanged = false; }
166 
167  auto& GetHBTResults() const noexcept { return HBTResults; }
168  auto& GetHBTResults() noexcept { return HBTResults; }
169 
170  private:
171  void ResetImpl(dispatch_tag<DataStreamInstrumentData>) override final;
173 
183 
190  mutable bool StreamModeChanged;
191 
196  };
197 
202  {
203  public:
209 
216 
217  virtual ~TimeTaggerParams() = 0;
218 
219  virtual const char* GetParamClassTag() const noexcept override { return "TimeTaggerParams"; }
220 
225 
229  Param<TimeTaggerData::StreamModeType> StreamMode = { *this, StreamModeTypeStrList(), "StreamMode", "Stream mode",
230  "Determines what to store in the sample stream of this instrument.", true, TimeTaggerData::StreamModeType::Counts };
231 
232  private:
235  };
236 
241  {
242  public:
245 
247  virtual ~TimeTaggerConfigurator() = 0;
248  };
249 
255  {
256  public:
260 
269 
270  constexpr static auto Name() noexcept { return "Time Tagger"; }
271  constexpr static auto Category() noexcept { return "I/O"; }
272 
277  : DataStreamInstrument(OwnerThreadID, std::move(Params)) {}
278 
279  virtual ~TimeTagger() = 0;
280 
281  virtual std::string GetName() const override { return Name(); }
282  virtual std::string GetCategory() const override { return Category(); }
283 
284  virtual std::chrono::milliseconds GetTaskQueueDelay() const override { return std::chrono::milliseconds(10); }
286 
291 
297  virtual double GetMinThresholdInVolts() const noexcept = 0;
298 
305  virtual double GetMaxThresholdInVolts() const noexcept = 0;
306 
312  virtual Util::picoseconds GetResolution() const = 0;
313 
319  virtual size_t GetBufferSize() const = 0;
321 
328  virtual void ResetStreamSize(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<TimeTaggerTasks::ResetBufferSizeTask>(CallbackFunc); }
329 
335  virtual void Clear(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
336 
347  virtual void ConfigureInput(bool UseRisingEdge, double ThresholdInVolts, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
348 
357  virtual void SetExposureTime(Util::picoseconds ExposureTime, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
358 
366  virtual void SetCoincidenceWindow(Util::picoseconds CoincidenceWindow, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
367 
376  virtual void SetDelay(Util::picoseconds Delay, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
377 
385  virtual void SetHBTActive(bool Enable, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
386 
395  virtual void ConfigureHBT(Util::picoseconds BinWidth, size_t BinCount, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
396 
403  virtual void ResetHBT(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
405 
406  private:
407  void ResetImpl(dispatch_tag<DataStreamInstrument>) override final;
409 
410  virtual std::unique_ptr<DynExp::InitTaskBase> MakeInitTask() const override { return DynExp::MakeTask<TimeTaggerTasks::InitTask>(); }
411  virtual std::unique_ptr<DynExp::ExitTaskBase> MakeExitTask() const override { return DynExp::MakeTask<TimeTaggerTasks::ExitTask>(); }
412  virtual std::unique_ptr<DynExp::UpdateTaskBase> MakeUpdateTask() const override { return DynExp::MakeTask<TimeTaggerTasks::UpdateTask>(); }
413  };
414 }
Implementation of a data stream meta instrument and of data streams input/output devices might work o...
Implements a circular data stream based on Util::circularbuf using samples of type BasicSample.
Configurator class for DataStreamInstrument.
Data class for DataStreamInstrument.
UnitType
Units which can be used for data stream instruments.
@ Counts
Count rate in counts per second (cps)
const DataStreamBasePtrType SampleStream
Refer to DynExp::InstrumentDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl()...
Parameter class for DataStreamInstrument.
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Implementation of the data stream meta instrument, which is a base class for all instruments reading/...
Bundles parameters to describe a data stream's stream size.
Configurator class for TimeTagger.
Definition: TimeTagger.h:241
Data class for TimeTagger.
Definition: TimeTagger.h:98
void ResetStreamMode() const noexcept
Sets StreamModeChanged to true. Callable by modules.
Definition: TimeTagger.h:164
auto & GetHBTResults() const noexcept
Getter for HBTResults.
Definition: TimeTagger.h:167
StreamModeType
Type to determine whether the instrument reads out all time-tagged events or summarized count rates....
Definition: TimeTagger.h:134
@ Counts
Read out summarized count rates in Hz.
Definition: TimeTagger.h:135
@ Events
Read out the timestamps of all time-tagged events.
Definition: TimeTagger.h:136
virtual void ResetImpl(dispatch_tag< TimeTaggerData >)
Definition: TimeTagger.h:172
StreamModeType StreamMode
Refer to DynExp::InstrumentDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl()...
Definition: TimeTagger.h:172
bool StreamModeChanged
Indicates whether StreamMode has to be applied to the phyiscal device. Also refer to StreamMode....
Definition: TimeTagger.h:190
bool GetStreamModeChanged() const noexcept
Getter for StreamModeChanged.
Definition: TimeTagger.h:163
auto GetStreamMode() const noexcept
Getter for StreamMode.
Definition: TimeTagger.h:161
void ClearStreamModeChanged() noexcept
Sets StreamModeChanged to false.
Definition: TimeTagger.h:165
TimeTaggerData(size_t BufferSizeInSamples=1)
Constructs a TimeTaggerData instance.
Definition: TimeTagger.h:147
HBTResultsType HBTResults
Stores the results of a g^(2) measurement.
Definition: TimeTagger.h:195
TimeTaggerData(DataStreamBasePtrType &&SampleStream)
Constructs a TimeTaggerData instance.
Definition: TimeTagger.h:155
virtual ~TimeTaggerData()=default
void ResetImpl(dispatch_tag< DataStreamInstrumentData >) override final
Definition: TimeTagger.cpp:47
void SetStreamMode(StreamModeType StreamMode) const noexcept
Setter for StreamMode. Adjustable by modules. Sets StreamModeChanged to true.
Definition: TimeTagger.cpp:41
auto & GetHBTResults() noexcept
Getter for HBTResults.
Definition: TimeTagger.h:168
Parameter class for TimeTagger.
Definition: TimeTagger.h:202
void ConfigureParamsImpl(dispatch_tag< DataStreamInstrumentParams >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Definition: TimeTagger.h:233
TimeTaggerParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Constructs the parameters for a TimeTagger instance.
Definition: TimeTagger.h:214
static Util::TextValueListType< TimeTaggerData::StreamModeType > StreamModeTypeStrList()
Maps description strings to the TimeTaggerData::StreamModeType enum's items.
Definition: TimeTagger.cpp:55
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: TimeTagger.h:219
Param< TimeTaggerData::StreamModeType > StreamMode
Parameter to store the time tagger's stream mode.
Definition: TimeTagger.h:229
virtual void ConfigureParamsImpl(dispatch_tag< TimeTaggerParams >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Definition: TimeTagger.h:234
StreamSizeParamsExtension StreamSizeParams
Parameter to store the size of the time tagger's sample stream in samples.
Definition: TimeTagger.h:224
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Definition: TimeTagger.h:54
void ExitFuncImpl(dispatch_tag< DataStreamInstrumentTasks::ExitTask >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Definition: TimeTagger.h:55
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Definition: TimeTagger.h:60
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Definition: TimeTagger.h:27
virtual bool ApplyDataStreamSizeFromParams() const noexcept
Determines whether to update the TimeTagger's data stream size according to the instrument parameters...
Definition: TimeTagger.h:46
virtual void InitFuncImpl(dispatch_tag< InitTask >, DynExp::InstrumentInstance &Instance)
Initializes the respective instrument within the instrument inheritance hierarchy....
Definition: TimeTagger.h:33
void InitFuncImpl(dispatch_tag< DataStreamInstrumentTasks::InitTask >, DynExp::InstrumentInstance &Instance) override final
Initializes the respective instrument within the instrument inheritance hierarchy....
Definition: TimeTagger.cpp:8
Task to reset the size of the TimeTagger's data stream to TimeTaggerParams::StreamSizeParams::StreamS...
Definition: TimeTagger.h:81
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...
Definition: TimeTagger.cpp:22
ResetBufferSizeTask(CallbackType CallbackFunc) noexcept
Constructs a ResetBufferSizeTask instance.
Definition: TimeTagger.h:87
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Definition: TimeTagger.h:67
virtual void UpdateFuncImpl(dispatch_tag< UpdateTask >, DynExp::InstrumentInstance &Instance)
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
Definition: TimeTagger.h:73
void UpdateFuncImpl(dispatch_tag< DataStreamInstrumentTasks::UpdateTask >, DynExp::InstrumentInstance &Instance) override final
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
Definition: TimeTagger.h:68
Meta instrument for a time tagging device to assign timestamps to (e.g. photon) detection events base...
Definition: TimeTagger.h:255
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...
Definition: TimeTagger.h:412
virtual DataStreamInstrumentData::UnitType GetValueUnit() const noexcept override
Determines which unit corresponds to the values managed by this DataStreamInstrument instance....
Definition: TimeTagger.h:285
virtual double GetMinThresholdInVolts() const noexcept=0
Determines the minimal configurable threshold voltage, which needs to be exceeded at the time tagger'...
virtual Util::picoseconds GetResolution() const =0
Determines the time tagger's time resolution in assigning timestamps to events.
virtual std::string GetCategory() const override
Returns the category of this Object type.
Definition: TimeTagger.h:282
virtual void ConfigureInput(bool UseRisingEdge, double ThresholdInVolts, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Configures the input channel of the physical device related to this instrument.
Definition: TimeTagger.cpp:77
virtual void ResetStreamSize(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Enqueues a task to reset the size of the instrument's sample stream to its default value.
Definition: TimeTagger.h:328
virtual std::string GetName() const override
Returns the name of this Object type.
Definition: TimeTagger.h:281
virtual void ResetImpl(dispatch_tag< TimeTagger >)=0
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
virtual double GetMaxThresholdInVolts() const noexcept=0
Determines the maximal configurable threshold voltage, which needs to be exceeded at the time tagger'...
virtual void Clear(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const =0
Clears the recorded time-tagged events from the hardware buffer of the underlying hardware adapter.
virtual void SetCoincidenceWindow(Util::picoseconds CoincidenceWindow, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Configures the time tagger's coincidence window.
Definition: TimeTagger.cpp:87
virtual void ConfigureHBT(Util::picoseconds BinWidth, size_t BinCount, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Configures the time tagger's HBT unit for g^(2) measurements.
Definition: TimeTagger.cpp:102
virtual void ResetHBT(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Resets the time tagger's HBT unit for g^(2) measurements.
Definition: TimeTagger.cpp:107
constexpr static auto Name() noexcept
Every derived class has to redefine this function.
Definition: TimeTagger.h:270
virtual void SetHBTActive(bool Enable, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Enables or disables the time tagger's HBT unit for g^(2) measurements.
Definition: TimeTagger.cpp:97
virtual std::chrono::milliseconds GetTaskQueueDelay() const override
Specifies in which time intervals the instrument's task queue runs to handle pending tasks.
Definition: TimeTagger.h:284
constexpr static auto Category() noexcept
Every derived class has to redefine this function.
Definition: TimeTagger.h:271
virtual size_t GetBufferSize() const =0
Determines the time tagger's internal buffer size for storing time-tagged events.
virtual std::unique_ptr< DynExp::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
Definition: TimeTagger.h:410
void ResetImpl(dispatch_tag< DataStreamInstrument >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
Definition: TimeTagger.cpp:112
virtual void SetDelay(Util::picoseconds Delay, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Configures the time tagger's channel delay. This is useful to compensate different signal delays betw...
Definition: TimeTagger.cpp:92
TimeTagger(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
Constructs an instrument instance.
Definition: TimeTagger.h:276
virtual void SetExposureTime(Util::picoseconds ExposureTime, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Configures the time tagger's exposure time. This is e.g. relevant to determine count rates in the Tim...
Definition: TimeTagger.cpp:82
virtual std::unique_ptr< DynExp::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
Definition: TimeTagger.h:411
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
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
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
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
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...
Definition: Instrument.h:1072
Defines the return type of task functions.
Definition: Instrument.h:824
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
DataStreamPtrType< DataStreamBase > DataStreamBasePtrType
Type of a pointer owning a DataStreamBase instance.
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.
DynExp's Util namespace contains commonly used functions and templates as well as extensions to Qt an...
Definition: circularbuf.cpp:7
std::chrono::duration< double, std::pico > picoseconds
Extends std::chrono by a duration data type for picoseconds.
Definition: Util.h:762
std::vector< std::pair< TextType, ValueType > > TextValueListType
Type of a list containing key-value pairs where key is a text of type Util::TextType.
Definition: QtUtil.h:37
Accumulates include statements to provide a precompiled header.
Type to store results of a g^(2) measurement.
Definition: TimeTagger.h:104
void Reset()
Sets Enabled to false, EventCounts as well as IntegrationTime to zero, and clears ResultVector.
Definition: TimeTagger.cpp:32
HBTResultsType()
Constructs a HBTResultsType instance calling Reset().
Definition: TimeTagger.h:113
std::chrono::microseconds IntegrationTime
Indicates the duration for which the g^(2) measurement is running.
Definition: TimeTagger.h:123
ResultVectorType ResultVector
Stores the g^(2)(t) samples.
Definition: TimeTagger.h:125
long long EventCounts
Indicates the amount of time-tagged events used to calculate g^(2).
Definition: TimeTagger.h:122
std::vector< BasicSample > ResultVectorType
List type to store the samples g^(2)(t)
Definition: TimeTagger.h:108
bool Enabled
Indicates whether a g^(2) measurement instead of timestamp readout is active.
Definition: TimeTagger.h:121