Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
31 ClassImp(TFPBlock);
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 
60 TFPBlock::~TFPBlock()
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 
72 void TFPBlock::SetPos(Int_t idx, Long64_t value)
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));
99  fRelOffset = (Long64_t*) TStorage::ReAlloc(fRelOffset, nb * sizeof(Long64_t), fNblock * sizeof(Long64_t));
100  fLen = TStorage::ReAllocInt(fLen, nb, fNblock);
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 }