// @(#)root/io:$Id$
// Author: Elvin Sindrilaru   19/05/2011

/*************************************************************************
 * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TFPBlock
#define ROOT_TFPBlock

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TFPBlock                                                             //
//                                                                      //
// This class represents the encapsulation of a block request.          //
// It contains the chunks to be prefetched and also serves as a         //
// container for the information read.                                  //
// These blocks are prefetch in a special reader thread by the          //
// TFilePrefetch class.                                                 //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif

class TFPBlock : public TObject{

private:
   char     *fBuffer;       // content of the block
   Int_t     fNblock;       // number of segment in the block
   Long64_t  fDataSize;     // total size of useful data in the block
   Long64_t  fCapacity;     // capacity of the buffer
   Int_t    *fLen;          // array of lengths of each segment
   Long64_t *fPos;          // array of positions of each segment
   Long64_t *fRelOffset;    // relative offset of piece in the buffer

   TFPBlock(const TFPBlock&);            // Not implemented.
   TFPBlock &operator=(const TFPBlock&); // Not implemented.

public:

   TFPBlock(Long64_t*, Int_t*, Int_t);
   virtual ~TFPBlock();

   Long64_t  GetPos(Int_t) const;
   Int_t     GetLen(Int_t) const;

   Long64_t *GetPos() const;
   Int_t    *GetLen() const;
   Long64_t  GetDataSize() const;
   Long64_t  GetCapacity() const;
   Int_t     GetNoElem() const;
   char     *GetBuffer() const;
   char     *GetPtrToPiece(Int_t index) const;

   void SetBuffer(char*);
   void SetPos(Int_t, Long64_t);
   void ReallocBlock(Long64_t*, Int_t*, Int_t);

   ClassDef(TFPBlock, 0);  // File prefetch block
};

//__________________________________________________________________
inline Long64_t* TFPBlock::GetPos() const
{
   // Get pointer to the array of postions.

   return fPos;
}

//__________________________________________________________________
inline Int_t* TFPBlock::GetLen() const
{
   // Get pointer to the array of lengths.

   return fLen;
}

//__________________________________________________________________
inline Long64_t TFPBlock::GetDataSize() const
{
   // Return size of the data in the block.

   return fDataSize;
}

//__________________________________________________________________
inline Long64_t TFPBlock::GetCapacity() const
{
   // Return capacity of the block.

   return fCapacity;
}

//__________________________________________________________________
inline Int_t TFPBlock::GetNoElem() const
{
   // Return number of elements in the block.

   return fNblock;
}

//__________________________________________________________________
inline Long64_t TFPBlock::GetPos(Int_t i) const
{
   // Get position of the element at index i.

   return fPos[i];
}

//__________________________________________________________________
inline Int_t TFPBlock::GetLen(Int_t i) const
{
  // Get length of the element at index i.

   return fLen[i];
}

//__________________________________________________________________
inline char* TFPBlock::GetBuffer() const
{
   // Get block buffer.

   return fBuffer;
}

//__________________________________________________________________
inline char* TFPBlock::GetPtrToPiece(Int_t index) const
{
   // Get block buffer.

  return (fBuffer + fRelOffset[index]);
}

#endif
 TFPBlock.h:1
 TFPBlock.h:2
 TFPBlock.h:3
 TFPBlock.h:4
 TFPBlock.h:5
 TFPBlock.h:6
 TFPBlock.h:7
 TFPBlock.h:8
 TFPBlock.h:9
 TFPBlock.h:10
 TFPBlock.h:11
 TFPBlock.h:12
 TFPBlock.h:13
 TFPBlock.h:14
 TFPBlock.h:15
 TFPBlock.h:16
 TFPBlock.h:17
 TFPBlock.h:18
 TFPBlock.h:19
 TFPBlock.h:20
 TFPBlock.h:21
 TFPBlock.h:22
 TFPBlock.h:23
 TFPBlock.h:24
 TFPBlock.h:25
 TFPBlock.h:26
 TFPBlock.h:27
 TFPBlock.h:28
 TFPBlock.h:29
 TFPBlock.h:30
 TFPBlock.h:31
 TFPBlock.h:32
 TFPBlock.h:33
 TFPBlock.h:34
 TFPBlock.h:35
 TFPBlock.h:36
 TFPBlock.h:37
 TFPBlock.h:38
 TFPBlock.h:39
 TFPBlock.h:40
 TFPBlock.h:41
 TFPBlock.h:42
 TFPBlock.h:43
 TFPBlock.h:44
 TFPBlock.h:45
 TFPBlock.h:46
 TFPBlock.h:47
 TFPBlock.h:48
 TFPBlock.h:49
 TFPBlock.h:50
 TFPBlock.h:51
 TFPBlock.h:52
 TFPBlock.h:53
 TFPBlock.h:54
 TFPBlock.h:55
 TFPBlock.h:56
 TFPBlock.h:57
 TFPBlock.h:58
 TFPBlock.h:59
 TFPBlock.h:60
 TFPBlock.h:61
 TFPBlock.h:62
 TFPBlock.h:63
 TFPBlock.h:64
 TFPBlock.h:65
 TFPBlock.h:66
 TFPBlock.h:67
 TFPBlock.h:68
 TFPBlock.h:69
 TFPBlock.h:70
 TFPBlock.h:71
 TFPBlock.h:72
 TFPBlock.h:73
 TFPBlock.h:74
 TFPBlock.h:75
 TFPBlock.h:76
 TFPBlock.h:77
 TFPBlock.h:78
 TFPBlock.h:79
 TFPBlock.h:80
 TFPBlock.h:81
 TFPBlock.h:82
 TFPBlock.h:83
 TFPBlock.h:84
 TFPBlock.h:85
 TFPBlock.h:86
 TFPBlock.h:87
 TFPBlock.h:88
 TFPBlock.h:89
 TFPBlock.h:90
 TFPBlock.h:91
 TFPBlock.h:92
 TFPBlock.h:93
 TFPBlock.h:94
 TFPBlock.h:95
 TFPBlock.h:96
 TFPBlock.h:97
 TFPBlock.h:98
 TFPBlock.h:99
 TFPBlock.h:100
 TFPBlock.h:101
 TFPBlock.h:102
 TFPBlock.h:103
 TFPBlock.h:104
 TFPBlock.h:105
 TFPBlock.h:106
 TFPBlock.h:107
 TFPBlock.h:108
 TFPBlock.h:109
 TFPBlock.h:110
 TFPBlock.h:111
 TFPBlock.h:112
 TFPBlock.h:113
 TFPBlock.h:114
 TFPBlock.h:115
 TFPBlock.h:116
 TFPBlock.h:117
 TFPBlock.h:118
 TFPBlock.h:119
 TFPBlock.h:120
 TFPBlock.h:121
 TFPBlock.h:122
 TFPBlock.h:123
 TFPBlock.h:124
 TFPBlock.h:125
 TFPBlock.h:126
 TFPBlock.h:127
 TFPBlock.h:128
 TFPBlock.h:129
 TFPBlock.h:130
 TFPBlock.h:131
 TFPBlock.h:132
 TFPBlock.h:133
 TFPBlock.h:134
 TFPBlock.h:135
 TFPBlock.h:136
 TFPBlock.h:137
 TFPBlock.h:138
 TFPBlock.h:139
 TFPBlock.h:140