ECCE @ EIC 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 ( sample < 0 || sample >= samples ) return 0;
156 
157  return decoded_data1[ch*samples + sample];
158 
159 }
160 
161 int oncsSub_idcaenv1742::iValue(const int n,const char *what)
162 {
163 
165 
166  if ( strcmp(what,"SAMPLES") == 0 )
167  {
168  return samples;
169  }
170 
171  if ( strcmp(what,"EVNR") == 0 )
172  {
173  return evnr;
174  }
175 
176  if ( strcmp(what,"TR0") == 0 )
177  {
178  if ( n <0 || n >=samples) return 0;
179 
180  return decoded_data2[n];
181  }
182 
183  if ( strcmp(what,"TR1") == 0 )
184  {
185  if ( n <0 || n >=samples) return 0;
186 
187  return decoded_data2[2*samples + n];
188  }
189 
190  if ( strcmp(what,"INDEXCELL") == 0 )
191  {
192  if ( n <0 || n >=4) return 0;
193 
194  return index_cell[n];
195  }
196 
197  if ( strcmp(what,"TRPRESENT") == 0 )
198  {
199  if ( n <0 || n >=4) return 0;
200 
201  return tr_present[n];
202  }
203 
204  if ( strcmp(what,"FREQUENCY") == 0 )
205  {
206  return freq;
207  }
208 
209  return 0;
210 
211 }
212 
213 
215 {
216  int i,j;
217  // int *SubeventData = &SubeventHdr->data;
218 
219  os << "Samples: " << iValue(0,"SAMPLES") << std::endl;
220  os << "Evt Nr: " << iValue(0,"EVNR") << std::endl;
221  int f = iValue(0,"FREQUENCY") ;
222  os << "Sample Frequency ";
223  switch (f)
224  {
225  case 0:
226  os << " 5 GS/s ";
227  break;
228 
229  case 1:
230  os << " 2.5 GS/s ";
231  break;
232 
233  case 2:
234  os << " 1 GS/s ";
235  break;
236 
237  default:
238  os << " Unknown ";
239  break;
240  }
241  os << "("<< f << ")" << std::endl;
242 
243  os << "contains trigger sample: ";
244  for ( i = 0; i < 4; i++)
245  {
246  os<< iValue(i, "TRPRESENT") << " ";
247  }
248  os << std::endl;
249 
250  os << "index cell: ";
251  for ( i = 0; i < 4; i++)
252  {
253  os<< iValue(i, "INDEXCELL") << " ";
254  }
255  os << std::endl;
256  os << std::endl;
257 
258 
259  for ( i = 0; i < samples ; i++)
260  {
261  os << std::setw(4) << i << " | ";
262 
263  for ( j = 0; j < 32 ; j++)
264  {
265 
266  os << std::setw(4) << iValue(i,j) << " ";
267  }
268  os << " tr: " << iValue(i, "TR0") << std::endl;
269  }
270 
271  os << std::endl;
272 }