ROOT  6.06/09
Reference Guide
TFPBlock.cxx
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Elvin Sindrilaru 19/05/2011
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /**
13 \class TFPBlock TFPBlock.cxx
14 \ingroup IO
15 
16 This class represents the encapsulation of a block request.
17 It contains the chunks to be prefetched and also serves as a
18 container for the information read.
19 These blocks are prefetch in a special reader thread by the
20 TFilePrefetch class.
21 */
22 
23 #include "TFPBlock.h"
24 #include "TStorage.h"
25 #include <cstdlib>
26 
27 using std::calloc;
28 using std::free;
29 using std::realloc;
30 
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Constructor.
35 
37 {
38  Long64_t aux = 0;
39 
40  fNblock = nb;
41  fPos = new Long64_t[nb];
42  fRelOffset = new Long64_t[nb];
43  fLen = new Int_t[nb];
44 
45  for (Int_t i=0; i < nb; i++){
46  fPos[i] = offset[i];
47  fLen[i] = length[i];
48  fRelOffset[i] = aux;
49  aux += length[i];
50  }
51 
52  fCapacity = aux;
53  fDataSize = aux;
54  fBuffer = (char*) calloc(fCapacity, sizeof(char));
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Destructor.
59 
61 {
62  delete[] fPos;
63  delete[] fLen;
64  delete[] fRelOffset;
65  free(fBuffer);
66 }
67 
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Set pos value for index idx.
71 
73 {
74  fPos[idx] = value;
75 }
76 
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Set block buffer.
80 
81 void TFPBlock::SetBuffer(char* buf)
82 {
83  if ( fBuffer ) {
84  free(fBuffer);
85  }
86  fBuffer = buf;
87 
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Reallocate the block's buffer based on the length
92 /// of the elements it will contain.
93 
95 {
96  Long64_t newSize = 0;
97 
98  fPos = (Long64_t*) TStorage::ReAlloc(fPos, nb * sizeof(Long64_t), fNblock * sizeof(Long64_t));
101  fNblock = nb;
102 
103  for(Int_t i=0; i < nb; i++){
104  fPos[i] = offset[i];
105  fLen[i] = length[i];
106  fRelOffset[i] = newSize;
107  newSize += fLen[i];
108  }
109 
110  if (newSize > fCapacity) {
111  fCapacity = newSize;
112  fBuffer = (char*) realloc(fBuffer, fCapacity);
113  }
114 
115  fDataSize = newSize;
116 }
long long Long64_t
Definition: RtypesCore.h:69
void ReallocBlock(Long64_t *, Int_t *, Int_t)
Reallocate the block's buffer based on the length of the elements it will contain.
Definition: TFPBlock.cxx:94
int Int_t
Definition: RtypesCore.h:41
void SetPos(Int_t, Long64_t)
Set pos value for index idx.
Definition: TFPBlock.cxx:72
Vc_ALWAYS_INLINE void free(T *p)
Frees memory that was allocated with Vc::malloc.
Definition: memory.h:94
ClassImp(TFPBlock) TFPBlock
Constructor.
Definition: TFPBlock.cxx:31
void SetBuffer(char *)
Set block buffer.
Definition: TFPBlock.cxx:81
This class represents the encapsulation of a block request.
Definition: TFPBlock.h:24
Long64_t fCapacity
Capacity of the buffer.
Definition: TFPBlock.h:30
Long64_t * fRelOffset
Relative offset of piece in the buffer.
Definition: TFPBlock.h:33
Long64_t fDataSize
Total size of useful data in the block.
Definition: TFPBlock.h:29
Double_t length(const TVector2 &v)
Definition: CsgOps.cxx:347
Int_t fNblock
Number of segment in the block.
Definition: TFPBlock.h:28
char * fBuffer
Content of the block.
Definition: TFPBlock.h:27
Long64_t * fPos
Array of positions of each segment.
Definition: TFPBlock.h:32
static void * ReAlloc(void *vp, size_t size)
Reallocate (i.e.
Definition: TStorage.cxx:177
Int_t * fLen
Array of lengths of each segment.
Definition: TFPBlock.h:31
virtual ~TFPBlock()
Destructor.
Definition: TFPBlock.cxx:60
float value
Definition: math.cpp:443
static Int_t * ReAllocInt(Int_t *vp, size_t size, size_t oldsize)
Reallocate (i.e.
Definition: TStorage.cxx:289