forked from sPHENIX-Collaboration/online_distribution
/
ospEvent.cc
111 lines (82 loc) · 2.3 KB
/
ospEvent.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "ospEvent.h"
#include "EventTypes.h"
#include <time.h>
#include <string.h>
// the constructor first ----------------
ospEvent::ospEvent (PHDWORD * where, const int length
, const int irun, const int etype, const int evtseq)
{
evthdr = ( oncsevtdata_ptr ) where;
evthdr->evt_type = etype;
max_length = length;
prepare_next (evtseq, irun);
}
void ospEvent::set_event_type(const int etype)
{
evthdr->evt_type = etype;
}
int ospEvent::prepare_next()
{
// re-initialize the event header length
evthdr->evt_length = EVTHEADERLENGTH;
// if < 0, just increment the current seq. number
evthdr->evt_sequence++;
// reset the current data index, and the leftover counter
current = 0;
left=max_length - EVTHEADERLENGTH ;
evthdr->date = time(0);
evthdr->time = 0;
return 0;
}
int ospEvent::prepare_next( const int evtseq
, const int irun )
{
// re-initialize the event header length
evthdr->evt_length = EVTHEADERLENGTH;
// if < 0, just increment the current seq. number
evthdr->evt_sequence = evtseq;
// if > 0, adjust the run number, else just keep it.
evthdr->run_number=irun;
// reset the current data index, and the leftover counter
current = 0;
left=max_length - EVTHEADERLENGTH ;
evthdr->date = time(0);
evthdr->time = 0;
return 0;
}
int ospEvent::addPacket( const Packet *p)
{
int* packetstart;
int packetlength = p->getLength();
packetstart = &(evthdr->data[current]);
p->copyMe( (int *)packetstart, packetlength );
if (packetlength >0)
{
evthdr->evt_length += packetlength;
current += packetlength;
left -= packetlength;
return packetlength;
}
else return -1;
}
int ospEvent::addUnstructPacketData(PHDWORD * data,
const int length,
const int id,
const int wordsize,
const int hitformat)
{
// int* packetstart;
subevtdata_ptr sevt = (subevtdata_ptr) &(evthdr->data[current]);
sevt->sub_length = SEVTHEADERLENGTH;
sevt->sub_id = id;
sevt->sub_type=wordsize;
sevt->sub_decoding = hitformat;
sevt->reserved[0] = 0;
sevt->reserved[1] = 0;
memcpy(&sevt->data , data, length * sizeof (int) );
sevt->sub_length += length;
evthdr->evt_length += sevt->sub_length;
current += sevt->sub_length;
left -= sevt->sub_length;
return sevt->sub_length;
}