The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TupleObj.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 // ============================================================================
12 #ifndef GAUDIALG_TUPLEOBJ_H
13 #define GAUDIALG_TUPLEOBJ_H 1
14 // ============================================================================
15 // Include files
16 // ============================================================================
17 // STD&STL
18 // ============================================================================
19 #include <array>
20 #include <cstddef>
21 #include <fmt/format.h>
22 #include <functional>
23 #include <limits>
24 #include <numeric>
25 #include <set>
26 #include <sstream>
27 #include <string>
28 
29 // ============================================================================
30 // GaudiKernel
31 // ============================================================================
32 #include "GaudiKernel/NTuple.h"
34 #include "GaudiKernel/VectorMap.h"
35 // ============================================================================
36 // GaudiAlg
37 // ============================================================================
38 #include "GaudiAlg/Maps.h"
39 #include "GaudiAlg/Tuples.h"
40 // ============================================================================
41 // ROOT
42 // ============================================================================
43 #include "Math/Point3D.h"
44 #include "Math/SMatrix.h"
45 #include "Math/SVector.h"
46 #include "Math/Vector3D.h"
47 #include "Math/Vector4D.h"
48 // ============================================================================
49 // forward declaration
50 // ============================================================================
51 // GaudiKernel
52 // ============================================================================
53 class IOpaqueAddress;
54 // ============================================================================
63 // ============================================================================
71 namespace Tuples {
72  namespace detail {
73  template <typename T>
74  struct to_ {
75  template <typename Arg>
76  T operator()( Arg&& i ) const {
77  return T( std::forward<Arg>( i ) );
78  }
79  };
80  constexpr to_<float> to_float{};
81 
82  template <typename Iterator>
83  using const_ref_t = std::add_const_t<typename std::iterator_traits<Iterator>::reference>;
84  } // namespace detail
85  // ==========================================================================
91  enum Type {
92  NTUPLE, // Analysis nTuple
93  EVTCOL // Event Collection
94  };
95  // ==========================================================================
104  InvalidTuple = 100,
108  InvalidItem,
109  TruncateValue = 200
110  };
111 } // namespace Tuples
112 
114 
115 namespace Tuples {
116  // ==========================================================================
212  public:
213  // ========================================================================
229  // ========================================================================
230  // the actual type for variable size matrix indices
231  typedef unsigned short MIndex;
232  // ========================================================================
233  // the map of all items
235  // ========================================================================
236  protected:
237  // ========================================================================
245  TupleObj( std::string name, NTuple::Tuple* tuple, const CLID& clid = CLID_ColumnWiseTuple,
246  const Tuples::Type type = Tuples::NTUPLE );
247  // ========================================================================
248  public:
249  // ========================================================================
250  virtual ~TupleObj();
251  // ========================================================================
267  StatusCode column( std::string_view name, float value );
268  // ========================================================================
269  public:
270  // ========================================================================
287  StatusCode column( std::string_view name, double value );
288  // ========================================================================
289  public:
290  // ========================================================================
306  StatusCode column( std::string_view name, short value );
307  // ========================================================================
325  StatusCode column( std::string_view name, short value, short minv, short maxv );
326  // ========================================================================
327  public:
328  // ========================================================================
344  StatusCode column( std::string_view name, unsigned short value );
345  // ========================================================================
363  StatusCode column( std::string_view name, unsigned short value, unsigned short minv, unsigned short maxv );
364  // ========================================================================
365  public:
366  // ========================================================================
382  StatusCode column( std::string_view name, char value );
383  // ========================================================================
401  StatusCode column( std::string_view name, char value, char minv, char maxv );
402  // ========================================================================
403  public:
404  // ========================================================================
420  StatusCode column( std::string_view name, unsigned char value );
421  // ========================================================================
439  StatusCode column( std::string_view name, unsigned char value, unsigned char minv, unsigned char maxv );
440  // ========================================================================
441  public:
442  // ========================================================================
458  StatusCode column( std::string_view name, int value );
459  // ========================================================================
477  StatusCode column( std::string_view name, int value, int minv, int maxv );
478  // ========================================================================
479  public:
480  // ========================================================================
496  StatusCode column( std::string_view name, unsigned int value );
497  // ========================================================================
515  StatusCode column( std::string_view name, unsigned int value, unsigned int minv, unsigned int maxv );
516  // ========================================================================
517  public:
518  // ========================================================================
535  StatusCode column( std::string_view name, long value );
536  // ========================================================================
554  StatusCode column( std::string_view name, long value, long minv, long maxv );
555  // ========================================================================
556  public:
557  // ========================================================================
574  StatusCode column( std::string_view name, unsigned long value );
575  // ========================================================================
593  StatusCode column( std::string_view name, unsigned long value, unsigned long minv, unsigned long maxv );
594  // ========================================================================
595  public:
596  // ========================================================================
612  StatusCode column( std::string_view name, long long value );
613  // ========================================================================
631  StatusCode column( std::string_view name, long long value, long long minv, long long maxv );
632  // ========================================================================
633  public:
634  // ========================================================================
650  StatusCode column( std::string_view name, unsigned long long value );
651  // ========================================================================
669  StatusCode column( std::string_view name, unsigned long long value, unsigned long long minv,
670  unsigned long long maxv );
671  // ========================================================================
672  public:
673  // ========================================================================
689  StatusCode column( std::string_view name, signed char value ) {
691  }
692  // ========================================================================
693  public:
694  // ========================================================================
709  StatusCode column( std::string_view name, bool value );
710  // ========================================================================
711  public:
712  // ========================================================================
731  StatusCode column( std::string_view name, IOpaqueAddress* address );
732  // ========================================================================
749  StatusCode column( IOpaqueAddress* address );
750  // ========================================================================
751  public:
752  // ========================================================================
772  template <typename Value, typename... Args>
773  StatusCode columns( Value&& value, Args&&... args ) {
774  if ( sizeof...( Args ) == 0 ) return StatusCode::SUCCESS;
776  this->column( std::get<0>( args ), std::invoke( std::get<1>( args ), value ) )... };
777  return std::accumulate( std::next( begin( scs ) ), end( scs ), *begin( scs ),
778  []( StatusCode sc, const StatusCode& i ) {
779  i.ignore(); // make sure there are no unchecked StatusCodes...
780  return sc.isFailure() ? sc : i; // latch to the first non-success case
781  } );
782  }
783  // ========================================================================
784  public:
785  // ========================================================================
806  template <typename Arg, typename... Args>
807  StatusCode fill( std::string_view fmt, Arg arg, Args... args ) {
808  constexpr auto separators = " ,;";
809  // split into token, and remainder
810  auto token = fmt.substr( 0, fmt.find_first_of( separators ) );
811  fmt.remove_prefix( std::min( token.size() + 1, fmt.size() ) );
812 
813  if ( !token.empty() ) {
814  // check the underlying tuple
815  if ( invalid() ) return ErrorCodes::InvalidTuple;
816  return column( token, arg ).andThen( [&] {
817  if constexpr ( sizeof...( Args ) != 0 ) { return fill( fmt, args... ); }
818  // no more args to deal with -- so check that there is nothing usefull left in fmt, and if so, call it a
819  // success...
820  if ( fmt.find_first_not_of( separators ) != std::string_view::npos )
821  throw std::runtime_error{ "TupleObj::fill: bad format -- too few arguments for specified format" };
823  } );
824  } else if ( !fmt.empty() ) {
825  // got a separator at the front of fmt -- try again now that it is removed from fmt...
826  return fill( fmt, arg, args... );
827  } else {
828  // empty token, and nothing left in fmt -- but we still where called with (at least) one argument...
829  throw std::runtime_error{ "TupleObj::fill: bad format -- too many arguments for specified format" };
830  return StatusCode::SUCCESS;
831  }
832  }
833 
834  // =======================================================================
835  public:
836  // =======================================================================
885  template <typename ITERATOR1, typename ITERATOR2>
886  StatusCode farray( std::string_view name, ITERATOR1&& first, ITERATOR2&& last, std::string_view length,
887  size_t maxv ) {
888  return farray( name, detail::to_float, std::forward<ITERATOR1>( first ), std::forward<ITERATOR2>( last ), length,
889  maxv );
890  }
891  // =======================================================================
934  template <class DATA>
935  StatusCode farray( std::string_view name, const DATA& data, std::string_view length, const size_t maxv ) {
936  return farray( name, std::begin( data ), std::end( data ), length, maxv );
937  }
938  // =======================================================================
1001  template <class FUNCTION, class ITERATOR>
1002  StatusCode farray( std::string_view name, const FUNCTION& function, ITERATOR first, ITERATOR last,
1003  std::string_view length, size_t maxv ) {
1004  if ( invalid() ) return ErrorCodes::InvalidTuple;
1005  if ( rowWise() ) return ErrorCodes::InvalidOperation;
1006 
1007  // adjust the length
1008  if ( std::distance( first, last ) > static_cast<std::ptrdiff_t>( maxv ) ) {
1009  Warning( fmt::format( "farray('{}'): array is overflow, skip extra entries", name ) )
1010  .ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
1011  last = std::next( first, maxv );
1012  }
1013 
1014  // get the length item
1015  Int* len = ints( length, 0, maxv );
1016  if ( !len ) return ErrorCodes::InvalidColumn;
1017 
1018  // adjust the length
1019  *len = std::distance( first, last );
1020 
1021  // get the array itself
1022  FArray* var = fArray( name, len );
1023  if ( !var ) return ErrorCodes::InvalidColumn;
1024 
1025  // fill the array
1026  std::transform( first, last, std::begin( *var ),
1027  [&]( auto&& i ) { return std::invoke( function, std::forward<decltype( i )>( i ) ); } );
1028 
1029  return StatusCode::SUCCESS;
1030  }
1031  // =======================================================================
1059  template <typename FunIterator, typename DataIterator>
1060  StatusCode farray_impl( FunIterator first_item, FunIterator last_item, DataIterator first, DataIterator last,
1061  std::string_view length, size_t maxv ) {
1062  if ( invalid() ) return ErrorCodes::InvalidTuple;
1063  if ( rowWise() ) return ErrorCodes::InvalidOperation;
1064 
1065  // adjust the length
1066  if ( std::distance( first, last ) > static_cast<std::ptrdiff_t>( maxv ) ) {
1068  std::ostringstream os;
1069  ostream_joiner( os, first_item, last_item, ",",
1070  []( std::ostream& os, const auto& i ) -> decltype( auto ) { return os << i.first; } );
1071  Warning( "farray('" + os.str() + "'): array overflow, skipping extra entries" ).ignore();
1072  last = std::next( first, maxv );
1073  }
1074 
1075  // get the length item
1076  Int* len = ints( length, 0, maxv );
1077  if ( !len ) return ErrorCodes::InvalidColumn;
1078 
1079  // adjust the length
1080  *len = std::distance( first, last );
1081 
1082  // get the arrays themselves
1083  std::vector<FArray*> vars;
1084  vars.reserve( std::distance( first_item, last_item ) );
1085  std::transform( first_item, last_item, std::back_inserter( vars ),
1086  [&]( const auto& item ) { return this->fArray( item.first, len ); } );
1087  if ( std::any_of( vars.begin(), vars.end(), []( const FArray* f ) { return !f; } ) ) {
1089  }
1090 
1091  // fill the array
1092  for ( size_t index = 0; first != last; ++first, ++index ) {
1093  auto item = first_item;
1094  for ( auto& var : vars ) { ( *var )[index] = std::invoke( ( item++ )->second, *first ); }
1095  }
1096 
1097  return StatusCode::SUCCESS;
1098  }
1099 
1100  template <
1101  typename DataIterator, template <typename, typename...> class Container = std::initializer_list,
1102  typename NamedFunction = std::pair<std::string_view, std::function<float( detail::const_ref_t<DataIterator> )>>,
1103  typename = std::enable_if_t<!std::is_convertible_v<Container<NamedFunction>, std::string_view>>>
1104  StatusCode farray( const Container<NamedFunction>& funs, DataIterator first, DataIterator last,
1105  std::string_view length, size_t maxv ) {
1106  return farray_impl( funs.begin(), funs.end(), std::forward<DataIterator>( first ),
1107  std::forward<DataIterator>( last ), length, maxv );
1108  }
1109 
1110  template <typename NamedFunctions, typename DataIterator,
1111  typename = std::enable_if_t<!std::is_convertible_v<NamedFunctions, std::string_view>>>
1112  StatusCode farray( const NamedFunctions& funs, DataIterator first, DataIterator last, std::string_view length,
1113  size_t maxv ) {
1114  return farray_impl( funs.begin(), funs.end(), std::forward<DataIterator>( first ),
1115  std::forward<DataIterator>( last ), length, maxv );
1116  }
1117  // =======================================================================
1149  template <class FUNC1, class FUNC2, class Iterator>
1150  StatusCode farray( std::string_view name1, const FUNC1& func1, std::string_view name2, const FUNC2& func2,
1151  Iterator&& first, Iterator&& last, std::string_view length, size_t maxv ) {
1152  return farray( { { name1, std::cref( func1 ) }, { name2, std::cref( func2 ) } }, std::forward<Iterator>( first ),
1153  std::forward<Iterator>( last ), length, maxv );
1154  }
1155  // =======================================================================
1192  template <class FUNC1, class FUNC2, class FUNC3, class Iterator>
1193  StatusCode farray( std::string_view name1, const FUNC1& func1, std::string_view name2, const FUNC2& func2,
1194  std::string_view name3, const FUNC3& func3, Iterator&& first, Iterator&& last,
1195  std::string_view length, size_t maxv ) {
1196  return farray( { { name1, std::cref( func1 ) }, { name2, std::cref( func2 ) }, { name3, std::cref( func3 ) } },
1197  std::forward<Iterator>( first ), std::forward<Iterator>( last ), length, maxv );
1198  }
1199  // =======================================================================
1239  template <class FUNC1, class FUNC2, class FUNC3, class FUNC4, class Iterator>
1240  StatusCode farray( std::string_view name1, const FUNC1& func1, std::string_view name2, const FUNC2& func2,
1241  std::string_view name3, const FUNC3& func3, std::string_view name4, const FUNC4& func4,
1242  Iterator&& first, Iterator&& last, std::string_view length, size_t maxv ) {
1243  return farray( { { name1, std::cref( func1 ) },
1244  { name2, std::cref( func2 ) },
1245  { name3, std::cref( func3 ) },
1246  { name4, std::cref( func4 ) } },
1247  std::forward<Iterator>( first ), std::forward<Iterator>( last ), length, maxv );
1248  }
1249  // =======================================================================
1250  public:
1251  // =======================================================================
1302  template <class MATRIX>
1303  StatusCode fmatrix( std::string_view name, const MATRIX& data, size_t rows, const MIndex& cols,
1304  std::string_view length, size_t maxv ) {
1305  if ( invalid() ) return ErrorCodes::InvalidTuple;
1306  if ( rowWise() ) return ErrorCodes::InvalidOperation;
1307 
1308  // adjust the length
1309  if ( rows >= maxv ) {
1310  Warning( fmt::format( "fmatrix('{}'): matrix is overflow, skip extra items", name ) ).ignore();
1311  rows = ( 0 < maxv ) ? ( maxv - 1 ) : 0;
1312  }
1313 
1314  // get the length item
1315  Int* len = ints( length, 0, maxv );
1316  if ( !len ) return ErrorCodes::InvalidColumn;
1317 
1318  // adjust the length item
1319  *len = rows;
1320 
1321  // get the array itself
1322  FMatrix* var = fMatrix( name, len, cols );
1323  if ( !var ) return ErrorCodes::InvalidColumn;
1324 
1326  for ( size_t iCol = 0; iCol < cols; ++iCol ) {
1327  for ( MIndex iRow = 0; iRow < rows; ++iRow ) { ( *var )[iRow][iCol] = data[iRow][iCol]; }
1328  }
1329 
1330  return StatusCode::SUCCESS;
1331  }
1332  // =======================================================================
1369  template <class DATA>
1370  StatusCode fmatrix( std::string_view name, DATA first, DATA last, const MIndex& cols, std::string_view length,
1371  size_t maxv ) {
1372  if ( invalid() ) return ErrorCodes::InvalidTuple;
1373  if ( rowWise() ) return ErrorCodes::InvalidOperation;
1374 
1375  // adjust the length
1376  if ( first + maxv < last ) {
1377  Warning( fmt::format( "fmatrix('{}'): matrix is overflow, skip extra items", name ) ).ignore();
1378  last = first + maxv;
1379  }
1380 
1381  // get the length item
1382  Int* len = ints( length, 0, maxv );
1383  if ( !len ) return ErrorCodes::InvalidColumn;
1384 
1385  // adjust the length item
1386  *len = last - first;
1387 
1388  // get the array itself
1389  FMatrix* var = fMatrix( name, len, cols );
1390  if ( !var ) return ErrorCodes::InvalidColumn;
1391 
1393  size_t iRow = 0;
1394  for ( ; first != last; ++first ) {
1395  //
1396  for ( MIndex iCol = 0; iCol < cols; ++iCol ) { ( *var )[iRow][iCol] = ( *first )[iCol]; }
1397  //
1398  ++iRow;
1399  }
1400 
1401  return StatusCode::SUCCESS;
1402  }
1403  // =======================================================================
1482  template <class FUN, class DATA>
1483  StatusCode fmatrix( std::string_view name, FUN funF, FUN funL, DATA first, DATA last, std::string_view length,
1484  size_t maxv ) {
1485  if ( invalid() ) return ErrorCodes::InvalidTuple;
1486  if ( rowWise() ) return ErrorCodes::InvalidOperation;
1487 
1488  // adjust the length
1489  if ( std::distance( first, last ) > static_cast<std::ptrdiff_t>( maxv ) ) {
1490  Warning( fmt::format( "fmatrix('{}'): matrix is overflow, skip extra items", name ) ).ignore();
1491  last = std::next( first, maxv );
1492  }
1493 
1494  // get the length item
1495  Int* len = ints( length, 0, maxv );
1496 
1497  if ( !len ) return ErrorCodes::InvalidColumn;
1498 
1499  // adjust the length item
1500  *len = std::distance( first, last );
1501 
1502  // get the array itself
1503  auto cols = std::distance( funF, funL );
1504  FMatrix* var = fMatrix( name, len, cols );
1505  if ( !var ) return ErrorCodes::InvalidColumn;
1506 
1508  size_t iRow = 0;
1509  for ( ; first != last; ++first ) {
1510  //
1511  for ( FUN fun = funF; fun < funL; ++fun ) { ( *var )[iRow][fun - funF] = std::invoke( *fun, *first ); }
1512  //
1513  ++iRow;
1514  }
1515 
1516  return StatusCode::SUCCESS;
1517  }
1518  // =======================================================================
1519  public:
1520  // =======================================================================
1543  template <class DATA>
1544  StatusCode array( std::string_view name, DATA first, DATA last )
1545 
1546  {
1547  if ( invalid() ) return ErrorCodes::InvalidTuple;
1548  if ( rowWise() ) return ErrorCodes::InvalidOperation;
1549 
1550  // get the length (fixed!)
1551  auto length = std::distance( first, last );
1552 
1553  // get the array itself
1554  FArray* var = fArray( name, length );
1555  if ( !var ) return ErrorCodes::InvalidColumn;
1556 
1558  std::copy( first, last, std::begin( *var ) );
1559 
1560  return StatusCode::SUCCESS;
1561  }
1562  // =======================================================================
1601  template <class ARRAY>
1602  StatusCode array( std::string_view name, const ARRAY& data, const MIndex& length ) {
1603  using std::begin; // allow data to be eg. CLHEP::HepVector (which does not define HepVector::begin()!,
1604  // in which case ADL prefers CLHEP::begin (yah! at least they (now) use a namespace)
1605  // so one just to insure double* CLHEP::begin(CLHEP::HepVector& v) { return &v[0]; }
1606  // is visible when this function gets instantiated for CLHEP::HepVector...
1607  auto first = begin( data );
1608  return array( name, first, std::next( first, length ) );
1609  }
1610  // =======================================================================
1641  template <class ARRAY>
1642  StatusCode array( std::string_view name, const ARRAY& data ) {
1643  using std::begin;
1644  using std::end;
1645  return array( name, begin( data ), end( data ) );
1646  }
1647  // =======================================================================
1648  public:
1649  // =======================================================================
1698  template <class MATRIX>
1699  StatusCode matrix( std::string_view name, const MATRIX& data, const MIndex& rows, const MIndex& cols ) {
1700  if ( invalid() ) return ErrorCodes::InvalidTuple;
1701  if ( rowWise() ) return ErrorCodes::InvalidOperation;
1702 
1703  // get the matrix itself
1704  FMatrix* var = fMatrix( name, rows, cols );
1705  if ( !var ) return ErrorCodes::InvalidColumn;
1706 
1708  for ( size_t iCol = 0; iCol < cols; ++iCol ) {
1709  for ( size_t iRow = 0; iRow < rows; ++iRow ) { ( *var )[iRow][iCol] = data[iRow][iCol]; }
1710  };
1711  return StatusCode::SUCCESS;
1712  }
1713  // =======================================================================
1714  public:
1715  // =======================================================================
1732  template <class TYPE>
1733  StatusCode column( std::string_view name, const ROOT::Math::LorentzVector<TYPE>& v ) {
1734  return columns( v, std::pair{ fmt::format( "{}E", name ), &ROOT::Math::LorentzVector<TYPE>::E },
1735  std::pair{ fmt::format( "{}X", name ), &ROOT::Math::LorentzVector<TYPE>::Px },
1736  std::pair{ fmt::format( "{}Y", name ), &ROOT::Math::LorentzVector<TYPE>::Py },
1737  std::pair{ fmt::format( "{}Z", name ), &ROOT::Math::LorentzVector<TYPE>::Pz } );
1738  }
1739  // =======================================================================
1756  template <class TYPE, class TAG>
1758  return this->columns( v, std::pair{ fmt::format( "{}X", name ), &ROOT::Math::DisplacementVector3D<TYPE, TAG>::X },
1761  }
1762  // =======================================================================
1779  template <class TYPE, class TAG>
1781  return this->columns( v, std::pair{ fmt::format( "{}X", name ), &ROOT::Math::PositionVector3D<TYPE, TAG>::X },
1784  }
1785  // =======================================================================
1794  template <class TYPE, unsigned int D1, unsigned int D2, class REP>
1795  StatusCode matrix( std::string_view name, const ROOT::Math::SMatrix<TYPE, D1, D2, REP>& mtrx ) {
1796  if ( invalid() ) return ErrorCodes::InvalidTuple;
1797  if ( rowWise() ) return ErrorCodes::InvalidOperation;
1798 
1799  // get the matrix itself
1800  FMatrix* var = fMatrix( name, (MIndex)D1, (MIndex)D2 );
1801  if ( !var ) return ErrorCodes::InvalidColumn;
1802 
1804  for ( size_t iCol = 0; iCol < D2; ++iCol ) {
1805  for ( size_t iRow = 0; iRow < D1; ++iRow ) { ( *var )[iRow][iCol] = mtrx( iRow, iCol ); }
1806  };
1807 
1808  return StatusCode::SUCCESS;
1809  }
1810  // =======================================================================
1828  template <class KEY, class VALUE>
1829  StatusCode fmatrix( std::string_view name, const GaudiUtils::VectorMap<KEY, VALUE>& info, std::string_view length,
1830  const size_t maxv = 100 ) {
1831  using Info = std::pair<KEY, VALUE>;
1832  static const std::array<float ( * )( const Info& ), 2> fns = {
1833  { []( const Info& i ) -> float { return i.first; }, []( const Info& i ) -> float { return i.second; } } };
1834  return fmatrix( name, begin( fns ), end( fns ), begin( info ), end( info ), length, maxv );
1835  }
1836  // =======================================================================
1837  public:
1838  // =======================================================================
1846  template <class TYPE>
1847  StatusCode put( std::string_view name, const TYPE* obj );
1848  // =======================================================================
1849  public:
1850  // =======================================================================
1854  StatusCode write();
1855  // =======================================================================
1857  const std::string& name() const { return m_name; }
1858  // =======================================================================
1862  const NTuple::Tuple* tuple() const { return m_tuple; }
1863  // =======================================================================
1867  NTuple::Tuple* tuple() { return m_tuple; }
1868  // =======================================================================
1870  const CLID& clid() const { return m_clid; }
1871  // =======================================================================
1873  Tuples::Type type() const { return m_type; }
1874  // =======================================================================
1876  bool columnWise() const { return CLID_ColumnWiseTuple == clid(); }
1877  // =======================================================================
1879  bool rowWise() const { return CLID_RowWiseTuple == clid(); }
1880  // =======================================================================
1882  bool evtColType() const { return Tuples::EVTCOL == type(); }
1883  // =======================================================================
1885  bool valid() const { return 0 != tuple(); }
1886  // =======================================================================
1888  bool invalid() const { return !valid(); }
1889  // =======================================================================
1890  public:
1891  // =======================================================================
1898  return m_items.emplace( std::move( name ), std::move( type ) ).second;
1899  }
1900  // =======================================================================
1905  bool goodItem( std::string_view name ) const { return m_items.end() == m_items.find( name ); }
1906  // =======================================================================
1908  const ItemMap& items() const { return m_items; }
1909  // =======================================================================
1910  public:
1911  // =======================================================================
1912  virtual StatusCode Error( const std::string& msg, const StatusCode sc = StatusCode::FAILURE ) const = 0;
1913  // =======================================================================
1914  virtual StatusCode Warning( const std::string& msg, const StatusCode sc = StatusCode::FAILURE ) const = 0;
1915  // =======================================================================
1916  private:
1917  // =======================================================================
1919  Int* ints( std::string_view name, int minv, int maxv );
1920  // =======================================================================
1922  FArray* fArray( std::string_view name, Int* item );
1923  // =======================================================================
1925  FArray* fArray( std::string_view name, const MIndex& rows );
1926  // =======================================================================
1928  Address* addresses( std::string_view name );
1929  // =======================================================================
1931  FMatrix* fMatrix( std::string_view name, Int* item, const MIndex& cols );
1932  // =======================================================================
1934  FMatrix* fMatrix( std::string_view name, const MIndex& rows, const MIndex& cols );
1935  // =======================================================================
1937  TupleObj( const TupleObj& ) = delete;
1938  TupleObj& operator=( const TupleObj& ) = delete;
1939  // =======================================================================
1940  private:
1941  // =======================================================================
1944  // =======================================================================
1947  // =======================================================================
1950  // =======================================================================
1953  // =======================================================================
1955  size_t m_refCount = 0;
1956  // =======================================================================
1957  // helper type to define the actual storage types
1958  template <typename T>
1961 
1962  public:
1963  using element_type = T;
1964  T* find( std::string_view sv ) {
1965  auto i = m_map.find( sv );
1966  return i != m_map.end() ? &i->second.first : nullptr;
1967  }
1968  T* end() { return nullptr; }
1969  std::pair<T*, bool> emplace( std::string_view k, T v = T{} ) {
1970  // tricky way to insert a string_view key which points to the
1971  // string contained in the mapped type... all just to make find(string_view) work in C++17...
1972  auto [i, b] = m_map.try_emplace( k, std::move( v ), std::string{ k } );
1973  if ( !b ) return { static_cast<T*>( nullptr ), false };
1974  auto nh = m_map.extract( i );
1975  nh.key() = nh.mapped().second; // "re-point" key to the string contained value_type
1976  auto r = m_map.insert( std::move( nh ) );
1977  return { &r.position->second.first, r.inserted };
1978  }
1979  };
1980 
1981  // =======================================================================
1984  // =======================================================================
1987  // =======================================================================
1990  // =======================================================================
1993  // =======================================================================
1996  // =======================================================================
1999  // =======================================================================
2002  // =======================================================================
2005  // =======================================================================
2008  // =======================================================================
2011  // =======================================================================
2014  // =======================================================================
2017  // =======================================================================
2020  // =======================================================================
2023  // =======================================================================
2026  // =======================================================================
2029  // =======================================================================
2032  // =======================================================================
2033  };
2034  // ==========================================================================
2035 } // end of namespace Tuples
2036 
2037 // ============================================================================
2038 // GaudiAlg
2039 // ============================================================================
2040 #include "GaudiAlg/TuplePut.h"
2041 // ============================================================================
2042 // The END
2043 // ============================================================================
2044 #endif // GAUDIALG_TUPLEOBJ_H
Tuples::TupleObj::ColumnStorage::m_map
std::unordered_map< std::string_view, std::pair< T, std::string > > m_map
Definition: TupleObj.h:1960
Tuples::TupleObj::m_type
Tuples::Type m_type
tuple 'type'
Definition: TupleObj.h:1952
Tuples::TupleObj::ColumnStorage
Definition: TupleObj.h:1959
Tuples::TupleObj::column
StatusCode column(std::string_view name, const ROOT::Math::PositionVector3D< TYPE, TAG > &v)
Useful shortcut to put 3D-Vector directly into N-Tuple:
Definition: TupleObj.h:1780
std::string
STL class.
Tuples::TupleObj::type
Tuples::Type type() const
accessor to the N-Tuple type
Definition: TupleObj.h:1873
Tuples::TupleObj::columns
StatusCode columns(Value &&value, Args &&... args)
Set the values for several columns simultaneously, for the same object Non-existing columns will be a...
Definition: TupleObj.h:773
Tuples.h
Tuples::TupleObj::m_shorts
ColumnStorage< Short > m_shorts
the actual storage of all 'Int' columns
Definition: TupleObj.h:1992
Tuples::ErrorCodes::InvalidColumn
@ InvalidColumn
std::move
T move(T... args)
Tuples::TupleObj::m_fmatrices
ColumnStorage< FMatrix > m_fmatrices
the actual storage of all 'FArray' columns
Definition: TupleObj.h:2025
ROOT::Math::PositionVector3D
Definition: IMagneticFieldSvc.h:25
Tuples::TupleObj::tuple
const NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
Definition: TupleObj.h:1862
Tuples::TupleObj::matrix
StatusCode matrix(std::string_view name, const MATRIX &data, const MIndex &rows, const MIndex &cols)
fill N-Tuple with fixed-size matrix
Definition: TupleObj.h:1699
Tuples::EVTCOL
@ EVTCOL
Definition: TupleObj.h:93
std::pair
std::vector::reserve
T reserve(T... args)
Tuples::TupleObj::Error
virtual StatusCode Error(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const =0
Tuples::TupleObj::m_arraysf
ColumnStorage< FArray > m_arraysf
the actual storage of all 'FArray' columns (fixed)
Definition: TupleObj.h:2022
IOpaqueAddress
Definition: IOpaqueAddress.h:33
Tuples::detail::to_
Definition: TupleObj.h:74
std::vector
STL class.
std::unordered_map::find
T find(T... args)
std::back_inserter
T back_inserter(T... args)
GaudiUtils::VectorMap
Definition: VectorMap.h:112
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
Tuples::TupleObj::evtColType
bool evtColType() const
Event collection ?
Definition: TupleObj.h:1882
Tuples::TupleObj::column
StatusCode column(std::string_view name, const ROOT::Math::LorentzVector< TYPE > &v)
Useful shortcut to put LorentzVector directly into N-Tuple:
Definition: TupleObj.h:1733
TuplePut.h
std::distance
T distance(T... args)
detail
Tuples::ErrorCodes::TruncateValue
@ TruncateValue
Tuples::TupleObj::fill
StatusCode fill(std::string_view fmt, Arg arg, Args... args)
Set the values for several columns simultaneously.
Definition: TupleObj.h:807
Tuples::TupleObj::farray_impl
StatusCode farray_impl(FunIterator first_item, FunIterator last_item, DataIterator first, DataIterator last, std::string_view length, size_t maxv)
Put arbitrary number of functions from one data array into LoKi-style N-Tuple simultaneously (effecti...
Definition: TupleObj.h:1060
Tuples::detail::to_::operator()
T operator()(Arg &&i) const
Definition: TupleObj.h:76
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:139
StatusCode::code_t
unsigned long code_t
type of StatusCode value
Definition: StatusCode.h:67
std::function
Tuples::TupleObj::array
StatusCode array(std::string_view name, DATA first, DATA last)
fill N-Tuple with fixed-size array
Definition: TupleObj.h:1544
std::any_of
T any_of(T... args)
GaudiAlg.Algs.column
column
Definition: Algs.py:1212
Tuples::TupleObj::m_clid
CLID m_clid
tuple CLID
Definition: TupleObj.h:1949
MultiMergers.Value
Value
Definition: MultiMergers.py:15
Tuples::TupleObj::m_floats
ColumnStorage< Float > m_floats
the actual storage of all 'Float' columns
Definition: TupleObj.h:2010
Tuples::TupleObj::addresses
Address * addresses(std::string_view name)
get the column
Tuples::TupleObj::fmatrix
StatusCode fmatrix(std::string_view name, const GaudiUtils::VectorMap< KEY, VALUE > &info, std::string_view length, const size_t maxv=100)
shortcut to put "ExtraInfo" fields of major into N-Tuple
Definition: TupleObj.h:1829
Tuples::TupleObj::ColumnStorage::end
T * end()
Definition: TupleObj.h:1968
Tuples::TupleObj::farray
StatusCode farray(std::string_view name1, const FUNC1 &func1, std::string_view name2, const FUNC2 &func2, std::string_view name3, const FUNC3 &func3, Iterator &&first, Iterator &&last, std::string_view length, size_t maxv)
Put three functions from one data array into LoKi-style N-Tuple simultaneously (effective!...
Definition: TupleObj.h:1193
Tuples::TupleObj::m_bools
ColumnStorage< Bool > m_bools
the actual storage of all 'bool' columns
Definition: TupleObj.h:1983
Tuples::TupleObj::matrix
StatusCode matrix(std::string_view name, const ROOT::Math::SMatrix< TYPE, D1, D2, REP > &mtrx)
shortcut to put Smatrix into N-tuple:
Definition: TupleObj.h:1795
Tuples::ErrorCodes
ErrorCodes
Definition: TupleObj.h:103
Tuples::TupleObj::farray
StatusCode farray(std::string_view name1, const FUNC1 &func1, std::string_view name2, const FUNC2 &func2, std::string_view name3, const FUNC3 &func3, std::string_view name4, const FUNC4 &func4, Iterator &&first, Iterator &&last, std::string_view length, size_t maxv)
Put four functions from one data array into LoKi-style N-Tuple simultaneously (effective!...
Definition: TupleObj.h:1240
Tuples
Definition: Maps.h:43
Tuples::NTUPLE
@ NTUPLE
Definition: TupleObj.h:92
VectorMap.h
Tuples::TupleObj::fmatrix
StatusCode fmatrix(std::string_view name, DATA first, DATA last, const MIndex &cols, std::string_view length, size_t maxv)
Fill N-Tuple with data from variable-size matrix.
Definition: TupleObj.h:1370
Tuples::TupleObj::m_matricesf
ColumnStorage< FMatrix > m_matricesf
the actual storage of all 'FMatrix' columns (fixed)
Definition: TupleObj.h:2028
Tuples::TupleObj
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: TupleObj.h:211
Tuples::TupleObj::TupleObj
TupleObj(const TupleObj &)=delete
delete the copy constructor and assignment
StatusCode
Definition: StatusCode.h:65
Tuples::TupleObj::m_items
ItemMap m_items
all booked types:
Definition: TupleObj.h:2031
Tuples::TupleObj::tuple
NTuple::Tuple * tuple()
provide the access to underlying Gaudi N-tuple
Definition: TupleObj.h:1867
std::ostream
STL class.
std::forward
T forward(T... args)
CLHEP::begin
double * begin(CLHEP::HepVector &v)
Definition: TupleAlg.cpp:45
Tuples::TupleObj::valid
bool valid() const
valid pointer to tuple ?
Definition: TupleObj.h:1885
NTuple.h
Tuples::TupleObj::fmatrix
StatusCode fmatrix(std::string_view name, const MATRIX &data, size_t rows, const MIndex &cols, std::string_view length, size_t maxv)
Fill N-Tuple with data from variable-size matrix.
Definition: TupleObj.h:1303
std::array
STL class.
Tuples::ErrorCodes::InvalidObject
@ InvalidObject
GaudiPython.Bindings.nullptr
nullptr
Definition: Bindings.py:87
std::copy
T copy(T... args)
std::runtime_error
STL class.
std::accumulate
T accumulate(T... args)
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
std::map
STL class.
Tuples::TupleObj::m_addresses
ColumnStorage< Address > m_addresses
the actual storage of all 'Address' columns
Definition: TupleObj.h:2016
std::transform
T transform(T... args)
Tuples::detail::to_float
constexpr to_< float > to_float
Definition: TupleObj.h:80
Tuples::TupleObj::goodItem
bool goodItem(std::string_view name) const
check the uniqueness of the name
Definition: TupleObj.h:1905
Tuples::TupleObj::column
StatusCode column(std::string_view name, const ROOT::Math::DisplacementVector3D< TYPE, TAG > &v)
Useful shortcut to put 3D-Vector directly into N-Tuple:
Definition: TupleObj.h:1757
Tuples::TupleObj::m_longlongs
ColumnStorage< LongLong > m_longlongs
the actual storage of all 'long long' columns
Definition: TupleObj.h:2004
Tuples::TupleObj::array
StatusCode array(std::string_view name, const ARRAY &data, const MIndex &length)
fill N-Tuple with fixed-size array
Definition: TupleObj.h:1602
Tuples::TupleObj::m_ushorts
ColumnStorage< UShort > m_ushorts
the actual storage of all 'unsigned int' columns
Definition: TupleObj.h:1995
Tuples::TupleObj::m_name
std::string m_name
name
Definition: TupleObj.h:1943
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
std::min
T min(T... args)
std::ostringstream
STL class.
NTuple::Matrix
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:62
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
Tuples::TupleObj::m_farrays
ColumnStorage< FArray > m_farrays
the actual storage of all 'FArray' columns
Definition: TupleObj.h:2019
Tuples::TupleObj::ColumnStorage::emplace
std::pair< T *, bool > emplace(std::string_view k, T v=T{})
Definition: TupleObj.h:1969
Tuples::TupleObj::addItem
bool addItem(std::string name, std::string type)
add the item name into the list of known items
Definition: TupleObj.h:1897
gaudirun.type
type
Definition: gaudirun.py:160
Tuples::TupleObj::clid
const CLID & clid() const
accessor to the N-Tuple CLID
Definition: TupleObj.h:1870
Tuples::TupleObj::m_doubles
ColumnStorage< Double > m_doubles
the actual storage of all 'Double' columns
Definition: TupleObj.h:2013
Tuples::TupleObj::Warning
virtual StatusCode Warning(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const =0
Tuples::TupleObj::m_ints
ColumnStorage< Int > m_ints
the actual storage of all 'Int' columns
Definition: TupleObj.h:1998
Tuples::TupleObj::array
StatusCode array(std::string_view name, const ARRAY &data)
fill N-Tuple with fixed-size array
Definition: TupleObj.h:1642
Tuples::TupleObj::m_ulonglongs
ColumnStorage< ULongLong > m_ulonglongs
the actual storage of all 'unsigned long long' columns
Definition: TupleObj.h:2007
STATUSCODE_ENUM_DECL
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
Definition: StatusCode.h:286
Tuples::TupleObj::column
StatusCode column(std::string_view name, signed char value)
Set the value for the selected tuple column.
Definition: TupleObj.h:689
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:76
Tuples::TupleObj::invalid
bool invalid() const
invalid pointer to tuple ?
Definition: TupleObj.h:1888
Maps.h
Tuples::TupleObj::farray
StatusCode farray(std::string_view name, const FUNCTION &function, ITERATOR first, ITERATOR last, std::string_view length, size_t maxv)
Put an indexed array into LoKi-style N-Tuple.
Definition: TupleObj.h:1002
Containers::array
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
Definition: KeyedObjectManager.h:37
gaudirun.args
args
Definition: gaudirun.py:336
Tuples::ErrorCodes::InvalidTuple
@ InvalidTuple
NTuple::Tuple
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:387
std::begin
T begin(T... args)
Tuples::Type
Type
Definition: TupleObj.h:91
Gaudi::Decays::valid
bool valid(Iterator begin, Iterator end)
check the validness of the trees or nodes
Definition: Nodes.h:35
Tuples::TupleObj::MIndex
unsigned short MIndex
Definition: TupleObj.h:231
std::unordered_map::insert
T insert(T... args)
Tuples::detail::const_ref_t
std::add_const_t< typename std::iterator_traits< Iterator >::reference > const_ref_t
Definition: TupleObj.h:83
fmt
Definition: MessageSvcSink.cpp:26
Tuples::TupleObj::farray
StatusCode farray(std::string_view name1, const FUNC1 &func1, std::string_view name2, const FUNC2 &func2, Iterator &&first, Iterator &&last, std::string_view length, size_t maxv)
Put two functions from one data array into LoKi-style N-Tuple simultaneously (effective!...
Definition: TupleObj.h:1150
std::ptrdiff_t
ROOT::Math::DisplacementVector3D
Definition: IMagneticFieldSvc.h:28
Tuples::TupleObj::farray
StatusCode farray(const NamedFunctions &funs, DataIterator first, DataIterator last, std::string_view length, size_t maxv)
Definition: TupleObj.h:1112
Tuples::TupleObj::m_uchars
ColumnStorage< UChar > m_uchars
the actual storage of all 'unsigned int' columns
Definition: TupleObj.h:1989
Tuples::TupleObj::fmatrix
StatusCode fmatrix(std::string_view name, FUN funF, FUN funL, DATA first, DATA last, std::string_view length, size_t maxv)
fill N-Tuple with matrix of "direct-product" of "data-vector" [first,last) and "function-vector" [fun...
Definition: TupleObj.h:1483
Tuples::TupleObj::m_tuple
NTuple::Tuple * m_tuple
tuple itself
Definition: TupleObj.h:1946
Properties.v
v
Definition: Properties.py:122
Tuples::TupleObj::items
const ItemMap & items() const
get the full list of booked items
Definition: TupleObj.h:1908
Tuples::TupleObj::farray
StatusCode farray(std::string_view name, ITERATOR1 &&first, ITERATOR2 &&last, std::string_view length, size_t maxv)
Add an indexed array (of type float) to N-tuple.
Definition: TupleObj.h:886
Tuples::TupleObj::m_uints
ColumnStorage< UInt > m_uints
the actual storage of all 'unsigned int' columns
Definition: TupleObj.h:2001
SerializeSTL.h
Tuples::TupleObj::rowWise
bool rowWise() const
row wise NTuple ?
Definition: TupleObj.h:1879
Tuples::TupleObj::operator=
TupleObj & operator=(const TupleObj &)=delete
ints
Gaudi::Functional::vector_of_const_< int > ints
Definition: merging_transformer.cpp:14
Gaudi::Utils::Histos::fill
GAUDI_API void fill(AIDA::IHistogram1D *histo, const double value, const double weight=1.0)
simple function to fill AIDA::IHistogram1D objects
Definition: Fill.cpp:45
std::end
T end(T... args)
IOTest.end
end
Definition: IOTest.py:123
NTuple::Item< bool >
Specialization acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:307
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Tuples::TupleObj::farray
StatusCode farray(const Container< NamedFunction > &funs, DataIterator first, DataIterator last, std::string_view length, size_t maxv)
Definition: TupleObj.h:1104
Tuples::TupleObj::ColumnStorage::find
T * find(std::string_view sv)
Definition: TupleObj.h:1964
NTuple::Array< float >
Tuples::ErrorCodes::InvalidItem
@ InvalidItem
Tuples::TupleObj::farray
StatusCode farray(std::string_view name, const DATA &data, std::string_view length, const size_t maxv)
Add an indexed array (of type float) to N-tuple.
Definition: TupleObj.h:935
Tuples::ErrorCodes::InvalidOperation
@ InvalidOperation
Tuples::TupleObj::columnWise
bool columnWise() const
column wise NTuple ?
Definition: TupleObj.h:1876
std::unordered_map
STL class.
std::numeric_limits
Tuples::TupleObj::ItemMap
std::map< std::string, std::string, std::less<> > ItemMap
Definition: TupleObj.h:234
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
Tuples::TupleObj::m_chars
ColumnStorage< Char > m_chars
the actual storage of all 'Int' columns
Definition: TupleObj.h:1986
std::cref
T cref(T... args)
Tuples::TupleObj::name
const std::string & name() const
get the name
Definition: TupleObj.h:1857
Gaudi::Functional::details::put
auto put(const DataObjectHandle< Out1 > &out_handle, Out2 &&out)
Definition: details.h:169
Gaudi::ParticleProperties::index
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
Definition: IParticlePropertySvc.cpp:39
GaudiUtils::details::ostream_joiner
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:73
NTuple::Item
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:58
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:28
std::next
T next(T... args)
std::initializer_list