Logo ROOT   6.16/01
Reference Guide
TFileSet.cxx
Go to the documentation of this file.
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
20//////////////////////////////////////////////////////////////////////////
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// //
36//////////////////////////////////////////////////////////////////////////
37
39
40////////////////////////////////////////////////////////////////////////////////
41///to be documented
42
44 : TDataSet()
45{
46}
47
48////////////////////////////////////////////////////////////////////////////////
49///
50/// Creates TFileSet
51/// Convert the "opearting system" file system tree into the memory resided TFileSet
52///
53/// Parameters:
54/// -----------
55/// dirname - the name of the "native file system" directory
56/// to convert into TFileSet
57/// setname - the name of this TFileSet (it is the "base name"
58/// of the "dirname" by default)
59/// expand - flag whether the "dirname" must be "expanded
60/// (kTRUE by default)
61/// maxDeep - the max number of the levels of the directory to read in
62/// (=10 by default)
63/// Note: If the "dirname" points to non-existent object, for examoe it is dead-link
64/// ---- the object is marked as "Zombie" and this flag is propagated upwards
65
66TFileSet::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 ) {
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;
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 }
113 } else
114 SetTitle("file");
115 } else {
116 // Set Zombie flag
117 MakeZombie();
118 SetTitle("Zombie");
119 }
120}
121
122////////////////////////////////////////////////////////////////////////////////
123///to be documented
124
126{
127}
128
129////////////////////////////////////////////////////////////////////////////////
130///to be documented
131
133{
134 return strcmp(GetTitle(),"file")!=0 ? kTRUE : kFALSE ;
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// This implementation is done in the TDataSet::Purge() method in mind
139/// Since this method returns non-zero for files the last are NOT "purged"
140/// by TDataSet::Purge()
141///
142
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
152////////////////////////////////////////////////////////////////////////////////
153/// If the title of this TFileSet is "file" it is NOT folder
154/// see: TFileSet(TString &dirname,const Char_t *setname,Bool_t expand)
155///
156
158{
159 return strcmp(GetTitle(),"file")!=0;
160}
int Int_t
Definition: RtypesCore.h:41
char Char_t
Definition: RtypesCore.h:29
const Bool_t kFALSE
Definition: RtypesCore.h:88
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
long long Long64_t
Definition: RtypesCore.h:69
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
virtual void Add(TDataSet *dataset)
Definition: TDataSet.h:150
virtual Long_t HasData() const
This implementation is done in the TDataSet::Purge() method in mind Since this method returns non-zer...
Definition: TFileSet.cxx:143
virtual Bool_t IsEmpty() const
to be documented
Definition: TFileSet.cxx:132
virtual ~TFileSet()
to be documented
Definition: TFileSet.cxx:125
virtual Bool_t IsFolder() const
If the title of this TFileSet is "file" it is NOT folder see: TFileSet(TString &dirname,...
Definition: TFileSet.cxx:157
TFileSet()
to be documented
Definition: TFileSet.cxx:43
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition: TObject.h:134
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
void MakeZombie()
Definition: TObject.h:49
Basic string class.
Definition: TString.h:131
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1264
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition: TSystem.cxx:852
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:843
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
Definition: TSystem.cxx:1061
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Definition: TSystem.cxx:1388
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition: TSystem.cxx:860
Definition: file.py:1