Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
packet_idcstr.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file packet_idcstr.cc
1 #include "packet_idcstr.h"
2 #include <stdio.h>
3 
5  : Packet_w1 (data)
6 {
7  sarray = 0;
8 }
9 
11 {
12  if ( sarray) delete [] sarray;
13 }
14 
15 
16 int Packet_idcstr::iValue(const int i)
17 {
18 
19  int n;
20  if ( ! sarray ) decode ( &n);
21 
22  if ( i < 0 || i >= allocated_length)
23  {
24  return 0;
25  }
26 
27  int c = sarray[i];
28  return c;
29 
30 }
31 
32 
33 
34 int *Packet_idcstr::decode ( int *nwout)
35 {
36 
37  int dlength = getDataLength();
38 
39  // std::cout << __FILE__ << " " << __LINE__ << " datalength: "
40  // << getDataLength() << " padding " << getPadding() << std::endl;
41 
42  if ( dlength <=0) dlength =1; // need at least an array of 1
43 
44  unsigned char *SubeventData = ( unsigned char * ) findPacketDataStart(packet);
45  sarray = new unsigned char[dlength+1];
46  memcpy ( sarray, SubeventData,dlength);
47  sarray[dlength] = 0;
49 
50  return 0;
51 
52 }
53 
55 {
56 
57  int n;
58  if ( ! sarray ) decode ( &n);
59 
60  os.write( (const char *) sarray, allocated_length);
61  os << std::flush;
62 
63 }
64