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