1 # Software development{#development}
4 \pre You have to install the library before to start using it. See \ref install page for details.
7 In order to use the library, just include the CAENMCA.h header in your project:
8 \snippet examples.h IncludeHeader
10 To link your code with the library, the instructions depends on your operating system
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:
17 $ gcc mytest.c -lCAENMCA -o mytest
21 An example make project is included in the source directory, under `<sourcedir>/MCALibTest`.
22 To get started, you may try to build it:
25 $ cd <sourcedir>/MCALibTest
27 $ ./bin/MCALibTest eth://127.0.0.1/
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`)
37 and this into the Linker properties:
38 * **Additional Library Directories**: `CAENMCA.lib` path (by default `<installdir>/lib/<platform>`)
39 * **Additional Dependencies**: `CAENMCA.lib`
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.
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.
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
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
58 You can connect only once per device:
60 Client -> Device1: CAEN_MCA_OpenDevice(...)
61 Device1 --[#blue]> Client: Ok
63 Client -> Device2: CAEN_MCA_OpenDevice(...)
64 Device2 --[#blue]> Client: Ok
66 Client -> Device1: CAEN_MCA_OpenDevice(...)
67 Device1 --[#red]>x Client: Fail: no reply
69 Client -> Device1: CAEN_MCA_CloseDevice(...)
70 Device1 --[#blue]> Client: Ok
71 Client -> Device1: CAEN_MCA_OpenDevice(...)
72 Device1 --[#blue]> Client: Ok
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.
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
86 Several types of handle exist, represented by the following class diagram:
88 \anchor handle-class-diagram
99 CHANNEL *-- ENERGYSPECTRUM
100 CHANNEL *-- MCSSPECTRUM
101 HVCHANNEL *-- HVRANGE
102 HVCHANNEL *-- PARAMETER
103 HVRANGE *-- PARAMETER
104 LVDSGROUP *-- PARAMETER
106 PARAMETER *-- PARAMETER
107 ENERGYSPECTRUM *-- ROI
108 ENERGYSPECTRUM *-- PARAMETER
109 MCSSPECTRUM *-- PARAMETER
112 DTSPECTRUM *-- PARAMETER
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
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
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
131 but not from the library handle:
132 \snippet examples_handles.c GetHandleInvalid
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.
138 For example, we can get a handle to the parameter "PARAM_CH_THRESHOLD" of the Channel 0:
139 \snippet examples_handles.c GetHandleByName1
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
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
151 In case no ancestor of the requested type are found, the function returns NULL:
152 \snippet examples_handles.c GetAncestorHandle2
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.
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.
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
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).
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
190 In the second case, pass a pointer where to store the result:
191 \snippet examples_parameters.c GetValue
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
203 The array containing the handles of the collection, as well as its length, can be obtained
205 \snippet examples_parameters.c GetCollectionInfo
207 ## Acquisition control
208 To start acquisition:
209 \snippet examples_acquisition_control.c StartAcquisition
212 \snippet examples_acquisition_control.c StopAcquisition
214 where `handle` can be either a device handle or a channel handle.
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
222 \snippet examples_hv.c SetStatus
225 \snippet examples_hv.c SetStatusAlternative
228 \snippet examples_hv.c GetOnOff
230 To get extended status bitmask:
231 \snippet examples_hv.c GetStatus
233 where the meaning of each bit can be printed in this way:
234 \snippet examples_hv.c StatusMask
236 To get the active range:
237 \snippet examples_hv.c GetActiveRange
239 Once we have the active range, monitor parameters like VMon can be read:
240 \snippet examples_hv.c GetVMon
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
246 then, use ::CAEN_MCA_DATA_HVRANGE_INFO:
247 \snippet examples_hv.c GetInfo
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.
254 The list of supported parameter of a given handle can be retrieved also at runtime:
255 \snippet examples_parameters.c GetSupportedParameters
257 To get a parameter handle given its codename:
258 \snippet examples_parameters.c GetHandle
260 To get extended parameter information:
261 \snippet examples_parameters.c GetInfo
263 To get the value of parameters with type ::CAEN_MCA_PARAMETER_TYPE_RANGE:
264 \snippet examples_parameters.c GetValue
266 To set the value of parameters with type ::CAEN_MCA_PARAMETER_TYPE_RANGE:
267 \snippet examples_parameters.c SetValue
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!
273 To set the value of parameters with type ::CAEN_MCA_PARAMETER_TYPE_LIST:
274 \snippet examples_parameters.c SetValueList
276 ## Save, load and delete configurations
277 Save the current configuration:
278 \snippet examples_board_control.c SaveConfiguration
280 Load a saved configuration:
281 \snippet examples_board_control.c LoadConfiguration
283 Delete a saved configuration:
284 \snippet examples_board_control.c DeleteConfiguration
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.
293 Read the value of a register:
294 \snippet examples_board_control.c ReadRegister
296 ## Energy Spectra and ROIs
297 Get a spectrum handle:
298 \snippet examples_spectrum.c GetHandle
300 Get an energy spectrum:
301 \snippet examples_spectrum.c GetSpectrum
303 Set the number of bins:
304 \snippet examples_spectrum.c SetNBins
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
309 Set the remote filename where to save che spectrum:
310 \snippet examples_spectrum.c SetFilename
313 \snippet examples_roi.c GetHandle
315 Get the entries in a ROI:
316 \snippet examples_roi.c GetROI
319 \snippet examples_roi.c SetLow
320 \snippet examples_roi.c SetHigh
322 Clear a spectrum and its ROIs:
323 \snippet examples_spectrum.c ClearSpectrum
325 The gain stabilization can be enabled for the energy spectrum in order to compensate for possible temperature variation effects.
327 Enable/Disable the gain stabilizer:
328 \snippet examples_spectrum.c GSEnableDisable
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
334 Set the update time for the gain stabilizer:
335 \snippet examples_spectrum.c GSSetTime
337 Reset the gain stabilizer:
338 \snippet examples_spectrum.c GSReset
340 ## Enable and get waveforms
342 \snippet examples_waveforms.c EnableWaveforms
345 \snippet examples_waveforms.c GetWaveforms
349 Get a MCS spectrum handle:
350 \snippet examples_mcs.c GetHandle
353 \snippet examples_mcs.c GetSpectrum
355 Set the number of bins:
356 \snippet examples_mcs.c SetNBins
359 \snippet examples_mcs.c SetDwell
361 Set the MCS counting mode (MCS on ICR, MCS on Ext.Signal, MCS on SCA):
362 \snippet examples_mcs.c SetMode
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
368 Enable/Disable hardware and software Dwell
369 \snippet examples_mcs.c EnableDisableDS
370 \snippet examples_mcs.c EnableDisableDH
372 Enable/Disable hardware and software Sweep
373 \snippet examples_mcs.c EnableDisableSS
374 \snippet examples_mcs.c EnableDisableSH
376 Clear a MCS spectrum:
377 \snippet examples_mcs.c Clear
379 Send a Sweep command to a MCS spectrum:
380 \snippet examples_mcs.c Sweep
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.
389 Set the number of DT spectrum bins:
390 \snippet examples_dt_spectrum.c DTSetNBins
392 Set the time interval for the DT spectrum:
393 \snippet examples_dt_spectrum.c DTSetTStep
395 Before enabling the DT spectrum, the user should set the reference channel for DT calculations:
396 \snippet examples_dt_spectrum.c DTSetRefCh
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
401 How to read the DT spectrum from the board:
402 \snippet examples_dt_spectrum.c DTSpectrumGet
404 Clear the DT spectrum:
405 \snippet examples_dt_spectrum.c ClearDTSpectrum
410 This feature can be used to get a list of the events, or save it to a remote file.
412 * timetag (in picoseconds since acquisition start)
414 * a set of flags (\ref ListEventFlagsMask)
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)
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
427 At stop, events in the buffer are written to file (if in file mode) and then freed.
429 A new acquisition will overwrite the existing file if the filename is not changed.
432 Enable or disable list mode:
433 \snippet examples_lists.c Enable
436 \snippet examples_lists.c SetMode
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
442 Set the maximum number of events to store in the server internal buffers:
443 \snippet examples_lists.c SetMaxNEvts
445 This is an example to get and parse lists:
446 \snippet examples_lists.c GetLists
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