ROOTANA
Loading...
Searching...
No Matches
v1190unpack.cxx
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdint.h>
3
4#include "v1190unpack.h"
5
7{
8 error = false;
9 event_count = 0;
10 geo = 0;
11}
12
13v1190event* UnpackV1190(const char** data8, int* datalen, bool verbose)
14{
15 const uint32_t *data = (const uint32_t*)(*data8);
16 int count = (*datalen)/4;
17
18 v1190event* e = new v1190event();
19
20 bool done = false;
21
22 for (int i=0; i<count; i++) {
23 switch ((data[i] >> 27) & 0x1F) {
24 case 0x8: // Global Header
25 {
26 e->event_count = (data[i] >> 5) & 0x3FFFFF;
27 e->geo = data[i] & 0x1F;
28 if (verbose)
29 printf("%d 0x%08x: global header: event count %d, geo 0x%2x\n", i, data[i], e->event_count, e->geo);
30 break;
31 }
32 case 0x1: // TDC Header
33 {
34 e->tdc_header_tdc = (data[i] >> 24) & 0x3;
35 e->tdc_header_event_id = (data[i] >> 12) & 0xFFF;
36 e->tdc_header_bunch_id = data[i] & 0xFFF;
37 if (verbose)
38 printf("%d 0x%08x: tdc header: tdc %d, event_id %d, bunch_id %d\n", i, data[i], e->tdc_header_tdc, e->tdc_header_event_id, e->tdc_header_bunch_id);
39 break;
40 }
41 case 0x0: // TDC measurement
42 {
43 v1190hit h;
44 h.trailing = (data[i] >> 26) & 1;
45 h.channel = (data[i] >> 19) & 0x7F;
46 h.measurement = data[i] & 0x7FFFF;
47
48 e->hits.push_back(h);
49
50 if (verbose)
51 printf("%d 0x%08x: tdc measurement: te %d, chan %d, meas %d\n", i, data[i], h.trailing, h.channel, h.measurement);
52 break;
53 }
54 case 0x3: // TDC Trailer
55 {
56 e->tdc_trailer_tdc = (data[i] >> 24) & 3;
57 e->tdc_trailer_event_id = (data[i] >> 12) & 0xFFF;
58 e->tdc_trailer_word_count = (data[i]) & 0xFFF;
59
60 if (verbose)
61 printf("%d 0x%08x: tdc trailer: tdc %d, event id %d, word count %d\n", i, data[i], e->tdc_trailer_tdc, e->tdc_trailer_event_id, e->tdc_trailer_word_count);
63 e->error = true;
64 printf ("v1190unpack: event number mismatch: trailer: %d, header: %d\n", e->tdc_trailer_event_id, e->tdc_header_event_id);
65 }
66 break;
67 }
68 case 0x4: // TDC Error
69 {
70 e->tdc_error_tdc = (data[i] >> 24) & 3;
71 e->tdc_error_flags = (data[i]) & 0xFFF;
72 if (e->tdc_error_flags)
73 e->error = true;
74 if (verbose)
75 printf("%d 0x%08x: tdc error: tdc %d, error flags 0x%x\n", i, data[i], e->tdc_error_tdc, e->tdc_error_flags);
76 break;
77 }
78 case 0x11: // Extended Trigger Time
79 {
80 e->ettt = data[i] & 0x7FFFFFF;
81 if (verbose)
82 printf("%d 0x%08x: extended trigger time 0x%x\n", i, data[i], e->ettt);
83 break;
84 }
85 case 0x10: // Trailer
86 {
87 done = true;
88 e->trailer_trigger_lost = (data[i] >> 26) & 1;
89 e->trailer_output_buffer_overflow = (data[i] >> 25) & 1;
90 e->trailer_tdc_error = (data[i] >> 24) & 1;
91 e->trailer_word_count = (data[i] >> 5) & 0xFFFF;
92 e->trailer_geo = (data[i]) & 0x1F;
93 if (e->trailer_tdc_error)
94 e->error = true;
95 if (verbose)
96 printf("%d 0x%08x: trailer: status TL %d, OBO %d, TDC_E %d, word count %d, geo 0x%x\n", i, data[i], e->trailer_trigger_lost, e->trailer_output_buffer_overflow, e->trailer_tdc_error, e->trailer_word_count, e->trailer_geo);
97 if (e->trailer_geo != e->geo) {
98 e->error = true;
99 printf ("v1190unpack: geo mismatch\n");
100 }
101 if (e->trailer_word_count != i+1) {
102 e->error = true;
103 printf ("v1190unpack: word count mismatch: trailer wc %d, but data has %d words\n", e->trailer_word_count, i+1);
104 }
105 break;
106 }
107 default:
108 {
109 if (verbose)
110 printf("%d 0x%08x: unexpected data\n", i, data[i]);
111 e->error = true;
112 printf("v1190unpack: unexpected data word 0x%08x\n", data[i]);
113 }
114 }
115
116 if (done) {
117 i++;
118 (*data8) += i*4;
119 (*datalen) -= i*4;
120 break;
121 }
122 }
123 return e;
124}
125
127{
128 printf("v1190event: error %d, ec %d, geo 0x%x, tl %d, obo %d, tdc_e %d, wc %d, %d hits\n", error, event_count, geo, trailer_trigger_lost, trailer_output_buffer_overflow, trailer_tdc_error, trailer_word_count, (int)hits.size());
129}
130
131/* emacs
132 * Local Variables:
133 * tab-width: 8
134 * c-basic-offset: 3
135 * indent-tabs-mode: nil
136 * End:
137 */
void Print() const
int tdc_header_tdc
Definition v1190unpack.h:21
int tdc_trailer_word_count
Definition v1190unpack.h:27
int tdc_error_tdc
Definition v1190unpack.h:29
std::vector< v1190hit > hits
Definition v1190unpack.h:40
bool trailer_tdc_error
Definition v1190unpack.h:36
int tdc_trailer_event_id
Definition v1190unpack.h:26
int trailer_word_count
Definition v1190unpack.h:37
int trailer_geo
Definition v1190unpack.h:38
int tdc_header_bunch_id
Definition v1190unpack.h:23
int tdc_error_flags
Definition v1190unpack.h:30
bool trailer_output_buffer_overflow
Definition v1190unpack.h:35
int tdc_trailer_tdc
Definition v1190unpack.h:25
bool trailer_trigger_lost
Definition v1190unpack.h:34
int tdc_header_event_id
Definition v1190unpack.h:22
int event_count
Definition v1190unpack.h:18
int channel
Definition v1190unpack.h:8
bool trailing
Definition v1190unpack.h:9
int measurement
Definition v1190unpack.h:10
v1190event * UnpackV1190(const char **data8, int *datalen, bool verbose)