DynExp
Highly flexible laboratory automation for dynamically changing experiments.
QutoolsQuTAG.cpp
Go to the documentation of this file.
1 // This file is part of DynExp.
2 
3 #include "stdafx.h"
4 #include "QutoolsQuTAG.h"
5 
6 namespace DynExpInstr
7 {
9  {
10  // In case one is only interested in the counts per exposure time window, there is no need to transfer all
11  // single count events to the computer. So, mute the channel in that case.
12  if (InstrData->GetStreamMode() == TimeTaggerData::StreamModeType::Counts)
13  InstrData->HardwareAdapter->ConfigureFilter(InstrData->GetChannel(), DynExpHardware::QutoolsTDCSyms::TDC_FilterType::FILTER_MUTE);
14  else
15  InstrData->HardwareAdapter->ConfigureFilter(InstrData->GetChannel());
16 
17  InstrData->ClearStreamModeChanged();
18  }
19 
21  {
22  auto InstrParams = DynExp::dynamic_Params_cast<QutoolsQuTAG>(Instance.ParamsGetter());
23  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
24 
25  InstrData->SetChannel(InstrParams->Channel);
26 
27  Instance.LockObject(InstrParams->HardwareAdapter, InstrData->HardwareAdapter);
28  UpdateStreamMode(InstrData);
29  InstrData->HardwareAdapter->EnableChannel(InstrData->GetChannel());
30 
32  }
33 
35  {
36  ExitFuncImpl(dispatch_tag<ExitTask>(), Instance);
37 
38  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
39 
40  InstrData->HardwareAdapter->DisableChannel(InstrData->GetChannel());
41  Instance.UnlockObject(InstrData->HardwareAdapter);
42  }
43 
45  {
46  {
47  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
48 
49  if (InstrData->GetStreamModeChanged())
50  UpdateStreamMode(InstrData);
51  } // InstrData unlocked here.
52 
53  UpdateFuncImpl(dispatch_tag<UpdateTask>(), Instance);
54  }
55 
57  {
58  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
59  auto SampleStream = InstrData->GetCastSampleStream<TimeTaggerData::SampleStreamType>();
60 
61  if (InstrData->GetStreamMode() == TimeTaggerData::StreamModeType::Counts)
62  {
63  auto Counts = InstrData->HardwareAdapter->GetCoincidenceCounts(InstrData->GetChannel() + 1);
64  if (Counts.second)
65  SampleStream->WriteSample(Counts.first);
66  }
67  else
68  SampleStream->WriteSamples(InstrData->HardwareAdapter->GetTimestamps(InstrData->GetChannel()));
69 
70  if (InstrData->GetHBTResults().Enabled)
71  {
72  InstrData->GetHBTResults().EventCounts = InstrData->HardwareAdapter->GetHBTEventCounts();
73  InstrData->GetHBTResults().IntegrationTime = InstrData->HardwareAdapter->GetHBTIntegrationTime();
74  InstrData->GetHBTResults().ResultVector = InstrData->HardwareAdapter->GetHBTResult();
75  }
76 
77  return {};
78  }
79 
81  {
82  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
83 
84  InstrData->HardwareAdapter->SetTimestampBufferSize(Util::NumToT<DynExpHardware::QutoolsTDCSyms::Int32>(BufferSizeInSamples));
85  InstrData->GetSampleStream()->SetStreamSize(BufferSizeInSamples);
86 
87  return {};
88  }
89 
91  {
92  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
93 
94  InstrData->HardwareAdapter->ClearTimestamps(InstrData->GetChannel());
95 
96  return {};
97  }
98 
100  {
101  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
102 
103  InstrData->HardwareAdapter->ConfigureSignalConditioning(InstrData->GetChannel(), DynExpHardware::QutoolsTDCSyms::SCOND_MISC, UseRisingEdge, ThresholdInVolts);
104 
105  return {};
106  }
107 
109  {
110  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
111 
112  InstrData->HardwareAdapter->SetExposureTime(std::chrono::duration_cast<std::chrono::milliseconds>(ExposureTime));
113 
114  return {};
115  }
116 
118  {
119  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
120 
121  InstrData->HardwareAdapter->SetCoincidenceWindow(CoincidenceWindow);
122 
123  return {};
124  }
125 
127  {
128  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
129 
130  InstrData->HardwareAdapter->SetChannelDelay(InstrData->GetChannel(), Delay);
131 
132  return {};
133  }
134 
136  {
137  auto InstrParams = DynExp::dynamic_Params_cast<QutoolsQuTAG>(Instance.ParamsGetter());
138  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
139 
140  InstrData->HardwareAdapter->EnableHBT(Enable);
141  InstrData->GetHBTResults().Enabled = Enable;
142 
143  if (Enable)
144  {
145  InstrData->HardwareAdapter->ConfigureHBTChannels(InstrData->GetChannel(), InstrParams->CrossCorrChannel);
146 
147  // Disable filters for HBT.
148  InstrData->HardwareAdapter->ConfigureFilter(InstrData->GetChannel());
149  InstrData->HardwareAdapter->ConfigureFilter(InstrParams->CrossCorrChannel);
150 
151  // Avoid going back to pre-defined stream mode if the flag was set and not cleared before.
152  InstrData->ClearStreamModeChanged();
153  }
154 
155  return {};
156  }
157 
159  {
160  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
161 
162  if (BinWidth / InstrData->HardwareAdapter->GetTimebase() < 1 || BinWidth / InstrData->HardwareAdapter->GetTimebase() > 1e6)
163  throw Util::OutOfRangeException("The bin width exceeds the allowed range (see tdchbt.h's reference).");
164  if (BinCount < 16 || BinCount > 64000)
165  throw Util::OutOfRangeException("The number of bins exceeds the allowed range (see tdchbt.h's reference).");
166 
167  InstrData->HardwareAdapter->ConfigureHBTParams(BinWidth, Util::NumToT<DynExpHardware::QutoolsTDCSyms::Int32>(BinCount));
168 
169  return {};
170  }
171 
173  {
174  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(Instance.InstrumentDataGetter());
175 
176  if (InstrData->GetHBTResults().Enabled)
177  InstrData->HardwareAdapter->ResetHBT();
178 
179  return {};
180  }
181 
183  {
184  Channel = 0;
185 
186  ResetImpl(dispatch_tag<QutoolsQuTAGData>());
187  }
188 
189  QutoolsQuTAG::QutoolsQuTAG(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType&& Params)
190  : TimeTagger(OwnerThreadID, std::move(Params))
191  {
192  }
193 
195  {
196  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(GetInstrumentData());
197 
198  return InstrData->HardwareAdapter->GetTimebase();
199  }
200 
202  {
203  auto InstrData = DynExp::dynamic_InstrumentData_cast<QutoolsQuTAG>(GetInstrumentData());
204 
205  return InstrData->HardwareAdapter->GetBufferSize();
206  }
207 
209  {
211  }
212 }
Implementation of an instrument to control a single input of the qutools TDC time tagger.
Implements a circular data stream based on Util::circularbuf using samples of type BasicSample.
void WriteSample(const SampleT &Sample)
Writes a single sample to the stream's buffer StreamBuffer.
void ResetImpl(dispatch_tag< TimeTaggerData >) override final
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...
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...
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...
void ExitFuncImpl(dispatch_tag< TimeTaggerTasks::ExitTask >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
void InitFuncImpl(dispatch_tag< TimeTaggerTasks::InitTask >, DynExp::InstrumentInstance &Instance) override final
Initializes the respective instrument within the instrument inheritance hierarchy....
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...
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...
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...
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...
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...
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...
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...
void UpdateFuncImpl(dispatch_tag< TimeTaggerTasks::UpdateTask >, DynExp::InstrumentInstance &Instance) override final
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
QutoolsQuTAG(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
virtual Util::picoseconds GetResolution() const override
Determines the time tagger's time resolution in assigning timestamps to events.
void ResetImpl(dispatch_tag< TimeTagger >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
virtual size_t GetBufferSize() const override
Determines the time tagger's internal buffer size for storing time-tagged events.
Meta instrument for a time tagging device to assign timestamps to (e.g. photon) detection events base...
Definition: TimeTagger.h:255
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1151
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1120
InstrumentDataTypeSyncPtrType GetInstrumentData(const std::chrono::milliseconds Timeout=GetInstrumentDataTimeoutDefault)
Locks the mutex of the instrument data class instance InstrumentData assigned to this InstrumentBase ...
Definition: Instrument.cpp:222
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
const InstrumentBase::InstrumentDataGetterType InstrumentDataGetter
Getter for instrument's data. Refer to InstrumentBase::InstrumentDataGetterType.
Definition: Instrument.h:791
Refer to ParamsBase::dispatch_tag.
Definition: Object.h:2018
const Object::ParamsGetterType ParamsGetter
Invoke to obtain the parameters (derived from ParamsBase) of Owner.
Definition: Object.h:3671
void UnlockObject(LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer)
Unlocks an Object instance stored in the LinkedObjectWrapperContainer ObjectWrapperContainer....
Definition: Object.h:3570
void LockObject(const ParamsBase::Param< ObjectLink< ObjectT >> &LinkParam, LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer, std::chrono::milliseconds Timeout=ObjectLinkBase::LockObjectTimeoutDefault)
Locks an Object instance referenced by a parameter LinkParam of type ParamsBase::Param< ObjectLink< O...
Definition: Object.h:3554
Defines the return type of task functions.
Definition: Instrument.h:824
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1182
Thrown when an argument passed to a function exceeds the valid range.
Definition: Exception.h:211
Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads....
Definition: Util.h:170
void UpdateStreamMode(Util::SynchronizedPointer< QutoolsQuTAGData > &InstrData)
Definition: QutoolsQuTAG.cpp:8
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
std::chrono::duration< double, std::pico > picoseconds
Extends std::chrono by a duration data type for picoseconds.
Definition: Util.h:762
Accumulates include statements to provide a precompiled header.