TFileSet.cxx

Go to the documentation of this file.
00001 // @(#)root/table:$Id: TFileSet.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Valery Fine(fine@mail.cern.ch)   03/07/98
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 #include "TFileSet.h"
00013 #include "TBrowser.h"
00014 #include "TSystem.h"
00015 
00016 #ifndef WIN32
00017 #include <errno.h>
00018 #endif
00019 
00020 //////////////////////////////////////////////////////////////////////////
00021 //                                                                      //
00022 // TFileSet                                                             //
00023 //                                                                      //
00024 // TFileSet class is a class to convert the                             //
00025 //      "native file system structure"                                  //
00026 // into an instance of the TDataSet class                               //
00027 //                                                                      //
00028 //  Example:                                                            //
00029 //    How to convert your home directory into the OO dataset            //
00030 //                                                                      //
00031 //  root [0] TString home = "$HOME";                                    //
00032 //  root [1] TFileSet set(home);                                        //
00033 //  root [2] TBrowser b("MyHome",&set);                                 //
00034 //  root [3] set.ls("*");                                               //
00035 //                                                                      //
00036 //////////////////////////////////////////////////////////////////////////
00037 
00038 ClassImp(TFileSet)
00039 
00040 //______________________________________________________________________________
00041 TFileSet::TFileSet()
00042          : TDataSet()
00043 {
00044    //to be documented
00045 }
00046 
00047 //______________________________________________________________________________
00048 TFileSet::TFileSet(const TString &dirname,const Char_t *setname,Bool_t expand, Int_t maxDepth)
00049            : TDataSet()
00050 {
00051   //
00052   // Creates TFileSet
00053   // Convert the "opearting system" file system tree into the memory resided TFileSet
00054   //
00055   //  Parameters:
00056   //  -----------
00057   //  dirname  - the name of the "native file system" directory
00058   //             to convert into TFileSet
00059   //  setname  - the name of this TFileSet (it is the "base name"
00060   //                                 of the "dirname" by default)
00061   //  expand   - flag whether the "dirname" must be "expanded
00062   //             (kTRUE by default)
00063   //  maxDeep  - the max number of the levels of the directory to read in
00064   //             (=10 by default)
00065   //  Note: If the "dirname" points to non-existent object, for examoe it is dead-link
00066   //  ----  the object is marked as "Zombie" and this flag is propagated upwards
00067 
00068    if (!maxDepth) return;
00069 
00070    Long64_t size;
00071    Long_t id, flags, modtime;
00072    TString dirbuf = dirname;
00073 
00074    if (expand) gSystem->ExpandPathName(dirbuf);
00075    const char *name= dirbuf;
00076    if (gSystem->GetPathInfo(name, &id, &size, &flags, &modtime)==0) {
00077 
00078       if (!setname) {
00079          setname = strrchr(name,'/');
00080          if (setname) setname++;
00081       }
00082       if (setname) SetName(setname);
00083       else SetName(name);
00084 
00085       // Check if "dirname" is a directory.
00086       void *dir = 0;
00087       if (flags & 2 ) {
00088          dir = gSystem->OpenDirectory(name);
00089          if (!dir) {
00090 #ifndef WIN32
00091             perror("can not be open due error\n");
00092             Error("TFileSet", "directory: %s",name);
00093 #endif
00094          }
00095       }
00096       if (dir) {   // this is a directory
00097          SetTitle("directory");
00098          while ( (name = gSystem->GetDirEntry(dir)) ) {
00099             // skip some "special" names
00100             if (!name[0] || strcmp(name,"..")==0 || strcmp(name,".")==0) continue;
00101             Char_t *file = gSystem->ConcatFileName(dirbuf,name);
00102             TString nextdir = file;
00103             delete [] file;
00104             TFileSet *fs = new TFileSet(nextdir,name,kFALSE,maxDepth-1);
00105             if (fs->IsZombie())  {
00106                // propagate "Zombie flag upwards
00107                MakeZombie();
00108             }
00109             Add(fs);
00110          }
00111          gSystem->FreeDirectory(dir);
00112       } else
00113          SetTitle("file");
00114    } else {
00115       // Set Zombie flag
00116       MakeZombie();
00117       SetTitle("Zombie");
00118    }
00119 }
00120 
00121 //______________________________________________________________________________
00122 TFileSet::~TFileSet()
00123 {
00124    //to be documented
00125 }
00126 
00127 //______________________________________________________________________________
00128 Bool_t TFileSet::IsEmpty() const
00129 {
00130    //to be documented
00131    return  strcmp(GetTitle(),"file")!=0 ? kTRUE : kFALSE ;
00132 }
00133 
00134 //______________________________________________________________________________
00135 Long_t TFileSet::HasData() const
00136 {
00137    // This implementation is done in the TDataSet::Purge() method in mind
00138    // Since this method returns non-zero for files the last are NOT "purged"
00139    // by TDataSet::Purge()
00140    //
00141    return strcmp(GetTitle(),"file")==0 ? 1 : 0;
00142 
00143    //  this must be like this:
00144    //  return !IsFolder() ;
00145    //  Alas TObject::IsFolder() isn't defined as "const" (IT IS in 2.25/03)
00146 }
00147 
00148 //______________________________________________________________________________
00149 Bool_t TFileSet::IsFolder() const
00150 {
00151    // If the title of this TFileSet is "file" it is NOT folder
00152    // see: TFileSet(TString &dirname,const Char_t *setname,Bool_t expand)
00153    //
00154    return strcmp(GetTitle(),"file")!=0;
00155 }

Generated on Tue Jul 5 14:45:04 2011 for ROOT_528-00b_version by  doxygen 1.5.1