Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagecpp
titleuser module registers type
#include "Translator/HdfWriterNew.h"

...
class TestNewHdfWriter : public Module {
public:
  TestNewHdfWriter(std::string moduleName) : Module(moduleName) {}
  virtual void beginJob(Event& evt, Env& env) {
    boost::shared_ptr<Translator::HdfWriterNew> newWriter = 
      boost::make_shared<Translator::HdfWriterNew>(&typeid(MyData), 
                                                   "data", 
                                                   createMyDataHdf5Type, 
                                                   fillMyDataWriteBuffer);
    evt.put(newWriter,"MyDataWriter");
  }
  
  virtual void event(Event& evt, Env& env) {
    boost::shared_ptr<MyData> myData = boost::make_shared<MyData>();
    myData->eventCounter = 11;
    myData->energy = 23.239;
    evt.put(myData,"example");
  }
};

 

...

The special type, HdfWriterNew, has the following arguments:

  •  the C++ std::type_info pointer for the new type being registered (&typeid(MyData) in the example)
  • the name of the dataset ("data")
  • the function that creates the hdf5 type
  • the function that returns the memory buffer for writing

HdfWriterNew also takes an optional fifth argument that users can use to clean up resources.  Since MyData is so simple, their is no need to use this part of the API.  We will create the hdf5 type once, and not worry about closing it.  More complex types may make numerous subtypes along the way, that depend on the object.  If the hdf5 resources created are extensive, the user module will want to close hdf5 resources when they are no longer needed. The create function and optional fifth argument for closing would have to share a persistent structure that indexes these resources and closes them when they are no longer needed.

The key "MyDataWriter" added when putting the newWriter in the event store is not important.  Giving it a distinct name will help with debugging.

The translator, in each calib cycle, will make the following groups (for example in calib cycle 0):

  • /Configure:0000/Run:0000/CalibCycle:0000/MyData/example
    • Note how the C++ type name, MyData, shows up in the path. 
    • Next the 'src' level group is based on the key "example" passed when putting myData in the event store.
  • The dataset: /Configure:0000/Run:0000/CalibCycle:0000/MyData/example/data
    • The name "data" comes from the 2nd parameter to the HdfWriterNew object.
    • The dataset will be a 1D array of the hdf5 compound type with the fields
      • "eventCount"  uint32
      • "energy"  float

Psana Configuration File and all Options

...