EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
oncsSub_iduppetdata.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file oncsSub_iduppetdata.cc
1 #include "oncsSub_iduppetdata.h"
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 
20 }
21 
23 {
24  if ( d_timelength )
25  {
26  delete [] d_time;
27  d_time = 0;
28  }
29  if ( lval)
30  {
31  delete [] lval;
32  lval = 0;
33  }
34  if ( tval)
35  {
36  delete [] tval;
37  tval = 0;
38  }
39 }
40 
41 
42 int *oncsSub_iduppetdata::decode ( int *nwout)
43 {
44  int *p;
45 
46 
47  int i;
48 
49  unsigned int *SubeventData = (unsigned int *) &SubeventHdr->data;
50 
51  unsigned short *sdata = ( unsigned short *) &SubeventData[3];
52 
53  int dlength = getLength()-4 - getPadding();
54 
55  samples = (dlength - 3) /2;
56 
57  p = new int [samples]; // block id
58 
59  decoded_data2 = new int [samples]; // crystal id
61 
62  decoded_data3 = new int [samples]; // rfgate
64 
65  decoded_data4 = new int [samples]; // cardiac
67 
68  lval = new long long [samples]; // raw samples
69  tval = new long long [samples]; // binary time
70 
71  d_time = new double [samples]; // time
73 
74  serialnumber = ntohl(SubeventData[0]);
75  udpheader1 = ntohl(SubeventData[1]);
76  udpheader2 = ntohl(SubeventData[2]);
77 
78  int k = 0;
79 
80  for ( i = 0; i < 2*(dlength-4); i+=4 )
81  {
82 
83  unsigned long long y;
84  unsigned long long x64 = ntohs( sdata[i+3]);
85  x64 <<= 48;
86 
87  y = ntohs( sdata[i+2]);
88  y <<=32;
89  x64 |= y;
90 
91  y = ntohs( sdata[i+1]);
92  y <<=16;
93  x64 |= y;
94 
95  y = ntohs( sdata[i]);
96  x64 |= y;
97 
98 
99  unsigned long long t = x64 & 0xfffffffffffL;
100  unsigned int crystalid = ( x64 >> 52) & 0x1f;
101  unsigned int block = ( x64 >> 57) & 0x1f;
102  unsigned int rfgate = ( x64 >> 62) & 0x1;
103  unsigned int cardiac = ( x64 >> 63) & 0x1;
104 
105  p[k] = block;
106  decoded_data2[k] = crystalid;
107  lval[k] = x64;
108  tval[k] = t;
109  d_time[k] = t;
110  decoded_data3[k] = rfgate;
111  decoded_data4[k] = cardiac;
112  k++;
113 
114  // cout << k<< endl;
115 
116  // cout << hex << x << dec << " "
117  // << " time: " << t
118  // << " block: " << block
119  // << " chan: " << channel
120  // << " rfgate " << rfgate
121  // << " Cardiac " << cardiac
122  // << endl;
123  }
124 
125  // samples = k;
126  *nwout = k;
127  return p;
128 }
129 
130 int oncsSub_iduppetdata::iValue(const int ich,const char *what)
131 {
132 
134 
135  if ( strcmp(what,"SAMPLES") == 0 )
136  {
137  return samples;
138  }
139 
140  if ( strcmp(what,"BLOCKID") == 0 )
141  {
142  if ( ich < 0 || ich >= samples) return 0;
143  return decoded_data1[ich];
144  }
145 
146  if ( strcmp(what,"CRYSTALID") == 0 )
147  {
148  if ( ich < 0 || ich >= samples) return 0;
149  return decoded_data2[ich];
150  }
151 
152  if ( strcmp(what,"RFGATE") == 0 )
153  {
154  if ( ich < 0 || ich >= samples) return 0;
155  return decoded_data3[ich];
156  }
157 
158  if ( strcmp(what,"CARDIAC") == 0 )
159  {
160  if ( ich < 0 || ich >= samples) return 0;
161  return decoded_data4[ich];
162  }
163 
164  return 0;
165 
166 }
167 
168 double oncsSub_iduppetdata::dValue(const int ich)
169 {
170 
172 
173  if ( ich < 0 || ich >= samples) return 0;
174  return d_time[ich];
175 }
176 
177 long long oncsSub_iduppetdata::lValue(const int ich)
178 {
179 
181 
182  if ( ich < 0 || ich >= samples) return 0;
183  return lval[ich];
184 }
185 
187 {
188 
189 
190  int i;
191  int is = iValue(0,"SAMPLES");
192 
193  // os << "Samples: " << iValue(0,"SAMPLES") << std::endl;
194 
195  os << " sample B id C id time ( " << is << " Samples )" << std::endl;
196 
197  for ( i = 0; i < is ; i++)
198  {
199  int prec = os.precision();
200 
201  os << std::setw(5) << i << " | ";
202 
203  os << std::setw(4) << iValue(i,"BLOCKID") << " ";
204  os << std::setw(4) << iValue(i,"CRYSTALID") << " ";
205  os << std::setw(24) << std::setprecision(24) << hex << tval[i]
206  << dec << std::setprecision(prec) << " " ;
207  os << std::setw(24) << std::setprecision(24) << hex << lValue(i) << dec
208  << std::setprecision(prec) ;
209 
210  os << std::endl;
211  }
212  os << std::endl;
213 }
214