Logo ROOT  
Reference Guide
TRemoteObject.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Bertrand Bellenot 19/06/2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, 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 /** \class TRemoteObject
13 \ingroup Base
14 
15 The TRemoteObject class provides protocol for browsing ROOT objects
16 from a remote ROOT session.
17 
18 It contains information on the real remote object as:
19 
20  - Object Properties (i.e. file stat if the object is a TSystemFile)
21  - Object Name
22  - Class Name
23  - TKey Object Name (if the remote object is a TKey)
24  - TKey Class Name (if the remote object is a TKey)
25  - Remote object address
26 */
27 
28 #include "TRemoteObject.h"
29 #include "TSystemDirectory.h"
30 #include "TApplication.h"
31 #include "TROOT.h"
32 #include "TBuffer.h"
33 #include "TBrowser.h"
34 #include "TList.h"
35 #include "TClass.h"
36 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Create a remote object.
41 
43 {
44  fIsFolder = kFALSE;
45  fRemoteAddress = 0;
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Create a remote object.
50 
51 TRemoteObject::TRemoteObject(const char *name, const char *title,
52  const char *classname) : TNamed(name, title)
53 {
54  fIsFolder = kFALSE;
55  fClassName = classname;
56  if ((fClassName == "TSystemDirectory") ||
57  (fClassName == "TFile"))
58  fIsFolder = kTRUE;
59  if (!strcmp(classname, "TSystemDirectory") ||
60  !strcmp(classname, "TSystemFile")) {
62  }
63  Long_t raddr = (Long_t) this;
64  fRemoteAddress = raddr;
65 }
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// Delete remote object.
69 
71 {
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Browse remote object.
76 
78 {
79  TList *ret;
80  TRemoteObject *robj;
81  const char *file;
82 
83  if (fClassName == "TSystemFile") {
84  if (b)
85  b->ExecuteDefaultAction(this);
86  return;
87  }
88  if (fClassName == "TKey") {
89  if (b->GetRefreshFlag())
90  b->SetRefreshFlag(kFALSE);
92  TObject *obj = (TObject *)gROOT->ProcessLine(Form("((TApplicationServer *)gApplication)->BrowseKey(\"%s\");", GetName()));
93  if (obj) {
94  if (obj->IsA()->GetMethodWithPrototype("SetDirectory", "TDirectory*"))
95  gROOT->ProcessLine(Form("((%s *)0x%lx)->SetDirectory(0);", obj->ClassName(), (ULong_t)obj));
96  obj->Browse(b);
97  b->SetRefreshFlag(kTRUE);
98  }
99  }
100  if (fClassName == "TSystemDirectory") {
101  if (b->GetRefreshFlag())
102  b->SetRefreshFlag(kFALSE);
104  ret = (TList *)gROOT->ProcessLine(Form("((TApplicationServer *)gApplication)->BrowseDirectory(\"%s\");", GetTitle()));
105  if (ret) {
106  TIter next(ret);
107  while ((robj = (TRemoteObject *)next())) {
108  file = robj->GetName();
109  if (b->TestBit(TBrowser::kNoHidden) && file[0] == '.' && file[1] != '.' )
110  continue;
111  b->Add(robj, robj->GetName());
112  }
113  }
114  return;
115  }
116  if (fClassName == "TFile") {
117  if (b->GetRefreshFlag())
118  b->SetRefreshFlag(kFALSE);
120  ret = (TList *)gROOT->ProcessLine(Form("((TApplicationServer *)gApplication)->BrowseFile(\"%s\");", GetName()));
121  if (ret) {
122  TIter next(ret);
123  while ((robj = (TRemoteObject *)next())) {
124  //file = robj->GetName();
125  b->Add(robj, robj->GetName());
126  }
127  }
128  return;
129  }
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Browse OS system directories.
134 
136 {
137  // Collections to keep track of all browser objects that have been
138  // generated. It's main goal is to prevent the continuous
139  // allocations of new objects with the same names during browsing.
140  TList *objects = new TList;
141 
142  static Int_t level = 0;
143  const char *name = GetTitle();
144  TRemoteObject *sdir;
145 
146  if (GetName()[0] == '.' && GetName()[1] == '.')
148 
149  TSystemDirectory dir(name, name);
150  TList *files = dir.GetListOfFiles();
151  if (files) {
152  files->Sort();
153  TIter next(files);
154  TSystemFile *file;
155  TString fname;
156  // directories first
157  while ((file=(TSystemFile*)next())) {
158  fname = file->GetName();
159  if (file->IsDirectory()) {
160  level++;
161  TString sdirpath;
162  if (!strcmp(fname.Data(), "."))
163  sdirpath = name;
164  else if (!strcmp(fname.Data(), ".."))
165  sdirpath = gSystem->GetDirName(name);
166  else {
167  sdirpath = name;
168  if (!sdirpath.EndsWith("/"))
169  sdirpath += "/";
170  sdirpath += fname.Data();
171  }
172  sdir = new TRemoteObject(fname.Data(), sdirpath.Data(), "TSystemDirectory");
173  objects->Add(sdir);
174  level--;
175  }
176  }
177  // then files...
178  TIter nextf(files);
179  while ((file=(TSystemFile*)nextf())) {
180  fname = file->GetName();
181  if (!file->IsDirectory()) {
182  sdir = new TRemoteObject(fname.Data(), gSystem->WorkingDirectory(), "TSystemFile");
183  objects->Add(sdir);
184  }
185  }
186  delete files;
187  }
188  return objects;
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Get remote file status.
193 
195 {
196  buf->fDev = fFileStat.fDev;
197  buf->fIno = fFileStat.fIno;
198  buf->fMode = fFileStat.fMode;
199  buf->fUid = fFileStat.fUid;
200  buf->fGid = fFileStat.fGid;
201  buf->fSize = fFileStat.fSize;
202  buf->fMtime = fFileStat.fMtime;
203  buf->fIsLink = fFileStat.fIsLink;
204  return kTRUE;
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// Remote object streamer.
209 
210 void TRemoteObject::Streamer(TBuffer &b)
211 {
212  if (b.IsReading()) {
213  b >> fFileStat.fDev;
214  b >> fFileStat.fIno;
215  b >> fFileStat.fMode;
216  b >> fFileStat.fUid;
217  b >> fFileStat.fGid;
218  b >> fFileStat.fSize;
219  b >> fFileStat.fMtime;
220  b >> fFileStat.fIsLink;
221  b >> fIsFolder;
222  b >> fRemoteAddress;
223  b >> fClassName;
224  b >> fKeyObjectName;
225  b >> fKeyClassName;
226  }
227  else {
228  b << fFileStat.fDev;
229  b << fFileStat.fIno;
230  b << fFileStat.fMode;
231  b << fFileStat.fUid;
232  b << fFileStat.fGid;
233  b << fFileStat.fSize;
234  b << fFileStat.fMtime;
235  b << fFileStat.fIsLink;
236  b << fIsFolder;
237  b << fRemoteAddress;
238  b << fClassName;
239  b << fKeyObjectName;
240  b << fKeyClassName;
241  }
242  TNamed::Streamer(b);
243 }
TSystem::GetPathInfo
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:1396
TSystemDirectory::GetListOfFiles
virtual TList * GetListOfFiles() const
Returns a TList of TSystemFile objects representing the contents of the directory.
Definition: TSystemDirectory.cxx:84
TBrowser
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TNamed::SetName
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
TRemoteObject::fFileStat
FileStat_t fFileStat
Definition: TRemoteObject.h:37
TSystem::BaseName
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:933
TString::Data
const char * Data() const
Definition: TString.h:369
TRemoteObject::fKeyObjectName
TString fKeyObjectName
Definition: TRemoteObject.h:41
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
FileStat_t
Definition: TSystem.h:124
FileStat_t::fMtime
Long_t fMtime
Definition: TSystem.h:131
TSystemDirectory
Describes an Operating System directory for the browser.
Definition: TSystemDirectory.h:32
TBrowser.h
TString::EndsWith
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2177
TClass.h
TRemoteObject::fKeyClassName
TString fKeyClassName
Definition: TRemoteObject.h:42
TList.h
TBuffer
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
TString
Basic string class.
Definition: TString.h:136
FileStat_t::fUid
Int_t fUid
Definition: TSystem.h:128
b
#define b(i)
Definition: RSha256.hxx:100
TSystem::GetDirName
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:1030
TRemoteObject.h
bool
TSystem::WorkingDirectory
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:870
TList::Sort
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition: TList.cxx:937
TROOT.h
TApplication.h
TRemoteObject
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session.
Definition: TRemoteObject.h:34
TSystemDirectory.h
TBrowser::kNoHidden
@ kNoHidden
Definition: TBrowser.h:55
TBuffer.h
TApplication::kProcessRemotely
@ kProcessRemotely
Definition: TApplication.h:44
TSystemFile
A TSystemFile describes an operating system file.
Definition: TSystemFile.h:29
TObject::SetBit
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
FileStat_t::fMode
Int_t fMode
Definition: TSystem.h:127
FileStat_t::fGid
Int_t fGid
Definition: TSystem.h:129
FileStat_t::fIsLink
Bool_t fIsLink
Definition: TSystem.h:132
FileStat_t::fSize
Long64_t fSize
Definition: TSystem.h:130
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TRemoteObject::fClassName
TString fClassName
Definition: TRemoteObject.h:40
Long_t
long Long_t
Definition: RtypesCore.h:54
TRemoteObject::~TRemoteObject
virtual ~TRemoteObject()
Delete remote object.
Definition: TRemoteObject.cxx:70
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
FileStat_t::fIno
Long_t fIno
Definition: TSystem.h:126
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
TRemoteObject::fIsFolder
Bool_t fIsFolder
Definition: TRemoteObject.h:38
file
Definition: file.py:1
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
name
char name[80]
Definition: TGX11.cxx:110
TIter
Definition: TCollection.h:233
TRemoteObject::fRemoteAddress
Long64_t fRemoteAddress
Definition: TRemoteObject.h:39
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
TRemoteObject::Browse
TList * Browse()
Browse OS system directories.
Definition: TRemoteObject.cxx:135
TObject::ClassName
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:130
TRemoteObject::TRemoteObject
TRemoteObject()
Create a remote object.
Definition: TRemoteObject.cxx:42
TList
A doubly linked list.
Definition: TList.h:44
TRemoteObject::GetFileStat
Bool_t GetFileStat(FileStat_t *sbuf)
Get remote file status.
Definition: TRemoteObject.cxx:194
gROOT
#define gROOT
Definition: TROOT.h:406
int
FileStat_t::fDev
Long_t fDev
Definition: TSystem.h:125