| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

# 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 <Tuple.h>`

Collaboration diagram for Tuples::TupleColumn< ITEM >:

[legend]

List of all members.

## Public Member Functions
| TupleColumn (const std::string &name, const ITEM &value)
const std::string & | name () const
| Return the column name.
const ITEM & | value () const
| Return the column value.
## Private Member Functions
| TupleColumn ()
## Private Attributes
std::string | m_name
| The column name.
ITEM | m_value
| The column value.

## 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.Belyaev@itep.ru

Definition at line 278 of file Tuple.h.

## Constructor & Destructor Documentation

template<class ITEM>

Tuples::TupleColumn< ITEM >::TupleColumn | ( | const std::string & | name,
|  | const ITEM & | value |
| ) |  |  | `[inline]`

Definition at line 281 of file Tuple.h.

    00283       : m_name ( name ) , m_value  (  value  ) {}

template<class ITEM>

Tuples::TupleColumn< ITEM >::TupleColumn | ( |  | ) | `[private]`

## Member Function Documentation

template<class ITEM>

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

Return the column name.

Definition at line 286 of file Tuple.h.

    00286 { return m_name  ; }

template<class ITEM>

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

Return the column value.

Definition at line 288 of file Tuple.h.

    00288 { return m_value ; }

## Member Data Documentation

template<class ITEM>

std::string Tuples::TupleColumn< ITEM >::m_name`[private]`

The column name.

Definition at line 292 of file Tuple.h.

template<class ITEM>

ITEM Tuples::TupleColumn< ITEM >::m_value`[private]`

The column value.

Definition at line 293 of file Tuple.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r9/GaudiAlg/GaudiAlg/Tuple.h