62 :
TNamed(name, title), fMother(0), fList(0),fContext(0)
64 if (initMotherDir==0) initMotherDir =
gDirectory;
66 if (strchr(name,
'/')) {
67 ::Error(
"TDirectory::TDirectory",
"directory name (%s) cannot contain a slash", name);
72 ::Error(
"TDirectory::TDirectory",
"directory name cannot be \"\"");
77 Build(initMotherDir ? initMotherDir->
GetFile() : 0, initMotherDir);
87 directory.
Copy(*
this);
114 Info(
"~TDirectory",
"dtor called for %s",
GetName());
155 if (obj == 0 ||
fList == 0)
return;
160 Warning(
"Append",
"Replacing existing %s: %s (Potential memory leak).",
187 while ((obj = nextin())) {
202 if (motherDir && strlen(
GetName()) != 0) motherDir->
Append(
this);
221 if (cursav && cursav !=
this) {
240 typedef void (*tcling_callfunc_Wrapper_t)(
void*, int,
void**,
void*);
241 static tcling_callfunc_Wrapper_t creator = 0;
250 void *args[] = { &mode, &size };
252 creator(0,2,args,&result);
269 char *pobj = (
char*)obj->IsA()->New();
271 Fatal(
"CloneObject",
"Failed to create new object");
276 if (baseOffset==-1) {
280 Fatal(
"CloneObject",
"Incorrect detection of the inheritance from TObject for class %s.\n",
290 Fatal(
"CloneObject",
"Not able to create a TBuffer!");
294 const_cast<TObject*
>(obj)->Streamer(*buffer);
301 newobj->Streamer(*buffer);
322 return currentDirectory;
339 Bool_t printError,
const char *funcname)
342 if (apath) nch = strlen(apath);
347 if (funcname==0 || strlen(funcname)==0) funcname =
"GetDirectory";
351 char *path =
new char[nch+1]; path[0] = 0;
352 if (nch) strlcpy(path,apath,nch+1);
353 char *s = (
char*)strrchr(path,
':');
358 if (!f && !strcmp(
gROOT->GetName(), path)) f =
gROOT;
362 if (s && *(s+1)) result = f->
GetDirectory(s+1,printError,funcname);
363 delete [] path;
return result;
365 if (printError)
Error(funcname,
"No such file %s", path);
366 delete [] path;
return 0;
371 if (path[0] ==
'/') {
374 delete [] path;
return result;
378 char *
slash = (
char*)strchr(path,
'/');
380 if (!strcmp(path,
"..")) {
382 delete [] path;
return result;
386 if (printError)
Error(funcname,
"Unknown directory %s", path);
387 delete [] path;
return 0;
392 if (printError)
Error(funcname,
"Object %s is not a directory", path);
393 delete [] path;
return 0;
399 slash = (
char*)strchr(subdir.
Data(),
'/');
402 if (!strcmp(subdir,
"..")) {
405 result = mom->
GetDirectory(slash+1,printError,funcname);
406 delete [] path;
return result;
410 if (printError)
Error(funcname,
"Unknown directory %s", subdir.
Data());
411 delete [] path;
return 0;
416 if (printError)
Error(funcname,
"Object %s is not a directory", subdir.
Data());
417 delete [] path;
return 0;
420 delete [] path;
return result;
456 if (apath) nch = strlen(apath);
496 if (apath) nch = strlen(apath);
497 if (!nch)
return kTRUE;
578 Info(
"Delete",
"Call for this = %s namecycle = %s",
579 GetName(), (namecycle ? namecycle :
"null"));
587 Int_t deletetree = 0;
588 if(strcmp(name,
"*") == 0) deleteall = 1;
589 if(strcmp(name,
"*T") == 0){ deleteall = 1; deletetree = 1;}
590 if(strcmp(name,
"T*") == 0){ deleteall = 1; deletetree = 1;}
591 if(namecycle==0 || !namecycle[0]){ deleteall = 1; deletetree = 1;}
598 if (cycle >= 9999 ) {
601 while ((idcur = (
TNamed *) next())) {
608 if (!deletetree && deleteall) deleteOK = 0;
617 idcur->
Delete(deletetree ?
"T*;*" :
"*");
667 while( (obj = next()) ) {
670 TObject *subobj = subdir->TDirectory::FindObjectAny(aname);
736 Int_t nch = strlen(name);
737 for (
Int_t i = nch-1; i > 0; i--) {
738 if (name[i] ==
'/') {
741 namobj = name + i + 1;
743 return dirToSearch?dirToSearch->
Get(namobj):0;
751 if (idcur==
this && strlen(namobj)!=0) {
756 }
else if (cycle == 9999) {
828 Int_t nch = strlen(name);
829 for (
Int_t i = nch-1; i > 0; i--) {
830 if (name[i] ==
'/') {
833 namobj = name + i + 1;
845 if (expectedClass==0 || expectedClass->
IsTObject()) {
848 if (objcur==
this && strlen(namobj)!=0) {
853 }
else if (cycle == 9999) {
855 if (expectedClass && objcur->IsA()->GetBaseClassOffset(expectedClass) == -1)
return 0;
875 static char *path = 0;
876 const int kMAXDEPTH = 128;
879 int depth = 0, len = 0;
882 len = strlen(cur->
GetName()) + 1;
884 while (cur->
fMother && depth < kMAXDEPTH) {
887 len += strlen(cur->
GetName()) + 1;
890 if (path)
delete [] path;
891 path =
new char[len+2];
893 for (
int i = depth-1; i >= 0; i--) {
895 strlcpy(path, d[i]->
GetName(),len+2);
896 strlcat(path,
":",len+2);
897 if (i == 0) strlcat(path,
"/",len+2);
899 strlcat(path,
"/",len+2);
900 strlcat(path, d[i]->
GetName(),len+2);
960 if (!name || !title || !name[0])
return 0;
961 if (!title[0]) title =
name;
963 if (
const char *
slash = strchr(name,
'/')) {
965 char *workname =
new char[size+1];
966 strncpy(workname, name, size);
971 tmpdir =
mkdir(workname,title);
972 if (!tmpdir)
return 0;
975 if (!tmpdir)
return 0;
976 if (!newdir) newdir = tmpdir;
983 newdir =
new TDirectory(name, title,
"",
this);
1012 reg = opt(2,opt.
Length());
1016 reg = opt(2,opt.
Length());
1017 }
else if (!opt.
IsNull())
1025 while ((obj = (
TObject *) nextobj())) {
1086 if ((name==0) || (*name==0))
return;
1110 if (!filename || !filename[0]) {
1114 if (fname.
Index(
".json") > 0) {
1116 nbytes =
gROOT->ProcessLine(cmd);
1118 cmd.
Form(
"TFile::Open(\"%s\",\"recreate\");",fname.
Data());
1121 if (!local)
return 0;
1122 nbytes = obj->
Write();
1152 strcpy(buffer, name);
1154 sprintf(buffer,
"%s;%d", name, cycle);
1163 const size_t namesize)
1166 const char *ni = strchr(buffer,
';');
1174 len = strlen(buffer);
1179 if (len > namesize-1ul) len = namesize-1;
1181 ::Warning(
"TDirectory::DecodeNameCycle",
1182 "Using unsafe version: invoke this metod by specifying the buffer size");
1185 strncpy(name, buffer, len);
1190 else if (isdigit(*ni)) {
1191 long parsed = strtol(ni,
nullptr,10);
1192 if (parsed >= (
long) std::numeric_limits<Short_t>::max())
1207 while(current->
fNext) {
1208 current = current->
fNext;
1210 current->
fNext = ctxt;
1222 const char *objname =
"no name specified";
1223 if (name) objname =
name;
1224 else if (obj) objname = obj->
GetName();
1225 Error(
"WriteTObject",
"The current directory (%s) is not associated with a file. The object (%s) has not been written.",
GetName(),objname);
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.
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.
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.
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
Pointer to the previous current directory.
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
Find an object in this list using its name.
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
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 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
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 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.
#define R__LOCKGUARD2(mutex)
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.
double func(double *x, double *p)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
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.
void UnregisterContext(TContext *ctxt)
UnRegister a TContext pointing to this TDirectory object.
static Bool_t fgAddDirectory
Pointer to a list of TContext object pointing to this TDirectory.
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...