StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
trgReader22.cxx
1 #include <stdio.h>
2 #include <string.h>
3 #include <arpa/inet.h>
4 
5 #include <rtsLog.h>
6 
7 #include <rtsSystems.h>
8 
9 // This reader works for TRG_VERSIONS: 0x21 (FY04 run); 0x22 (Nov 04)
10 
11 // one needs to diffuse the crummy trigger stuff first
12 #define TRG_VERSION 0x22
13 #include <daqFormats.h>
14 #include <rts.h> // for the sake of swap32 entry
15 
16 
17 #include "daq_trg.h"
18 
19 // this maps from the raw data to the following representation
20 // sector1,slat1,ch1 ... ch5, sector1,slat2,ch1.... ch5, sector2,slat1,ch1...
21 
22 static unsigned char ctbMap[240] = {
23 7, 6, 5, 4, 3, 23, 22, 21, 20, 19,
24 2, 1, 0, 15, 14, 18, 17, 16, 31, 30,
25 13, 12, 11, 10, 9, 29, 28, 27, 26, 25,
26 39, 38, 37, 36, 35, 55, 54, 53, 52, 51,
27 34, 33, 32, 47, 46, 50, 49, 48, 63, 62,
28 45, 44, 43, 42, 41, 61, 60, 59, 58, 57,
29 71, 70, 69, 68, 67, 87, 86, 85, 84, 83,
30 66, 65, 64, 79, 78, 82, 81, 80, 95, 94,
31 77, 76, 75, 74, 73, 93, 92, 91, 90, 89,
32 103, 102, 101, 100, 99, 119, 118, 117, 116, 115,
33 98, 97, 96, 111, 110, 114, 113, 112, 127, 126,
34 109, 108, 107, 106, 105, 125, 124, 123, 122, 121,
35 135, 134, 133, 132, 131, 151, 150, 149, 148, 147,
36 130, 129, 128, 143, 142, 146, 145, 144, 159, 158,
37 141, 140, 139, 138, 137, 157, 156, 155, 154, 153,
38 167, 166, 165, 164, 163, 183, 182, 181, 180, 179,
39 162, 161, 160, 175, 174, 178, 177, 176, 191, 190,
40 173, 172, 171, 170, 169, 189, 188, 187, 186, 185,
41 199, 198, 197, 196, 195, 215, 214, 213, 212, 211,
42 194, 193, 192, 207, 206, 210, 209, 208, 223, 222,
43 205, 204, 203, 202, 201, 221, 220, 219, 218, 217,
44 231, 230, 229, 228, 227, 247, 246, 245, 244, 243,
45 226, 225, 224, 239, 238, 242, 241, 240, 255, 254,
46 237, 236, 235, 234, 233, 253, 252, 251, 250, 249,
47 } ;
48 
49 
50 static unsigned char mwcMap[96] = {
51 71, 70, 69, 68, 67, 66, 65, 64, 79, 78, 77, 76,
52 95, 94, 93, 92, 87, 86, 85, 84, 83, 82, 81, 80,
53 99, 98, 97, 96, 111, 110, 109, 108, 103, 102, 101, 100,
54 119, 118, 117, 116, 115, 114, 113, 112, 127, 126, 125, 124,
55 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12,
56 31, 30, 29, 28, 23, 22, 21, 20, 19, 18, 17, 16,
57 35, 34, 33, 32, 47, 46, 45, 44, 39, 38, 37, 36,
58 55, 54, 53, 52, 51, 50, 49, 48, 63, 62, 61, 60,
59 } ;
60 
61 
62 static TrgSumData trg_sum ;
63 
64 // read the Trigger RAW data
65 int trgReader22(char *arg, struct trg_t *trg)
66 {
67  int i ;
68  int sdes, ssum, sraw ;
69  int len ;
70 
71 
72  struct TRGD *trgd = (struct TRGD *)arg ;
73 
74  int swap = 0;
75  if(trgd->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swap=1;
76 
77  len = swap ? swap32(trgd->bh.length)*4 : trgd->bh.length*4;
78 
79  sdes = sizeof(trgd->bh) + sizeof(trgd->desc) ;
80  ssum = sdes + sizeof(trgd->sum) ;
81  sraw = ssum + sizeof(trgd->raw[0]) ;
82 
83  if(len < ssum) {
84  LOG(NOTE,"No TRG Summaries, or Raw...",0,0,0,0,0) ;
85  return 0 ;
86  }
87  else if(len < sraw) {
88  LOG(NOTE,"TRG: Summaries ONLY!",0,0,0,0,0) ;
89  return 0 ;
90  }
91 
92  LOG(DBG,"len %d, desc len %d, sum len %d, raw trg 0 len %d, all raw len %d",
93  len,sizeof(trgd->desc),sizeof(trgd->sum),sizeof(trgd->raw[0]),sizeof(trgd->raw)) ;
94 
95  LOG(DBG,"evt desc bytes %d, sum bytes %d, raw bytes %d",trgd->desc.TCUdataBytes,
96  trgd->sum.TrgSumBytes,trgd->raw[0].RawDetBytes,0,0) ;
97 
98 
99  trg->npre = swap ? swap16(trgd->desc.npre) : trgd->desc.npre ;
100  trg->npost = swap ? swap16(trgd->desc.npost) : trgd->desc.npost ;
101 
102  trg->xing_lo = swap ? swap32(trgd->desc.bunchXing_lo) : trgd->desc.bunchXing_lo ;
103  trg->xing_hi = swap ? swap32(trgd->desc.bunchXing_hi) : trgd->desc.bunchXing_hi ;
104 
105  trg->phys_word = swap ? swap16(trgd->desc.physicsWord) : trgd->desc.physicsWord ;
106  trg->trg_word = swap ? swap16(trgd->desc.TriggerWord) : trgd->desc.TriggerWord ;
107 
108  trg->trgd = (void *) trgd ;
109 
110 // what the hell did I mean by this "40 is spurious"???
111 // int trg_length = len - sizeof(struct bankHeader) - 40 ; // 40 is supurious
112 
113  int trg_length = len - sizeof(struct bankHeader) ;
114  int exp_length = sizeof(EvtDescData) + sizeof(trgd->sum) + sizeof(trgd->raw[0]) +
115  sizeof(trgd->raw[0])*trg->npre + sizeof(trgd->raw[0])*trg->npost ;
116 
117  if(trg_length != exp_length) {
118  LOG(NOTE,"Trigger data: is %d, expect %d bytes, trg->npre %d, trg->npost %d",
119  trg_length, exp_length,trg->npre,trg->npost,0) ;
120  }
121  else {
122  LOG(DBG,"Trigger data: is %d, expect %d bytes, trg->npre %d, trg->npost %d",
123  trg_length, exp_length,trg->npre,trg->npost,0) ;
124  }
125 
126  // get the last DSM aka TCU bits
127  trg->tcubits = swap ? swap16(trgd->desc.DSMInput) : trgd->desc.DSMInput;
128  trg->detlive = swap ? swap16(trgd->desc.externalBusy) : trgd->desc.externalBusy ;
129 
130 
131  LOG(DBG,"TrgDataFmtVer 0x%X, 0x%04X %c %c", trgd->desc.TrgDataFmtVer,
132  trgd->sum.TrgSumHeader,
133  trgd->raw[0].CTBdataHeader[0],
134  trgd->raw[0].CTBdataHeader[1],0) ;
135 
136  LOG(DBG,"TrgSumBytes %d, 0x%04X %c %c %c", trgd->sum.TrgSumBytes,
137  trgd->sum.L0SumHeader,
138  trgd->raw[0].RawDetHeader[0],
139  trgd->raw[0].RawDetHeader[1],0) ;
140 
141 
142 
143 
144  // Trigger Summary
145  // set pointer & clear all to 0
146  trg->trg_sum = (void *) &trg_sum ;
147  memset(&trg_sum,0,sizeof(trg_sum)) ;
148 
149  for(i=0;i<2;i++) {
150  trg_sum.L1Sum[i] = swap ? swap32(trgd->sum.L1Sum[i]) : trgd->sum.L1Sum[i] ;
151  trg_sum.L2Sum[i] = swap ? swap32(trgd->sum.L2Sum[i]) : trgd->sum.L2Sum[i] ;
152  }
153 
154 
155 // Arghhh, I wish I had some generic programming tools...
156 #define REAL_BAD_HACK(x) trg_sum.DSMdata.x = (swap ? swap16(trgd->sum.DSMdata.x) : trgd->sum.DSMdata.x)
157 
158  for(i=0;i<32;i++) {
159  REAL_BAD_HACK(CPA[i]) ;
160  }
161  for(i=0;i<16;i++) {
162  REAL_BAD_HACK(BCdata[i]) ;
163  }
164 
165  for(i=0;i<8;i++) {
166  REAL_BAD_HACK(quadDSM[i]) ;
167  REAL_BAD_HACK(lastDSM[i]) ;
168  REAL_BAD_HACK(VTX[i]) ;
169  REAL_BAD_HACK(EMC[i]) ;
170  REAL_BAD_HACK(specialTriggers[i]) ;
171  REAL_BAD_HACK(FPD[i]) ;
172  }
173 
174 #undef REAL_BAD_HACK
175 
176 
177  // RAW data stuff. Just the crossing - NOT pre/post!
178 
179 
180  for(i=0;i<240;i++) {
181  trg->CTB[i] = trgd->raw[0].CTB[ctbMap[i]] ;
182  }
183 
184  for(i=0;i<96;i++) {
185  trg->MWC[i] = trgd->raw[0].MWC[mwcMap[i]] ;
186  }
187 
188  // east
189  for(i=0;i<240;i++) {
190  trg->BEMC[0][i] = trgd->raw[0].BEMCEast[i] ;
191  }
192  // west
193  for(i=0;i<240;i++) {
194  trg->BEMC[1][i] = trgd->raw[0].BEMCWest[i] ;
195  }
196  // layer1
197  for(i=0;i<48;i++) {
198  trg->BEMC_l1[i] = swap ? swap16(trgd->raw[0].BEMClayer1[i]) : trgd->raw[0].BEMClayer1[i] ;
199  }
200 
201 
202 
203  for(i=0;i<144;i++) {
204  trg->EEMC[i] = trgd->raw[0].EEMC[i] ;
205  }
206  for(i=0;i<16;i++) {
207  trg->EEMC_l1[i] = swap ? swap16(trgd->raw[0].EEMClayer1[i]) : trgd->raw[0].EEMClayer1[i];
208  }
209 
210  // FPD:
211  // first index is 0 East, 1 West
212  // second index is 0 NortSouth, 1 TopBottom
213  // East, NS
214  for(i=0;i<112;i++) {
215  trg->FPD[0][0][i] = trgd->raw[0].FPDEastNSLayer0[i] ;
216  }
217  for(i=0;i<8;i++) {
218  trg->FPD_l1[0][0][i] = swap ? swap16(trgd->raw[0].FPDEastNSLayer1[i]) : trgd->raw[0].FPDEastNSLayer1[i] ;
219  }
220  // East, TB
221  for(i=0;i<64;i++) {
222  trg->FPD[0][1][i] = trgd->raw[0].FPDEastTBLayer0[i] ;
223  }
224  for(i=0;i<8;i++) {
225  trg->FPD_l1[0][1][i] = swap ? swap16(trgd->raw[0].FPDEastTBLayer1[i]) : trgd->raw[0].FPDEastTBLayer1[i] ;
226  }
227  // West, NS
228  for(i=0;i<112;i++) {
229  trg->FPD[1][0][i] = trgd->raw[0].FPDWestNSLayer0[i] ;
230  }
231  for(i=0;i<8;i++) {
232  trg->FPD_l1[1][0][i] = swap ? swap16(trgd->raw[0].FPDWestNSLayer1[i]) : trgd->raw[0].FPDWestNSLayer1[i];
233  }
234  // West, TB
235  for(i=0;i<64;i++) {
236  trg->FPD[1][1][i] = trgd->raw[0].FPDWestTBLayer0[i] ;
237  }
238  for(i=0;i<8;i++) {
239  trg->FPD_l1[1][1][i] = swap ? swap16(trgd->raw[0].FPDWestTBLayer1[i]) : trgd->raw[0].FPDWestTBLayer1[i];
240  }
241 
242 
243 
244  // get the size from trgStructures.h
245  for(i=0;i<(int)sizeof(trgd->raw[0].BBC)/(int)sizeof(trgd->raw[0].BBC[0]);i++) {
246  trg->BBC[i] = trgd->raw[0].BBC[i] ;
247  }
248 
249  for(i=0;i<16;i++) {
250  trg->BBC_l1[i] = swap ? swap16(trgd->raw[0].BBClayer1[i]) : trgd->raw[0].BBClayer1[i] ;
251  }
252 
253  for(i=0;i<16;i++) {
254  trg->ZDC[i] = trgd->raw[0].ZDC[i] ;
255  }
256  for(i=0;i<8;i++) {
257  trg->ZDC_l1[i] = swap ? swap16(trgd->raw[0].ZDClayer1[i]) : trgd->raw[0].ZDClayer1[i];
258  }
259 
260  for(i=0;i<32;i++) {
261  trg->ZDCSMD[i] = trgd->raw[0].ZDCSMD[i] ;
262  }
263 
264 
265 /*
266  int j ;
267  for(j=0;j<11;j++) {
268  for(i=0;i<16;i++) {
269  printf("pre %d, ZDC %d = %u\n",j,i,trgd->raw[j].ZDC[i]) ;
270  }
271  for(i=0;i<8;i++) {
272  printf("pre %d, ZDC_l1 %d = %u\n",j,i,b2h16(trgd->raw[j].ZDClayer1[i])) ;
273  }
274  }
275 */
276 
277  return len ;
278 }
279 
Definition: daq_trg.h:9