ROOT logo
// @(#)root/io:$Id$
// Author: Philippe Canal, May 2011

/*************************************************************************
 * Copyright (C) 1995-2009, 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_TMemFile
#define ROOT_TMemFile

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TMemFile                                                             //
//                                                                      //
// A TMemFile is like a normal TFile except that it reads and writes    //
// its data via in memory.                                              //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TFile
#include "TFile.h"
#endif

class TMemFile : public TFile {

private:
   struct TMemBlock {
   private:
      TMemBlock(const TMemBlock&);            // Not implemented
      TMemBlock &operator=(const TMemBlock&); // Not implemented.
   public:
      TMemBlock();
      TMemBlock(Long64_t size, TMemBlock *previous = 0);
      ~TMemBlock();

      void CreateNext(Long64_t size);
      
      TMemBlock *fPrevious;
      TMemBlock *fNext;
      UChar_t   *fBuffer;
      Long64_t   fSize;
   };
   TMemBlock    fBlockList;   // Colletion of memory blocks of size fBlockSize
   Long64_t     fSize;        // Total file size (sum of the size of the chunks)
   Long64_t     fSysOffset;   // Seek offset in file
   TMemBlock   *fBlockSeek;   // Pointer to the block we seeked to.
   Long64_t     fBlockOffset; // Seek offset within the block

   static Long64_t fgDefaultBlockSize;

   Long64_t MemRead(Int_t fd, void *buf, Long64_t len) const;

   // Overload TFile interfaces.
   Int_t    SysOpen(const char *pathname, Int_t flags, UInt_t mode);
   Int_t    SysClose(Int_t fd);
   Int_t    SysRead(Int_t fd, void *buf, Int_t len);
   Int_t    SysWrite(Int_t fd, const void *buf, Int_t len);
   Long64_t SysSeek(Int_t fd, Long64_t offset, Int_t whence);
   Int_t    SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime);
   Int_t    SysSync(Int_t fd);

   void ResetObjects(TDirectoryFile *, TFileMergeInfo *) const;

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

public:
   TMemFile(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1);
   TMemFile(const char *name, char *buffer, Long64_t size, Option_t *option="", const char *ftitle="", Int_t compress=1);
   TMemFile(const TMemFile &orig);
   virtual ~TMemFile();

   virtual Long64_t CopyTo(void *to, Long64_t maxsize) const;
   virtual void     CopyTo(TBuffer &tobuf) const;
   virtual Long64_t GetSize() const;

   void ResetAfterMerge(TFileMergeInfo *);
   void ResetErrno() const;

   virtual void        Print(Option_t *option="") const;
   
   ClassDef(TMemFile, 0) //A ROOT file that reads/writes via HDFS
};

#endif
 TMemFile.h:1
 TMemFile.h:2
 TMemFile.h:3
 TMemFile.h:4
 TMemFile.h:5
 TMemFile.h:6
 TMemFile.h:7
 TMemFile.h:8
 TMemFile.h:9
 TMemFile.h:10
 TMemFile.h:11
 TMemFile.h:12
 TMemFile.h:13
 TMemFile.h:14
 TMemFile.h:15
 TMemFile.h:16
 TMemFile.h:17
 TMemFile.h:18
 TMemFile.h:19
 TMemFile.h:20
 TMemFile.h:21
 TMemFile.h:22
 TMemFile.h:23
 TMemFile.h:24
 TMemFile.h:25
 TMemFile.h:26
 TMemFile.h:27
 TMemFile.h:28
 TMemFile.h:29
 TMemFile.h:30
 TMemFile.h:31
 TMemFile.h:32
 TMemFile.h:33
 TMemFile.h:34
 TMemFile.h:35
 TMemFile.h:36
 TMemFile.h:37
 TMemFile.h:38
 TMemFile.h:39
 TMemFile.h:40
 TMemFile.h:41
 TMemFile.h:42
 TMemFile.h:43
 TMemFile.h:44
 TMemFile.h:45
 TMemFile.h:46
 TMemFile.h:47
 TMemFile.h:48
 TMemFile.h:49
 TMemFile.h:50
 TMemFile.h:51
 TMemFile.h:52
 TMemFile.h:53
 TMemFile.h:54
 TMemFile.h:55
 TMemFile.h:56
 TMemFile.h:57
 TMemFile.h:58
 TMemFile.h:59
 TMemFile.h:60
 TMemFile.h:61
 TMemFile.h:62
 TMemFile.h:63
 TMemFile.h:64
 TMemFile.h:65
 TMemFile.h:66
 TMemFile.h:67
 TMemFile.h:68
 TMemFile.h:69
 TMemFile.h:70
 TMemFile.h:71
 TMemFile.h:72
 TMemFile.h:73
 TMemFile.h:74
 TMemFile.h:75
 TMemFile.h:76
 TMemFile.h:77
 TMemFile.h:78
 TMemFile.h:79
 TMemFile.h:80
 TMemFile.h:81
 TMemFile.h:82
 TMemFile.h:83
 TMemFile.h:84
 TMemFile.h:85
 TMemFile.h:86
 TMemFile.h:87
 TMemFile.h:88