Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TDirectoryFile Class Reference

A ROOT file is structured in Directories (like a file system).

Each Directory has a list of Keys (see TKeys) and a list of objects in memory. A Key is a small object that describes the type and location of a persistent object in a file. The persistent object may be a directory.

The structure of a file is shown in TFile::TFile

PyROOT

In the same way as for TDirectory, it is possible to inspect the content of a TDirectoryFile object from Python as if the subdirectories and objects it contains were its attributes. For more information, please refer to the TDirectory documentation.

In addition to the attribute syntax, one can inspect a TDirectoryFile in Python via the Get method. In this case, the subdirectory/object name is specified as a string:

# Access a subdirectory
d.Get('subdir')
# We can go further down in the hierarchy of directories
d.Get('subdir/subsubdir')
# Access an object (e.g. a histogram) in the directory
d.Get('obj')
# ... or in a subdirectory
d.Get('subdir/obj')
# Wrong attribute: returns null
x = d.Get('wrongAttr') # x points to null

Furthermore, TDirectoryFile inherits a WriteObject Python method from TDirectory. Such method allows to write an object into a TDirectoryFile with the following syntax:

# Write object obj with identifier 'keyName'
d.WriteObject(obj, 'keyName')

Definition at line 32 of file TDirectoryFile.h.

Public Types

enum  EStatusBits { kCloseDirectory = (1ULL << ( 7 )) }
 
- Public Types inherited from TObject
enum  {
  kIsOnHeap = 0x01000000 , kNotDeleted = 0x02000000 , kZombie = 0x04000000 , kInconsistent = 0x08000000 ,
  kBitMask = 0x00ffffff
}
 
enum  { kSingleKey = (1ULL << ( 0 )) , kOverwrite = (1ULL << ( 1 )) , kWriteDelete = (1ULL << ( 2 )) }
 
enum  EDeprecatedStatusBits { kObjInCanvas = (1ULL << ( 3 )) }
 
enum  EStatusBits {
  kCanDelete = (1ULL << ( 0 )) , kMustCleanup = (1ULL << ( 3 )) , kIsReferenced = (1ULL << ( 4 )) , kHasUUID = (1ULL << ( 5 )) ,
  kCannotPick = (1ULL << ( 6 )) , kNoContextMenu = (1ULL << ( 8 )) , kInvalidObject = (1ULL << ( 13 ))
}
 

Public Member Functions

 TDirectoryFile ()
 Default TDirectoryFile constructor.
 
 TDirectoryFile (const char *name, const char *title, Option_t *option="", TDirectory *motherDir=nullptr)
 Create a new TDirectoryFile.
 
 ~TDirectoryFile () override
 Destructor.
 
void Add (TObject *obj, Bool_t replace=kFALSE) override
 
void Append (TObject *obj, Bool_t replace=kFALSE) override
 Append object to this directory.
 
Int_t AppendKey (TKey *key) override
 Insert key in the linked list of keys of this directory.
 
void Browse (TBrowser *b) override
 Browse the content of the directory.
 
void Build (TFile *motherFile=nullptr, TDirectory *motherDir=nullptr) override
 
Bool_t cd () override
 Change current directory to "this" directory.
 
Bool_t cd (const char *path) override
 Change current directory the directory described by the path if given one.
 
TObjectCloneObject (const TObject *obj, Bool_t autoadd=kTRUE) override
 Make a clone of an object using the Streamer facility.
 
void Close (Option_t *option="") override
 Delete all objects from memory and directory structure itself.
 
void Copy (TObject &) const override
 Copy this to obj.
 
void Delete (const char *namecycle="") override
 Delete Objects or/and keys in a directory.
 
void FillBuffer (char *&buffer) override
 Encode directory header into output buffer.
 
TKeyFindKey (const char *keyname) const override
 Find key with name keyname in the current directory.
 
TKeyFindKeyAny (const char *keyname) const override
 Find key with name keyname in the current directory or its subdirectories.
 
TObjectFindObjectAny (const char *name) const override
 Find object by name in the list of memory objects of the current directory or its sub-directories.
 
TObjectFindObjectAnyFile (const char *name) const override
 Scan the memory lists of all files for an object with name.
 
template<class T >
T * Get (const char *namecycle)
 See documentation of TDirectoryFile::Get(const char *namecycle)
 
TObjectGet (const char *namecycle) override
 Return pointer to object identified by namecycle.
 
Int_t GetBufferSize () const override
 Return the buffer size to create new TKeys.
 
const TDatimeGetCreationDate () const
 
TDirectoryGetDirectory (const char *apath, Bool_t printError=false, const char *funcname="GetDirectory") override
 Find a directory named "apath".
 
TFileGetFile () const override
 
TKeyGetKey (const char *name, Short_t cycle=9999) const override
 Return pointer to key with name,cycle.
 
TListGetListOfKeys () const override
 
const TDatimeGetModificationDate () const
 
Int_t GetNbytesKeys () const override
 
Int_t GetNkeys () const override
 
void * GetObjectChecked (const char *namecycle, const char *classname) override
 See documentation of TDirectoryFile::GetObjectCheck(const char *namecycle, const TClass *cl)
 
void * GetObjectChecked (const char *namecycle, const TClass *cl) override
 Return pointer to object identified by namecycle if and only if the actual object is a type suitable to be stored as a pointer to a "expectedClass" If expectedClass is null, no check is performed.
 
void * GetObjectUnchecked (const char *namecycle) override
 Return pointer to object identified by namecycle.
 
Long64_t GetSeekDir () const override
 
Long64_t GetSeekKeys () const override
 
Long64_t GetSeekParent () const override
 
TClassIsA () const override
 
Bool_t IsModified () const override
 
Bool_t IsWritable () const override
 
void ls (Option_t *option="") const override
 List Directory contents.
 
TDirectorymkdir (const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE) override
 Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
 
TFileOpenFile (const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0) override
 Interface to TFile::Open.
 
void Purge (Short_t nkeep=1) override
 Purge lowest key cycles in a directory.
 
void ReadAll (Option_t *option="") override
 Read objects from a ROOT file directory into memory.
 
Int_t ReadKeys (Bool_t forceRead=kTRUE) override
 Read the linked list of keys.
 
Int_t ReadTObject (TObject *obj, const char *keyname) override
 Read object with keyname from the current directory.
 
virtual void ResetAfterMerge (TFileMergeInfo *)
 Reset the TDirectory after its content has been merged into another Directory.
 
void rmdir (const char *name) override
 Removes subdirectory from the directory.
 
void Save () override
 Save recursively all directory keys and headers.
 
Int_t SaveObjectAs (const TObject *obj, const char *filename="", Option_t *option="") const override
 Save object in filename.
 
void SaveSelf (Bool_t force=kFALSE) override
 Save Directory keys and header.
 
void SetBufferSize (Int_t bufsize) override
 Set the default buffer size when creating new TKeys.
 
void SetModified () override
 
void SetSeekDir (Long64_t v) override
 
void SetTRefAction (TObject *ref, TObject *parent) override
 Find the action to be executed in the dictionary of the parent class and store the corresponding exec number into fBits.
 
void SetWritable (Bool_t writable=kTRUE) override
 Set the new value of fWritable recursively.
 
Int_t Sizeof () const override
 Return the size in bytes of the directory header.
 
void Streamer (TBuffer &) override
 Stream a class object.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
Int_t Write (const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) const override
 One can not save a const TDirectory object.
 
Int_t Write (const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) override
 Write all objects in memory to disk.
 
void WriteDirHeader () override
 Overwrite the Directory header record.
 
void WriteKeys () override
 Write Keys linked list on the file.
 
Int_t WriteObjectAny (const void *obj, const char *classname, const char *name, Option_t *option="", Int_t bufsize=0) override
 Write object from pointer of class classname in this directory.
 
Int_t WriteObjectAny (const void *obj, const TClass *cl, const char *name, Option_t *option="", Int_t bufsize=0) override
 Write object of class with dictionary cl in this directory.
 
Int_t WriteTObject (const TObject *obj, const char *name=nullptr, Option_t *option="", Int_t bufsize=0) override
 Write object obj to this directory.
 
- Public Member Functions inherited from TDirectory
 TDirectory ()
 Directory default constructor.
 
 TDirectory (const char *name, const char *title, Option_t *option="", TDirectory *motherDir=nullptr)
 Create a new Directory.
 
virtual ~TDirectory ()
 Destructor.
 
void Clear (Option_t *option="") override
 Delete all objects from a Directory list.
 
virtual void DeleteAll (Option_t *option="")
 Delete all objects from memory.
 
void Draw (Option_t *option="") override
 Fill Graphics Structure and Paint.
 
TObjectFindObject (const char *name) const override
 Find object by name in the list of memory objects.
 
TObjectFindObject (const TObject *obj) const override
 Find object in the list of memory objects.
 
template<class T >
T * Get (const char *namecycle)
 See documentation of TDirectoryFile::Get(const char *namecycle)
 
virtual TListGetList () const
 
TObjectGetMother () const
 
TDirectoryGetMotherDir () const
 
template<class T >
void GetObject (const char *namecycle, T *&ptr)
 Get an object with proper type checking.
 
virtual const char * GetPath () const
 Returns the full path of the directory.
 
virtual const char * GetPathStatic () const
 Returns the full path of the directory.
 
TUUID GetUUID () const
 
Bool_t IsBuilt () const
 
Bool_t IsFolder () const override
 Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
 
void Paint (Option_t *option="") override
 Paint all objects in the directory.
 
void Print (Option_t *option="") const override
 Print all objects in the directory.
 
virtual void pwd () const
 Print the path of the directory.
 
void RecursiveRemove (TObject *obj) override
 Recursively remove object from a Directory.
 
virtual TObjectRemove (TObject *)
 Remove an object from the in-memory list.
 
virtual void SetMother (TObject *mother)
 
void SetName (const char *newname) override
 Set the name for directory If the directory name is changed after the directory was written once, ROOT currently would NOT change the name of correspondent key in the mother directory.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
template<typename T >
std::enable_if_t<!std::is_base_of< TObject, T >::value, Int_tWriteObject (const T *obj, const char *name, Option_t *option="", Int_t bufsize=0)
 Write an object with proper type checking.
 
template<typename T >
std::enable_if_t< std::is_base_of< TObject, T >::value, Int_tWriteObject (const T *obj, const char *name, Option_t *option="", Int_t bufsize=0)
 Write an object with proper type checking.
 
- Public Member Functions inherited from TNamed
 TNamed ()
 
 TNamed (const char *name, const char *title)
 
 TNamed (const TNamed &named)
 TNamed copy ctor.
 
 TNamed (const TString &name, const TString &title)
 
virtual ~TNamed ()
 TNamed destructor.
 
void Clear (Option_t *option="") override
 Set name and title to empty strings ("").
 
TObjectClone (const char *newname="") const override
 Make a clone of an object using the Streamer facility.
 
Int_t Compare (const TObject *obj) const override
 Compare two TNamed objects.
 
void Copy (TObject &named) const override
 Copy this to obj.
 
const char * GetName () const override
 Returns name of object.
 
const char * GetTitle () const override
 Returns title of object.
 
ULong_t Hash () const override
 Return hash value for this object.
 
TClassIsA () const override
 
Bool_t IsSortable () const override
 
void ls (Option_t *option="") const override
 List TNamed name and title.
 
TNamedoperator= (const TNamed &rhs)
 TNamed assignment operator.
 
void Print (Option_t *option="") const override
 Print TNamed name and title.
 
virtual void SetNameTitle (const char *name, const char *title)
 Set all the TNamed parameters (name and title).
 
virtual void SetTitle (const char *title="")
 Set the title of the TNamed.
 
void Streamer (TBuffer &) override
 Stream an object of class TObject.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
- Public Member Functions inherited from TObject
 TObject ()
 TObject constructor.
 
 TObject (const TObject &object)
 TObject copy ctor.
 
virtual ~TObject ()
 TObject destructor.
 
void AbstractMethod (const char *method) const
 Use this method to implement an "abstract" method that you don't want to leave purely abstract.
 
virtual void AppendPad (Option_t *option="")
 Append graphics object to current pad.
 
ULong_t CheckedHash ()
 Check and record whether this class has a consistent Hash/RecursiveRemove setup (*) and then return the regular Hash value for this object.
 
virtual const char * ClassName () const
 Returns name of class to which the object belongs.
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 Computes distance from point (px,py) to the object.
 
virtual void DrawClass () const
 Draw class inheritance tree of the class to which this object belongs.
 
virtual TObjectDrawClone (Option_t *option="") const
 Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1).
 
virtual void Dump () const
 Dump contents of object on stdout.
 
virtual void Error (const char *method, const char *msgfmt,...) const
 Issue error message.
 
virtual void Execute (const char *method, const char *params, Int_t *error=nullptr)
 Execute method on this object with the given parameter string, e.g.
 
virtual void Execute (TMethod *method, TObjArray *params, Int_t *error=nullptr)
 Execute method on this object with parameters stored in the TObjArray.
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 Execute action corresponding to an event at (px,py).
 
virtual void Fatal (const char *method, const char *msgfmt,...) const
 Issue fatal error message.
 
virtual Option_tGetDrawOption () const
 Get option used by the graphics system to draw this object.
 
virtual const char * GetIconName () const
 Returns mime type name of object.
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 Returns string containing info about the object at position (px,py).
 
virtual Option_tGetOption () const
 
virtual UInt_t GetUniqueID () const
 Return the unique object id.
 
virtual Bool_t HandleTimer (TTimer *timer)
 Execute action in response of a timer timing out.
 
Bool_t HasInconsistentHash () const
 Return true is the type of this object is known to have an inconsistent setup for Hash and RecursiveRemove (i.e.
 
virtual void Info (const char *method, const char *msgfmt,...) const
 Issue info message.
 
virtual Bool_t InheritsFrom (const char *classname) const
 Returns kTRUE if object inherits from class "classname".
 
virtual Bool_t InheritsFrom (const TClass *cl) const
 Returns kTRUE if object inherits from TClass cl.
 
virtual void Inspect () const
 Dump contents of this object in a graphics canvas.
 
void InvertBit (UInt_t f)
 
Bool_t IsDestructed () const
 IsDestructed.
 
virtual Bool_t IsEqual (const TObject *obj) const
 Default equal comparison (objects are equal if they have the same address in memory).
 
R__ALWAYS_INLINE Bool_t IsOnHeap () const
 
R__ALWAYS_INLINE Bool_t IsZombie () const
 
void MayNotUse (const char *method) const
 Use this method to signal that a method (defined in a base class) may not be called in a derived class (in principle against good design since a child class should not provide less functionality than its parent, however, sometimes it is necessary).
 
virtual Bool_t Notify ()
 This method must be overridden to handle object notification (the base implementation is no-op).
 
void Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const
 Use this method to declare a method obsolete.
 
void operator delete (void *ptr)
 Operator delete.
 
void operator delete (void *ptr, void *vp)
 Only called by placement new when throwing an exception.
 
void operator delete[] (void *ptr)
 Operator delete [].
 
void operator delete[] (void *ptr, void *vp)
 Only called by placement new[] when throwing an exception.
 
void * operator new (size_t sz)
 
void * operator new (size_t sz, void *vp)
 
void * operator new[] (size_t sz)
 
void * operator new[] (size_t sz, void *vp)
 
TObjectoperator= (const TObject &rhs)
 TObject assignment operator.
 
virtual void Pop ()
 Pop on object drawn in a pad to the top of the display list.
 
virtual Int_t Read (const char *name)
 Read contents of object with specified name from the current directory.
 
void ResetBit (UInt_t f)
 
virtual void SaveAs (const char *filename="", Option_t *option="") const
 Save this object in the file specified by filename.
 
virtual void SavePrimitive (std::ostream &out, Option_t *option="")
 Save a primitive as a C++ statement(s) on output stream "out".
 
void SetBit (UInt_t f)
 
void SetBit (UInt_t f, Bool_t set)
 Set or unset the user status bits as specified in f.
 
virtual void SetDrawOption (Option_t *option="")
 Set drawing option for object.
 
virtual void SetUniqueID (UInt_t uid)
 Set the unique object id.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
virtual void SysError (const char *method, const char *msgfmt,...) const
 Issue system error message.
 
R__ALWAYS_INLINE Bool_t TestBit (UInt_t f) const
 
Int_t TestBits (UInt_t f) const
 
virtual void UseCurrentStyle ()
 Set current style settings in this object This function is called when either TCanvas::UseCurrentStyle or TROOT::ForceStyle have been invoked.
 
virtual void Warning (const char *method, const char *msgfmt,...) const
 Issue warning message.
 

Static Public Member Functions

static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
- Static Public Member Functions inherited from TDirectory
static void AddDirectory (Bool_t add=kTRUE)
 Sets the flag controlling the automatic add objects like histograms, TGraph2D, etc in memory.
 
static Bool_t AddDirectoryStatus ()
 Static function: see TDirectory::AddDirectory for more comments.
 
static Bool_t Cd (const char *path)
 Change current directory to "path".
 
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static std::atomic< TDirectory * > & CurrentDirectory ()
 Return the current directory for the current thread.
 
static const char * DeclFileName ()
 
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 Public Member Functions inherited from TNamed
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
- Static Public Member Functions inherited from TObject
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
static Longptr_t GetDtorOnly ()
 Return destructor only flag.
 
static Bool_t GetObjectStat ()
 Get status of object stat flag.
 
static void SetDtorOnly (void *obj)
 Set destructor only flag.
 
static void SetObjectStat (Bool_t stat)
 Turn on/off tracking of objects in the TObjectTable.
 

Protected Member Functions

void BuildDirectoryFile (TFile *motherFile, TDirectory *motherDir)
 Initialise directory to defaults.
 
void CleanTargets ()
 Clean the pointers to this object (gDirectory, TContext, etc.)
 
void InitDirectoryFile (TClass *cl=nullptr)
 Initialize the key associated with this directory (and the related data members.
 
- Protected Member Functions inherited from TDirectory
 TDirectory (const TDirectory &directory)=delete
 
void BuildDirectory (TFile *motherFile, TDirectory *motherDir)
 Initialise directory to defaults.
 
Bool_t cd1 (const char *path)
 flag to add histograms, graphs,etc to the directory
 
void CleanTargets ()
 Clean the pointers to this object (gDirectory, TContext, etc.).
 
void FillFullPath (TString &buf) const
 Recursive method to fill full path for directory.
 
void operator= (const TDirectory &)=delete
 
void RegisterContext (TContext *ctxt)
 Register a TContext pointing to this TDirectory object.
 
void RegisterGDirectory (SharedGDirectory_t &ptr)
 Register a std::atomic<TDirectory*> that will soon be pointing to this TDirectory object.
 
void UnregisterContext (TContext *ctxt)
 UnRegister a TContext pointing to this TDirectory object.
 
- Protected Member Functions inherited from TObject
virtual void DoError (int level, const char *location, const char *fmt, va_list va) const
 Interface to ErrorHandler (protected).
 
void MakeZombie ()
 

Protected Attributes

Int_t fBufferSize {0}
 Default buffer size to create new TKeys.
 
TDatime fDatimeC
 Date and time when directory is created.
 
TDatime fDatimeM
 Date and time of last modification.
 
TFilefFile {nullptr}
 Pointer to current file in memory.
 
TListfKeys {nullptr}
 Pointer to keys list in memory.
 
Bool_t fModified {kFALSE}
 True if directory has been modified.
 
Int_t fNbytesKeys {0}
 Number of bytes for the keys.
 
Int_t fNbytesName {0}
 Number of bytes in TNamed at creation time.
 
Long64_t fSeekDir {0}
 Location of directory on file.
 
Long64_t fSeekKeys {0}
 Location of Keys record on file.
 
Long64_t fSeekParent {0}
 Location of parent directory on file.
 
Bool_t fWritable {kFALSE}
 True if directory is writable.
 
- Protected Attributes inherited from TDirectory
TContextfContext {nullptr}
 Buffer for GetPath() function.
 
std::atomic< size_t > fContextPeg {0}
 thread local gDirectory pointing to this object.
 
std::vector< SharedGDirectory_tfGDirectories
 
TListfList {nullptr}
 
TObjectfMother {nullptr}
 
TString fPathBuffer
 
std::atomic_flag fSpinLock
 Counter delaying the TDirectory destructor from finishing.
 
TUUID fUUID
 
- Protected Attributes inherited from TNamed
TString fName
 
TString fTitle
 

Private Member Functions

 TDirectoryFile (const TDirectoryFile &directory)=delete
 
void operator= (const TDirectoryFile &)=delete
 

Additional Inherited Members

- Protected Types inherited from TDirectory
using SharedGDirectory_t = std::shared_ptr< std::atomic< TDirectory * > >
 Pointer to a list of TContext object pointing to this TDirectory.
 
- Protected Types inherited from TObject
enum  { kOnlyPrepStep = (1ULL << ( 3 )) }
 
- Static Protected Member Functions inherited from TDirectory
static Bool_t Cd1 (const char *path)
 Change current directory to "path".
 
static SharedGDirectory_tGetSharedLocalCurrentDirectory ()
 Return the (address of) a shared pointer to the struct holding the actual thread local gDirectory pointer and the atomic_flag for its lock.
 
- Static Protected Attributes inherited from TDirectory
static Bool_t fgAddDirectory = kTRUE
 MSVC doesn't support = ATOMIC_FLAG_INIT;.
 

#include <TDirectoryFile.h>

Inheritance diagram for TDirectoryFile:
[legend]

Member Enumeration Documentation

◆ EStatusBits

Enumerator
kCloseDirectory 

Definition at line 58 of file TDirectoryFile.h.

Constructor & Destructor Documentation

◆ TDirectoryFile() [1/3]

TDirectoryFile::TDirectoryFile ( const TDirectoryFile directory)
privatedelete

◆ TDirectoryFile() [2/3]

TDirectoryFile::TDirectoryFile ( )

Default TDirectoryFile constructor.

Definition at line 60 of file TDirectoryFile.cxx.

◆ TDirectoryFile() [3/3]

TDirectoryFile::TDirectoryFile ( const char *  name,
const char *  title,
Option_t classname = "",
TDirectory initMotherDir = nullptr 
)

Create a new TDirectoryFile.

A new directory with a name and a title is created in the current directory. The directory header information is immediately saved on the file A new key is added in the parent directory. When this constructor is called from a class directly derived from TDirectoryFile, the third argument, classname, MUST be specified. In this case, classname must be the name of the derived class.

Note that the directory name cannot contain slashes.

Definition at line 80 of file TDirectoryFile.cxx.

◆ ~TDirectoryFile()

TDirectoryFile::~TDirectoryFile ( )
override

Destructor.

Definition at line 177 of file TDirectoryFile.cxx.

Member Function Documentation

◆ Add()

void TDirectoryFile::Add ( TObject obj,
Bool_t  replace = kFALSE 
)
inlineoverridevirtual

Reimplemented from TDirectory.

Reimplemented in RooWorkspace::WSDir.

Definition at line 65 of file TDirectoryFile.h.

◆ Append()

void TDirectoryFile::Append ( TObject obj,
Bool_t  replace = kFALSE 
)
overridevirtual

Append object to this directory.

If replace is true: remove any existing objects with the same same (if the name is not ""

Reimplemented from TDirectory.

Reimplemented in RooWorkspace::WSDir.

Definition at line 209 of file TDirectoryFile.cxx.

◆ AppendKey()

Int_t TDirectoryFile::AppendKey ( TKey key)
overridevirtual

Insert key in the linked list of keys of this directory.

Reimplemented from TDirectory.

Definition at line 225 of file TDirectoryFile.cxx.

◆ Browse()

void TDirectoryFile::Browse ( TBrowser b)
overridevirtual

Browse the content of the directory.

Reimplemented from TDirectory.

Definition at line 260 of file TDirectoryFile.cxx.

◆ Build()

void TDirectoryFile::Build ( TFile motherFile = nullptr,
TDirectory motherDir = nullptr 
)
inlineoverridevirtual

Reimplemented from TDirectory.

Definition at line 68 of file TDirectoryFile.h.

◆ BuildDirectoryFile()

void TDirectoryFile::BuildDirectoryFile ( TFile motherFile,
TDirectory motherDir 
)
protected

Initialise directory to defaults.

Definition at line 305 of file TDirectoryFile.cxx.

◆ cd() [1/2]

Bool_t TDirectoryFile::cd ( )
overridevirtual

Change current directory to "this" directory.

Returns kTRUE in case of success.

Reimplemented from TDirectory.

Definition at line 334 of file TDirectoryFile.cxx.

◆ cd() [2/2]

Bool_t TDirectoryFile::cd ( const char *  path)
overridevirtual

Change current directory the directory described by the path if given one.

change the current directory to "path". The absolute path syntax is:

file.root:/dir1/dir2

where file.root is the file and /dir1/dir2 the desired subdirectory in the file. Relative syntax is relative to "this" directory. E.g: ../aa. Returns kTRUE in case of success.

Reimplemented from TDirectory.

Definition at line 352 of file TDirectoryFile.cxx.

◆ Class()

static TClass * TDirectoryFile::Class ( )
static
Returns
TClass describing this class

◆ Class_Name()

static const char * TDirectoryFile::Class_Name ( )
static
Returns
Name of this class

◆ Class_Version()

static constexpr Version_t TDirectoryFile::Class_Version ( )
inlinestaticconstexpr
Returns
Version of this class

Definition at line 131 of file TDirectoryFile.h.

◆ CleanTargets()

void TDirectoryFile::CleanTargets ( )
protected

Clean the pointers to this object (gDirectory, TContext, etc.)

Definition at line 363 of file TDirectoryFile.cxx.

◆ CloneObject()

TObject * TDirectoryFile::CloneObject ( const TObject obj,
Bool_t  autoadd = kTRUE 
)
overridevirtual

Make a clone of an object using the Streamer facility.

If the object derives from TNamed, this function is called by TNamed::Clone. TNamed::Clone uses the optional argument newname to set a new name to the newly created object.

If autoadd is true and if the object class has a DirectoryAutoAdd function, it will be called at the end of the function with the parameter gDirectory. This usually means that the object will be appended to the current ROOT directory.

Reimplemented from TDirectory.

Definition at line 386 of file TDirectoryFile.cxx.

◆ Close()

void TDirectoryFile::Close ( Option_t option = "")
overridevirtual

Delete all objects from memory and directory structure itself.

Reimplemented from TDirectory.

Reimplemented in TSQLFile, TXMLFile, TFile, TNetFile, TParallelMergingFile, and TWebFile.

Definition at line 560 of file TDirectoryFile.cxx.

◆ Copy()

void TDirectoryFile::Copy ( TObject object) const
inlineoverridevirtual

Copy this to obj.

Reimplemented from TDirectory.

Reimplemented in TFile.

Definition at line 71 of file TDirectoryFile.h.

◆ DeclFileName()

static const char * TDirectoryFile::DeclFileName ( )
inlinestatic
Returns
Name of the file containing the class declaration

Definition at line 131 of file TDirectoryFile.h.

◆ Delete()

void TDirectoryFile::Delete ( const char *  namecycle = "")
overridevirtual

Delete Objects or/and keys in a directory.

Properties of the namecycle string:

  • namecycle has the format name;cycle
  • namecycle = "" is same as namecycle ="T*"
  • name = * means all
  • cycle = * means all cycles (memory and keys)
  • cycle = "" or cycle = 9999 ==> apply to a memory object When name=* use T* to delete subdirectories also

To delete one directory, you must specify the directory cycle, eg. file.Delete("dir1;1");

Examples:

Pattern Description
foo delete object named foo in memory
foo* delete all objects with a name starting with foo
foo;1 delete cycle 1 of foo on file
foo;* delete all cycles of foo on file and also from memory
*;2 delete all objects on file having the cycle 2
*;* delete all objects from memory and file
T*;* delete all objects from memory and file and all subdirectories

WARNING

If the key to be deleted contains special characters ("+","^","?", etc that have a special meaning for the regular expression parser (see TRegexp) then you must specify 2 backslash characters to escape the regular expression. For example, if the key to be deleted is namecycle = "C++", you must call

mydir.Delete("C\\+\\+"));

Reimplemented from TDirectory.

Reimplemented in TFile.

Definition at line 631 of file TDirectoryFile.cxx.

◆ FillBuffer()

void TDirectoryFile::FillBuffer ( char *&  buffer)
overridevirtual

Encode directory header into output buffer.

Reimplemented from TNamed.

Reimplemented in TSQLFile, TXMLFile, and TFile.

Definition at line 735 of file TDirectoryFile.cxx.

◆ FindKey()

TKey * TDirectoryFile::FindKey ( const char *  keyname) const
overridevirtual

Find key with name keyname in the current directory.

Reimplemented from TDirectory.

Definition at line 779 of file TDirectoryFile.cxx.

◆ FindKeyAny()

TKey * TDirectoryFile::FindKeyAny ( const char *  keyname) const
overridevirtual

Find key with name keyname in the current directory or its subdirectories.

NOTE: that If a key is found, the directory containing the key becomes the current directory

Reimplemented from TDirectory.

Definition at line 795 of file TDirectoryFile.cxx.

◆ FindObjectAny()

TObject * TDirectoryFile::FindObjectAny ( const char *  aname) const
overridevirtual

Find object by name in the list of memory objects of the current directory or its sub-directories.

After this call the current directory is not changed. To automatically set the current directory where the object is found, use FindKeyAny(aname)->ReadObj().

Reimplemented from TDirectory.

Definition at line 843 of file TDirectoryFile.cxx.

◆ FindObjectAnyFile()

TObject * TDirectoryFile::FindObjectAnyFile ( const char *  name) const
overridevirtual

Scan the memory lists of all files for an object with name.

Reimplemented from TDirectory.

Definition at line 444 of file TDirectoryFile.cxx.

◆ Get() [1/2]

template<class T >
T * TDirectoryFile::Get ( const char *  namecycle)
inlinevirtual

See documentation of TDirectoryFile::Get(const char *namecycle)

Reimplemented from TDirectory.

Definition at line 82 of file TDirectoryFile.h.

◆ Get() [2/2]

TObject * TDirectoryFile::Get ( const char *  namecycle)
overridevirtual

Return pointer to object identified by namecycle.

Properties:

  • namecycle has the format name;cycle
  • name = * is illegal, cycle = * is illegal
  • cycle = "" or cycle = 9999 ==> apply to a memory object

Examples:

Pattern Explanation
foo get object named foo in memory if object is not in memory, try with highest cycle from file
foo;1 get cycle 1 of foo on file

The retrieved object should in principle derive from TObject. If not, the function TDirectoryFile::Get<T> should be called. However, this function will still work for a non-TObject, provided that the calling application cast the return type to the correct type (which is the actual type of the object).

The Get<T> Method

The method Get<T> offers better protection and avoids the need for any cast:

auto objPtr = directory->Get<MyClass>("some object");
if (objPtr) { ... the object exist and inherits from MyClass ... }

Very important note about inheritance

In case the class of this object derives from TObject but not as a first inheritance, one must use dynamic_cast<>().

Example 1 - Normal case:

class MyClass : public TObject, public AnotherClass

then on return, one can adopt a C style cast:

auto objPtr = (MyClass*)directory->Get("some object of MyClass");

Example 2 - Special case:

class MyClass : public AnotherClass, public TObject

then on return, one must do:

auto objPtr = dynamic_cast<MyClass*>(directory->Get("some object of MyClass"));

Of course, dynamic_cast<> can also be used in the example 1.

Reimplemented from TDirectory.

Definition at line 937 of file TDirectoryFile.cxx.

◆ GetBufferSize()

Int_t TDirectoryFile::GetBufferSize ( ) const
overridevirtual

Return the buffer size to create new TKeys.

If the stored fBufferSize is null, the value returned is the average buffer size of objects in the file so far.

Reimplemented from TDirectory.

Definition at line 1124 of file TDirectoryFile.cxx.

◆ GetCreationDate()

const TDatime & TDirectoryFile::GetCreationDate ( ) const
inline

Definition at line 91 of file TDirectoryFile.h.

◆ GetDirectory()

TDirectory * TDirectoryFile::GetDirectory ( const char *  apath,
Bool_t  printError = false,
const char *  funcname = "GetDirectory" 
)
overridevirtual

Find a directory named "apath".

It apath is null or empty, returns "this" directory. Otherwise use the name "apath" to find a directory. The absolute path syntax is:

file.root:/dir1/dir2

where file.root is the file and /dir1/dir2 the desired subdirectory in the file. Relative syntax is relative to "this" directory. E.g: ../aa. Returns 0 in case path does not exist. If printError is true, use Error with 'funcname' to issue an error message.

Reimplemented from TDirectory.

Definition at line 471 of file TDirectoryFile.cxx.

◆ GetFile()

TFile * TDirectoryFile::GetFile ( ) const
inlineoverridevirtual

Reimplemented from TDirectory.

Definition at line 92 of file TDirectoryFile.h.

◆ GetKey()

TKey * TDirectoryFile::GetKey ( const char *  name,
Short_t  cycle = 9999 
) const
overridevirtual

Return pointer to key with name,cycle.

if cycle = 9999 returns highest cycle

Reimplemented from TDirectory.

Definition at line 1136 of file TDirectoryFile.cxx.

◆ GetListOfKeys()

TList * TDirectoryFile::GetListOfKeys ( ) const
inlineoverridevirtual

Reimplemented from TDirectory.

Definition at line 94 of file TDirectoryFile.h.

◆ GetModificationDate()

const TDatime & TDirectoryFile::GetModificationDate ( ) const
inline

Definition at line 95 of file TDirectoryFile.h.

◆ GetNbytesKeys()

Int_t TDirectoryFile::GetNbytesKeys ( ) const
inlineoverridevirtual

Reimplemented from TDirectory.

Definition at line 96 of file TDirectoryFile.h.

◆ GetNkeys()

Int_t TDirectoryFile::GetNkeys ( ) const
inlineoverridevirtual

Reimplemented from TDirectory.

Definition at line 97 of file TDirectoryFile.h.

◆ GetObjectChecked() [1/2]

void * TDirectoryFile::GetObjectChecked ( const char *  namecycle,
const char *  classname 
)
overridevirtual

See documentation of TDirectoryFile::GetObjectCheck(const char *namecycle, const TClass *cl)

Reimplemented from TDirectory.

Definition at line 1018 of file TDirectoryFile.cxx.

◆ GetObjectChecked() [2/2]

void * TDirectoryFile::GetObjectChecked ( const char *  namecycle,
const TClass expectedClass 
)
overridevirtual

Return pointer to object identified by namecycle if and only if the actual object is a type suitable to be stored as a pointer to a "expectedClass" If expectedClass is null, no check is performed.

  • namecycle has the format name;cycle
  • name = * is illegal, cycle = * is illegal
  • cycle = "" or cycle = 9999 ==> apply to a memory object

Very important note

The calling application must cast the returned pointer to the type described by the 2 arguments (i.e. cl):

auto objPtr = (MyClass*)directory->GetObjectChecked("some object of MyClass","MyClass"));

Note: We recommend using the method TDirectoryFile::Get<T>:

auto objPtr = directory->Get<MyClass>("some object inheriting from MyClass");
if (objPtr) { ... we found what we are looking for ... }
static const char * what
Definition stlLoader.cc:5

Reimplemented from TDirectory.

Definition at line 1045 of file TDirectoryFile.cxx.

◆ GetObjectUnchecked()

void * TDirectoryFile::GetObjectUnchecked ( const char *  namecycle)
overridevirtual

Return pointer to object identified by namecycle.

The returned object may or may not derive from TObject.

  • namecycle has the format name;cycle
  • name = * is illegal, cycle = * is illegal
  • cycle = "" or cycle = 9999 ==> apply to a memory object

Very important note

The calling application must cast the returned object to the final type, e.g.

auto objPtr = (MyClass*)directory->GetObject("some object of MyClass");

Reimplemented from TDirectory.

Definition at line 1010 of file TDirectoryFile.cxx.

◆ GetSeekDir()

Long64_t TDirectoryFile::GetSeekDir ( ) const
inlineoverridevirtual

Reimplemented from TDirectory.

Definition at line 98 of file TDirectoryFile.h.

◆ GetSeekKeys()

Long64_t TDirectoryFile::GetSeekKeys ( ) const
inlineoverridevirtual

Reimplemented from TDirectory.

Definition at line 100 of file TDirectoryFile.h.

◆ GetSeekParent()

Long64_t TDirectoryFile::GetSeekParent ( ) const
inlineoverridevirtual

Reimplemented from TDirectory.

Definition at line 99 of file TDirectoryFile.h.

◆ InitDirectoryFile()

void TDirectoryFile::InitDirectoryFile ( TClass cl = nullptr)
protected

Initialize the key associated with this directory (and the related data members.

Definition at line 147 of file TDirectoryFile.cxx.

◆ IsA()

TClass * TDirectoryFile::IsA ( ) const
inlineoverridevirtual
Returns
TClass describing current object

Reimplemented from TDirectory.

Reimplemented in TFile, TMemFile, TSQLFile, TXMLFile, TNetFile, TParallelMergingFile, TS3WebFile, TWebFile, TNetXNGFile, and RooWorkspace::WSDir.

Definition at line 131 of file TDirectoryFile.h.

◆ IsModified()

Bool_t TDirectoryFile::IsModified ( ) const
inlineoverridevirtual

Reimplemented from TDirectory.

Definition at line 101 of file TDirectoryFile.h.

◆ IsWritable()

Bool_t TDirectoryFile::IsWritable ( ) const
inlineoverridevirtual

Reimplemented from TDirectory.

Definition at line 102 of file TDirectoryFile.h.

◆ ls()

void TDirectoryFile::ls ( Option_t option = "") const
overridevirtual

List Directory contents.

Indentation is used to identify the directory tree Subdirectories are listed first, then objects in memory, then objects on the file

The option can has the following format: [-d |-m][<regexp>] Options:

  • -d: only list objects in the file
  • -m: only list objects in memory The <regexp> will be used to match the name of the objects. By default memory and disk objects are listed.

Reimplemented from TDirectory.

Reimplemented in TFile.

Definition at line 1171 of file TDirectoryFile.cxx.

◆ mkdir()

TDirectory * TDirectoryFile::mkdir ( const char *  name,
const char *  title = "",
Bool_t  returnExistingDirectory = kFALSE 
)
overridevirtual

Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".

Returns 0 in case of error or if a sub-directory (hierarchy) with the requested name already exists. returnExistingDirectory returns a pointer to an already existing sub-directory instead of 0. Returns a pointer to the created sub-directory or to the top sub-directory of the hierarchy (in the above example, the returned TDirectory * always points to "a").

Reimplemented from TDirectory.

Definition at line 1249 of file TDirectoryFile.cxx.

◆ OpenFile()

TFile * TDirectoryFile::OpenFile ( const char *  name,
Option_t option = "",
const char *  ftitle = "",
Int_t  compress = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault,
Int_t  netopt = 0 
)
overridevirtual

Interface to TFile::Open.

Reimplemented from TDirectory.

Definition at line 1233 of file TDirectoryFile.cxx.

◆ operator=()

void TDirectoryFile::operator= ( const TDirectoryFile )
privatedelete

◆ Purge()

void TDirectoryFile::Purge ( Short_t  nkeep = 1)
overridevirtual

Purge lowest key cycles in a directory.

By default, only the highest cycle of a key is kept. Keys for which the "KEEP" flag has been set are not removed. See TKey::Keep(). NOTE: This does not reduce the size of a TFile– the space is simply freed up to be overwritten.

Reimplemented from TDirectory.

Definition at line 1290 of file TDirectoryFile.cxx.

◆ ReadAll()

void TDirectoryFile::ReadAll ( Option_t opt = "")
overridevirtual

Read objects from a ROOT file directory into memory.

If an object is already in memory, the memory copy is deleted and the object is again read from the file. If opt=="dirs", only subdirectories will be read If opt=="dirs*" complete directory tree will be read

Reimplemented from TDirectory.

Definition at line 1326 of file TDirectoryFile.cxx.

◆ ReadKeys()

Int_t TDirectoryFile::ReadKeys ( Bool_t  forceRead = kTRUE)
overridevirtual

Read the linked list of keys.

Every directory has a linked list (fKeys). This linked list has been written on the file via WriteKeys as a single data record.

It is interesting to call this function in the following situation. Assume another process1 is connecting this directory in Update mode

  • Process1 is adding/updating objects in this directory
  • You want to see the latest status from process1. Example Process1:
    obj1.Write();
    obj2.Write();
    gDirectory->SaveSelf();
    #define gDirectory
    Definition TDirectory.h:384

Example Process2:

gDirectory->ReadKeys();
obj1->Draw();

This is an efficient way (without opening/closing files) to view the latest updates of a file being modified by another process as it is typically the case in a data acquisition system.

Reimplemented from TDirectory.

Definition at line 1379 of file TDirectoryFile.cxx.

◆ ReadTObject()

Int_t TDirectoryFile::ReadTObject ( TObject obj,
const char *  keyname 
)
overridevirtual

Read object with keyname from the current directory.

Read contents of object with specified name from the current directory. First the key with keyname is searched in the current directory, next the key buffer is deserialized into the object. The object must have been created before via the default constructor. See TObject::Write().

Reimplemented from TDirectory.

Definition at line 1465 of file TDirectoryFile.cxx.

◆ ResetAfterMerge()

void TDirectoryFile::ResetAfterMerge ( TFileMergeInfo info)
virtual

Reset the TDirectory after its content has been merged into another Directory.

This returns the TDirectoryFile object back to its state before any data has been written to the file. The object in the in-memory list are assumed to also have been reset.

Reimplemented in TMemFile.

Definition at line 1494 of file TDirectoryFile.cxx.

◆ rmdir()

void TDirectoryFile::rmdir ( const char *  name)
overridevirtual

Removes subdirectory from the directory.

When directory is deleted, all keys in all subdirectories will be read first and deleted from file (if exists) Equivalent call is Delete("name;*");

Reimplemented from TDirectory.

Definition at line 1540 of file TDirectoryFile.cxx.

◆ Save()

void TDirectoryFile::Save ( )
overridevirtual

Save recursively all directory keys and headers.

Reimplemented from TDirectory.

Definition at line 1552 of file TDirectoryFile.cxx.

◆ SaveObjectAs()

Int_t TDirectoryFile::SaveObjectAs ( const TObject obj,
const char *  filename = "",
Option_t option = "" 
) const
overridevirtual

Save object in filename.

If filename is nullptr or "", a file with "<objectname>.root" is created. The name of the key is the object name. By default new file will be created. Using option "a", one can append object to the existing ROOT file. If the operation is successful, it returns the number of bytes written to the file otherwise it returns 0. By default a message is printed. Use option "q" to not print the message. If filename contains ".json" extension, JSON representation of the object will be created and saved in the text file. Such file can be used in JavaScript ROOT (https://root.cern/js/) to display object in web browser When creating JSON file, option string may contain compression level from 0 to 3 (default 0)

Reimplemented from TDirectory.

Definition at line 1587 of file TDirectoryFile.cxx.

◆ SaveSelf()

void TDirectoryFile::SaveSelf ( Bool_t  force = kFALSE)
overridevirtual

Save Directory keys and header.

If the directory has been modified (fModified set), write the keys and the directory header. This function assumes the cd is correctly set.

It is recommended to use this function in the following situation: Assume a process1 using a directory in Update mode

  • New objects or modified objects have been written to the directory.
  • You do not want to close the file.
  • You want your changes be visible from another process2 already connected to this directory in read mode.
  • Call this function.
  • In process2, use TDirectoryFile::ReadKeys to refresh the directory.

Reimplemented from TDirectory.

Definition at line 1629 of file TDirectoryFile.cxx.

◆ SetBufferSize()

void TDirectoryFile::SetBufferSize ( Int_t  bufsize)
overridevirtual

Set the default buffer size when creating new TKeys.

See also TDirectoryFile::GetBufferSize

Reimplemented from TDirectory.

Definition at line 1650 of file TDirectoryFile.cxx.

◆ SetModified()

void TDirectoryFile::SetModified ( )
inlineoverridevirtual

Reimplemented from TDirectory.

Definition at line 118 of file TDirectoryFile.h.

◆ SetSeekDir()

void TDirectoryFile::SetSeekDir ( Long64_t  v)
inlineoverridevirtual

Reimplemented from TDirectory.

Definition at line 119 of file TDirectoryFile.h.

◆ SetTRefAction()

void TDirectoryFile::SetTRefAction ( TObject ref,
TObject parent 
)
overridevirtual

Find the action to be executed in the dictionary of the parent class and store the corresponding exec number into fBits.

This function searches a data member in the class of parent with an offset corresponding to this. If a comment "TEXEC:" is found in the comment field of the data member, the function stores the exec identifier of the exec statement following this keyword.

Reimplemented from TDirectory.

Definition at line 1665 of file TDirectoryFile.cxx.

◆ SetWritable()

void TDirectoryFile::SetWritable ( Bool_t  writable = kTRUE)
overridevirtual

Set the new value of fWritable recursively.

Reimplemented from TDirectory.

Definition at line 1684 of file TDirectoryFile.cxx.

◆ Sizeof()

Int_t TDirectoryFile::Sizeof ( ) const
overridevirtual

Return the size in bytes of the directory header.

Reimplemented from TDirectory.

Reimplemented in TSQLFile, TXMLFile, and TFile.

Definition at line 1707 of file TDirectoryFile.cxx.

◆ Streamer()

void TDirectoryFile::Streamer ( TBuffer b)
overridevirtual

Stream a class object.

Reimplemented from TDirectory.

Reimplemented in TFile, TMemFile, TSQLFile, TXMLFile, TNetFile, TParallelMergingFile, TS3WebFile, TWebFile, TNetXNGFile, and RooWorkspace::WSDir.

Definition at line 1723 of file TDirectoryFile.cxx.

◆ StreamerNVirtual()

void TDirectoryFile::StreamerNVirtual ( TBuffer ClassDef_StreamerNVirtual_b)
inline

Definition at line 131 of file TDirectoryFile.h.

◆ Write() [1/2]

Int_t TDirectoryFile::Write ( const char *  name = nullptr,
Int_t  opt = 0,
Int_t  bufsize = 0 
) const
overridevirtual

One can not save a const TDirectory object.

Reimplemented from TDirectory.

Reimplemented in TSQLFile, TXMLFile, TFile, and TParallelMergingFile.

Definition at line 1859 of file TDirectoryFile.cxx.

◆ Write() [2/2]

Int_t TDirectoryFile::Write ( const char *  name = nullptr,
Int_t  opt = 0,
Int_t  bufsize = 0 
)
overridevirtual

Write all objects in memory to disk.

Loop on all objects in memory (including subdirectories). A new key is created in the keys linked list for each object. For allowed options see TObject::Write(). The directory header info is rewritten on the directory header record.

Reimplemented from TDirectory.

Reimplemented in TSQLFile, TXMLFile, TFile, and TParallelMergingFile.

Definition at line 1838 of file TDirectoryFile.cxx.

◆ WriteDirHeader()

void TDirectoryFile::WriteDirHeader ( )
overridevirtual

Overwrite the Directory header record.

Reimplemented from TDirectory.

Definition at line 2141 of file TDirectoryFile.cxx.

◆ WriteKeys()

void TDirectoryFile::WriteKeys ( )
overridevirtual

Write Keys linked list on the file.

The linked list of keys (fKeys) is written as a single data record

Reimplemented from TDirectory.

Definition at line 2170 of file TDirectoryFile.cxx.

◆ WriteObjectAny() [1/2]

Int_t TDirectoryFile::WriteObjectAny ( const void *  obj,
const char *  classname,
const char *  name,
Option_t option = "",
Int_t  bufsize = 0 
)
overridevirtual

Write object from pointer of class classname in this directory.

obj may not derive from TObject. See TDirectoryFile::WriteTObject for comments

Very important note

The value passed as 'obj' needs to be from a pointer to the type described by classname. For example:

TopClass *top;
BottomClass *bottom;
top = bottom;

you can do:

directory->WriteObjectAny(top,"top","name of object");
directory->WriteObjectAny(bottom,"bottom","name of object");

BUT YOU CAN NOT DO the following since it will fail with multiple inheritance:

directory->WriteObjectAny(top,"bottom","name of object");

We STRONGLY recommend to use

TopClass *top = ....;
directory->WriteObject(top,"name of object")

See also remarks in TDirectoryFile::WriteTObject

Reimplemented from TDirectory.

Definition at line 2022 of file TDirectoryFile.cxx.

◆ WriteObjectAny() [2/2]

Int_t TDirectoryFile::WriteObjectAny ( const void *  obj,
const TClass cl,
const char *  name,
Option_t option = "",
Int_t  bufsize = 0 
)
overridevirtual

Write object of class with dictionary cl in this directory.

obj may not derive from TObject To get the TClass* cl pointer, one can use

TClass *cl = TClass::GetClass("classname");

An alternative is to call the function WriteObjectAny above. see TDirectoryFile::WriteTObject for comments

Reimplemented from TDirectory.

Definition at line 2049 of file TDirectoryFile.cxx.

◆ WriteTObject()

Int_t TDirectoryFile::WriteTObject ( const TObject obj,
const char *  name = nullptr,
Option_t option = "",
Int_t  bufsize = 0 
)
overridevirtual

Write object obj to this directory.

The data structure corresponding to this object is serialized. The corresponding buffer is written to this directory with an associated key with name "name".

Writing an object to a file involves the following steps:

  • Creation of a support TKey object in the directory. The TKey object creates a TBuffer object.
  • The TBuffer object is filled via the class::Streamer function.
  • If the file is compressed (default) a second buffer is created to hold the compressed buffer.
  • Reservation of the corresponding space in the file by looking in the TFree list of free blocks of the file.
  • The buffer is written to the file.

By default, the buffersize will be taken from the average buffer size of all objects written to the current file so far. Use TDirectoryFile::SetBufferSize to force a given buffer size.

If a name is specified, it will be the name of the key. If name is not given, the name of the key will be the name as returned by obj->GetName().

The option can be a combination of:

  • "SingleKey"
  • "Overwrite"
  • "WriteDelete" Using the "Overwrite" option a previous key with the same name is overwritten. The previous key is deleted before writing the new object. Using the "WriteDelete" option a previous key with the same name is deleted only after the new object has been written. This option is safer than kOverwrite but it is slower. The "SingleKey" option is only used by TCollection::Write() to write a container with a single key instead of each object in the container with its own key. An object is read from this directory via TDirectoryFile::Get. The function returns the total number of bytes written to the directory. It returns 0 if the object cannot be written.

WARNING: avoid special characters like '^','$','.' in the name as they are used by the regular expression parser (see TRegexp).

Reimplemented from TDirectory.

Definition at line 1909 of file TDirectoryFile.cxx.

Member Data Documentation

◆ fBufferSize

Int_t TDirectoryFile::fBufferSize {0}
protected

Default buffer size to create new TKeys.

Definition at line 41 of file TDirectoryFile.h.

◆ fDatimeC

TDatime TDirectoryFile::fDatimeC
protected

Date and time when directory is created.

Definition at line 37 of file TDirectoryFile.h.

◆ fDatimeM

TDatime TDirectoryFile::fDatimeM
protected

Date and time of last modification.

Definition at line 38 of file TDirectoryFile.h.

◆ fFile

TFile* TDirectoryFile::fFile {nullptr}
protected

Pointer to current file in memory.

Definition at line 45 of file TDirectoryFile.h.

◆ fKeys

TList* TDirectoryFile::fKeys {nullptr}
protected

Pointer to keys list in memory.

Definition at line 46 of file TDirectoryFile.h.

◆ fModified

Bool_t TDirectoryFile::fModified {kFALSE}
protected

True if directory has been modified.

Definition at line 35 of file TDirectoryFile.h.

◆ fNbytesKeys

Int_t TDirectoryFile::fNbytesKeys {0}
protected

Number of bytes for the keys.

Definition at line 39 of file TDirectoryFile.h.

◆ fNbytesName

Int_t TDirectoryFile::fNbytesName {0}
protected

Number of bytes in TNamed at creation time.

Definition at line 40 of file TDirectoryFile.h.

◆ fSeekDir

Long64_t TDirectoryFile::fSeekDir {0}
protected

Location of directory on file.

Definition at line 42 of file TDirectoryFile.h.

◆ fSeekKeys

Long64_t TDirectoryFile::fSeekKeys {0}
protected

Location of Keys record on file.

Definition at line 44 of file TDirectoryFile.h.

◆ fSeekParent

Long64_t TDirectoryFile::fSeekParent {0}
protected

Location of parent directory on file.

Definition at line 43 of file TDirectoryFile.h.

◆ fWritable

Bool_t TDirectoryFile::fWritable {kFALSE}
protected

True if directory is writable.

Definition at line 36 of file TDirectoryFile.h.

Libraries for TDirectoryFile:

The documentation for this class was generated from the following files: