Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
oncsSub_idcaenv1742.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file oncsSub_idcaenv1742.cc
1 #include "oncsSub_idcaenv1742.h"
2 #include <cstring>
3 
5  :oncsSubevent_w4 (data)
6 {
7  samples = 0;
8  dlength = 0;
9 
10  evnr = 0;
11  freq=3;
12  group_mask=0;
13  int i;
14  for ( i=0; i< 4; i++)
15  {
16  index_cell[i] = 0;
17  tr_present[i] = 0;
18  }
19 
20 }
21 
22 int *oncsSub_idcaenv1742::decode ( int *nwout)
23 {
24  int *p;
25 
26 
27  int *SubeventData = &SubeventHdr->data;
28 
29 
30  // the first word must have 0xa in the MSB, and
31  // has the total payload size in bits 0-27
32  if ( (( *SubeventData >> 28) & 0xf ) != 0xa )
33  {
34  std::cout << "error in data structure" << std::endl;
35  return 0;
36  }
37  dlength = *SubeventData & 0x0fffffff;
38 
39  // word 1 has the group enable pattern
40  group_mask = SubeventData[1] & 0xf;
41 
42  // word 2 has the event counter in bits 0-21
43  evnr = SubeventData[2] & 0x3fffff;
44  // std::cout << "Evnt nr: " << evnr << std::endl;
45 
46  // and we ignore word 3 for now
47 
48  // before we go through the groups indexed by group_index,
49  // we take a peek into the first group to figure out how many samples we have.
50  // the sample count is the same for all groups, although each group encodes this
51  // value again. We use this value here up front to allocate the right amount of memory
52  // for the decoded waveforms.
53 
54  int size = SubeventData[4] & 0xfff;
55  samples = size / 3;
56 
57  p = new int [ samples * 8 * 4];
58  memset(p, 0, samples * 8 * 4 * sizeof(int));
59 
60  // the trigger waveform, if any
61  int *p_tr = new int [ samples * 4];
62  memset(p_tr, 0, samples * 4 * sizeof(int));
63  decoded_data2 = p_tr;
64  data2_length = samples *4;
65 
66 
67  // we also extract the sampling frequency here (encoded in each group but
68  // the same for all)
69  freq = (SubeventData[4] >> 16) & 3;
70 
71 
72  //now we go through the groups
73  int group_offset = 4;
74  int group_nr;
75 
76  for ( group_nr=0; group_nr < 4; group_nr++)
77  {
78  int pos = 0;
79 
80  if ( (group_mask >> group_nr) &1) // we have that group present
81  {
82  int *groupdata = &(SubeventData[group_offset]); // first group
83  tr_present[group_nr] = (groupdata[0] >> 12) & 1;
84  index_cell[group_nr] = (groupdata[0] >> 20) & 0x3ff;
85 
86 
87  // std::cout << "group " << group_nr << " size: " << size << std::endl;
88  // std::cout << "contains_tr: " << tr_present[group_nr] << std::endl;
89  // std::cout << "frequency : " << freq << std::endl;
90  // std::cout << "index cell : " << index_cell[group_nr] << std::endl;
91 
92  int s, ch;
93  pos = 1;
94 
95  for ( s = 0; s < samples; s++ )
96  {
97  ch = 0;
98  p[group_nr*samples*8 + samples * ch++ + s] =( groupdata[pos] & 0xfff);
99  p[group_nr*samples*8 + samples * ch++ + s] =(groupdata[pos] >> 12) & 0xfff;
100  p[group_nr*samples*8 + samples * ch++ + s] = ((groupdata[pos] >> 24) & 0xff) + ( (groupdata[pos+1] & 0xf)<<8);
101 
102  p[group_nr*samples*8 + samples * ch++ + s] =(groupdata[pos+1] >> 4) & 0xfff;
103  p[group_nr*samples*8 + samples * ch++ + s] =(groupdata[pos+1] >> 16) & 0xfff;
104  p[group_nr*samples*8 + samples * ch++ + s] =((groupdata[pos+1] >> 28) & 0xf) + ( (groupdata[pos+2] & 0xff)<<4);
105 
106  p[group_nr*samples*8 + samples * ch++ + s] =(groupdata[pos+2] >> 8) & 0xfff;
107  p[group_nr*samples*8 + samples * ch++ + s] =(groupdata[pos+2] >> 20) & 0xfff;
108  pos +=3;
109 
110  }
111  if ( tr_present[group_nr])
112  {
113  s = 0;
114  while (s < samples)
115  {
116  p_tr[group_nr*samples + s++] = ( groupdata[pos] & 0xfff);
117  p_tr[group_nr*samples + s++] =(groupdata[pos] >> 12) & 0xfff;
118  p_tr[group_nr*samples + s++] = ((groupdata[pos] >> 24) & 0xff) + ( (groupdata[pos+1] & 0xf)<<8);
119 
120  p_tr[group_nr*samples + s++] =(groupdata[pos+1] >> 4) & 0xfff;
121  p_tr[group_nr*samples + s++] =(groupdata[pos+1] >> 16) & 0xfff;
122  p_tr[group_nr*samples + s++] =((groupdata[pos+1] >> 28) & 0xf) + ( (groupdata[pos+2] & 0xff)<<4);
123 
124  p_tr[group_nr*samples + s++] =(groupdata[pos+2] >> 8) & 0xfff;
125  p_tr[group_nr*samples + s++] =(groupdata[pos+2] >> 20) & 0xfff;
126  pos +=3;
127  }
128  }
129  }
130  group_offset += pos + 1;
131  }
132  *nwout = samples*8 *4;
133 
134  return p;
135 
136 }
137 
139 {
140 
142 
143  if ( ch < 0 || ch >= data1_length ) return 0;
144 
145  return decoded_data1[ch];
146 
147 }
148 
149 int oncsSub_idcaenv1742::iValue(const int sample, const int ch)
150 {
151 
153 
154  //if ( ch < 0 || ch >= 32 ) return 0;
155  if ( ch < 0 || ch >= 36 ) return 0;
156  if ( sample < 0 || sample >= samples ) return 0;
157 
158  //return decoded_data1[ch*samples + sample];
159  return (ch < 32 ? decoded_data1[ch*samples + sample] : decoded_data2[(ch-32)*samples + sample]);
160 
161 }
162 
163 int oncsSub_idcaenv1742::iValue(const int n,const char *what)
164 {
165 
167 
168  if ( strcmp(what,"SAMPLES") == 0 )
169  {
170  return samples;
171  }
172 
173  if ( strcmp(what,"EVNR") == 0 )
174  {
175  return evnr;
176  }
177 
178  if ( strcmp(what,"TR0") == 0 )
179  {
180  if ( n <0 || n >=samples) return 0;
181 
182  return decoded_data2[n];
183  }
184 
185  if ( strcmp(what,"TR1") == 0 )
186  {
187  if ( n <0 || n >=samples) return 0;
188 
189  return decoded_data2[2*samples + n];
190  }
191 
192  if ( strcmp(what,"TR0-0") == 0 )
193  {
194  if ( n <0 || n >=samples) return 0;
195 
196  return decoded_data2[ n];
197  }
198  if ( strcmp(what,"TR0-1") == 0 )
199  {
200  if ( n <0 || n >=samples) return 0;
201 
202  return decoded_data2[1*samples + n];
203  }
204  if ( strcmp(what,"TR1-0") == 0 )
205  {
206  if ( n <0 || n >=samples) return 0;
207 
208  return decoded_data2[2*samples + n];
209  }
210  if ( strcmp(what,"TR1-1") == 0 )
211  {
212  if ( n <0 || n >=samples) return 0;
213 
214  return decoded_data2[3*samples + n];
215  }
216 
217  if ( strcmp(what,"INDEXCELL") == 0 )
218  {
219  if ( n <0 || n >=4) return 0;
220 
221  return index_cell[n];
222  }
223 
224  if ( strcmp(what,"TRPRESENT") == 0 )
225  {
226  if ( n <0 || n >=4) return 0;
227 
228  return tr_present[n];
229  }
230 
231  if ( strcmp(what,"FREQUENCY") == 0 )
232  {
233  return freq;
234  }
235 
236  if ( strcmp(what,"GROUPPRESENT") == 0 )
237  {
238  if ( n <0 || n >=4) return 0;
239  return (group_mask >> n) &1;
240  }
241 
242  return 0;
243 
244 }
245 
246 
248 {
249  int i,j;
250  // int *SubeventData = &SubeventHdr->data;
251 
252  os << "Samples: " << iValue(0,"SAMPLES") << std::endl;
253  os << "Evt Nr: " << iValue(0,"EVNR") << std::endl;
254  int f = iValue(0,"FREQUENCY") ;
255  os << "Sample Frequency ";
256  switch (f)
257  {
258  case 0:
259  os << " 5 GS/s ";
260  break;
261 
262  case 1:
263  os << " 2.5 GS/s ";
264  break;
265 
266  case 2:
267  os << " 1 GS/s ";
268  break;
269 
270  default:
271  os << " Unknown ";
272  break;
273  }
274  os << "("<< f << ")" << std::endl;
275 
276  os << "Group present: ";
277  for ( i = 0; i < 4; i++)
278  {
279  os<< iValue(i, "GROUPPRESENT") << " ";
280  }
281  os << std::endl;
282 
283 
284  os << "contains trigger sample: ";
285  for ( i = 0; i < 4; i++)
286  {
287  os<< iValue(i, "TRPRESENT") << " ";
288  }
289  os << std::endl;
290 
291  os << "index cell: ";
292  for ( i = 0; i < 4; i++)
293  {
294  os<< iValue(i, "INDEXCELL") << " ";
295  }
296  os << std::endl;
297  os << std::endl;
298 
299 
300  for ( i = 0; i < samples ; i++)
301  {
302  os << std::setw(4) << i << " | ";
303 
304  for ( j = 0; j < 32 ; j++)
305  {
306 
307  os << std::setw(4) << iValue(i,j) << " ";
308  }
309  os << " tr: " << iValue(i, "TR0") << std::endl;
310  }
311 
312  os << std::endl;
313 }