Chapter 3. Writing ring items to a data sink

In this chapter we're going to show how to write NSCL DAQ data. NSCLDAQ data is composed of ring items. A ring item is a payload of data preceded by a header. This header, called the \ ring item header has a self inclusive size and a ring item type. Furthermore, since NSCLDAQ 11.0, the payload of most ring items contains a body header. The body header was introduced to make event building easier. It holds information like timestamps, source ids and barrier types used by the event builder to sort fragments and glue them together into events.

As before, this chapter consists of two parts. The first part, Background provides some background information on the important library classes our program will use. Note that we assume you've mastered the previous chapter and will not re-introduce the classes used there. The code presents the code and explanation.

The code and Makefile for this example are in $DAQROOT/share/recipes/writerings.

3.1. Background

In addition to the NSCLDAQ library classes we used in the ring reading program, we are going to use additional classes designed to make writing ring items easy. Just as the data source classes and factory support reading ring items from a data source, data sink classes and a factory support writing ring items to a sink of ring items.

CDataSink

This is an abstract base class for all ring item sinks. A ring item sink is an object that can be given a stream of ring items and will dispose of them to some consumer.

CFileDataSink

A data sink that writes ring items to a file descriptor.

CRingDataSink

A data sink that puts ring items into a ring buffer.

As with data sources, there is a factory, CDataSinkFactory, that will generate the right type of data sink given a URI. URI's can have either file: protocol to write ring items to file or tcp: protocols to write ring items to a ring buffers.

Note that since you can only write ring items to a local ring buffer the host part of a tcp: URI must be either empty or localhost. The factor can also accept the special string - to create a data sink that's connected to the program's standard output. This allows you to use the techniques described in this chapter to build filters or pipeline elements.