NSCL DDAS
12.1-001
Support for XIA DDAS at FRIB
|
Simulates data produced by a DDAS readout program in user code. More...
#include <DDASDataSimulator.h>
Public Member Functions | |
DDASDataSimulator (std::string fname, int version) | |
Constructor. More... | |
void | beginRun () |
Begin a simulated run. More... | |
void | endRun () |
End a simulated run. More... | |
void | putHit (const ddasfmt::DDASHit &hit, int sourceID=0, bool useExtTS=false, double cal=0.0) |
Write a hit to the output file. This is the normal way users will add simulated data to the output. More... | |
void | setBuffer (const ddasfmt::DDASHit &hit) |
Set the data buffer from a DDASHit. More... | |
std::vector< uint32_t > | getBuffer () |
Get the data buffer. More... | |
void | dumpBuffer () |
Formatted dump of data buffer to stdout. More... | |
Simulates data produced by a DDAS readout program in user code.
This class provides an interface to simulate the data output by an NSCLDAQ readout program running DDAS electronics. The ddasfmt::DDASHit class is used to encapsulate the hit information. The putHit()
method of this class fills an event buffer with the Pixie data payload based on the contents of the passed ddasfmt::DDASHit, including optional data like QDC sums or traces, wraps it in an NSCLDAQ header and writes it to a file data sink.
The output NSCLDAQ data format is specified by the user when they instantiate the class. For completeness, the beginRun()
and endRun()
methods will write the expected data format and state change items you would see when starting and stopping a run.
In general the code uses the information contained within the ddasfmt::DDASHit to figure out its size. In order to calculate calibrated timestamps, the module MSPS must be defined as part of the hit, or, if using an external timestamp, the calibration must be provided when adding the hit. Trace data is not checked for overflows or to ensure that the range of the trace matches the bit depth of the module, that responsiblity is on the user. It is assumed that the CFD always succeeds, even if the correction is 0.
To use this class in your own code:
$DAQINC
, $DAQROOT
/unifiedformat/include and $DAQROOT
/ddasformat/include are in the compiler include files search path (add -I<path>
in e.g., CXXFLAGS
) and include DDASDataSimulator.h and DDASHit.h.$DAQLIB
and $DAQROOT
/ddasformat/lib (add -L<path> -Wl,-rpath=<path>
to LDFLAGS
and -l<libname>
to LDLIBS
).Example code to create a complete run with a single event:
DAQ::DDAS::DDASDataSimulator::DDASDataSimulator | ( | std::string | fname, |
int | version | ||
) |
Constructor.
fname | Output file name. |
version | NSLCDAQ data format version. Mapped to ufmt enum value. |
The format factory owns the concrete factory subclass. Any exceptions when mapping version specifiers are thrown to the caller.
void DAQ::DDAS::DDASDataSimulator::beginRun | ( | ) |
Begin a simulated run.
CErrnoExecption | If the output file isn't opened properly. |
On begin:
void DAQ::DDAS::DDASDataSimulator::dumpBuffer | ( | ) |
Formatted dump of data buffer to stdout.
void DAQ::DDAS::DDASDataSimulator::endRun | ( | ) |
End a simulated run.
CErrnoExecption | If the output file isn't closed properly. |
On end:
beginRun()
. The elapsed run time will be nonsense if the start time is not set by calling beginRun()
prior to this function.
|
inline |
Get the data buffer.
setBuffer()
is called first. void DAQ::DDAS::DDASDataSimulator::putHit | ( | const ddasfmt::DDASHit & | hit, |
int | sourceID = 0 , |
||
bool | useExtTS = false , |
||
double | cal = 0.0 |
||
) |
Write a hit to the output file. This is the normal way users will add simulated data to the output.
hit | References the hit to write. |
sourceID | The source ID value (optional, default=0). |
useExtTS | Use an external timestamp (optional, default=false). |
cal | Clock calibration in nanoseconds per clock cycle. Required if useExtTS is true (optional, default=0.0). |
std::runtime_error | If using an external timestamp with an invalid clock calibration (<= 0.0). |
Sets the internal data buffer using setBuffer()
and creates a PHYSICS_EVENT ring item from it. For events with an external timestamp, the user must provide a clock calibration in nanoseconds per clock tick. Otherwise the calibraton is determined from the module type. All exceptions thrown when parsing the hit are raised to the caller.
void DAQ::DDAS::DDASDataSimulator::setBuffer | ( | const ddasfmt::DDASHit & | hit | ) |
Set the data buffer from a DDASHit.
hit | References the hit to process. |
Sets the data buffer based on the size of the hit passed in. Assumes that the input hit data is valid.