Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
packet_idll1v1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file packet_idll1v1.cc
1 #include "packet_idll1v1.h"
2 
3 #include <string.h>
4 
5 using namespace std;
6 
8  :Packet_w4 (data)
9 {
10 
11  _slot_nr = 0;
12  _card_nr = 0;
13  _nsamples = 0;
14  _evt_nr = 0;
15  _clock = 0;
16 
17  _nchannels = 13*4 + 8;
18  _even_checksum = 0;
19  _odd_checksum = 0;
20 
23 
24  _even_checksum_ok = -1; // -1 convention: "cannot be evaluated", typically for 0-supp. data
25  _odd_checksum_ok = -1; // else ok =1, not ok 0.
26 
27  _is_decoded = 0;
28 
29 
30 }
31 
32 
34 {
35  // if (array) delete [][] array;
36 }
37 
38 
39 
40 const int offset=2;
41 // const int samples=12;
42 // const int channels=64;
43 
44 
46 {
47 
48 
49  if (_is_decoded ) return 0;
50  _is_decoded = 1;
51 
52 
53  int *k;
54 
55 
56  // check later int dlength = ( getLength()-4) - getPadding();
57 
58  int *SubeventData = (int *) findPacketDataStart(packet);
59 
60  switch ( getHitFormat() )
61  {
62  case IDLL1_20S:
63  _nsamples = 20;
64  _hitbits = 6;
65  break;
66  case IDLL1v2_20S:
67  _nsamples = 20;
68  _hitbits = 7;
69  default:
70  _nsamples = 20;
71  _hitbits = 7;
72  break;
73  }
74 
75  int upperbits[10] = { 15,
76  15,
77  _hitbits,
78  _hitbits,
79  _hitbits,
80  _hitbits,
81  9,
82  10,
83  16,
84  25};
85 
86  _slot_nr = (SubeventData[0] & 0xffff) / 2;
87  _card_nr = (SubeventData[0] & 0xffff) % 2;
88 
89  _clock = (SubeventData[1] & 0xffff) ;
90  _evt_nr = ((SubeventData[1] >> 16) & 0xffff) ;
91 
92 
93  int index = getDataLength() - 1;
94  _even_checksum = (SubeventData[index] >> 16) & 0xffff;
95  _odd_checksum = SubeventData[index] & 0xffff;
96 
97  k = &SubeventData[offset];
98 
99  int is;
100 
101  int ia, ib, iw, ijk, iturn;
102  int count;
103  for (is=0; is< _nsamples; is++ ) {
104 
105  for (ia = 0; ia < 20; ia++)
106  {
107 
108  array[2*ia][is] = (k[(ia*_nsamples) + is] & 0xffff) ;
109  array[2*ia + 1][is] = ((k[(ia*_nsamples) + is] >> 16 ) & 0xffff) ;
110 
111  }
112 
113  for (ia=0; ia<4; ia++) {
114  ijk = ia*8;
115  itrig_charge[ia][0][is] = array[ijk][is] & 0x1ff; //8-0
116  itrig_charge[ia][1][is] = ((array[ijk][is] & 0xfe00) >>9) + ((array[ijk+1][is] & 0x3)<<7) ; //17-9
117  itrig_charge[ia][2][is] = ((array[ijk+1][is] & 0x7fc) >>2) ; //26-18
118  itrig_charge[ia][3][is] = ((array[ijk+1][is] & 0xf800) >>11) + ((array[ijk+2][is] & 0xf)<<5) ; //35-27
119  itrig_charge[ia][4][is] = ((array[ijk+2][is] & 0x1ff0) >>4) ; //44-36
120  itrig_charge[ia][5][is] = ((array[ijk+2][is] & 0xe000) >>13) + ((array[ijk+3][is] & 0x3f)<<3) ; //53-45
121  itrig_charge[ia][6][is] = ((array[ijk+3][is] & 0x7fc0) >>6) ; //62-54
122  itrig_charge[ia][7][is] = ((array[ijk+3][is] & 0x8000) >>15) + ((array[ijk+4][is] & 0xff)<<1) ; //71-63
123  itrig_nhit[ia][is] = (array[ijk+4][is] & 0xff00) >> 8;
124  itrig_time[ia][0][is] = array[ijk+5][is] & 0xfff; //91-80
125  itrig_time[ia][1][is] = ((array[ijk+5][is] & 0xf000) >>12) + ((array[ijk+6][is] & 0xff)<<4) ; //103-92
126  itrig_time[ia][2][is] = ((array[ijk+6][is] & 0xff00) >>8) + ((array[ijk+7][is] & 0xf)<<8) ; //115- 104
127  itrig_time[ia][3][is] = (array[ijk+7][is] & 0xfff0)>>4; //127-116
128  }
129 
130  ijk = 32;
131  ib = 0;
132  iturn = 0;
133  count = 0;
134  for (ia = 0; ia < 8; ia++)
135  {
136  triggerwords[ia][is] = 0;
137  for (iw = 0 ; iw < upperbits[ia] ; iw++)
138  {
139  if (iw+ib == 16)
140  {
141  ib = iw;
142  ijk++;
143  iturn = 1 - iturn;
144 
145  }
146 
147  if (!iturn) triggerwords[ia][is] += ((array[ijk][is] & (0x1 << (ib+iw))) >> ib);
148  else triggerwords[ia][is] += ((array[ijk][is] & (0x1 << (iw - ib))) << ib);
149 
150  // if (is == 8 || is == 9 ) cout << dec<< count << "= ia: "<<ia<<" , sample "<<is<<", iw/ib/turn: "<<iw<<"/"<<ib<<"/"<<iturn<<" --> "<< hex<<triggerwords[ia][is]<<endl;
151 
152  count++;
153  }
154  ib = (iturn? iw-ib: iw+ib);
155  iturn = 0;
156  }
157 
158  // triggerwords[0][is] = array[32][is] & 0x7fff;
159  // triggerwords[1][is] = ((array[32][is] & 0x8000)>>15)+((array[33][is] & 0x3fff) <<1);
160  // triggerwords[2][is] = ((array[33][is] & 0xc000)>>14)+((array[34][is] & 0xf) <<2);
161  // triggerwords[3][is] = ((array[34][is] & 0x03f0)>>4);
162  // triggerwords[4][is] = ((array[34][is] & 0xfc00)>>10);
163  // triggerwords[5][is] = (array[35][is] & 0x3f);
164  // triggerwords[6][is] = ((array[35][is] & 0x7fc0)>>6);
165  // triggerwords[7][is] = ((array[35][is] & 0x8000)>>15)+((array[36][is] & 0x1ff) <<1);
166 
167  }
168 
169  for ( index = 5; index < getDataLength()-3; index+=2) // -3 to spare the CS fields out
170  {
171  _calculated_even_checksum ^= (SubeventData[index]) & 0xffff;
172  _calculated_odd_checksum ^= (SubeventData[index+1] >> 16 ) & 0xffff;
173  }
174 
175  return 0;
176 }
177 
178 
179 int Packet_idll1v1::iValue(const int sample, const int ch)
180 {
181  decode();
182 
183  if ( sample >= _nsamples || sample < 0
184  || ch >= _nchannels || ch < 0 ) return 0;
185 
186  if (ch < 52)
187  {
188  if (ch%13 < 8)
189  {
190  return itrig_charge[ch/13][ch%13][sample];
191  }
192  else if (ch%13 == 8)
193  {
194  return itrig_nhit[ch/13][sample];
195  }
196  else
197  {
198  return itrig_time[ch/13][(ch - 9)%13][sample];
199  }
200  }
201  return triggerwords[ch - 52][sample];
202 
203 }
204 
205 int Packet_idll1v1::iValue(const int n, const char *what)
206 {
207 
208  decode();
209 
210  if ( strcmp(what,"CLOCK") == 0 )
211  {
212  return _clock;
213  }
214 
215  if ( strcmp(what,"EVTNR") == 0 )
216  {
217  return _evt_nr;
218  }
219 
220  if ( strcmp(what,"SAMPLES") == 0 )
221  {
222  return _nsamples;
223  }
224 
225  if ( strcmp(what,"CHANNELS") == 0 )
226  {
227  return _nchannels;
228  }
229 
230  if ( strcmp(what,"SLOTNR") == 0 )
231  {
232  return _slot_nr;
233  }
234 
235  if ( strcmp(what,"CARDNR") == 0 )
236  {
237  return _card_nr;
238  }
239 
240  if ( strcmp(what,"EVENCHECKSUM") == 0 )
241  {
242  return _even_checksum;
243  }
244 
245  if ( strcmp(what,"ODDCHECKSUM") == 0 )
246  {
247  return _odd_checksum;
248  }
249 
250  if ( strcmp(what,"CALCEVENCHECKSUM") == 0 )
251  {
253  }
254 
255  if ( strcmp(what,"CALCODDCHECKSUM") == 0 )
256  {
258  }
259 
260  if ( strcmp(what,"EVENCHECKSUMOK") == 0 )
261  {
262  if ( _calculated_even_checksum < 0 ) return -1; // cannot evaluate
263  if ( _even_checksum == _calculated_even_checksum) return 1;
264  return 0;
265  }
266 
267  if ( strcmp(what,"ODDCHECKSUMOK") == 0 )
268  {
269  if ( _calculated_odd_checksum < 0 ) return -1; // cannot evaluate
270  if ( _odd_checksum == _calculated_odd_checksum) return 1;
271  return 0;
272  }
273 
274 
275  return 0;
276 
277 }
278 
280 {
281  identify(os);
282 
283  os << "Evt Nr: " << iValue(0,"EVTNR") << std::endl;
284  os << "Clock: " << iValue(0,"CLOCK") << std::endl;
285  os << "Channels: " << iValue(0,"CHANNELS") << std::endl;
286  os << "Samples: " << iValue(0,"SAMPLES") << std::endl;
287 
288  os << "Slot: " << iValue(0,"SLOTNR") << std::endl;
289  os << "Card: " << iValue(0,"CARDNR") << std::endl;
290 
291  os << "Even chksum: 0x" << hex << iValue(0,"EVENCHECKSUM") << " calculated: 0x" << iValue(0,"CALCEVENCHECKSUM");
292  if ( iValue(0,"EVENCHECKSUMOK") == 1) os << " ok" << endl;
293  else if ( iValue(0,"EVENCHECKSUMOK") == 0) os << " **wrong" << endl;
294 
295  os << "Odd chksum: 0x" << hex << iValue(0,"ODDCHECKSUM") << " calculated: 0x" << iValue(0,"CALCODDCHECKSUM");
296  if ( iValue(0,"ODDCHECKSUMOK") == 1) os << " ok" << endl;
297  else if ( iValue(0,"ODDCHECKSUMOK") == 0) os << " **wrong" << endl;
298  os << dec << endl;
299 
300  for ( int c = 0; c < 4; c++)
301  {
302  for (int j = 0; j < 13; j++)
303  {
304  os << setw(4) << c << " " << j << " | ";
305 
306  os << hex;
307  for ( int s = 0; s < _nsamples; s++)
308  {
309  os << setw(6) << iValue(s,c*13 + j);
310  }
311  os << dec << endl;
312  }
313  }
314 
315  for (int j = 0; j < 8; j++)
316  {
317  os << setw(4) << 25 << " " << j << " | ";
318 
319  os << hex;
320  for ( int s = 0; s < _nsamples; s++)
321  {
322  os << setw(6) << iValue(s, 52 + j);
323  }
324  os << dec << endl;
325  }
326 
327 }