Tuple.h
Go to the documentation of this file.
1 #ifndef GAUDIALG_TUPLE_H
2 #define GAUDIALG_TUPLE_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <string>
9 
10 // ============================================================================
18 // ============================================================================
19 
20 // ============================================================================
28 // ============================================================================
29 
30 #include "GaudiAlg/TupleObj.h"
31 
32 namespace Tuples
33 {
34 
35  template <class ITEM> class TupleItem ;
36 
115  class GAUDI_API Tuple
116  {
117  public:
118 
123  Tuple ( TupleObj* tuple ) ;
124 
126  Tuple ( const Tuple& tuple ) ;
127 
129  virtual ~Tuple() ;
130 
135  Tuple& operator=( const Tuple& tuple ) ;
136 
140  TupleObj* operator-> () const { return tuple () ; }
141 
143  bool valid () const { return 0 != tuple () ; }
144 
145  protected:
146 
148  TupleObj* tuple() const { return m_tuple ; }
149 
150  private:
151 
153  Tuple();
154 
155  private:
156 
158  TupleObj* m_tuple ;
159 
160  };
161 
274  template<class ITEM>
275  class TupleColumn
276  {
277  public:
278  TupleColumn ( const std::string& name ,
279  const ITEM& value )
280  : m_name ( name ) , m_value ( value ) {}
281  public:
283  const std::string& name () const { return m_name ; }
285  const ITEM& value () const { return m_value ; }
286  private:
287  TupleColumn();
288  private:
289  std::string m_name ;
290  ITEM m_value ;
291  };
292 
296  template<class ITEM>
297  inline TupleColumn<ITEM>
298  make_column ( const std::string& name , const ITEM& item )
299  { return TupleColumn<ITEM> ( name , item ) ; }
300 
304  template<class ITEM>
305  inline TupleColumn<const ITEM*>
306  make_column ( const std::string& name , const ITEM* item )
307  { return TupleColumn<const ITEM*>( name , item ) ; }
308 
312  template<class ITEM>
313  inline TupleColumn<ITEM*>
314  make_column ( const std::string& name , ITEM* item )
315  { return TupleColumn<ITEM*> ( name , item ) ; }
316 
317  template<class ITEM>
318  inline TupleColumn<ITEM>
319  Column ( const std::string& name , const ITEM& item )
320  { return make_column ( name , item ) ; }
321 
322  template<class ITEM>
323  inline TupleColumn<const ITEM*>
324  Column ( const std::string& name , const ITEM* item )
325  { return make_column ( name , item ) ; }
326 
327  template<class ITEM>
328  inline TupleColumn<ITEM*>
329  Column ( const std::string& name , ITEM* item )
330  { return make_column ( name , item ) ; }
331 
332 } // end of the namespace Tuples
333 
334 // ============================================================================
336 // ============================================================================
337 template <class ITEM>
338 inline Tuples::Tuple& operator<<
339  ( Tuples::Tuple& tuple ,
341 {
342  if ( !tuple.valid() ) { return tuple ; } // no action for invalid tuple
343  tuple->column( item.name() , item.value () ) ;
344  return tuple ;
345 }
346 // ============================================================================
347 
348 
349 
350 // ============================================================================
351 // THe END
352 // ============================================================================
353 #endif // GAUDIALG_TUPLE_H
354 // ============================================================================
#define GAUDI_API
Definition: Kernel.h:108
TupleColumn< ITEM > Column(const std::string &name, const ITEM &item)
Definition: Tuple.h:319
const ITEM & value() const
Return the column value.
Definition: Tuple.h:285
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: Tuple.h:115
const std::string & name() const
Return the column name.
Definition: Tuple.h:283
StatusCode column(const std::string &name, const float value)
Set the value for selected tuple column.
Definition: TupleObj.cpp:337
ITEM m_value
The column value.
Definition: Tuple.h:290
Helper class which allows to extend the functionality of Tuple with possibility to use your own repre...
Definition: Tuple.h:275
tuple item
print s1,s2
Definition: ana.py:146
std::string m_name
The column name.
Definition: Tuple.h:289
TupleColumn< ITEM > make_column(const std::string &name, const ITEM &item)
helper function to create 'on-the-fly' the helper object Tuples::TupleColumn
Definition: Tuple.h:298
General namespace for Tuple properties.
Definition: Maps.h:35