Belle II Software development
|
Wrap a root histogram or TNtuple to make it mergeable. More...
#include <RootMergeable.h>
Public Member Functions | |
RootMergeable () | |
default constructor for root. | |
template<class ... Args> | |
RootMergeable (Args &&... params) | |
Constructor, forwards all arguments to T constructor. | |
void | assign (T *p) |
Replace wrapped object with p (takes ownership). | |
T & | get () |
Get the wrapped root object. | |
const T & | get () const |
Get the wrapped root object. | |
void | write (TDirectory *file) |
Write the wrapped object into 'file', overwriting existing objects of same name. | |
virtual void | merge (const Mergeable *other) override |
Merge object 'other' into this one. | |
virtual void | clear () override |
Clear content of this object (e.g. | |
virtual void | removeSideEffects () override |
An ugly little method that is called before event() for input and worker processes. | |
virtual void | RecursiveRemove (TObject *obj) override |
Called from ROOT if obj is deleted. | |
virtual Long64_t | Merge (TCollection *hlist) |
Allow merging using TFileMerger if saved directly to a file. | |
virtual void | Reset () |
Root-like Reset function for "template compatibility" with ROOT objects. | |
virtual void | SetDirectory (TDirectory *) |
Root-like SetDirectory function for "template compatibility" with ROOT objects. | |
Private Member Functions | |
ClassDefOverride (RootMergeable, 2) | |
Wrap a root histogram or ntuple to make them mergeable. | |
ClassDef (Mergeable, 0) | |
Abstract base class for objects that can be merged. | |
Private Attributes | |
T * | m_wrapped |
Wrapped root object. | |
Wrap a root histogram or TNtuple to make it mergeable.
To use it to save data in your module:
create RootMergeable<X> in initalize (or in your constructor) of durability DataStore::c_Persistent, register it by calling registerInDataStore() and construct() the actual histogram. Especially for larger TTrees, you should also create a TFile and cd() into it before creating the histogram. To actually save the objects, use the following in terminate() to ensure this is done only in the output process (where the data from all events will be collected):
This should work out of the box for TTree, TNtuple, TH1F, TH2F, TH1D, and TH2D. Additional template instantiations need an entry in framework/pcore/include/linkdef.h, please contact the framework librarian if your use case requires other classes.
Be aware that for larger histograms, this way of sharing the data may not be a good idea. E.g. for hundred thousand bins, basf2 would transfer about half a megabyte in each event, which may take a significant fraction of total processing time. Trees or Ntuples will however only transfer the newly added data, which is probably manageable.
To deal with ownership issues arising from objects belonging to TFiles, each RootMergeable object is added to the global list gROOT->GetListOfCleanups(), which will ensure RootMergeable::RecursiveRemove() is called when m_wrapped is deleted.
Definition at line 61 of file RootMergeable.h.
|
inline |
|
inlineexplicit |
Constructor, forwards all arguments to T constructor.
Definition at line 66 of file RootMergeable.h.
|
inlinevirtual |
Definition at line 72 of file RootMergeable.h.
|
inline |
Replace wrapped object with p (takes ownership).
Definition at line 79 of file RootMergeable.h.
|
inlineoverridevirtual |
Clear content of this object (e.g.
set to zeroes).
Called after sending the objects to another process. If no clearing is performed, the same data (e.g. histogram entries) might be added again and again in each event.
Implements Mergeable.
Definition at line 130 of file RootMergeable.h.
|
inline |
|
inline |
|
inlineoverridevirtual |
Merge object 'other' into this one.
Your derived class should implement this function. You can static_cast 'other' to your own type (when called, this and other are guaranteed to point to objects of the same type).
Note that 'other' will be deleted after the merge, so make sure you copy all data from it that you will need.
Implements Mergeable.
Definition at line 115 of file RootMergeable.h.
|
virtualinherited |
Allow merging using TFileMerger if saved directly to a file.
Definition at line 14 of file Mergeable.cc.
|
inlineoverridevirtual |
Called from ROOT if obj is deleted.
Kill pointer to avoid double free.
Definition at line 150 of file RootMergeable.h.
|
inlineoverridevirtual |
An ugly little method that is called before event() for input and worker processes.
Main use case is to detach any attached TFile from this object. In the output process, it can stay attached (and grow as much as it likes).
Reimplemented from Mergeable.
Definition at line 140 of file RootMergeable.h.
|
inlinevirtualinherited |
Root-like Reset function for "template compatibility" with ROOT objects.
Alias for clear().
Definition at line 66 of file Mergeable.h.
|
inlinevirtualinherited |
Root-like SetDirectory function for "template compatibility" with ROOT objects.
Does nothing.
Definition at line 68 of file Mergeable.h.
|
inline |
Write the wrapped object into 'file', overwriting existing objects of same name.
This function should be prefered to calling Write() by hand.
Definition at line 98 of file RootMergeable.h.
|
private |
Wrapped root object.
Definition at line 158 of file RootMergeable.h.