ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
oncsSubevent.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file oncsSubevent.cc
1 #include "oncsSubevent.h"
2 #include <string.h>
3 
4 
5 const char *oncs_get_mnemonic (const int structure,const int format);
6 const char *get_type_mnemonic (const int id);
7 const char *get_evt_mnemonic(const int id);
8 
9 
11 {
12  SubeventHdr = sevt_ptr;
13 
14  data1_length = 0;
15  data2_length = 0;
16  data3_length = 0;
17  data4_length = 0;
18 
19  decoded_data1 = NULL;
20  decoded_data2 = NULL;
21  decoded_data3 = NULL;
22  decoded_data4 = NULL;
23 
24  is_data_type = 0; //assume "p" type first.
25 
26 }
27 
29 {
30  if (decoded_data1 != NULL) delete [] decoded_data1;
31  if (decoded_data2 != NULL) delete [] decoded_data2;
32  if (decoded_data3 != NULL) delete [] decoded_data3;
33  if (decoded_data4 != NULL) delete [] decoded_data4;
34 
35  if (is_data_type) delete [] (int *) SubeventHdr;
36 }
37 
38 
39 
40 // ----------------------------------------------
41 
43 {
44  return SubeventHdr->sub_length;
45 }
46 
47 // ----------------------------------------------
48 
50 {
51  return SubeventHdr->sub_length -4;
52 }
53 
54 // ----------------------------------------------
55 
57 {
58  return SubeventHdr->sub_id;
59 }
60 
61 // ----------------------------------------------
62 //int oncsSubevent::get_type()
63 //{
64 // return SubeventHdr->sub_type;
65 //}
66 
67 // -----------------------------------------------
69 {
70  return SubeventHdr->sub_decoding;
71 }
72 
73 // -----------------------------------------------
75 {
76  return SubeventHdr->sub_padding;
77 }
78 
79 
80 
81 void oncsSubevent::identify( OSTREAM& out ) const
82 {
83  out << std::dec
84  << "Packet " << SETW(5) << getIdentifier()
85  << " " << SETW(5) << getLength()
86  << " -1" << " (sPHENIX Packet) ";
87 
88  out << SETW(3) << getHitFormat()
89  << " (" << oncs_get_mnemonic( getStructure(), getHitFormat()) << ")" << std::endl;
90 }
91 
92 
94 {
95  if (is_data_type) return 0;
96  else return 1;
97 }
98 
100 {
101  if (is_data_type) return -1;
102 
103  int *tmp;
104 
105  tmp = new int[getLength()];
106  int *from= (int *) SubeventHdr;
107  int *to=tmp;
108  for (int k=0; k< getLength(); k++)
109  {
110  *to++ = *from++;
111  }
112  SubeventHdr = ( subevtdata_ptr )tmp;
113  is_data_type = 1;
114  return 0;
115 
116 }
117 
118 
119 // ------------------------------------------------------
120 
121 int oncsSubevent::iValue(const int ich)
122 {
123  // now let's derefence the proxy array. If we didn't decode
124  // the data until now, we do it now
125  if (decoded_data1 == NULL )
126  {
127  if ( (decoded_data1 = decode(&data1_length))==NULL)
128  return 0;
129  }
130 
131  // see if our array is long enough
132  if (ich > data1_length) return 0;
133 
134  return decoded_data1[ich];
135 }
136 
137 // ------------------------------------------------------
138 
139 int oncsSubevent::iValue(const int ich, const char *what)
140 {
141  // now let's derefence the proxy array. If we didn't decode
142  // the data until now, we do it now
143  if (decoded_data1 == NULL )
144  {
145  if ( (decoded_data1 = decode(&data1_length))==NULL)
146  return 0;
147  }
148 
149  // see if our array is long enough
150  if (ich > data1_length) return 0;
151 
152  return decoded_data1[ich];
153 }
154 
155 // ------------------------------------------------------
156 
157 int oncsSubevent::iValue(const int ich, const int iy)
158 {
159  // now let's derefence the proxy array. If we didn't decode
160  // the data until now, we do it now
161  if (decoded_data1 == NULL )
162  {
163  if ( (decoded_data1 = decode(&data1_length))==NULL)
164  return 0;
165  }
166 
167  // see if our array is long enough
168  if (ich > data1_length) return 0;
169 
170  return decoded_data1[ich];
171 }
172 
173 // ------------------------------------------------------
174 
175 float oncsSubevent::rValue(const int ich)
176 {
177  // now let's derefence the proxy array. If we didn't decode
178  // the data until now, we do it now
179  if (decoded_data1 == NULL )
180  {
181  if ( (decoded_data1 = decode(&data1_length))==NULL)
182  return 0;
183  }
184 
185  // see if our array is long enough
186  if (ich > data1_length) return 0;
187 
188  return float(decoded_data1[ich]);
189 }
190 
191 // ------------------------------------------------------
192 
193 float oncsSubevent::rValue(const int ich, const char *what)
194 {
195  // now let's derefence the proxy array. If we didn't decode
196  // the data until now, we do it now
197  if (decoded_data1 == NULL )
198  {
199  if ( (decoded_data1 = decode(&data1_length))==NULL)
200  return 0;
201  }
202 
203  // see if our array is long enough
204  if (ich > data1_length) return 0;
205 
206  return float(decoded_data1[ich]);
207 }
208 
209 // ------------------------------------------------------
210 
211 float oncsSubevent::rValue(const int ich, const int iy)
212 {
213  // now let's derefence the proxy array. If we didn't decode
214  // the data until now, we do it now
215  if (decoded_data1 == NULL )
216  {
217  if ( (decoded_data1 = decode(&data1_length))==NULL)
218  return 0;
219  }
220 
221  // see if our array is long enough
222  if (ich > data1_length) return 0;
223 
224  return float(decoded_data1[ich]);
225 }
226 
227 // ----------------------------------------------
228 
229 int
231 {
232  // now let's derefence the proxy array. If we didn't decode
233  // the data until now, we do it now
234  if (decoded_data1 == NULL )
235  {
236  if ( (decoded_data1 = decode(&data1_length))==NULL)
237  return -1;
238  }
239 
240  return data1_length;
241 }
242 
243 // ----------------------------------------------
244 
245 int
247  const int nlen, int *nwout,
248  const char *what)
249 {
250 
251  if (strcmp(what,"") ==0)
252  {
253  // now let's derefence the proxy array. If we didn't decode
254  // the data until now, we do it now
255  if (decoded_data1 == NULL )
256  {
257  if ( (decoded_data1 = decode(&data1_length))==NULL)
258  {
259  *nwout=0;
260  return -1;
261  }
262  }
263 
264  // see if our array is long enough
265  if (nlen < data1_length) return -2;
266 
267  // and copy the data to the output array
268  int *from = decoded_data1;
269  for (int i=0; i<data1_length; i++) *iarr++ = *from++;
270 
271  // tell how much we copied
272  *nwout = data1_length;
273  }
274 
275  if (strcmp(what,"RAW") ==0)
276  {
277  if (nlen < getLength() ) return -2;
278  int *from = (int *) SubeventHdr;
279  for (int i=0; i<getLength(); i++) *iarr++ = *from++;
280 
281  *nwout = getLength();
282  }
283 
284  if (strcmp(what,"DATA") ==0)
285  {
286  if (nlen < getLength() -4 ) return -2;
287  int *from = &SubeventHdr->data;
288  for (int i=0; i<getLength() -4; i++) *iarr++ = *from++;
289 
290  *nwout = getLength()-4;
291  }
292  return 0;
293 }
294 
295 // ------------------------------------------------------
296 
297 int
299  const int nlen, int *nwout,
300  const char *what)
301 {
302 
303  // now let's derefence the proxy array. If we didn't decode
304  // the data until now, we do it now
305  if (decoded_data1 == NULL )
306  {
307  if ( (decoded_data1 = decode(&data1_length))==NULL)
308  {
309  *nwout=0;
310  return -1;
311  }
312  }
313 
314  // see if our array is long enough
315  if (nlen < data1_length) return -2;
316 
317  // and copy the data to the output array
318  int *from = decoded_data1;
319  for (int i=0; i<data1_length; i++) *rarr++ = float (*from++);
320 
321  // tell how much we copied
322  *nwout = data1_length;
323  return 0;
324 }
325 
326 // ------------------------------------------------------
327 int*
328 oncsSubevent::getIntArray (int *nwout, const char *what)
329 {
330 
331  // now let's derefence the proxy array. If we didn't decode
332  // the data until now, we do it now
333  if (decoded_data1 == NULL )
334  {
335  if ( (decoded_data1 = decode(&data1_length))==NULL)
336  {
337  *nwout=0;
338  return NULL;
339  }
340  }
341 
342  int *temp=new int[data1_length];
343  int is = fillIntArray(temp, data1_length, nwout);
344  if (is)
345  {
346  *nwout=0;
347  return NULL;
348  }
349  return temp;
350 }
351 
352 // ------------------------------------------------------
353 float* oncsSubevent::getFloatArray (int *nwout, const char *what)
354 {
355  // now let's derefence the proxy array. If we didn't decode
356  // the data until now, we do it now
357  if (decoded_data1 == NULL )
358  {
359  if ( (decoded_data1 = decode(&data1_length))==NULL)
360  {
361  *nwout=0;
362  return NULL;
363  }
364  }
365 
366  float *temp=new float[data1_length];
367  int is = fillFloatArray(temp, data1_length, nwout);
368  if (is)
369  {
370  *nwout=0;
371  return NULL;
372  }
373  return temp;
374 }
375 
376 // ----------------------------------------------
377 
378 
379 
380 // now the member functions common to all
381 // the individial p1, p2, and p4 classes.
382 
383 // ------------Constructors first -----------------
384 
386  : oncsSubevent(sevt_ptr)
387 {}
388 
390  : oncsSubevent(sevt_ptr)
391 {}
392 
394  : oncsSubevent(sevt_ptr)
395 {}
396 
397 // ---- and the dump routines, which just call the
398 // ---- generic dump routines, but may be overloaded
399 // ---- by the subclasses.
400 
401 void oncsSubevent_w1::dump(OSTREAM& out) { gdump(2,out);}
402 void oncsSubevent_w2::dump(OSTREAM& out) { gdump(2,out);}
403 void oncsSubevent_w4::dump(OSTREAM& out) { gdump(2,out);}
404 
405 void oncsSubevent_w4::gdump(const int i, OSTREAM& out) const
406 {
407 
408  int *SubeventData = &SubeventHdr->data;
409 
410  if ( i == EVT_RAW)
411  {
412  fwrite(SubeventData, sizeof(int), getDataLength(), stdout);
413  return;
414  }
415 
416  if ( i == EVT_RAW_WH)
417  {
418  fwrite(SubeventHdr, sizeof(int), getLength(), stdout);
419  return;
420  }
421 
422  unsigned int j;
423  int l;
424  identify(out);
425 
426  switch (i)
427  {
428  case (EVT_HEXADECIMAL):
429  j = 0;
430  while (1)
431  {
432  out << SETW(5) << j << " | ";
433  for (l=0;l<4;l++)
434  {
435  out << std::hex << SETW(8) << std::setfill ('0') << SubeventData[j++] << std::setfill(' ') << " " << std::dec;
437  }
438  out << std::endl;
440  }
441  break;
442 
443  case (EVT_DECIMAL):
444  j = 0;
445  while (1)
446  {
447  out << std::dec << SETW(5) << j << " | ";
448 
449  for (l=0;l<6;l++)
450  {
451  out << SETW(10) << SubeventData[j++] << " ";
453  }
454  out << std::endl;
456  }
457  break;
458 
459  default:
460  break;
461  }
462  out << std::endl;
463 
464 }
465 
466 // ---------------------------------------------------------------------
467 
468 void oncsSubevent_w2::gdump(const int i, OSTREAM& out) const
469 {
470  short *SubeventData = (short *) &SubeventHdr->data;
471 
472  if ( i == EVT_RAW)
473  {
474  fwrite(SubeventData, sizeof(int), getDataLength(), stdout);
475  return;
476  }
477 
478  if ( i == EVT_RAW_WH)
479  {
480  fwrite(SubeventHdr, sizeof(int), getLength(), stdout);
481  return;
482  }
483 
484  unsigned int j;
485  int l;
486 
487  identify(out);
488 
489  switch (i)
490  {
491  case (EVT_HEXADECIMAL):
492  j = 0;
493  while (1)
494  {
495  out << std::dec << SETW(5) << j << " | ";
496  for (l=0;l<8;l++)
497  {
498  out << std::hex << SETW(4) << std::setfill ('0') << SubeventData[j++] << std::setfill(' ') << " " << std::dec;
500  }
501  out << std::endl;
502 
504  }
505  break;
506 
507  case (EVT_DECIMAL):
508  j = 0;
509  while (1)
510  {
511  out << std::dec << SETW(5) << j << " | ";
512  for (l=0;l<8;l++)
513  {
514  out << std::dec << SETW(6) << SubeventData[j++] << " ";
516  }
517  out << std::endl;
519  }
520  break;
521 
522  default: break;
523  }
524  out << std::endl;
525 }
526 
527 // ---------------------------------------------------------------------
528 
529 void oncsSubevent_w1::gdump(const int i, OSTREAM& out) const
530 {
531  char *SubeventData = (char *) &SubeventHdr->data;
532 
533 
534  if ( i == EVT_RAW)
535  {
536  fwrite(SubeventData, sizeof(int), getDataLength(), stdout);
537  return;
538  }
539 
540  if ( i == EVT_RAW_WH)
541  {
542  fwrite(SubeventHdr, sizeof(int), getLength(), stdout);
543  return;
544  }
545 
546  unsigned int j;
547  int l;
548 
549 
550  char cstring[20];
551  char *c;
552  identify(out);
553 
554  j = 0;
555  switch (i)
556  {
557  case (EVT_HEXADECIMAL):
558  while (1)
559  {
560  c = cstring;
561  out << std::dec << SETW(5) << j << " | ";
562  for (l=0;l<16;l++)
563  {
565  {
566  out << std::hex << SETW(2) << (int) SubeventData[j] << " ";
567  if (SubeventData[j] >=32 && SubeventData[j] <=127)
568  {
569  *c++ = SubeventData[j];
570  }
571  else
572  {
573  *c++ = 0x20;
574  }
575  out << " ";
576  }
577  j++;
578  }
579  *c = 0;
580  out << " | " << cstring;
581  out << std::endl;
583  }
584  break;
585 
586  case (EVT_DECIMAL):
587  while (1)
588  {
589  c = cstring;
590  out << std::dec << SETW(5) << j << " | ";
591  for (l=0;l<16;l++)
592  {
594  {
595  out << SETW(3) << (int) SubeventData[j] << " ";
596  if (SubeventData[j] >=32 && SubeventData[j] <=127)
597  {
598  *c++ = SubeventData[j];
599  }
600  else
601  {
602  *c++ = 0x20;
603  }
604  out << " ";
605  }
606  j++;
607  }
608  *c = 0;
609  out << " | " << cstring;
610  out << std::endl;
612  }
613  break;
614 
615  default: break;
616  }
617  out << std::endl;
618 }
619