Logo ROOT   6.14/05
Reference Guide
List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
ROOT::Experimental::TDirectory Class Reference

Key/value store of objects.

Given a name, a TDirectory can store and retrieve an object. It will manage shared ownership through a shared_ptr.

Example: TDirectory dirMC; TDirectory dirHiggs;

dirMC.Add("higgs", histHiggsMC); dirHiggs.Add("mc", histHiggsMC);

Definition at line 70 of file TDirectory.hxx.

Classes

struct  ToContentType
 

Public Types

enum  EFindStatus { EFindStatus::kValidValue, EFindStatus::kValidValueBase, EFindStatus::kKeyNameNotFound, EFindStatus::kTypeMismatch }
 Status of the call to Find<T>(name). More...
 

Public Member Functions

template<class T >
void Add (std::string_view name, const std::shared_ptr< T > &ptr)
 Add an existing object (rather a shared_ptr to it) to the TDirectory. More...
 
template<class T , class... ARGS>
std::shared_ptr< ToContentType_t< T > > Create (std::string_view name, ARGS &&... args)
 Create an object of type T (passing some arguments to its constructor). More...
 
Internal::TDirectoryEntry Find (std::string_view name) const
 Find the TDirectoryEntry associated to the name. More...
 
template<class T >
std::pair< Internal::TDirectoryEntry, EFindStatusFind (std::string_view name) const
 Find the TDirectoryEntry associated with the name. More...
 
template<class T >
std::shared_ptr< ToContentType_t< T > > Get (std::string_view name)
 Get the object for a key. More...
 

Static Public Member Functions

static TDirectoryHeap ()
 Dedicated, process-wide TDirectory. More...
 

Private Types

using ContentMap_t = std::unordered_map< std::string, Internal::TDirectoryEntry >
 The directory content is a hashed map of name => Internal::TDirectoryEntry. More...
 
template<class T >
using ToContentType_t = typename ToContentType< T >::type
 

Private Attributes

ContentMap_t fContent
 The TDirectory's content. More...
 

#include <ROOT/TDirectory.hxx>

Inheritance diagram for ROOT::Experimental::TDirectory:
[legend]

Member Typedef Documentation

◆ ContentMap_t

using ROOT::Experimental::TDirectory::ContentMap_t = std::unordered_map<std::string, Internal::TDirectoryEntry>
private

The directory content is a hashed map of name => Internal::TDirectoryEntry.

Definition at line 75 of file TDirectory.hxx.

◆ ToContentType_t

template<class T >
using ROOT::Experimental::TDirectory::ToContentType_t = typename ToContentType<T>::type
private

Definition at line 89 of file TDirectory.hxx.

Member Enumeration Documentation

◆ EFindStatus

Status of the call to Find<T>(name).

Enumerator
kValidValue 

Value known for this key name and type.

kValidValueBase 

Value known for this key name and base type.

kKeyNameNotFound 

No key is known for this name.

kTypeMismatch 

The provided type does not match the value's type.

Definition at line 118 of file TDirectory.hxx.

Member Function Documentation

◆ Add()

template<class T >
void ROOT::Experimental::TDirectory::Add ( std::string_view  name,
const std::shared_ptr< T > &  ptr 
)
inline

Add an existing object (rather a shared_ptr to it) to the TDirectory.

The TDirectory will have shared ownership.

Definition at line 172 of file TDirectory.hxx.

◆ Create()

template<class T , class... ARGS>
std::shared_ptr<ToContentType_t<T> > ROOT::Experimental::TDirectory::Create ( std::string_view  name,
ARGS &&...  args 
)
inline

Create an object of type T (passing some arguments to its constructor).

The TDirectory will have shared ownership of the object.

Parameters
name- Key of the object.
args- arguments to be passed to the constructor of T

Definition at line 98 of file TDirectory.hxx.

◆ Find() [1/2]

Internal::TDirectoryEntry ROOT::Experimental::TDirectory::Find ( std::string_view  name) const
inline

Find the TDirectoryEntry associated to the name.

Returns empty TDirectoryEntry if nothing is found.

Definition at line 107 of file TDirectory.hxx.

◆ Find() [2/2]

template<class T >
std::pair<Internal::TDirectoryEntry, EFindStatus> ROOT::Experimental::TDirectory::Find ( std::string_view  name) const
inline

Find the TDirectoryEntry associated with the name.

Returns
empty TDirectoryEntry in first if nothing is found, or if the type does not match the expected type. second contains the reason.
Note
if second is kValidValue, then static_pointer_cast<T>(first.GetPointer()) is shared_ptr<T> to initially stored object
if second is kValidValueBase, then first.CastPointer<T>() is a valid cast to base class T of the stored object

Definition at line 133 of file TDirectory.hxx.

◆ Get()

template<class T >
std::shared_ptr<ToContentType_t<T> > ROOT::Experimental::TDirectory::Get ( std::string_view  name)
inline

Get the object for a key.

T can be the object's type or a base class. The TDirectory will return the same object for subsequent calls to Get().

Returns
a shared_ptr to the object or its base.
Exceptions
TDirectoryUnknownKeyif no object is stored under this name.
TDirectoryTypeMismatchif the object stored under this name is of a type that is not a derived type of T.

Definition at line 153 of file TDirectory.hxx.

◆ Heap()

ROOT::Experimental::TDirectory & TDirectory::Heap ( )
static

Dedicated, process-wide TDirectory.

Note
This is not thread-safe. You will need to syncronize yourself. In general it's a bad idea to use a global collection in a multi-threaded environment; ROOT itself does not make use of it. It is merely offered for historical, process-wide object registration by name. Instead, pass a pointer to the object where you need to access it - this is also much faster than a lookup by name.

Definition at line 23 of file TFile.cxx.

Member Data Documentation

◆ fContent

ContentMap_t ROOT::Experimental::TDirectory::fContent
private

The TDirectory's content.

Definition at line 78 of file TDirectory.hxx.

Libraries for ROOT::Experimental::TDirectory:
[legend]

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