Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Tuple.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIALG_TUPLE_H
12 #define GAUDIALG_TUPLE_H 1
13 // ============================================================================
14 // Include files
15 // ============================================================================
16 // STD & STL
17 // ============================================================================
18 #include <string>
19 
20 // ============================================================================
28 // ============================================================================
29 
30 // ============================================================================
38 // ============================================================================
39 
40 #include "GaudiAlg/TupleObj.h"
41 #include "GaudiKernel/SmartIF.h"
42 
43 namespace Tuples {
44 
45  template <class ITEM>
46  class TupleItem;
47 
126  class GAUDI_API Tuple {
127  public:
132  Tuple( std::shared_ptr<TupleObj> tuple ) : m_tuple( std::move( tuple ) ) {}
133 
134  virtual ~Tuple() = default;
135 
139  TupleObj* operator->() const { return m_tuple.get(); }
140 
142  bool valid() const { return static_cast<bool>( m_tuple ); }
143 
144  protected:
145  TupleObj* tuple() { return m_tuple.get(); }
146 
147  private:
150  };
151 
264  template <class ITEM>
265  class TupleColumn {
266  public:
267  TupleColumn( std::string name, ITEM value ) : m_name( std::move( name ) ), m_value( std::move( value ) ) {}
268 
270  const std::string& name() const { return m_name; }
272  const ITEM& value() const { return m_value; }
273 
274  private:
276  ITEM m_value;
277  };
278 
282  template <class ITEM>
283  inline TupleColumn<ITEM> make_column( std::string name, const ITEM& item ) {
284  return { std::move( name ), item };
285  }
286 
290  template <class ITEM>
291  inline TupleColumn<const ITEM*> make_column( std::string name, const ITEM* item ) {
292  return { std::move( name ), item };
293  }
294 
298  template <class ITEM>
300  return { std::move( name ), item };
301  }
302 
303  template <class ITEM>
304  inline TupleColumn<ITEM> Column( std::string name, const ITEM& item ) {
305  return make_column( std::move( name ), item );
306  }
307 
308  template <class ITEM>
309  inline TupleColumn<const ITEM*> Column( std::string name, const ITEM* item ) {
310  return make_column( std::move( name ), item );
311  }
312 
313  template <class ITEM>
314  inline TupleColumn<ITEM*> Column( std::string name, ITEM* item ) {
315  return make_column( std::move( name ), item );
316  }
317 
318 } // namespace Tuples
319 
320 // ============================================================================
322 // ============================================================================
323 template <class ITEM>
325  if ( !tuple.valid() ) return tuple; // no action for invalid tuple
326  tuple->column( item.name(), item.value() )
327  .orThrow( "Failed to fill the tuple", "operator<<( Tuples::Tuple&, ...)" )
328  .ignore();
329  return tuple;
330 }
331 // ============================================================================
332 
333 // ============================================================================
334 // THe END
335 // ============================================================================
336 #endif // GAUDIALG_TUPLE_H
std::string
STL class.
std::shared_ptr
STL class.
Tuples::TupleObj::column
StatusCode column(std::string_view name, float value)
Set the value for selected tuple column.
Definition: TupleObj.cpp:267
std::move
T move(T... args)
StatusCode::orThrow
const StatusCode & orThrow(std::string_view message, std::string_view tag) const
Throw a GaudiException in case of failures.
Definition: StatusCode.h:206
Tuples::TupleItem
Definition: Tuple.h:46
Tuples::Tuple::tuple
TupleObj * tuple()
Definition: Tuple.h:145
Tuples::TupleColumn
Definition: Tuple.h:265
Tuples::Tuple::m_tuple
std::shared_ptr< TupleObj > m_tuple
The (shared) tuple object.
Definition: Tuple.h:149
Tuples::Tuple::~Tuple
virtual ~Tuple()=default
Tuples
Definition: Maps.h:43
Tuples::Tuple::Tuple
Tuple(std::shared_ptr< TupleObj > tuple)
standard constructor
Definition: Tuple.h:132
SmartIF.h
Tuples::TupleObj
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: TupleObj.h:211
Tuples::make_column
TupleColumn< ITEM > make_column(std::string name, const ITEM &item)
helper function to create 'on-the-fly' the helper object Tuples::TupleColumn
Definition: Tuple.h:283
TupleObj.h
Tuples::Tuple
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: Tuple.h:126
Tuples::TupleColumn::TupleColumn
TupleColumn(std::string name, ITEM value)
Definition: Tuple.h:267
Tuples::TupleColumn::name
const std::string & name() const
Return the column name.
Definition: Tuple.h:270
operator<<
Tuples::Tuple & operator<<(Tuples::Tuple &tuple, const Tuples::TupleColumn< ITEM > &item)
helper operator to feed Tuple with the data, see Tuples::TupleColumn
Definition: Tuple.h:324
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
Tuples::Tuple::valid
bool valid() const
check the validity of the tuple object
Definition: Tuple.h:142
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:76
std
STL namespace.
Tuples::Tuple::operator->
TupleObj * operator->() const
get the pointer to the underlying object
Definition: Tuple.h:139
Tuples::TupleColumn::m_name
std::string m_name
The column name.
Definition: Tuple.h:275
Tuples::TupleColumn::m_value
ITEM m_value
The column value.
Definition: Tuple.h:276
Tuples::Column
TupleColumn< ITEM > Column(std::string name, const ITEM &item)
Definition: Tuple.h:304
Tuples::TupleColumn::value
const ITEM & value() const
Return the column value.
Definition: Tuple.h:272
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81