RingItemFactoryBase

Name

RingItemFactoryBase -- Provide interface for ring item factoires.

Synopsis


#include <RingItemFactoryBase.h>

class RingItemFactoryBase {
public:
    virtual CRingItem* makeRingItem(uint16_t type, size_t maxBody) = 0;
    virtual CRingItem* makeRingItem(uint16_t type, uint64_t timestamp, uint32_t sourceId,
            size_t maxBody, uint32_t barrierType = 0 ) = 0;
    virtual CRingItem* makeRingItem(const CRingItem& rhs) = 0;
    virtual CRingItem* makeRingItem(const RingItem* pRawRing) = 0;


    virtual CRingItem* getRingItem(CRingBuffer& ringbuf) = 0;
    virtual CRingItem* getRingItem(int fd) = 0;
    virtual CRingItem* getRingItem(std::istream& in) = 0;

    virtual std::ostream& putRingItem(const CRingItem* pItem, std::ostream& out) = 0;
    virtual void putRingItem(const CRingItem* pItem, int fd) = 0;
    virtual void putRingItem(const CRingItem* pItem, CRingBuffer& ringbuf) = 0;

    virtual CAbnormalEndItem* makeAbnormalEndItem() = 0;
    virtual CAbnormalEndItem* makeAbnormalEndItem(const CRingItem& rhs) = 0;

    virtual CDataFormatItem* makeDataFormatItem() = 0;
    virtual CDataFormatItem* makeDataFormatItem(const CRingItem& rhs) = 0;

    virtual CGlomParameters* makeGlomParameters(
        uint64_t interval, bool isBuilding, uint16_t policy
    )  = 0;
    virtual CGlomParameters* makeGlomParameters(const CRingItem& rhs) = 0;

    virtual CPhysicsEventItem* makePhysicsEventItem(size_t maxBody) = 0;
    virtual CPhysicsEventItem* makePhysicsEventItem(
        uint64_t timestamp, uint32_t source, uint32_t barrier, size_t maxBody
    ) = 0;
    virtual CPhysicsEventItem* makePhysicsEventItem(const CRingItem& rhs) = 0;

    virtual CRingFragmentItem* makeRingFragmentItem(
        uint64_t timestamp, uint32_t source, uint32_t payloadSize,
        const void* payload, uint32_t barrier=0
    ) = 0;
    virtual CRingFragmentItem* makeRingFragmentItem(const CRingItem& rhs) = 0;


    virtual CRingPhysicsEventCountItem* makePhysicsEventCountItem(
        uint64_t count, uint32_t timeoffset, time_t stamp,
    int divisor=1
    ) = 0;
    virtual CRingPhysicsEventCountItem* makePhysicsEventCountItem(const CRingItem& rhs) = 0;

    virtual CRingScalerItem* makeScalerItem(size_t numScalers) = 0;
    virtual CRingScalerItem* makeScalerItem(
        uint32_t startTime,
        uint32_t stopTime,
        time_t   timestamp,
        std::vector<uint32_t> scalers,
        bool                  isIncremental = true,
        uint32_t              sid = 0,
        uint32_t              timeOffsetDivisor = 1
    ) = 0;
    virtual CRingScalerItem* makeScalerItem(const CRingItem& rhs) = 0;

    virtual CRingTextItem* makeTextItem(
        uint16_t type,
                std::vector<std::string> theStrings
    ) = 0;
    virtual CRingTextItem* makeTextItem(
        uint16_t type,
                std::vector<std::string> theStrings,
                uint32_t                 offsetTime,
                time_t                   timestamp, uint32_t divisor=1
    ) = 0;
    virtual CRingTextItem* makeTextItem(const CRingItem& rhs) = 0;

    virtual CUnknownFragment* makeUnknownFragment(
        uint64_t timestamp, uint32_t sourceid, uint32_t barrier,
        uint32_t size, void* pPayload
    ) = 0;
    virtual CUnknownFragment* makeUnknownFragment(const CRingItem& rhs) = 0;

    virtual CRingStateChangeItem* makeStateChangeItem(
        uint32_t itemType, uint32_t runNumber,
        uint32_t timeOffset,
        time_t   timestamp,
        std::string title
    ) = 0;
    virtual CRingStateChangeItem* makeStateChangeItem(const CRingItem& rhs) = 0;

};


                

DESCRIPTION

The CRingItemFactoryBase class provides an abstract base class for the ring item factories implemented by version specific libraries. Note that specific return classes defined as forward classes in the header and, therefore, you need to #include the specific ring item classes you need to actually use.

All return values are pointers to dynamically allocated objects. These objects are owned by the caller and must be deleted by the caller when no longer needed. The return pointer types are from the abstract library, however the actual return types from any version specific factory will be objects of the correct version's library.

Since storage management can be difficult, users are encouraged to use these methods to initialize smart pointer objects such as std::unique_ptr or std::shared_ptr to ensure that these objects are, in fact, properly managed.

METHODS

Note that all public methods are pure virtual and must be implemented by any concrete version specific factory.

virtual CRingItem* makeRingItem(uint16_t type, size_t maxBody);

Creates an undifferentiated ring item. The storage should be sufficient to hold maxBody bytes of data. The ring item header should be initialized such that its type is type.

The precise initialization of the remainder of the ring item's storage is implementation dependent.

virtual CRingItem* makeRingItem(uint16_t type, uint64_t timestamp, uint32_t sourceId, size_t maxBody, uint32_t barrierType = 0);

As before but also provides the body header parameters: timestamp, which will be used as the event timestamp in any body header, sourceId which will be used as the item's source id and barrierType which is an optional parameter that specifies the barrier type. This defaults to zero as that's the most common

The implementation of this method shall be equivalent to:


std::auto_ptr<::CRingItem> pItem(fact.makeRingItem(type, maxbody));
pItem->setBodyHeader(timestamp, sourceId, barrierType);
                            

virtual CRingItem* makeRingItem(const CRingItem& rhs);

Makes a new ring item that is a copy of the ring item that is referenced by the rhs.

virtual CRingItem* makeRingItem(const RingItem* pRawRing);

Copies the contents of pRawRing into local storage of a new ringitem object.

virtual CRingItem* getRingItem(CRingBuffer& ringbuf);

Givena reference to an NSCLDAQ CRingBuffer object that is created as a consumer; consumes a raw ring item from that ringbuffer encapsulating it in a CRingItem.

Note that ringbuffers and ring items are such that the actual NSCLDAQ library version used does not matter much in the execution of this method.

If a complete ring item is not yet available for this consumer ringbuf, the calling program will block until one is.

virtual CRingItem* getRingItem(int fd);

Consumes a ring item from the file descriptor fd and wraps it in a new CRingItem object. If the file descriptor is e.g. a pipe and no ring item is available, this will block.

virtual CRingItem* getRingItem(std::istream& in);

Consumes a raw ring item from the stream in wraps it up in a new CRingBuffer class, returning a pointer to that object. If in is e.g. a pipe and no object is available, the program will block until one is seen.

virtual std::ostream& putRingItem(const CRingItem* pItem, std::ostream& out);

Puts the encapsulated ring item pointed to by pItem to the C++ output stream out. A reference to the stream after the output is returned.

The ring itme is output in raw format. This allows getRingItem to reconstruct the ring item.

virtual void putRingItem(const CRingItem* pItem, int fd);

Outputs the ring item pointed to by pItem to whatever the file descriptor fd is open on.

virtual void putRingItem(const CRingItem* pItem, CRingBuffer& ringbuf);

Puts the raw ring item encapsulated in pItem into the ring buffer refrenced by ringbuf. ringbuf must have been created

virtual CAbnormalEndItem* makeAbnormalEndItem()();

Creates an abnormal end ring item type. This is used by versions of NSCLDAQ to flag a run that was not properly ended. If this item type cannot be created nullptr must be returned.

virtual CAbnormalEndItem* makeAbnormalEndItem(const CRingItem& rhs);

Given an undifferentiated ring item reference, rhs, creates the equivalent CAbnormalEndItem. Note that if this is not possible (e.g. because rhs is not an abnormal end item or because the version of NSCLDAQ format in the concrete implementation does not yet support CAbnormalEndItems, std::bad_cast must be thrown.

virtual CDataFormatItem* makeDataFormatItem();

Creates and returns a pointer to a data format item for the format represented by the concrete factory. If the version represented by the concrete factory does not support data format items, this method must return nullptr

virtual CDataFormatItem* makeDataFormatItem(const CRingItem& rhs);

Given an undifferentiated ring item; rhs, an equivalent CDataFormatItem object is created and a pointer to it returned. If rhs is not a data format item, or data format items are not supported by the concreate implementation the implementation must throw std::bad_cast.

virtual CGlomParameters* makeGlomParameters(uint64_t interval, bool isBuilding, uint16_t policy);

Creates and returns a pointer to a CGlomParameters item described by its parameters. If the underlying format does not support glom parameter items, nullptr must be returned.

Glom is the component of the event builder that glues events together from a totally time ordered stream of event fragments. If isBuilding is true, glom is building events and not running in the test mode in which it just emits fragments without bothering to build them. When building, fragments are built if they all fit in the timestamp window defined by interval. The units of this are dependent on the application and simply represent timestamp ticks.

policy is an integer that describes how output event timestamps are created from the fragment timestamps in an event. Constants in DataFormat.h describe the legal values for this parameter which are:

  • GLOM_TIMESTAMP_FIRST - The event timestamp is taken from the timestamp of its first, earliest, fragment.

  • GLOM_TIMESTAMP_LAST - The event timestamp is taken from the timestamp of its last, latest, fragment.

  • GLOM_TIMESTAMP_AVERAGE - the timestamp is computed from the average of all fragment timestamps in the event.

virtual CGlomParameters* makeGlomParameters(const CRingItem& rhs);

If rhs references a glom parameters item returns a newly created, equivalent CGomParameters object's pointer. If rhs is not a glom parameters object or if the concrete implementation does not yet support items of that time, std::bad_cast must be thrown.

virtual CPhysicsEventItem* makePhysicsEventItem(size_t maxBody);

Creates a new physics event item. maxBody sets the maximum size event body that will be filled in. It is used to reserve space into which the ring item will be formatted. The return value is a pointer to a newly created physics event item object.

If the underlying format of the concrete factory supports body headers, this item will not be created with a body header.

virtual CPhysicsEventItem* makePhysicsEventItem(uint64_t timestamp, uint32_t source, uint32_t barrier, size_t maxBody);

Makes a physics event item with a body header (if supported by the concrete format). IF body headers are not supported the implementation should just invoke the prior creational method.

As before, maxBody determines the maximum body size of the item. The remaining parameter determine the contents of the body header: timestamp is the Event/fragment timestamp, source is the Event/fragment source id and barrier is the event/fragment's barrier type.

virtual CPhysicsEventItem* makePhysicsEventItem(const CRingItem& rhs);

Given rhs a reference to a ring item that actually contains a physics event, creates a new ring item of type CPHysicsEventItem that is a functional equivalent of rhs and returns a pointer to that item.

If rhs is not, in fact, a physics event item, this method throws std::bad_cast.

virtual CRingFragmentItem* makeRingFragmentItem( uint64_t timestamp, uint32_t source, uint32_t payloadSize, const void* payload, uint32_t barrier = 0);

A CRingFragmentItem represents an event fragment whose payload is a ring item. The fragment itself looks like a ring item and has an obligatory body header. The body header is followed by a payload which, for this type is assumed to be another ring item.

The contents of the obligatory body header are defined by timestamp, the fragment timestamp, source, the fragment source id and barrier, the optional barrier type. If not provided barrier defaults to zero which is no barrier.

The payload is defined by paylaodSize which is the number of bytes in the payload and payload which points to the payload itself.

The return value is a pointer to a new created CRingFragmentItem. If the concrete factory is of a format that does not support CRingFragmentItem object (does not implement the ring fragment raw ring item), a nullptr must be returned.

virtual CRingFragmentItem* makeRingFragmentItem(const CRingItem& rhs);

If rhs references a CRingItem whose contents are a fragment item, this method creates a new CRingFragmentItem, fills it with the contents of the rhs and returns a pointer to the new item.

If rhs is not a ring fragment item or the version of NSCLDAQ used by the concrete factory does not support CRingFragmentItems, std::bad_cast must be thrown.

virtual CRingPhysicsEventCountItem* makePhysicsEventCountItem(uint64_t count, uint32_t timeoffset, time_t stamp, int divisor = 1);

A physics event count item represents the number of event triggers on a data source. This can be used online analysis programs to know the fraction of the data they are able to analyze.

count is the total number of triggers this run. timeoffset is the time offset into the run at which the number of triggers represents. divisor, if supplied indicates the number of timeoffset ticks in a second. This allows for run offsets to be represented with sub-second resolution. The stamp parameter represents the clock time at which the item was created.

All versions of NSCLDAQ since version 10 (the lowest version we attempt to handle in this library) support event count items.

virtual CRingPhysicsEventCountItem* makePhysicsEventCountItem(const CRingItem& rhs);

If the contents of rhs are a physics event count raw item, this method creates a new CRingPhysicsEventCountItem object to wrap a copy of the item in rhs and returns a pointer to that object.

If rhs is not encapsulating an event count item; std::bad_cast is thrown.

virtual CRingScalerItem* makeScalerItem(size_t numScalers);

Creates a new scaler item and returns a pointer to it. Object methods can be used to modify the contents of the item. The item is sized for numScalers 32 bit scalers. The clock timestamp for the item is its creation time. The counting interval is initialized to from zero to zero and the time divisor is initialized to 1.

For formats that support a body header, this item should be created with no body header. A full body header can, of course, be added with the object's setBodyHeader.

virtual CRingScalerItem* makeScalerItem(uint32_t startTime, uint32_t stopTime, time_t timestamp, std::vector<uint32_t> scalers, bool isIncremental = true, uint32_t sid = 0, uint32_t timeOffsetDivisor = 1);

Constructs a scaler item and returns a pointer to it. The startTime and stopTime parameters provide the offset into the run at which the counting interval started and ended. The divisor provides the number of ticks per second for both of these parameters.

scalers is the array of scaler values. isIncremental indicates if the scalers were zeroed after the read.

For versions that support an original source id, sid provides this value. This allows event built data to track the source id of the emitter of this item even as Glom rewrites the body header source id.

See concrete implementations for information about how, if at all, the implementation fills in a body header for the item.

virtual CRingScalerItem* makeScalerItem(const CRingItem& rhs);

If rhs encapsulates a raw scaler item a new CRingScalerItem is created and the data in rhs are copied into the new item. A pointer to that new item is returned.

If rhs does not represent scaler data, std::bad_cast is thrown.

virtual CRingTextItem* makeTextItem(uint16_t type, std::vector<std::string> theStrings);

Creates a ring item that contains a set of strings. The type parameter contains the type of the ring item (type field of ring item header). The possible values for this are in DataFormat.h and can be:

  • PACKET_TYPES describes the set of packet data types physics event bodies may have.

  • MONITORED_VARIABLES Contains a set of variable names and values as Tcl scriptlets that would set those variables to their values.

theStrings contains the strings to put in the payload section of the body.

Timing information in the bodiesof this ring item type are initialized as follows: The run offset time is zero, The clock timestamp is the creation time of the object and the offset divisor is 1.

virtual CRingTextItem* makeTextItem( uint16_t type, std::vector<std::string> theStrings, uint32_t offsetTime, time_t timestamp, uint32_t divisor = 1);

Creates an item with a list of text strings encapsulates it in a CRingTextItem and returns a pointer to the resulting item. As before, type is the ring item type and theStrings are the text strings to store in the ring item.

Additional parameters provide time information. offsetTime is the offset into the run while divisor is the number of counts in offsetTime per second. timestamp is the clock time that will tag the item.

virtual CRingTextItem* makeTextItem(const CRingItem& rhs);

Given that rhs encapsulates a ring text item, this method creates a new CRingTextItem, copies the raw ring item encapsulated by rhs and returns a pointer to that new CRingTextItem.

If the ring item type of rhs makes it clear that this is not a valid text item, a std::bad_cast will be thrown.

virtual CUnknownFragment* makeUnknownFragment(uint64_t timestamp, uint32_t sourceid, uint32_t barrier, uint32_t size, void* pPayload);

This method is the same as makeRingFragmentItem but the payload is not assumed to be a ring item. While ring fragment items have type EVB_FRAGMENT, these have type EVB_UNKNOWN_PAYLOAD

virtual CUnknownFragment* makeUnknownFragment(const CRingItem& rhs);

Again see makeRingFragmentItem.

virtual CRingStateChangeItem* makeStateChangeItem(uint32_t itemType, uint32_t runNumber, uint32_t timeOffset, time_t timestamp, std::string title);

Creates a new state change ring item wrapping it in a CRingStateChangeItem and returning a pointer to the new object.

The itemType parameter provides the exact state change reason. Its possible values are defined in DataFormat.h and are: BEGIN_RUN, PAUSE_RUN, RESUME_RUN, and END_RUN with obvious (I hope) meanings.

runNumber provides the run number of the run having the transition, and title its title string. timeOffset provides the time offset into the run while timestamp is intended to provide an absolute clock time at which the transtion occured.

virtual CRingStateChangeItem* makeStateChangeItem(const CRingItem& rhs);

If rhs is a CRingItem that is wrapping a state change raw ring item, this method creates a new CRingStateChangeItem, wraps a copy of the raw ring item in rhs and returns a pointer to the new item to the caller. If rhs is not a valid state change item, std::bad_cast is thrown.