NSCL DDAS  12.1-001
Support for XIA DDAS at FRIB
Public Member Functions | List of all members
DAQ::DDAS::DDASDataSimulator Class Reference

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...
 

Detailed Description

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:

Example code to create a complete run with a single event:

#include <DDASHit.h>
using namespace DAQ::DDAS;
using namespace ddasfmt;
int main () {
DDASDataSimulator sim("data.evt", 12);
DDASHit hit;
sim.beginRun();
hit.setModMSPS(250);
hit.setCrateID(0);
hit.setSlotID(2);
hit.setChannelID(0);
hit.setEnergy(1000);
hit.setTime(1234.5678);
sim.putHit(hit);
sim.endRun();
return 0;
}
Defines a class to simulate DDAS data recored by NSCLDAQ readout.
DDASDataSimulator(std::string fname, int version)
Constructor.
Definition: DDASDataSimulator.cpp:85
Definition: RootFileDataSink.h:31
int main(int argc, char *argv[])
QtScope main.
Definition: qtscope.cpp:27

Constructor & Destructor Documentation

◆ DDASDataSimulator()

DAQ::DDAS::DDASDataSimulator::DDASDataSimulator ( std::string  fname,
int  version 
)

Constructor.

Parameters
fnameOutput file name.
versionNSLCDAQ 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.

Member Function Documentation

◆ beginRun()

void DAQ::DDAS::DDASDataSimulator::beginRun ( )

Begin a simulated run.

Exceptions
CErrnoExecptionIf the output file isn't opened properly.

On begin:

  • Open an output data file for writing.
  • Save the run start time.
  • Write a format item to the output file.
  • Write the begin run item to the output file.

◆ dumpBuffer()

void DAQ::DDAS::DDASDataSimulator::dumpBuffer ( )

Formatted dump of data buffer to stdout.

◆ endRun()

void DAQ::DDAS::DDASDataSimulator::endRun ( )

End a simulated run.

Exceptions
CErrnoExecptionIf the output file isn't closed properly.

On end:

  • Set the run stop time.
  • Calculates an elapsed run time based on the start time set during beginRun(). The elapsed run time will be nonsense if the start time is not set by calling beginRun() prior to this function.
  • Writes an end run item to the output file.
  • Closes the output file.

◆ getBuffer()

std::vector<uint32_t> DAQ::DDAS::DDASDataSimulator::getBuffer ( )
inline

Get the data buffer.

Returns
The data buffer. May or may not be empty, depending on whether setBuffer() is called first.

◆ putHit()

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.

Parameters
hitReferences the hit to write.
sourceIDThe source ID value (optional, default=0).
useExtTSUse an external timestamp (optional, default=false).
calClock calibration in nanoseconds per clock cycle. Required if useExtTS is true (optional, default=0.0).
Exceptions
std::runtime_errorIf 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.

◆ setBuffer()

void DAQ::DDAS::DDASDataSimulator::setBuffer ( const ddasfmt::DDASHit &  hit)

Set the data buffer from a DDASHit.

Parameters
hitReferences 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.


The documentation for this class was generated from the following files: