Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ospEvent.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ospEvent.cc
1 #include "ospEvent.h"
2 #include "EventTypes.h"
3 
4 #include <time.h>
5 #include <string.h>
6 
7 // the constructor first ----------------
8 ospEvent::ospEvent (PHDWORD * where, const int length
9  , const int irun, const int etype, const int evtseq)
10 {
11  evthdr = ( oncsevtdata_ptr ) where;
12  evthdr->evt_type = etype;
14  prepare_next (evtseq, irun);
15 }
16 
17 void ospEvent::set_event_type(const int etype)
18 {
19  evthdr->evt_type = etype;
20 }
21 
23 {
24  // re-initialize the event header length
26 
27  // if < 0, just increment the current seq. number
29 
30  // reset the current data index, and the leftover counter
31  current = 0;
33  evthdr->date = time(0);
34  evthdr->time = 0;
35 
36  return 0;
37 
38 }
39 
40 int ospEvent::prepare_next( const int evtseq
41  , const int irun )
42 {
43  // re-initialize the event header length
45 
46  // if < 0, just increment the current seq. number
47 
48  evthdr->evt_sequence = evtseq;
49 
50  // if > 0, adjust the run number, else just keep it.
51  evthdr->run_number=irun;
52 
53  // reset the current data index, and the leftover counter
54  current = 0;
56  evthdr->date = time(0);
57  evthdr->time = 0;
58 
59  return 0;
60 }
61 
63 {
64 
65  int* packetstart;
66  int packetlength = p->getLength();
67 
68 
69  packetstart = &(evthdr->data[current]);
70 
71  p->copyMe( (int *)packetstart, packetlength );
72 
73  if (packetlength >0)
74  {
75  evthdr->evt_length += packetlength;
76  current += packetlength;
77  left -= packetlength;
78  return packetlength;
79  }
80  else return -1;
81 }
82 
83 
84 
86  const int length,
87  const int id,
88  const int wordsize,
89  const int hitformat)
90 {
91 
92 // int* packetstart;
93 
96  sevt->sub_id = id;
97  sevt->sub_type=wordsize;
98  sevt->sub_decoding = hitformat;
99  sevt->reserved[0] = 0;
100  sevt->reserved[1] = 0;
101 
102  memcpy(&sevt->data , data, length * sizeof (int) );
103  sevt->sub_length += length;
104 
105  evthdr->evt_length += sevt->sub_length;
106  current += sevt->sub_length;
107  left -= sevt->sub_length;
108  return sevt->sub_length;
109 
110 }
111