| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Private Attributes | List of all members
Tuples::TupleColumn< ITEM > Class Template Reference

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

`#include <GaudiAlg/Tuple.h>`

Collaboration diagram for Tuples::TupleColumn< ITEM >:
[legend]

## Public Member Functions
| TupleColumn ()=delete
| TupleColumn (std::string name, ITEM value)
const std::string & | name () 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 ,
const Tuples::TupleColumn<MyClass>& item )
{
// 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 ,
const Tuples::TupleColumn<const MCParticle*>& item )
{
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 276 of file Tuple.h.

## Constructor & Destructor Documentation

template<class ITEM>

Tuples::TupleColumn< ITEM >::TupleColumn | ( |  | ) |
| delete

template<class ITEM>

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

Definition at line 280 of file Tuple.h.

282 : m_name ( std::move(name) ) , m_value ( std::move(value) ) {}
Tuples::TupleColumn::value
const ITEM & value() const
Return the column value.
Definition: Tuple.h:287
Tuples::TupleColumn::m_value
ITEM m_value
The column value.
Definition: Tuple.h:290
std::move
T move(T...args)
Tuples::TupleColumn::m_name
std::string m_name
The column name.
Definition: Tuple.h:289

## Member Function Documentation

template<class ITEM>

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

Return the column name.

Definition at line 285 of file Tuple.h.

285 { return m_name ; }
Tuples::TupleColumn::m_name
std::string m_name
The column name.
Definition: Tuple.h:289
template<class ITEM>

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

Return the column value.

Definition at line 287 of file Tuple.h.

287 { return m_value ; }
Tuples::TupleColumn::m_value
ITEM m_value
The column value.
Definition: Tuple.h:290

## Member Data Documentation

template<class ITEM>

std::string Tuples::TupleColumn< ITEM >::m_name
| private

The column name.

Definition at line 289 of file Tuple.h.

template<class ITEM>

ITEM Tuples::TupleColumn< ITEM >::m_value
| private

The column value.

Definition at line 290 of file Tuple.h.

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

- GaudiAlg/GaudiAlg/Tuple.h