Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <cstdlib>
12
13#include "Strlen.h"
14#include "strlcpy.h"
15#include "TDirectory.h"
16#include "TBuffer.h"
17#include "TClassTable.h"
18#include "TInterpreter.h"
19#include "THashList.h"
20#include "TBrowser.h"
21#include "TROOT.h"
22#include "TError.h"
23#include "TClass.h"
24#include "TRegexp.h"
25#include "TSystem.h"
26#include "TVirtualMutex.h"
27#include "TThreadSlots.h"
28#include "TMethod.h"
29
30#include "TSpinLockGuard.h"
31
32#include <algorithm>
33#include <limits>
34
36
37const Int_t kMaxLen = 2048;
38
39static std::atomic_flag *GetCurrentDirectoryLock()
40{
41 thread_local std::atomic_flag gDirectory_lock = ATOMIC_FLAG_INIT;
42 return &gDirectory_lock;
43}
44
45/** \class TDirectory
46\ingroup Base
47
48Describe directory structure in memory.
49*/
50
52
53////////////////////////////////////////////////////////////////////////////////
54/// Directory default constructor.
55
57{
58 // MSVC doesn't support fSpinLock=ATOMIC_FLAG_INIT; in the class definition
59 std::atomic_flag_clear( &fSpinLock );
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// Create a new Directory.
64///
65/// A new directory with name,title is created in the current directory
66/// The directory header information is immediately saved in the file
67/// A new key is added in the parent directory
68///
69/// When this constructor is called from a class directly derived
70/// from TDirectory, the third argument classname MUST be specified.
71/// In this case, classname must be the name of the derived class.
72///
73/// Note that the directory name cannot contain slashes.
74
75TDirectory::TDirectory(const char *name, const char *title, Option_t * /*classname*/, TDirectory* initMotherDir)
76 : TNamed(name, title)
77{
78 // MSVC doesn't support fSpinLock=ATOMIC_FLAG_INIT; in the class definition
79 std::atomic_flag_clear( &fSpinLock );
80
82
83 if (strchr(name,'/')) {
84 ::Error("TDirectory::TDirectory","directory name (%s) cannot contain a slash", name);
85 gDirectory = nullptr;
86 return;
87 }
88 if (strlen(GetName()) == 0) {
89 ::Error("TDirectory::TDirectory","directory name cannot be \"\"");
90 gDirectory = nullptr;
91 return;
92 }
93
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Destructor.
99
101{
102 // Use gROOTLocal to avoid triggering undesired initialization of gROOT.
103 // For example in compiled C++ programs that don't use it directly.
105 delete fList;
106 return; //when called by TROOT destructor
107 }
108
109 if (fList) {
110 if (!fList->IsUsingRWLock())
111 Fatal("~TDirectory","In %s:%p the fList (%p) is not using the RWLock\n",
112 GetName(),this,fList);
113 fList->Delete("slow");
115 }
116
118
120
121 if (mom) {
122 mom->Remove(this);
123 }
124
125 if (gDebug) {
126 Info("~TDirectory", "dtor called for %s", GetName());
127 }
128}
129
130
131////////////////////////////////////////////////////////////////////////////////
132/// Set the current directory to null.
133/// This is called from the TContext destructor. Since the destructor is
134/// inline, we do not want to have it directly use a global variable.
135
137{
138 gDirectory = nullptr;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Destructor.
143///
144/// Reset the current directory to its previous state.
145
147{
148 fActiveDestructor = true;
149 if (fDirectory) {
150 // UnregisterContext must not be virtual to allow
151 // this to work even with fDirectory set to nullptr.
152 (*fDirectory).UnregisterContext(this);
153 // While we were waiting for the lock, the TDirectory
154 // may have been deleted by another thread, so
155 // we need to recheck the value of fDirectory.
156 if (fDirectory)
157 (*fDirectory).cd();
158 else
159 CdNull();
160 } else {
161 CdNull();
162 }
163 fActiveDestructor = false;
164 while(fDirectoryWait);
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Sets the flag controlling the automatic add objects like histograms, TGraph2D, etc
169/// in memory
170///
171/// By default (fAddDirectory = kTRUE), these objects are automatically added
172/// to the list of objects in memory.
173/// Note that in the classes like TH1, TGraph2D supporting this facility,
174/// one object can be removed from its support directory
175/// by calling object->SetDirectory(nullptr) or object->SetDirectory(dir) to add it
176/// to the list of objects in the directory dir.
177///
178/// NOTE that this is a static function. To call it, use:
179/// ~~~ {.cpp}
180/// TDirectory::AddDirectory
181/// ~~~
182
184{
185 fgAddDirectory = add;
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Static function: see TDirectory::AddDirectory for more comments.
190
195
196////////////////////////////////////////////////////////////////////////////////
197/// Append object to this directory.
198///
199/// If `replace` is true:
200/// remove any existing objects with the same name (if the name is not "")
201
202void TDirectory::Append(TObject *obj, Bool_t replace /* = kFALSE */)
203{
204 if (!obj || !fList) return;
205
206 if (replace && obj->GetName() && obj->GetName()[0]) {
207 TObject *old;
208 while (nullptr != (old = GetList()->FindObject(obj->GetName()))) {
209 Warning("Append","Replacing existing %s: %s (Potential memory leak).",
210 obj->IsA()->GetName(),obj->GetName());
211 ROOT::DirAutoAdd_t func = old->IsA()->GetDirectoryAutoAdd();
212 if (func) {
213 func(old,nullptr);
214 } else {
215 Remove(old);
216 }
217 }
218 }
219
220 fList->Add(obj);
221 // A priori, a `TDirectory` object is assumed to not have shared ownership.
222 // If it is, let's rely on the user to update the bit.
223 if (!dynamic_cast<TDirectory*>(obj))
224 obj->SetBit(kMustCleanup);
225}
226
227////////////////////////////////////////////////////////////////////////////////
228/// Browse the content of the directory.
229
231{
232 if (b) {
233 TObject *obj = nullptr;
235
236 cd();
237
238 //Add objects that are only in memory
239 while ((obj = nextin())) {
240 b->Add(obj, obj->GetName());
241 }
242 }
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Initialise directory to defaults.
247///
248/// If directory is created via default ctor (when dir is read from file)
249/// don't add it here to the directory since its name is not yet known.
250/// It will be added to the directory in TKey::ReadObj().
251
253{
254 fList = new THashList(100,50);
255 fList->UseRWLock();
258
259 // Build is done and is the last part of the constructor (and is not
260 // being called from the derived classes) so we can publish.
261 if (motherDir && strlen(GetName()) != 0) motherDir->Append(this);
262}
263
264////////////////////////////////////////////////////////////////////////////////
265/// Clean the pointers to this object (gDirectory, TContext, etc.).
266
268{
269 std::vector<TContext*> extraWait;
270
271 {
273
274 while (fContext) {
275 const auto next = fContext->fNext;
276 const auto ctxt = fContext;
277 ctxt->fDirectoryWait = true;
278
279 // If fDirectory is assigned to gROOT but we do not unregister ctxt
280 // (and/or stop unregister for gROOT) then ~TContext will call Unregister on gROOT.
281 // Then unregister of this ctxt and its Previous context can actually be run
282 // in parallel (this takes the gROOT lock, Previous takes the lock of fDirectory)
283 // and thus step on each other.
284 ctxt->fDirectory = nullptr; // Can not be gROOT
285
286 if (ctxt->fActiveDestructor) {
287 extraWait.push_back(fContext);
288 } else {
289 ctxt->fDirectoryWait = false;
290 }
291 fContext = next;
292 }
293
294 // Now loop through the set of thread local 'gDirectory' that
295 // have a one point or another pointed to this directory.
296 for (auto &ptr : fGDirectories) {
297 // If the thread local gDirectory still point to this directory
298 // we need to reset it using the following sematic:
299 // we fall back to the mother/owner of this directory or gROOTLocal
300 // if there is no parent or nullptr if the current object is gROOTLocal.
301 if (ptr->load() == this) {
302 TDirectory *next = GetMotherDir();
303 if (!next || next == this) {
304 if (this == ROOT::Internal::gROOTLocal) { /// in that case next == this.
305 next = nullptr;
306 } else {
308 }
309 } else {
310 // We can not use 'cd' as this would access the current thread
311 // rather than the thread corresponding to that gDirectory.
312 next->RegisterGDirectory(ptr);
313 }
314 // Actually do the update of the thread local gDirectory
315 // using its object specific lock.
316 auto This = this;
317 ptr->compare_exchange_strong(This, next);
318 }
319 }
320 }
321 for(auto &&context : extraWait) {
322 // Wait until the TContext is done spinning
323 // over the lock.
324 while(context->fActiveDestructor);
325 // And now let the TContext destructor finish.
326 context->fDirectoryWait = false;
327 }
328
329 // Wait until all register attempts are done.
330 while(fContextPeg) {}
331
332}
333
334////////////////////////////////////////////////////////////////////////////////
335/// Fast execution of 'new TBufferFile(TBuffer::kWrite,10000), without having
336/// a compile time circular dependency ... alternatively we could (should?)
337/// introduce yet another abstract interface.
338
340{
341 typedef void (*tcling_callfunc_Wrapper_t)(void*, int, void**, void*);
342 static tcling_callfunc_Wrapper_t creator = nullptr;
343 if (!creator) {
345 TClass *c = TClass::GetClass("TBufferFile");
346 TMethod *m = c->GetMethodWithPrototype("TBufferFile","TBuffer::EMode,Int_t",kFALSE,ROOT::kExactMatch);
347 creator = (tcling_callfunc_Wrapper_t)( m->InterfaceMethod() );
348 }
350 Int_t size = 10000;
351 void *args[] = { &mode, &size };
353 creator(nullptr,2,args,&result);
354 return result;
355}
356
357////////////////////////////////////////////////////////////////////////////////
358/// Clone an object.
359/// This function is called when the directory is not a TDirectoryFile.
360/// This version has to load the I/O package, hence via Cling.
361///
362/// If autoadd is true and if the object class has a
363/// DirectoryAutoAdd function, it will be called at the end of the
364/// function with the parameter gDirector. This usually means that
365/// the object will be appended to the current ROOT directory.
366
368{
369 // if no default ctor return immediately (error issued by New())
370 char *pobj = (char*)obj->IsA()->New();
371 if (!pobj) {
372 Fatal("CloneObject","Failed to create new object");
373 return nullptr;
374 }
375
376 Int_t baseOffset = obj->IsA()->GetBaseClassOffset(TObject::Class());
377 if (baseOffset==-1) {
378 // cl does not inherit from TObject.
379 // Since this is not supported in this function, the only reason we could reach this code
380 // is because something is screwed up in the ROOT code.
381 Fatal("CloneObject","Incorrect detection of the inheritance from TObject for class %s.\n",
382 obj->IsA()->GetName());
383 }
385
386 //create a buffer where the object will be streamed
387 //We are forced to go via the I/O package (ie TBufferFile).
388 //Invoking TBufferFile via CINT will automatically load the I/O library
389 TBuffer *buffer = R__CreateBuffer();
390 if (!buffer) {
391 Fatal("CloneObject","Not able to create a TBuffer!");
392 return nullptr;
393 }
394 buffer->MapObject(obj); //register obj in map to handle self reference
395 const_cast<TObject*>(obj)->Streamer(*buffer);
396
397 // read new object from buffer
398 buffer->SetReadMode();
399 buffer->ResetMap();
400 buffer->SetBufferOffset(0);
401 buffer->MapObject(newobj); //register obj in map to handle self reference
402 newobj->Streamer(*buffer);
403 newobj->ResetBit(kIsReferenced);
404 newobj->ResetBit(kCanDelete);
405
406 delete buffer;
407 if (autoadd) {
408 ROOT::DirAutoAdd_t func = obj->IsA()->GetDirectoryAutoAdd();
409 if (func) {
410 func(newobj,this);
411 }
412 }
413 return newobj;
414}
415
416////////////////////////////////////////////////////////////////////////////////
417/// Return the (address of) a shared pointer to the struct holding the
418/// actual thread local gDirectory pointer and the atomic_flag for its lock.
420{
422
423 // Note in previous implementation every time gDirectory was lookup in
424 // a thread, if it was set to nullptr it would be reset to gROOT. This
425 // was unexpected and this routine is not re-introducing this issue.
426 thread_local shared_ptr_type currentDirectory =
427 std::make_shared<shared_ptr_type::element_type>(ROOT::Internal::gROOTLocal);
428
429 return currentDirectory;
430}
431
432////////////////////////////////////////////////////////////////////////////////
433/// Return the current directory for the current thread.
434
435std::atomic<TDirectory*> &TDirectory::CurrentDirectory()
436{
437 return *GetSharedLocalCurrentDirectory().get();
438}
439
440////////////////////////////////////////////////////////////////////////////////
441/// Find a directory using apath.
442/// It apath is null or empty, returns "this" directory.
443/// Otherwise use apath to find a directory.
444/// The absolute path syntax is: `file.root:/dir1/dir2`
445///
446/// where file.root is the file and /dir1/dir2 the desired subdirectory
447/// in the file. Relative syntax is relative to "this" directory. E.g: `../aa`.
448/// Returns 0 in case path does not exist.
449/// If printError is true, use Error with 'funcname' to issue an error message.
450
452 Bool_t printError, const char *funcname)
453{
454 Int_t nch = 0;
455 if (apath) nch = strlen(apath);
456 if (!nch) {
457 return this;
458 }
459
460 if (funcname==nullptr || strlen(funcname)==0) funcname = "GetDirectory";
461
462 TDirectory *result = this;
463
464 char *path = new char[nch+1]; path[0] = 0;
465 if (nch) strlcpy(path,apath,nch+1);
466 char *s = (char*)strrchr(path, ':');
467 if (s) {
468 *s = '\0';
470 TDirectory *f = (TDirectory *)gROOT->GetListOfFiles()->FindObject(path);
471 if (!f && !strcmp(gROOT->GetName(), path)) f = gROOT;
472 if (s) *s = ':';
473 if (f) {
474 result = f;
475 if (s && *(s+1)) result = f->GetDirectory(s+1,printError,funcname);
476 delete [] path; return result;
477 } else {
478 if (printError) Error(funcname, "No such file %s", path);
479 delete [] path; return nullptr;
480 }
481 }
482
483 // path starts with a slash (assumes current file)
484 if (path[0] == '/') {
486 result = td->GetDirectory(path+1,printError,funcname);
487 delete [] path; return result;
488 }
489
490 TObject *obj;
491 char *slash = (char*)strchr(path,'/');
492 if (!slash) { // we are at the lowest level
493 if (!strcmp(path, "..")) {
495 delete [] path; return result;
496 }
497 obj = Get(path);
498 if (!obj) {
499 if (printError) Error(funcname,"Unknown directory %s", path);
500 delete [] path; return nullptr;
501 }
502
503 //Check return object is a directory
504 if (!obj->InheritsFrom(TDirectory::Class())) {
505 if (printError) Error(funcname,"Object %s is not a directory", path);
506 delete [] path; return nullptr;
507 }
508 delete [] path; return (TDirectory*)obj;
509 }
510
511 TString subdir(path);
512 slash = (char*)strchr(subdir.Data(),'/');
513 *slash = 0;
514 //Get object with path from current directory/file
515 if (!strcmp(subdir, "..")) {
517 if (mom)
518 result = mom->GetDirectory(slash+1,printError,funcname);
519 delete [] path; return result;
520 }
521 obj = Get(subdir);
522 if (!obj) {
523 if (printError) Error(funcname,"Unknown directory %s", subdir.Data());
524 delete [] path; return nullptr;
525 }
526
527 //Check return object is a directory
528 if (!obj->InheritsFrom(TDirectory::Class())) {
529 if (printError) Error(funcname,"Object %s is not a directory", subdir.Data());
530 delete [] path; return nullptr;
531 }
532 result = ((TDirectory*)obj)->GetDirectory(slash+1,printError,funcname);
533 delete [] path; return result;
534}
535
536////////////////////////////////////////////////////////////////////////////////
537/// Change current directory to "this" directory.
538///
539/// Returns kTRUE (it's guaranteed to succeed).
540
551
552////////////////////////////////////////////////////////////////////////////////
553/// Change current directory to "this" directory or to the directory described
554/// by the path if given one.
555///
556/// Using path one can change the current directory to "path". The absolute path
557/// syntax is: `file.root:/dir1/dir2`
558/// where `file.root` is the file and `/dir1/dir2` the desired subdirectory
559/// in the file.
560///
561/// Relative syntax is relative to "this" directory. E.g: `../aa`.
562///
563/// Returns kTRUE in case of success.
564
565Bool_t TDirectory::cd(const char *path)
566{
567 return cd1(path);
568}
569
570////////////////////////////////////////////////////////////////////////////////
571/// Change current directory to "this" directory or to the directory described
572/// by the path if given one.
573///
574/// Using path one can
575/// change the current directory to "path". The absolute path syntax is:
576/// `file.root:/dir1/dir2`
577/// where `file.root` is the file and `/dir1/dir2` the desired subdirectory
578/// in the file.
579///
580/// Relative syntax is relative to "this" directory. E.g: `../aa`.
581///
582/// Returns kFALSE in case path does not exist.
583
585{
586 if (!apath || !apath[0])
587 return this->cd();
588
590 if (where) {
591 where->cd();
592 return kTRUE;
593 }
594 return kFALSE;
595}
596
597////////////////////////////////////////////////////////////////////////////////
598/// Change current directory to "path". The absolute path syntax is:
599/// `file.root:/dir1/dir2`
600/// where file.root is the file and `/dir1/dir2 the desired subdirectory
601/// in the file.
602/// Relative syntax is relative to the current directory `gDirectory`, e.g.: `../aa`.
603///
604/// Returns kTRUE in case of success.
605
606Bool_t TDirectory::Cd(const char *path)
607{
608 return Cd1(path);
609}
610
611////////////////////////////////////////////////////////////////////////////////
612/// Change current directory to "path". The path syntax is:
613/// `file.root:/dir1/dir2`
614/// where file.root is the file and `/dir1/dir2` the desired subdirectory
615/// in the file.
616/// Relative syntax is relative to the current directory `gDirectory`, e.g.: `../aa`.
617///
618/// Returns kFALSE in case path does not exist.
619
621{
622 // null path is always true (i.e. stay in the current directory)
623 if (!apath || !apath[0])
624 return kTRUE;
625
626 TDirectory *where = gDirectory->GetDirectory(apath, kTRUE, "Cd");
627 if (where) {
628 where->cd();
629 return kTRUE;
630 }
631 return kFALSE;
632}
633
634////////////////////////////////////////////////////////////////////////////////
635/// Delete all objects from a Directory list.
636
638{
639 if (fList) fList->Clear();
640}
641
642////////////////////////////////////////////////////////////////////////////////
643/// Delete all objects from memory and directory structure itself.
644/// if option is "slow", iterate through the containers in a way to can handle
645/// 'external' modification (induced by recursions)
646/// if option is "nodelete", write the TDirectory but do not delete the contained
647/// objects.
649{
650 if (!fList) {
651 return;
652 }
653
654 // Save the directory key list and header
655 Save();
656
657 Bool_t nodelete = option ? (!strcmp(option, "nodelete") ? kTRUE : kFALSE) : kFALSE;
658
659 if (!nodelete) {
660 Bool_t slow = option ? (!strcmp(option, "slow") ? kTRUE : kFALSE) : kFALSE;
661 if (!slow) {
662 // Check if it is wise to use the fast deletion path.
664 while (lnk) {
665 if (lnk->GetObject()->IsA() == TDirectory::Class()) {
666 slow = kTRUE;
667 break;
668 }
669 lnk = lnk->Next();
670 }
671 }
672
673 // Delete objects from directory list, this in turn, recursively closes all
674 // sub-directories (that were allocated on the heap)
675 // if this dir contains subdirs, we must use the slow option for Delete!
676 // we must avoid "slow" as much as possible, in particular Delete("slow")
677 // with a large number of objects (eg >10^5) would take for ever.
678 if (slow) fList->Delete("slow");
679 else fList->Delete();
680 }
681
683}
684
685////////////////////////////////////////////////////////////////////////////////
686/// Delete all objects from memory.
687
689{
690 fList->Delete("slow");
691}
692
693////////////////////////////////////////////////////////////////////////////////
694/// Delete Objects or/and keys in a directory.
695///
696/// - namecycle has the format name;cycle
697/// - namecycle = "" same as namecycle ="T*"
698/// - name = * means all
699/// - cycle = * means all cycles (memory and keys)
700/// - cycle = "" or cycle = 9999 ==> apply to a memory object
701/// When name=* use T* to delete subdirectories also
702///
703/// To delete one directory, you must specify the directory cycle,
704/// eg. `file.Delete("dir1;1");`
705///
706/// examples:
707/// - foo : delete object named foo in memory
708/// - foo* : delete all objects with a name starting with foo
709/// - foo;1 : delete cycle 1 of foo on file
710/// - foo;* : delete all cycles of foo on file and also from memory
711/// - *;2 : delete all objects on file having the cycle 2
712/// - *;* : delete all objects from memory and file
713/// - T*;* : delete all objects from memory and file and all subdirectories
714
716{
717 if (gDebug)
718 Info("Delete","Call for this = %s namecycle = %s",
719 GetName(), (namecycle ? namecycle : "null"));
720
722 Short_t cycle;
723 char name[kMaxLen];
725
726 Int_t deleteall = 0;
727 Int_t deletetree = 0;
728 if(strcmp(name,"*") == 0) deleteall = 1;
729 if(strcmp(name,"*T") == 0){ deleteall = 1; deletetree = 1;}
730 if(strcmp(name,"T*") == 0){ deleteall = 1; deletetree = 1;}
731 if(namecycle==nullptr || !namecycle[0]){ deleteall = 1; deletetree = 1;}
732 TRegexp re(name,kTRUE);
733 TString s;
734 Int_t deleteOK = 0;
735
736//*-*---------------------Case of Object in memory---------------------
737// ========================
738 if (cycle >= 9999 ) {
739 TNamed *idcur;
740 TIter next(fList);
741 while ((idcur = (TNamed *) next())) {
742 deleteOK = 0;
743 s = idcur->GetName();
744 if (deleteall || s.Index(re) != kNPOS) {
745 deleteOK = 1;
746 if (idcur->IsA() == TDirectory::Class()) {
747 deleteOK = 2;
748 if (!deletetree && deleteall) deleteOK = 0;
749 }
750 }
751 if (deleteOK != 0) {
753 if (deleteOK==2) {
754 // read subdirectories to correctly delete them
755 if (deletetree)
756 ((TDirectory*) idcur)->ReadAll("dirs");
757 idcur->Delete(deletetree ? "T*;*" : "*");
758 delete idcur;
759 } else
760 idcur->Delete(name);
761 }
762 }
763 }
764}
765
766////////////////////////////////////////////////////////////////////////////////
767/// Fill Graphics Structure and Paint.
768///
769/// Loop on all objects (memory or file) and all subdirectories
770
772{
773 fList->R__FOR_EACH(TObject,Draw)(option);
774}
775
776////////////////////////////////////////////////////////////////////////////////
777/// Find object in the list of memory objects.
778
780{
781 return fList->FindObject(obj);
782}
783
784////////////////////////////////////////////////////////////////////////////////
785/// Find object by name in the list of memory objects.
786
788{
789 return fList->FindObject(name);
790}
791
792////////////////////////////////////////////////////////////////////////////////
793/// Find object by name in the list of memory objects of the current
794/// directory or its sub-directories.
795/// After this call the current directory is not changed.
796/// To automatically set the current directory where the object is found,
797/// use FindKeyAny(aname)->ReadObj().
798
800{
801 //object may be already in the list of objects in memory
802 TObject *obj = fList->FindObject(aname);
803 if (obj) return obj;
804
805 //try with subdirectories
806 TIter next(fList);
807 while( (obj = next()) ) {
808 if (obj->IsA()->InheritsFrom(TDirectory::Class())) {
809 TDirectory* subdir = static_cast<TDirectory*>(obj);
810 TObject *subobj = subdir->TDirectory::FindObjectAny(aname); // Explicitly recurse into _this_ exact function.
811 if (subobj) {
812 return subobj;
813 }
814 }
815 }
816 return nullptr;
817}
818
819////////////////////////////////////////////////////////////////////////////////
820/// Return pointer to object identified by namecycle.
821///
822/// namecycle has the format name;cycle
823/// - name = * is illegal, cycle = * is illegal
824/// - cycle = "" or cycle = 9999 ==> apply to a memory object
825///
826/// examples:
827/// - foo : get object named foo in memory
828/// if object is not in memory, try with highest cycle from file
829/// - foo;1 : get cycle 1 of foo on file
830///
831/// The retrieved object should in principle derive from TObject.
832/// If not, the function TDirectory::GetObject should be called.
833/// However, this function will still work for a non-TObject, providing that
834/// the calling application cast the return type to the correct type (which
835/// is the actual type of the object).
836///
837/// NOTE:
838///
839/// The method GetObject offer better protection and avoid the need
840/// for any cast:
841/// ~~~ {.cpp}
842/// MyClass *obj;
843/// directory->GetObject("some object",obj);
844/// if (obj) { ... the object exist and inherits from MyClass ... }
845/// ~~~
846///
847/// VERY IMPORTANT NOTE:
848///
849/// In case the class of this object derives from TObject but not
850/// as a first inheritance, one must use dynamic_cast<>().
851/// #### Example 1: Normal case:
852/// ~~~ {.cpp}
853/// class MyClass : public TObject, public AnotherClass
854/// ~~~
855/// then on return, one can do:
856/// ~~~ {.cpp}
857/// MyClass *obj = (MyClass*)directory->Get("some object of MyClass");
858/// ~~~
859/// #### Example 2: Special case:
860/// ~~~ {.cpp}
861/// class MyClass : public AnotherClass, public TObject
862/// ~~~
863/// then on return, one must do:
864/// ~~~ {.cpp}
865/// MyClass *obj = dynamic_cast<MyClass*>(directory->Get("some object of MyClass"));
866/// ~~~
867/// Of course, dynamic_cast<> can also be used in the example 1.
868
870{
871 Short_t cycle;
872 char name[kMaxLen];
873
875 char *namobj = name;
876 Int_t nch = strlen(name);
877 for (Int_t i = nch-1; i > 0; i--) {
878 if (name[i] == '/') {
879 name[i] = 0;
881 namobj = name + i + 1;
882 name[i] = '/';
883 return dirToSearch ? dirToSearch->Get(namobj) : nullptr;
884 }
885 }
886
887//*-*---------------------Case of Object in memory---------------------
888// ========================
890 if (idcur) {
891 if (idcur==this && strlen(namobj)!=0) {
892 // The object has the same name has the directory and
893 // that's what we picked-up! We just need to ignore
894 // it ...
895 idcur = nullptr;
896 } else if (cycle == 9999) {
897 return idcur;
898 } else {
899 if (idcur->InheritsFrom(TCollection::Class()))
900 idcur->Delete(); // delete also list elements
901 delete idcur;
902 idcur = nullptr;
903 }
904 }
905 return idcur;
906}
907
908////////////////////////////////////////////////////////////////////////////////
909/// Return pointer to object identified by namecycle.
910/// The returned object may or may not derive from TObject.
911///
912/// - namecycle has the format name;cycle
913/// - name = * is illegal, cycle = * is illegal
914/// - cycle = "" or cycle = 9999 ==> apply to a memory object
915///
916/// VERY IMPORTANT NOTE:
917///
918/// The calling application must cast the returned object to
919/// the final type, e.g.
920/// ~~~ {.cpp}
921/// MyClass *obj = (MyClass*)directory->GetObject("some object of MyClass");
922/// ~~~
923
925{
926 return GetObjectChecked(namecycle,(TClass *)nullptr);
927}
928
929////////////////////////////////////////////////////////////////////////////////
930/// See documentation of TDirectory::GetObjectCheck(const char *namecycle, const TClass *cl)
931
932void *TDirectory::GetObjectChecked(const char *namecycle, const char* classname)
933{
934 return GetObjectChecked(namecycle, TClass::GetClass(classname));
935}
936
937
938////////////////////////////////////////////////////////////////////////////////
939/// Return pointer to object identified by namecycle if and only if the actual
940/// object is a type suitable to be stored as a pointer to a "expectedClass"
941/// If expectedClass is null, no check is performed.
942///
943/// namecycle has the format `name;cycle`
944/// - name = * is illegal, cycle = * is illegal
945/// - cycle = "" or cycle = 9999 ==> apply to a memory object
946///
947/// VERY IMPORTANT NOTE:
948///
949/// The calling application must cast the returned pointer to
950/// the type described by the 2 arguments (i.e. cl):
951/// ~~~ {.cpp}
952/// MyClass *obj = (MyClass*)directory->GetObjectChecked("some object of MyClass","MyClass"));
953/// ~~~
954/// Note: We recommend using the method TDirectory::GetObject:
955/// ~~~ {.cpp}
956/// MyClass *obj = nullptr;
957/// directory->GetObject("some object inheriting from MyClass",obj);
958/// if (obj) { ... we found what we are looking for ... }
959/// ~~~
960
962{
963 Short_t cycle;
964 char name[kMaxLen];
965
967 char *namobj = name;
968 Int_t nch = strlen(name);
969 for (Int_t i = nch-1; i > 0; i--) {
970 if (name[i] == '/') {
971 name[i] = 0;
973 namobj = name + i + 1;
974 name[i] = '/';
975 if (dirToSearch) {
976 return dirToSearch->GetObjectChecked(namobj, expectedClass);
977 } else {
978 return nullptr;
979 }
980 }
981 }
982
983//*-*---------------------Case of Object in memory---------------------
984// ========================
985 if (!expectedClass || expectedClass->IsTObject()) {
987 if (objcur) {
988 if (objcur==this && strlen(namobj)!=0) {
989 // The object has the same name has the directory and
990 // that's what we picked-up! We just need to ignore
991 // it ...
992 objcur = nullptr;
993 } else if (cycle == 9999) {
994 // Check type
995 if (expectedClass && objcur->IsA()->GetBaseClassOffset(expectedClass) == -1) return nullptr;
996 else return objcur;
997 } else {
998 if (objcur->InheritsFrom(TCollection::Class()))
999 objcur->Delete(); // delete also list elements
1000 delete objcur;
1001 objcur = nullptr;
1002 }
1003 }
1004 }
1005
1006 return nullptr;
1007}
1008
1009////////////////////////////////////////////////////////////////////////////////
1010/// Returns the full path of the directory. E.g. `file:/dir1/dir2`.
1011/// The returned path will be re-used by the next call to GetPath().
1012
1013const char *TDirectory::GetPathStatic() const
1014{
1015 static char *path = nullptr;
1016 const int kMAXDEPTH = 128;
1017 const TDirectory *d[kMAXDEPTH];
1018 const TDirectory *cur = this;
1019 int depth = 0, len = 0;
1020
1021 d[depth++] = cur;
1022 len = strlen(cur->GetName()) + 1; // +1 for the /
1023
1024 while (cur->fMother && depth < kMAXDEPTH) {
1025 cur = (TDirectory *)cur->fMother;
1026 d[depth++] = cur;
1027 len += strlen(cur->GetName()) + 1;
1028 }
1029
1030 if (path) delete [] path;
1031 path = new char[len+2];
1032
1033 for (int i = depth-1; i >= 0; i--) {
1034 if (i == depth-1) { // file or TROOT name
1035 strlcpy(path, d[i]->GetName(),len+2);
1036 strlcat(path, ":",len+2);
1037 if (i == 0) strlcat(path, "/",len+2);
1038 } else {
1039 strlcat(path, "/",len+2);
1040 strlcat(path, d[i]->GetName(),len+2);
1041 }
1042 }
1043
1044 return path;
1045}
1046
1047////////////////////////////////////////////////////////////////////////////////
1048/// Returns the full path of the directory. E.g. `file:/dir1/dir2`.
1049/// The returned path will be re-used by the next call to GetPath().
1050
1051const char *TDirectory::GetPath() const
1052{
1054
1055 if (!GetMotherDir()) // case of file
1056 fPathBuffer.Append("/");
1057
1058 return fPathBuffer.Data();
1059}
1060
1061////////////////////////////////////////////////////////////////////////////////
1062/// Recursive method to fill full path for directory.
1063
1065{
1067 if (mom) {
1068 mom->FillFullPath(buf);
1069 buf += "/";
1070 buf += GetName();
1071 } else {
1072 buf = GetName();
1073 buf += ":";
1074 }
1075}
1076
1077////////////////////////////////////////////////////////////////////////////////
1078/// Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
1079///
1080/// @param name the name or hierarchy of the subdirectory ("a" or "a/b/c")
1081/// @param title the title
1082/// @param returnExistingDirectory if key-name is already existing, the returned
1083/// value points to preexisting sub-directory if true and to `nullptr` if false.
1084/// @return a pointer to the created sub-directory, not to the top sub-directory
1085/// of the hierarchy (in the above example, the returned TDirectory * points
1086/// to "c"). In case of an error, it returns `nullptr`. In case of a preexisting
1087/// sub-directory (hierarchy) with the requested name, the return value depends
1088/// on the parameter returnExistingDirectory.
1089///
1090/// In particular, the steps to create first a/b/c and then a/b/d without receiving
1091/// errors are:
1092/// ~~~ {.cpp}
1093/// TFile * file = new TFile("afile","RECREATE");
1094/// file->mkdir("a");
1095/// file->cd("a");
1096/// gDirectory->mkdir("b/c");
1097/// gDirectory->cd("b");
1098/// gDirectory->mkdir("d");
1099/// ~~~
1100/// or
1101/// ~~~ {.cpp}
1102/// TFile * file = new TFile("afile","RECREATE");
1103/// file->mkdir("a");
1104/// file->cd("a");
1105/// gDirectory->mkdir("b/c");
1106/// gDirectory->mkdir("b/d", "", true);
1107/// ~~~
1108
1110{
1113 if (existingdir)
1114 return existingdir;
1115 }
1116 if (!name || !title || !name[0]) return nullptr;
1117 if (!title[0]) title = name;
1118 if (const char *slash = strchr(name,'/')) {
1120 char *workname = new char[size+1];
1122 workname[size] = 0;
1125 if (!tmpdir)
1126 tmpdir = mkdir(workname,title);
1127 delete[] workname;
1128 if (!tmpdir) return nullptr;
1129 return tmpdir->mkdir(slash+1);
1130 }
1131
1133
1134 return new TDirectory(name, title, "", this);
1135}
1136
1137////////////////////////////////////////////////////////////////////////////////
1138/// List Directory contents.
1139///
1140/// Indentation is used to identify the directory tree
1141/// Subdirectories are listed first, then objects in memory.
1142///
1143/// The option can has the following format:
1144///
1145/// [<regexp>]
1146///
1147/// The `<regexp>` will be used to match the name of the objects.
1148/// By default memory and disk objects are listed.
1149
1151{
1154
1156 TString opt = opta.Strip(TString::kBoth);
1158 TString reg = "*";
1159 if (opt.BeginsWith("-m")) {
1160 if (opt.Length() > 2)
1161 reg = opt(2,opt.Length());
1162 } else if (opt.BeginsWith("-d")) {
1163 memobj = kFALSE;
1164 if (opt.Length() > 2)
1165 reg = opt(2,opt.Length());
1166 } else if (!opt.IsNull())
1167 reg = opt;
1168
1169 TRegexp re(reg, kTRUE);
1170
1171 if (memobj) {
1172 TObject *obj;
1174 while ((obj = (TObject *) nextobj())) {
1175 TString s = obj->GetName();
1176 if (s.Index(re) == kNPOS) continue;
1177 obj->ls(option); //*-* Loop on all the objects in memory
1178 }
1179 }
1181}
1182
1183////////////////////////////////////////////////////////////////////////////////
1184/// Paint all objects in the directory.
1185
1187{
1188 fList->R__FOR_EACH(TObject,Paint)(option);
1189}
1190
1191////////////////////////////////////////////////////////////////////////////////
1192/// Print all objects in the directory.
1193
1195{
1196 fList->R__FOR_EACH(TObject,Print)(option);
1197}
1198
1199////////////////////////////////////////////////////////////////////////////////
1200/// Print the path of the directory.
1201
1203{
1204 Printf("%s", GetPath());
1205}
1206
1207////////////////////////////////////////////////////////////////////////////////
1208/// Recursively remove object from a Directory.
1209
1211{
1212 if (fList)
1213 fList->RecursiveRemove(obj);
1214}
1215
1216////////////////////////////////////////////////////////////////////////////////
1217/// Remove an object from the in-memory list.
1218
1220{
1221 TObject *p = nullptr;
1222 if (fList) {
1223 p = fList->Remove(obj);
1224 }
1225 return p;
1226}
1227
1228////////////////////////////////////////////////////////////////////////////////
1229/// Removes subdirectory from the directory
1230/// When directory is deleted, all keys in all subdirectories will be
1231/// read first and deleted from file (if exists)
1232/// Equivalent call is Delete("name;*");
1233
1234void TDirectory::rmdir(const char *name)
1235{
1236 if ((name==nullptr) || (*name==0)) return;
1237
1238 TString mask(name);
1239 mask+=";*";
1240 Delete(mask);
1241}
1242
1243////////////////////////////////////////////////////////////////////////////////
1244/// Save object in filename,
1245/// if filename is `nullptr` or "", a file with "<objectname>.root" is created.
1246/// The name of the key is the object name.
1247/// By default new file will be created. Using option "a", one can append object
1248/// to the existing ROOT file.
1249/// If the operation is successful, it returns the number of bytes written to the file
1250/// otherwise it returns 0.
1251/// By default a message is printed. Use option "q" to not print the message.
1252/// If filename contains ".json" extension, JSON representation of the object
1253/// will be created and saved in the text file. Such file can be used in
1254/// JavaScript ROOT (https://root.cern/js/) to display object in web browser
1255/// When creating JSON file, option string may contain compression level from 0 to 3 (default 0)
1256
1258{
1259 // option can contain single letter args: "a" for append, "q" for quiet in any combinations
1260
1261 if (!obj) return 0;
1262 Int_t nbytes = 0;
1263 TString fname, opt = option, cmd;
1264 if (filename && *filename)
1265 fname = filename;
1266 else
1267 fname.Form("%s.root", obj->GetName());
1268 opt.ToLower();
1269
1270 if (fname.Index(".json") > 0) {
1271 cmd.Form("TBufferJSON::ExportToFile(\"%s\", (TObject *) 0x%zx, \"%s\");", fname.Data(), (size_t) obj, (option ? option : ""));
1272 nbytes = gROOT->ProcessLine(cmd);
1273 } else {
1274 cmd.Form("TFile::Open(\"%s\",\"%s\");", fname.Data(), opt.Contains("a") ? "update" : "recreate");
1275 TContext ctxt; // The TFile::Open will change the current directory.
1276 TDirectory *local = (TDirectory*)gROOT->ProcessLine(cmd);
1277 if (!local) return 0;
1278 nbytes = obj->Write();
1279 delete local;
1280 }
1281 if (!opt.Contains("q") && !gSystem->AccessPathName(fname.Data()))
1282 obj->Info("SaveAs", "ROOT file %s has been created", fname.Data());
1283 return nbytes;
1284}
1285
1286////////////////////////////////////////////////////////////////////////////////
1287/// Set the name for directory
1288/// If the directory name is changed after the directory was written once,
1289/// ROOT currently would NOT change the name of correspondent key in the
1290/// mother directory.
1291/// DO NOT use this method to 'rename a directory'.
1292/// Renaming a directory is currently NOT supported.
1293
1295{
1297}
1298
1299////////////////////////////////////////////////////////////////////////////////
1300/// Decode a namecycle `"aap;2"` contained in the null-terminated string `buffer` into name `"aap"` and cycle `2`.
1301/// The destination buffer size for `name` (including the string terminator) should be specified in
1302/// `namesize`. If `namesize` is too small to contain the full name, the name will be truncated to `namesize`.
1303/// If `namesize == 0` but `name` is not nullptr, this method will assume that `name` points
1304/// to a large enough buffer to hold the name. THIS IS UNSAFE, so you should **always** pass the proper `namesize`!
1305/// If `name` is nullptr, only the cycle will be returned and `namesize` will be ignored.
1306/// @note Edge cases:
1307/// - If the number after the `;` is larger than `SHORT_MAX`, cycle is set to `0`.
1308/// - If name ends with `;*`, cycle is set to 10000`.
1309/// - In all other cases, i.e. when number is not a digit, buffer is a nullptr or buffer does not contain a cycle,
1310/// `cycle` is set to `9999`.
1311/// @return The actual name length, or 0 if `buffer` was a nullptr.
1312
1313size_t TDirectory::DecodeNameCycle(const char *buffer, char *name, Short_t &cycle, const size_t namesize)
1314{
1315 if (!buffer) {
1316 cycle = 9999;
1317 return 0;
1318 }
1319
1320 // Scan the string to find the name length and the semicolon
1321 size_t nameLen = 0;
1322 int semicolonIdx = -1;
1323 {
1324 char ch = buffer[nameLen];
1325 while (ch) {
1326 if (ch == ';') {
1328 break;
1329 }
1330 ++nameLen;
1331 ch = buffer[nameLen];
1332 }
1333 }
1334 assert(semicolonIdx == -1 || semicolonIdx == static_cast<int>(nameLen));
1335
1336 if (name) {
1337 size_t truncatedNameLen = nameLen;
1338 if (namesize) {
1339 // accommodate string terminator
1341 } else {
1342 ::Error("TDirectory::DecodeNameCycle",
1343 "Using unsafe version: invoke this method by specifying the buffer size");
1344 }
1345
1346 strncpy(name, buffer, truncatedNameLen);
1347 name[truncatedNameLen] = '\0';
1348 }
1349
1350 if (semicolonIdx < 0) {
1351 // namecycle didn't contain a cycle
1352 cycle = 9999;
1353 return nameLen;
1354 }
1355
1356 const char *cycleStr = buffer + semicolonIdx + 1;
1357
1358 if (cycleStr[0] == '*') {
1359 cycle = 10000;
1360 } else if (isdigit(cycleStr[0])) {
1361 long parsed = strtol(cycleStr, nullptr, 10);
1362 if (parsed >= static_cast<long>(std::numeric_limits<Short_t>::max()))
1363 cycle = 0;
1364 else
1365 cycle = static_cast<Short_t>(parsed);
1366 } else {
1367 // Either `;` was the last character of the string, or the character following it was invalid.
1368 cycle = 9999;
1369 }
1370
1371 return nameLen;
1372}
1373
1375{
1376 // peg the current directory
1377 TDirectory *current;
1378 {
1380 current = TDirectory::CurrentDirectory().load();
1381 // Don't peg if there is no current directory or if the current
1382 // directory's destruction has already started (in another thread)
1383 // and is waiting for this thread to leave the critical section.
1384 if (!current || !current->IsBuilt())
1385 return;
1386 ++(current->fContextPeg);
1387 }
1388 current->RegisterContext(this);
1389 --(current->fContextPeg);
1390}
1391
1392///////////////////////////////////////////////////////////////////////////////
1393/// Register a TContext pointing to this TDirectory object
1394
1397
1398 if (!IsBuilt() || this == ROOT::Internal::gROOTLocal)
1399 return;
1400 if (fContext) {
1401 TContext *current = fContext;
1402 while(current->fNext) {
1403 current = current->fNext;
1404 }
1405 current->fNext = ctxt;
1406 ctxt->fPrevious = current;
1407 } else {
1408 fContext = ctxt;
1409 }
1410}
1411
1412////////////////////////////////////////////////////////////////////////////////
1413/// Register a std::atomic<TDirectory*> that will soon be pointing to this TDirectory object
1414
1416{
1418 if (std::find(fGDirectories.begin(), fGDirectories.end(), gdirectory_ptr) == fGDirectories.end()) {
1419 fGDirectories.emplace_back(gdirectory_ptr);
1420 }
1421 // FIXME:
1422 // globalptr->load()->fGDirectories will still contain globalptr, but we cannot
1423 // know whether globalptr->load() has been deleted by another thread in the meantime.
1424}
1425
1426////////////////////////////////////////////////////////////////////////////////
1427/// \copydoc TDirectoryFile::WriteObject(const T*,const char*,Option_t*,Int_t).
1428
1429Int_t TDirectory::WriteTObject(const TObject *obj, const char *name, Option_t * /*option*/, Int_t /*bufsize*/)
1430{
1431 const char *objname = "no name specified";
1432 if (name) objname = name;
1433 else if (obj) objname = obj->GetName();
1434 Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.",GetName(),objname);
1435 return 0;
1436}
1437
1438////////////////////////////////////////////////////////////////////////////////
1439/// UnRegister a TContext pointing to this TDirectory object
1440
1442
1444
1445 // Another thread already unregistered the TContext.
1446 if (ctxt->fDirectory == nullptr || ctxt->fDirectory == ROOT::Internal::gROOTLocal)
1447 return;
1448
1449 if (ctxt==fContext) {
1450 fContext = ctxt->fNext;
1451 if (fContext) fContext->fPrevious = nullptr;
1452 ctxt->fPrevious = ctxt->fNext = nullptr;
1453 } else {
1454 TContext *next = ctxt->fNext;
1455 ctxt->fPrevious->fNext = next;
1456 if (next) next->fPrevious = ctxt->fPrevious;
1457 ctxt->fPrevious = ctxt->fNext = nullptr;
1458 }
1459}
1460
1461////////////////////////////////////////////////////////////////////////////////
1462/// TDirectory Streamer.
1464{
1465 // Stream an object of class TDirectory.
1466
1467 UInt_t R__s, R__c;
1468 if (R__b.IsReading()) {
1469 Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
1471 R__b >> fMother;
1472 R__b >> fList;
1473 fList->UseRWLock();
1475 R__b.CheckByteCount(R__s, R__c, TDirectory::IsA());
1476 } else {
1477 R__c = R__b.WriteVersion(TDirectory::IsA(), kTRUE);
1479 R__b << fMother;
1480 R__b << fList;
1482 R__b.SetByteCount(R__c, kTRUE);
1483 }
1484}
#define SafeDelete(p)
Definition RConfig.hxx:533
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:53
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
Definition RtypesCore.h:131
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define ClassImp(name)
Definition Rtypes.h:376
void(* tcling_callfunc_Wrapper_t)(void *, int, void **, void *)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
static std::atomic_flag * GetCurrentDirectoryLock()
static TBuffer * R__CreateBuffer()
Fast execution of 'new TBufferFile(TBuffer::kWrite,10000), without having a compile time circular dep...
const Int_t kMaxLen
#define gDirectory
Definition TDirectory.h:385
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void reg
char name[80]
Definition TGX11.cxx:110
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:411
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2510
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define R__LOCKGUARD(mutex)
A spin mutex-as-code-guard class.
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
Buffer base class used for serializing objects.
Definition TBuffer.h:43
@ kWrite
Definition TBuffer.h:73
virtual void ResetMap()=0
void SetBufferOffset(Int_t offset=0)
Definition TBuffer.h:93
void SetReadMode()
Set buffer in read mode.
Definition TBuffer.cxx:302
virtual void MapObject(const TObject *obj, UInt_t offset=1)=0
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
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:2974
static TClass * Class()
virtual bool UseRWLock(Bool_t enable=true)
Set this collection to use a RW lock upon access, making it thread safe.
R__ALWAYS_INLINE Bool_t IsUsingRWLock() const
TDirectory::TContext keeps track and restore the current directory.
Definition TDirectory.h:89
void CdNull()
Set the current directory to null.
~TContext()
Destructor.
TContext * fPrevious
Set to true if a TDirectory might still access this object.
Definition TDirectory.h:94
TContext * fNext
Pointer to the next TContext in the implied list of context pointing to fPrevious.
Definition TDirectory.h:95
Describe directory structure in memory.
Definition TDirectory.h:45
Bool_t cd1(const char *path)
flag to add histograms, graphs,etc to the directory
static TClass * Class()
void Delete(const char *namecycle="") override
Delete Objects or/and keys in a directory.
virtual void Close(Option_t *option="")
Delete all objects from memory and directory structure itself.
virtual void Save()
Definition TDirectory.h:254
virtual TList * GetList() const
Definition TDirectory.h:223
std::shared_ptr< std::atomic< TDirectory * > > SharedGDirectory_t
Pointer to a list of TContext object pointing to this TDirectory.
Definition TDirectory.h:147
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual const char * GetPath() const
Returns the full path of the directory.
std::atomic_flag fSpinLock
Counter delaying the TDirectory destructor from finishing.
Definition TDirectory.h:154
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
virtual void * GetObjectUnchecked(const char *namecycle)
Return pointer to object identified by namecycle.
void Draw(Option_t *option="") override
Fill Graphics Structure and Paint.
static size_t DecodeNameCycle(const char *namecycle, char *name, Short_t &cycle, const size_t namesize=0)
Decode a namecycle "aap;2" contained in the null-terminated string buffer into name "aap" and cycle 2...
virtual void DeleteAll(Option_t *option="")
Delete all objects from memory.
std::atomic< size_t > fContextPeg
thread local gDirectory pointing to this object.
Definition TDirectory.h:153
std::vector< SharedGDirectory_t > fGDirectories
Definition TDirectory.h:151
virtual void rmdir(const char *name)
Removes subdirectory from the directory When directory is deleted, all keys in all subdirectories wil...
static Bool_t AddDirectoryStatus()
Static function: see TDirectory::AddDirectory for more comments.
void FillFullPath(TString &buf) const
Recursive method to fill full path for directory.
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add objects like histograms, TGraph2D, etc in memory.
void CleanTargets()
Clean the pointers to this object (gDirectory, TContext, etc.).
void ls(Option_t *option="") const override
List Directory contents.
TContext * fContext
Buffer for GetPath() function.
Definition TDirectory.h:145
virtual void Append(TObject *obj, Bool_t replace=kFALSE)
Append object to this directory.
void RegisterGDirectory(SharedGDirectory_t &ptr)
Register a std::atomic<TDirectory*> that will soon be pointing to this TDirectory object.
TDirectory()
Directory default constructor.
static Bool_t Cd(const char *path)
Change current directory to "path".
void Clear(Option_t *option="") override
Delete all objects from a Directory list.
virtual Int_t WriteTObject(const TObject *obj, const char *name=nullptr, Option_t *="", Int_t=0)
Write an object with proper type checking.
TObject * FindObject(const char *name) const override
Find object by name in the list of memory objects.
void Print(Option_t *option="") const override
Print all objects in the directory.
virtual Bool_t cd()
Change current directory to "this" directory.
virtual ~TDirectory()
Destructor.
static Bool_t Cd1(const char *path)
Change current directory to "path".
void UnregisterContext(TContext *ctxt)
UnRegister a TContext pointing to this TDirectory object.
void Streamer(TBuffer &) override
TDirectory Streamer.
void RecursiveRemove(TObject *obj) override
Recursively remove object from a Directory.
virtual Int_t SaveObjectAs(const TObject *, const char *="", Option_t *="") const
Save object in filename, if filename is nullptr or "", a file with "<objectname>.root" is created.
TString fPathBuffer
Definition TDirectory.h:144
virtual TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE)
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
void SetName(const char *newname) override
Set the name for directory If the directory name is changed after the directory was written once,...
void BuildDirectory(TFile *motherFile, TDirectory *motherDir)
Initialise directory to defaults.
static SharedGDirectory_t & GetSharedLocalCurrentDirectory()
Return the (address of) a shared pointer to the struct holding the actual thread local gDirectory poi...
TUUID fUUID
Definition TDirectory.h:143
static Bool_t fgAddDirectory
MSVC doesn't support = ATOMIC_FLAG_INIT;.
Definition TDirectory.h:156
TDirectory * GetMotherDir() const
Definition TDirectory.h:226
virtual const char * GetPathStatic() const
Returns the full path of the directory.
static std::atomic< TDirectory * > & CurrentDirectory()
Return the current directory for the current thread.
TClass * IsA() const override
Definition TDirectory.h:309
TObject * fMother
Definition TDirectory.h:141
void Browse(TBrowser *b) override
Browse the content of the directory.
void GetObject(const char *namecycle, T *&ptr)
Get an object with proper type checking.
Definition TDirectory.h:213
virtual void pwd() const
Print the path of the directory.
virtual void * GetObjectChecked(const char *namecycle, const char *classname)
See documentation of TDirectory::GetObjectCheck(const char *namecycle, const TClass *cl)
virtual TObject * CloneObject(const TObject *obj, Bool_t autoadd=kTRUE)
Clone an object.
Bool_t IsBuilt() const
Definition TDirectory.h:235
virtual TObject * Remove(TObject *)
Remove an object from the in-memory list.
void RegisterContext(TContext *ctxt)
Register a TContext pointing to this TDirectory object.
TList * fList
Definition TDirectory.h:142
void Paint(Option_t *option="") override
Paint all objects in the directory.
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.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
void Clear(Option_t *option="") override
Remove all objects from the list.
Definition TList.cxx:400
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:576
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition TList.cxx:762
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:820
virtual TObjLink * FirstLink() const
Definition TList.h:102
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:468
Each ROOT class (see TClass) has a linked list of methods.
Definition TMethod.h:38
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
void Streamer(TBuffer &) override
Stream an object of class TObject.
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:150
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:458
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1058
static TClass * Class()
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition TObject.cxx:965
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:865
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:544
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1072
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1100
virtual TClass * IsA() const
Definition TObject.h:246
virtual void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
Definition TObject.cxx:593
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:68
@ kIsReferenced
if object is referenced by a TRef or TRefArray
Definition TObject.h:71
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition TObject.h:70
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1046
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition TROOT.cxx:2891
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2899
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition TROOT.cxx:2749
Regular expression class.
Definition TRegexp.h:31
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
void ToLower()
Change string to lower-case.
Definition TString.cxx:1190
const char * Data() const
Definition TString.h:384
@ kBoth
Definition TString.h:284
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:631
Bool_t IsNull() const
Definition TString.h:422
TString & Append(const char *cs)
Definition TString.h:580
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:659
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:1309
virtual void Streamer(TBuffer &)
R__EXTERN TROOT * gROOTLocal
Definition TROOT.h:384
void(* DirAutoAdd_t)(void *, TDirectory *)
Definition Rtypes.h:120
@ kExactMatch
TCanvas * slash()
Definition slash.C:1
th1 Draw()
TMarker m
Definition textangle.C:8