Analysis Software
Documentation for sPHENIX simulation 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 
63 int oncsSubevent::setIdentifier(const int newid)
64 {
65  // check that we have short range; we want the parameter to be int
66  if ( newid & 0xffff0000) return -1;
67  SubeventHdr->sub_id = newid;
68  return 0;
69 }
70 
71 // ----------------------------------------------
72 //int oncsSubevent::get_type()
73 //{
74 // return SubeventHdr->sub_type;
75 //}
76 
77 // -----------------------------------------------
79 {
80  return SubeventHdr->sub_decoding;
81 }
82 
83 // -----------------------------------------------
85 {
86  return SubeventHdr->sub_padding;
87 }
88 
89 
90 
92 {
93  out << std::dec
94  << "Packet " << SETW(5) << getIdentifier()
95  << " " << SETW(5) << getLength()
96  << " -1" << " (sPHENIX Packet) ";
97 
98  out << SETW(3) << getHitFormat()
99  << " (" << oncs_get_mnemonic( getStructure(), getHitFormat()) << ")" << std::endl;
100 }
101 
102 
104 {
105  if (is_data_type) return 0;
106  else return 1;
107 }
108 
110 {
111  if (is_data_type) return -1;
112 
113  int *tmp;
114 
115  tmp = new int[getLength()];
116  int *from= (int *) SubeventHdr;
117  int *to=tmp;
118  for (int k=0; k< getLength(); k++)
119  {
120  *to++ = *from++;
121  }
122  SubeventHdr = ( subevtdata_ptr )tmp;
123  is_data_type = 1;
124  return 0;
125 
126 }
127 
128 
129 // ------------------------------------------------------
130 
131 int oncsSubevent::iValue(const int ich)
132 {
133  // now let's derefence the proxy array. If we didn't decode
134  // the data until now, we do it now
135  if (decoded_data1 == NULL )
136  {
137  if ( (decoded_data1 = decode(&data1_length))==NULL)
138  return 0;
139  }
140 
141  // see if our array is long enough
142  if (ich > data1_length) return 0;
143 
144  return decoded_data1[ich];
145 }
146 
147 // ------------------------------------------------------
148 
149 int oncsSubevent::iValue(const int ich, const char *what)
150 {
151  // now let's derefence the proxy array. If we didn't decode
152  // the data until now, we do it now
153  if (decoded_data1 == NULL )
154  {
155  if ( (decoded_data1 = decode(&data1_length))==NULL)
156  return 0;
157  }
158 
159  // see if our array is long enough
160  if (ich > data1_length) return 0;
161 
162  return decoded_data1[ich];
163 }
164 
165 // ------------------------------------------------------
166 
167 int oncsSubevent::iValue(const int ich, const int iy)
168 {
169  // now let's derefence the proxy array. If we didn't decode
170  // the data until now, we do it now
171  if (decoded_data1 == NULL )
172  {
173  if ( (decoded_data1 = decode(&data1_length))==NULL)
174  return 0;
175  }
176 
177  // see if our array is long enough
178  if (ich > data1_length) return 0;
179 
180  return decoded_data1[ich];
181 }
182 
183 // ------------------------------------------------------
184 
185 float oncsSubevent::rValue(const int ich)
186 {
187  // now let's derefence the proxy array. If we didn't decode
188  // the data until now, we do it now
189  if (decoded_data1 == NULL )
190  {
191  if ( (decoded_data1 = decode(&data1_length))==NULL)
192  return 0;
193  }
194 
195  // see if our array is long enough
196  if (ich > data1_length) return 0;
197 
198  return float(decoded_data1[ich]);
199 }
200 
201 // ------------------------------------------------------
202 
203 float oncsSubevent::rValue(const int ich, const char *what)
204 {
205  // now let's derefence the proxy array. If we didn't decode
206  // the data until now, we do it now
207  if (decoded_data1 == NULL )
208  {
209  if ( (decoded_data1 = decode(&data1_length))==NULL)
210  return 0;
211  }
212 
213  // see if our array is long enough
214  if (ich > data1_length) return 0;
215 
216  return float(decoded_data1[ich]);
217 }
218 
219 // ------------------------------------------------------
220 
221 float oncsSubevent::rValue(const int ich, const int iy)
222 {
223  // now let's derefence the proxy array. If we didn't decode
224  // the data until now, we do it now
225  if (decoded_data1 == NULL )
226  {
227  if ( (decoded_data1 = decode(&data1_length))==NULL)
228  return 0;
229  }
230 
231  // see if our array is long enough
232  if (ich > data1_length) return 0;
233 
234  return float(decoded_data1[ich]);
235 }
236 
237 // ----------------------------------------------
238 
239 int
241 {
242  // now let's derefence the proxy array. If we didn't decode
243  // the data until now, we do it now
244  if (decoded_data1 == NULL )
245  {
246  if ( (decoded_data1 = decode(&data1_length))==NULL)
247  return -1;
248  }
249 
250  return data1_length;
251 }
252 
253 // ----------------------------------------------
254 
255 int
257  const int nlen, int *nwout,
258  const char *what)
259 {
260 
261  if (strcmp(what,"") ==0)
262  {
263  // now let's derefence the proxy array. If we didn't decode
264  // the data until now, we do it now
265  if (decoded_data1 == NULL )
266  {
267  if ( (decoded_data1 = decode(&data1_length))==NULL)
268  {
269  *nwout=0;
270  return -1;
271  }
272  }
273 
274  // see if our array is long enough
275  if (nlen < data1_length) return -2;
276 
277  // and copy the data to the output array
278  int *from = decoded_data1;
279  for (int i=0; i<data1_length; i++) *iarr++ = *from++;
280 
281  // tell how much we copied
282  *nwout = data1_length;
283  }
284 
285  if (strcmp(what,"RAW") ==0)
286  {
287  if (nlen < getLength() ) return -2;
288  int *from = (int *) SubeventHdr;
289  for (int i=0; i<getLength(); i++) *iarr++ = *from++;
290 
291  *nwout = getLength();
292  }
293 
294  if (strcmp(what,"DATA") ==0)
295  {
296  if (nlen < getLength() -4 ) return -2;
297  int *from = &SubeventHdr->data;
298  for (int i=0; i<getLength() -4; i++) *iarr++ = *from++;
299 
300  *nwout = getLength()-4;
301  }
302  return 0;
303 }
304 
305 // ------------------------------------------------------
306 
307 int
309  const int nlen, int *nwout,
310  const char *what)
311 {
312 
313  // now let's derefence the proxy array. If we didn't decode
314  // the data until now, we do it now
315  if (decoded_data1 == NULL )
316  {
317  if ( (decoded_data1 = decode(&data1_length))==NULL)
318  {
319  *nwout=0;
320  return -1;
321  }
322  }
323 
324  // see if our array is long enough
325  if (nlen < data1_length) return -2;
326 
327  // and copy the data to the output array
328  int *from = decoded_data1;
329  for (int i=0; i<data1_length; i++) *rarr++ = float (*from++);
330 
331  // tell how much we copied
332  *nwout = data1_length;
333  return 0;
334 }
335 
336 // ------------------------------------------------------
337 int*
338 oncsSubevent::getIntArray (int *nwout, const char *what)
339 {
340 
341  // now let's derefence the proxy array. If we didn't decode
342  // the data until now, we do it now
343  if (decoded_data1 == NULL )
344  {
345  if ( (decoded_data1 = decode(&data1_length))==NULL)
346  {
347  *nwout=0;
348  return NULL;
349  }
350  }
351 
352  int *temp=new int[data1_length];
353  int is = fillIntArray(temp, data1_length, nwout);
354  if (is)
355  {
356  *nwout=0;
357  return NULL;
358  }
359  return temp;
360 }
361 
362 // ------------------------------------------------------
363 float* oncsSubevent::getFloatArray (int *nwout, const char *what)
364 {
365  // now let's derefence the proxy array. If we didn't decode
366  // the data until now, we do it now
367  if (decoded_data1 == NULL )
368  {
369  if ( (decoded_data1 = decode(&data1_length))==NULL)
370  {
371  *nwout=0;
372  return NULL;
373  }
374  }
375 
376  float *temp=new float[data1_length];
377  int is = fillFloatArray(temp, data1_length, nwout);
378  if (is)
379  {
380  *nwout=0;
381  return NULL;
382  }
383  return temp;
384 }
385 
386 // ----------------------------------------------
387 
388 int oncsSubevent::copyMe(int dest[], const int maxlength) const
389 {
390 
391  if ( getLength() > maxlength )
392  {
393  return 0;
394  }
395 
396  memcpy((void *) dest, (void *) SubeventHdr, 4*getLength() );
397  return getLength();
398 }
399 
400 
401 
402 // now the member functions common to all
403 // the individial p1, p2, and p4 classes.
404 
405 // ------------Constructors first -----------------
406 
408  : oncsSubevent(sevt_ptr)
409 {}
410 
412  : oncsSubevent(sevt_ptr)
413 {}
414 
416  : oncsSubevent(sevt_ptr)
417 {}
418 
419 // ---- and the dump routines, which just call the
420 // ---- generic dump routines, but may be overloaded
421 // ---- by the subclasses.
422 
426 
427 void oncsSubevent_w4::gdump(const int i, OSTREAM& out) const
428 {
429 
430  int *SubeventData = &SubeventHdr->data;
431 
432  if ( i == EVT_RAW)
433  {
434  fwrite(SubeventData, sizeof(int), getDataLength(), stdout);
435  return;
436  }
437 
438  if ( i == EVT_RAW_WH)
439  {
440  fwrite(SubeventHdr, sizeof(int), getLength(), stdout);
441  return;
442  }
443 
444  unsigned int j;
445  int l;
446  identify(out);
447 
448  switch (i)
449  {
450  case (EVT_HEXADECIMAL):
451  j = 0;
452  while (1)
453  {
454  out << SETW(5) << j << " | ";
455  for (l=0;l<4;l++)
456  {
457  out << std::hex << SETW(8) << std::setfill ('0') << SubeventData[j++] << std::setfill(' ') << " " << std::dec;
459  }
460  out << std::endl;
462  }
463  break;
464 
465  case (EVT_DECIMAL):
466  j = 0;
467  while (1)
468  {
469  out << std::dec << SETW(5) << j << " | ";
470 
471  for (l=0;l<6;l++)
472  {
473  out << SETW(10) << SubeventData[j++] << " ";
475  }
476  out << std::endl;
478  }
479  break;
480 
481  default:
482  break;
483  }
484  out << std::endl;
485 
486 }
487 
488 // ---------------------------------------------------------------------
489 
490 void oncsSubevent_w2::gdump(const int i, OSTREAM& out) const
491 {
492  short *SubeventData = (short *) &SubeventHdr->data;
493 
494  if ( i == EVT_RAW)
495  {
496  fwrite(SubeventData, sizeof(int), getDataLength(), stdout);
497  return;
498  }
499 
500  if ( i == EVT_RAW_WH)
501  {
502  fwrite(SubeventHdr, sizeof(int), getLength(), stdout);
503  return;
504  }
505 
506  unsigned int j;
507  int l;
508 
509  identify(out);
510 
511  switch (i)
512  {
513  case (EVT_HEXADECIMAL):
514  j = 0;
515  while (1)
516  {
517  out << std::dec << SETW(5) << j << " | ";
518  for (l=0;l<8;l++)
519  {
520  out << std::hex << SETW(4) << std::setfill ('0') << SubeventData[j++] << std::setfill(' ') << " " << std::dec;
522  }
523  out << std::endl;
524 
526  }
527  break;
528 
529  case (EVT_DECIMAL):
530  j = 0;
531  while (1)
532  {
533  out << std::dec << SETW(5) << j << " | ";
534  for (l=0;l<8;l++)
535  {
536  out << std::dec << SETW(6) << SubeventData[j++] << " ";
538  }
539  out << std::endl;
541  }
542  break;
543 
544  default: break;
545  }
546  out << std::endl;
547 }
548 
549 // ---------------------------------------------------------------------
550 
551 void oncsSubevent_w1::gdump(const int i, OSTREAM& out) const
552 {
553  char *SubeventData = (char *) &SubeventHdr->data;
554 
555 
556  if ( i == EVT_RAW)
557  {
558  fwrite(SubeventData, sizeof(int), getDataLength(), stdout);
559  return;
560  }
561 
562  if ( i == EVT_RAW_WH)
563  {
564  fwrite(SubeventHdr, sizeof(int), getLength(), stdout);
565  return;
566  }
567 
568  unsigned int j;
569  int l;
570 
571 
572  char cstring[20];
573  char *c;
574  identify(out);
575 
576  j = 0;
577  switch (i)
578  {
579  case (EVT_HEXADECIMAL):
580  while (1)
581  {
582  c = cstring;
583  out << std::dec << SETW(5) << j << " | ";
584  for (l=0;l<16;l++)
585  {
587  {
588  out << std::hex << SETW(2) << (int) SubeventData[j] << " ";
589  if (SubeventData[j] >=32 && SubeventData[j] <=127)
590  {
591  *c++ = SubeventData[j];
592  }
593  else
594  {
595  *c++ = 0x20;
596  }
597  out << " ";
598  }
599  j++;
600  }
601  *c = 0;
602  out << " | " << cstring;
603  out << std::endl;
605  }
606  break;
607 
608  case (EVT_DECIMAL):
609  while (1)
610  {
611  c = cstring;
612  out << std::dec << SETW(5) << j << " | ";
613  for (l=0;l<16;l++)
614  {
616  {
617  out << SETW(3) << (int) SubeventData[j] << " ";
618  if (SubeventData[j] >=32 && SubeventData[j] <=127)
619  {
620  *c++ = SubeventData[j];
621  }
622  else
623  {
624  *c++ = 0x20;
625  }
626  out << " ";
627  }
628  j++;
629  }
630  *c = 0;
631  out << " | " << cstring;
632  out << std::endl;
634  }
635  break;
636 
637  default: break;
638  }
639  out << std::endl;
640 }
641