15 #include "TDirectory.h"
60 :
TNamed(name, title), fMother(0), fList(0),fContext(0)
62 if (initMotherDir==0) initMotherDir =
gDirectory;
64 if (strchr(name,
'/')) {
65 ::Error(
"TDirectory::TDirectory",
"directory name (%s) cannot contain a slash", name);
70 ::Error(
"TDirectory::TDirectory",
"directory name cannot be \"\"");
75 Build(initMotherDir ? initMotherDir->
GetFile() : 0, initMotherDir);
85 directory.
Copy(*
this);
112 Info(
"~TDirectory",
"dtor called for %s",
GetName());
153 if (obj == 0 ||
fList == 0)
return;
158 Warning(
"Append",
"Replacing existing %s: %s (Potential memory leak).",
185 while ((obj = nextin())) {
200 if (motherDir && strlen(
GetName()) != 0) motherDir->
Append(
this);
219 if (cursav && cursav !=
this) {
248 void *args[] = { &mode, &size };
250 creator(0,2,args,&result);
267 char *pobj = (
char*)obj->IsA()->New();
269 Fatal(
"CloneObject",
"Failed to create new object");
274 if (baseOffset==-1) {
278 Fatal(
"CloneObject",
"Incorrect detection of the inheritance from TObject for class %s.\n",
288 Fatal(
"CloneObject",
"Not able to create a TBuffer!");
299 newobj->Streamer(*buffer);
320 return currentDirectory;
337 Bool_t printError,
const char *funcname)
340 if (apath) nch = strlen(apath);
345 if (funcname==0 || strlen(funcname)==0) funcname =
"GetDirectory";
349 char *path =
new char[nch+1]; path[0] = 0;
350 if (nch) strlcpy(path,apath,nch+1);
351 char *s = (
char*)strrchr(path,
':');
356 if (!f && !strcmp(
gROOT->GetName(), path)) f =
gROOT;
360 if (s && *(s+1)) result = f->
GetDirectory(s+1,printError,funcname);
361 delete [] path;
return result;
363 if (printError)
Error(funcname,
"No such file %s", path);
364 delete [] path;
return 0;
369 if (path[0] ==
'/') {
372 delete [] path;
return result;
376 char *
slash = (
char*)strchr(path,
'/');
378 if (!strcmp(path,
"..")) {
380 delete [] path;
return result;
384 if (printError)
Error(funcname,
"Unknown directory %s", path);
385 delete [] path;
return 0;
390 if (printError)
Error(funcname,
"Object %s is not a directory", path);
391 delete [] path;
return 0;
397 slash = (
char*)strchr(subdir.
Data(),
'/');
400 if (!strcmp(subdir,
"..")) {
403 result = mom->
GetDirectory(slash+1,printError,funcname);
404 delete [] path;
return result;
408 if (printError)
Error(funcname,
"Unknown directory %s", subdir.
Data());
409 delete [] path;
return 0;
414 if (printError)
Error(funcname,
"Object %s is not a directory", subdir.
Data());
415 delete [] path;
return 0;
418 delete [] path;
return result;
454 if (apath) nch = strlen(apath);
494 if (apath) nch = strlen(apath);
495 if (!nch)
return kTRUE;
576 Info(
"Delete",
"Call for this = %s namecycle = %s",
577 GetName(), (namecycle ? namecycle :
"null"));
585 Int_t deletetree = 0;
586 if(strcmp(name,
"*") == 0) deleteall = 1;
587 if(strcmp(name,
"*T") == 0){ deleteall = 1; deletetree = 1;}
588 if(strcmp(name,
"T*") == 0){ deleteall = 1; deletetree = 1;}
589 if(namecycle==0 || !namecycle[0]){ deleteall = 1; deletetree = 1;}
596 if (cycle >= 9999 ) {
606 if (!deletetree && deleteall) deleteOK = 0;
615 idcur->
Delete(deletetree ?
"T*;*" :
"*");
665 while( (obj =
next()) ) {
668 TObject *subobj = subdir->TDirectory::FindObjectAny(aname);
734 Int_t nch = strlen(name);
735 for (
Int_t i = nch-1; i > 0; i--) {
736 if (name[i] ==
'/') {
739 namobj = name + i + 1;
741 return dirToSearch?dirToSearch->
Get(namobj):0;
749 if (idcur==
this && strlen(namobj)!=0) {
754 }
else if (cycle == 9999) {
826 Int_t nch = strlen(name);
827 for (
Int_t i = nch-1; i > 0; i--) {
828 if (name[i] ==
'/') {
831 namobj = name + i + 1;
843 if (expectedClass==0 || expectedClass->
IsTObject()) {
846 if (objcur==
this && strlen(namobj)!=0) {
851 }
else if (cycle == 9999) {
853 if (expectedClass && objcur->IsA()->GetBaseClassOffset(expectedClass) == -1)
return 0;
873 static char *path = 0;
874 const int kMAXDEPTH = 128;
877 int depth = 0, len = 0;
880 len = strlen(cur->
GetName()) + 1;
882 while (cur->
fMother && depth < kMAXDEPTH) {
885 len += strlen(cur->
GetName()) + 1;
888 if (path)
delete [] path;
889 path =
new char[len+2];
891 for (
int i = depth-1; i >= 0; i--) {
893 strlcpy(path, d[i]->
GetName(),len+2);
894 strlcat(path,
":",len+2);
895 if (i == 0) strlcat(path,
"/",len+2);
897 strlcat(path,
"/",len+2);
898 strlcat(path, d[i]->
GetName(),len+2);
957 if (!name || !title || !name[0])
return 0;
958 if (!title[0]) title =
name;
960 if (
const char *
slash = strchr(name,
'/')) {
962 char *workname =
new char[size+1];
963 strncpy(workname, name, size);
968 tmpdir =
mkdir(workname,title);
969 if (!tmpdir)
return 0;
972 if (!tmpdir)
return 0;
973 if (!newdir) newdir = tmpdir;
980 newdir =
new TDirectory(name, title,
"",
this);
1009 reg = opt(2,opt.
Length());
1013 reg = opt(2,opt.
Length());
1014 }
else if (!opt.
IsNull())
1022 while ((obj = (
TObject *) nextobj())) {
1083 if ((name==0) || (*name==0))
return;
1103 if (!filename || !filename[0]) {
1107 cmd.
Form(
"TFile::Open(\"%s\",\"recreate\");",fname.
Data());
1111 if (!local)
return 0;
1112 nbytes = obj->
Write();
1142 strcpy(buffer, name);
1144 sprintf(buffer,
"%s;%d", name, cycle);
1153 const size_t namesize)
1156 const char *ni = strchr(buffer,
';');
1164 len = strlen(buffer);
1169 if (len > namesize-1ul) len = namesize-1;
1171 ::Warning(
"TDirectory::DecodeNameCycle",
1172 "Using unsafe version: invoke this metod by specifying the buffer size");
1175 strncpy(name, buffer, len);
1180 else if (isdigit(*ni)) {
1181 long parsed = strtol(ni,
nullptr,10);
1197 while(current->
fNext) {
1198 current = current->
fNext;
1200 current->
fNext = ctxt;
1212 const char *objname =
"no name specified";
1213 if (name) objname =
name;
1214 else if (obj) objname = obj->
GetName();
1215 Error(
"WriteTObject",
"The current directory (%s) is not associated with a file. The object (%s) has not been written.",
GetName(),objname);
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
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 ~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 Build(TFile *motherFile=0, TDirectory *motherDir=0)
Initialise directory to defaults.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
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...
void GetObject(const char *namecycle, T *&ptr)
virtual TObject * CloneObject(const TObject *obj, Bool_t autoadd=kTRUE)
Clone an object.
virtual void SetName(const char *name)
Change (i.e.
virtual TList * GetList() const
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
void * InterfaceMethod() const
Return pointer to the interface method.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Buffer base class used for serializing objects.
Regular expression class.
static const char * filename()
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 and return a pointer to the created directory.
R__EXTERN TVirtualMutex * gROOTMutex
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
TContext * fPrevious
Pointer to the previous current directory.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
virtual const char * GetPath() const
Returns the full path of the directory.
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 void Print(Option_t *option="") const
Print all objects in the directory.
virtual void * GetObjectChecked(const char *namecycle, const char *classname)
See documentation of TDirectory::GetObjectCheck(const char *namecycle, const TClass *cl) ...
virtual void ls(Option_t *option="") const
List Directory contents.
const char * Data() const
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
virtual void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
The TNamed class is the base class for all named ROOT classes.
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
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 void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Delete(const char *namecycle="")
Delete Objects or/and keys in a directory.
virtual TFile * GetFile() const
virtual const char * GetPathStatic() const
Returns the full path of the 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.
TObject * GetObject() 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.
static Bool_t Cd1(const char *path)
Change current directory to "path".
virtual Int_t SaveObjectAs(const TObject *, const char *="", Option_t *="") const
Save object in filename, if filename is 0 or "", a file with "objectname.root" is created...
virtual void Append(TObject *obj, Bool_t replace=kFALSE)
Append object to this directory.
void FillFullPath(TString &buf) const
Recursive method to fill full path for directory.
void SetReadMode()
Set buffer in read mode.
virtual const char * GetName() const
Returns name of object.
TSubString Strip(EStripType s=kTrailing, char c= ' ') const
Return a substring of self stripped at beginning and/or end.
The ROOT global object gROOT contains a list of all defined classes.
void(* DirAutoAdd_t)(void *, TDirectory *)
virtual TObjLink * FirstLink() const
ClassImp(TDirectory) TDirectory
Directory default constructor.
virtual void Clear(Option_t *option="")
Delete all objects from a Directory list.
virtual TObject * FindObject(const char *name) const
Find object by name in the list of memory objects.
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".
virtual const char * GetName() const
Returns name of object.
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.
virtual void Copy(TObject &) const
Copy this to obj.
static Bool_t AddDirectoryStatus()
Static function: see TDirectory::AddDirectory for more comments.
double func(double *x, double *p)
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.
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
virtual TDirectory * GetMotherDir() const
Mother of all ROOT objects.
void(* tcling_callfunc_Wrapper_t)(void *, int, void **, void *)
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
typedef void((*Func_t)())
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)
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.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
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.
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
virtual void ResetMap()=0
void RegisterContext(TContext *ctxt)
Register a TContext pointing to this TDirectory object.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
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 pwd() const
Print the path of the directory.
virtual void CleanTargets()
Clean the pointers to this object (gDirectory, TContext, etc.).
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.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.