Skip to content

[skip-ci][io] clarify behavior of Delete #18763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions io/io/src/TDirectoryFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,16 @@ void TDirectoryFile::Close(Option_t *option)
}

////////////////////////////////////////////////////////////////////////////////
/// 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
/// Delete Objects or/and keys in the current directory.
///
/// \param[in] namecycle Encodes the name and cycle of the objects to delete in
/// the current directory (e.g. the top directory of a TFile)
/// - <em>namecycle</em> has the format <em>name;cycle</em>.
/// - <em>namecycle</em>="" is same as <em>namecycle</em>="T*"
/// - <em>name</em>="*" means all objects, use "T*" to also delete subdirectories
/// - <em>cycle</em>="*" means all cycles (memory and keys)
/// - <em>cycle</em>="" or <em>cycle</em>="9999" ==> apply to a memory object
/// - When <em>name</em>="*"" use "T*" to delete subdirectories also
///
/// To delete one directory, you must specify the directory cycle,
/// eg. file.Delete("dir1;1");
Expand All @@ -620,6 +621,18 @@ void TDirectoryFile::Close(Option_t *option)
/// | *;* | delete all objects from memory and file |
/// | T*;* | delete all objects from memory and file and all subdirectories |
///
/// \note For some objects, this method, which is used e.g. by rootrm,
/// properly deletes the specified cycles of the object, but does not free any ‘dependent’
/// data records (unless it is a TDirectoryFile). In other words, in these cases, Delete
/// does not free all subdata records, but rather orphans them, ie. the file size is not
/// reduced, and there is later no option to shrink it nor recover the disappeared ‘dependent’
/// items. For example, deleting a TTree does not free up space from the directory since the
/// underlying basket records are not recursively deleted. If this is wanted, one can call
/// TTree::Delete("all") before calling TDirectoryFile::Delete(); file size won't
/// shrink either, but more space will be left open for overwriting with other objects.
/// See also Purge() documentation. A workaround to reduce filesize is to clone all
/// objects (excluding those to be deleted) into a new TFile.
///
/// ## WARNING
/// If the key to be deleted contains special characters ("+","^","?", etc
/// that have a special meaning for the regular expression parser (see TRegexp)
Expand Down
21 changes: 1 addition & 20 deletions io/io/src/TFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1080,26 +1080,7 @@ TFile *&TFile::CurrentFile()
}

////////////////////////////////////////////////////////////////////////////////
/// Delete object namecycle.
///
/// \param[in] namecycle Encodes the name and cycle of the objects to delete
///
/// Namecycle identifies an object in the top directory of the file namecycle
/// has the format <em>name;cycle</em>.
/// - <em>name = *</em> means all objects
/// - <em>cycle = *</em> means all cycles (memory and keys)
/// - <em>cycle = ""</em> or cycle = 9999 ==> apply to a memory object
/// When name=* use T* to delete subdirectories also
///
/// Examples:
/// name/cycle | Action
/// -----------|-------
/// foo | delete object named foo in memory
/// foo;1 | delete cycle 1 of foo on file
/// foo;* | delete all cycles of foo on disk 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
/// \copydoc TDirectoryFile::Delete

void TFile::Delete(const char *namecycle)
{
Expand Down