71 if (initMotherDir==0) initMotherDir =
gDirectory;
73 if (strchr(name,
'/')) {
74 ::Error(
"TDirectory::TDirectory",
"directory name (%s) cannot contain a slash", name);
79 ::Error(
"TDirectory::TDirectory",
"directory name cannot be \"\"");
84 Build(initMotherDir ? initMotherDir->
GetFile() : 0, initMotherDir);
95 directory.
Copy(*
this);
110 Fatal(
"~TDirectory",
"In %s:%p the fList (%p) is not using the RWLock\n",
125 Info(
"~TDirectory",
"dtor called for %s",
GetName());
136 fActiveDestructor =
true;
140 (*fDirectory).UnregisterContext(
this);
151 fActiveDestructor =
false;
152 while(fDirectoryWait);
192 if (obj == 0 ||
fList == 0)
return;
197 Warning(
"Append",
"Replacing existing %s: %s (Potential memory leak).",
224 while ((obj = nextin())) {
246 if (motherDir && strlen(
GetName()) != 0) motherDir->
Append(
this);
254 std::vector<TContext*> extraWait;
264 ctxt->fDirectory =
nullptr;
266 if (ctxt->fActiveDestructor) {
269 ctxt->fDirectoryWait =
false;
274 for(
auto &&context : extraWait) {
277 while(context->fActiveDestructor);
283 if (cursav && cursav !=
this) {
302 typedef void (*tcling_callfunc_Wrapper_t)(
void*, int,
void**,
void*);
303 static tcling_callfunc_Wrapper_t creator = 0;
312 void *args[] = { &mode, &size };
314 creator(0,2,args,&result);
331 char *pobj = (
char*)obj->IsA()->New();
333 Fatal(
"CloneObject",
"Failed to create new object");
338 if (baseOffset==-1) {
342 Fatal(
"CloneObject",
"Incorrect detection of the inheritance from TObject for class %s.\n",
352 Fatal(
"CloneObject",
"Not able to create a TBuffer!");
356 const_cast<TObject*
>(obj)->Streamer(*buffer);
363 newobj->Streamer(*buffer);
384 return currentDirectory;
401 Bool_t printError,
const char *funcname)
404 if (apath) nch = strlen(apath);
409 if (funcname==0 || strlen(funcname)==0) funcname =
"GetDirectory";
413 char *path =
new char[nch+1]; path[0] = 0;
414 if (nch) strlcpy(path,apath,nch+1);
415 char *
s = (
char*)strrchr(path,
':');
420 if (!f && !strcmp(
gROOT->GetName(), path)) f =
gROOT;
424 if (s && *(s+1)) result = f->
GetDirectory(s+1,printError,funcname);
425 delete [] path;
return result;
427 if (printError)
Error(funcname,
"No such file %s", path);
428 delete [] path;
return 0;
433 if (path[0] ==
'/') {
436 delete [] path;
return result;
440 char *
slash = (
char*)strchr(path,
'/');
442 if (!strcmp(path,
"..")) {
444 delete [] path;
return result;
448 if (printError)
Error(funcname,
"Unknown directory %s", path);
449 delete [] path;
return 0;
454 if (printError)
Error(funcname,
"Object %s is not a directory", path);
455 delete [] path;
return 0;
461 slash = (
char*)strchr(subdir.
Data(),
'/');
464 if (!strcmp(subdir,
"..")) {
467 result = mom->
GetDirectory(slash+1,printError,funcname);
468 delete [] path;
return result;
472 if (printError)
Error(funcname,
"Unknown directory %s", subdir.
Data());
473 delete [] path;
return 0;
478 if (printError)
Error(funcname,
"Object %s is not a directory", subdir.
Data());
479 delete [] path;
return 0;
482 delete [] path;
return result;
518 if (apath) nch = strlen(apath);
558 if (apath) nch = strlen(apath);
559 if (!nch)
return kTRUE;
654 Info(
"Delete",
"Call for this = %s namecycle = %s",
655 GetName(), (namecycle ? namecycle :
"null"));
663 Int_t deletetree = 0;
664 if(strcmp(name,
"*") == 0) deleteall = 1;
665 if(strcmp(name,
"*T") == 0){ deleteall = 1; deletetree = 1;}
666 if(strcmp(name,
"T*") == 0){ deleteall = 1; deletetree = 1;}
667 if(namecycle==0 || !namecycle[0]){ deleteall = 1; deletetree = 1;}
674 if (cycle >= 9999 ) {
677 while ((idcur = (
TNamed *) next())) {
684 if (!deletetree && deleteall) deleteOK = 0;
693 idcur->
Delete(deletetree ?
"T*;*" :
"*");
743 while( (obj = next()) ) {
746 TObject *subobj = subdir->TDirectory::FindObjectAny(aname);
812 Int_t nch = strlen(name);
813 for (
Int_t i = nch-1; i > 0; i--) {
814 if (name[i] ==
'/') {
817 namobj = name + i + 1;
819 return dirToSearch?dirToSearch->
Get(namobj):0;
827 if (idcur==
this && strlen(namobj)!=0) {
832 }
else if (cycle == 9999) {
904 Int_t nch = strlen(name);
905 for (
Int_t i = nch-1; i > 0; i--) {
906 if (name[i] ==
'/') {
909 namobj = name + i + 1;
921 if (expectedClass==0 || expectedClass->
IsTObject()) {
924 if (objcur==
this && strlen(namobj)!=0) {
929 }
else if (cycle == 9999) {
931 if (expectedClass && objcur->IsA()->GetBaseClassOffset(expectedClass) == -1)
return 0;
951 static char *path = 0;
952 const int kMAXDEPTH = 128;
955 int depth = 0, len = 0;
958 len = strlen(cur->
GetName()) + 1;
960 while (cur->
fMother && depth < kMAXDEPTH) {
963 len += strlen(cur->
GetName()) + 1;
966 if (path)
delete [] path;
967 path =
new char[len+2];
969 for (
int i = depth-1; i >= 0; i--) {
971 strlcpy(path, d[i]->
GetName(),len+2);
972 strlcat(path,
":",len+2);
973 if (i == 0) strlcat(path,
"/",len+2);
975 strlcat(path,
"/",len+2);
976 strlcat(path, d[i]->
GetName(),len+2);
1036 if (!name || !title || !name[0])
return 0;
1037 if (!title[0]) title =
name;
1039 if (
const char *
slash = strchr(name,
'/')) {
1041 char *workname =
new char[size+1];
1042 strncpy(workname, name, size);
1047 tmpdir =
mkdir(workname,title);
1048 if (!tmpdir)
return 0;
1051 if (!tmpdir)
return 0;
1052 if (!newdir) newdir = tmpdir;
1059 newdir =
new TDirectory(name, title,
"",
this);
1088 reg = opt(2,opt.
Length());
1092 reg = opt(2,opt.
Length());
1093 }
else if (!opt.
IsNull())
1101 while ((obj = (
TObject *) nextobj())) {
1162 if ((name==0) || (*name==0))
return;
1186 if (!filename || !filename[0]) {
1190 if (fname.
Index(
".json") > 0) {
1192 nbytes =
gROOT->ProcessLine(cmd);
1194 cmd.
Form(
"TFile::Open(\"%s\",\"recreate\");",fname.
Data());
1197 if (!local)
return 0;
1198 nbytes = obj->
Write();
1228 strcpy(buffer, name);
1230 sprintf(buffer,
"%s;%d", name, cycle);
1239 const size_t namesize)
1242 const char *ni = strchr(buffer,
';');
1250 len = strlen(buffer);
1255 if (len > namesize-1ul) len = namesize-1;
1257 ::Warning(
"TDirectory::DecodeNameCycle",
1258 "Using unsafe version: invoke this metod by specifying the buffer size");
1261 strncpy(name, buffer, len);
1266 else if (isdigit(*ni)) {
1267 long parsed = strtol(ni,
nullptr,10);
1268 if (parsed >= (
long) std::numeric_limits<Short_t>::max())
1284 while(current->
fNext) {
1285 current = current->
fNext;
1287 current->
fNext = ctxt;
1299 const char *objname =
"no name specified";
1300 if (name) objname =
name;
1301 else if (obj) objname = obj->
GetName();
1302 Error(
"WriteTObject",
"The current directory (%s) is not associated with a file. The object (%s) has not been written.",
GetName(),objname);
1341 void TDirectory::Streamer(
TBuffer &R__b)
1348 TNamed::Streamer(R__b);
1352 fUUID.Streamer(R__b);
1357 TNamed::Streamer(R__b);
1360 fUUID.Streamer(R__b);
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
virtual const char * GetName() const
Returns name of object.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
void SetBufferOffset(Int_t offset=0)
virtual void Draw(Option_t *option="")
Fill Graphics Structure and Paint.
virtual void Copy(TObject &) const
Copy this to obj.
virtual ~TDirectory()
Destructor.
std::atomic_flag fSpinLock
Counter delaying the TDirectory destructor from finishing.
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
virtual void Build(TFile *motherFile=0, TDirectory *motherDir=0)
Initialise directory to defaults.
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
virtual TDirectory * GetMotherDir() const
void GetObject(const char *namecycle, T *&ptr)
virtual void Print(Option_t *option="") const
Print all objects in the directory.
virtual TObject * CloneObject(const TObject *obj, Bool_t autoadd=kTRUE)
Clone an object.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual const char * GetPathStatic() const
Returns the full path of the directory.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
virtual TObject * FindObject(const char *name) const
Find object by name in the list of memory objects.
Buffer base class used for serializing objects.
Regular expression class.
void FillFullPath(TString &buf) const
Recursive method to fill full path for directory.
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual Int_t WriteTObject(const TObject *obj, const char *name=0, Option_t *="", Int_t=0)
See TDirectoryFile::WriteTObject for details.
std::atomic< bool > fDirectoryWait
Set to true during the destructor execution.
void ToLower()
Change string to lower-case.
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
R__EXTERN TVirtualMutex * gROOTMutex
TContext * fPrevious
Set to true if a TDirectory might still access this object.
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
virtual Int_t SaveObjectAs(const TObject *, const char *="", Option_t *="") const
Save object in filename, if filename is 0 or "", a file with "objectname.root" is created...
R__EXTERN void **(* gThreadTsd)(void *, Int_t)
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual TObject * FindObject(const char *name) const
Delete a TObjLink object.
virtual void * GetObjectChecked(const char *namecycle, const char *classname)
See documentation of TDirectory::GetObjectCheck(const char *namecycle, const TClass *cl) ...
if object in a list can be deleted
std::atomic< TDirectory * > fDirectory
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
void * InterfaceMethod() const
Return pointer to the interface method.
The TNamed class is the base class for all named ROOT classes.
virtual void Paint(Option_t *option="")
Paint all objects in the directory.
Bool_t cd1(const char *path)
flag to add histograms, graphs,etc to the directory
TString & Append(const char *cs)
virtual void Close(Option_t *option="")
Delete all objects from memory and directory structure itself.
virtual void rmdir(const char *name)
Removes subdirectory from the directory When directory is deleted, all keys in all subdirectories wil...
virtual bool UseRWLock()
Set this collection to use a RW lock upon access, making it thread safe.
virtual TList * GetList() const
virtual TFile * GetFile() const
virtual void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
virtual void pwd() const
Print the path of the directory.
virtual void Delete(const char *namecycle="")
Delete Objects or/and keys in a directory.
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add objects like histograms, TGraph2D, etc in memory...
virtual void Delete(Option_t *option="")
Delete this object.
Using a TBrowser one can browse all ROOT objects.
TContext * fNext
Pointer to the next TContext in the implied list of context pointing to fPrevious.
virtual void Browse(TBrowser *b)
Browse the content of the directory.
R__EXTERN TSystem * gSystem
R__ALWAYS_INLINE Bool_t IsUsingRWLock() const
TContext * fContext
Buffer for GetPath() function.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
virtual void * GetObjectUnchecked(const char *namecycle)
Return pointer to object identified by namecycle.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
static Bool_t Cd1(const char *path)
Change current directory to "path".
virtual void Append(TObject *obj, Bool_t replace=kFALSE)
Append object to this directory.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
void SetReadMode()
Set buffer in read mode.
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
The ROOT global object gROOT contains a list of all defined classes.
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
virtual const char * GetPath() const
Returns the full path of the directory.
if object destructor must call RecursiveRemove()
virtual TObjLink * FirstLink() const
virtual void Clear(Option_t *option="")
Delete all objects from a Directory list.
virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=0)=0
virtual void MapObject(const TObject *obj, UInt_t offset=1)=0
virtual void SetName(const char *newname)
Set the name for directory If the directory name is changed after the directory was written once...
virtual TObject * Remove(TObject *)
Remove an object from the in-memory list.
static Bool_t Cd(const char *path)
Change current directory to "path".
static void EncodeNameCycle(char *buffer, const char *name, Short_t cycle)
Encode the name and cycle into buffer like: "aap;2".
Describe directory structure in memory.
static TDirectory *& CurrentDirectory()
Return the current directory for the current thread.
Wrapper around a TObject so it can be stored in a TList.
static Bool_t AddDirectoryStatus()
Static function: see TDirectory::AddDirectory for more comments.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
static constexpr double s
#define R__LOCKGUARD(mutex)
static void DecodeNameCycle(const char *namecycle, char *name, Short_t &cycle, const size_t namesize=0)
Decode a namecycle "aap;2" into name "aap" and cycle "2".
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Mother of all ROOT objects.
TObject * GetObject() const
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
typedef void((*Func_t)())
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
static TBuffer * R__CreateBuffer()
Fast execution of 'new TBufferFile(TBuffer::kWrite,10000), without having a compile time circular dep...
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
virtual void Add(TObject *obj)
void(* DirAutoAdd_t)(void *, TDirectory *)
virtual void RecursiveRemove(TObject *obj)
Remove object from this collection and recursively remove the object from all other objects (and coll...
virtual void DeleteAll(Option_t *option="")
Delete all objects from memory.
virtual void ls(Option_t *option="") const
List Directory contents.
Each ROOT class (see TClass) has a linked list of methods.
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
TDirectory()
Directory default constructor.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
if object is referenced by a TRef or TRefArray
static TString LLtoa(Long64_t value, Int_t base)
Converts a Long64_t to a TString with respect to the base specified (2-36).
virtual void ResetMap()=0
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
void RegisterContext(TContext *ctxt)
Register a TContext pointing to this TDirectory object.
virtual const char * GetName() const
Returns name of object.
TMethod * GetMethodWithPrototype(const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Find the method with a given prototype.
virtual void RecursiveRemove(TObject *obj)
Recursively remove object from a Directory.
virtual void CleanTargets()
Clean the pointers to this object (gDirectory, TContext, etc.).
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
A spin mutex-as-code-guard class.
void UnregisterContext(TContext *ctxt)
UnRegister a TContext pointing to this TDirectory object.
static Bool_t fgAddDirectory
MSVC doesn't support = ATOMIC_FLAG_INIT;.
void CdNull()
Set the current directory to null.
const char * Data() const
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...