Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  template <class ITEM>
36  class TupleItem;
37 
116  class GAUDI_API Tuple {
117  public:
122  Tuple( std::shared_ptr<TupleObj> tuple ) : m_tuple( std::move( tuple ) ) {}
123 
124  virtual ~Tuple() = default;
125 
129  TupleObj* operator->() const { return m_tuple.get(); }
130 
132  bool valid() const { return static_cast<bool>( m_tuple ); }
133 
134  protected:
135  TupleObj* tuple() { return m_tuple.get(); }
136 
137  private:
140  };
141 
254  template <class ITEM>
255  class TupleColumn {
256  public:
257  TupleColumn( std::string name, ITEM value ) : m_name( std::move( name ) ), m_value( std::move( value ) ) {}
258 
260  const std::string& name() const { return m_name; }
262  const ITEM& value() const { return m_value; }
263 
264  private:
266  ITEM m_value;
267  };
268 
272  template <class ITEM>
273  inline TupleColumn<ITEM> make_column( std::string name, const ITEM& item ) {
274  return {std::move( name ), item};
275  }
276 
280  template <class ITEM>
281  inline TupleColumn<const ITEM*> make_column( std::string name, const ITEM* item ) {
282  return {std::move( name ), item};
283  }
284 
288  template <class ITEM>
290  return {std::move( name ), item};
291  }
292 
293  template <class ITEM>
294  inline TupleColumn<ITEM> Column( std::string name, const ITEM& item ) {
295  return make_column( std::move( name ), item );
296  }
297 
298  template <class ITEM>
299  inline TupleColumn<const ITEM*> Column( std::string name, const ITEM* item ) {
300  return make_column( std::move( name ), item );
301  }
302 
303  template <class ITEM>
304  inline TupleColumn<ITEM*> Column( std::string name, ITEM* item ) {
305  return make_column( std::move( name ), item );
306  }
307 
308 } // namespace Tuples
309 
310 // ============================================================================
312 // ============================================================================
313 template <class ITEM>
314 inline Tuples::Tuple& operator<<( Tuples::Tuple& tuple, const Tuples::TupleColumn<ITEM>& item ) {
315  if ( !tuple.valid() ) return tuple; // no action for invalid tuple
316  tuple->column( item.name(), item.value() );
317  return tuple;
318 }
319 // ============================================================================
320 
321 // ============================================================================
322 // THe END
323 // ============================================================================
324 #endif // GAUDIALG_TUPLE_H
Header file for class TupleObj.
StatusCode column(const std::string &name, float value)
Set the value for selected tuple column.
Definition: TupleObj.cpp:292
TupleObj * tuple()
Definition: Tuple.h:135
STL namespace.
const ITEM & value() const
Return the column value.
Definition: Tuple.h:262
std::shared_ptr< TupleObj > m_tuple
The (shared) tuple object.
Definition: Tuple.h:139
STL class.
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: Tuple.h:116
const std::string & name() const
Return the column name.
Definition: Tuple.h:260
Tuple(std::shared_ptr< TupleObj > tuple)
standard constructor
Definition: Tuple.h:122
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: TupleObj.h:200
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:273
ITEM m_value
The column value.
Definition: Tuple.h:266
bool valid() const
check the validity of the tuple object
Definition: Tuple.h:132
T move(T...args)
Helper class which allows to extend the functionality of Tuple with possibility to use your own repre...
Definition: Tuple.h:255
std::string m_name
The column name.
Definition: Tuple.h:265
TupleObj * operator->() const
get the pointer to the underlying object
Definition: Tuple.h:129
#define GAUDI_API
Definition: Kernel.h:71
TupleColumn(std::string name, ITEM value)
Definition: Tuple.h:257
TupleColumn< ITEM > Column(std::string name, const ITEM &item)
Definition: Tuple.h:294
General namespace for Tuple properties.
Definition: Maps.h:33