Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
16This class represents the encapsulation of a block request.
17It contains the chunks to be prefetched and also serves as a
18container for the information read.
19These blocks are prefetch in a special reader thread by the
20TFilePrefetch class.
21*/
22
23#include "TFPBlock.h"
24#include "TStorage.h"
25#include <cstdlib>
26
27using std::calloc;
28using std::free;
29using 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;
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
81void TFPBlock::SetBuffer(char* buf)
82{
83 if ( 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
#define ClassImp(name)
Definition Rtypes.h:382
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
#define realloc
Definition civetweb.c:1538
#define free
Definition civetweb.c:1539
#define calloc
Definition civetweb.c:1537
This class represents the encapsulation of a block request.
Definition TFPBlock.h:22
Long64_t fDataSize
Total size of useful data in the block.
Definition TFPBlock.h:27
void SetPos(Int_t, Long64_t)
Set pos value for index idx.
Definition TFPBlock.cxx:72
void SetBuffer(char *)
Set block buffer.
Definition TFPBlock.cxx:81
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
Long64_t * fPos
Array of positions of each segment.
Definition TFPBlock.h:30
Long64_t * fRelOffset
Relative offset of piece in the buffer.
Definition TFPBlock.h:31
char * fBuffer
Content of the block.
Definition TFPBlock.h:25
Int_t fNblock
Number of segment in the block.
Definition TFPBlock.h:26
TFPBlock(const TFPBlock &)=delete
Int_t * fLen
Array of lengths of each segment.
Definition TFPBlock.h:29
Long64_t fCapacity
Capacity of the buffer.
Definition TFPBlock.h:28
~TFPBlock() override
Destructor.
Definition TFPBlock.cxx:60
static Int_t * ReAllocInt(Int_t *vp, size_t size, size_t oldsize)
Reallocate (i.e.
Definition TStorage.cxx:258
static void * ReAlloc(void *vp, size_t size, size_t oldsize)
Reallocate (i.e.
Definition TStorage.cxx:183