You may be forced to write YODA-style data output (e.g. from a
simulation program or an input formatter). This should be no problem
using the Eventstream class. See the example below:
/*>--------------------------------------------------------------------------*/
/*
* a short program to test the ability of producing containerevents
*/
/*<--------------------------------------------------------------------------*/
#include "eventstream.h"
/*>--------------------------------------------------------------------------*/
main()
/*
*
*/
/*<--------------------------------------------------------------------------*/
{
/*
* declare the application-specific data to be written
*/
struct Mydata // some nonsens we want to write
{
double foo;
float bar;
int stuff;
} data;
/*
* now make a new eventstream, which pumps the containerevents from
* filedescriptor IN to file OUT. It is also used to generate containervents
* from scratch (this is used here), and then write them to file.
* default is stdin / stdout
*/
Eventstream eventstream(stdin, stdout); // this defaults to stdin / out
/*
* setup a new containerevent. this is needed everytime the containerevent
* structure is modified (NOT regarding the eventnumber.
* choose type/subtype according to your needs. variable names below are used
* just for verbosity
*/
short triggerpat=1;
short runnum=12;
short expnum=42;
unsigned evtnum=0;
eventstream.setup(CEVT_T_SIMULATION, triggerpat, runnum, expnum, evtnum);
/*
* now produce 100 containerevents in a loop. first calculate
* the quantities to be written, then add thenm to the current containerevent
* as a subevent
*/
for (int i=0; i<100; i++)
{
data.foo = sin(i);
data.bar = cos(i);
data.stuff = random();
/*
* now add this as a subevent. supply type/subtype, pointer to data
* and length of data.
*/
eventstream.add_subevent(SEVT_T_CALCULATED, SEVT_ST_DUMMY,
&data, sizeof(data));
cerr << "writing container number " << i << "\n";
eventstream.put(); // write to output
eventstream.next_container(); // increment the event number
}
}