CAEN MCA  0.99.10
SDK for Hexagon
DEVELOPMENT.md
Go to the documentation of this file.
1 # Software development{#development}
2 \tableofcontents
3 
4 \pre You have to install the library before to start using it. See \ref install page for details.
5 
6 # Compile your project
7 In order to use the library, just include the CAENMCA.h header in your project:
8 \snippet examples.h IncludeHeader
9 
10 To link your code with the library, the instructions depends on your operating system
11 
12 ## Linux
13 By default the installer puts libraries and headers into the system folders.
14 To use the library into your project, just add the parameter `-lCAENMCA` to the linker. For example:
15 
16 ``` bash
17 $ gcc mytest.c -lCAENMCA -o mytest
18 ```
19 
20 ### Examples
21 An example make project is included in the source directory, under `<sourcedir>/MCALibTest`.
22 To get started, you may try to build it:
23 
24 ``` bash
25 $ cd <sourcedir>/MCALibTest
26 $ make -j3
27 $ ./bin/MCALibTest eth://127.0.0.1/
28 ```
29 
30 ## Windows
31 By default the installer puts DLL files into the system folders. You may find a copy also into
32 your install directory, at `<installdir>/lib`.
33 To use the library into your project, just add the following stuff into your Visual Studio
34 project C/C++ properties:
35 * **Additional Include Directories**: `CAENMCA.h` path (by default `<installdir>/include`)
36 
37 and this into the Linker properties:
38 * **Additional Library Directories**: `CAENMCA.lib` path (by default `<installdir>/lib/<platform>`)
39 * **Additional Dependencies**: `CAENMCA.lib`
40 
41 ### Examples
42 An example Visual Studio project is included in the install directory, under `<installdir>\MCALibTest`.
43 To get started, you may try to copy it to your user directory, and open it in Visual Studio.
44 
45 \attention The path settings of the example project have been set relative to the installer default path
46 `C:\Program Files\CAEN\Digitizers\CAENMCA`. In case you have chosen a different location, you have to
47 adjust the Visual Studio project accordingly.
48 
49 # Connect a device
50 The connection with a device in your network is established using CAEN_MCA_OpenDevice().
51 The function returns an handle that can be used later to interact with the system.
52 For example, this connects to a local instance of the Hexagon Server:
53 \snippet examples_board_control.c OpenDevice
54 
55 Eventually, the connection should be closed by CAEN_MCA_CloseDevice(). This also free all the allocated memory:
56 \snippet examples_board_control.c CloseDevice
57 
58 You can connect only once per device:
59 \startuml
60  Client -> Device1: CAEN_MCA_OpenDevice(...)
61  Device1 --[#blue]> Client: Ok
62  ...
63  Client -> Device2: CAEN_MCA_OpenDevice(...)
64  Device2 --[#blue]> Client: Ok
65  ...
66  Client -> Device1: CAEN_MCA_OpenDevice(...)
67  Device1 --[#red]>x Client: Fail: no reply
68  ...
69  Client -> Device1: CAEN_MCA_CloseDevice(...)
70  Device1 --[#blue]> Client: Ok
71  Client -> Device1: CAEN_MCA_OpenDevice(...)
72  Device1 --[#blue]> Client: Ok
73 \enduml
74 
75 # Handles{#handles}
76 From [Handle](https://en.wikipedia.org/wiki/Handle_(computing)) article on Wikipedia:
77 > In computer programming, a handle is an abstract reference to a resource.
78 > Handles are used when application software references blocks of memory or objects managed
79 > by another system [...]. A resource handle [...]
80 > can be a pointer that allows access to further information.
81 
82 In this library, handles are pointers to instances of abstract data types.
83 In a object-oriented programming analogy, they can be seen just as pointers to objects
84 a certain class.
85 
86 Several types of handle exist, represented by the following class diagram:
87 
88 \anchor handle-class-diagram
89 \startuml
90  LIBRARY *-- DEVICE
91  DEVICE *-- CHANNEL
92  DEVICE *-- HVCHANNEL
93  DEVICE *-- PARAMETER
94  DEVICE *-- LVDSGROUP
95  DEVICE *-- TRACE
96  DEVICE *-- MONOUT
97  DEVICE *-- DTSPECTRUM
98  CHANNEL *-- PARAMETER
99  CHANNEL *-- ENERGYSPECTRUM
100  CHANNEL *-- MCSSPECTRUM
101  HVCHANNEL *-- HVRANGE
102  HVCHANNEL *-- PARAMETER
103  HVRANGE *-- PARAMETER
104  LVDSGROUP *-- PARAMETER
105  TRACE *-- PARAMETER
106  PARAMETER *-- PARAMETER
107  ENERGYSPECTRUM *-- ROI
108  ENERGYSPECTRUM *-- PARAMETER
109  MCSSPECTRUM *-- PARAMETER
110  ROI *-- PARAMETER
111  MONOUT *-- PARAMETER
112  DTSPECTRUM *-- PARAMETER
113 \enduml
114 
115 ## Children
116 The function CAEN_MCA_GetChildHandle() can be used to get handles to child objects, given a handle.
117 The only exception is to get the library handle, when no input handle is needed as first parameter,
118 and the index can be any number:
119 \snippet examples_handles.c Library
120 
121 The handle of the device is returned by CAEN_MCA_OpenDevice(). Additionally, with the index returned by
122 by the last argument of that function it is possible to get the same handle using CAEN_MCA_GetChildHandle()
123 with the library as first argument.
124 Anyway, the first opened device has always index 0:
125 \snippet examples_handles.c Device
126 
127 CAEN_MCA_GetChildHandle() can be used only for children, and not for other descendants. For example,
128 it is possible to get the channel handles from the device handle:
129 \snippet examples_handles.c GetHandle
130 
131 but not from the library handle:
132 \snippet examples_handles.c GetHandleInvalid
133 
134 For parameters, a convenient function CAEN_MCA_GetChildHandleByName() is provided, which can be used with a string
135 instead of a numeric index. It is implemented using hash tables, and the performances are almost identical.
136 Numeric indexes of parameters exist but are not published.
137 
138 For example, we can get a handle to the parameter "PARAM_CH_THRESHOLD" of the Channel 0:
139 \snippet examples_handles.c GetHandleByName1
140 
141 Note that CAEN_MCA_GetChildHandleByName() can be used also for other handle types
142 (except for ::CAEN_MCA_HANDLE_COLLECTION). In these cases, the index is just the literal version of the index,
143 except for ::CAEN_MCA_HANDLE_DEVICE, where it represents the hostname used in CAEN_MCA_OpenDevice():
144 \snippet examples_handles.c GetHandleByName2
145 
146 ## Ancestors
147 The function CAEN_MCA_GetAncestorHandle() can be used to get the the handle of an ancestor of the provided handle.
148 For example, we can get the Channel 0 handle from a parameter of the Channel 0, as well as the device handle:
149 \snippet examples_handles.c GetAncestorHandle1
150 
151 In case no ancestor of the requested type are found, the function returns NULL:
152 \snippet examples_handles.c GetAncestorHandle2
153 
154 # Data and Commands
155 Data retrieve from MCA is managed using the functions CAEN_MCA_SetData() (or its `va_list` version
156 CAEN_MCA_SetDataV()) and CAEN_MCA_GetData() (or its `va_list` version CAEN_MCA_GetDataV()).
157 The expected arguments are:
158 * first argument is a ::CAEN_MCA_HANDLE on which to execute the call
159 * second argument is an integer representing the requested type (see ::CAEN_MCA_DataType_t)
160 * the third argument is a 64-bit mask, with bit-meaning depending on the selected type (see \ref DataMask)
161 * variadic arguments, one for each bit selected in the mask.
162 
163 Similarly to Data related functions, Commands are managed using the function CAEN_MCA_SendCommand()
164 (or its `va_list` version CAEN_MCA_SendCommandV()).
165 The expected arguments are:
166 * first argument is a ::CAEN_MCA_HANDLE on which to execute the call
167 * second argument is an integer representing the requested type (see ::CAEN_MCA_CommandType_t)
168 * the third argument is a 64-bit mask for input data, with bit-meaning depending on the selected type (see \ref CommandMask)
169 * the forth argument is a 64-bit mask for output data, with bit-meaning depending on the selected type (see \ref CommandMask)
170 * variadic arguments, one for each bit selected first in the input data mask, and then in the output data mask.
171 
172 ## Variadic argument order{#variadic-argument-order}
173 The order of the variadic arguments is specified by the order of the value of its relative mask.
174 For example, if the mask sets the bits with `mask = (MASK_A | MASK_B)`, where `MASK_A = 0x1`
175 and `MASK_B = 0x4` then you must append the variable relative to `MASK_A` first, and then the
176 one relative to `MASK_B`. Note that since the bitwise-OR operator is commutative, the order
177 in which you specify the bits of the mask does not matter at all, like in this example:
178 \snippet examples_board_control.c WrongOrder
179 
180 ## Variadic argument type{#variadic-argument-type}
181 The type of the variadic arguments is specified in the mask documentation: it is the type to be used
182 by CAEN_MCA_SetData(). In CAEN_MCA_GetData() functions, you have to pass **a pointer** to allocated memory
183 of that type (except for arrays).
184 
185 In this examples, the same data #DATAMASK_VALUE_NUMERIC of ::CAEN_MCA_DATA_PARAMETER_VALUE
186 is used both with CAEN_MCA_SetData() and CAEN_MCA_GetData(). As reported in the relative documentation,
187 that data requires a `double` variable as argument. In the first case, pass just the variable as argument:
188 \snippet examples_parameters.c SetValue
189 
190 In the second case, pass a pointer where to store the result:
191 \snippet examples_parameters.c GetValue
192 
193 # Examples
194 
195 ## Handle collections
196 A special case of handles is represented by the collections. Collections are "transparent" elements of the class diagram
197 tree shown in the \ref handle-class-diagram "Handle class diagram". Each object has a collection for every type of
198 child, and every child is contained in the relative collections.
199 For example, the handles of type ::CAEN_MCA_HANDLE_HVCHANNEL are contained in a special collection belonging
200 to the handle of type ::CAEN_MCA_HANDLE_DEVICE:
201 \snippet examples_handles.c GetCollection
202 
203 The array containing the handles of the collection, as well as its length, can be obtained
204 in this way:
205 \snippet examples_parameters.c GetCollectionInfo
206 
207 ## Acquisition control
208 To start acquisition:
209 \snippet examples_acquisition_control.c StartAcquisition
210 
211 To stop acquisition:
212 \snippet examples_acquisition_control.c StopAcquisition
213 
214 where `handle` can be either a device handle or a channel handle.
215 
216 To set an automatic stop criteria, set the following four parameters
217 (if the parameter is set to zero, the stop criteria is disabled):
218 \snippet examples_acquisition_control.c SetStopCriteria
219 
220 ## HV control
221 To set status:
222 \snippet examples_hv.c SetStatus
223 
224 or, alternatively:
225 \snippet examples_hv.c SetStatusAlternative
226 
227 To get status:
228 \snippet examples_hv.c GetOnOff
229 
230 To get extended status bitmask:
231 \snippet examples_hv.c GetStatus
232 
233 where the meaning of each bit can be printed in this way:
234 \snippet examples_hv.c StatusMask
235 
236 To get the active range:
237 \snippet examples_hv.c GetActiveRange
238 
239 Once we have the active range, monitor parameters like VMon can be read:
240 \snippet examples_hv.c GetVMon
241 
242 Note that monitor parameters can be accessed only from the currently active range.
243 To get information about the other ranges, get the handle of a range:
244 \snippet examples_hv.c GetHandle
245 
246 then, use ::CAEN_MCA_DATA_HVRANGE_INFO:
247 \snippet examples_hv.c GetInfo
248 
249 ## Parameters
250 Parameters are values that can be set at runtime to change the behaviour and
251 the state of the device. The full list of the supported parameters, grouped by handle,
252 can be found at \ref parameters.
253 
254 The list of supported parameter of a given handle can be retrieved also at runtime:
255 \snippet examples_parameters.c GetSupportedParameters
256 
257 To get a parameter handle given its codename:
258 \snippet examples_parameters.c GetHandle
259 
260 To get extended parameter information:
261 \snippet examples_parameters.c GetInfo
262 
263 To get the value of parameters with type ::CAEN_MCA_PARAMETER_TYPE_RANGE:
264 \snippet examples_parameters.c GetValue
265 
266 To set the value of parameters with type ::CAEN_MCA_PARAMETER_TYPE_RANGE:
267 \snippet examples_parameters.c SetValue
268 
269 To get the value of parameters with type ::CAEN_MCA_PARAMETER_TYPE_LIST:
270 \snippet examples_parameters.c GetValueList
271 \note You do not have to pass a pointer to an array, but just the array!
272 
273 To set the value of parameters with type ::CAEN_MCA_PARAMETER_TYPE_LIST:
274 \snippet examples_parameters.c SetValueList
275 
276 ## Save, load and delete configurations
277 Save the current configuration:
278 \snippet examples_board_control.c SaveConfiguration
279 
280 Load a saved configuration:
281 \snippet examples_board_control.c LoadConfiguration
282 
283 Delete a saved configuration:
284 \snippet examples_board_control.c DeleteConfiguration
285 
286 Change configurations database path:
287 \snippet examples_board_control.c DatabasePath
288 NOTE: the change is not persistent, you need to set path every time the
289 library is reloaded. The previous database is left unchanged and not
290 copied to the new location.
291 
292 ## Registers
293 Read the value of a register:
294 \snippet examples_board_control.c ReadRegister
295 
296 ## Energy Spectra and ROIs
297 Get a spectrum handle:
298 \snippet examples_spectrum.c GetHandle
299 
300 Get an energy spectrum:
301 \snippet examples_spectrum.c GetSpectrum
302 
303 Set the number of bins:
304 \snippet examples_spectrum.c SetNBins
305 
306 Spectra are saved at stop and periodically during the run. Set the auto-save period (the default is 5 seconds):
307 \snippet examples_spectrum.c SetPeriod
308 
309 Set the remote filename where to save che spectrum:
310 \snippet examples_spectrum.c SetFilename
311 
312 Get a ROI handle:
313 \snippet examples_roi.c GetHandle
314 
315 Get the entries in a ROI:
316 \snippet examples_roi.c GetROI
317 
318 Set range of a ROI:
319 \snippet examples_roi.c SetLow
320 \snippet examples_roi.c SetHigh
321 
322 Clear a spectrum and its ROIs:
323 \snippet examples_spectrum.c ClearSpectrum
324 
325 The gain stabilization can be enabled for the energy spectrum in order to compensate for possible temperature variation effects.
326 
327 Enable/Disable the gain stabilizer:
328 \snippet examples_spectrum.c GSEnableDisable
329 
330 Set the ROI used by the gain stabilizer (this ROI defines the stabilization peak):
331 \snippet examples_spectrum.c GSSetLow
332 \snippet examples_spectrum.c GSSetHigh
333 
334 Set the update time for the gain stabilizer:
335 \snippet examples_spectrum.c GSSetTime
336 
337 Reset the gain stabilizer:
338 \snippet examples_spectrum.c GSReset
339 
340 ## Enable and get waveforms
341 Enable waveforms:
342 \snippet examples_waveforms.c EnableWaveforms
343 
344 Get waveforms:
345 \snippet examples_waveforms.c GetWaveforms
346 
347 ## MCS Spectra
348 
349 Get a MCS spectrum handle:
350 \snippet examples_mcs.c GetHandle
351 
352 Get a MCS spectrum:
353 \snippet examples_mcs.c GetSpectrum
354 
355 Set the number of bins:
356 \snippet examples_mcs.c SetNBins
357 
358 Set the dwell time:
359 \snippet examples_mcs.c SetDwell
360 
361 Set the MCS counting mode (MCS on ICR, MCS on Ext.Signal, MCS on SCA):
362 \snippet examples_mcs.c SetMode
363 
364 Set the MCS acquisition mode:
365 MCS REPLACE (replace bin contents after a sweep), MCS SUM (sum bin contents after a sweep), MCS REPLACE AND SUM (replace bin contents after first sweep, then sum)
366 \snippet examples_mcs.c SetAcqMode
367 
368 Enable/Disable hardware and software Dwell
369 \snippet examples_mcs.c EnableDisableDS
370 \snippet examples_mcs.c EnableDisableDH
371 
372 Enable/Disable hardware and software Sweep
373 \snippet examples_mcs.c EnableDisableSS
374 \snippet examples_mcs.c EnableDisableSH
375 
376 Clear a MCS spectrum:
377 \snippet examples_mcs.c Clear
378 
379 Send a Sweep command to a MCS spectrum:
380 \snippet examples_mcs.c Sweep
381 
382 ## DT Spectra
383 
384 ### Introduction
385 This tool can be used to find the best values for the coincidence parameters (coincidence window length and coincidence delay), in order to configure the board channels to work in coincidence/anticoincidence mode.
386 When the DT spectrum is enabled, it is filled with the time difference DT between the timestamps of the events collected by the board channels.
387 The plot is always centered in DT = 0 and its range is given by [-(Nbins/2 * DTstep), Nbins/2 * DTstep], where Nbins is the number of bins and DTstep is the time value corresponding to a single bin.
388 
389 Set the number of DT spectrum bins:
390 \snippet examples_dt_spectrum.c DTSetNBins
391 
392 Set the time interval for the DT spectrum:
393 \snippet examples_dt_spectrum.c DTSetTStep
394 
395 Before enabling the DT spectrum, the user should set the reference channel for DT calculations:
396 \snippet examples_dt_spectrum.c DTSetRefCh
397 
398 Enable the coincidence mode for both channels and set a big value for the coincidence window length:
399 \snippet examples_dt_spectrum.c DTEnableDisable
400 
401 How to read the DT spectrum from the board:
402 \snippet examples_dt_spectrum.c DTSpectrumGet
403 
404 Clear the DT spectrum:
405 \snippet examples_dt_spectrum.c ClearDTSpectrum
406 
407 ## List mode
408 
409 ### Introduction
410 This feature can be used to get a list of the events, or save it to a remote file.
411 An event is made of:
412 * timetag (in picoseconds since acquisition start)
413 * energy (in bins)
414 * a set of flags (\ref ListEventFlagsMask)
415 
416 Three buffers (one per each type of data) are allocated on acquisition start with size ::DATAMASK_LIST_MAXNEVTS.
417 When the buffers have been filled, behaviour depends on the selected mode:
418 * ::CAEN_MCA_SAVEMODE_FILE_ASCII: events are written to a file in the ASCII format and buffers reset
419 * ::CAEN_MCA_SAVEMODE_FILE_BINARY: events are written to a file in the binary format and buffers reset
420 * ::CAEN_MCA_SAVEMODE_MEMORY: nothing is done until a buffer reset occurs (i.e. buffers not reset)
421 
422 A reset occurs as soon as you call ::CAEN_MCA_DATA_LIST_MODE on CAEN_MCA_GetData() to get any of:
423 * ::DATAMASK_LIST_DATA_TIMETAG
424 * ::DATAMASK_LIST_DATA_ENERGY
425 * ::DATAMASK_LIST_DATA_FLAGS_DATAMASK
426 
427 At stop, events in the buffer are written to file (if in file mode) and then freed.
428 
429 A new acquisition will overwrite the existing file if the filename is not changed.
430 
431 ### Control
432 Enable or disable list mode:
433 \snippet examples_lists.c Enable
434 
435 Set the save mode:
436 \snippet examples_lists.c SetMode
437 
438 In case of save mode set to ::CAEN_MCA_SAVEMODE_FILE_ASCII or ::CAEN_MCA_SAVEMODE_FILE_BINARY,
439 this set the data to save into the remote file:
440 \snippet examples_lists.c SetData
441 
442 Set the maximum number of events to store in the server internal buffers:
443 \snippet examples_lists.c SetMaxNEvts
444 
445 This is an example to get and parse lists:
446 \snippet examples_lists.c GetLists
447 
448 ## Discover devices on the newtork
449 Find Hexagon devices on your network, a special command::CAEN_MCA_DATA_DISCOVEREDDEVICES
450 on CAEN_MCA_GetData() is provided:
451 \snippet examples_discovery.c DiscoverDevices