Belle II Software light-2406-ragdoll
SetMergeable< T > Class Template Reference

Wrap an STL set to make it mergeable. More...

#include <SetMergeable.h>

Inheritance diagram for SetMergeable< T >:
Collaboration diagram for SetMergeable< T >:

Public Member Functions

template<class ... Args>
 SetMergeable (Args &&... params)
 Constructor, forwards all arguments to T constructor.
 
T & get ()
 Get the wrapped standard object.
 
const T & get () const
 Get the wrapped standard object.
 
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 ()
 An ugly little method that is called before event() for input and worker processes.
 
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 (SetMergeable, 1)
 Wrap an STL set to make it mergeable.
 
 ClassDef (Mergeable, 0)
 Abstract base class for objects that can be merged.
 

Private Attributes

m_wrapped
 Wrapped object.
 

Detailed Description

template<class T>
class Belle2::SetMergeable< T >

Wrap an STL set to make it mergeable.

Should work out-of-the-box with std::set and 'similar' containers.

To use it to save data in your module:

setPropertyFlags(c_Parallelprocessing | c_terminateInAllProcesses);

create SetMergeable<X> in initalize (or in your constructor) of durability DataStore::c_Persistent, register it by calling registerInDataStore() and construct() the actual container.

Each template instance needs its own entry in framework/pcore/include/linkdef.h, please contact the framework librarian if your use case requires other classes than those in there.

See also
Mergeable

Definition at line 35 of file SetMergeable.h.

Constructor & Destructor Documentation

◆ SetMergeable() [1/2]

SetMergeable ( )
inline

Definition at line 37 of file SetMergeable.h.

37: m_wrapped() { }
T m_wrapped
Wrapped object.
Definition: SetMergeable.h:79

◆ ~SetMergeable()

virtual ~SetMergeable ( )
inlinevirtual

Definition at line 39 of file SetMergeable.h.

39{ }

◆ SetMergeable() [2/2]

SetMergeable ( Args &&...  params)
inlineexplicit

Constructor, forwards all arguments to T constructor.

Definition at line 41 of file SetMergeable.h.

41: m_wrapped(std::forward<Args>(params)...) { }

Member Function Documentation

◆ clear()

virtual void clear ( )
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 72 of file SetMergeable.h.

73 {
74 m_wrapped.clear();
75 }

◆ get() [1/2]

T & get ( )
inline

Get the wrapped standard object.

Definition at line 44 of file SetMergeable.h.

44{ return m_wrapped; }

◆ get() [2/2]

const T & get ( ) const
inline

Get the wrapped standard object.

Definition at line 47 of file SetMergeable.h.

47{ return m_wrapped; }

◆ merge()

virtual void merge ( const Mergeable other)
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 56 of file SetMergeable.h.

57 {
58 auto* otherMergeable = static_cast<const SetMergeable*>(other);
59 for (const auto& element : otherMergeable->get()) {
60 auto it = m_wrapped.find(element);
61 if (it == m_wrapped.end()) {
62 m_wrapped.insert(element);
63 }
64 }
65 }

◆ Merge()

Long64_t Merge ( TCollection *  hlist)
virtualinherited

Allow merging using TFileMerger if saved directly to a file.

Note
dictionaries containing your Mergeable class need to be loaded, so 'hadd' will not work currently.

Definition at line 14 of file Mergeable.cc.

15{
16 Long64_t nMerged = 0;
17 if (hlist) {
18 const Mergeable* xh = nullptr;
19 TIter nxh(hlist);
20 while ((xh = dynamic_cast<Mergeable*>(nxh()))) {
21 // Add xh to me
22 merge(xh);
23 ++nMerged;
24 }
25 }
26 return nMerged;
27}
Abstract base class for objects that can be merged.
Definition: Mergeable.h:31
virtual void merge(const Mergeable *other)=0
Merge object 'other' into this one.

◆ removeSideEffects()

virtual void removeSideEffects ( )
inlinevirtualinherited

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 in RootMergeable< T >.

Definition at line 58 of file Mergeable.h.

58{}

◆ Reset()

virtual void Reset ( )
inlinevirtualinherited

Root-like Reset function for "template compatibility" with ROOT objects.

Alias for clear().

Definition at line 66 of file Mergeable.h.

66{clear();}
virtual void clear()=0
Clear content of this object (e.g.

◆ SetDirectory()

virtual void SetDirectory ( TDirectory *  )
inlinevirtualinherited

Root-like SetDirectory function for "template compatibility" with ROOT objects.

Does nothing.

Definition at line 68 of file Mergeable.h.

68{}

Member Data Documentation

◆ m_wrapped

T m_wrapped
private

Wrapped object.

Definition at line 79 of file SetMergeable.h.


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