EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
oncsSub_iduppetdata_v104.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file oncsSub_iduppetdata_v104.cc
2 #include <cstring>
3 
4 #include <arpa/inet.h>
5 
6 using namespace std;
7 
9  :oncsSubevent_w4 (data)
10 {
11  samples = 0;
12  d_time = 0;
13  d_timelength = 0;
14  lval = 0;
15  tval = 0;
16  serialnumber = 0;
17  udpheader1 = 0;
18  udpheader2 = 0;
19  sysword = 0;
20  eventrate = 0;
21  ratcap_upenn = 0;
22  clock_sel = 0;
23 }
24 
26 {
27  if ( d_timelength )
28  {
29  delete [] d_time;
30  d_time = 0;
31  }
32  if ( lval)
33  {
34  delete [] lval;
35  lval = 0;
36  }
37  if ( tval)
38  {
39  delete [] tval;
40  tval = 0;
41  }
42 }
43 
44 
46 {
47  int *p;
48 
49 
50 
51  int i;
52 
53  unsigned int *SubeventData = (unsigned int *) &SubeventHdr->data;
54 
55  unsigned short *sdata = ( unsigned short *) &SubeventData[4];
56 
57  int dlength = getLength()-4 - getPadding();
58 
59  samples = (dlength - 3) /2;
60 
61  p = new int [samples]; // block id
62 
63  decoded_data2 = new int [samples]; // crystal id
65 
66  decoded_data3 = new int [samples]; // rfgate
68 
69  decoded_data4 = new int [samples]; // cardiac
71 
72  lval = new long long [samples]; // raw samples
73  tval = new long long [samples]; // binary time
74 
75  d_time = new double [samples]; // time
77 
78  serialnumber = ntohl(SubeventData[0]);
79  udpheader1 = ntohl(SubeventData[1]);
80  udpheader2 = ntohl(SubeventData[2]);
81  sysword = ntohl(SubeventData[3]);
82 
83  eventrate = sysword & 0xfffffff;
84  ratcap_upenn = ( sysword >> 28 ) & 1;
85  clock_sel = ( sysword >> 29 ) & 1;
86 
87 
88 
89  int k = 0;
90 
91  for ( i = 0; i < 2*(dlength-4); i+=4 )
92  {
93 
94  unsigned long long y;
95  unsigned long long x64 = ntohs( sdata[i+3]);
96  x64 <<= 48;
97 
98  y = ntohs( sdata[i+2]);
99  y <<=32;
100  x64 |= y;
101 
102  y = ntohs( sdata[i+1]);
103  y <<=16;
104  x64 |= y;
105 
106  y = ntohs( sdata[i]);
107  x64 |= y;
108 
109  unsigned long long t = x64 & 0x3fffffffffffL;
110  unsigned int crystalid = ( x64 >> 52) & 0x1f;
111  unsigned int block = ( x64 >> 57) & 0x1f;
112  unsigned int rfgate = ( x64 >> 62) & 0x1;
113  unsigned int cardiac = ( x64 >> 63) & 0x1;
114 
115  p[k] = block;
116  decoded_data2[k] = crystalid;
117  lval[k] = x64;
118  tval[k] = t;
119  d_time[k] = t;
120  decoded_data3[k] = rfgate;
121  decoded_data4[k] = cardiac;
122  k++;
123 
124  // cout << k<< endl;
125 
126  // cout << hex << x << dec << " "
127  // << " time: " << t
128  // << " block: " << block
129  // << " chan: " << channel
130  // << " rfgate " << rfgate
131  // << " Cardiac " << cardiac
132  // << endl;
133  }
134 
135  // samples = k;
136  *nwout = k;
137  return p;
138 }
139 
140 int oncsSub_iduppetdata_v104::iValue(const int ich,const char *what)
141 {
142 
144 
145  if ( strcmp(what,"SAMPLES") == 0 )
146  {
147  return samples;
148  }
149 
150  if ( strcmp(what,"BLOCKID") == 0 )
151  {
152  if ( ich < 0 || ich >= samples) return 0;
153  return decoded_data1[ich];
154  }
155 
156  if ( strcmp(what,"CRYSTALID") == 0 )
157  {
158  if ( ich < 0 || ich >= samples) return 0;
159  return decoded_data2[ich];
160  }
161 
162  if ( strcmp(what,"RFGATE") == 0 )
163  {
164  if ( ich < 0 || ich >= samples) return 0;
165  return decoded_data3[ich];
166  }
167 
168  if ( strcmp(what,"CARDIAC") == 0 )
169  {
170  if ( ich < 0 || ich >= samples) return 0;
171  return decoded_data4[ich];
172  }
173 
174  if ( strcmp(what,"SERIAL") == 0 )
175  {
176  return serialnumber;
177  }
178 
179  if ( strcmp(what,"UDPHEADER1") == 0 )
180  {
181  return udpheader1;
182  }
183 
184  if ( strcmp(what,"UDPHEADER2") == 0 )
185  {
186  return udpheader2;
187  }
188 
189  if ( strcmp(what,"EVENTRATE") == 0 )
190  {
191  return eventrate;
192  }
193 
194  if ( strcmp(what,"RC_UP") == 0 )
195  {
196  return ratcap_upenn;
197  }
198 
199  if ( strcmp(what,"CLOCKSELECT") == 0 )
200  {
201  return clock_sel;
202  }
203 
204  return 0;
205 
206 }
207 
208 double oncsSub_iduppetdata_v104::dValue(const int ich)
209 {
210 
212 
213  if ( ich < 0 || ich >= samples) return 0;
214  return d_time[ich];
215 }
216 
217 long long oncsSub_iduppetdata_v104::lValue(const int ich)
218 {
219 
221 
222  if ( ich < 0 || ich >= samples) return 0;
223  return lval[ich];
224 }
225 
227 {
228 
229  identify(os);
230 
231  int i;
232  int is = iValue(0,"SAMPLES");
233 
234 
235  os << " Format: ";
236  if ( iValue(0, "RC_UP") )
237  {
238  os << "Ratcap ";
239  }
240  else
241  {
242  os << "UPenn ";
243  }
244  os << endl;
245 
246  os << " Clock setting: ";
247  if ( iValue(0, "CLOCKSELECT") )
248  {
249  os << "Fine ";
250  }
251  else
252  {
253  os << "Coarse ";
254  }
255  os << endl;
256 
257  os << " Event rate: " << iValue(0,"EVENTRATE") << endl;
258  os << " UDP Header 1, 2: " << iValue(0,"UDPHEADER1")
259  << " " << iValue(0,"UDPHEADER2") << endl;
260  os << " Serial Number : " << iValue(0,"SERIAL") << endl;
261 
262  os << " Samples: " << iValue(0,"SAMPLES") << std::endl;
263  os << " sample B id C id time ( " << is << " Samples )" << std::endl;
264 
265  for ( i = 0; i < is ; i++)
266  {
267  int prec = os.precision();
268 
269  os << std::setw(5) << i << " | ";
270 
271  os << std::setw(4) << iValue(i,"BLOCKID") << " ";
272  os << std::setw(4) << iValue(i,"CRYSTALID") << " ";
273  os << std::setw(24) << std::setprecision(24) << hex
274  //<< tval[i]
275  << dValue(i)
276  << dec << std::setprecision(prec) << " " ;
277  os << std::setw(24) << std::setprecision(24) << hex << lValue(i) << dec
278  << std::setprecision(prec) ;
279 
280  os << std::endl;
281  }
282  os << std::endl;
283 }
284