Logo ROOT  
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 
36 TFPBlock::TFPBlock(Long64_t* offset, Int_t* length, Int_t nb)
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 
94 void TFPBlock::ReallocBlock(Long64_t* offset, Int_t* length, Int_t nb)
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 }
TFPBlock::fNblock
Int_t fNblock
Number of segment in the block.
Definition: TFPBlock.h:26
TFPBlock::fPos
Long64_t * fPos
Array of positions of each segment.
Definition: TFPBlock.h:30
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TFPBlock::ReallocBlock
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
TFPBlock::fRelOffset
Long64_t * fRelOffset
Relative offset of piece in the buffer.
Definition: TFPBlock.h:31
TFPBlock::fLen
Int_t * fLen
Array of lengths of each segment.
Definition: TFPBlock.h:29
TStorage::ReAllocInt
static Int_t * ReAllocInt(Int_t *vp, size_t size, size_t oldsize)
Reallocate (i.e.
Definition: TStorage.cxx:295
calloc
#define calloc
Definition: civetweb.c:1537
TFPBlock::~TFPBlock
virtual ~TFPBlock()
Destructor.
Definition: TFPBlock.cxx:60
TStorage.h
realloc
#define realloc
Definition: civetweb.c:1538
TFPBlock.h
TFPBlock::SetBuffer
void SetBuffer(char *)
Set block buffer.
Definition: TFPBlock.cxx:81
TFPBlock::fBuffer
char * fBuffer
Content of the block.
Definition: TFPBlock.h:25
TFPBlock::SetPos
void SetPos(Int_t, Long64_t)
Set pos value for index idx.
Definition: TFPBlock.cxx:72
TFPBlock::fCapacity
Long64_t fCapacity
Capacity of the buffer.
Definition: TFPBlock.h:28
TFPBlock::fDataSize
Long64_t fDataSize
Total size of useful data in the block.
Definition: TFPBlock.h:27
TStorage::ReAlloc
static void * ReAlloc(void *vp, size_t size)
Reallocate (i.e.
Definition: TStorage.cxx:183
free
#define free
Definition: civetweb.c:1539
TFPBlock
Definition: TFPBlock.h:22
TFPBlock::TFPBlock
TFPBlock(const TFPBlock &)=delete
int