Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lzobuffer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file lzobuffer.cc
1 #include "lzobuffer.h"
2 #include "lzo/lzoutil.h"
3 #include "oncsBuffer.h"
4 
6 
7 
8 // the constructor first ----------------
10 
11 {
12 
13  if ( ! lzo_initialized )
14  {
15  if (lzo_init() != LZO_E_OK)
16  {
17  COUT << "Could not initialize LZO" << std::endl;
18  _broken = 1;
19  }
20 
21  lzo_initialized = 1;
22  }
23 
24 
25  is_good =1;
26  bufferarray=0;
27  theBuffer=0;
28 
29  lzo_uint bytes;
30  lzo_uint outputlength_in_bytes;
31  if (array[1] == LZO1XBUFFERMARKER )
32  {
33  bytes = array[0]-4*BUFFERHEADERLENGTH;
34  outputlength_in_bytes = array[3];
35  }
36  else if ( u4swap(array[1]) == LZO1XBUFFERMARKER)
37  {
38  bytes = i4swap(array[0])-16;
39  outputlength_in_bytes = i4swap(array[3]);
40  }
41 
42  else
43  {
44  COUT << " wrong buffer" << std::endl;
45  is_good = 0;
46  return;
47  }
48 
49 
50  int outputlength = (outputlength_in_bytes+3)/4;
51  bufferarray = new PHDWORD[outputlength];
52  lzo_uint olen;
53 
54  // std::cout << __FILE__ << " " << __LINE__ << " safe!!! array length before is " << array[-1] << std::endl;
55  olen = outputlength_in_bytes;
56  lzo1x_decompress_safe ( (lzo_byte *) &array[4], bytes,
57  (lzo_byte *) bufferarray, &olen, NULL );
58 
59 
60  // std::cout << __FILE__ << " " << __LINE__ << " array length after is " << array[-1] << std::endl;
61 
62  if ( olen != outputlength_in_bytes)
63  {
64  COUT << __FILE__ << " " << __LINE__ << " wrong-sized buffer: " << olen << " should be " << outputlength_in_bytes << std::endl;
65  is_good = 0;
66  // delete [] bufferarray;
67  // bufferarray = 0;
68  // return;
69  }
71  {
72  theBuffer = new prdfBuffer(bufferarray, outputlength);
73  }
75  {
76  theBuffer = new oncsBuffer(bufferarray, outputlength);
77  }
78  else
79  {
80  theBuffer = 0;
81  }
82 }
83 
84 // ---------------------------------------------------------
86 {
87  if ( theBuffer) return theBuffer->getEvent();
88  return 0;
89 }
90 
91 // ---------------------------------------------------------
92 
94 {
95  if ( theBuffer) delete theBuffer;
96  if ( bufferarray) delete [] bufferarray;
97 }
98 
99