Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROOT::Experimental::RDirectory Class Reference

Key/value store of objects.

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

Example: RDirectory dirMC; RDirectory dirHiggs;

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

Definition at line 73 of file RDirectory.hxx.

Classes

struct  ToContentType
 

Public Types

enum class  EFindStatus { kValidValue , kValidValueBase , kKeyNameNotFound , 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 RDirectory.
 
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).
 
Internal::RDirectoryEntry Find (std::string_view name) const
 Find the RDirectoryEntry associated to the name.
 
template<class T >
std::pair< Internal::RDirectoryEntry, EFindStatusFind (std::string_view name) const
 Find the RDirectoryEntry associated with the name.
 
template<class T >
std::shared_ptr< ToContentType_t< T > > Get (std::string_view name)
 Get the object for a key.
 
bool Remove (std::string_view name)
 Remove entry from RDirectory (if exists)
 

Static Public Member Functions

static RDirectoryHeap ()
 Dedicated, process-wide RDirectory.
 

Private Types

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

Private Attributes

ContentMap_t fContent
 The RDirectory's content.
 

#include <ROOT/RDirectory.hxx>

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

Member Typedef Documentation

◆ ContentMap_t

using ROOT::Experimental::RDirectory::ContentMap_t = std::unordered_map<std::string, Internal::RDirectoryEntry>
private

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

Definition at line 78 of file RDirectory.hxx.

◆ ToContentType_t

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

Definition at line 92 of file RDirectory.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 121 of file RDirectory.hxx.

Member Function Documentation

◆ Add()

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

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

The RDirectory will have shared ownership.

Definition at line 175 of file RDirectory.hxx.

◆ Create()

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

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

The RDirectory 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 101 of file RDirectory.hxx.

◆ Find() [1/2]

Internal::RDirectoryEntry ROOT::Experimental::RDirectory::Find ( std::string_view  name) const
inline

Find the RDirectoryEntry associated to the name.

Returns empty RDirectoryEntry if nothing is found.

Definition at line 110 of file RDirectory.hxx.

◆ Find() [2/2]

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

Find the RDirectoryEntry associated with the name.

Returns
empty RDirectoryEntry 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 136 of file RDirectory.hxx.

◆ Get()

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

Get the object for a key.

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

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

Definition at line 156 of file RDirectory.hxx.

◆ Heap()

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

Dedicated, process-wide RDirectory.

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 RFile.cxx.

◆ Remove()

bool ROOT::Experimental::RDirectory::Remove ( std::string_view  name)
inline

Remove entry from RDirectory (if exists)

Definition at line 190 of file RDirectory.hxx.

Member Data Documentation

◆ fContent

ContentMap_t ROOT::Experimental::RDirectory::fContent
private

The RDirectory's content.

Definition at line 81 of file RDirectory.hxx.

Libraries for ROOT::Experimental::RDirectory:

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