1    	// @(#)root/io:$Id$
2    	// Author: Rene Brun   28/12/94
3    	
4    	/*************************************************************************
5    	 * Copyright (C) 1995-2000, 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   	#ifndef ROOT_TKey
13   	#define ROOT_TKey
14   	
15   	
16   	//////////////////////////////////////////////////////////////////////////
17   	//                                                                      //
18   	// TKey                                                                 //
19   	//                                                                      //
20   	// Header description of a logical record on file.                      //
21   	//                                                                      //
22   	//////////////////////////////////////////////////////////////////////////
23   	
24   	#ifndef ROOT_TNamed
25   	#include "TNamed.h"
26   	#endif
27   	#ifndef ROOT_TDatime
28   	#include "TDatime.h"
29   	#endif
30   	#ifndef ROOT_TBuffer
31   	#include "TBuffer.h"
32   	#endif
33   	
34   	class TClass;
35   	class TBrowser;
36   	class TDirectory;
37   	class TFile;
38   	
39   	class TKey : public TNamed {
40   	
41   	private:
42   	   enum EStatusBits {
43   	      kIsDirectoryFile = BIT(14)
44   	   };
45   	   TKey(const TKey&);            // TKey objects are not copiable.
46   	   TKey& operator=(const TKey&); // TKey objects are not copiable.
47   	
48   	protected:
49   	   Int_t       fVersion;     //Key version identifier
50   	   Int_t       fNbytes;      //Number of bytes for the object on file
51   	   Int_t       fObjlen;      //Length of uncompressed object in bytes
52   	   TDatime     fDatime;      //Date/Time of insertion in file
53   	   Short_t     fKeylen;      //Number of bytes for the key itself
54   	   Short_t     fCycle;       //Cycle number
55   	   Long64_t    fSeekKey;     //Location of object on file
56   	   Long64_t    fSeekPdir;    //Location of parent directory on file
57   	   TString     fClassName;   //Object Class name
58   	   Int_t       fLeft;        //Number of bytes left in current segment
59   	   char       *fBuffer;      //Object buffer
60   	   TBuffer    *fBufferRef;   //Pointer to the TBuffer object
61   	   UShort_t    fPidOffset;   //! Offset to be added to the pid index in this key/buffer.  This is actually saved in the high bits of fSeekPdir
62   	   TDirectory *fMotherDir;   //! pointer to mother directory
63   	
64   	   virtual Int_t    Read(const char *name) { return TObject::Read(name); }
65   	   virtual void     Create(Int_t nbytes, TFile* f = 0);
66   	           void     Build(TDirectory* motherDir, const char* classname, Long64_t filepos);
67   	   virtual void     Reset(); // Currently only for the use of TBasket.
68   	   virtual Int_t    WriteFileKeepBuffer(TFile *f = 0);
69   	
70   	
71   	 public:
72   	   TKey();
73   	   TKey(TDirectory* motherDir);
74   	   TKey(TDirectory* motherDir, const TKey &orig, UShort_t pidOffset);
75   	   TKey(const char *name, const char *title, const TClass *cl, Int_t nbytes, TDirectory* motherDir = 0);
76   	   TKey(const TString &name, const TString &title, const TClass *cl, Int_t nbytes, TDirectory* motherDir = 0);
77   	   TKey(const TObject *obj, const char *name, Int_t bufsize, TDirectory* motherDir = 0);
78   	   TKey(const void *obj, const TClass *cl, const char *name, Int_t bufsize, TDirectory* motherDir = 0);
79   	   TKey(Long64_t pointer, Int_t nbytes, TDirectory* motherDir = 0);
80   	   virtual ~TKey();
81   	
82   	   virtual void        Browse(TBrowser *b);
83   	   virtual void        Delete(Option_t *option="");
84   	   virtual void        DeleteBuffer();
85   	   virtual void        FillBuffer(char *&buffer);
86   	   virtual const char *GetClassName() const {return fClassName.Data();}
87   	   virtual const char *GetIconName() const;
88   	   virtual const char *GetTitle() const;
89   	   virtual char       *GetBuffer() const {return fBuffer+fKeylen;}
90   	           TBuffer    *GetBufferRef() const {return fBufferRef;}
91   	           Short_t     GetCycle() const;
92   	   const   TDatime    &GetDatime() const   {return fDatime;}
93   	           TFile      *GetFile() const;
94   	           Short_t     GetKeep() const;
95   	           Int_t       GetKeylen() const   {return fKeylen;}
96   	           TDirectory* GetMotherDir() const { return fMotherDir; }
97   	           Int_t       GetNbytes() const   {return fNbytes;}
98   	           Int_t       GetObjlen() const   {return fObjlen;}
99   	           Int_t       GetVersion() const  {return fVersion;}
100  	   virtual Long64_t    GetSeekKey() const  {return fSeekKey;}
101  	   virtual Long64_t    GetSeekPdir() const {return fSeekPdir;}
102  	   virtual ULong_t     Hash() const;
103  	   virtual void        IncrementPidOffset(UShort_t offset);
104  	           Bool_t      IsFolder() const;
105  	   virtual void        Keep();
106  	   virtual void        ls(Option_t *option="") const;
107  	   virtual void        Print(Option_t *option="") const;
108  	   virtual Int_t       Read(TObject *obj);
109  	   virtual TObject    *ReadObj();
110  	   virtual TObject    *ReadObjWithBuffer(char *bufferRead);
111  	   virtual void       *ReadObjectAny(const TClass *expectedClass);
112  	   virtual void        ReadBuffer(char *&buffer);
113  	           void        ReadKeyBuffer(char *&buffer);
114  	   virtual Bool_t      ReadFile();
115  	   virtual void        SetBuffer() { fBuffer = new char[fNbytes];}
116  	   virtual void        SetParent(const TObject *parent);
117  	           void        SetMotherDir(TDirectory* dir) { fMotherDir = dir; }
118  	   virtual Int_t       Sizeof() const;
119  	   virtual Int_t       WriteFile(Int_t cycle=1, TFile* f = 0);
120  	
121  	   ClassDef(TKey,4); //Header description of a logical record on file.
122  	};
123  	
124  	#endif
125