StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TFileSet.cxx
1 // @(#)root/table:$Id$
2 // Author: Valery Fine(fine@mail.cern.ch) 03/07/98
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 #include "TFileSet.h"
13 #include "TBrowser.h"
14 #include "TSystem.h"
15 
16 #ifndef WIN32
17 #include <errno.h>
18 #endif
19 
21 // //
22 // TFileSet //
23 // //
24 // TFileSet class is a class to convert the //
25 // "native file system structure" //
26 // into an instance of the TDataSet class //
27 // //
28 // Example: //
29 // How to convert your home directory into the OO dataset //
30 // //
31 // root [0] TString home = "$HOME"; //
32 // root [1] TFileSet set(home); //
33 // root [2] TBrowser b("MyHome",&set); //
34 // root [3] set.ls("*"); //
35 // //
37 
38 ClassImp(TFileSet);
39 
42 
44  : TDataSet()
45 {
46 }
47 
65 
66 TFileSet::TFileSet(const TString &dirname,const Char_t *setname,Bool_t expand, Int_t maxDepth)
67  : TDataSet()
68 {
69  if (!maxDepth) return;
70 
71  Long64_t size;
72  Long_t id, flags, modtime;
73  TString dirbuf = dirname;
74 
75  if (expand) gSystem->ExpandPathName(dirbuf);
76  const char *name= dirbuf;
77  if (gSystem->GetPathInfo(name, &id, &size, &flags, &modtime)==0) {
78 
79  if (!setname) {
80  setname = strrchr(name,'/');
81  if (setname) setname++;
82  }
83  if (setname) SetName(setname);
84  else SetName(name);
85 
86  // Check if "dirname" is a directory.
87  void *dir = 0;
88  if (flags & 2 ) {
89  dir = gSystem->OpenDirectory(name);
90  if (!dir) {
91 #ifndef WIN32
92  perror("can not be open due error\n");
93  Error("TFileSet", "directory: %s",name);
94 #endif
95  }
96  }
97  if (dir) { // this is a directory
98  SetTitle("directory");
99  while ( (name = gSystem->GetDirEntry(dir)) ) {
100  // skip some "special" names
101  if (!name[0] || strcmp(name,"..")==0 || strcmp(name,".")==0) continue;
102  Char_t *file = gSystem->ConcatFileName(dirbuf,name);
103  TString nextdir = file;
104  delete [] file;
105  TFileSet *fs = new TFileSet(nextdir,name,kFALSE,maxDepth-1);
106  if (fs->IsZombie()) {
107  // propagate "Zombie flag upwards
108  MakeZombie();
109  }
110  Add(fs);
111  }
112  gSystem->FreeDirectory(dir);
113  } else
114  SetTitle("file");
115  } else {
116  // Set Zombie flag
117  MakeZombie();
118  SetTitle("Zombie");
119  }
120 }
121 
124 
126 {
127 }
128 
131 
132 Bool_t TFileSet::IsEmpty() const
133 {
134  return strcmp(GetTitle(),"file")!=0 ? kTRUE : kFALSE ;
135 }
136 
142 
143 Long_t TFileSet::HasData() const
144 {
145  return strcmp(GetTitle(),"file")==0 ? 1 : 0;
146 
147  // this must be like this:
148  // return !IsFolder() ;
149  // Alas TObject::IsFolder() isn't defined as "const" (IT IS in 2.25/03)
150 }
151 
156 
157 Bool_t TFileSet::IsFolder() const
158 {
159  return strcmp(GetTitle(),"file")!=0;
160 }
Definition: FJcore.h:367
TFileSet()
to be documented
Definition: TFileSet.cxx:43
virtual Long_t HasData() const
Definition: TFileSet.cxx:143
virtual Bool_t IsEmpty() const
to be documented
Definition: TFileSet.cxx:132
virtual Bool_t IsFolder() const
Definition: TFileSet.cxx:157
virtual ~TFileSet()
to be documented
Definition: TFileSet.cxx:125