13 #if defined(__linux__) || defined(__APPLE__)
14 #if defined(__linux__)
19 static inline unsigned short bswap_16(
unsigned short x) {
20 return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)) ;
22 static inline unsigned int bswap_32(
unsigned int x) {
23 return (bswap_16(x&0xffff)<<16) | (bswap_16(x>>16));
25 static inline unsigned long long bswap_64(
unsigned long long x) {
26 return (((
unsigned long long)bswap_32(x&0xffffffffull))<<32) |
37 #include "trgConfNum_fms.h"
38 #include "trgDataDefs_v45.h"
43 static const char* crateNames[] = { 0,
"L1",
"BC1",
"MXQ",
"MIX",
"BCW",
"BCE",
"FEQ",
"BBC",
"BBQ",
"FMS",
"QT1",
"QT2",
"QT3",
"QT4" };
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
194 enum { NBOARDS = 18 };
196 Board boards[NBOARDS];
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)); }
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);
211 printf(
"CRATE::READ CALLED!!!\n");
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;) {
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);
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;
385 inline unsigned long long Crate::swapLL(
unsigned long long x)
387 return ((x & 0xffff000000000000ull) >> 48 |
388 (x & 0x0000ffff00000000ull) >> 16 |
389 (x & 0x00000000ffff0000ull) << 16 |
390 (x & 0x000000000000ffffull) << 48);
393 inline void Crate::copy_and_swap(
unsigned char* dest,
const unsigned char* src)
395 unsigned long long* x = (
unsigned long long*)src;
396 unsigned long long* y = (
unsigned long long*)dest;
398 *y = bswap_64(*x); ++x; ++y;
399 *y = bswap_64(*x); ++x; ++y;
402 inline void Crate::copy_and_swap(
unsigned short* dest,
const unsigned short* src)
404 unsigned long long* x = (
unsigned long long*)src;
405 unsigned long long* y = (
unsigned long long*)dest;
411 inline void Crate::unpack(
unsigned short* dest,
const unsigned char* src)
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;
419 *sp++ = *ip >> 12 & 0xfff;