#include <Dig2Device.h> namespace caen_nscldaq { void set_tracing(bool onoff) ; class Dig2Device { private: std::uint64_t m_deviceHandle; std::uint64_t m_endpointHandle; public: Dig2Device(const char* hostOrPid, bool isUsb = false); virtual ~Dig2Device(); void SetValue(const char* parameterName, const char* value) const; void SetValue(const char* parameterName, int value) const; void SetValue(const char* parameterName, std::uint64_t value) const; void SetValue(const char* parameterName, double value) const; void SetValue(const char* parameterName, bool value) const; void SetDeviceValue(const char* devParName, const char* value) const; void SetDeviceValue(const char* devParName, int value) const; void SetDeviceValue(const char* devParName, std::uint64_t value) const; void SetDeviceValue(const char* devParName, double value) const; void SetDeviceValue(const char* devParName, bool value) const; void SetChanValue(unsigned chan, const char* chanParName, const char* value) const; void SetChanValue(unsigned chan, const char* chanParName, int value) const; void SetChanValue(unsigned chan, const char* chanParName, std::uint64_t value) const; void SetChanValue(unsigned chan, const char* chanParName, double value) const; void SetChanValue(unsigned chan, const char* chanParName, bool value) const; void SetLVDSValue(unsigned quartet, const char* LVDSName, const char* value) const; void SetLVDSValue(unsigned quartet, const char* LVDSName, int value) const; void SetLVDSValue(unsigned quartet, const char* LVDSName, std::uint64_t value) const; void SetLVDSTriggerMask(unsigned maskNo, std::uint64_t mask) const; std::string GetValue(const char* parameterName, const char* initial = nullptr) const; int GetInteger(const char* parameterName) const; std::uint64_t GetULong(const char* parameterName) const; double GetReal(const char* parameterName) const; bool GetBool(const char* parameterName) const; std::string GetDeviceValue(const char* parameterName) const; int GetDeviceInteger(const char* parameterName) const; std::uint64_t GetDeviceULong(const char* parameterName) const; double GetDeviceReal(const char* parameterName) const; bool GetDeviceBool(const char* parameterName) const; std::string GetChanValue(unsigned chan, const char* parameterName) const; int GetChanInteger(unsigned chan, const char* parameterName) const; std::uint64_t GetChanULong(unsigned chan, const char* parameterName) const; double GetChanReal(unsigned chan, const char* parameterName) const; bool GetChanBool(unsigned chan, const char* parameterName) const; std::string GetLVDSValue(unsigned quartet, const char* parameterName) const; int GetLVDSInteger(unsigned quartet, const char* parameterName) const; std::uint64_t GetLVDSULong(unsigned quartet, const char* parameterName) const; std::uint64_t GetLVDSTriggerMask(unsigned maskNo) const; void Command(const char* command) const; void SetActiveEndpoint(const char* ep) const; std::string GetActiveEndpoint() const; void SetReadDataFormat(const char* json) const; bool ReadData(int timeout, int argc, void** argv) const; bool hasData() const; }; }
Dig2Device
provides low level
access to the the device, channel and LVDS parameter spaces
of a CAEN nextgen digitizer. For parameter setting
methods, method overloading provides the appearance of
a single method, while, since C++ does not support overloading
that is based solely on the return type, there are separate
parameter getters for each possible parameter type.
Addditionally, digitizer commands, endpoint selection, testing for data presence and data acquisition are supported at a low level.
Note that if the class is built with the preprocessor
variable ENABLE_TRACING defined
and caen_nscldaq::set_tracing
is called with a true parameter,
all interactions with the CAEN support library will
be logged to the file Dig2Device.log.
This causes a huge performance hit but is useful
in sending information to CAEN support when questions
about digitizer operation arise.
Dig2Device(const char* hostOrPid, bool isUsb = false);
Constructing a Dig2Device
requires knowing how to connect to the device.
There are currently two ways to do so, direct USB
connection of via ETHERNET. The hostOrPid
parameter should be a textual host (dotted IP address
e.g. "10.0.0.2") or the USB
PID of the module (there's a sticker on each module
with the module's pid e.g. "15236")
depending on how you are connecting to the module.
The isUsb
parameter, which
defaults to false should be
true only if you are connected
directly to the module via USB.
Note that no DNS translation is attempted on the
hostOrPid
parameter if
isUsb
is false.
const void SetValue(const char* parameterName, T value);
This is the core parameter setting method.
parameterName
is a full,
absolute path to the parameter being set and
value
is the value to
set the parameter to.
The
T data type for value
,
in this case indicates that there are several overloads
for this method in which T has the type
const char*,
int,
std::uint64_t,
double
and bool, for the various data types
that parameters may take.
Note that the CAEN API requires stringified
versions when setting all of its parameter types,
so the various overloads eventually invoke
the SetValue
that accept a const char*
vaule.
Errors reported back by the CAEN FELib
are converted to
std::runtime_error
exceptions.
const void SetDeviceValue(const char* devParName, T value);
The parameter space of the CAEN digitizers looks like a file system. Paths to parameters look like paths to files in that file system. The directory parts of that path determine the class of the parameter. Device level parameters have a specific and (mostly) consistent path.
This overloaded method (same possible types for
value
as SetValue
)
computes the path to a device level parameter given the
terminal node in the path and invokes
SetValue
to set a device
level parameter.
const void SetChanValue(unsigned chan, const char* chanParName, T value);
As with device parameters, per channel parameters
have paths that are consistently constructed
given the parameter name and channel number.
This method computes the full path to a per channel
parameter and sets that parameter. It is overloaded
int the same manner as SetValue
.
Note that the CAEN FELib API actually supports setting more than one per channel parameter to the same value if the channels involved form a contiguous range. This is not supported in this version of the class.
const void SetLVDSValue(unsigned quartet, const char* LVDSName, T value);
The parameters that control the functionality of the front panel LVDS I/O pins is a separate part of the digitizer parameter 'filesystem' parameter space. This is because the 16 pins are organized into 4 pin quartets that can be independently programmed.
This overloaded method computes the path to the specified parameter name and quartet and sets that parameter's value.
const void SetLVDSTriggerMask(unsigned maskNo, std::uint64_t mask);
With apologies to my colleagues at CAEN> THe handling of the LVDS trigger mask is just totally inconsistent with the manner in which all other parameters in the digitizer are handled. They therefore merit a separate method to set their values.
const std::string GetValue(const char* parameterName, const char* initial = nullptr);
Returns the raw parameter string for a digitizer
parameter given its full path. The
initial
parameter has to do
with the wonky manner in which LVDS trigger masks
must be set. Ignore and use
GetLVDSTriggerMask
to
retrieve those trigger masks and it will take care
handling that wonkiness transparently.
const int GetInteger(const char* parameterName);
Invokes GetValue
and
attempts to conver the resulting string to
an integer which is then returned.
const std::uint64_t GetULong(const char* parameterName);
Calls GetValue
, converts
the returned string to a std::uint64_t
and returns the converted value.
const double GetReal(const char* parameterName);
Calls GetValue
and converts
the result to a double
which is returned.
const bool GetBool(const char* parameterName);
Calls GetValue
and
converts the returned value to a boolean
which is returned.
const std::string GetDeviceValue(const char* parameterName);
Computes the full path to the device level parameter
parameterName
and
returns
the value GetValue
returns for that path.
const int GetDeviceInteger(const char* parameterName);
Same as GetDeviceValue
but calls GetInteger
with the computed full path.
const td::uint64_t GetDeviceULong(const char* parameterName);
Calls GetUlong
with
the computed full path to the parameter.
const double GetDeviceReal(const char* parameterName);
Calls GetReal
with the
fully computed path to parameterName
.
const
bool GetDeviceBool(const char* parameterName);
Calls getBool
with the
full computed path for parameterName
.
const std::string GetChanValue(unsigned chan, const char* parameterName);
Computes the full path to
the channel level parameter;
parameterName
for
channel chan
and
returns the value for
getValue
.
const int GetChanInteger(unsigned chan, const char* parameterName);
Same as getChanValue
but returns the value of GetInteger
const std::uint64_t GetChanULong(unsigned chan, const char* parameterName);
Same as GetChanValue
but returns the value of GetUlong
const
double GetChanReal(unsigned chan, const char* parameterName);
Same as GetChanValue
but returns the result of GetReal
const bool GetChanBool(unsigned chan, const char* parameterName);
Same as
GetChanValue
but returns
the results of GetBool
const std::string GetLVDSValue(unsigned quartet, const char* parameterName);
Retrieves the value of the LVDS configuration
parameter; parameterName
for the selected
quartet
of pins.
This computes the full path to that parameter
and invokes GetValue
to get the result.
const int GetLVDSInteger(unsigned quartet, const char* parameterName);
Same as GetLVDSValue
but uses GetInteger
to retrive the result.
const std::uint64_t GetLVDSUlong(unsigned quartet, const char* parameterName);
Same as GetLVDSValue
but uses GetULong
to retrive the result.
const std::uint64_t GetLVDSTriggerMask(unsigned maskNo);
See my rather acerbit note about LVS trigger masks
in SetLVDSTriggerMask
.
This returns the value of LVDS trigger mask
maskNo
. That is the
mask to be applied to pin
maskNo
.
const void Command(const char* command);
Sends the command specified by
command
to the digitizer.
const void SetActiveEndpoint(const char* ep);
Digitizers have several endpoints from which data
can be acquired. In order to acquire data
from an endpoint the end point must be made
active and its data format configured
(see SetReadDataFormat
).
Once this is done, hasData
and ReadData
will,
respectively, check for data on the active endpoint
and read data from it.
The set of endpoints exported by a digitizer depend on the firmware that it is running.
This method selects the active endpoint
via its name: ep
.
const std::string GetActiveEndpoint();
Returns the name of the currently active digitizer endpoint.
const void SetReadDataFormat(const char* json);
Each endpoint can, on a read, return a number of
parameters, at the client's discretion.
The parameters desired and the order in which
they are desired is determined by a JSON
(JavaScript Object Notation) string that is passed
as json
to this method.
The method determines what is returned by
ReadData
for the active
endpoint. It also, implicitly detemrines the
number and type of parameters to be passed to
ReadData
.
The specific set of parameters and each parameter type depends on the firmware running in the digitizer and the current endpoint.
const bool ReadData(int timeout, int argc, void** argv);
Attempts to read data from the active endpoint.
If no data is available within
timeout
millisconds of
initiating the read, the method returns
false, If data is available,
then the method returns true
argc
is the number of
parameters in the argument array argv
.
argv
, in general is an
array of pointers to buffers for the items
sequentially requested in the JSON passed to
SetReadDataFormat
for the active endpoint. The data types to
which the pointers point, again, is determined
by the JSON passed to the endpoint.
bool hasData();
Returns true if the digitizer has data on the currently selected endpoint or false if not. This returns immediately either way.