ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
oEvent.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file oEvent.cc
1 #include "oEvent.h"
2 #include "EventTypes.h"
3 
4 #include "A_Event.h"
5 #include "Cframe.h"
6 #include "frameRoutines.h"
7 #include "packetRoutines.h"
8 #include "packetConstants.h"
9 
10 #include <time.h>
11 
12 // the constructor first ----------------
13 oEvent::oEvent (PHDWORD * where, const int length
14  , const int irun, const int etype, const int evtseq)
15 {
16  event_base = where;
17  evthdr = ( evtdata_ptr ) where;
18  evthdr->evt_type = etype;
21  prepare_next (evtseq, irun);
22 }
23 
24 void oEvent::set_event_type(const int etype)
25 {
26  evthdr->evt_type = etype;
27 }
28 
30 {
31  // re-initialize the event header length
33 
34  // if < 0, just increment the current seq. number
36 
37  // reset the current data index, and the leftover counter
38  current = 0;
39  in_frame = 0; // indicate that we are just now assembling a frame
41  evthdr->date = time(0);
42  evthdr->time = -1;
43 
44  return 0;
45 
46 }
47 
48 int oEvent::prepare_next( const int evtseq
49  , const int irun )
50 {
51  // re-initialize the event header length
53 
54  // if < 0, just increment the current seq. number
55 
56  evthdr->evt_sequence = evtseq;
57 
58  // if > 0, adjust the run number, else just keep it.
59  evthdr->run_number=irun;
60 
61  // reset the current data index, and the leftover counter
62  current = 0;
63  in_frame = 0; // indicate that we are just now assembling a frame
65  evthdr->date = time(0);
66  evthdr->time = -1;
67 
68  return 0;
69 }
70 
71 
73 {
74  int len,i;
75  PHDWORD *to = &(evthdr->data[current]);
76  PHDWORD *from = frame;
77 
78  len = getFrameLength(frame);
79  for (i=0; i< len; i++) *to++ = *from++;
80 
81  evthdr->evt_length += len;
82  current += len;
83  left -= len;
84  in_frame = 0;
85  return len;
86 }
87 
88 
89 
91 {
92 
93  int additionalFrameLength = 0;
94  if (!in_frame)
95  {
98  rawData,oncsFrame,101);
99  in_frame = 1;
102  additionalFrameLength = currentFrameHdrLength;
105  }
106 
107  PHDWORD* packetstart;
108  int packetlength = p->getLength();
109 
110 
111  packetstart = findFrameDataEnd(currentFramePtr ) +1;
112 
113  p->copyMe( (int *)packetstart, packetlength );
114 
115  if (packetlength >0)
116  {
117  evthdr->evt_length += packetlength;
118  current += packetlength;
120  left -= packetlength;
121  return packetlength + additionalFrameLength;
122  }
123  else return -1;
124 }
125 
126 
127 
129  const int length,
130  const int id,
131  const int wordsize,
132  const int hitformat)
133 {
134 
135  int additionalFrameLength = 0;
136  if (!in_frame)
137  {
140  rawData,oncsFrame,101);
141  in_frame = 1;
144  additionalFrameLength = currentFrameHdrLength;
147  }
148 
149  PHDWORD* packetstart;
150  int packetlength;
151 
152  packetstart = findFrameDataEnd(currentFramePtr ) +1;
153 
154  makeUnstructPacket (packetstart, left, id, wordsize, hitformat);
155 
156  packetlength = storePacketHits (packetstart, left,
157  0, (BYTE*) data, length, 0);
158 
159  if (packetlength >0)
160  {
161  evthdr->evt_length += packetlength;
162  current += packetlength;
164  left -= packetlength;
165  return packetlength + additionalFrameLength;
166  }
167  else return -1;
168 }
169