EIC 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 
5 
6 
7 // the constructor first ----------------
8 lzobuffer::lzobuffer (PHDWORD *array , const int length )
9 
10 {
11 
12  if ( ! lzo_initialized )
13  {
14  if (lzo_init() != LZO_E_OK)
15  {
16  COUT << "Could not initialize LZO" << std::endl;
17  _broken = 1;
18  }
19 
20  lzo_initialized = 1;
21  }
22 
23 
24  is_good =1;
25  bufferarray=0;
26  theBuffer=0;
27 
28  lzo_uint bytes;
29  lzo_uint outputlength_in_bytes;
30  if (array[1] == LZO1XBUFFERMARKER )
31  {
32  bytes = array[0]-4*BUFFERHEADERLENGTH;
33  outputlength_in_bytes = array[3];
34  }
35  else if ( u4swap(array[1]) == LZO1XBUFFERMARKER)
36  {
37  bytes = i4swap(array[0])-16;
38  outputlength_in_bytes = i4swap(array[3]);
39  }
40 
41  else
42  {
43  COUT << " wrong buffer" << std::endl;
44  is_good = 0;
45  return;
46  }
47 
48 
49  int outputlength = (outputlength_in_bytes+3)/4;
50  bufferarray = new PHDWORD[outputlength];
51  lzo_uint olen;
52 
53  // std::cout << __FILE__ << " " << __LINE__ << " safe!!! array length before is " << array[-1] << std::endl;
54  olen = outputlength_in_bytes;
55  lzo1x_decompress_safe ( (lzo_byte *) &array[4], bytes,
56  (lzo_byte *) bufferarray, &olen, NULL );
57 
58 
59  // std::cout << __FILE__ << " " << __LINE__ << " array length after is " << array[-1] << std::endl;
60 
61  if ( olen != outputlength_in_bytes)
62  {
63  COUT << __FILE__ << " " << __LINE__ << " wrong-sized buffer: " << olen << " should be " << outputlength_in_bytes << std::endl;
64  is_good = 0;
65  // delete [] bufferarray;
66  // bufferarray = 0;
67  // return;
68  }
69 
70  theBuffer = new prdfBuffer(bufferarray, outputlength);
71 
72 }
73 
74 // ---------------------------------------------------------
76 {
77  if ( theBuffer) return theBuffer->getEvent();
78  return 0;
79 }
80 
81 // ---------------------------------------------------------
82 
84 {
85  if ( theBuffer) delete theBuffer;
86  if ( bufferarray) delete [] bufferarray;
87 }
88 
89