ROOT  6.06/09
Reference Guide
TDirectory.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id: 65b4f3646f4e5b2fa77218ba786b7fe4e16e27be $
2 // Author: Rene Brun 28/11/94
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 #include <stdlib.h>
12 
13 #include "Riostream.h"
14 #include "Strlen.h"
15 #include "TDirectory.h"
16 #include "TClassTable.h"
17 #include "TInterpreter.h"
18 #include "THashList.h"
19 #include "TBrowser.h"
20 #include "TROOT.h"
21 #include "TError.h"
22 #include "TClass.h"
23 #include "TRegexp.h"
24 #include "TSystem.h"
25 #include "TVirtualMutex.h"
26 #include "TThreadSlots.h"
27 #include "TMethod.h"
28 
30 
31 const Int_t kMaxLen = 2048;
32 
33 /** \class TDirectory
34 Describe directory structure in memory.
35 */
36 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Directory default constructor.
41 
42 TDirectory::TDirectory() : TNamed(), fMother(0),fList(0),fContext(0)
43 {
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Create a new Directory.
48 ///
49 /// A new directory with name,title is created in the current directory
50 /// The directory header information is immediately saved in the file
51 /// A new key is added in the parent directory
52 ///
53 /// When this constructor is called from a class directly derived
54 /// from TDirectory, the third argument classname MUST be specified.
55 /// In this case, classname must be the name of the derived class.
56 ///
57 /// Note that the directory name cannot contain slashes.
58 
59 TDirectory::TDirectory(const char *name, const char *title, Option_t * /*classname*/, TDirectory* initMotherDir)
60  : TNamed(name, title), fMother(0), fList(0),fContext(0)
61 {
62  if (initMotherDir==0) initMotherDir = gDirectory;
63 
64  if (strchr(name,'/')) {
65  ::Error("TDirectory::TDirectory","directory name (%s) cannot contain a slash", name);
66  gDirectory = 0;
67  return;
68  }
69  if (strlen(GetName()) == 0) {
70  ::Error("TDirectory::TDirectory","directory name cannot be \"\"");
71  gDirectory = 0;
72  return;
73  }
74 
75  Build(initMotherDir ? initMotherDir->GetFile() : 0, initMotherDir);
76 
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Copy constructor.
82 
83 TDirectory::TDirectory(const TDirectory &directory) : TNamed(directory)
84 {
85  directory.Copy(*this);
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Destructor.
90 
92 {
93  if (!gROOT) {
94  delete fList;
95  return; //when called by TROOT destructor
96  }
97 
98  if (fList) {
99  fList->Delete("slow");
100  SafeDelete(fList);
101  }
102 
103  CleanTargets();
104 
105  TDirectory* mom = GetMotherDir();
106 
107  if (mom) {
108  mom->Remove(this);
109  }
110 
111  if (gDebug) {
112  Info("~TDirectory", "dtor called for %s", GetName());
113  }
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Sets the flag controlling the automatic add objects like histograms, TGraph2D, etc
118 /// in memory
119 ///
120 /// By default (fAddDirectory = kTRUE), these objects are automatically added
121 /// to the list of objects in memory.
122 /// Note that in the classes like TH1, TGraph2D supporting this facility,
123 /// one object can be removed from its support directory
124 /// by calling object->SetDirectory(0) or object->SetDirectory(dir) to add it
125 /// to the list of objects in the directory dir.
126 ///
127 /// NOTE that this is a static function. To call it, use:
128 /// ~~~ {.cpp}
129 /// TDirectory::AddDirectory
130 /// ~~~
131 
133 {
134  fgAddDirectory = add;
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Static function: see TDirectory::AddDirectory for more comments.
139 
141 {
142  return fgAddDirectory;
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Append object to this directory.
147 ///
148 /// If `replace` is true:
149 /// remove any existing objects with the same name (if the name is not "")
150 
151 void TDirectory::Append(TObject *obj, Bool_t replace /* = kFALSE */)
152 {
153  if (obj == 0 || fList == 0) return;
154 
155  if (replace && obj->GetName() && obj->GetName()[0]) {
156  TObject *old;
157  while (0!=(old = GetList()->FindObject(obj->GetName()))) {
158  Warning("Append","Replacing existing %s: %s (Potential memory leak).",
159  obj->IsA()->GetName(),obj->GetName());
160  ROOT::DirAutoAdd_t func = old->IsA()->GetDirectoryAutoAdd();
161  if (func) {
162  func(old,0);
163  } else {
164  Remove(old);
165  }
166  }
167  }
168 
169  fList->Add(obj);
170  obj->SetBit(kMustCleanup);
171 }
172 
173 ////////////////////////////////////////////////////////////////////////////////
174 /// Browse the content of the directory.
175 
177 {
178  if (b) {
179  TObject *obj = 0;
180  TIter nextin(fList);
181 
182  cd();
183 
184  //Add objects that are only in memory
185  while ((obj = nextin())) {
186  b->Add(obj, obj->GetName());
187  }
188  }
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Initialise directory to defaults.
193 ///
194 /// If directory is created via default ctor (when dir is read from file)
195 /// don't add it here to the directory since its name is not yet known.
196 /// It will be added to the directory in TKey::ReadObj().
197 
198 void TDirectory::Build(TFile* /*motherFile*/, TDirectory* motherDir)
199 {
200  if (motherDir && strlen(GetName()) != 0) motherDir->Append(this);
201 
202  fList = new THashList(100,50);
203  fMother = motherDir;
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// Clean the pointers to this object (gDirectory, TContext, etc.).
209 
211 {
212  while (fContext) {
213  fContext->fDirectory = 0;
215  }
216 
217  if (gDirectory == this) {
218  TDirectory *cursav = GetMotherDir();
219  if (cursav && cursav != this) {
220  cursav->cd();
221  } else {
222  if (this == gROOT) {
223  gDirectory = 0;
224  } else {
225  gROOT->cd();
226  }
227  }
228  }
229 }
230 
231 ////////////////////////////////////////////////////////////////////////////////
232 /// Fast execution of 'new TBufferFile(TBuffer::kWrite,10000), without having
233 /// a compile time circular dependency ... alternatively we could (should?)
234 /// introduce yet another abstract interface.
235 
237 {
238  typedef void (*tcling_callfunc_Wrapper_t)(void*, int, void**, void*);
239  static tcling_callfunc_Wrapper_t creator = 0;
240  if (creator == 0) {
242  TClass *c = TClass::GetClass("TBufferFile");
243  TMethod *m = c->GetMethodWithPrototype("TBufferFile","TBuffer::EMode,Int_t",kFALSE,ROOT::kExactMatch);
244  creator = (tcling_callfunc_Wrapper_t)( m->InterfaceMethod() );
245  }
247  Int_t size = 10000;
248  void *args[] = { &mode, &size };
249  TBuffer *result;
250  creator(0,2,args,&result);
251  return result;
252 }
253 
254 ////////////////////////////////////////////////////////////////////////////////
255 /// Clone an object.
256 /// This function is called when the directory is not a TDirectoryFile.
257 /// This version has to load the I/O package, hence via Cling.
258 ///
259 /// If autoadd is true and if the object class has a
260 /// DirectoryAutoAdd function, it will be called at the end of the
261 /// function with the parameter gDirector. This usually means that
262 /// the object will be appended to the current ROOT directory.
263 
264 TObject *TDirectory::CloneObject(const TObject *obj, Bool_t autoadd /* = kTRUE */)
265 {
266  // if no default ctor return immediately (error issued by New())
267  char *pobj = (char*)obj->IsA()->New();
268  if (!pobj) {
269  Fatal("CloneObject","Failed to create new object");
270  return 0;
271  }
272 
273  Int_t baseOffset = obj->IsA()->GetBaseClassOffset(TObject::Class());
274  if (baseOffset==-1) {
275  // cl does not inherit from TObject.
276  // Since this is not supported in this function, the only reason we could reach this code
277  // is because something is screwed up in the ROOT code.
278  Fatal("CloneObject","Incorrect detection of the inheritance from TObject for class %s.\n",
279  obj->IsA()->GetName());
280  }
281  TObject *newobj = (TObject*)(pobj+baseOffset);
282 
283  //create a buffer where the object will be streamed
284  //We are forced to go via the I/O package (ie TBufferFile).
285  //Invoking TBufferFile via CINT will automatically load the I/O library
286  TBuffer *buffer = R__CreateBuffer();
287  if (!buffer) {
288  Fatal("CloneObject","Not able to create a TBuffer!");
289  return 0;
290  }
291  buffer->MapObject(obj); //register obj in map to handle self reference
292  const_cast<TObject*>(obj)->Streamer(*buffer);
293 
294  // read new object from buffer
295  buffer->SetReadMode();
296  buffer->ResetMap();
297  buffer->SetBufferOffset(0);
298  buffer->MapObject(newobj); //register obj in map to handle self reference
299  newobj->Streamer(*buffer);
300  newobj->ResetBit(kIsReferenced);
301  newobj->ResetBit(kCanDelete);
302 
303  delete buffer;
304  if (autoadd) {
305  ROOT::DirAutoAdd_t func = obj->IsA()->GetDirectoryAutoAdd();
306  if (func) {
307  func(newobj,this);
308  }
309  }
310  return newobj;
311 }
312 
313 ////////////////////////////////////////////////////////////////////////////////
314 /// Return the current directory for the current thread.
315 
317 {
318  static TDirectory *currentDirectory = 0;
319  if (!gThreadTsd)
320  return currentDirectory;
321  else
322  return *(TDirectory**)(*gThreadTsd)(&currentDirectory,ROOT::kDirectoryThreadSlot);
323 }
324 
325 ////////////////////////////////////////////////////////////////////////////////
326 /// Find a directory using apath.
327 /// It apath is null or empty, returns "this" directory.
328 /// Otherwise use apath to find a directory.
329 /// The absolute path syntax is: `file.root:/dir1/dir2`
330 ///
331 /// where file.root is the file and /dir1/dir2 the desired subdirectory
332 /// in the file. Relative syntax is relative to "this" directory. E.g: `../aa`.
333 /// Returns 0 in case path does not exist.
334 /// If printError is true, use Error with 'funcname' to issue an error message.
335 
337  Bool_t printError, const char *funcname)
338 {
339  Int_t nch = 0;
340  if (apath) nch = strlen(apath);
341  if (!nch) {
342  return this;
343  }
344 
345  if (funcname==0 || strlen(funcname)==0) funcname = "GetDirectory";
346 
347  TDirectory *result = this;
348 
349  char *path = new char[nch+1]; path[0] = 0;
350  if (nch) strlcpy(path,apath,nch+1);
351  char *s = (char*)strrchr(path, ':');
352  if (s) {
353  *s = '\0';
355  TDirectory *f = (TDirectory *)gROOT->GetListOfFiles()->FindObject(path);
356  if (!f && !strcmp(gROOT->GetName(), path)) f = gROOT;
357  if (s) *s = ':';
358  if (f) {
359  result = f;
360  if (s && *(s+1)) result = f->GetDirectory(s+1,printError,funcname);
361  delete [] path; return result;
362  } else {
363  if (printError) Error(funcname, "No such file %s", path);
364  delete [] path; return 0;
365  }
366  }
367 
368  // path starts with a slash (assumes current file)
369  if (path[0] == '/') {
370  TDirectory *td = gROOT;
371  result = td->GetDirectory(path+1,printError,funcname);
372  delete [] path; return result;
373  }
374 
375  TObject *obj;
376  char *slash = (char*)strchr(path,'/');
377  if (!slash) { // we are at the lowest level
378  if (!strcmp(path, "..")) {
379  result = GetMotherDir();
380  delete [] path; return result;
381  }
382  obj = Get(path);
383  if (!obj) {
384  if (printError) Error(funcname,"Unknown directory %s", path);
385  delete [] path; return 0;
386  }
387 
388  //Check return object is a directory
389  if (!obj->InheritsFrom(TDirectory::Class())) {
390  if (printError) Error(funcname,"Object %s is not a directory", path);
391  delete [] path; return 0;
392  }
393  delete [] path; return (TDirectory*)obj;
394  }
395 
396  TString subdir(path);
397  slash = (char*)strchr(subdir.Data(),'/');
398  *slash = 0;
399  //Get object with path from current directory/file
400  if (!strcmp(subdir, "..")) {
401  TDirectory* mom = GetMotherDir();
402  if (mom)
403  result = mom->GetDirectory(slash+1,printError,funcname);
404  delete [] path; return result;
405  }
406  obj = Get(subdir);
407  if (!obj) {
408  if (printError) Error(funcname,"Unknown directory %s", subdir.Data());
409  delete [] path; return 0;
410  }
411 
412  //Check return object is a directory
413  if (!obj->InheritsFrom(TDirectory::Class())) {
414  if (printError) Error(funcname,"Object %s is not a directory", subdir.Data());
415  delete [] path; return 0;
416  }
417  result = ((TDirectory*)obj)->GetDirectory(slash+1,printError,funcname);
418  delete [] path; return result;
419 }
420 
421 ////////////////////////////////////////////////////////////////////////////////
422 /// Change current directory to "this" directory.
423 ///
424 /// Using path one can change the current directory to "path". The absolute path
425 /// syntax is: `file.root:/dir1/dir2`
426 /// where `file.root` is the file and `/dir1/dir2` the desired subdirectory
427 /// in the file.
428 ///
429 /// Relative syntax is relative to "this" directory. E.g: `../aa`.
430 ///
431 /// Returns kTRUE in case of success.
432 
433 Bool_t TDirectory::cd(const char *path)
434 {
435  return cd1(path);
436 }
437 
438 ////////////////////////////////////////////////////////////////////////////////
439 /// Change current directory to "this" directory.
440 ///
441 /// Using path one can
442 /// change the current directory to "path". The absolute path syntax is:
443 /// `file.root:/dir1/dir2`
444 /// where `file.root` is the file and `/dir1/dir2` the desired subdirectory
445 /// in the file.
446 ///
447 /// Relative syntax is relative to "this" directory. E.g: `../aa`.
448 ///
449 /// Returns kFALSE in case path does not exist.
450 
451 Bool_t TDirectory::cd1(const char *apath)
452 {
453  Int_t nch = 0;
454  if (apath) nch = strlen(apath);
455  if (!nch) {
456  gDirectory = this;
457  return kTRUE;
458  }
459 
460  TDirectory *where = GetDirectory(apath,kTRUE,"cd");
461  if (where) {
462  where->cd();
463  return kTRUE;
464  }
465  return kFALSE;
466 }
467 
468 ////////////////////////////////////////////////////////////////////////////////
469 /// Change current directory to "path". The absolute path syntax is:
470 /// `file.root:/dir1/dir2`
471 /// where file.root is the file and `/dir1/dir2 the desired subdirectory
472 /// in the file.
473 /// Relative syntax is relative to the current directory `gDirectory`, e.g.: `../aa`.
474 ///
475 /// Returns kTRUE in case of success.
476 
477 Bool_t TDirectory::Cd(const char *path)
478 {
479  return Cd1(path);
480 }
481 
482 ////////////////////////////////////////////////////////////////////////////////
483 /// Change current directory to "path". The path syntax is:
484 /// `file.root:/dir1/dir2`
485 /// where file.root is the file and `/dir1/dir2` the desired subdirectory
486 /// in the file.
487 ///
488 /// Returns kFALSE in case path does not exist.
489 
490 Bool_t TDirectory::Cd1(const char *apath)
491 {
492  // null path is always true (i.e. stay in the current directory)
493  Int_t nch = 0;
494  if (apath) nch = strlen(apath);
495  if (!nch) return kTRUE;
496 
497  TDirectory *where = gDirectory->GetDirectory(apath,kTRUE,"Cd");
498  if (where) {
499  where->cd();
500  return kTRUE;
501  }
502  return kFALSE;
503 }
504 
505 ////////////////////////////////////////////////////////////////////////////////
506 /// Delete all objects from a Directory list.
507 
509 {
510  if (fList) fList->Clear();
511 
512 }
513 
514 ////////////////////////////////////////////////////////////////////////////////
515 /// Delete all objects from memory and directory structure itself.
516 
518 {
519  if (!fList) {
520  return;
521  }
522 
523  // Save the directory key list and header
524  Save();
525 
526  Bool_t fast = kTRUE;
527  TObjLink *lnk = fList->FirstLink();
528  while (lnk) {
529  if (lnk->GetObject()->IsA() == TDirectory::Class()) {fast = kFALSE;break;}
530  lnk = lnk->Next();
531  }
532  // Delete objects from directory list, this in turn, recursively closes all
533  // sub-directories (that were allocated on the heap)
534  // if this dir contains subdirs, we must use the slow option for Delete!
535  // we must avoid "slow" as much as possible, in particular Delete("slow")
536  // with a large number of objects (eg >10^5) would take for ever.
537  if (fast) fList->Delete();
538  else fList->Delete("slow");
539 
540  CleanTargets();
541 }
542 
543 ////////////////////////////////////////////////////////////////////////////////
544 /// Delete all objects from memory.
545 
547 {
548  fList->Delete("slow");
549 }
550 
551 ////////////////////////////////////////////////////////////////////////////////
552 /// Delete Objects or/and keys in a directory.
553 ///
554 /// - namecycle has the format name;cycle
555 /// - namecycle = "" same as namecycle ="T*"
556 /// - name = * means all
557 /// - cycle = * means all cycles (memory and keys)
558 /// - cycle = "" or cycle = 9999 ==> apply to a memory object
559 /// When name=* use T* to delete subdirectories also
560 ///
561 /// To delete one directory, you must specify the directory cycle,
562 /// eg. `file.Delete("dir1;1");`
563 ///
564 /// examples:
565 /// - foo : delete object named foo in memory
566 /// - foo* : delete all objects with a name starting with foo
567 /// - foo;1 : delete cycle 1 of foo on file
568 /// - foo;* : delete all cycles of foo on file and also from memory
569 /// - *;2 : delete all objects on file having the cycle 2
570 /// - *;* : delete all objects from memory and file
571 /// - T*;* : delete all objects from memory and file and all subdirectories
572 
573 void TDirectory::Delete(const char *namecycle)
574 {
575  if (gDebug)
576  Info("Delete","Call for this = %s namecycle = %s",
577  GetName(), (namecycle ? namecycle : "null"));
578 
579  TDirectory::TContext ctxt(this);
580  Short_t cycle;
581  char name[kMaxLen];
582  DecodeNameCycle(namecycle, name, cycle, kMaxLen);
583 
584  Int_t deleteall = 0;
585  Int_t deletetree = 0;
586  if(strcmp(name,"*") == 0) deleteall = 1;
587  if(strcmp(name,"*T") == 0){ deleteall = 1; deletetree = 1;}
588  if(strcmp(name,"T*") == 0){ deleteall = 1; deletetree = 1;}
589  if(namecycle==0 || !namecycle[0]){ deleteall = 1; deletetree = 1;}
590  TRegexp re(name,kTRUE);
591  TString s;
592  Int_t deleteOK = 0;
593 
594 //*-*---------------------Case of Object in memory---------------------
595 // ========================
596  if (cycle >= 9999 ) {
597  TNamed *idcur;
598  TIter next(fList);
599  while ((idcur = (TNamed *) next())) {
600  deleteOK = 0;
601  s = idcur->GetName();
602  if (deleteall || s.Index(re) != kNPOS) {
603  deleteOK = 1;
604  if (idcur->IsA() == TDirectory::Class()) {
605  deleteOK = 2;
606  if (!deletetree && deleteall) deleteOK = 0;
607  }
608  }
609  if (deleteOK != 0) {
610  fList->Remove(idcur);
611  if (deleteOK==2) {
612  // read subdirectories to correctly delete them
613  if (deletetree)
614  ((TDirectory*) idcur)->ReadAll("dirs");
615  idcur->Delete(deletetree ? "T*;*" : "*");
616  delete idcur;
617  } else
618  idcur->Delete(name);
619  }
620  }
621  }
622 }
623 
624 ////////////////////////////////////////////////////////////////////////////////
625 /// Fill Graphics Structure and Paint.
626 ///
627 /// Loop on all objects (memory or file) and all subdirectories
628 
630 {
631  fList->R__FOR_EACH(TObject,Draw)(option);
632 }
633 
634 ////////////////////////////////////////////////////////////////////////////////
635 /// Find object in the list of memory objects.
636 
638 {
639  return fList->FindObject(obj);
640 }
641 
642 ////////////////////////////////////////////////////////////////////////////////
643 /// Find object by name in the list of memory objects.
644 
646 {
647  return fList->FindObject(name);
648 }
649 
650 ////////////////////////////////////////////////////////////////////////////////
651 /// Find object by name in the list of memory objects of the current
652 /// directory or its sub-directories.
653 /// After this call the current directory is not changed.
654 /// To automatically set the current directory where the object is found,
655 /// use FindKeyAny(aname)->ReadObj().
656 
657 TObject *TDirectory::FindObjectAny(const char *aname) const
658 {
659  //object may be already in the list of objects in memory
660  TObject *obj = fList->FindObject(aname);
661  if (obj) return obj;
662 
663  //try with subdirectories
664  TIter next(fList);
665  while( (obj = next()) ) {
666  if (obj->IsA()->InheritsFrom(TDirectory::Class())) {
667  TDirectory* subdir = static_cast<TDirectory*>(obj);
668  TObject *subobj = subdir->TDirectory::FindObjectAny(aname); // Explicitly recurse into _this_ exact function.
669  if (subobj) {
670  return subobj;
671  }
672  }
673  }
674  return 0;
675 }
676 
677 ////////////////////////////////////////////////////////////////////////////////
678 /// Return pointer to object identified by namecycle.
679 ///
680 /// namecycle has the format name;cycle
681 /// - name = * is illegal, cycle = * is illegal
682 /// - cycle = "" or cycle = 9999 ==> apply to a memory object
683 ///
684 /// examples:
685 /// - foo : get object named foo in memory
686 /// if object is not in memory, try with highest cycle from file
687 /// - foo;1 : get cycle 1 of foo on file
688 ///
689 /// The retrieved object should in principle derive from TObject.
690 /// If not, the function TDirectory::GetObject should be called.
691 /// However, this function will still work for a non-TObject, providing that
692 /// the calling application cast the return type to the correct type (which
693 /// is the actual type of the object).
694 ///
695 /// NOTE:
696 ///
697 /// The method GetObject offer better protection and avoid the need
698 /// for any cast:
699 /// ~~~ {.cpp}
700 /// MyClass *obj;
701 /// directory->GetObject("some object",obj);
702 /// if (obj) { ... the object exist and inherits from MyClass ... }
703 /// ~~~
704 ///
705 /// VERY IMPORTANT NOTE:
706 ///
707 /// In case the class of this object derives from TObject but not
708 /// as a first inheritance, one must use dynamic_cast<>().
709 /// #### Example 1: Normal case:
710 /// ~~~ {.cpp}
711 /// class MyClass : public TObject, public AnotherClass
712 /// ~~~
713 /// then on return, one can do:
714 /// ~~~ {.cpp}
715 /// MyClass *obj = (MyClass*)directory->Get("some object of MyClass");
716 /// ~~~
717 /// #### Example 2: Special case:
718 /// ~~~ {.cpp}
719 /// class MyClass : public AnotherClass, public TObject
720 /// ~~~
721 /// then on return, one must do:
722 /// ~~~ {.cpp}
723 /// MyClass *obj = dynamic_cast<MyClass*>(directory->Get("some object of MyClass"));
724 /// ~~~
725 /// Of course, dynamic_cast<> can also be used in the example 1.
726 
727 TObject *TDirectory::Get(const char *namecycle)
728 {
729  Short_t cycle;
730  char name[kMaxLen];
731 
732  DecodeNameCycle(namecycle, name, cycle, kMaxLen);
733  char *namobj = name;
734  Int_t nch = strlen(name);
735  for (Int_t i = nch-1; i > 0; i--) {
736  if (name[i] == '/') {
737  name[i] = 0;
738  TDirectory* dirToSearch=GetDirectory(name);
739  namobj = name + i + 1;
740  name[i] = '/';
741  return dirToSearch?dirToSearch->Get(namobj):0;
742  }
743  }
744 
745 //*-*---------------------Case of Object in memory---------------------
746 // ========================
747  TObject *idcur = fList->FindObject(namobj);
748  if (idcur) {
749  if (idcur==this && strlen(namobj)!=0) {
750  // The object has the same name has the directory and
751  // that's what we picked-up! We just need to ignore
752  // it ...
753  idcur = 0;
754  } else if (cycle == 9999) {
755  return idcur;
756  } else {
757  if (idcur->InheritsFrom(TCollection::Class()))
758  idcur->Delete(); // delete also list elements
759  delete idcur;
760  idcur = 0;
761  }
762  }
763  return idcur;
764 }
765 
766 ////////////////////////////////////////////////////////////////////////////////
767 /// Return pointer to object identified by namecycle.
768 /// The returned object may or may not derive from TObject.
769 ///
770 /// - namecycle has the format name;cycle
771 /// - name = * is illegal, cycle = * is illegal
772 /// - cycle = "" or cycle = 9999 ==> apply to a memory object
773 ///
774 /// VERY IMPORTANT NOTE:
775 ///
776 /// The calling application must cast the returned object to
777 /// the final type, e.g.
778 /// ~~~ {.cpp}
779 /// MyClass *obj = (MyClass*)directory->GetObject("some object of MyClass");
780 /// ~~~
781 
782 void *TDirectory::GetObjectUnchecked(const char *namecycle)
783 {
784  return GetObjectChecked(namecycle,(TClass*)0);
785 }
786 
787 ////////////////////////////////////////////////////////////////////////////////
788 /// See documentation of TDirectory::GetObjectCheck(const char *namecycle, const TClass *cl)
789 
790 void *TDirectory::GetObjectChecked(const char *namecycle, const char* classname)
791 {
792  return GetObjectChecked(namecycle,TClass::GetClass(classname));
793 }
794 
795 
796 ////////////////////////////////////////////////////////////////////////////////
797 /// Return pointer to object identified by namecycle if and only if the actual
798 /// object is a type suitable to be stored as a pointer to a "expectedClass"
799 /// If expectedClass is null, no check is performed.
800 ///
801 /// namecycle has the format `name;cycle`
802 /// - name = * is illegal, cycle = * is illegal
803 /// - cycle = "" or cycle = 9999 ==> apply to a memory object
804 ///
805 /// VERY IMPORTANT NOTE:
806 ///
807 /// The calling application must cast the returned pointer to
808 /// the type described by the 2 arguments (i.e. cl):
809 /// ~~~ {.cpp}
810 /// MyClass *obj = (MyClass*)directory->GetObjectChecked("some object of MyClass","MyClass"));
811 /// ~~~
812 /// Note: We recommend using the method TDirectory::GetObject:
813 /// ~~~ {.cpp}~
814 /// MyClass *obj = 0;
815 /// directory->GetObject("some object inheriting from MyClass",obj);
816 /// if (obj) { ... we found what we are looking for ... }
817 /// ~~~
818 
819 void *TDirectory::GetObjectChecked(const char *namecycle, const TClass* expectedClass)
820 {
821  Short_t cycle;
822  char name[kMaxLen];
823 
824  DecodeNameCycle(namecycle, name, cycle, kMaxLen);
825  char *namobj = name;
826  Int_t nch = strlen(name);
827  for (Int_t i = nch-1; i > 0; i--) {
828  if (name[i] == '/') {
829  name[i] = 0;
830  TDirectory* dirToSearch=GetDirectory(name);
831  namobj = name + i + 1;
832  name[i] = '/';
833  if (dirToSearch) {
834  return dirToSearch->GetObjectChecked(namobj, expectedClass);
835  } else {
836  return 0;
837  }
838  }
839  }
840 
841 //*-*---------------------Case of Object in memory---------------------
842 // ========================
843  if (expectedClass==0 || expectedClass->IsTObject()) {
844  TObject *objcur = fList->FindObject(namobj);
845  if (objcur) {
846  if (objcur==this && strlen(namobj)!=0) {
847  // The object has the same name has the directory and
848  // that's what we picked-up! We just need to ignore
849  // it ...
850  objcur = 0;
851  } else if (cycle == 9999) {
852  // Check type
853  if (expectedClass && objcur->IsA()->GetBaseClassOffset(expectedClass) == -1) return 0;
854  else return objcur;
855  } else {
856  if (objcur->InheritsFrom(TCollection::Class()))
857  objcur->Delete(); // delete also list elements
858  delete objcur;
859  objcur = 0;
860  }
861  }
862  }
863 
864  return 0;
865 }
866 
867 ////////////////////////////////////////////////////////////////////////////////
868 /// Returns the full path of the directory. E.g. `file:/dir1/dir2`.
869 /// The returned path will be re-used by the next call to GetPath().
870 
871 const char *TDirectory::GetPathStatic() const
872 {
873  static char *path = 0;
874  const int kMAXDEPTH = 128;
875  const TDirectory *d[kMAXDEPTH];
876  const TDirectory *cur = this;
877  int depth = 0, len = 0;
878 
879  d[depth++] = cur;
880  len = strlen(cur->GetName()) + 1; // +1 for the /
881 
882  while (cur->fMother && depth < kMAXDEPTH) {
883  cur = (TDirectory *)cur->fMother;
884  d[depth++] = cur;
885  len += strlen(cur->GetName()) + 1;
886  }
887 
888  if (path) delete [] path;
889  path = new char[len+2];
890 
891  for (int i = depth-1; i >= 0; i--) {
892  if (i == depth-1) { // file or TROOT name
893  strlcpy(path, d[i]->GetName(),len+2);
894  strlcat(path, ":",len+2);
895  if (i == 0) strlcat(path, "/",len+2);
896  } else {
897  strlcat(path, "/",len+2);
898  strlcat(path, d[i]->GetName(),len+2);
899  }
900  }
901 
902  return path;
903 }
904 
905 ////////////////////////////////////////////////////////////////////////////////
906 /// Returns the full path of the directory. E.g. `file:/dir1/dir2`.
907 /// The returned path will be re-used by the next call to GetPath().
908 
909 const char *TDirectory::GetPath() const
910 {
911  //
912  TString* buf = &(const_cast<TDirectory*>(this)->fPathBuffer);
913 
914  FillFullPath(*buf);
915  if (GetMotherDir()==0) // case of file
916  buf->Append("/");
917 
918  return buf->Data();
919 }
920 
921 ////////////////////////////////////////////////////////////////////////////////
922 /// Recursive method to fill full path for directory.
923 
925 {
926  TDirectory* mom = GetMotherDir();
927  if (mom!=0) {
928  mom->FillFullPath(buf);
929  buf += "/";
930  buf += GetName();
931  } else {
932  buf = GetName();
933  buf +=":";
934  }
935 }
936 
937 ////////////////////////////////////////////////////////////////////////////////
938 /// Create a sub-directory and return a pointer to the created directory.
939 /// Returns 0 in case of error.
940 /// Returns 0 if a directory with the same name already exists.
941 /// Note that the directory name may be of the form "a/b/c" to create a hierarchy of directories.
942 /// In this case, the function returns the pointer to the "a" directory if the operation is successful.
943 ///
944 /// For example the step to the steps to create first a/b/c and then a/b/d without receiving
945 /// and errors are:
946 /// ~~~ {.cpp}
947 /// TFile * file = new TFile("afile","RECREATE");
948 /// file->mkdir("a");
949 /// file->cd("a");
950 /// gDirectory->mkdir("b");
951 /// gDirectory->cd("b");
952 /// gDirectory->mkdir("d");
953 /// ~~~
954 
955 TDirectory *TDirectory::mkdir(const char *name, const char *title)
956 {
957  if (!name || !title || !name[0]) return 0;
958  if (!title[0]) title = name;
959  TDirectory *newdir = 0;
960  if (const char *slash = strchr(name,'/')) {
961  Long_t size = Long_t(slash-name);
962  char *workname = new char[size+1];
963  strncpy(workname, name, size);
964  workname[size] = 0;
965  TDirectory *tmpdir;
966  GetObject(workname,tmpdir);
967  if (!tmpdir) {
968  tmpdir = mkdir(workname,title);
969  if (!tmpdir) return 0;
970  }
971  delete[] workname;
972  if (!tmpdir) return 0;
973  if (!newdir) newdir = tmpdir;
974  tmpdir->mkdir(slash+1);
975  return newdir;
976  }
977 
978  TDirectory::TContext ctxt(this);
979 
980  newdir = new TDirectory(name, title, "", this);
981 
982  return newdir;
983 }
984 
985 ////////////////////////////////////////////////////////////////////////////////
986 /// List Directory contents.
987 ///
988 /// Indentation is used to identify the directory tree
989 /// Subdirectories are listed first, then objects in memory.
990 ///
991 /// The option can has the following format:
992 ///
993 /// [<regexp>]
994 ///
995 /// The `<regexp>` will be used to match the name of the objects.
996 /// By default memory and disk objects are listed.
997 
998 void TDirectory::ls(Option_t *option) const
999 {
1002 
1003  TString opta = option;
1004  TString opt = opta.Strip(TString::kBoth);
1005  Bool_t memobj = kTRUE;
1006  TString reg = "*";
1007  if (opt.BeginsWith("-m")) {
1008  if (opt.Length() > 2)
1009  reg = opt(2,opt.Length());
1010  } else if (opt.BeginsWith("-d")) {
1011  memobj = kFALSE;
1012  if (opt.Length() > 2)
1013  reg = opt(2,opt.Length());
1014  } else if (!opt.IsNull())
1015  reg = opt;
1016 
1017  TRegexp re(reg, kTRUE);
1018 
1019  if (memobj) {
1020  TObject *obj;
1021  TIter nextobj(fList);
1022  while ((obj = (TObject *) nextobj())) {
1023  TString s = obj->GetName();
1024  if (s.Index(re) == kNPOS) continue;
1025  obj->ls(option); //*-* Loop on all the objects in memory
1026  }
1027  }
1029 }
1030 
1031 ////////////////////////////////////////////////////////////////////////////////
1032 /// Paint all objects in the directory.
1033 
1035 {
1036  fList->R__FOR_EACH(TObject,Paint)(option);
1037 }
1038 
1039 ////////////////////////////////////////////////////////////////////////////////
1040 /// Print all objects in the directory.
1041 
1042 void TDirectory::Print(Option_t *option) const
1043 {
1044  fList->R__FOR_EACH(TObject,Print)(option);
1045 }
1046 
1047 ////////////////////////////////////////////////////////////////////////////////
1048 /// Print the path of the directory.
1049 
1050 void TDirectory::pwd() const
1051 {
1052  Printf("%s", GetPath());
1053 }
1054 
1055 ////////////////////////////////////////////////////////////////////////////////
1056 /// Recursively remove object from a Directory.
1057 
1059 {
1060  fList->RecursiveRemove(obj);
1061 }
1062 
1063 ////////////////////////////////////////////////////////////////////////////////
1064 /// Remove an object from the in-memory list.
1065 
1067 {
1068  TObject *p = 0;
1069  if (fList) {
1070  p = fList->Remove(obj);
1071  }
1072  return p;
1073 }
1074 
1075 ////////////////////////////////////////////////////////////////////////////////
1076 /// Removes subdirectory from the directory
1077 /// When directory is deleted, all keys in all subdirectories will be
1078 /// read first and deleted from file (if exists)
1079 /// Equivalent call is Delete("name;*");
1080 
1081 void TDirectory::rmdir(const char *name)
1082 {
1083  if ((name==0) || (*name==0)) return;
1084 
1085  TString mask(name);
1086  mask+=";*";
1087  Delete(mask);
1088 }
1089 
1090 ////////////////////////////////////////////////////////////////////////////////
1091 /// Save object in filename,
1092 /// if filename is 0 or "", a file with "objectname.root" is created.
1093 /// The name of the key is the object name.
1094 /// If the operation is successful, it returns the number of bytes written to the file
1095 /// otherwise it returns 0.
1096 /// By default a message is printed. Use option "q" to not print the message.
1097 
1098 Int_t TDirectory::SaveObjectAs(const TObject *obj, const char *filename, Option_t *option) const
1099 {
1100  if (!obj) return 0;
1101  Int_t nbytes = 0;
1102  TString fname = filename;
1103  if (!filename || !filename[0]) {
1104  fname.Form("%s.root",obj->GetName());
1105  }
1106  TString cmd;
1107  cmd.Form("TFile::Open(\"%s\",\"recreate\");",fname.Data());
1108  {
1109  TContext ctxt; // The TFile::Open will change the current directory.
1110  TDirectory *local = (TDirectory*)gROOT->ProcessLine(cmd);
1111  if (!local) return 0;
1112  nbytes = obj->Write();
1113  delete local;
1114  }
1115  TString opt(option);
1116  opt.ToLower();
1117  if (!opt.Contains("q")) {
1118  if (!gSystem->AccessPathName(fname.Data())) obj->Info("SaveAs", "ROOT file %s has been created", fname.Data());
1119  }
1120  return nbytes;
1121 }
1122 
1123 ////////////////////////////////////////////////////////////////////////////////
1124 /// Set the name for directory
1125 /// If the directory name is changed after the directory was written once,
1126 /// ROOT currently would NOT change the name of correspondent key in the
1127 /// mother directory.
1128 /// DO NOT use this method to 'rename a directory'.
1129 /// Renaming a directory is currently NOT supported.
1130 
1131 void TDirectory::SetName(const char* newname)
1132 {
1133  TNamed::SetName(newname);
1134 }
1135 
1136 ////////////////////////////////////////////////////////////////////////////////
1137 /// Encode the name and cycle into buffer like: "aap;2".
1138 
1139 void TDirectory::EncodeNameCycle(char *buffer, const char *name, Short_t cycle)
1140 {
1141  if (cycle == 9999)
1142  strcpy(buffer, name);
1143  else
1144  sprintf(buffer, "%s;%d", name, cycle);
1145 }
1146 
1147 ////////////////////////////////////////////////////////////////////////////////
1148 /// Decode a namecycle "aap;2" into name "aap" and cycle "2". Destination
1149 /// buffer size for name (including string terminator) should be specified in
1150 /// namesize.
1151 
1152 void TDirectory::DecodeNameCycle(const char *buffer, char *name, Short_t &cycle,
1153  const size_t namesize)
1154 {
1155  size_t len = 0;
1156  const char *ni = strchr(buffer, ';');
1157 
1158  if (ni) {
1159  // Found ';'
1160  len = ni - buffer;
1161  ++ni;
1162  } else {
1163  // No ';' found
1164  len = strlen(buffer);
1165  ni = &buffer[len];
1166  }
1167 
1168  if (namesize) {
1169  if (len > namesize-1ul) len = namesize-1; // accommodate string terminator
1170  } else {
1171  ::Warning("TDirectory::DecodeNameCycle",
1172  "Using unsafe version: invoke this metod by specifying the buffer size");
1173  }
1174 
1175  strncpy(name, buffer, len);
1176  name[len] = '\0';
1177 
1178  if (*ni == '*')
1179  cycle = 10000;
1180  else if (isdigit(*ni)) {
1181  long parsed = strtol(ni,nullptr,10);
1182  if (parsed >= (long) std::numeric_limits<Short_t>::max())
1183  cycle = 0;
1184  else
1185  cycle = (Short_t)parsed;
1186  } else
1187  cycle = 9999;
1188 }
1189 
1190 ////////////////////////////////////////////////////////////////////////////////
1191 /// Register a TContext pointing to this TDirectory object
1192 
1195  if (fContext) {
1196  TContext *current = fContext;
1197  while(current->fNext) {
1198  current = current->fNext;
1199  }
1200  current->fNext = ctxt;
1201  ctxt->fPrevious = current;
1202  } else {
1203  fContext = ctxt;
1204  }
1205 }
1206 
1207 ////////////////////////////////////////////////////////////////////////////////
1208 /// See TDirectoryFile::WriteTObject for details
1209 
1210 Int_t TDirectory::WriteTObject(const TObject *obj, const char *name, Option_t * /*option*/, Int_t /*bufsize*/)
1211 {
1212  const char *objname = "no name specified";
1213  if (name) objname = name;
1214  else if (obj) objname = obj->GetName();
1215  Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.",GetName(),objname);
1216  return 0;
1217 }
1218 
1219 ////////////////////////////////////////////////////////////////////////////////
1220 /// UnRegister a TContext pointing to this TDirectory object
1221 
1224  if (ctxt==fContext) {
1225  fContext = ctxt->fNext;
1226  if (fContext) fContext->fPrevious = 0;
1227  ctxt->fPrevious = ctxt->fNext = 0;
1228  } else {
1229  TContext *next = ctxt->fNext;
1230  ctxt->fPrevious->fNext = next;
1231  if (next) next->fPrevious = ctxt->fPrevious;
1232  ctxt->fPrevious = ctxt->fNext = 0;
1233  }
1234 }
1235 
1236 ////////////////////////////////////////////////////////////////////////////////
1237 /// Set the current directory to null.
1238 /// This is called from the TContext destructor. Since the destructor is
1239 /// inline, we do not want to have it directly use a global variable.
1240 
1242 {
1243  gDirectory = 0;
1244 }
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
Definition: TBrowser.cxx:259
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:823
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1265
void SetBufferOffset(Int_t offset=0)
Definition: TBuffer.h:88
virtual void Draw(Option_t *option="")
Fill Graphics Structure and Paint.
Definition: TDirectory.cxx:629
virtual ~TDirectory()
Destructor.
Definition: TDirectory.cxx:91
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition: TROOT.cxx:2390
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:404
virtual void Build(TFile *motherFile=0, TDirectory *motherDir=0)
Initialise directory to defaults.
Definition: TDirectory.cxx:198
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
Definition: TDirectory.cxx:727
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Ssiz_t Length() const
Definition: TString.h:390
virtual TObject * FindObjectAny(const char *name) const
Find object by name in the list of memory objects of the current directory or its sub-directories...
Definition: TDirectory.cxx:657
const char Option_t
Definition: RtypesCore.h:62
void GetObject(const char *namecycle, T *&ptr)
Definition: TDirectory.h:144
TList * fList
Definition: TDirectory.h:96
virtual TObject * CloneObject(const TObject *obj, Bool_t autoadd=kTRUE)
Clone an object.
Definition: TDirectory.cxx:264
#define gDirectory
Definition: TDirectory.h:218
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
virtual TList * GetList() const
Definition: TDirectory.h:154
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition: TClass.cxx:5552
void * InterfaceMethod() const
Return pointer to the interface method.
Definition: TFunction.cxx:208
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
Regular expression class.
Definition: TRegexp.h:35
static const char * filename()
#define gROOT
Definition: TROOT.h:340
virtual Int_t WriteTObject(const TObject *obj, const char *name=0, Option_t *="", Int_t=0)
See TDirectoryFile::WriteTObject for details.
Basic string class.
Definition: TString.h:137
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1088
int Int_t
Definition: RtypesCore.h:41
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory and return a pointer to the created directory.
Definition: TDirectory.cxx:955
bool Bool_t
Definition: RtypesCore.h:59
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:63
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:496
TContext * fPrevious
Pointer to the previous current directory.
Definition: TDirectory.h:51
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
virtual const char * GetPath() const
Returns the full path of the directory.
Definition: TDirectory.cxx:909
R__EXTERN void **(* gThreadTsd)(void *, Int_t)
Definition: TThreadSlots.h:42
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
virtual void Print(Option_t *option="") const
Print all objects in the directory.
virtual void * GetObjectChecked(const char *namecycle, const char *classname)
See documentation of TDirectory::GetObjectCheck(const char *namecycle, const TClass *cl) ...
Definition: TDirectory.cxx:790
virtual void ls(Option_t *option="") const
List Directory contents.
Definition: TDirectory.cxx:998
const char * Data() const
Definition: TString.h:349
TString fPathBuffer
Definition: TDirectory.h:98
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:946
virtual void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
Definition: TObject.cxx:536
#define SafeDelete(p)
Definition: RConfig.h:436
void Class()
Definition: Class.C:29
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
virtual void Save()
Definition: TDirectory.h:184
virtual void Paint(Option_t *option="")
Paint all objects in the directory.
Bool_t cd1(const char *path)
flag to add histograms, graphs,etc to the directory
Definition: TDirectory.cxx:451
TString & Append(const char *cs)
Definition: TString.h:492
virtual void Close(Option_t *option="")
Delete all objects from memory and directory structure itself.
Definition: TDirectory.cxx:517
virtual void rmdir(const char *name)
Removes subdirectory from the directory When directory is deleted, all keys in all subdirectories wil...
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
const Int_t kMaxLen
Definition: TDirectory.cxx:31
virtual void Delete(const char *namecycle="")
Delete Objects or/and keys in a directory.
Definition: TDirectory.cxx:573
virtual TFile * GetFile() const
Definition: TDirectory.h:152
virtual const char * GetPathStatic() const
Returns the full path of the directory.
Definition: TDirectory.cxx:871
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add objects like histograms, TGraph2D, etc in memory...
Definition: TDirectory.cxx:132
virtual void Delete(Option_t *option="")
Delete this object.
Definition: TObject.cxx:228
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
TContext * fNext
Pointer to the next TContext in the implied list of context pointing to fPrevious.
Definition: TDirectory.h:52
virtual void Browse(TBrowser *b)
Browse the content of the directory.
Definition: TDirectory.cxx:176
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
TContext * fContext
Buffer for GetPath() function.
Definition: TDirectory.h:99
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:674
TDirectory * fDirectory
Definition: TDirectory.h:50
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2321
TMarker * m
Definition: textangle.C:8
virtual void * GetObjectUnchecked(const char *namecycle)
Return pointer to object identified by namecycle.
Definition: TDirectory.cxx:782
static Bool_t Cd1(const char *path)
Change current directory to "path".
Definition: TDirectory.cxx:490
virtual Int_t SaveObjectAs(const TObject *, const char *="", Option_t *="") const
Save object in filename, if filename is 0 or "", a file with "objectname.root" is created...
virtual void Append(TObject *obj, Bool_t replace=kFALSE)
Append object to this directory.
Definition: TDirectory.cxx:151
void FillFullPath(TString &buf) const
Recursive method to fill full path for directory.
Definition: TDirectory.cxx:924
void SetReadMode()
Set buffer in read mode.
Definition: TBuffer.cxx:269
short Short_t
Definition: RtypesCore.h:35
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
TSubString Strip(EStripType s=kTrailing, char c= ' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1069
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
void(* DirAutoAdd_t)(void *, TDirectory *)
Definition: Rtypes.h:152
Bool_t IsNull() const
Definition: TString.h:387
virtual TObjLink * FirstLink() const
Definition: TList.h:101
#define Printf
Definition: TGeoToOCC.h:18
ClassImp(TDirectory) TDirectory
Directory default constructor.
Definition: TDirectory.cxx:37
virtual void Clear(Option_t *option="")
Delete all objects from a Directory list.
Definition: TDirectory.cxx:508
TObject * fMother
Definition: TDirectory.h:95
virtual TObject * FindObject(const char *name) const
Find object by name in the list of memory objects.
Definition: TDirectory.cxx:645
long Long_t
Definition: RtypesCore.h:50
virtual void MapObject(const TObject *obj, UInt_t offset=1)=0
virtual void SetName(const char *newname)
Set the name for directory If the directory name is changed after the directory was written once...
virtual TObject * Remove(TObject *)
Remove an object from the in-memory list.
static Bool_t Cd(const char *path)
Change current directory to "path".
Definition: TDirectory.cxx:477
double f(double x)
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
static void EncodeNameCycle(char *buffer, const char *name, Short_t cycle)
Encode the name and cycle into buffer like: "aap;2".
Describe directory structure in memory.
Definition: TDirectory.h:41
static TDirectory *& CurrentDirectory()
Return the current directory for the current thread.
Definition: TDirectory.cxx:316
virtual void Copy(TObject &) const
Copy this to obj.
Definition: TDirectory.h:131
static Bool_t AddDirectoryStatus()
Static function: see TDirectory::AddDirectory for more comments.
Definition: TDirectory.cxx:140
double func(double *x, double *p)
Definition: stressTF1.cxx:213
static void DecodeNameCycle(const char *namecycle, char *name, Short_t &cycle, const size_t namesize=0)
Decode a namecycle "aap;2" into name "aap" and cycle "2".
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2881
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Definition: TList.cxx:348
TCanvas * slash()
Definition: slash.C:1
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
virtual TDirectory * GetMotherDir() const
Definition: TDirectory.h:157
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
void(* tcling_callfunc_Wrapper_t)(void *, int, void **, void *)
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition: TROOT.cxx:2453
typedef void((*Func_t)())
static TBuffer * R__CreateBuffer()
Fast execution of 'new TBufferFile(TBuffer::kWrite,10000), without having a compile time circular dep...
Definition: TDirectory.cxx:236
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
Definition: TDirectory.cxx:433
virtual void Add(TObject *obj)
Definition: TList.h:81
const Ssiz_t kNPOS
Definition: Rtypes.h:115
virtual void RecursiveRemove(TObject *obj)
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition: TList.cxx:634
virtual void DeleteAll(Option_t *option="")
Delete all objects from memory.
Definition: TDirectory.cxx:546
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:40
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
Definition: TDirectory.cxx:336
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2461
virtual void ResetMap()=0
double result[121]
void ResetBit(UInt_t f)
Definition: TObject.h:172
void RegisterContext(TContext *ctxt)
Register a TContext pointing to this TDirectory object.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
const Bool_t kTRUE
Definition: Rtypes.h:91
TMethod * GetMethodWithPrototype(const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Find the method with a given prototype.
Definition: TClass.cxx:4194
TObject * obj
virtual void RecursiveRemove(TObject *obj)
Recursively remove object from a Directory.
virtual void pwd() const
Print the path of the directory.
virtual void CleanTargets()
Clean the pointers to this object (gDirectory, TContext, etc.).
Definition: TDirectory.cxx:210
void UnregisterContext(TContext *ctxt)
UnRegister a TContext pointing to this TDirectory object.
static Bool_t fgAddDirectory
Pointer to a list of TContext object pointing to this TDirectory.
Definition: TDirectory.h:100
void CdNull()
Set the current directory to null.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904