38 thread_local std::atomic_flag gDirectory_lock = ATOMIC_FLAG_INIT;
39 return &gDirectory_lock;
78 if (!initMotherDir) initMotherDir =
gDirectory;
80 if (strchr(
name,
'/')) {
81 ::Error(
"TDirectory::TDirectory",
"directory name (%s) cannot contain a slash",
name);
86 ::Error(
"TDirectory::TDirectory",
"directory name cannot be \"\"");
106 Fatal(
"~TDirectory",
"In %s:%p the fList (%p) is not using the RWLock\n",
121 Info(
"~TDirectory",
"dtor called for %s",
GetName());
143 fActiveDestructor =
true;
147 (*fDirectory).UnregisterContext(
this);
158 fActiveDestructor =
false;
159 while(fDirectoryWait);
199 if (!obj || !
fList)
return;
204 Warning(
"Append",
"Replacing existing %s: %s (Potential memory leak).",
231 while ((obj = nextin())) {
253 if (motherDir && strlen(
GetName()) != 0) motherDir->
Append(
this);
261 std::vector<TContext*> extraWait;
276 ctxt->fDirectory =
nullptr;
278 if (ctxt->fActiveDestructor) {
281 ctxt->fDirectoryWait =
false;
293 if (ptr->load() ==
this) {
295 if (!next || next ==
this) {
309 ptr->compare_exchange_strong(This, next);
313 for(
auto &&context : extraWait) {
316 while(context->fActiveDestructor);
318 context->fDirectoryWait =
false;
343 void *args[] = { &mode, &
size };
345 creator(
nullptr,2,args,&result);
362 char *pobj = (
char*)obj->IsA()->New();
364 Fatal(
"CloneObject",
"Failed to create new object");
368 Int_t baseOffset = obj->IsA()->GetBaseClassOffset(TObject::Class());
369 if (baseOffset==-1) {
373 Fatal(
"CloneObject",
"Incorrect detection of the inheritance from TObject for class %s.\n",
383 Fatal(
"CloneObject",
"Not able to create a TBuffer!");
387 const_cast<TObject*
>(obj)->Streamer(*buffer);
394 newobj->Streamer(*buffer);
418 thread_local shared_ptr_type currentDirectory =
421 return currentDirectory;
444 Bool_t printError,
const char *funcname)
447 if (apath) nch = strlen(apath);
452 if (funcname==
nullptr || strlen(funcname)==0) funcname =
"GetDirectory";
456 char *path =
new char[nch+1]; path[0] = 0;
457 if (nch) strlcpy(path,apath,nch+1);
458 char *s = (
char*)strrchr(path,
':');
467 if (s && *(s+1)) result =
f->
GetDirectory(s+1,printError,funcname);
468 delete [] path;
return result;
470 if (printError)
Error(funcname,
"No such file %s", path);
471 delete [] path;
return nullptr;
476 if (path[0] ==
'/') {
479 delete [] path;
return result;
483 char *
slash = (
char*)strchr(path,
'/');
485 if (!strcmp(path,
"..")) {
487 delete [] path;
return result;
491 if (printError)
Error(funcname,
"Unknown directory %s", path);
492 delete [] path;
return nullptr;
497 if (printError)
Error(funcname,
"Object %s is not a directory", path);
498 delete [] path;
return nullptr;
504 slash = (
char*)strchr(subdir.
Data(),
'/');
507 if (!strcmp(subdir,
"..")) {
511 delete [] path;
return result;
515 if (printError)
Error(funcname,
"Unknown directory %s", subdir.
Data());
516 delete [] path;
return nullptr;
521 if (printError)
Error(funcname,
"Object %s is not a directory", subdir.
Data());
522 delete [] path;
return nullptr;
525 delete [] path;
return result;
539 thread_local_gdirectory->exchange(
this);
578 if (!apath || !apath[0])
615 if (!apath || !apath[0])
657 if (lnk->
GetObject()->IsA() == TDirectory::Class()) {
710 Info(
"Delete",
"Call for this = %s namecycle = %s",
711 GetName(), (namecycle ? namecycle :
"null"));
719 Int_t deletetree = 0;
720 if(strcmp(
name,
"*") == 0) deleteall = 1;
721 if(strcmp(
name,
"*T") == 0){ deleteall = 1; deletetree = 1;}
722 if(strcmp(
name,
"T*") == 0){ deleteall = 1; deletetree = 1;}
723 if(namecycle==
nullptr || !namecycle[0]){ deleteall = 1; deletetree = 1;}
730 if (cycle >= 9999 ) {
733 while ((idcur = (
TNamed *) next())) {
738 if (idcur->IsA() == TDirectory::Class()) {
740 if (!deletetree && deleteall) deleteOK = 0;
749 idcur->
Delete(deletetree ?
"T*;*" :
"*");
799 while( (obj = next()) ) {
802 TObject *subobj = subdir->TDirectory::FindObjectAny(aname);
869 for (
Int_t i = nch-1; i > 0; i--) {
870 if (
name[i] ==
'/') {
873 namobj =
name + i + 1;
875 return dirToSearch ? dirToSearch->
Get(namobj) :
nullptr;
883 if (idcur==
this && strlen(namobj)!=0) {
888 }
else if (cycle == 9999) {
961 for (
Int_t i = nch-1; i > 0; i--) {
962 if (
name[i] ==
'/') {
965 namobj =
name + i + 1;
977 if (!expectedClass || expectedClass->
IsTObject()) {
980 if (objcur==
this && strlen(namobj)!=0) {
985 }
else if (cycle == 9999) {
987 if (expectedClass && objcur->IsA()->GetBaseClassOffset(expectedClass) == -1)
return nullptr;
1007 static char *path =
nullptr;
1008 const int kMAXDEPTH = 128;
1011 int depth = 0, len = 0;
1014 len = strlen(cur->
GetName()) + 1;
1016 while (cur->
fMother && depth < kMAXDEPTH) {
1019 len += strlen(cur->
GetName()) + 1;
1022 if (path)
delete [] path;
1023 path =
new char[len+2];
1025 for (
int i = depth-1; i >= 0; i--) {
1027 strlcpy(path,
d[i]->
GetName(),len+2);
1028 strlcat(path,
":",len+2);
1029 if (i == 0) strlcat(path,
"/",len+2);
1031 strlcat(path,
"/",len+2);
1032 strlcat(path,
d[i]->
GetName(),len+2);
1099 if (returnExistingDirectory) {
1104 if (!
name || !title || !
name[0])
return nullptr;
1105 if (!title[0]) title =
name;
1106 if (
const char *
slash = strchr(
name,
'/')) {
1108 char *workname =
new char[
size+1];
1114 tmpdir =
mkdir(workname,title);
1116 if (!tmpdir)
return nullptr;
1149 reg = opt(2,opt.
Length());
1153 reg = opt(2,opt.
Length());
1154 }
else if (!opt.
IsNull())
1162 while ((obj = (
TObject *) nextobj())) {
1223 if ((
name==
nullptr) || (*
name==0))
return;
1247 if (!filename || !filename[0]) {
1251 if (fname.
Index(
".json") > 0) {
1253 nbytes =
gROOT->ProcessLine(cmd);
1255 cmd.
Form(
"TFile::Open(\"%s\",\"recreate\");",fname.
Data());
1258 if (!local)
return 0;
1259 nbytes = obj->
Write();
1290 strcpy(buffer,
name);
1292 sprintf(buffer,
"%s;%d",
name, cycle);
1305 const size_t namesize)
1308 ::Warning(
"TDirectory::DecodeNameCycle",
1309 "An empty buffer was passed, cannot decode.");
1315 const char *ni = strchr(buffer,
';');
1323 len = strlen(buffer);
1328 if (len > namesize-1ul) len = namesize-1;
1330 ::Warning(
"TDirectory::DecodeNameCycle",
1331 "Using unsafe version: invoke this method by specifying the buffer size");
1334 strncpy(
name, buffer, len);
1339 else if (isdigit(*ni)) {
1340 long parsed = strtol(ni,
nullptr,10);
1341 if (parsed >= (
long) std::numeric_limits<Short_t>::max())
1359 if (!current || !current->
IsBuilt())
1377 while(current->
fNext) {
1378 current = current->
fNext;
1380 current->
fNext = ctxt;
1407 const char *objname =
"no name specified";
1409 else if (obj) objname = obj->
GetName();
1410 Error(
"WriteTObject",
"The current directory (%s) is not associated with a file. The object (%s) has not been written.",
GetName(),objname);
1439void TDirectory::Streamer(
TBuffer &R__b)
1446 TNamed::Streamer(R__b);
1450 fUUID.Streamer(R__b);
1454 TNamed::Streamer(R__b);
1457 fUUID.Streamer(R__b);
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
void(* tcling_callfunc_Wrapper_t)(void *, int, void **, void *)
static std::atomic_flag * GetCurrentDirectoryLock()
static TBuffer * R__CreateBuffer()
Fast execution of 'new TBufferFile(TBuffer::kWrite,10000), without having a compile time circular dep...
R__EXTERN TVirtualMutex * gROOTMutex
void Printf(const char *fmt,...)
R__EXTERN TSystem * gSystem
#define R__LOCKGUARD(mutex)
A spin mutex-as-code-guard class.
Using a TBrowser one can browse all ROOT objects.
Buffer base class used for serializing objects.
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual void ResetMap()=0
void SetBufferOffset(Int_t offset=0)
void SetReadMode()
Set buffer in read mode.
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
virtual void MapObject(const TObject *obj, UInt_t offset=1)=0
TClass instances represent classes, structs and namespaces in the ROOT type system.
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
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 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.
std::atomic< bool > fDirectoryWait
Set to true during the destructor execution.
void RegisterCurrentDirectory()
void CdNull()
Set the current directory to null.
TContext * fPrevious
Set to true if a TDirectory might still access this object.
TContext * fNext
Pointer to the next TContext in the implied list of context pointing to fPrevious.
std::atomic< TDirectory * > fDirectory
Describe directory structure in memory.
std::shared_ptr< std::atomic< TDirectory * > > SharedGDirectory_t
Pointer to a list of TContext object pointing to this TDirectory.
Bool_t cd1(const char *path)
flag to add histograms, graphs,etc to the directory
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 TList * GetList() const
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual const char * GetPath() const
Returns the full path of the directory.
std::atomic_flag fSpinLock
Counter delaying the TDirectory destructor from finishing.
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.
virtual void DeleteAll(Option_t *option="")
Delete all objects from memory.
std::atomic< size_t > fContextPeg
thread local gDirectory pointing to this object.
std::vector< SharedGDirectory_t > fGDirectories
virtual void rmdir(const char *name)
Removes subdirectory from the directory When directory is deleted, all keys in all subdirectories wil...
static Bool_t AddDirectoryStatus()
Static function: see TDirectory::AddDirectory for more comments.
void FillFullPath(TString &buf) const
Recursive method to fill full path for directory.
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add objects like histograms, TGraph2D, etc in memory.
void CleanTargets()
Clean the pointers to this object (gDirectory, TContext, etc.).
void ls(Option_t *option="") const override
List Directory contents.
TContext * fContext
Buffer for GetPath() function.
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 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 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)
virtual TFile * GetFile() const
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 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 0 or "", a file with "objectname.root" is created.
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...
static Bool_t fgAddDirectory
MSVC doesn't support = ATOMIC_FLAG_INIT;.
TDirectory * GetMotherDir() const
static void EncodeNameCycle(char *buffer, const char *name, Short_t cycle)
Encode the name and cycle into buffer like: "aap;2".
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.
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.
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.
virtual TObject * Remove(TObject *)
Remove an object from the in-memory list.
void RegisterContext(TContext *ctxt)
Register a TContext pointing to this TDirectory object.
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 a suite of consecutive data records (TKey instances) with a well defined format.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
virtual void Add(TObject *obj)
virtual TObject * Remove(TObject *obj)
Remove object from the list.
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
virtual TObjLink * FirstLink() const
virtual void RecursiveRemove(TObject *obj)
Remove object from this collection and recursively remove the object from all other objects (and coll...
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Each ROOT class (see TClass) has a linked list of methods.
The TNamed class is the base class for all named ROOT classes.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual const char * GetName() const
Returns name of object.
Wrapper around a TObject so it can be stored in a TList.
TObject * GetObject() const
Mother of all ROOT objects.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
virtual const char * GetName() const
Returns name of object.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Delete(Option_t *option="")
Delete this object.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
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.
@ kCanDelete
if object in a list can be deleted
@ kIsReferenced
if object is referenced by a TRef or TRefArray
@ kMustCleanup
if object destructor must call RecursiveRemove()
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Regular expression class.
static TString LLtoa(Long64_t value, Int_t base)
Converts a Long64_t to a TString with respect to the base specified (2-36).
void ToLower()
Change string to lower-case.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
const char * Data() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Append(const char *cs)
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
R__EXTERN TROOT * gROOTLocal
void(* DirAutoAdd_t)(void *, TDirectory *)