ROOTANA
Loading...
Searching...
No Matches
v1742unpack.cxx
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdint.h>
3#include <string.h>
4
5#include "v1742unpack.h"
6
7#define MEMZERO(array) memset((array), 0, sizeof(array))
8
10{
11 error = false;
12 //event_count = 0;
13 //geo = 0;
14 MEMZERO(adc);
18}
19
20v1742event* UnpackV1742(const char** data8, int* datalen, bool verbose)
21{
22 const uint32_t *data = (const uint32_t*)(*data8);
23 //int count = (*datalen)/4;
24
25 v1742event* e = new v1742event();
26
27 if (verbose) {
28 printf("Header:\n");
29 printf(" total event size: 0x%08x (%d)\n", data[0], data[0]&0x0FFFFFFF);
30 printf(" board id, pattern, gr mask: 0x%08x\n", data[1]);
31 printf(" event counter: 0x%08x (%d)\n", data[2], data[2]);
32 printf(" event time tag: 0x%08x (%d)\n", data[3], data[3]);
33 }
34
35 // header word 0
36 e->total_event_size = data[0]&0x0FFFFFFF;
37
38 // header word 1
39 e->board_id = (data[1]>>27)&0x1F;
40 e->pattern = (data[1]>>8)&0x3FFF;
41 e->group_mask = data[1] & 0xF;
42
43 // header word 2
44 e->event_counter = data[2] & 0x3FFFFF;
45
46 // header word 3
47 e->event_time_tag = data[3];
48
49 const uint32_t *g = data + 4;
50 for (int i=0; i<4; i++) {
51
52 if (((1<<i)&e->group_mask)==0)
53 continue;
54
55 e->len[i] = g[0] & 0xfff;
56 e->tr[i] = (g[0]>>12)&1;
57 e->freq[i] = (g[0]>>16)&3;
58 e->cell[i] = (g[0]>>20)&0x3ff;
59
60 g += 1;
61 // g points to the data
62
63 //for (int k=0; k<10; k++)
64 // printf(" adc data[k]: 0x%08x\n", g[k]);
65
66 int k=0;
67
68 const uint8_t* p = (const uint8_t*)g;
69 int x = 0;
70 for (int s=0; s<1024; s++)
71 for (int a=0; a<8; a++) {
72 int v = 0;
73 if (x==0) {
74 v = (p[0]) | ((p[1]&0xF)<<8);
75 p += 1;
76 x = 1;
77 } else {
78 v = ((p[0]&0xF0)>>4) | ((p[1]&0xFF)<<4);
79 p += 2;
80 x = 0;
81 }
82
83 //printf("group %d, channel %d, sample %d: value %6d (0x%03x)\n", i, a, s, v, v);
84
85 e->adc[i*8+a][s] = v;
86
87 if (v == 0)
88 e->adc_overflow[i*8+a] = true;
89
90 k++;
91 //if (k > 10)
92 //abort();
93 }
94
95 g += e->len[i];
96
97 if (e->tr[i]) {
98 int trlen = e->len[i]/8;
99
100 const uint8_t* p = (const uint8_t*)g;
101 int x = 0;
102 for (int s=0; s<1024; s++) {
103 int v = 0;
104 if (x==0) {
105 v = (p[0]) | ((p[1]&0xF)<<8);
106 p += 1;
107 x = 1;
108 } else {
109 v = ((p[0]&0xF0)>>4) | ((p[1]&0xFF)<<4);
110 p += 2;
111 x = 0;
112 }
113
114 //printf("group %d, channel %d, sample %d: value %6d (0x%03x)\n", i, a, s, v, v);
115
116 e->adc_tr[i][s] = v;
117
118 if (v == 0)
119 e->adc_tr_overflow[i] = true;
120
121 k++;
122 //if (k > 10)
123 //abort();
124 }
125
126 g += trlen;
127 }
128
129 // g points to the time tag
130 if (verbose) {
131 printf(" group trigger time tag: 0x%08x\n", g[0]);
132 }
133
134 e->trigger_time_tag[i] = g[0];
135
136 g += 1;
137 // g point s to the next group
138 }
139
140
141#if 0
142 if (e->trailer_word_count != i+1) {
143 e->error = true;
144 printf ("v1190unpack: word count mismatch: trailer wc %d, but data has %d words\n", e->trailer_word_count, i+1);
145 }
146 break;
147 }
148 default:
149 {
150 if (verbose)
151 printf("%d 0x%08x: unexpected data\n", i, data[i]);
152 e->error = true;
153 printf("v1190unpack: unexpected data word 0x%08x\n", data[i]);
154 }
155#endif
156
157 return e;
158}
159
161{
162#if 0
163 printf("v1742event: 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());
164#endif
165}
166
167/* emacs
168 * Local Variables:
169 * tab-width: 8
170 * c-basic-offset: 3
171 * indent-tabs-mode: nil
172 * End:
173 */
#define MEMZERO(array)
Definition Alpha16.cxx:15
int adc[32][1024]
Definition v1742unpack.h:21
void Print() const
bool adc_tr_overflow[4]
Definition v1742unpack.h:25
int trigger_time_tag[4]
Definition v1742unpack.h:19
int event_time_tag
Definition v1742unpack.h:13
int total_event_size
Definition v1742unpack.h:8
int event_counter
Definition v1742unpack.h:12
int cell[4]
Definition v1742unpack.h:18
int adc_tr[4][1024]
Definition v1742unpack.h:22
int tr[4]
Definition v1742unpack.h:16
int freq[4]
Definition v1742unpack.h:17
int len[4]
Definition v1742unpack.h:15
bool adc_overflow[32]
Definition v1742unpack.h:24
v1742event * UnpackV1742(const char **data8, int *datalen, bool verbose)