StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
trgReader20.cxx
1 #include <stdio.h>
2 #include <string.h>
3 #include <arpa/inet.h>
4 
5 #include <rtsLog.h>
6 
7 
8 #include <rtsSystems.h>
9 
10 // one needs to diffuse the crummy trigger stuff first
11 #define TRG_VERSION 0x20
12 #include <daqFormats.h>
13 
14 
15 #include <rts.h> // fror the sake of swap32 entry
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 
63 
64 // read the Trigger RAW data
65 int trgReader20(char *arg, struct trg_t *trg)
66 {
67  int i ;
68  int sdes, ssum, sraw ;
69  int len ;
70 
71  struct TRGD *trgd = (struct TRGD *)arg ;
72 
73  int swap = 0;
74  if(trgd->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swap=1;
75 
76  len = swap ? swap32(trgd->bh.length)*4 : trgd->bh.length;
77 
78  sdes = sizeof(trgd->bh) + sizeof(trgd->desc) ;
79  ssum = sdes + sizeof(trgd->sum) ;
80  sraw = ssum + sizeof(trgd->raw[0]) ;
81 
82  if(len < ssum) {
83  LOG(NOTE,"No TRG Summaries, or Raw...",0,0,0,0,0) ;
84  return 0 ;
85  }
86  else if(len < sraw) {
87  LOG(NOTE,"TRG: Summaries ONLY!",0,0,0,0,0) ;
88  return 0 ;
89  }
90 
91  LOG(DBG,"len %d, desc len %d, sum len %d, raw trg 0 len %d, all raw len %d",
92  len,sizeof(trgd->desc),sizeof(trgd->sum),sizeof(trgd->raw[0]),sizeof(trgd->raw)) ;
93 
94  LOG(DBG,"evt desc bytes %d, sum bytes %d, raw bytes %d",trgd->desc.TCUdataBytes,
95  trgd->sum.TrgSumBytes,trgd->raw[0].RawDetBytes,0,0) ;
96 
97  int pre, post ;
98 
99  pre = swap ? swap16(trgd->desc.npre) : trgd->desc.npre ;
100  post = swap ? swap16(trgd->desc.npost) : trgd->desc.npost ;
101 
102  int trg_length = len - sizeof(struct bankHeader) - 40 ; // 40 is supurious
103  int exp_length = sizeof(EvtDescData) + sizeof(trgd->sum) + sizeof(trgd->raw[0]) +
104  sizeof(trgd->raw[0])*pre + sizeof(trgd->raw[0])*post ;
105 
106  if(trg_length != exp_length) {
107  LOG(NOTE,"Trigger data: is %d, expect %d bytes, pre %d, post %d",
108  trg_length, exp_length,pre,post,0) ;
109  }
110  else {
111  LOG(DBG,"Trigger data: is %d, expect %d bytes, pre %d, post %d",
112  trg_length, exp_length,pre,post,0) ;
113  }
114 
115  // get the last DSM aka TCU bits
116  trg->tcubits = swap ? swap16(trgd->desc.DSMInput) : trgd->desc.DSMInput;
117  trg->detlive = swap ? swap16(trgd->desc.externalBusy) : trgd->desc.externalBusy ;
118 
119 
120  LOG(DBG,"TrgDataFmtVer 0x%X, 0x%04X %c %c", trgd->desc.TrgDataFmtVer,
121  trgd->sum.TrgSumHeader,
122  trgd->raw[0].CTBdataHeader[0],
123  trgd->raw[0].CTBdataHeader[1],0) ;
124 LOG(DBG,"TrgSumBytes %d, 0x%04X %c %c %c", trgd->sum.TrgSumBytes,
125  trgd->sum.L0SumHeader,
126  trgd->raw[0].RawDetHeader[0],
127  trgd->raw[0].RawDetHeader[1],0) ;
128 
129  for(i=0;i<240;i++) {
130  trg->CTB[i] = trgd->raw[0].CTB[ctbMap[i]] ;
131  }
132 
133  for(i=0;i<96;i++) {
134  trg->MWC[i] = trgd->raw[0].MWC[mwcMap[i]] ;
135  }
136 
137  // east
138  for(i=0;i<240;i++) {
139  trg->BEMC[0][i] = trgd->raw[0].BEMCEast[i] ;
140  }
141  // west
142  for(i=0;i<240;i++) {
143  trg->BEMC[1][i] = trgd->raw[0].BEMCWest[i] ;
144  }
145  // layer1
146  for(i=0;i<48;i++) {
147  trg->BEMC_l1[i] = swap ? swap16(trgd->raw[0].BEMClayer1[i]) : trgd->raw[0].BEMClayer1[i] ;
148  }
149 
150 
151 
152  for(i=0;i<144;i++) {
153  trg->EEMC[i] = trgd->raw[0].EEMC[i] ;
154  }
155  for(i=0;i<16;i++) {
156  trg->EEMC_l1[i] = swap ? swap16(trgd->raw[0].EEMClayer1[i]) : trgd->raw[0].EEMClayer1[i];
157  }
158 
159  // FPD:
160  // first index is 0 East, 1 West
161  // second index is 0 NortSouth, 1 TopBottom
162  // East, NS
163  for(i=0;i<112;i++) {
164  trg->FPD[0][0][i] = trgd->raw[0].FPDEastNSLayer0[i] ;
165  }
166  for(i=0;i<8;i++) {
167  trg->FPD_l1[0][0][i] = swap ? swap16(trgd->raw[0].FPDEastNSLayer1[i]) : trgd->raw[0].FPDEastNSLayer1[i] ;
168  }
169  // East, TB
170  for(i=0;i<64;i++) {
171  trg->FPD[0][1][i] = trgd->raw[0].FPDEastTBLayer0[i] ;
172  }
173  for(i=0;i<8;i++) {
174  trg->FPD_l1[0][1][i] = swap ? swap16(trgd->raw[0].FPDEastTBLayer1[i]) : trgd->raw[0].FPDEastTBLayer1[i] ;
175  }
176  // West, NS
177  for(i=0;i<112;i++) {
178  trg->FPD[1][0][i] = trgd->raw[0].FPDWestNSLayer0[i] ;
179  }
180  for(i=0;i<8;i++) {
181  trg->FPD_l1[1][0][i] = swap ? swap16(trgd->raw[0].FPDWestNSLayer1[i]) : trgd->raw[0].FPDWestNSLayer1[i];
182  }
183  // West, TB
184  for(i=0;i<64;i++) {
185  trg->FPD[1][1][i] = trgd->raw[0].FPDWestTBLayer0[i] ;
186  }
187  for(i=0;i<8;i++) {
188  trg->FPD_l1[1][1][i] = swap ? swap16(trgd->raw[0].FPDWestTBLayer1[i]) : trgd->raw[0].FPDWestTBLayer1[i];
189  }
190 
191 
192 
193 
194  for(i=0;i<80;i++) {
195  trg->BBC[i] = trgd->raw[0].BBC[i] ;
196  }
197  for(i=0;i<16;i++) {
198  trg->BBC_l1[i] = swap ? swap16(trgd->raw[0].BBClayer1[i]) : trgd->raw[0].BBClayer1[i] ;
199  }
200 
201 
202  for(i=0;i<16;i++) {
203  trg->ZDC[i] = trgd->raw[0].ZDC[i] ;
204  }
205  for(i=0;i<8;i++) {
206  trg->ZDC_l1[i] = swap ? swap16(trgd->raw[0].ZDClayer1[i]) : trgd->raw[0].ZDClayer1[i];
207  }
208 
209  trg->trg_sum = NULL ;
210 
211 
212 /*
213  int j ;
214  for(j=0;j<11;j++) {
215  for(i=0;i<16;i++) {
216  printf("pre %d, ZDC %d = %u\n",j,i,trgd->raw[j].ZDC[i]) ;
217  }
218  for(i=0;i<8;i++) {
219  printf("pre %d, ZDC_l1 %d = %u\n",j,i,b2h16(trgd->raw[j].ZDClayer1[i])) ;
220  }
221  }
222 */
223 
224  return len ;
225 }
226 
Definition: daq_trg.h:9