TDirectory-example.h

Go to the documentation of this file.
00001 // @(#)root/base:$Name: v5-14-00f $:$Id: TDirectory.h,v 1.37 2006/06/20 18:17:34 pcanal Exp $
00002 // Author: Rene Brun   28/11/94
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TDirectory
00013 #define ROOT_TDirectory
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TDirectory                                                           //
00019 //                                                                      //
00020 // Describe directory structure in memory.                              //
00021 //                                                                      //
00022 //////////////////////////////////////////////////////////////////////////
00023 
00024 #ifndef ROOT_TNamed
00025 #include "TNamed.h"
00026 #endif
00027 #ifndef ROOT_TList
00028 #include "TList.h"
00029 #endif
00030 #ifndef ROOT_TDatime
00031 #include "TDatime.h"
00032 #endif
00033 #ifndef ROOT_TUUID
00034 #include "TUUID.h"
00035 #endif
00036 
00037 class TBrowser;
00038 class TKey;
00039 class TFile;
00040 
00041 R__EXTERN TDirectory *gDirectory;
00042 
00043 class TDirectory : public TNamed {
00044 
00045 protected:
00046    Bool_t      fModified;        //true if directory has been modified
00047    Bool_t      fWritable;        //true if directory is writable
00048    TDatime     fDatimeC;         //Date and time when directory is created
00049    TDatime     fDatimeM;         //Date and time of last modification
00050    Int_t       fNbytesKeys;      //Number of bytes for the keys
00051    Int_t       fNbytesName;      //Number of bytes in TNamed at creation time
00052    Int_t       fBufferSize;      //Default buffer size to create new TKeys
00053    Long64_t    fSeekDir;         //Location of directory on file
00054    Long64_t    fSeekParent;      //Location of parent directory on file
00055    Long64_t    fSeekKeys;        //Location of Keys record on file
00056    TFile      *fFile;            //pointer to current file in memory
00057    TObject    *fMother;          //pointer to mother of the directory
00058    TList      *fList;            //Pointer to objects list in memory
00059    TList      *fKeys;            //Pointer to keys list in memory
00060    TUUID       fUUID;            //Unique identifier
00061    TString     fPathBuffer;      //!Buffer for GetPath() function
00062 
00063           Bool_t cd1(const char *path);
00064    static Bool_t Cd1(const char *path);
00065 
00066           void   FillFullPath(TString& buf) const;
00067 
00068 private:
00069    TDirectory(const TDirectory &directory);  //Directories cannot be copied
00070    void operator=(const TDirectory &); //Directorise cannot be copied
00071 
00072 public:
00073    // TDirectory status bits
00074    enum { kCloseDirectory = BIT(7) };
00075 
00076    /** @class Context
00077      *
00078      *  Small helper to keep current directory context.
00079      *  Automatically reverts to "old" directory
00080      */
00081    class TContext  {
00082    private:
00083       TDirectory* fPrevious;   // Pointer to the previous current directory.
00084       TContext(TContext&);
00085       TContext& operator=(TContext&);
00086       void CdNull();
00087    public:
00088       TContext(TDirectory* previous, TDirectory* newCurrent)
00089          : fPrevious(previous)
00090       {
00091          // Store the current directory so we can restore it
00092          // later and cd to the new directory.
00093          if ( newCurrent ) newCurrent->cd();
00094       }
00095       TContext(TDirectory* newCurrent) : fPrevious(gDirectory)
00096       {
00097          // Store the current directory so we can restore it
00098          // later and cd to the new directory.
00099          if ( newCurrent ) newCurrent->cd();
00100       }
00101       ~TContext()
00102       {
00103          // Destructor.   Reset the current directory to its
00104          // previous state.
00105          if ( fPrevious ) fPrevious->cd();
00106          else CdNull();
00107       }
00108    };
00109 
00110    TDirectory();
00111    TDirectory(const char *name, const char *title, Option_t *option="", TDirectory* motherDir = 0);
00112    virtual ~TDirectory();
00113    virtual void        Append(TObject *obj);
00114            void        Add(TObject *obj) { Append(obj); }
00115            Int_t       AppendKey(TKey *key);
00116    virtual void        Browse(TBrowser *b);
00117            void        Build(TFile* motherFile = 0, TDirectory* motherDir = 0);
00118    virtual void        Clear(Option_t *option="");
00119    virtual void        Close(Option_t *option="");
00120    virtual void        Copy(TObject &) const { MayNotUse("Copy(TObject &)"); }
00121    virtual Bool_t      cd(const char *path = 0);
00122    virtual void        DeleteAll(Option_t *option="");
00123    virtual void        Delete(const char *namecycle="");
00124    virtual void        Draw(Option_t *option="");
00125    virtual void        FillBuffer(char *&buffer);
00126    virtual TKey       *FindKey(const char *keyname) const;
00127    virtual TKey       *FindKeyAny(const char *keyname) const;
00128    virtual TObject    *FindObject(const char *name) const;
00129    virtual TObject    *FindObject(const TObject *obj) const;
00130    virtual TObject    *FindObjectAny(const char *name) const;
00131    virtual TObject    *Get(const char *namecycle);
00132    virtual TDirectory *GetDirectory(const char *namecycle, Bool_t printError = false, const char *funcname = "GetDirectory");
00133    template <class T> inline void GetObject(const char* namecycle, T*& ptr) // See TDirectory::Get for information
00134       {
00135          ptr = (T*)GetObjectChecked(namecycle,TBuffer::GetClass(typeid(T)));
00136       }
00137    virtual void       *GetObjectChecked(const char *namecycle, const char* classname);
00138    virtual void       *GetObjectChecked(const char *namecycle, const TClass* cl);
00139    virtual void       *GetObjectUnchecked(const char *namecycle);
00140    virtual Int_t       GetBufferSize() const;
00141    const TDatime      &GetCreationDate() const { return fDatimeC; }
00142    virtual TFile      *GetFile() const { return fFile; }
00143    virtual TKey       *GetKey(const char *name, Short_t cycle=9999) const;
00144    virtual TList      *GetList() const { return fList; }
00145    virtual TList      *GetListOfKeys() const { return fKeys; }
00146    const TDatime      &GetModificationDate() const { return fDatimeM; }
00147    TObject            *GetMother() const { return fMother; }
00148    TDirectory         *GetMotherDir() const { return fMother==0 ? 0 : dynamic_cast<TDirectory*>(fMother); }
00149    virtual Int_t       GetNbytesKeys() const { return fNbytesKeys; }
00150    virtual Int_t       GetNkeys() const { return fKeys->GetSize(); }
00151    virtual Long64_t    GetSeekDir() const { return fSeekDir; }
00152    virtual Long64_t    GetSeekParent() const { return fSeekParent; }
00153    virtual Long64_t    GetSeekKeys() const { return fSeekKeys; }
00154    virtual const char *GetPathStatic() const;
00155    virtual const char *GetPath() const;
00156    TUUID               GetUUID() const {return fUUID;}
00157    Bool_t              IsFolder() const { return kTRUE; }
00158    Bool_t              IsModified() const { return fModified; }
00159    Bool_t              IsWritable() const { return fWritable; }
00160    virtual void        ls(Option_t *option="") const;
00161    virtual TDirectory *mkdir(const char *name, const char *title="");
00162    virtual void        Paint(Option_t *option="");
00163    virtual void        Print(Option_t *option="") const;
00164    virtual void        Purge(Short_t nkeep=1);
00165    virtual void        pwd() const;
00166    virtual void        ReadAll(Option_t *option="");
00167    virtual Int_t       ReadKeys();
00168    virtual void        RecursiveRemove(TObject *obj);
00169    virtual void        rmdir(const char *name);
00170    virtual void        Save();
00171    virtual void        SaveSelf(Bool_t force = kFALSE);
00172    virtual void        SetBufferSize(Int_t bufsize);
00173    void                SetModified() {fModified = kTRUE;}
00174    void                SetMother(const TObject *mother) {fMother = (TObject*)mother;}
00175    virtual void        SetName(const char* newname);
00176    void                SetSeekDir(Long64_t v) { fSeekDir = v; }
00177    void                SetWritable(Bool_t writable=kTRUE);
00178    virtual Int_t       Sizeof() const;
00179    virtual Int_t       Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0);
00180    virtual Int_t       Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0) const ;
00181    virtual Int_t       WriteTObject(const TObject *obj, const char *name=0, Option_t *option="");
00182    template <class T> inline Int_t WriteObject(const T* obj, const char* name, Option_t *option="") // see TDirectory::WriteObject or TDirectoryWriteObjectAny for explanation
00183       {
00184          return WriteObjectAny(obj,TBuffer::GetClass(typeid(T)),name,option);
00185       }
00186    virtual Int_t       WriteObjectAny(const void *obj, const char *classname, const char *name, Option_t *option="");
00187    virtual Int_t       WriteObjectAny(const void *obj, const TClass *cl, const char *name, Option_t *option="");
00188    virtual void        WriteDirHeader();
00189    virtual void        WriteKeys();
00190 
00191    static Bool_t       Cd(const char *path);
00192    static void         DecodeNameCycle(const char *namecycle, char *name, Short_t &cycle);
00193    static void         EncodeNameCycle(char *buffer, const char *name, Short_t cycle);
00194 
00195    ClassDef(TDirectory,4)  //Describe directory structure in memory
00196 };
00197 
00198 #endif
00199 

Generated on 12 Feb 2016 for ROOT Analyzer by  doxygen 1.6.1