You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 121 Next »

Draft, in work.

Topics

Go back to the Top of this tree.

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

CSPADXtcWriter padwriter()

DAQFramework.registerHandler("configure", padwriter.setup)
DAQFramework.registerHandler("runstart", std::bind(padwriter.openXtcFile, filename))
DAQFramework.registerHandler("readout", padwriter.writeImage)
DAQFramework.registerHandler("runend", padwriter.closeXtcFile)

"setup" Method: Set Up The Names Structure

    Register the algorithms and "shape" of the data associated with detector elements to tell the processing pipeline what to do with it.

    1. First some plumbing...
      1. Create an XtcData:Dgram as the root container.
    2. 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

      Another list of steps/big ideas this time about appending data.

      1. A chunk of code summary.
      2. 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.

      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

      CSPADXtcWriter Example

      #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
      
      CSPADXtcWriter::CSPADXtcWriter()
      {
      	// Squirrel away algorithm definitions in a VarDef
      	class PadDef:public VarDef
      	{
      		enum index
      			{
      				arrayRaw
      			};
      
      		PadDef()
      			{
      				Alg segmentAlg("caspadseg",2,3,42); // alg name, major, minor, patch)	
      				// We get a NameVec by subclassing from VarDef
      				NameVec.push_back({"arrayRaw", segmentAlg});
      			}
      	
      	};
      
      	// Define some instance variables.
      	FILE *this->xtcoutfile;
      	Dgram& this->configDgram;
      	std::vector<NameIndex>& this->namesVec;
      	this->PadDef = new PadDef();
      
      	// Now initialize various things
      	_initializeConfigDgram();
       }
      
      void CSPADXtcWriter::_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 CSPADWriter::_addNames(Xtc& parent, std::vector<NameIndex>& namesVec)
      {
      	
      }
      
      void CSPADXtcWriter::setup()
      {
      	_addNames(this->configDgram.xtc, this->namesVec);
      }
      
      void CSPADXtcWriter::openXtcFile(xtcoutfilename)
      {
      	this->xtcoutfile = fopen(xtcoutfilename, "w");
      }
      
      void CSPADXtcWriter::writeImage()
      {
      
      
      }
      
      void CSPADXtcWriter::closeXtcFile()
      {
      	fclose(this->xtcoutfile);
      }

       

       

       

      • No labels