Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ogzBuffer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ogzBuffer.cc
1 
2 #include "ogzBuffer.h"
3 #include "BufferConstants.h"
4 
5 
6 // the constructor first ----------------
7 #ifndef WIN32
8 ogzBuffer::ogzBuffer (int fdin, PHDWORD * where,
9  const int length,
10  const int level,
11  const int irun,
12  const int iseq):
13  ophBuffer(fdin,where,length,irun,iseq)
14 #else
15 ogzBuffer::ogzBuffer (const char *fpp, PHDWORD * where,
16  const int length,
17  int & status,
18  const int level,
19  const int irun,
20  const int iseq):
21  ophBuffer(fpp,where,length,status,irun,iseq)
22 #endif
23 {
24  // get a buffer for zlib
25 
27  outputarraylength = (int)(length *1.1) + 2048;
29 
30 }
31 
32 // ----------------------------------------------------------
33 // returns the number of bytes written, including record wasted space.
34 //
36 {
37  if (! dirty) return 0;
38 
39  if (! has_end) addEoB();
40 
41  uLongf outputlength_in_bytes = outputarraylength*4;
42  uLong bytes_to_be_written = bptr->Length;
43 
44  compress2 ( (Bytef*) &outputarray[4], &outputlength_in_bytes, (Bytef*) bptr,
45  bytes_to_be_written, compressionlevel);
46 
47  outputarray[0] = outputlength_in_bytes +4*BUFFERHEADERLENGTH;
48  outputarray[1] = GZBUFFERMARKER; // -518;
49  outputarray[2] = bptr->Bufseq;
50  outputarray[3] = bptr->Length;
51 
52  unsigned int ip =0;
53  char *cp = (char *) outputarray;
54 
55  while (ip<outputarray[0])
56  {
57  int n = write ( fd, cp, BUFFERBLOCKSIZE);
58  if ( n != BUFFERBLOCKSIZE)
59  {
60  std::cout << " could not write output, bytes written: " << n << std::endl;
61  return 0;
62  }
63  cp += BUFFERBLOCKSIZE;
64  ip += BUFFERBLOCKSIZE;
65  }
66  dirty = 0;
67  byteswritten += ip;
68  return 0;
69 }
70 
71 
72 // ----------------------------------------------------------
74 {
75  writeout();
76  delete [] outputarray;
77 
78 }
79