A helper to manage ROOT objects with consistent naming. More...
#include <PlotSandbox.h>
Classes | |
struct | Data_t |
The whole data in a convenient package! More... | |
struct | TFileDirectoryHelper |
Contains both a art::TFileDirectory and the TDirectory it manages. More... | |
Public Member Functions | |
PlotSandbox (art::TFileDirectory parentDir, std::string name, std::string desc) | |
Constructor: specifies all sandbox characteristics. More... | |
PlotSandbox (PlotSandbox const &)=delete | |
PlotSandbox (PlotSandbox &&from) | |
PlotSandbox & | operator= (PlotSandbox const &)=delete |
PlotSandbox & | operator= (PlotSandbox &&from)=delete |
virtual | ~PlotSandbox ()=default |
Virtual destructor. Default, but C++ wants it. More... | |
bool | hasName () const |
Returns whether we have a non-empty name. More... | |
std::string const & | name () const |
Returns the sandbox name. More... | |
bool | hasDescription () const |
Returns whether we have a non-empty description. More... | |
std::string const & | description () const |
Returns the sandbox description. More... | |
virtual std::string const & | Description () const |
std::string | ID () const |
Returns a string ID for this sandbox. More... | |
virtual std::string | processName (std::string const &name) const |
Processes the specified string as it were a name. More... | |
virtual std::string | processTitle (std::string const &title) const |
Processes the specified string as it were a description or title. More... | |
bool | deleteSubSandbox (std::string const &name) |
Deletes the subbox with the specified name and its directory. More... | |
template<typename Stream > | |
void | dump (Stream &&out, std::string indent, std::string firstIndent) const |
Dumps the hierarchy of sandboxes into the specified stream. More... | |
template<typename Stream > | |
void | dump (Stream &&out, std::string indent="") const |
Dumps the hierarchy of sandboxes into the specified stream. More... | |
ROOT object management | |
bool | empty () const |
Returns if the sandbox is empty (neither it nor subboxes hold objects). More... | |
template<typename Obj = TObject> | |
Obj const * | get (std::string const &name) const |
Fetches the object with the specified name from the sandbox. More... | |
template<typename Obj = TObject> | |
Obj * | use (std::string const &name) const |
Fetches an object with the specified name to be modified. More... | |
template<typename Obj = TObject> | |
Obj & | demand (std::string const &name) const |
Fetches an object with the specified name to be modified. More... | |
template<typename DirObj = TDirectory> | |
DirObj * | getDirectory () const |
Fetches the base directory of the sandbox. More... | |
template<typename DirObj = TDirectory> | |
DirObj * | getDirectory (std::string const &path) const |
Fetches the directory with the specified name from the sandbox. More... | |
template<typename Obj , typename... Args> | |
Obj * | make (std::string const &name, std::string const &title, Args &&...args) |
Creates a new ROOT object with the specified name and title. More... | |
Contained sandboxes | |
template<typename SandboxType = PlotSandbox, typename... Args> | |
SandboxType & | addSubSandbox (std::string const &name, std::string const &desc, Args &&...args) |
Creates a new sandbox contained in this one. More... | |
std::size_t | nSubSandboxes () const |
Returns the number of contained sand boxes. More... | |
PlotSandbox const * | findSandbox (std::string const &name) const |
Returns the first contained sandbox with the specified name. More... | |
PlotSandbox * | findSandbox (std::string const &name) |
PlotSandbox const & | demandSandbox (std::string const &name) const |
Returns the first contained sandbox with the specified name. More... | |
PlotSandbox & | demandSandbox (std::string const &name) |
decltype(auto) | subSandboxes () const |
Returns an object proper to iterate through all contained sand boxes. More... | |
decltype(auto) | subSandboxes () |
Protected Member Functions | |
PlotSandbox (PlotSandbox const &parent, std::string name, std::string desc) | |
Constructor: specifies all sandbox characteristics. More... | |
virtual void | setParent (PlotSandbox const *parent) |
Sets the parent of this box. More... | |
std::string | processPlotTitle (std::string const &title) const |
Applies title processing only at the title part of the string. More... | |
virtual std::string | processedSandboxName () const |
virtual std::string | processedSandboxDesc () const |
template<typename Stream > | |
void | dumpContent (Stream &&out, std::string indent, std::string firstIndent) const |
Dumps the content of this box (nosubboxes) into out stream. More... | |
Static Private Member Functions | |
template<typename SandboxType > | |
static auto * | findSandbox (SandboxType &sandbox, std::string const &name) |
Helper function for findSandbox() implementations. More... | |
template<typename SandboxType > | |
static auto & | demandSandbox (SandboxType &sandbox, std::string const &name) |
Helper function for demandSandbox() implementations. More... | |
Private Attributes | |
struct icarus::trigger::PlotSandbox::Data_t | fData |
Object creation specializations | |
These are implementation details.
A few basic tools are provided, which support specific types of objects:
Building on that, different overloads of Note that in this strategy it is not possible to use a constructor without name and title for an object that also supports the construction with name and title: as long as Also note that no name decoration happens at this level: all object names and titles are expected to be final (processing happens e.g. in | |
template<typename Obj , typename... Args> | |
Obj * | makeWithNameTitle (art::TFileDirectory &destDir, std::string const &name, std::string const &title, Args &&...args) const |
Creates, stores and returns a new object. More... | |
template<typename Obj , typename... Args> | |
Obj * | makeAndSetNameTitle (art::TFileDirectory &destDir, std::string const &name, std::string const &title, Args &&...args) const |
Creates, stores and returns a new object. More... | |
template<typename Obj , typename... Args> | |
Obj * | doConstruct (art::TFileDirectory &destDir, TObject *, std::string const &name, std::string const &title, Args &&...args) const |
General implementation: creates and registers an Obj (name and title used in Obj constructor). More... | |
template<typename GraphObj , typename... Args> | |
GraphObj * | doConstruct (art::TFileDirectory &destDir, TGraph *, std::string const &name, std::string const &title, Args &&...args) const |
Implementation for TGraph -derived objects. More... | |
static std::pair< std::string, std::string > | splitPath (std::string const &path, char sep= '/') |
static std::string | joinPath (std::initializer_list< std::string > pathElements, char sep= '/') |
A helper to manage ROOT objects with consistent naming.
A sandbox includes a ROOT directory where all the objects are written. It also provides a name pattern to modify a generic object name in one specific to this sandbox, e.g. from "HEnergy"
to "HMuonNeutrinoEnergy"
. Object descriptions (usually titles) may also be processed in the same way.
In addition, the sandbox can point to a parent sandbox, in which case the names and descriptions are first processed by this sandbox and then passed to that parent sandbox for further processing.
The sandbox has two characterizing strings:
"MuonNeutrino"
or "CC"
. This string becoming part of the ROOT object name, it is better to keep it short and simply alphanumeric."#nu_{#mu}"
or "charged current"
.Definition at line 95 of file PlotSandbox.h.
icarus::trigger::PlotSandbox::PlotSandbox | ( | art::TFileDirectory | parentDir, |
std::string | name, | ||
std::string | desc | ||
) |
Constructor: specifies all sandbox characteristics.
parentDir | ROOT directory under which the sandbox is created |
name | the name of the sandbox |
desc | description of the sandbox |
If the name
is empty, as a special case, the sandbox is unnamed and it is created directly in parentDir
. In that case, the title of the output directory (parentDir
) is also not changed. If name
or desc
are empty, the pertaining processing is not performed: if name
is empty, ROOT object names will be unchanged, and if desc
is empty their descriptions/titles will be.
To create a sandbox with a parent, call addSubSandbox()
of that parent.
Definition at line 80 of file PlotSandbox.cxx.
|
delete |
icarus::trigger::PlotSandbox::PlotSandbox | ( | PlotSandbox && | from | ) |
Definition at line 93 of file PlotSandbox.cxx.
|
virtualdefault |
Virtual destructor. Default, but C++ wants it.
|
protected |
Constructor: specifies all sandbox characteristics.
parent | the sandbox used as parent |
name | the name of the sandbox |
desc | description of the sandbox |
Compared to the public constructor, this one picks the parent directory to be the output directory of the parent
sandbox, and it registers that parent
box as parent. Note that this constructor does not update the list of subboxes of the parent.
Definition at line 192 of file PlotSandbox.cxx.
SandboxType & icarus::trigger::PlotSandbox::addSubSandbox | ( | std::string const & | name, |
std::string const & | desc, | ||
Args &&... | args | ||
) |
Creates a new sandbox contained in this one.
SandboxType | (default: PlotSandbox ) type of sandbox to be created |
Args | types of the additional arguments for the sandbox constructor |
name | name of the new contained sand box |
desc | description of the new contained sand box |
args | additional arguments for the sandbox constructor |
cet::exception | (category: "PlotSandbox" ) if a sandbox with this name already exists. |
The arguments of this method are equivalent to the ones of the constructor.
The new sand box parent is set to point to this sand box.
Definition at line 723 of file PlotSandbox.h.
bool icarus::trigger::PlotSandbox::deleteSubSandbox | ( | std::string const & | name | ) |
Deletes the subbox with the specified name
and its directory.
name
Definition at line 174 of file PlotSandbox.cxx.
Obj & icarus::trigger::PlotSandbox::demand | ( | std::string const & | name | ) | const |
Fetches an object with the specified name to be modified.
Obj | (default: TObject ) type of the object to fetch |
name | unprocessed name and path of the object to fetch |
cet::exception | (category: "PlotSandbox" ) if no object with name exists in the box |
This method is equivalent to use()
, with the difference that the returned object must exist.
Definition at line 667 of file PlotSandbox.h.
|
staticprivate |
Helper function for demandSandbox()
implementations.
Definition at line 750 of file PlotSandbox.h.
auto icarus::trigger::PlotSandbox::demandSandbox | ( | std::string const & | name | ) | const |
Returns the first contained sandbox with the specified name.
name | unprocessed name of the box to be retrieved |
cet::exception | (category: "PlotSandbox" ) if no a sandbox with this name exists |
findSandbox()
Definition at line 168 of file PlotSandbox.cxx.
auto icarus::trigger::PlotSandbox::demandSandbox | ( | std::string const & | name | ) |
Definition at line 164 of file PlotSandbox.cxx.
|
inline |
Returns the sandbox description.
Definition at line 202 of file PlotSandbox.h.
|
inlinevirtual |
Returns the sandbox description for use at the beginning of a sentence.
Definition at line 206 of file PlotSandbox.h.
|
protected |
General implementation: creates and registers an Obj
(name and title used in Obj
constructor).
Obj | type of the object to construct |
Args | type of additional arguments to Obj constructor, if any |
destDir | art::TFileDirectory where to store the object |
obj | pointer to Obj ; unused except to direct C++ overloading |
name | final name of the object |
title | final title of the object |
args | additional arguments to Obj constructor |
This is the most fundamental method constructing an object, which is used as fallback for all TObject
-derived objects if nothing more appropriate is available. It is also the best option in general, when Obj
supports it. It requires Obj
to have a constructor whose first two arguments are name and title of the object.
Definition at line 795 of file PlotSandbox.h.
|
protected |
Implementation for TGraph
-derived objects.
GraphObj | type of TGraph -derived object to construct |
Args | type of arguments to GraphObj constructor, if any |
destDir | art::TFileDirectory where to store the object |
graph | pointer to GraphObj ; unused except to direct C++ overloading |
name | final name of the graph object |
title | final title of the graph object |
args | arguments to GraphObj constructor |
This method manages the creation of objects derived from TGraph
. Note that TGraph
itself does feature a constructor with two strings as first arguments, but that is not the standard name/title constructor (in fact, there is no such standard constructor for TGraph
, and that matching one takes a text file path for input and an option string...).
The name and title of the graph are still set, via SetName()
and SetTitle()
(this action is delegated to TFileDirectory::makeAndRegister()
).
Definition at line 808 of file PlotSandbox.h.
void icarus::trigger::PlotSandbox::dump | ( | Stream && | out, |
std::string | indent, | ||
std::string | firstIndent | ||
) | const |
Dumps the hierarchy of sandboxes into the specified stream.
Definition at line 822 of file PlotSandbox.h.
|
inline |
Dumps the hierarchy of sandboxes into the specified stream.
Definition at line 389 of file PlotSandbox.h.
|
protected |
Dumps the content of this box (nosubboxes) into out
stream.
Definition at line 844 of file PlotSandbox.h.
bool icarus::trigger::PlotSandbox::empty | ( | ) | const |
Returns if the sandbox is empty (neither it nor subboxes hold objects).
Definition at line 124 of file PlotSandbox.cxx.
|
staticprivate |
Helper function for findSandbox()
implementations.
Definition at line 740 of file PlotSandbox.h.
auto icarus::trigger::PlotSandbox::findSandbox | ( | std::string const & | name | ) | const |
Returns the first contained sandbox with the specified name.
name | unprocessed name of the box to be retrieved |
nullptr
if not found demandSandbox()
Definition at line 158 of file PlotSandbox.cxx.
auto icarus::trigger::PlotSandbox::findSandbox | ( | std::string const & | name | ) |
Definition at line 154 of file PlotSandbox.cxx.
Obj const * icarus::trigger::PlotSandbox::get | ( | std::string const & | name | ) | const |
Fetches the object with the specified name from the sandbox.
Obj | (default: TObject ) type of the object to fetch |
name | unprocessed name and path of the object to fetch |
nullptr
if not available or wrong type use()
The name
specification may contain a ROOT path. The directory component of the path, defined by everything preceding a /
character, is not processed.
The fetched object is converted to the desired type via dynamic_cast
. If conversion fails, a null pointer is returned.
Definition at line 646 of file PlotSandbox.h.
DirObj * icarus::trigger::PlotSandbox::getDirectory | ( | ) | const |
Fetches the base directory of the sandbox.
nullptr
if wrong typeThe directory is converted to the desired type via dynamic_cast
. If conversion fails, a null pointer is returned.
Definition at line 683 of file PlotSandbox.h.
DirObj * icarus::trigger::PlotSandbox::getDirectory | ( | std::string const & | path | ) | const |
Fetches the directory with the specified name from the sandbox.
DirObj | (default: TDirectory ) type of ROOT directory object to get |
path | path of the directory to fetch within this sandbox |
nullptr
if not available or wrong typeThe fetched object is converted to the desired type via dynamic_cast
. If conversion fails, a null pointer is returned.
Definition at line 690 of file PlotSandbox.h.
|
inline |
Returns whether we have a non-empty description.
Definition at line 199 of file PlotSandbox.h.
|
inline |
Returns whether we have a non-empty name.
Definition at line 193 of file PlotSandbox.h.
std::string icarus::trigger::PlotSandbox::ID | ( | ) | const |
Returns a string ID for this sandbox.
Definition at line 101 of file PlotSandbox.cxx.
|
staticprotected |
Merges the pieces of path that are not empty into a path. One separator at the end of each piece is ignored.
Definition at line 269 of file PlotSandbox.cxx.
Obj * icarus::trigger::PlotSandbox::make | ( | std::string const & | name, |
std::string const & | title, | ||
Args &&... | args | ||
) |
Creates a new ROOT object with the specified name and title.
Obj | type of ROOT object to be created |
Args | types of the argumenst to be forwarded to the constructor |
name | unprocessed name of the new object |
title | unprocessed title of the new object |
args | additional arguments forwarded to the constructor |
The name and title are processed with processName()
and processTitle()
method respectively, before the object is created.
Definition at line 701 of file PlotSandbox.h.
|
protected |
Creates, stores and returns a new object.
Obj | type of the new object to create |
Args | type of the additional arguments to Obj constructor |
destDir | the art::TFileDirectory where the object is stored |
name | final name of the object to be created |
title | final title of the object to be created |
args | additional arguments to Obj constructor, if any |
makeAndRegister()
This method registers a new object into destDir
via art::TFileDirectory::makeAndRegister()
, using only the constructor arguments specified in args
. The name
and title
are set afterwards via SetName()
and SetTitle()
.
Definition at line 785 of file PlotSandbox.h.
|
protected |
Creates, stores and returns a new object.
Obj | type of the new object to create |
Args | type of the additional arguments to Obj constructor |
destDir | the art::TFileDirectory where the object is stored |
name | final name of the object to be created |
title | final title of the object to be created |
args | additional arguments to Obj constructor, if any |
makeAndSetNameTitle()
This method registers a new object into destDir
via art::TFileDirectory::makeAndRegister()
, using the name
and title
as the first arguments of the constructor.
Definition at line 774 of file PlotSandbox.h.
|
inline |
Returns the sandbox name.
Definition at line 196 of file PlotSandbox.h.
|
inline |
Returns the number of contained sand boxes.
Definition at line 341 of file PlotSandbox.h.
|
delete |
|
delete |
|
protectedvirtual |
Returns a processed version of the description of this sandbox.
This may be used when integrating the sandbox description into the processed object descriptions.
Definition at line 242 of file PlotSandbox.cxx.
|
protectedvirtual |
Returns a processed version of the name of this sandbox.
This may be used when integrating the sandbox name into the processed object names.
Definition at line 227 of file PlotSandbox.cxx.
|
virtual |
Processes the specified string as it were a name.
Definition at line 107 of file PlotSandbox.cxx.
|
protected |
Applies title processing only at the title part of the string.
Definition at line 200 of file PlotSandbox.cxx.
|
virtual |
Processes the specified string as it were a description or title.
Definition at line 116 of file PlotSandbox.cxx.
|
inlineprotectedvirtual |
Sets the parent of this box.
Definition at line 410 of file PlotSandbox.h.
|
staticprotected |
Retrieves or, if not present, creates a ROOT subdirectory in the sandbox. Returns a pair with the directory and the name part of path
. The directory part may be empty.
Definition at line 257 of file PlotSandbox.cxx.
|
inline |
Returns an object proper to iterate through all contained sand boxes.
Definition at line 369 of file PlotSandbox.h.
|
inline |
Definition at line 371 of file PlotSandbox.h.
Obj * icarus::trigger::PlotSandbox::use | ( | std::string const & | name | ) | const |
Fetches an object with the specified name to be modified.
Obj | (default: TObject ) type of the object to fetch |
name | unprocessed name and path of the object to fetch |
nullptr
if not available or wrong type get()
This method is fully equivalent to get()
, with the difference that the returned object may be modified.
Definition at line 652 of file PlotSandbox.h.
|
private |