StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Crate.hh
1 //
2 // Pibero Djawotho <pibero@tamu.edu>
3 // Texas A&M
4 // 16 July 2012
5 //
6 
7 #ifndef CRATE_HH
8 #define CRATE_HH
9 
10 #include <stdio.h>
11 #include "Board.hh"
12 
13 #if defined(__linux__) || defined(__APPLE__)
14 #if defined(__linux__)
15 /* linux has its own (fast) swaps */
16 #include <byteswap.h>
17 #else /* __APPLE__ */
18 //#warning "byteswap.h is an unportable GNU extension! Don't use!"
19 static inline unsigned short bswap_16(unsigned short x) {
20  return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)) ;
21 }
22 static inline unsigned int bswap_32(unsigned int x) {
23  return (bswap_16(x&0xffff)<<16) | (bswap_16(x>>16));
24 }
25 static inline unsigned long long bswap_64(unsigned long long x) {
26  return (((unsigned long long)bswap_32(x&0xffffffffull))<<32) |
27 (bswap_32(x>>32));
28 }
29 #endif /* __APPLE__ */
30 #endif /* __linux__ || __APPLE__ */
31 #include <cassert>
32 #include <cstring>
33 #include <algorithm>
34 #include <functional>
35 //#include "RTS/trg/include/trgConfNum.h"
36 //#include "RTS/trg/include/trgDataDefs.h"
37 #include "trgConfNum_fms.h"
38 #include "trgDataDefs_v45.h"
39 #include "Board.hh"
40 
41 using namespace std;
42 
43 static const char* crateNames[] = { 0, "L1", "BC1", "MXQ", "MIX", "BCW", "BCE", "FEQ", "BBC", "BBQ", "FMS", "QT1", "QT2", "QT3", "QT4" };
44 
45 // L1 crate
46 const int TF201_BASE_ADDRESS = 0x10000000;
47 const int VT201_BASE_ADDRESS = 0x12000000;
48 const int EM201_BASE_ADDRESS = 0x14000000;
49 const int EM202_BASE_ADDRESS = 0x15000000;
50 const int BX201_BASE_ADDRESS = 0x16000000;
51 const int BX202_BASE_ADDRESS = 0x18000000;
52 const int ST201_BASE_ADDRESS = 0x1a000000;
53 const int FP201_BASE_ADDRESS = 0x1c000000;
54 const int LD301_BASE_ADDRESS = 0x1e000000;
55 
56 // BC1 crate
57 const int BC101_BASE_ADDRESS = 0x21000000;
58 const int BC102_BASE_ADDRESS = 0x10000000;
59 const int BC103_BASE_ADDRESS = 0x11000000;
60 const int BC104_BASE_ADDRESS = 0x12000000;
61 const int BC105_BASE_ADDRESS = 0x13000000;
62 const int BC106_BASE_ADDRESS = 0x14000000;
63 const int EE101_BASE_ADDRESS = 0x15000000;
64 const int EE102_BASE_ADDRESS = 0x16000000;
65 const int EE001_BASE_ADDRESS = 0x17000000;
66 const int EE002_BASE_ADDRESS = 0x18000000;
67 const int EE003_BASE_ADDRESS = 0x19000000;
68 const int EE004_BASE_ADDRESS = 0x1a000000;
69 const int EE005_BASE_ADDRESS = 0x1b000000;
70 const int EE006_BASE_ADDRESS = 0x1c000000;
71 const int EE007_BASE_ADDRESS = 0x1d000000;
72 const int EE008_BASE_ADDRESS = 0x1e000000;
73 const int EE009_BASE_ADDRESS = 0x1f000000;
74 
75 // MIX crate
76 const int FE101_BASE_ADDRESS = 0x10000000;
77 const int MT101_BASE_ADDRESS = 0x11000000;
78 const int TF101_BASE_ADDRESS = 0x12000000;
79 const int TF001_BASE_ADDRESS = 0x14000000;
80 const int TF002_BASE_ADDRESS = 0x16000000;
81 const int TF003_BASE_ADDRESS = 0x18000000;
82 const int TF004_BASE_ADDRESS = 0x1a000000;
83 const int TF005_BASE_ADDRESS = 0x1c000000;
84 const int TF006_BASE_ADDRESS = 0x1e000000;
85 
86 // BCW crate
87 const int BW001_BASE_ADDRESS = 0x10000000;
88 const int BW002_BASE_ADDRESS = 0x11000000;
89 const int BW003_BASE_ADDRESS = 0x12000000;
90 const int BW004_BASE_ADDRESS = 0x13000000;
91 const int BW005_BASE_ADDRESS = 0x14000000;
92 const int BW006_BASE_ADDRESS = 0x15000000;
93 const int BW007_BASE_ADDRESS = 0x16000000;
94 const int BW008_BASE_ADDRESS = 0x17000000;
95 const int BW009_BASE_ADDRESS = 0x18000000;
96 const int BW010_BASE_ADDRESS = 0x19000000;
97 const int BW011_BASE_ADDRESS = 0x1a000000;
98 const int BW012_BASE_ADDRESS = 0x1b000000;
99 const int BW013_BASE_ADDRESS = 0x1c000000;
100 const int BW014_BASE_ADDRESS = 0x1d000000;
101 const int BW015_BASE_ADDRESS = 0x1e000000;
102 
103 // BCE crate
104 const int BE001_BASE_ADDRESS = 0x10000000;
105 const int BE002_BASE_ADDRESS = 0x11000000;
106 const int BE003_BASE_ADDRESS = 0x12000000;
107 const int BE004_BASE_ADDRESS = 0x13000000;
108 const int BE005_BASE_ADDRESS = 0x14000000;
109 const int BE006_BASE_ADDRESS = 0x15000000;
110 const int BE007_BASE_ADDRESS = 0x16000000;
111 const int BE008_BASE_ADDRESS = 0x17000000;
112 const int BE009_BASE_ADDRESS = 0x18000000;
113 const int BE010_BASE_ADDRESS = 0x19000000;
114 const int BE011_BASE_ADDRESS = 0x1a000000;
115 const int BE012_BASE_ADDRESS = 0x1b000000;
116 const int BE013_BASE_ADDRESS = 0x1c000000;
117 const int BE014_BASE_ADDRESS = 0x1d000000;
118 const int BE015_BASE_ADDRESS = 0x1e000000;
119 
120 // FEQ crate
121 
122 const int FE001_BASE_ADDRESS = 0x10000000;
123 const int FE002_BASE_ADDRESS = 0x11000000;
124 const int FE003_BASE_ADDRESS = 0x12000000;
125 const int FE004_BASE_ADDRESS = 0x13000000;
126 const int FS001_BASE_ADDRESS = 0x19000000;
127 const int FS002_BASE_ADDRESS = 0x1a000000;
128 const int FS003_BASE_ADDRESS = 0x1b000000;
129 const int FS004_BASE_ADDRESS = 0x1c000000;
130 const int FS005_BASE_ADDRESS = 0x1d000000;
131 const int FS006_BASE_ADDRESS = 0x1e000000;
132 
133 // BBC crate
134 const int BB101_BASE_ADDRESS = 0x10000000;
135 const int BB102_BASE_ADDRESS = 0x12000000;
136 const int ZD101_BASE_ADDRESS = 0x14000000;
137 const int VP101_BASE_ADDRESS = 0x16000000;
138 
139 // FMS crate
140 #define RUN15
141 #ifndef RUN15
142 const int FM001_BASE_ADDRESS = 0x10000000;
143 const int FM002_BASE_ADDRESS = 0x11000000;
144 const int FM003_BASE_ADDRESS = 0x12000000;
145 const int FM004_BASE_ADDRESS = 0x13000000;
146 const int FM101_BASE_ADDRESS = 0x14000000;
147 const int FM005_BASE_ADDRESS = 0x15000000;
148 const int FM006_BASE_ADDRESS = 0x16000000;
149 const int FM007_BASE_ADDRESS = 0x17000000;
150 const int FM008_BASE_ADDRESS = 0x18000000;
151 const int FM102_BASE_ADDRESS = 0x19000000;
152 const int FM009_BASE_ADDRESS = 0x1a000000;
153 const int FM010_BASE_ADDRESS = 0x1b000000;
154 const int FM011_BASE_ADDRESS = 0x1c000000;
155 const int FM012_BASE_ADDRESS = 0x1d000000;
156 const int FM103_BASE_ADDRESS = 0x1e000000;
157 #endif
158 #ifdef RUN15
159 const int FM001_BASE_ADDRESS = 0x21000000;
160 const int FM002_BASE_ADDRESS = 0x10000000;
161 const int FM101_BASE_ADDRESS = 0x11000000;
162 const int FM003_BASE_ADDRESS = 0x12000000;
163 const int FM004_BASE_ADDRESS = 0x13000000;
164 const int FM102_BASE_ADDRESS = 0x14000000;
165 const int FM005_BASE_ADDRESS = 0x15000000;
166 const int FM006_BASE_ADDRESS = 0x16000000;
167 const int FM007_BASE_ADDRESS = 0x17000000;
168 const int FM008_BASE_ADDRESS = 0x18000000;
169 const int FM103_BASE_ADDRESS = 0x19000000;
170 const int FM009_BASE_ADDRESS = 0x1a000000;
171 const int FM010_BASE_ADDRESS = 0x1b000000;
172 const int FM011_BASE_ADDRESS = 0x1c000000;
173 const int FM012_BASE_ADDRESS = 0x1d000000;
174 const int FM104_BASE_ADDRESS = 0x1e000000;
175 #endif
176 
177 // BBQ crate
178 const int BB001_BASE_ADDRESS = 0x10000000;
179 const int BB002_BASE_ADDRESS = 0x12000000;
180 const int BB003_BASE_ADDRESS = 0x14000000;
181 const int VP001_BASE_ADDRESS = 0x16000000;
182 const int VP002_BASE_ADDRESS = 0x18000000;
183 const int ZD001_BASE_ADDRESS = 0x1e000000;
184 
185 // MXQ crate
186 const int MT001_BASE_ADDRESS = 0x10000000;
187 const int PP001_BASE_ADDRESS = 0x12000000;
188 const int ZP001_BASE_ADDRESS = 0x14000000;
189 const int VP003_BASE_ADDRESS = 0x16000000;
190 const int VP004_BASE_ADDRESS = 0x18000000;
191 const int MT002_BASE_ADDRESS = 0x1a000000;
192 
193 struct Crate {
194  enum { NBOARDS = 18 };
195 
196  Board boards[NBOARDS];
197 
198  //const char* name() const { return crateNames[id]; }
199  const Board& boardAt(int i) const { return boards[(i>>24)-0x10]; }
200  Board& boardAt(int i) { return boards[(i>>24)-0x10]; }
201  void clear() { for_each(boards,boards+NBOARDS,mem_fun_ref(&Board::clear)); }
202  void read(const TriggerDataBlk& event, int id);
203  void decodeQT(const QTBlock& qt, int crate, int t=MAXPP);
204  unsigned long long swapLL(unsigned long long x);
205  void copy_and_swap(unsigned char* dest, const unsigned char* src);
206  void copy_and_swap(unsigned short* dest, const unsigned short* src);
207  void unpack(unsigned short* dest, const unsigned char* src);
208 };
209 
210 inline void Crate::read(const TriggerDataBlk& event, int id){
211  printf("CRATE::READ CALLED!!!\n");
212 /*
213  clear();
214  switch (id) {
215  // DSM crates
216  case L1_CONF_NUM:
217  if (L1_DSM_Data* L1data = (L1_DSM_Data*)((char*)&event+event.L1_DSM_ofl.offset)) {
218  assert(strncmp(L1data->name,"L1DS",4) == 0);
219  copy_and_swap(boardAt(TF201_BASE_ADDRESS).channels,L1data->TOF);
220  copy_and_swap(boardAt(VT201_BASE_ADDRESS).channels,L1data->VTX);
221  copy_and_swap(boardAt(EM201_BASE_ADDRESS).channels,L1data->EMC);
222  copy_and_swap(boardAt(EM202_BASE_ADDRESS).channels,L1data->TPCMask);
223  copy_and_swap(boardAt(BX201_BASE_ADDRESS).channels,L1data->BCdata);
224  copy_and_swap(boardAt(BX202_BASE_ADDRESS).channels,L1data->BCdata+8);
225  copy_and_swap(boardAt(ST201_BASE_ADDRESS).channels,L1data->specialTriggers);
226  copy_and_swap(boardAt(FP201_BASE_ADDRESS).channels,L1data->FPD);
227  copy(L1data->lastDSM,L1data->lastDSM+8,boardAt(LD301_BASE_ADDRESS).channels); // new TCU
228  }
229  break;
230  case BC1_CONF_NUM:
231  if (event.MainX[BC1_CONF_NUM].offset && event.MainX[BC1_CONF_NUM].length) {
232  BELayerBlock* bc1 = (BELayerBlock*)((char*)&event+event.MainX[BC1_CONF_NUM].offset);
233  assert(strncmp(bc1->name,"BC1",3) == 0);
234  copy_and_swap(boardAt(BC101_BASE_ADDRESS).channels,bc1->BEMClayer1);
235  copy_and_swap(boardAt(BC102_BASE_ADDRESS).channels,bc1->BEMClayer1+8);
236  copy_and_swap(boardAt(BC103_BASE_ADDRESS).channels,bc1->BEMClayer1+16);
237  copy_and_swap(boardAt(BC104_BASE_ADDRESS).channels,bc1->BEMClayer1+24);
238  copy_and_swap(boardAt(BC105_BASE_ADDRESS).channels,bc1->BEMClayer1+32);
239  copy_and_swap(boardAt(BC106_BASE_ADDRESS).channels,bc1->BEMClayer1+40);
240  copy_and_swap(boardAt(EE101_BASE_ADDRESS).channels,bc1->EEMClayer1);
241  copy_and_swap(boardAt(EE102_BASE_ADDRESS).channels,bc1->EEMClayer1+8);
242  unsigned char buffer[16];
243  copy_and_swap(buffer,bc1->EEMC); unpack(boardAt(EE001_BASE_ADDRESS).channels,buffer);
244  copy_and_swap(buffer,bc1->EEMC+16); unpack(boardAt(EE002_BASE_ADDRESS).channels,buffer);
245  copy_and_swap(buffer,bc1->EEMC+32); unpack(boardAt(EE003_BASE_ADDRESS).channels,buffer);
246  copy_and_swap(buffer,bc1->EEMC+48); unpack(boardAt(EE004_BASE_ADDRESS).channels,buffer);
247  copy_and_swap(buffer,bc1->EEMC+64); unpack(boardAt(EE005_BASE_ADDRESS).channels,buffer);
248  copy_and_swap(buffer,bc1->EEMC+80); unpack(boardAt(EE006_BASE_ADDRESS).channels,buffer);
249  copy_and_swap(buffer,bc1->EEMC+96); unpack(boardAt(EE007_BASE_ADDRESS).channels,buffer);
250  copy_and_swap(buffer,bc1->EEMC+112); unpack(boardAt(EE008_BASE_ADDRESS).channels,buffer);
251  copy_and_swap(buffer,bc1->EEMC+128); unpack(boardAt(EE009_BASE_ADDRESS).channels,buffer);
252  }
253  break;
254  case MIX_CONF_NUM:
255  if (event.MainX[MIX_CONF_NUM].offset && event.MainX[MIX_CONF_NUM].length) {
256  MIXBlock* mix = (MIXBlock*)((char*)&event+event.MainX[MIX_CONF_NUM].offset);
257  assert(strncmp(mix->name,"MIX",3) == 0);
258  copy_and_swap(boardAt(FE101_BASE_ADDRESS).channels,mix->FPDEastNSLayer1);
259  copy_and_swap((unsigned char*)boardAt(MT101_BASE_ADDRESS).channels,mix->MTD_P2PLayer1);
260  copy_and_swap(boardAt(TF101_BASE_ADDRESS).channels,mix->TOFLayer1);
261  copy_and_swap(boardAt(TF001_BASE_ADDRESS).channels,mix->TOF);
262  copy_and_swap(boardAt(TF002_BASE_ADDRESS).channels,mix->TOF+8);
263  copy_and_swap(boardAt(TF003_BASE_ADDRESS).channels,mix->TOF+16);
264  copy_and_swap(boardAt(TF004_BASE_ADDRESS).channels,mix->TOF+24);
265  copy_and_swap(boardAt(TF005_BASE_ADDRESS).channels,mix->TOF+32);
266  copy_and_swap(boardAt(TF006_BASE_ADDRESS).channels,mix->TOF+40);
267  }
268  break;
269  case BCW_CONF_NUM:
270  if (event.MainX[BCW_CONF_NUM].offset && event.MainX[BCW_CONF_NUM].length) {
271  BWestBlock* bcw = (BWestBlock*)((char*)&event+event.MainX[BCW_CONF_NUM].offset);
272  assert(strncmp(bcw->name,"BCW",3) == 0);
273  unsigned char buffer[16];
274  copy_and_swap(buffer,bcw->BEMCWest); unpack(boardAt(BW001_BASE_ADDRESS).channels,buffer);
275  copy_and_swap(buffer,bcw->BEMCWest+16); unpack(boardAt(BW002_BASE_ADDRESS).channels,buffer);
276  copy_and_swap(buffer,bcw->BEMCWest+32); unpack(boardAt(BW003_BASE_ADDRESS).channels,buffer);
277  copy_and_swap(buffer,bcw->BEMCWest+48); unpack(boardAt(BW004_BASE_ADDRESS).channels,buffer);
278  copy_and_swap(buffer,bcw->BEMCWest+64); unpack(boardAt(BW005_BASE_ADDRESS).channels,buffer);
279  copy_and_swap(buffer,bcw->BEMCWest+80); unpack(boardAt(BW006_BASE_ADDRESS).channels,buffer);
280  copy_and_swap(buffer,bcw->BEMCWest+96); unpack(boardAt(BW007_BASE_ADDRESS).channels,buffer);
281  copy_and_swap(buffer,bcw->BEMCWest+112); unpack(boardAt(BW008_BASE_ADDRESS).channels,buffer);
282  copy_and_swap(buffer,bcw->BEMCWest+128); unpack(boardAt(BW009_BASE_ADDRESS).channels,buffer);
283  copy_and_swap(buffer,bcw->BEMCWest+144); unpack(boardAt(BW010_BASE_ADDRESS).channels,buffer);
284  copy_and_swap(buffer,bcw->BEMCWest+160); unpack(boardAt(BW011_BASE_ADDRESS).channels,buffer);
285  copy_and_swap(buffer,bcw->BEMCWest+176); unpack(boardAt(BW012_BASE_ADDRESS).channels,buffer);
286  copy_and_swap(buffer,bcw->BEMCWest+192); unpack(boardAt(BW013_BASE_ADDRESS).channels,buffer);
287  copy_and_swap(buffer,bcw->BEMCWest+208); unpack(boardAt(BW014_BASE_ADDRESS).channels,buffer);
288  copy_and_swap(buffer,bcw->BEMCWest+224); unpack(boardAt(BW015_BASE_ADDRESS).channels,buffer);
289  }
290  break;
291  case BCE_CONF_NUM:
292  if (event.MainX[BCE_CONF_NUM].offset && event.MainX[BCE_CONF_NUM].length) {
293  BEastBlock* bce = (BEastBlock*)((char*)&event+event.MainX[BCE_CONF_NUM].offset);
294  assert(strncmp(bce->name,"BCE",3) == 0);
295  unsigned char buffer[16];
296  copy_and_swap(buffer,bce->BEMCEast); unpack(boardAt(BE001_BASE_ADDRESS).channels,buffer);
297  copy_and_swap(buffer,bce->BEMCEast+16); unpack(boardAt(BE002_BASE_ADDRESS).channels,buffer);
298  copy_and_swap(buffer,bce->BEMCEast+32); unpack(boardAt(BE003_BASE_ADDRESS).channels,buffer);
299  copy_and_swap(buffer,bce->BEMCEast+48); unpack(boardAt(BE004_BASE_ADDRESS).channels,buffer);
300  copy_and_swap(buffer,bce->BEMCEast+64); unpack(boardAt(BE005_BASE_ADDRESS).channels,buffer);
301  copy_and_swap(buffer,bce->BEMCEast+80); unpack(boardAt(BE006_BASE_ADDRESS).channels,buffer);
302  copy_and_swap(buffer,bce->BEMCEast+96); unpack(boardAt(BE007_BASE_ADDRESS).channels,buffer);
303  copy_and_swap(buffer,bce->BEMCEast+112); unpack(boardAt(BE008_BASE_ADDRESS).channels,buffer);
304  copy_and_swap(buffer,bce->BEMCEast+128); unpack(boardAt(BE009_BASE_ADDRESS).channels,buffer);
305  copy_and_swap(buffer,bce->BEMCEast+144); unpack(boardAt(BE010_BASE_ADDRESS).channels,buffer);
306  copy_and_swap(buffer,bce->BEMCEast+160); unpack(boardAt(BE011_BASE_ADDRESS).channels,buffer);
307  copy_and_swap(buffer,bce->BEMCEast+176); unpack(boardAt(BE012_BASE_ADDRESS).channels,buffer);
308  copy_and_swap(buffer,bce->BEMCEast+192); unpack(boardAt(BE013_BASE_ADDRESS).channels,buffer);
309  copy_and_swap(buffer,bce->BEMCEast+208); unpack(boardAt(BE014_BASE_ADDRESS).channels,buffer);
310  copy_and_swap(buffer,bce->BEMCEast+224); unpack(boardAt(BE015_BASE_ADDRESS).channels,buffer);
311  }
312  break;
313  case BBC_CONF_NUM:
314  if (event.MainX[BBC_CONF_NUM].offset && event.MainX[BBC_CONF_NUM].length) {
315  BBCBlock* bbc = (BBCBlock*)((char*)&event+event.MainX[BBC_CONF_NUM].offset);
316  assert(strncmp(bbc->name,"BBC",3) == 0);
317  copy_and_swap(boardAt(BB101_BASE_ADDRESS).channels,bbc->BBClayer1);
318  copy_and_swap(boardAt(BB102_BASE_ADDRESS).channels,bbc->BBClayer1+8);
319  copy_and_swap(boardAt(ZD101_BASE_ADDRESS).channels,bbc->ZDClayer1);
320  copy_and_swap(boardAt(VP101_BASE_ADDRESS).channels,bbc->VPD);
321  }
322  break;
323  case FMS_CONF_NUM:
324  if (event.MainX[FMS_CONF_NUM].offset && event.MainX[FMS_CONF_NUM].length) {
325  FMSBlock* fms = (FMSBlock*)((char*)&event+event.MainX[FMS_CONF_NUM].offset);
326  assert(strncmp(fms->name,"FMS",3) == 0);
327  copy_and_swap((unsigned char*)boardAt(FM001_BASE_ADDRESS).channels,fms->FMS);
328  copy_and_swap((unsigned char*)boardAt(FM002_BASE_ADDRESS).channels,fms->FMS+16);
329  copy_and_swap((unsigned char*)boardAt(FM003_BASE_ADDRESS).channels,fms->FMS+32);
330  copy_and_swap((unsigned char*)boardAt(FM004_BASE_ADDRESS).channels,fms->FMS+48);
331  copy_and_swap((unsigned char*)boardAt(FM101_BASE_ADDRESS).channels,fms->FMS+64);
332  copy_and_swap((unsigned char*)boardAt(FM005_BASE_ADDRESS).channels,fms->FMS+80);
333  copy_and_swap((unsigned char*)boardAt(FM006_BASE_ADDRESS).channels,fms->FMS+96);
334  copy_and_swap((unsigned char*)boardAt(FM007_BASE_ADDRESS).channels,fms->FMS+112);
335  copy_and_swap((unsigned char*)boardAt(FM008_BASE_ADDRESS).channels,fms->FMS+128);
336  copy_and_swap((unsigned char*)boardAt(FM102_BASE_ADDRESS).channels,fms->FMS+144);
337  copy_and_swap((unsigned char*)boardAt(FM009_BASE_ADDRESS).channels,fms->FMS+160);
338  copy_and_swap((unsigned char*)boardAt(FM010_BASE_ADDRESS).channels,fms->FMS+176);
339  copy_and_swap((unsigned char*)boardAt(FM011_BASE_ADDRESS).channels,fms->FMS+192);
340  copy_and_swap((unsigned char*)boardAt(FM012_BASE_ADDRESS).channels,fms->FMS+208);
341  copy_and_swap((unsigned char*)boardAt(FM103_BASE_ADDRESS).channels,fms->FMS+224);
342  }
343  break;
344  // QT crates
345  case MXQ_CONF_NUM:
346  case FEQ_CONF_NUM:
347  case BBQ_CONF_NUM:
348  case QT1_CONF_NUM:
349  case QT2_CONF_NUM:
350  case QT3_CONF_NUM:
351  case QT4_CONF_NUM:
352  if (event.MainX[id].offset && event.MainX[id].length) {
353  QTBlock* qt = (QTBlock*)((char*)&event+event.MainX[id].offset);
354  assert(strncmp(qt->name,crateNames[id],3) == 0);
355  decodeQT(*qt,id);
356  }
357  break;
358  default:
359  break;
360  }
361 */
362 }
363 
364 inline void Crate::decodeQT(const QTBlock& qt, int crate, int t){
365  int sz = qt.length/4;
366  assert(qt.data[sz-1] == 0xac10);
367  for (int i = 0; i < sz-1;) {
368  // Header
369  int h = qt.data[i++];
370  assert(crate == (h >> 24 & 0xff));
371  int nlines = h & 0xff;
372  int addr = h >> 16 & 0xff;
373  assert(0x10 <= addr && addr < 0x20);
374  addr -= 0x10;
375  // Data
376  while (nlines--) {
377  int d = qt.data[i++];
378  int ch = d >> 27 & 0x1f;
379  assert(0 <= ch && ch < 32);
380  boards[addr].channels[t][ch] = d & 0xfff;
381  }
382  }
383 }
384 
385 inline unsigned long long Crate::swapLL(unsigned long long x)
386 {
387  return ((x & 0xffff000000000000ull) >> 48 |
388  (x & 0x0000ffff00000000ull) >> 16 |
389  (x & 0x00000000ffff0000ull) << 16 |
390  (x & 0x000000000000ffffull) << 48);
391 }
392 
393 inline void Crate::copy_and_swap(unsigned char* dest, const unsigned char* src)
394 {
395  unsigned long long* x = (unsigned long long*)src;
396  unsigned long long* y = (unsigned long long*)dest;
397 
398  *y = bswap_64(*x); ++x; ++y;
399  *y = bswap_64(*x); ++x; ++y;
400 }
401 
402 inline void Crate::copy_and_swap(unsigned short* dest, const unsigned short* src)
403 {
404  unsigned long long* x = (unsigned long long*)src;
405  unsigned long long* y = (unsigned long long*)dest;
406 
407  *y++ = swapLL(*x++);
408  *y++ = swapLL(*x++);
409 }
410 
411 inline void Crate::unpack(unsigned short* dest, const unsigned char* src)
412 {
413  const unsigned char* cpMin = src;
414  const unsigned char* cpMax = cpMin+15;
415  unsigned short* sp = dest;
416  for (const unsigned char* cp = cpMin; cp < cpMax; cp += 3) {
417  unsigned int* ip = (unsigned int*)cp;
418  *sp++ = *ip & 0xfff;
419  *sp++ = *ip >> 12 & 0xfff;
420  }
421 }
422 
423 #endif // CRATE_HH
Definition: Crate.hh:193
Definition: Board.hh:14