Logo ROOT   6.07/09
Reference Guide
TAlienDirectory.cxx
Go to the documentation of this file.
1 // @(#)root/alien:$Id$
2 // Author: Jan Fiete Grosse-Oetringhaus 28/9/2004
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, 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 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TAlienDirectory //
15 // //
16 // Class which creates Directory files for the AliEn middleware //
17 // //
18 //////////////////////////////////////////////////////////////////////////
19 
20 #include "TAlienDirectory.h"
21 #include "TAlien.h"
22 #include "TGridResult.h"
23 #include "TSystemFile.h"
24 #include "TAlienFile.h"
25 #include "TSystem.h"
26 #include "TFile.h"
27 #include "TObjString.h"
28 
29 
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 /// Browse an Alien directory.
34 
36 {
37  if (b) {
38  TString alienname = "alien://";
39  alienname += fLfn;
40  if (!fBrowserObjects.FindObject(alienname)) {
41  TFile *newfile = TFile::Open(alienname.Data());
42  b->Add(newfile);
43  fBrowserObjects.Add(new TObjString(alienname.Data()), (TObject*) newfile);
44  }
45  }
46 }
47 
48 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Constructor.
53 
54 TAlienDirectory::TAlienDirectory(const char *ldn, const char *name)
55 {
56  if (!gGrid->Cd(ldn)) {
57  MakeZombie();
58  return;
59  }
60 
61  if (!name) {
62  SetName(gSystem->BaseName(ldn));
63  } else {
64  SetName(name);
65  }
66 
67  SetTitle(ldn);
68 };
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// Fill directory entry list.
72 
74 {
75  if (!gGrid->Cd(GetTitle())) {
76  MakeZombie();
77  return;
78  }
79 
80  fEntries.Clear();
81  TGridResult *dirlist = gGrid->Ls(GetTitle(), "-la");
82  if (dirlist) {
83  dirlist->Sort();
84  Int_t i = 0;
85  while (dirlist->GetFileName(i)) {
86  if (!strcmp(".",dirlist->GetFileName(i))) {
87  i++;
88  continue;
89  }
90  if (!strcmp("..",dirlist->GetFileName(i))) {
91  i++;
92  continue;
93  }
94 
95  if (dirlist->GetKey(i,"permissions")[0] == 'd') {
96  fEntries.Add(new TAlienDirectory(dirlist->GetFileNamePath(i)));
97  } else {
98  fEntries.Add(new TAlienDirectoryEntry(dirlist->GetFileNamePath(i), dirlist->GetFileName(i)));
99  }
100  i++;
101  }
102  delete dirlist;
103  }
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Browser interface to ob status.
108 
110 {
111  if (b) {
112  Fill();
113  TIter next(&fEntries);
114  TObject *obj = 0;
115  TObject *bobj = 0;
116  while ((obj = next())) {
117  if (!(bobj = fBrowserObjects.FindObject(obj->GetName()))) {
118  b->Add(obj, obj->GetName());
119  fBrowserObjects.Add(new TObjString(obj->GetName()), (TObject*) obj);
120  } else {
121  b->Add(bobj, bobj->GetName());
122  }
123  }
124  }
125 }
126 
127 ////////////////////////////////////////////////////////////////////////////////
128 /// Destructor.
129 
131 {
132  fEntries.Clear();
133 }
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
Definition: TBrowser.cxx:261
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:929
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
TAlienDirectory(const char *ldn, const char *name=0)
Constructor.
Collectable string class.
Definition: TObjString.h:32
R__EXTERN TGrid * gGrid
Definition: TGrid.h:135
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
virtual const char * GetFileName(UInt_t) const
Definition: TGridResult.h:39
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection)...
Definition: TMap.cxx:53
void Browse(TBrowser *b)
Browser interface to ob status.
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
virtual Bool_t Cd(const char *="", Bool_t=kFALSE)
Definition: TGrid.h:97
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3871
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition: TList.cxx:771
const char * Data() const
Definition: TString.h:349
virtual ~TAlienDirectory()
Destructor.
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition: TMap.cxx:214
void Add(TObject *obj, Bool_t replace=kFALSE)
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
virtual const char * GetFileNamePath(UInt_t) const
Definition: TGridResult.h:41
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
void Fill()
Fill directory entry list.
virtual const char * GetKey(UInt_t, const char *) const
Definition: TGridResult.h:47
#define ClassImp(name)
Definition: Rtypes.h:279
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:416
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Definition: TList.cxx:349
Mother of all ROOT objects.
Definition: TObject.h:44
typedef void((*Func_t)())
virtual void Add(TObject *obj)
Definition: TList.h:81
void MakeZombie()
Definition: TObject.h:54
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
virtual TGridResult * Ls(const char *="", Option_t *="", Bool_t=kFALSE)
Definition: TGrid.h:91
gr SetName("gr")
char name[80]
Definition: TGX11.cxx:109