Draft, in work.
The DAQ Side: Generating Xtc
For tutorial purposes, the following streamlined example shows XXX. For an example involving more detectors, formats and algorithms, see xtcdata/xtcdata/app/xtcwriter.cc.
A Notional DAQ Harness
Let's motivate the example. Assume we're developing a an Xtc writer class to output HSD data. This class will get plugged in to a (notional) DAQ framework.
# Assume some totally made-up data acquisition callback framework named DAQFramework # Developers of the psdaq package are welcome to come in and change this toy example # to match the real DAQ API. HSDXtcWriter hsdwriter() DAQFramework.registerHandler("configure", hsdwriter.setup) DAQFramework.registerHandler("runstart", std::bind(hsdwriter.openXtcFile, filename)) DAQFramework.registerHandler("readout", hsdwriter.writeImage) DAQFramework.registerHandler("runend", hsdwriter.closeXtcFile)
"setup" Method: Set Up The Names Structure
Register the algorithms and "shape" of the data associated with detector elements so the processing pipeline knows what to do with it.
- First some plumbing...
- Create an XtcData:Dgram as the root container. %codesample1:1-11%
- Next code sample summary.
At some initialization step, for example in response to a DAQ configure signal:
- Subclass XtcData::VarDef to build a data structure specific to the detector in question.
"writeImage" Method: Add Readout Data
(Introduce CreateData and its set_value (assign values explicitly) and allocate (set aside structured memory for the data then full in the structure with values) here. Assume that the data coming out has a well-defined shape, i.e. definable as a record like the FexDef object, so per-event, you will update and emit this data record into the output stream)
Another list of steps/big ideas this time about appending data.
- .
- A chunk of code summary.
At some initialization step, for example in response to a DAQ configure signal:
- Subclass XtcData::VarDef to build a data structure specific to the detector in question.
The Pipeline Side: Parsing Whole Xtc Files, Using Small Data Files
xtcreader.cc and XtcIterator.hh
A Notional Offline Pipeline Harness
Notes for Real-World Code
Realistic Xtc Writers
(Bullet lists of gotchas and recommendations)
- Thread safety issue #1
- Thread safety issue #2
- (You'll likely need to sub-class from XYZ in order to ABC)
Realistic Xtc Readers
(Bullet lists of gotchas and recommendations)
- Thread safety issue #1
- Thread safety issue #2
- (You'll likely need to sub-class from XYZ in order to ABC)
Full "Hello Xtc" Code Listings
HSDXtcWriter Example
// @sample:codesample1 #include "xtcdata/xtc/ShapesData.hh" #include "xtcdata/xtc/DescData.hh" #include "xtcdata/xtc/Dgram.hh" #include "xtcdata/xtc/TypeId.hh" #include "xtcdata/xtc/XtcIterator.hh" #include "xtcdata/xtc/VarDef.hh" using namespace XtcData; #define BUFSIZE 0x4000000 HSDXtcWriter::HSDXtcWriter() { // Squirrel away algorithm definitions in a VarDef class FexDef:public VarDef { public: enum index { floatFex, arrayFex, intFex }; FexDef() { NameVec.push_back({"floatFex",Name::DOUBLE}); NameVec.push_back({"arrayFex",Name::FLOAT,2}); NameVec.push_back({"intFex",Name::INT64}); } }; // Define some instance variables. FILE *this->xtcoutfile; Dgram& this->configDgram; std::vector<NameIndex>& this->namesVec; this->FexDef = new FexDef(); // Now initialize various things _initializeConfigDgram(); } void HSDXtcWriter::_initializeConfigDgram() { TypeId tid(TypeId::Parent, 0); void* configbuf = malloc(BUFSIZE); this->configDgram = *(Dgram*)configbuf; this->configDgram.xtc.contains = tid; this->configDgram.xtc.damage = 0; this->configDgram.xtc.extent = sizeof(Xtc); } void HSDXtcWriter::_addNames(Xtc& parent, std::vector<NameIndex>& namesVec) { // Use Alg to define metadata for a feature extraction ("fex") algorithm Alg hsdFexAlg("fex",4,5,6); Names& this->fexNames = *new(parent) Names("xpphsd", hsdFexAlg, "hsd","detnum1234") this->fexNames.add(parent, this->FexDef); namesVec.push_back(NameIndex(this->fexNames)); } void HSDXtcWriter::setup() { // Add a Names structure to the configuration Dgram _addNames(this->configDgram.xtc, this->namesVec); } void HSDXtcWriter::openXtcFile(xtcoutfilename) { this->xtcoutfile = fopen(xtcoutfilename, "w"); } void HSDXtcWriter::writeImage() { } void HSDXtcWriter::closeXtcFile() { fclose(this->xtcoutfile); }