evio
6.0
|
This class is used for creating and manipulating events. More...
#include <EventBuilder.h>
Public Member Functions | |
EventBuilder (uint16_t tag, DataType const dataType, uint8_t num) | |
This is the constructor to use for an EventBuilder object that will operate on a new, empty event. More... | |
EventBuilder (std::shared_ptr< EvioEvent > &event) | |
This is the constructor to use when you want to manipulate an existing event. More... | |
void | setAllHeaderLengths () |
This goes through the event recursively, and makes sure all the length fields in the headers are properly set. More... | |
void | clearData (std::shared_ptr< BaseStructure > structure) |
This clears all the data fields in a structure, but not the parent or the children. More... | |
void | addChild (std::shared_ptr< BaseStructure > parent, std::shared_ptr< BaseStructure > child) |
Add a child to a parent structure. More... | |
void | remove (std::shared_ptr< BaseStructure > child) |
This removes a structure (and all its descendants) from the tree. More... | |
void | setIntData (std::shared_ptr< BaseStructure > structure, int32_t *data, size_t count) |
Set int data in the structure. More... | |
void | setUIntData (std::shared_ptr< BaseStructure > structure, uint32_t *data, size_t count) |
Set unsigned int data in the structure. More... | |
void | setShortData (std::shared_ptr< BaseStructure > structure, int16_t *data, size_t count) |
Set short data in the structure. More... | |
void | setUShortData (std::shared_ptr< BaseStructure > structure, uint16_t *data, size_t count) |
Set unsigned short data in the structure. More... | |
void | setLongData (std::shared_ptr< BaseStructure > structure, int64_t *data, size_t count) |
Set long data in the structure. More... | |
void | setULongData (std::shared_ptr< BaseStructure > structure, uint64_t *data, size_t count) |
Set unsigned long data in the structure. More... | |
void | setCharData (std::shared_ptr< BaseStructure > structure, char *data, size_t count) |
Set char data in the structure. More... | |
void | setUCharData (std::shared_ptr< BaseStructure > structure, unsigned char *data, size_t count) |
Set unsigned char data in the structure. More... | |
void | setFloatData (std::shared_ptr< BaseStructure > structure, float *data, size_t count) |
Set float data in the structure. More... | |
void | setDoubleData (std::shared_ptr< BaseStructure > structure, double *data, size_t count) |
Set double data in the structure. More... | |
void | setStringData (std::shared_ptr< BaseStructure > structure, std::string *data, size_t count) |
Set string data in the structure. More... | |
void | setCompositeData (std::shared_ptr< BaseStructure > structure, std::shared_ptr< CompositeData > *data, size_t count) |
Set composite data in the structure. More... | |
void | appendIntData (std::shared_ptr< BaseStructure > structure, int32_t *data, size_t count) |
Append int data to the structure. More... | |
void | appendUIntData (std::shared_ptr< BaseStructure > structure, uint32_t *data, size_t count) |
Append unsigned int data to the structure. More... | |
void | appendShortData (std::shared_ptr< BaseStructure > structure, int16_t *data, size_t count) |
Append short data to the structure. More... | |
void | appendUShortData (std::shared_ptr< BaseStructure > structure, uint16_t *data, size_t count) |
Append unsigned short data to the structure. More... | |
void | appendLongData (std::shared_ptr< BaseStructure > structure, int64_t *data, size_t count) |
Append long data to the structure. More... | |
void | appendULongData (std::shared_ptr< BaseStructure > structure, uint64_t *data, size_t count) |
Append unsigned long data to the structure. More... | |
void | appendCharData (std::shared_ptr< BaseStructure > structure, char *data, size_t count) |
Append char data to the structure. More... | |
void | appendUCharData (std::shared_ptr< BaseStructure > structure, unsigned char *data, size_t count) |
Append unsigned char data to the structure. More... | |
void | appendFloatData (std::shared_ptr< BaseStructure > structure, float *data, size_t count) |
Append float data to the structure. More... | |
void | appendDoubleData (std::shared_ptr< BaseStructure > structure, double *data, size_t count) |
Append double data to the structure. More... | |
void | appendStringData (std::shared_ptr< BaseStructure > structure, std::string *data, size_t count) |
Append string data to the structure. More... | |
void | appendCompositeData (std::shared_ptr< BaseStructure > structure, std::shared_ptr< CompositeData > *data, size_t count) |
Append string data to the structure. More... | |
std::shared_ptr< EvioEvent > | getEvent () |
Get the underlying event. More... | |
void | setEvent (std::shared_ptr< EvioEvent > &ev) |
Set the underlying event. More... | |
Static Public Member Functions | |
static int | main (int argc, char **argv) |
Main program for testing. More... | |
This class is used for creating and manipulating events.
One constructor is convenient for creating new events while another is useful for manipulating existing events. You can create a new EventBuilder for each event being handled; however, in many cases one can use the same EventBuilder for all events by calling the setEvent method. The only reason a singleton pattern was not used was to allow for the possibility that events will be built or manipulated on multiple threads.
evio::EventBuilder::EventBuilder | ( | uint16_t | tag, |
DataType const | dataType, | ||
uint8_t | num | ||
) |
This is the constructor to use for an EventBuilder object that will operate on a new, empty event.
tag | the tag for the event header (which is just a bank header). |
dataType | the data type for the event object–which again is just the type for the outer most bank. Often an event is a bank of banks, so typically this will be DataType.BANK, or 0xe (14). |
num | often an ordinal enumeration. |
References evio::EvioEvent::getInstance().
evio::EventBuilder::EventBuilder | ( | std::shared_ptr< EvioEvent > & | ev | ) |
This is the constructor to use when you want to manipulate an existing event.
ev | the event to manipulate. |
void evio::EventBuilder::addChild | ( | std::shared_ptr< BaseStructure > | parent, |
std::shared_ptr< BaseStructure > | child | ||
) |
Add a child to a parent structure.
parent | the parent structure. |
child | the child structure. |
EvioException | if parent or child is null, child has wrong byte order, is wrong structure type, or parent is not a container |
References evio::DataType::ALSOBANK, evio::DataType::ALSOSEGMENT, evio::DataType::BANK, evio::DataType::getDataType(), evio::DataType::getName(), evio::DataType::isStructure(), evio::DataType::SEGMENT, setAllHeaderLengths(), evio::StructureType::STRUCT_BANK, evio::StructureType::STRUCT_SEGMENT, evio::StructureType::STRUCT_TAGSEGMENT, and evio::DataType::TAGSEGMENT.
Referenced by main().
void evio::EventBuilder::appendCharData | ( | std::shared_ptr< BaseStructure > | structure, |
char * | data, | ||
size_t | count | ||
) |
Append char data to the structure.
If the structure has no data, then this is the same as setting the data (except the the data type may not be changed).
structure | the structure to receive the data. |
data | pointer to data (array of chars) to append. |
count | number of chars to append. |
EvioException | if structure or data arg(s) is null, data type is not char. |
References evio::DataType::CHAR8, and setAllHeaderLengths().
void evio::EventBuilder::appendCompositeData | ( | std::shared_ptr< BaseStructure > | structure, |
std::shared_ptr< CompositeData > * | data, | ||
size_t | count | ||
) |
Append string data to the structure.
If the structure has no data, then this is the same as setting the data (except the the data type may not be changed).
structure | the structure to receive the data. |
data | pointer to data (array of string) to append. |
count | number of strings to append. |
EvioException | if structure or data arg(s) is null, data type is not string. |
References evio::DataType::COMPOSITE, and setAllHeaderLengths().
void evio::EventBuilder::appendDoubleData | ( | std::shared_ptr< BaseStructure > | structure, |
double * | data, | ||
size_t | count | ||
) |
Append double data to the structure.
If the structure has no data, then this is the same as setting the data (except the the data type may not be changed).
structure | the structure to receive the data. |
data | pointer to data (array of doubles) to append. |
count | number of doubles to append. |
EvioException | if structure or data arg(s) is null, data type is not double. |
References evio::DataType::DOUBLE64, and setAllHeaderLengths().
Referenced by main().
void evio::EventBuilder::appendFloatData | ( | std::shared_ptr< BaseStructure > | structure, |
float * | data, | ||
size_t | count | ||
) |
Append float data to the structure.
If the structure has no data, then this is the same as setting the data (except the the data type may not be changed).
structure | the structure to receive the data. |
data | pointer to data (array of floats) to append. |
count | number of floats to append. |
EvioException | if structure or data arg(s) is null, data type is not float. |
References evio::DataType::FLOAT32, and setAllHeaderLengths().
void evio::EventBuilder::appendIntData | ( | std::shared_ptr< BaseStructure > | structure, |
int32_t * | data, | ||
size_t | count | ||
) |
Append int data to the structure.
If the structure has no data, then this is the same as setting the data (except the the data type may not be changed).
structure | the structure to receive the data. |
data | pointer to data (array of ints) to append. |
count | number of ints to append. |
EvioException | if structure or data arg(s) is null, data type is not int. |
References evio::DataType::INT32, and setAllHeaderLengths().
void evio::EventBuilder::appendLongData | ( | std::shared_ptr< BaseStructure > | structure, |
int64_t * | data, | ||
size_t | count | ||
) |
Append long data to the structure.
If the structure has no data, then this is the same as setting the data (except the the data type may not be changed).
structure | the structure to receive the data. |
data | pointer to data (array of longs) to append. |
count | number of longs to append. |
EvioException | if structure or data arg(s) is null, data type is not long. |
References evio::DataType::LONG64, and setAllHeaderLengths().
void evio::EventBuilder::appendShortData | ( | std::shared_ptr< BaseStructure > | structure, |
int16_t * | data, | ||
size_t | count | ||
) |
Append short data to the structure.
If the structure has no data, then this is the same as setting the data (except the the data type may not be changed).
structure | the structure to receive the data. |
data | pointer to data (array of shorts) to append. |
count | number of shorts to append. |
EvioException | if structure or data arg(s) is null, data type is not short. |
References setAllHeaderLengths(), and evio::DataType::SHORT16.
void evio::EventBuilder::appendStringData | ( | std::shared_ptr< BaseStructure > | structure, |
std::string * | data, | ||
size_t | count | ||
) |
Append string data to the structure.
If the structure has no data, then this is the same as setting the data (except the the data type may not be changed).
structure | the structure to receive the data. |
data | pointer to data (array of string) to append. |
count | number of strings to append. |
EvioException | if structure or data arg(s) is null, data type is not string. |
References evio::DataType::CHARSTAR8, and setAllHeaderLengths().
Referenced by main().
void evio::EventBuilder::appendUCharData | ( | std::shared_ptr< BaseStructure > | structure, |
unsigned char * | data, | ||
size_t | count | ||
) |
Append unsigned char data to the structure.
If the structure has no data, then this is the same as setting the data (except the the data type may not be changed).
structure | the structure to receive the data. |
data | pointer to data (array of uchars) to append. |
count | number of chars to append. |
EvioException | if structure or data arg(s) is null, data type is not unsigned char. |
References setAllHeaderLengths(), and evio::DataType::UCHAR8.
void evio::EventBuilder::appendUIntData | ( | std::shared_ptr< BaseStructure > | structure, |
uint32_t * | data, | ||
size_t | count | ||
) |
Append unsigned int data to the structure.
If the structure has no data, then this is the same as setting the data (except the the data type may not be changed).
structure | the structure to receive the data. |
data | pointer to data (array of uints) to append. |
count | number of ints to append. |
EvioException | if structure or data arg(s) is null, data type is not unsigned int. |
References setAllHeaderLengths(), and evio::DataType::UINT32.
Referenced by main().
void evio::EventBuilder::appendULongData | ( | std::shared_ptr< BaseStructure > | structure, |
uint64_t * | data, | ||
size_t | count | ||
) |
Append unsigned long data to the structure.
If the structure has no data, then this is the same as setting the data (except the the data type may not be changed).
structure | the structure to receive the data. |
data | pointer to data (array of ulongs) to append. |
count | number of longs to append. |
EvioException | if structure or data arg(s) is null, data type is not unsigned long. |
References setAllHeaderLengths(), and evio::DataType::ULONG64.
void evio::EventBuilder::appendUShortData | ( | std::shared_ptr< BaseStructure > | structure, |
uint16_t * | data, | ||
size_t | count | ||
) |
Append unsigned short data to the structure.
If the structure has no data, then this is the same as setting the data (except the the data type may not be changed).
structure | the structure to receive the data. |
data | pointer to data (array of ushorts) to append. |
count | number of shorts to append. |
EvioException | if structure or data arg(s) is null, data type is not unsigned short. |
References setAllHeaderLengths(), and evio::DataType::USHORT16.
Referenced by main().
void evio::EventBuilder::clearData | ( | std::shared_ptr< BaseStructure > | structure | ) |
This clears all the data fields in a structure, but not the parent or the children.
This keeps the existing tree structure intact. To remove a structure (and, consequently, all its descendants) from the tree, use remove
structure | the segment to clear. |
std::shared_ptr< EvioEvent > evio::EventBuilder::getEvent | ( | ) |
|
static |
Main program for testing.
argc | ignored command line count. |
argv | ignored command line arguments. |
References addChild(), appendDoubleData(), appendStringData(), appendUIntData(), appendUShortData(), evio::DataType::BANK, evio::DataType::CHARSTAR8, evio::EventWriter::close(), evio::DataType::DOUBLE64, getEvent(), evio::EvioTagSegment::getInstance(), evio::EvioSegment::getInstance(), evio::EvioBank::getInstance(), evio::DataType::INT32, evio::DataType::SEGMENT, evio::DataType::SHORT16, evio::DataType::TAGSEGMENT, and evio::EventWriter::writeEvent().
void evio::EventBuilder::remove | ( | std::shared_ptr< BaseStructure > | child | ) |
This removes a structure (and all its descendants) from the tree.
child | the child structure to remove. |
EvioException | if arg is null or its parent is null |
References setAllHeaderLengths().
void evio::EventBuilder::setAllHeaderLengths | ( | ) |
This goes through the event recursively, and makes sure all the length fields in the headers are properly set.
Referenced by addChild(), appendCharData(), appendCompositeData(), appendDoubleData(), appendFloatData(), appendIntData(), appendLongData(), appendShortData(), appendStringData(), appendUCharData(), appendUIntData(), appendULongData(), appendUShortData(), remove(), setCharData(), setCompositeData(), setDoubleData(), setFloatData(), setIntData(), setLongData(), setShortData(), setStringData(), setUCharData(), setUIntData(), setULongData(), and setUShortData().
void evio::EventBuilder::setCharData | ( | std::shared_ptr< BaseStructure > | structure, |
char * | data, | ||
size_t | count | ||
) |
Set char data in the structure.
If the structure has data, it is overwritten even if the existing data is of a different type.
structure | the structure to receive the data. |
data | pointer to data (array of chars) to write. |
count | number of bytes to write. |
EvioException | if structure or data arg(s) is null. |
References evio::DataType::CHAR8, and setAllHeaderLengths().
void evio::EventBuilder::setCompositeData | ( | std::shared_ptr< BaseStructure > | structure, |
std::shared_ptr< CompositeData > * | data, | ||
size_t | count | ||
) |
Set composite data in the structure.
If the structure has data, it is overwritten even if the existing data is of a different type.
structure | the structure to receive the data. |
data | pointer to data (array of shared pointers of composite type) to write. |
count | number of (shared pointer of) composites to write. |
EvioException | if structure or data arg(s) is null. |
References evio::DataType::COMPOSITE, and setAllHeaderLengths().
void evio::EventBuilder::setDoubleData | ( | std::shared_ptr< BaseStructure > | structure, |
double * | data, | ||
size_t | count | ||
) |
Set double data in the structure.
If the structure has data, it is overwritten even if the existing data is of a different type.
structure | the structure to receive the data. |
data | pointer to data (array of doubles) to write. |
count | number of doubles to write. |
EvioException | if structure or data arg(s) is null. |
References evio::DataType::DOUBLE64, and setAllHeaderLengths().
void evio::EventBuilder::setEvent | ( | std::shared_ptr< EvioEvent > & | ev | ) |
Set the underlying event.
As far as this event builder is concerned, the previous underlying event is lost, and all subsequent calls will affect the newly supplied event.
ev | the new underlying event. |
void evio::EventBuilder::setFloatData | ( | std::shared_ptr< BaseStructure > | structure, |
float * | data, | ||
size_t | count | ||
) |
Set float data in the structure.
If the structure has data, it is overwritten even if the existing data is of a different type.
structure | the structure to receive the data. |
data | pointer to data (array of floats) to write. |
count | number of floats to write. |
EvioException | if structure or data arg(s) is null. |
References evio::DataType::FLOAT32, and setAllHeaderLengths().
void evio::EventBuilder::setIntData | ( | std::shared_ptr< BaseStructure > | structure, |
int32_t * | data, | ||
size_t | count | ||
) |
Set int data in the structure.
If the structure has data, it is overwritten even if the existing data is of a different type.
structure | the structure to receive the data. |
data | pointer to data (array of ints) to write. |
count | number of ints to write. |
EvioException | if structure or data arg(s) is null. |
References evio::DataType::INT32, and setAllHeaderLengths().
void evio::EventBuilder::setLongData | ( | std::shared_ptr< BaseStructure > | structure, |
int64_t * | data, | ||
size_t | count | ||
) |
Set long data in the structure.
If the structure has data, it is overwritten even if the existing data is of a different type.
structure | the structure to receive the data. |
data | pointer to data (array of longs) to write. |
count | number of longs to write. |
EvioException | if structure or data arg(s) is null. |
References evio::DataType::LONG64, and setAllHeaderLengths().
void evio::EventBuilder::setShortData | ( | std::shared_ptr< BaseStructure > | structure, |
int16_t * | data, | ||
size_t | count | ||
) |
Set short data in the structure.
If the structure has data, it is overwritten even if the existing data is of a different type.
structure | the structure to receive the data. |
data | pointer to data (array of shorts) to write. |
count | number of shorts to write. |
EvioException | if structure or data arg(s) is null. |
References setAllHeaderLengths(), and evio::DataType::SHORT16.
void evio::EventBuilder::setStringData | ( | std::shared_ptr< BaseStructure > | structure, |
std::string * | data, | ||
size_t | count | ||
) |
Set string data in the structure.
If the structure has data, it is overwritten even if the existing data is of a different type.
structure | the structure to receive the data. |
data | pointer to data (array of strings) to write. |
count | number of strings to write. |
EvioException | if structure or data arg(s) is null. |
References evio::DataType::CHARSTAR8, and setAllHeaderLengths().
void evio::EventBuilder::setUCharData | ( | std::shared_ptr< BaseStructure > | structure, |
unsigned char * | data, | ||
size_t | count | ||
) |
Set unsigned char data in the structure.
If the structure has data, it is overwritten even if the existing data is of a different type.
structure | the structure to receive the data. |
data | pointer to data (array of uchars) to write. |
count | number of bytes to write. |
EvioException | if structure or data arg(s) is null. |
References setAllHeaderLengths(), and evio::DataType::UCHAR8.
void evio::EventBuilder::setUIntData | ( | std::shared_ptr< BaseStructure > | structure, |
uint32_t * | data, | ||
size_t | count | ||
) |
Set unsigned int data in the structure.
If the structure has data, it is overwritten even if the existing data is of a different type.
structure | the structure to receive the data. |
data | pointer to data (array of uints) to write. |
count | number of ints to write. |
EvioException | if structure or data arg(s) is null. |
References setAllHeaderLengths(), and evio::DataType::UINT32.
void evio::EventBuilder::setULongData | ( | std::shared_ptr< BaseStructure > | structure, |
uint64_t * | data, | ||
size_t | count | ||
) |
Set unsigned long data in the structure.
If the structure has data, it is overwritten even if the existing data is of a different type.
structure | the structure to receive the data. |
data | pointer to data (array of ulongs) to write. |
count | number of longs to write. |
EvioException | if structure or data arg(s) is null. |
References setAllHeaderLengths(), and evio::DataType::ULONG64.
void evio::EventBuilder::setUShortData | ( | std::shared_ptr< BaseStructure > | structure, |
uint16_t * | data, | ||
size_t | count | ||
) |
Set unsigned short data in the structure.
If the structure has data, it is overwritten even if the existing data is of a different type.
structure | the structure to receive the data. |
data | pointer to data (array of ushorts) to write. |
count | number of shorts to write. |
EvioException | if structure or data arg(s) is null. |
References setAllHeaderLengths(), and evio::DataType::USHORT16.