areaDetector  3-13
EPICS areaDetector framework
ADnED.h
Go to the documentation of this file.
1 
9 #ifndef ADNED_H
10 #define ADNED_H
11 
12 #include <stddef.h>
13 #include <stdlib.h>
14 #include <stdarg.h>
15 #include <math.h>
16 #include <stdio.h>
17 #include <errno.h>
18 #include <string.h>
19 #include <ctype.h>
20 #include <fcntl.h>
21 #include <sys/stat.h>
22 #include <unistd.h>
23 
24 #include <epicsTime.h>
25 #include <epicsTypes.h>
26 #include <epicsThread.h>
27 #include <epicsEvent.h>
28 #include <epicsMutex.h>
29 #include <epicsString.h>
30 #include <epicsStdio.h>
31 #include <cantProceed.h>
32 #include <epicsTypes.h>
33 
34 #include <asynOctetSyncIO.h>
35 
36 #include <pv/pvTimeStamp.h>
37 #include "ADDriver.h"
38 #include "nEDChannel.h"
39 #include "ADnEDTransform.h"
40 #include "ADnEDGlobals.h"
41 
42 /* These are the drvInfo strings that are used to identify the parameters.
43  * They are used by asyn clients, including standard asyn device support */
44 #define ADnEDFirstParamString "ADNED_FIRST"
45 #define ADnEDLastParamString "ADNED_LAST"
46 #define ADnEDResetParamString "ADNED_RESET"
47 #define ADnEDStartParamString "ADNED_START"
48 #define ADnEDStopParamString "ADNED_STOP"
49 #define ADnEDPauseParamString "ADNED_PAUSE"
50 #define ADnEDEventDebugParamString "ADNED_EVENT_DEBUG"
51 #define ADnEDSeqCounterParamString "ADNED_SEQ_COUNTER"
52 #define ADnEDPulseCounterParamString "ADNED_PULSE_COUNTER"
53 #define ADnEDEventRateParamString "ADNED_EVENT_RATE"
54 #define ADnEDSeqIDParamString "ADNED_SEQ_ID"
55 #define ADnEDSeqIDMissingParamString "ADNED_SEQ_ID_MISSING"
56 #define ADnEDSeqIDNumMissingParamString "ADNED_SEQ_ID_NUM_MISSING"
57 #define ADnEDBadTimeStampParamString "ADNED_BAD_TIMESTAMP"
58 #define ADnEDPChargeParamString "ADNED_PCHARGE"
59 #define ADnEDPChargeIntParamString "ADNED_PCHARGE_INT"
60 #define ADnEDEventUpdatePeriodParamString "ADNED_EVENT_UPDATE_PERIOD"
61 #define ADnEDFrameUpdatePeriodParamString "ADNED_FRAME_UPDATE_PERIOD"
62 #define ADnEDNumChannelsParamString "ADNED_NUM_CHANNELS"
63 #define ADnEDPVNameParamString "ADNED_PV_NAME"
64 #define ADnEDNumDetParamString "ADNED_NUM_DET"
65 #define ADnEDDetPixelNumStartParamString "ADNED_DET_PIXEL_NUM_START"
66 #define ADnEDDetPixelNumEndParamString "ADNED_DET_PIXEL_NUM_END"
67 #define ADnEDDetPixelNumSizeParamString "ADNED_DET_PIXEL_NUM_SIZE"
68 #define ADnEDDetTOFNumBinsParamString "ADNED_DET_TOF_NUM_BINS"
69 #define ADnEDDet2DTypeParamString "ADNED_DET_2D_TYPE"
70 #define ADnEDDetNDArrayStartParamString "ADNED_DET_NDARRAY_START"
71 #define ADnEDDetNDArrayEndParamString "ADNED_DET_NDARRAY_END"
72 #define ADnEDDetNDArraySizeParamString "ADNED_DET_NDARRAY_SIZE"
73 #define ADnEDDetNDArrayTOFStartParamString "ADNED_DET_NDARRAY_TOF_START"
74 #define ADnEDDetNDArrayTOFEndParamString "ADNED_DET_NDARRAY_TOF_END"
75 #define ADnEDDetEventRateParamString "ADNED_DET_EVENT_RATE"
76 #define ADnEDDetEventTotalParamString "ADNED_DET_EVENT_TOTAL"
77 #define ADnEDDetTOFROIStartParamString "ADNED_DET_TOF_ROI_START"
78 #define ADnEDDetTOFROISizeParamString "ADNED_DET_TOF_ROI_SIZE"
79 #define ADnEDDetTOFROIEnableParamString "ADNED_DET_TOF_ROI_ENABLE"
80 #define ADnEDDetTOFArrayResetParamString "ADNED_DET_TOF_ARRAY_RESET"
81 //Params to use with ADnEDTransform
82 #define ADnEDDetTOFTransFile0ParamString "ADNED_DET_TOF_TRANS_FILE0"
83 #define ADnEDDetTOFTransFile1ParamString "ADNED_DET_TOF_TRANS_FILE1"
84 #define ADnEDDetTOFTransFile2ParamString "ADNED_DET_TOF_TRANS_FILE2"
85 #define ADnEDDetTOFTransFile3ParamString "ADNED_DET_TOF_TRANS_FILE3"
86 #define ADnEDDetTOFTransFile4ParamString "ADNED_DET_TOF_TRANS_FILE4"
87 #define ADnEDDetTOFTransFile5ParamString "ADNED_DET_TOF_TRANS_FILE5"
88 #define ADnEDDetTOFTransInt0ParamString "ADNED_DET_TOF_TRANS_INT0"
89 #define ADnEDDetTOFTransInt1ParamString "ADNED_DET_TOF_TRANS_INT1"
90 #define ADnEDDetTOFTransInt2ParamString "ADNED_DET_TOF_TRANS_INT2"
91 #define ADnEDDetTOFTransInt3ParamString "ADNED_DET_TOF_TRANS_INT3"
92 #define ADnEDDetTOFTransInt4ParamString "ADNED_DET_TOF_TRANS_INT4"
93 #define ADnEDDetTOFTransInt5ParamString "ADNED_DET_TOF_TRANS_INT5"
94 #define ADnEDDetTOFTransFloat0ParamString "ADNED_DET_TOF_TRANS_FLOAT0"
95 #define ADnEDDetTOFTransFloat1ParamString "ADNED_DET_TOF_TRANS_FLOAT1"
96 #define ADnEDDetTOFTransFloat2ParamString "ADNED_DET_TOF_TRANS_FLOAT2"
97 #define ADnEDDetTOFTransFloat3ParamString "ADNED_DET_TOF_TRANS_FLOAT3"
98 #define ADnEDDetTOFTransFloat4ParamString "ADNED_DET_TOF_TRANS_FLOAT4"
99 #define ADnEDDetTOFTransFloat5ParamString "ADNED_DET_TOF_TRANS_FLOAT5"
100 #define ADnEDDetTOFTransPrintParamString "ADNED_DET_TOF_TRANS_PRINT"
101 #define ADnEDDetTOFTransDebugParamString "ADNED_DET_TOF_TRANS_DEBUG"
102 #define ADnEDDetTOFTransTypeParamString "ADNED_DET_TOF_TRANS_TYPE"
103 #define ADnEDDetTOFTransOffsetParamString "ADNED_DET_TOF_TRANS_OFFSET"
104 #define ADnEDDetTOFTransScaleParamString "ADNED_DET_TOF_TRANS_SCALE"
105 //
106 #define ADnEDDetPixelMapFileParamString "ADNED_DET_PIXEL_MAP_FILE"
107 #define ADnEDDetPixelMapPrintParamString "ADNED_DET_PIXEL_MAP_PRINT"
108 #define ADnEDDetPixelMapEnableParamString "ADNED_DET_PIXEL_MAP_ENABLE"
109 #define ADnEDDetPixelROIStartXParamString "ADNED_DET_PIXEL_ROI_START_X"
110 #define ADnEDDetPixelROISizeXParamString "ADNED_DET_PIXEL_ROI_SIZE_X"
111 #define ADnEDDetPixelROIStartYParamString "ADNED_DET_PIXEL_ROI_START_Y"
112 #define ADnEDDetPixelROISizeYParamString "ADNED_DET_PIXEL_ROI_SIZE_Y"
113 #define ADnEDDetPixelSizeXParamString "ADNED_DET_PIXEL_SIZE_X"
114 #define ADnEDDetPixelROIEnableParamString "ADNED_DET_PIXEL_ROI_ENABLE"
115 #define ADnEDTOFMaxParamString "ADNED_TOF_MAX"
116 #define ADnEDAllocSpaceParamString "ADNED_ALLOC_SPACE"
117 #define ADnEDAllocSpaceStatusParamString "ADNED_ALLOC_SPACE_STATUS"
118 
119 extern "C" {
120  asynStatus ADnEDConfig(const char *portName, int maxBuffers, size_t maxMemory, int debug);
121  asynStatus ADnEDCreateFactory();
122 }
123 
124 namespace epics {
125  namespace pvData {
126  class PVStructure;
127  }
128 }
129 
130 class ADnED : public ADDriver {
131 
132  public:
133  ADnED(const char *portName, int maxBuffers, size_t maxMemory, int debug);
134  virtual ~ADnED();
135 
136  /* These are the methods that we override from asynPortDriver */
137  virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);
138  virtual asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value);
139  virtual asynStatus writeOctet(asynUser *pasynUser, const char *value,
140  size_t nChars, size_t *nActual);
141  virtual void report(FILE *fp, int details);
142 
143  static asynStatus createFactory();
144 
145  void eventTask(void);
146  void frameTask(void);
147  void eventHandler(std::tr1::shared_ptr<epics::pvData::PVStructure> const &pv_struct, epicsUInt32 channelID);
148  asynStatus allocArray(void);
149  asynStatus clearParams(void);
150 
151  private:
152 
153  //Put private functions here
154  void printPixelMap(epicsUInt32 det);
155  void printTofTrans(epicsUInt32 det);
156  asynStatus checkPixelMap(epicsUInt32 det);
157  asynStatus setupChannelMonitor(const char *pvName, int channel);
158  bool matchTransFile(const int asynParam, epicsUInt32 &transIndex);
159  bool matchTransInt(const int asynParam, epicsUInt32 &transIndex);
160  bool matchTransFloat(const int asynParam, epicsUInt32 &transIndex);
161  void resetTOFArray(epicsUInt32 det);
162 
163  //Put private static data members here
164  static const epicsInt32 s_ADNED_MAX_STRING_SIZE;
165  static const epicsInt32 s_ADNED_MAX_DETS;
166  static const epicsInt32 s_ADNED_MAX_CHANNELS;
167  static const epicsUInt32 s_ADNED_ALLOC_STATUS_OK;
168  static const epicsUInt32 s_ADNED_ALLOC_STATUS_REQ;
169  static const epicsUInt32 s_ADNED_ALLOC_STATUS_FAIL;
170  static const epicsUInt32 s_ADNED_2D_PLOT_XY;
171  static const epicsUInt32 s_ADNED_2D_PLOT_XTOF;
172  static const epicsUInt32 s_ADNED_2D_PLOT_YTOF;
173  static const epicsUInt32 s_ADNED_2D_PLOT_PIXELIDTOF;
174 
175  //Put private dynamic here
176  epicsUInt32 m_acquiring;
177  epicsUInt32 m_seqCounter[ADNED_MAX_CHANNELS];
178  epicsUInt32 m_seqID[ADNED_MAX_CHANNELS];
179  epicsUInt32 m_lastSeqID[ADNED_MAX_CHANNELS];
180  epicsUInt32 m_pulseCounter;
181  epicsFloat64 m_pChargeInt;
182  epicsTimeStamp m_nowTime;
183  double m_nowTimeSecs;
184  double m_lastTimeSecs;
185  epicsUInt32 *p_Data;
186  epicsUInt32 *p_PixelMap[ADNED_MAX_DETS+1];
187  epicsUInt32 m_PixelMapSize[ADNED_MAX_DETS+1];
188  bool m_dataAlloc;
189  epicsUInt32 m_dataMaxSize;
190  epicsUInt32 m_bufferMaxSize;
191  epicsUInt32 m_tofMax;
192  epics::pvData::PVTimeStamp m_PVTimeStamp;
193  epics::pvData::TimeStamp m_TimeStamp[ADNED_MAX_CHANNELS];
194  epics::pvData::TimeStamp m_TimeStampLast[ADNED_MAX_CHANNELS];
195  int m_detStartValues[ADNED_MAX_DETS+1];
196  int m_detEndValues[ADNED_MAX_DETS+1];
197  int m_detSizeValues[ADNED_MAX_DETS+1];
198  int m_NDArrayStartValues[ADNED_MAX_DETS+1];
199  int m_NDArrayTOFStartValues[ADNED_MAX_DETS+1];
200  int m_detTOFROIStartValues[ADNED_MAX_DETS+1];
201  int m_detTOFROISizeValues[ADNED_MAX_DETS+1];
202  int m_detTOFROIEnabled[ADNED_MAX_DETS+1];
203  int m_detPixelMappingEnabled[ADNED_MAX_DETS+1];
204  int m_detTOFTransType[ADNED_MAX_DETS+1];
205  double m_detTOFTransScale[ADNED_MAX_DETS+1];
206  double m_detTOFTransOffset[ADNED_MAX_DETS+1];
207  int m_detPixelROIStartX[ADNED_MAX_DETS+1];
208  int m_detPixelROIStartY[ADNED_MAX_DETS+1];
209  int m_detPixelROISizeX[ADNED_MAX_DETS+1];
210  int m_detPixelROISizeY[ADNED_MAX_DETS+1];
211  int m_detPixelSizeX[ADNED_MAX_DETS+1];
212  int m_detPixelROIEnable[ADNED_MAX_DETS+1];
213  epicsUInt32 m_eventsSinceLastUpdate;
214  epicsUInt32 m_detEventsSinceLastUpdate[ADNED_MAX_DETS+1];
215  epicsFloat64 m_detTotalEvents[ADNED_MAX_DETS+1];
216 
217  epics::pvAccess::ChannelProvider::shared_pointer p_ChannelProvider;
218  std::tr1::shared_ptr<nEDChannel::nEDChannelRequester> p_ChannelRequester;
219  std::tr1::shared_ptr<nEDChannel::nEDMonitorRequester> p_MonitorRequester[ADNED_MAX_CHANNELS];
220  epics::pvData::Monitor::shared_pointer p_Monitor[ADNED_MAX_CHANNELS];
221  epics::pvAccess::Channel::shared_pointer p_Channel[ADNED_MAX_CHANNELS];
222 
223  ADnEDTransform *p_Transform[ADNED_MAX_DETS+1];
224 
225  //Constructor parameters.
226  const epicsUInt32 m_debug;
227 
228  epicsEventId m_startEvent;
229  epicsEventId m_stopEvent;
230  epicsEventId m_startFrame;
231  epicsEventId m_stopFrame;
232 
233  //Values used for pasynUser->reason, and indexes into the parameter library.
234  int ADnEDFirstParam;
235  #define ADNED_FIRST_DRIVER_COMMAND ADnEDFirstParam
236  int ADnEDResetParam;
237  int ADnEDStartParam;
238  int ADnEDStopParam;
239  int ADnEDPauseParam;
240  int ADnEDEventDebugParam;
241  int ADnEDSeqCounterParam;
242  int ADnEDPulseCounterParam;
243  int ADnEDEventRateParam;
244  int ADnEDSeqIDParam;
245  int ADnEDSeqIDMissingParam;
246  int ADnEDSeqIDNumMissingParam;
247  int ADnEDBadTimeStampParam;
248  int ADnEDPChargeParam;
249  int ADnEDPChargeIntParam;
250  int ADnEDEventUpdatePeriodParam;
251  int ADnEDFrameUpdatePeriodParam;
252  int ADnEDNumChannelsParam;
253  int ADnEDPVNameParam;
254  int ADnEDNumDetParam;
255  int ADnEDDetPixelNumStartParam;
256  int ADnEDDetPixelNumEndParam;
257  int ADnEDDetPixelNumSizeParam;
258  int ADnEDDetTOFNumBinsParam;
259  int ADnEDDet2DTypeParam;
260  int ADnEDDetNDArrayStartParam;
261  int ADnEDDetNDArrayEndParam;
262  int ADnEDDetNDArraySizeParam;
263  int ADnEDDetNDArrayTOFStartParam;
264  int ADnEDDetNDArrayTOFEndParam;
265  int ADnEDDetEventRateParam;
266  int ADnEDDetEventTotalParam;
267  int ADnEDDetTOFROIStartParam;
268  int ADnEDDetTOFROISizeParam;
269  int ADnEDDetTOFROIEnableParam;
270  int ADnEDDetTOFArrayResetParam;
271  //Params to use with ADnEDTransform
272  int ADnEDDetTOFTransFile0Param;
273  int ADnEDDetTOFTransFile1Param;
274  int ADnEDDetTOFTransFile2Param;
275  int ADnEDDetTOFTransFile3Param;
276  int ADnEDDetTOFTransFile4Param;
277  int ADnEDDetTOFTransFile5Param;
278  int ADnEDDetTOFTransInt0Param;
279  int ADnEDDetTOFTransInt1Param;
280  int ADnEDDetTOFTransInt2Param;
281  int ADnEDDetTOFTransInt3Param;
282  int ADnEDDetTOFTransInt4Param;
283  int ADnEDDetTOFTransInt5Param;
284  int ADnEDDetTOFTransFloat0Param;
285  int ADnEDDetTOFTransFloat1Param;
286  int ADnEDDetTOFTransFloat2Param;
287  int ADnEDDetTOFTransFloat3Param;
288  int ADnEDDetTOFTransFloat4Param;
289  int ADnEDDetTOFTransFloat5Param;
290  int ADnEDDetTOFTransPrintParam;
291  int ADnEDDetTOFTransDebugParam;
292  int ADnEDDetTOFTransTypeParam;
293  int ADnEDDetTOFTransOffsetParam;
294  int ADnEDDetTOFTransScaleParam;
295  //
296  int ADnEDDetPixelMapFileParam;
297  int ADnEDDetPixelMapPrintParam;
298  int ADnEDDetPixelMapEnableParam;
299  int ADnEDDetPixelROIStartXParam;
300  int ADnEDDetPixelROISizeXParam;
301  int ADnEDDetPixelROIStartYParam;
302  int ADnEDDetPixelROISizeYParam;
303  int ADnEDDetPixelSizeXParam;
304  int ADnEDDetPixelROIEnableParam;
305  int ADnEDTOFMaxParam;
306  int ADnEDAllocSpaceParam;
307  int ADnEDAllocSpaceStatusParam;
308  int ADnEDLastParam;
309  #define ADNED_LAST_DRIVER_COMMAND ADnEDLastParam
310 
311 };
312 
313 #define NUM_DRIVER_PARAMS (&ADNED_LAST_DRIVER_COMMAND - &ADNED_FIRST_DRIVER_COMMAND + 1)
314 
315 #endif //ADNED_H
asynStatus ADnEDConfig(const char *portName, int maxBuffers, size_t maxMemory, int debug)
The following functions have C linkage, and can be called directly or from iocsh.
Definition: ADnED.cpp:1834
asynStatus ADnEDCreateFactory()
Config function for IOC shell.
Definition: ADnED.cpp:1852
#define ADNED_MAX_CHANNELS
Definition: ADnEDGlobals.h:4
#define ADNED_MAX_DETS
Definition: ADnEDGlobals.h:3
Class from which areaDetector drivers are directly derived.
Definition: ADDriver.h:132
Definition: ADnED.h:130
virtual void report(FILE *fp, int details)
Report status of the driver.
Definition: ADnED.cpp:402
virtual asynStatus writeOctet(asynUser *pasynUser, const char *value, size_t nChars, size_t *nActual)
Reimplementing this function from asynNDArrayDriver to deal with strings.
Definition: ADnED.cpp:675
void eventHandler(std::tr1::shared_ptr< epics::pvData::PVStructure > const &pv_struct, epicsUInt32 channelID)
Event handler callback for monitor.
Definition: ADnED.cpp:981
asynStatus allocArray(void)
Allocate local storage for event handler.
Definition: ADnED.cpp:1318
virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value)
Reimplementing this function from ADDriver to deal with integer values.
Definition: ADnED.cpp:423
static asynStatus createFactory()
Class function to create a PVAccess client factory.
Definition: ADnED.cpp:380
void frameTask(void)
Frame readout task.
Definition: ADnED.cpp:1716
virtual asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value)
Reimplementing this function from ADDriver to deal with floating point values.
Definition: ADnED.cpp:620
ADnED(const char *portName, int maxBuffers, size_t maxMemory, int debug)
Constructor.
Definition: ADnED.cpp:67
virtual ~ADnED()
Destructor.
Definition: ADnED.cpp:372
asynStatus clearParams(void)
Clear parameters and data members on a acqusition start.
Definition: ADnED.cpp:1429
void eventTask(void)
Event readout task.
Definition: ADnED.cpp:1477
Library of functions to use for transforming the time of flight value into another parameter (for exa...
Definition: ADnEDTransform.h:33
Definition: ADnED.h:124
list value
Definition: makeDbAndEdl.py:234