REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Public Member Functions | Static Public Member Functions | Private Attributes | Friends
TRestRootFileHandle Class Reference

Detailed Description

Move-only owner for ROOT files opened by REST.

UPDATE mode preserves all semantically required historical user schemas and embedded rules before the writable file is exposed. A failed open or preservation produces an invalid handle, queryable through operator bool() and Error().

Definition at line 71 of file TRestTools.h.

#include <TRestTools.h>

Public Member Functions

bool Close () noexcept
 
const std::string & Error () const noexcept
 
TFile * Get () const noexcept
 Borrow the file without transferring ownership; do not delete or outlive the handle. More...
 
 operator bool () const noexcept
 
TFile & operator* () const noexcept
 
TFile * operator-> () const noexcept
 
TRestRootFileHandle & operator= (const TRestRootFileHandle &)=delete
 
TRestRootFileHandle & operator= (TRestRootFileHandle &&other) noexcept
 
 TRestRootFileHandle (const TRestRootFileHandle &)=delete
 
 TRestRootFileHandle (TRestRootFileHandle &&other) noexcept
 

Static Public Member Functions

static TRestRootFileHandle Open (const std::string &filename, TRestRootFileMode mode)
 
static bool PrepareBorrowedUpdate (TFile &file, std::string *error=nullptr)
 

Private Attributes

std::string fError
 
std::unique_ptr< TFile > fFile
 

Friends

class TRestTools
 

Constructor & Destructor Documentation

◆ TRestRootFileHandle()

TRestRootFileHandle::TRestRootFileHandle ( TRestRootFileHandle &&  other)
noexcept

Definition at line 645 of file TRestTools.cxx.

◆ ~TRestRootFileHandle()

TRestRootFileHandle::~TRestRootFileHandle ( )

Definition at line 656 of file TRestTools.cxx.

Member Function Documentation

◆ Close()

bool TRestRootFileHandle::Close ( )
noexcept

Release the file and report ROOT close/write errors. Check before claiming write success; destructor cleanup alone cannot report success to the caller.

Close and release the owned file, reporting ROOT's zombie/write-error flags. Writers must call and check this explicitly: the destructor also cleans up, but cannot report success to its caller. Borrowed pointers become invalid. This checks reported ROOT errors, not filesystem durability after power loss.

Definition at line 662 of file TRestTools.cxx.

◆ Error()

const std::string & TRestRootFileHandle::Error ( ) const
inlinenoexcept

Definition at line 93 of file TRestTools.h.

◆ Get()

TFile * TRestRootFileHandle::Get ( ) const
inlinenoexcept

Borrow the file without transferring ownership; do not delete or outlive the handle.

Definition at line 90 of file TRestTools.h.

◆ Open()

TRestRootFileHandle TRestRootFileHandle::Open ( const std::string &  filename,
TRestRootFileMode  mode 
)
static

Open with explicit ownership and checked writable-mode policy. Existing UPDATE files first open READ and pass PrepareBorrowedUpdate; missing ones use CREATE to avoid overwriting a file appearing during the existence check. RECREATE is intentionally destructive. Remote files are supported only in READ mode. Failure returns an invalid handle with Error(); callers must check it.

Definition at line 597 of file TRestTools.cxx.

◆ operator bool()

TRestRootFileHandle::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 88 of file TRestTools.h.

◆ operator*()

TFile & TRestRootFileHandle::operator* ( ) const
inlinenoexcept

Definition at line 92 of file TRestTools.h.

◆ operator->()

TFile * TRestRootFileHandle::operator-> ( ) const
inlinenoexcept

Definition at line 91 of file TRestTools.h.

◆ operator=()

TRestRootFileHandle & TRestRootFileHandle::operator= ( TRestRootFileHandle &&  other)
noexcept

Definition at line 648 of file TRestTools.cxx.

◆ PrepareBorrowedUpdate()

bool TRestRootFileHandle::PrepareBorrowedUpdate ( TFile &  file,
std::string *  error = nullptr 
)
static

Validate an already-owned READ file, then transition it safely to UPDATE.

The file remains read-only when validation fails before ReOpen.

Gate an existing owner's READ file into UPDATE without taking ownership. Resolve and retain historical schemas/rules before requesting writable access; compare local path identity around ReOpen, then select schemas for later writes. A preflight refusal leaves the file read-only. If the transition was attempted before a failure, disable writable state; this is not rollback for arbitrary subsequent writes and does not serialize concurrent writers.

Definition at line 678 of file TRestTools.cxx.

Friends And Related Function Documentation

◆ TRestTools

friend class TRestTools
friend

Definition at line 73 of file TRestTools.h.

Field Documentation

◆ fError

std::string TRestRootFileHandle::fError
private

Definition at line 76 of file TRestTools.h.

◆ fFile

std::unique_ptr<TFile> TRestRootFileHandle::fFile
private

Definition at line 75 of file TRestTools.h.


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