The Gaudi Framework  v36r9p1 (5c15b2bb)
Tuples::TupleColumn< ITEM > Class Template Reference

#include </builds/gaudi/Gaudi/GaudiAlg/include/GaudiAlg/Tuple.h>

Collaboration diagram for Tuples::TupleColumn< ITEM >:

Public Member Functions

 TupleColumn (std::string name, ITEM value)
 
const std::stringname () const
 Return the column name. More...
 
const ITEM & value () const
 Return the column value. More...
 

Private Attributes

std::string m_name
 The column name. More...
 
ITEM m_value
 The column value. More...
 

Detailed Description

template<class ITEM>
class Tuples::TupleColumn< ITEM >

Helper class which allows to extend the functionality of Tuple with possibility to use your own representation of complex objects.

It allows to extend the functionality of Tuples::Tuple and Tuples::TupleObj classes for your own needs, according to your own taste and without touching the classes at all. Neither the extension or the functionality through inheritance nor the extension through aggregation is used. One use the trick with template specialization of streamer operators.

Assuming one need to add into private code the N-Tuple representation of e.g. MyClass class

// 0) Class which needs N-Tuple representation
class MyClass
{
...
double field1() const ;
double field2() const ;
long field3() const ;
bool field4() const ;
};
// 1) define specialization of operator with needed
// representation
template <>
inline Tuples::Tuple& operator<<
( Tuples::Tuple& tuple ,
{
// no action for invalid tuple
if( !tuple.valid() ) { return tuple ;}
tuple->column( item.name() + "field1" , item.value().field1() );
tuple->column( item.name() + "field2" , item.value().field2() );
tuple->column( item.name() + "field3" , item.value().field3() );
tuple->column( item.name() + "field4" , item.value().field4() );
return tuple ;
}
// 3) use the operator to 'stream' objects of type MyClass ito
// N-Tuple:
Tuple tuple = ... ;
MyClass a = ... ;
tuple << Tuples::make_column( "A" , a ) ;
// operators can be chained:
MyClass a1 = ... ;
MyClass a2 = ... ;
MyClass a3 = ... ;
tuple << Tuples::make_column( "A1" , a1 )
<< Tuples::make_column( "A2" , a2 )
<< Tuples::make_column( "A3" , a3 ) ;

Alternatively one can use function Tuples::Column

//
MyClass a1 = ... ;
MyClass a2 = ... ;
MyClass a3 = ... ;
tuple << Tuples::Column( "A1" , a1 )
<< Tuples::Column( "A2" , a2 )
<< Tuples::Column( "A3" , a3 ) ;

Using this technique one can put 'any' object into NTuple and create the own representation. E.g. if the 'standard' representation of HepLorentzVector is not suitable one can create the alternative representation.

Also one can create own representations of complex classes, e.g. class MCParticle :

template <>
inline Tuples::Tuple& operator<<
( Tuples::Tuple& tuple ,
{
if( !tuple.valid() ) { return tuple ;}
const MCParticle* mcp = item.value() ;
tuple->column( item.name() + "Mom" , mcp->momentum() ) ;
tuple->column( item.name() + "PID" , mcp->particleID().pid() ) ;
tuple->column( item.name() + "hasVX" , 0 != mcp->originVertex() ) ;
};
Tuple tuple = ... ;
const MCParticle* mcp = ... ;
tuple << Tuples::Column( "MCP" , mcp ) ;
Author
Vanya BELYAEV Ivan..nosp@m.Bely.nosp@m.aev@i.nosp@m.tep..nosp@m.ru

Definition at line 265 of file Tuple.h.

Constructor & Destructor Documentation

◆ TupleColumn()

template<class ITEM >
Tuples::TupleColumn< ITEM >::TupleColumn ( std::string  name,
ITEM  value 
)
inline

Definition at line 267 of file Tuple.h.

267 : m_name( std::move( name ) ), m_value( std::move( value ) ) {}

Member Function Documentation

◆ name()

template<class ITEM >
const std::string& Tuples::TupleColumn< ITEM >::name ( ) const
inline

Return the column name.

Definition at line 270 of file Tuple.h.

270 { return m_name; }

◆ value()

template<class ITEM >
const ITEM& Tuples::TupleColumn< ITEM >::value ( ) const
inline

Return the column value.

Definition at line 272 of file Tuple.h.

272 { return m_value; }

Member Data Documentation

◆ m_name

template<class ITEM >
std::string Tuples::TupleColumn< ITEM >::m_name
private

The column name.

Definition at line 275 of file Tuple.h.

◆ m_value

template<class ITEM >
ITEM Tuples::TupleColumn< ITEM >::m_value
private

The column value.

Definition at line 276 of file Tuple.h.


The documentation for this class was generated from the following file:
AutoLoadUnmetDataInputs.a2
a2
Definition: AutoLoadUnmetDataInputs.py:43
Tuples::TupleObj::column
StatusCode column(std::string_view name, float value)
Set the value for selected tuple column.
Definition: TupleObj.cpp:267
std::move
T move(T... args)
GaudiPython.GaudiAlgs.Tuple
Tuple
Definition: GaudiAlgs.py:1174
Tuples::TupleColumn
Definition: Tuple.h:265
AutoLoadUnmetDataInputs.a1
a1
Definition: AutoLoadUnmetDataInputs.py:41
Tuples::make_column
TupleColumn< ITEM > make_column(std::string name, const ITEM &item)
helper function to create 'on-the-fly' the helper object Tuples::TupleColumn
Definition: Tuple.h:283
AutoLoadUnmetDataInputs.a3
a3
Definition: AutoLoadUnmetDataInputs.py:46
Tuples::Tuple
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: Tuple.h:126
Tuples::TupleColumn::name
const std::string & name() const
Return the column name.
Definition: Tuple.h:270
Tuples::TupleColumn::m_name
std::string m_name
The column name.
Definition: Tuple.h:275
Tuples::TupleColumn::m_value
ITEM m_value
The column value.
Definition: Tuple.h:276
Tuples::Column
TupleColumn< ITEM > Column(std::string name, const ITEM &item)
Definition: Tuple.h:304
Tuples::TupleColumn::value
const ITEM & value() const
Return the column value.
Definition: Tuple.h:272