lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
XtcData::XtcUpdateIter Class Reference

XtcIterator that copies Names and ShapesData xtcs into an output buffer (setOutput()), dropping ShapesData whose detName_algName key is filtered, and records Names in its own NamesLookup. More...

#include <XtcUpdateIter.hh>

Inherits XtcData::XtcIterator.

Public Types

enum  { Stop , Continue }
 Return values of process(). More...
 

Public Member Functions

 XtcUpdateIter (unsigned numWords)
 Store numWords (passed by get_value() to the array dump helper) and zero the counters and flags; the NamesId range trackers start at 0 and 255.
 
 ~XtcUpdateIter ()
 Destructor; does nothing.
 
virtual int process (XtcData::Xtc *xtc, const void *bufEnd)
 Iterate into Parent xtcs.
 
void get_value (int i, Name &name, DescData &descdata)
 Print field i of descdata to stdout: scalars as 'name': value, CHARSTR arrays as a quoted string.
 
unsigned getSize ()
 Return the size set by the last copyParent(): sizeof(Dgram) plus the bytes copied to the output buffer before that call.
 
uint32_t getRemovedSize ()
 Return the bytes of filtered ShapesData skipped by process() since the last copyParent().
 
unsigned getNodeId ()
 Return the node id of the last Names xtc seen by process() (0 initially).
 
unsigned getNextNamesId ()
 Increment the lower-range NamesId tracker and return its new value.
 
void setCfgFlag (int cfgFlag)
 Set the cfg flag.
 
void setCfgWriteFlag (int cfgWriteFlag)
 Set the cfg-write flag.
 
void setOutput (char *outbuf)
 Set the output buffer.
 
int isConfig ()
 Return the cfg flag set by setCfgFlag().
 
void addNames (Xtc &xtc, const void *bufEnd, char *detName, char *detType, char *detId, unsigned nodeId, unsigned namesId, unsigned segment, char *algName, uint8_t major, uint8_t minor, uint8_t micro, DataDef &datadef)
 Append to xtc a Names xtc built from detName, detType, detId, segment, NamesId(nodeId, namesId) and Alg(algName, major, minor, micro), add one Name per datadef entry, and store its NameIndex in the internal NamesLookup.
 
void setString (char *data, DataDef &datadef, char *varname)
 Call set_string() on the CreateData from the last createData() call for field datadef.index(varname), with data as the string.
 
void setValue (unsigned nodeId, unsigned namesId, char *data, DataDef &datadef, char *varname)
 Read a scalar of the field's DataType from data and append it with set_value() to the CreateData from the last createData() call.
 
void addData (unsigned nodeId, unsigned namesId, unsigned *shape, char *data, DataDef &datadef, char *varname)
 Allocate array field datadef.index(varname) with the given shape in the current CreateData (allocate<T>()) and copy Shape(shape).size(name) bytes from data into it.
 
Dgram & createTransition (unsigned transId, bool counting_timestamps, uint64_t timestamp_val, char *buf)
 Placement-construct at buf a Dgram of type Event with transition id transId, env low bits 0 and an empty Parent xtc, and return it.
 
void createData (Xtc &xtc, const void *bufEnd, unsigned nodeId, unsigned namesId)
 Create a CreateData for NamesId(nodeId, namesId) that appends a new ShapesData to xtc, using the internal NamesLookup, and keep it in a unique_ptr.
 
void updateTimeStamp (Dgram &d, uint64_t timestamp_val)
 Set d.time to TimeStamp(timestamp_val): low 32 bits nanoseconds, high 32 bits seconds.
 
void updateService (Dgram &d, uint8_t transtionId)
 Replace bits 27:24 of d.env with transtionId, which is shifted left by 24 and ORed in, so values above 15 also set bits in 31:28.
 
void updateDamage (Dgram &d, uint16_t damage)
 Set d.xtc.damage to damage.
 
int getElementSize (unsigned nodeId, unsigned namesId, DataDef &datadef, char *varname)
 Return Name::get_element_size() of field datadef.index(varname) in the Names for NamesId(nodeId, namesId).
 
void copyParent (Dgram *parent_d)
 Copy the Dgram header parent_d to the start of the output buffer, set getSize() to sizeof(Dgram) plus the bytes copied so far, reset the copied and removed byte counts, and clear all filter flags.
 
void copyPayload (char *in_buf, unsigned in_size)
 Copy in_size bytes from in_buf into the output buffer after sizeof(Dgram) plus the bytes already copied, and add in_size to that count.
 
void setFilter (char *detName, char *algName)
 Set the filter flag of the existing key detName_algName to 1, so process() drops matching ShapesData; unknown keys are ignored.
 
void clearFilter ()
 Reset all filter flags to 0.
 
- Public Member Functions inherited from XtcData::XtcIterator
 XtcIterator (Xtc *root, const void *bufEnd)
 Store root and bufEnd for use by iterate().
 
 XtcIterator ()
 Default constructor; root and bufEnd are left uninitialized (use iterate(Xtc*, const void*)).
 
virtual ~XtcIterator ()
 Virtual destructor; does nothing.
 
void iterate ()
 Call iterate(root, bufEnd) with the values given to the constructor.
 
void iterate (Xtc *, const void *bufEnd)
 Call process() on each child xtc in root's payload, in order, until process() returns 0 or the payload is used up.
 
const Xtc * root () const
 Return the root xtc given to the constructor.
 

Detailed Description

XtcIterator that copies Names and ShapesData xtcs into an output buffer (setOutput()), dropping ShapesData whose detName_algName key is filtered, and records Names in its own NamesLookup.

It also has helpers to add Names and ShapesData and to create or edit Dgram headers.

Member Enumeration Documentation

◆ anonymous enum

Return values of process().

XtcIterator::iterate() stops when process() returns 0 (Stop).

Enumerator
Stop 

Value 0: stop iterating.

Continue 

Value 1: keep iterating.

Constructor & Destructor Documentation

◆ XtcUpdateIter()

XtcData::XtcUpdateIter::XtcUpdateIter ( unsigned  numWords)
inline

Store numWords (passed by get_value() to the array dump helper) and zero the counters and flags; the NamesId range trackers start at 0 and 255.

The output buffer is not set.

◆ ~XtcUpdateIter()

XtcData::XtcUpdateIter::~XtcUpdateIter ( )
inline

Destructor; does nothing.

Member Function Documentation

◆ addData()

void XtcData::XtcUpdateIter::addData ( unsigned  nodeId,
unsigned  namesId,
unsigned *  shape,
char *  data,
DataDef &  datadef,
char *  varname 
)

Allocate array field datadef.index(varname) with the given shape in the current CreateData (allocate<T>()) and copy Shape(shape).size(name) bytes from data into it.

T follows the field's DataType in the Names for NamesId(nodeId, namesId); ENUMVAL and ENUMDICT only print a "not handled" message.

◆ addNames()

void XtcData::XtcUpdateIter::addNames ( Xtc &  xtc,
const void *  bufEnd,
char *  detName,
char *  detType,
char *  detId,
unsigned  nodeId,
unsigned  namesId,
unsigned  segment,
char *  algName,
uint8_t  major,
uint8_t  minor,
uint8_t  micro,
DataDef &  datadef 
)

Append to xtc a Names xtc built from detName, detType, detId, segment, NamesId(nodeId, namesId) and Alg(algName, major, minor, micro), add one Name per datadef entry, and store its NameIndex in the internal NamesLookup.

The Names/Name constructors and Xtc::alloc() abort on invalid names or if bufEnd would be passed.

◆ clearFilter()

void XtcData::XtcUpdateIter::clearFilter ( )

Reset all filter flags to 0.

◆ copyParent()

void XtcData::XtcUpdateIter::copyParent ( Dgram *  parent_d)

Copy the Dgram header parent_d to the start of the output buffer, set getSize() to sizeof(Dgram) plus the bytes copied so far, reset the copied and removed byte counts, and clear all filter flags.

The copied header's extent is not changed.

◆ copyPayload()

void XtcData::XtcUpdateIter::copyPayload ( char *  in_buf,
unsigned  in_size 
)

Copy in_size bytes from in_buf into the output buffer after sizeof(Dgram) plus the bytes already copied, and add in_size to that count.

There is no bounds check.

◆ createData()

void XtcData::XtcUpdateIter::createData ( Xtc &  xtc,
const void *  bufEnd,
unsigned  nodeId,
unsigned  namesId 
)

Create a CreateData for NamesId(nodeId, namesId) that appends a new ShapesData to xtc, using the internal NamesLookup, and keep it in a unique_ptr.

Replacing a previous CreateData runs its destructor, which aborts if it did not receive all its fields.

◆ createTransition()

Dgram & XtcData::XtcUpdateIter::createTransition ( unsigned  transId,
bool  counting_timestamps,
uint64_t  timestamp_val,
char *  buf 
)

Placement-construct at buf a Dgram of type Event with transition id transId, env low bits 0 and an empty Parent xtc, and return it.

The time is TimeStamp(timestamp_val) if counting_timestamps; otherwise gettimeofday() seconds, with the microsecond count stored unscaled in the nanoseconds word.

◆ get_value()

void XtcData::XtcUpdateIter::get_value ( int  i,
Name &  name,
DescData &  descdata 
)

Print field i of descdata to stdout: scalars as 'name': value, CHARSTR arrays as a quoted string.

Other arrays go to a dump helper that prints nothing because VERBOSE is 0 in XtcUpdateIter.cc.

◆ getElementSize()

int XtcData::XtcUpdateIter::getElementSize ( unsigned  nodeId,
unsigned  namesId,
DataDef &  datadef,
char *  varname 
)

Return Name::get_element_size() of field datadef.index(varname) in the Names for NamesId(nodeId, namesId).

◆ getNextNamesId()

unsigned XtcData::XtcUpdateIter::getNextNamesId ( )
inline

Increment the lower-range NamesId tracker and return its new value.

Prints a message and throws a const char* if the new value equals the upper-range tracker.

◆ getNodeId()

unsigned XtcData::XtcUpdateIter::getNodeId ( )
inline

Return the node id of the last Names xtc seen by process() (0 initially).

◆ getRemovedSize()

uint32_t XtcData::XtcUpdateIter::getRemovedSize ( )
inline

Return the bytes of filtered ShapesData skipped by process() since the last copyParent().

◆ getSize()

unsigned XtcData::XtcUpdateIter::getSize ( )
inline

Return the size set by the last copyParent(): sizeof(Dgram) plus the bytes copied to the output buffer before that call.

◆ isConfig()

int XtcData::XtcUpdateIter::isConfig ( )
inline

Return the cfg flag set by setCfgFlag().

◆ process()

virtual int XtcData::XtcUpdateIter::process ( XtcData::Xtc *  xtc,
const void *  bufEnd 
)
virtual

Iterate into Parent xtcs.

For Names: store a NameIndex, add its detName_algName filter key (flag 0), record its node id, update the NamesId range trackers, and copy it to the output buffer if the cfg-write flag is 1. For ShapesData (throws a const char* if its NamesId has no Names): if the cfg flag is 1, copy it only when the cfg-write flag is 1; otherwise copy it unless its key is filtered, in which case add its size to the removed size.

Returns
Always Continue.

Implements XtcData::XtcIterator.

◆ setCfgFlag()

void XtcData::XtcUpdateIter::setCfgFlag ( int  cfgFlag)
inline

Set the cfg flag.

When it is 1, process() copies ShapesData only if the cfg-write flag is 1 and ignores filters; the member comment says it marks a Configure datagram.

◆ setCfgWriteFlag()

void XtcData::XtcUpdateIter::setCfgWriteFlag ( int  cfgWriteFlag)
inline

Set the cfg-write flag.

When it is 1, process() copies Names xtcs (and, with the cfg flag, ShapesData) to the output buffer.

◆ setFilter()

void XtcData::XtcUpdateIter::setFilter ( char *  detName,
char *  algName 
)

Set the filter flag of the existing key detName_algName to 1, so process() drops matching ShapesData; unknown keys are ignored.

◆ setOutput()

void XtcData::XtcUpdateIter::setOutput ( char *  outbuf)
inline

Set the output buffer.

copyPayload() writes after its first sizeof(Dgram) bytes and copyParent() writes the Dgram header at its start.

◆ setString()

void XtcData::XtcUpdateIter::setString ( char *  data,
DataDef &  datadef,
char *  varname 
)

Call set_string() on the CreateData from the last createData() call for field datadef.index(varname), with data as the string.

◆ setValue()

void XtcData::XtcUpdateIter::setValue ( unsigned  nodeId,
unsigned  namesId,
char *  data,
DataDef &  datadef,
char *  varname 
)

Read a scalar of the field's DataType from data and append it with set_value() to the CreateData from the last createData() call.

The field is datadef.index(varname) in the Names for NamesId(nodeId, namesId); CHARSTR, ENUMVAL and ENUMDICT only print a "not handled" message.

◆ updateDamage()

void XtcData::XtcUpdateIter::updateDamage ( Dgram &  d,
uint16_t  damage 
)

Set d.xtc.damage to damage.

◆ updateService()

void XtcData::XtcUpdateIter::updateService ( Dgram &  d,
uint8_t  transtionId 
)

Replace bits 27:24 of d.env with transtionId, which is shifted left by 24 and ORed in, so values above 15 also set bits in 31:28.

◆ updateTimeStamp()

void XtcData::XtcUpdateIter::updateTimeStamp ( Dgram &  d,
uint64_t  timestamp_val 
)

Set d.time to TimeStamp(timestamp_val): low 32 bits nanoseconds, high 32 bits seconds.


The documentation for this class was generated from the following file: