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
31
32////////////////////////////////////////////////////////////////////////////////
33/// Constructor.
34
36{
37 Long64_t aux = 0;
38
39 fNblock = nb;
40 fPos = new Long64_t[nb];
41 fRelOffset = new Long64_t[nb];
42 fLen = new Int_t[nb];
43
44 for (Int_t i=0; i < nb; i++){
45 fPos[i] = offset[i];
46 fLen[i] = length[i];
47 fRelOffset[i] = aux;
48 aux += length[i];
49 }
50
51 fCapacity = aux;
52 fDataSize = aux;
53 fBuffer = (char*) calloc(fCapacity, sizeof(char));
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Destructor.
58
60{
61 delete[] fPos;
62 delete[] fLen;
63 delete[] fRelOffset;
65}
66
67
68////////////////////////////////////////////////////////////////////////////////
69/// Set pos value for index idx.
70
72{
73 fPos[idx] = value;
74}
75
76
77////////////////////////////////////////////////////////////////////////////////
78/// Set block buffer.
79
80void TFPBlock::SetBuffer(char* buf)
81{
82 if ( fBuffer ) {
84 }
85 fBuffer = buf;
86
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Reallocate the block's buffer based on the length
91/// of the elements it will contain.
92
94{
95 Long64_t newSize = 0;
96
97 fPos = (Long64_t*) TStorage::ReAlloc(fPos, nb * sizeof(Long64_t), fNblock * sizeof(Long64_t));
100 fNblock = nb;
101
102 for(Int_t i=0; i < nb; i++){
103 fPos[i] = offset[i];
104 fLen[i] = length[i];
105 fRelOffset[i] = newSize;
106 newSize += fLen[i];
107 }
108
109 if (newSize > fCapacity) {
111 fBuffer = (char*) realloc(fBuffer, fCapacity);
112 }
113
115}
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:1577
#define free
Definition civetweb.c:1578
#define calloc
Definition civetweb.c:1576
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:71
void SetBuffer(char *)
Set block buffer.
Definition TFPBlock.cxx:80
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:93
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:59
static Int_t * ReAllocInt(Int_t *vp, size_t size, size_t oldsize)
Reallocate (i.e.
Definition TStorage.cxx:257
static void * ReAlloc(void *vp, size_t size, size_t oldsize)
Reallocate (i.e.
Definition TStorage.cxx:182