The Gaudi Framework  v30r3 (a5ef0a68)
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 #include "GaudiKernel/SmartIF.h"
32 
33 namespace Tuples
34 {
35 
36  template <class ITEM>
37  class TupleItem;
38 
118  {
119  public:
124  Tuple( std::shared_ptr<TupleObj> tuple ) : m_tuple( std::move( tuple ) ) {}
125 
126  virtual ~Tuple() = default;
127 
131  TupleObj* operator->() const { return m_tuple.get(); }
132 
134  bool valid() const { return static_cast<bool>( m_tuple ); }
135 
136  protected:
137  TupleObj* tuple() { return m_tuple.get(); }
138 
139  private:
142  };
143 
256  template <class ITEM>
258  {
259  public:
260  TupleColumn( std::string name, ITEM value ) : m_name( std::move( name ) ), m_value( std::move( value ) ) {}
261 
263  const std::string& name() const { return m_name; }
265  const ITEM& value() const { return m_value; }
266 
267  private:
269  ITEM m_value;
270  };
271 
275  template <class ITEM>
276  inline TupleColumn<ITEM> make_column( std::string name, const ITEM& item )
277  {
278  return {std::move( name ), item};
279  }
280 
284  template <class ITEM>
286  {
287  return {std::move( name ), item};
288  }
289 
293  template <class ITEM>
295  {
296  return {std::move( name ), item};
297  }
298 
299  template <class ITEM>
300  inline TupleColumn<ITEM> Column( std::string name, const ITEM& item )
301  {
302  return make_column( std::move( name ), item );
303  }
304 
305  template <class ITEM>
306  inline TupleColumn<const ITEM*> Column( std::string name, const ITEM* item )
307  {
308  return make_column( std::move( name ), item );
309  }
310 
311  template <class ITEM>
313  {
314  return make_column( std::move( name ), item );
315  }
316 
317 } // end of the namespace Tuples
318 
319 // ============================================================================
321 // ============================================================================
322 template <class ITEM>
323 inline Tuples::Tuple& operator<<( Tuples::Tuple& tuple, const Tuples::TupleColumn<ITEM>& item )
324 {
325  if ( !tuple.valid() ) return tuple; // no action for invalid tuple
326  tuple->column( item.name(), item.value() );
327  return tuple;
328 }
329 // ============================================================================
330 
331 // ============================================================================
332 // THe END
333 // ============================================================================
334 #endif // GAUDIALG_TUPLE_H
335 // ============================================================================
Header file for class TupleObj.
StatusCode column(const std::string &name, float value)
Set the value for selected tuple column.
Definition: TupleObj.cpp:315
TupleObj * tuple()
Definition: Tuple.h:137
STL namespace.
const ITEM & value() const
Return the column value.
Definition: Tuple.h:265
std::shared_ptr< TupleObj > m_tuple
The (shared) tuple object.
Definition: Tuple.h:141
STL class.
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: Tuple.h:117
const std::string & name() const
Return the column name.
Definition: Tuple.h:263
Tuple(std::shared_ptr< TupleObj > tuple)
standard constructor
Definition: Tuple.h:124
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: TupleObj.h:204
TupleColumn< ITEM > make_column(std::string name, const ITEM &item)
helper function to create &#39;on-the-fly&#39; the helper object Tuples::TupleColumn
Definition: Tuple.h:276
ITEM m_value
The column value.
Definition: Tuple.h:269
bool valid() const
check the validity of the tuple object
Definition: Tuple.h:134
T move(T...args)
Helper class which allows to extend the functionality of Tuple with possibility to use your own repre...
Definition: Tuple.h:257
std::string m_name
The column name.
Definition: Tuple.h:268
TupleObj * operator->() const
get the pointer to the underlying object
Definition: Tuple.h:131
#define GAUDI_API
Definition: Kernel.h:104
TupleColumn(std::string name, ITEM value)
Definition: Tuple.h:260
TupleColumn< ITEM > Column(std::string name, const ITEM &item)
Definition: Tuple.h:300
General namespace for Tuple properties.
Definition: Maps.h:34