| The Gaudi Framework v32r1 (f65d50dc)

TupleObj.h
Go to the documentation of this file.
1 // ============================================================================
2 #ifndef GAUDIALG_TUPLEOBJ_H
3 #define GAUDIALG_TUPLEOBJ_H 1
4 // ============================================================================
5 // Include files
6 // ============================================================================
7 // STD&STL
8 // ============================================================================
9 #include <array>
10 #include <cstddef>
11 #include <functional>
12 #include <limits>
13 #include <numeric>
14 #include <set>
15 #include <sstream>
16 #include <string>
17 // ============================================================================
18 // GaudiKernel
19 // ============================================================================
20 #include "GaudiKernel/NTuple.h"
21 #include "GaudiKernel/SerializeSTL.h"
22 #include "GaudiKernel/VectorMap.h"
23 // ============================================================================
24 // GaudiAlg
25 // ============================================================================
26 #include "GaudiAlg/Maps.h"
27 #include "GaudiAlg/Tuples.h"
28 // ============================================================================
29 // ROOT
30 // ============================================================================
31 #include "Math/Point3D.h"
32 #include "Math/SMatrix.h"
33 #include "Math/SVector.h"
34 #include "Math/Vector3D.h"
35 #include "Math/Vector4D.h"
36 // ============================================================================
37 // forward declaration
38 // ============================================================================
39 // GaudiKernel
40 // ============================================================================
41 class IOpaqueAddress;
42 // ============================================================================
51 // ============================================================================
59 namespace Tuples {
60 namespace detail {
61 template <typename T>
62 struct to_ {
63 template <typename Arg>
64 T operator()( Arg&& i ) const {
65 return T( std::forward<Arg>( i ) );
66 }
67 };
68 constexpr to_<float> to_float{};
69
70 template <typename Iterator>
71 using const_ref_t = std::add_const_t<typename std::iterator_traits<Iterator>::reference>;
72 } // namespace detail
73 // ==========================================================================
79 enum Type {
80 NTUPLE, // Analysis nTuple
81 EVTCOL // Event Collection
82 };
83 // ==========================================================================
91 enum class ErrorCodes : StatusCode::code_t {
92 InvalidTuple = 100,
93 InvalidColumn,
94 InvalidOperation,
95 InvalidObject,
96 InvalidItem,
97 TruncateValue = 200
98 };
99 } // namespace Tuples
100
101 STATUSCODE_ENUM_DECL( Tuples::ErrorCodes )
102
103 namespace Tuples {
104 // ==========================================================================
199 class GAUDI_API TupleObj {
200 public:
201 // ========================================================================
203 typedef NTuple::Item<bool> Bool;
204 // ========================================================================
206 typedef NTuple::Item<char> Char;
207 // ========================================================================
209 typedef NTuple::Item<unsigned char> UChar;
210 // ========================================================================
212 typedef NTuple::Item<short> Short;
213 // ========================================================================
215 typedef NTuple::Item<unsigned short> UShort;
216 // ========================================================================
218 typedef NTuple::Item<int> Int;
219 // ========================================================================
221 typedef NTuple::Item<unsigned int> UInt;
222 // ========================================================================
224 typedef NTuple::Item<long long> LongLong;
225 // ========================================================================
227 typedef NTuple::Item<unsigned long long> ULongLong;
228 // ========================================================================
230 typedef NTuple::Item<float> Float;
231 // ========================================================================
233 typedef NTuple::Item<double> Double;
234 // ========================================================================
236 typedef NTuple::Item<IOpaqueAddress*> Address;
237 // ========================================================================
239 typedef NTuple::Array<float> FArray;
240 // ========================================================================
242 typedef NTuple::Matrix<float> FMatrix;
243 // ========================================================================
244 // the actual type for variable size matrix indices
245 typedef unsigned short MIndex;
246 // ========================================================================
247 // the map of all items
248 typedef std::map<std::string, std::string> ItemMap;
249 // ========================================================================
250 protected:
251 // ========================================================================
259 TupleObj( std::string name, NTuple::Tuple* tuple, const CLID& clid = CLID_ColumnWiseTuple,
260 const Tuples::Type type = Tuples::NTUPLE );
261 // ========================================================================
262 public:
263 // ========================================================================
264 virtual ~TupleObj();
265 // ========================================================================
281 StatusCode column( const std::string& name, float value );
282 // ========================================================================
283 public:
284 // ========================================================================
301 StatusCode column( const std::string& name, double value );
302 // ========================================================================
303 public:
304 // ========================================================================
320 StatusCode column( const std::string& name, short value );
321 // ========================================================================
339 StatusCode column( const std::string& name, short value, short minv, short maxv );
340 // ========================================================================
341 public:
342 // ========================================================================
358 StatusCode column( const std::string& name, unsigned short value );
359 // ========================================================================
377 StatusCode column( const std::string& name, unsigned short value, unsigned short minv, unsigned short maxv );
378 // ========================================================================
379 public:
380 // ========================================================================
396 StatusCode column( const std::string& name, char value );
397 // ========================================================================
415 StatusCode column( const std::string& name, char value, char minv, char maxv );
416 // ========================================================================
417 public:
418 // ========================================================================
434 StatusCode column( const std::string& name, unsigned char value );
435 // ========================================================================
453 StatusCode column( const std::string& name, unsigned char value, unsigned char minv, unsigned char maxv );
454 // ========================================================================
455 public:
456 // ========================================================================
472 StatusCode column( const std::string& name, int value );
473 // ========================================================================
491 StatusCode column( const std::string& name, int value, int minv, int maxv );
492 // ========================================================================
493 public:
494 // ========================================================================
510 StatusCode column( const std::string& name, unsigned int value );
511 // ========================================================================
529 StatusCode column( const std::string& name, unsigned int value, unsigned int minv, unsigned int maxv );
530 // ========================================================================
531 public:
532 // ========================================================================
549 StatusCode column( const std::string& name, long value );
550 // ========================================================================
568 StatusCode column( const std::string& name, long value, long minv, long maxv );
569 // ========================================================================
570 public:
571 // ========================================================================
588 StatusCode column( const std::string& name, unsigned long value );
589 // ========================================================================
607 StatusCode column( const std::string& name, unsigned long value, unsigned long minv, unsigned long maxv );
608 // ========================================================================
609 public:
610 // ========================================================================
626 StatusCode column( const std::string& name, long long value );
627 // ========================================================================
645 StatusCode column( const std::string& name, long long value, long long minv, long long maxv );
646 // ========================================================================
647 public:
648 // ========================================================================
664 StatusCode column( const std::string& name, unsigned long long value );
665 // ========================================================================
683 StatusCode column( const std::string& name, unsigned long long value, unsigned long long minv,
684 unsigned long long maxv );
685 // ========================================================================
686 public:
687 // ========================================================================
703 StatusCode column( const std::string& name, signed char value ) {
704 return column( name, value, std::numeric_limits<signed char>::min(), std::numeric_limits<signed char>::max() );
705 }
706 // ========================================================================
707 public:
708 // ========================================================================
723 StatusCode column( const std::string& name, bool value );
724 // ========================================================================
725 public:
726 // ========================================================================
745 StatusCode column( const std::string& name, IOpaqueAddress* address );
746 // ========================================================================
763 StatusCode column( IOpaqueAddress* address );
764 // ========================================================================
765 public:
766 // ========================================================================
786 template <typename Value, typename... Args>
787 StatusCode columns( Value&& value, Args&&... args ) {
788 if ( sizeof...( Args ) == 0 ) return StatusCode::SUCCESS;
789 std::initializer_list<StatusCode> scs{
790 this->column( std::get<0>( args ), std::invoke( std::get<1>( args ), value ) )...};
791 return std::accumulate( std::next( begin( scs ) ), end( scs ), *begin( scs ),
792 []( StatusCode sc, const StatusCode& i ) {
793 i.ignore(); // make sure there are no unchecked StatusCodes...
794 return sc.isFailure() ? sc : i; // latch to the first non-success case
795 } );
796 }
797 // ========================================================================
798 public:
799 // ========================================================================
823 StatusCode fill( const char* format... );
824 // =======================================================================
825 public:
826 // =======================================================================
875 template <typename ITERATOR1, typename ITERATOR2>
876 StatusCode farray( const std::string& name, ITERATOR1&& first, ITERATOR2&& last, const std::string& length,
877 size_t maxv ) {
878 return farray( name, detail::to_float, std::forward<ITERATOR1>( first ), std::forward<ITERATOR2>( last ), length,
879 maxv );
880 }
881 // =======================================================================
924 template <class DATA>
925 StatusCode farray( const std::string& name, const DATA& data, const std::string& length, const size_t maxv ) {
926 return farray( name, std::begin( data ), std::end( data ), length, maxv );
927 }
928 // =======================================================================
991 template <class FUNCTION, class ITERATOR>
992 StatusCode farray( const std::string& name, const FUNCTION& function, ITERATOR first, ITERATOR last,
993 const std::string& length, size_t maxv ) {
994 if ( invalid() ) return ErrorCodes::InvalidTuple;
995 if ( rowWise() ) return ErrorCodes::InvalidOperation;
996
997 // adjust the length
998 if ( std::distance( first, last ) > static_cast<std::ptrdiff_t>( maxv ) ) {
999 Warning( "farray('" + name + "'): array is overflow, skip extra entries" );
1000 last = std::next( first, maxv );
1001 }
1002
1003 // get the length item
1004 Int* len = ints( length, 0, maxv );
1005 if ( !len ) return ErrorCodes::InvalidColumn;
1006
1007 // adjust the length
1008 *len = std::distance( first, last );
1009
1010 // get the array itself
1011 FArray* var = fArray( name, len );
1012 if ( !var ) return ErrorCodes::InvalidColumn;
1013
1014 // fill the array
1015 std::transform( first, last, std::begin( *var ),
1016 [&]( auto&& i ) { return std::invoke( function, std::forward<decltype( i )>( i ) ); } );
1017
1018 return StatusCode::SUCCESS;
1019 }
1020 // =======================================================================
1048 template <typename FunIterator, typename DataIterator>
1049 StatusCode farray_impl( FunIterator first_item, FunIterator last_item, DataIterator first, DataIterator last,
1050 const std::string& length, size_t maxv ) {
1051 if ( invalid() ) return ErrorCodes::InvalidTuple;
1052 if ( rowWise() ) return ErrorCodes::InvalidOperation;
1053
1054 // adjust the length
1055 if ( std::distance( first, last ) > static_cast<std::ptrdiff_t>( maxv ) ) {
1056 using GaudiUtils::details::ostream_joiner;
1057 std::ostringstream os;
1058 ostream_joiner( os, first_item, last_item, ",",
1059 []( std::ostream& os, const auto& i ) -> decltype( auto ) { return os << i.first; } );
1060 Warning( "farray('" + os.str() + "'): array overflow, skipping extra entries" ).ignore();
1061 last = std::next( first, maxv );
1062 }
1063
1064 // get the length item
1065 Int* len = ints( length, 0, maxv );
1066 if ( !len ) return ErrorCodes::InvalidColumn;
1067
1068 // adjust the length
1069 *len = std::distance( first, last );
1070
1071 // get the arrays themselves
1072 std::vector<FArray*> vars;
1073 vars.reserve( std::distance( first_item, last_item ) );
1074 std::transform( first_item, last_item, std::back_inserter( vars ),
1075 [&]( const auto& item ) { return this->fArray( item.first, len ); } );
1076 if ( std::any_of( vars.begin(), vars.end(), []( const FArray* f ) { return !f; } ) ) {
1077 return ErrorCodes::InvalidColumn;
1078 }
1079
1080 // fill the array
1081 for ( size_t index = 0; first != last; ++first, ++index ) {
1082 auto item = first_item;
1083 for ( auto& var : vars ) { ( *var )[index] = std::invoke( ( item++ )->second, *first ); }
1084 }
1085
1086 return StatusCode::SUCCESS;
1087 }
1088
1089 template <
1090 typename DataIterator, template <typename, typename...> class Container = std::initializer_list,
1091 typename NamedFunction = std::pair<std::string, std::function<float( detail::const_ref_t<DataIterator> )>>,
1092 typename = std::enable_if_t<!std::is_convertible_v<Container<NamedFunction>, std::string>>>
1093 StatusCode farray( const Container<NamedFunction>& funs, DataIterator first, DataIterator last,
1094 const std::string& length, size_t maxv ) {
1095 return farray_impl( funs.begin(), funs.end(), std::forward<DataIterator>( first ),
1096 std::forward<DataIterator>( last ), length, maxv );
1097 }
1098
1099 template <typename NamedFunctions, typename DataIterator,
1100 typename = std::enable_if_t<!std::is_convertible_v<NamedFunctions, std::string>>>
1101 StatusCode farray( const NamedFunctions& funs, DataIterator first, DataIterator last, const std::string& length,
1102 size_t maxv ) {
1103 return farray_impl( funs.begin(), funs.end(), std::forward<DataIterator>( first ),
1104 std::forward<DataIterator>( last ), length, maxv );
1105 }
1106 // =======================================================================
1138 template <class FUNC1, class FUNC2, class Iterator>
1139 StatusCode farray( const std::string& name1, const FUNC1& func1, const std::string& name2, const FUNC2& func2,
1140 Iterator&& first, Iterator&& last, const std::string& length, size_t maxv ) {
1141 return farray( {{name1, std::cref( func1 )}, {name2, std::cref( func2 )}}, std::forward<Iterator>( first ),
1142 std::forward<Iterator>( last ), length, maxv );
1143 }
1144 // =======================================================================
1181 template <class FUNC1, class FUNC2, class FUNC3, class Iterator>
1182 StatusCode farray( const std::string& name1, const FUNC1& func1, const std::string& name2, const FUNC2& func2,
1183 const std::string& name3, const FUNC3& func3, Iterator&& first, Iterator&& last,
1184 const std::string& length, size_t maxv ) {
1185 return farray( {{name1, std::cref( func1 )}, {name2, std::cref( func2 )}, {name3, std::cref( func3 )}},
1186 std::forward<Iterator>( first ), std::forward<Iterator>( last ), length, maxv );
1187 }
1188 // =======================================================================
1228 template <class FUNC1, class FUNC2, class FUNC3, class FUNC4, class Iterator>
1229 StatusCode farray( const std::string& name1, const FUNC1& func1, const std::string& name2, const FUNC2& func2,
1230 const std::string& name3, const FUNC3& func3, const std::string& name4, const FUNC4& func4,
1231 Iterator&& first, Iterator&& last, const std::string& length, size_t maxv ) {
1232 return farray( {{name1, std::cref( func1 )},
1233 {name2, std::cref( func2 )},
1234 {name3, std::cref( func3 )},
1235 {name4, std::cref( func4 )}},
1236 std::forward<Iterator>( first ), std::forward<Iterator>( last ), length, maxv );
1237 }
1238 // =======================================================================
1239 public:
1240 // =======================================================================
1291 template <class MATRIX>
1292 StatusCode fmatrix( const std::string& name, const MATRIX& data, size_t rows, const MIndex& cols,
1293 const std::string& length, size_t maxv ) {
1294 if ( invalid() ) return ErrorCodes::InvalidTuple;
1295 if ( rowWise() ) return ErrorCodes::InvalidOperation;
1296
1297 // adjust the length
1298 if ( rows >= maxv ) {
1299 Warning( "fmatrix('" + name + "'): matrix is overflow, skip extra items" ).ignore();
1300 rows = ( 0 < maxv ) ? ( maxv - 1 ) : 0;
1301 }
1302
1303 // get the length item
1304 Int* len = ints( length, 0, maxv );
1305 if ( !len ) return ErrorCodes::InvalidColumn;
1306
1307 // adjust the length item
1308 *len = rows;
1309
1310 // get the array itself
1311 FMatrix* var = fMatrix( name, len, cols );
1312 if ( !var ) return ErrorCodes::InvalidColumn;
1313
1315 for ( size_t iCol = 0; iCol < cols; ++iCol ) {
1316 for ( MIndex iRow = 0; iRow < rows; ++iRow ) { ( *var )[iRow][iCol] = data[iRow][iCol]; }
1317 }
1318
1319 return StatusCode::SUCCESS;
1320 }
1321 // =======================================================================
1358 template <class DATA>
1359 StatusCode fmatrix( const std::string& name, DATA first, DATA last, const MIndex& cols, const std::string& length,
1360 size_t maxv ) {
1361 if ( invalid() ) return ErrorCodes::InvalidTuple;
1362 if ( rowWise() ) return ErrorCodes::InvalidOperation;
1363
1364 // adjust the length
1365 if ( first + maxv < last ) {
1366 Warning( "fmatrix('" + name + "'): matrix is overflow, skip extra items" ).ignore();
1367 last = first + maxv;
1368 }
1369
1370 // get the length item
1371 Int* len = ints( length, 0, maxv );
1372 if ( !len ) return ErrorCodes::InvalidColumn;
1373
1374 // adjust the length item
1375 *len = last - first;
1376
1377 // get the array itself
1378 FMatrix* var = fMatrix( name, len, cols );
1379 if ( !var ) return ErrorCodes::InvalidColumn;
1380
1382 size_t iRow = 0;
1383 for ( ; first != last; ++first ) {
1384 //
1385 for ( MIndex iCol = 0; iCol < cols; ++iCol ) { ( *var )[iRow][iCol] = ( *first )[iCol]; }
1386 //
1387 ++iRow;
1388 }
1389
1390 return StatusCode::SUCCESS;
1391 }
1392 // =======================================================================
1471 template <class FUN, class DATA>
1472 StatusCode fmatrix( const std::string& name, FUN funF, FUN funL, DATA first, DATA last, const std::string& length,
1473 size_t maxv ) {
1474 if ( invalid() ) return ErrorCodes::InvalidTuple;
1475 if ( rowWise() ) return ErrorCodes::InvalidOperation;
1476
1477 // adjust the length
1478 if ( std::distance( first, last ) > static_cast<std::ptrdiff_t>( maxv ) ) {
1479 Warning( "fmatrix('" + name + "'): matrix is overflow, skip extra items" ).ignore();
1480 last = std::next( first, maxv );
1481 }
1482
1483 // get the length item
1484 Int* len = ints( length, 0, maxv );
1485
1486 if ( !len ) return ErrorCodes::InvalidColumn;
1487
1488 // adjust the length item
1489 *len = std::distance( first, last );
1490
1491 // get the array itself
1492 auto cols = std::distance( funF, funL );
1493 FMatrix* var = fMatrix( name, len, cols );
1494 if ( !var ) return ErrorCodes::InvalidColumn;
1495
1497 size_t iRow = 0;
1498 for ( ; first != last; ++first ) {
1499 //
1500 for ( FUN fun = funF; fun < funL; ++fun ) { ( *var )[iRow][fun - funF] = std::invoke( *fun, *first ); }
1501 //
1502 ++iRow;
1503 }
1504
1505 return StatusCode::SUCCESS;
1506 }
1507 // =======================================================================
1508 public:
1509 // =======================================================================
1532 template <class DATA>
1533 StatusCode array( const std::string& name, DATA first, DATA last )
1534
1535 {
1536 if ( invalid() ) return ErrorCodes::InvalidTuple;
1537 if ( rowWise() ) return ErrorCodes::InvalidOperation;
1538
1539 // get the length (fixed!)
1540 auto length = std::distance( first, last );
1541
1542 // get the array itself
1543 FArray* var = fArray( name, length );
1544 if ( !var ) return ErrorCodes::InvalidColumn;
1545
1547 std::copy( first, last, std::begin( *var ) );
1548
1549 return StatusCode::SUCCESS;
1550 }
1551 // =======================================================================
1590 template <class ARRAY>
1591 StatusCode array( const std::string& name, const ARRAY& data, const MIndex& length ) {
1592 using std::begin; // allow data to be eg. CLHEP::HepVector (which does not define HepVector::begin()!,
1593 // in which case ADL prefers CLHEP::begin (yah! at least they (now) use a namespace)
1594 // so one just to insure double* CLHEP::begin(CLHEP::HepVector& v) { return &v[0]; }
1595 // is visible when this function gets instantiated for CLHEP::HepVector...
1596 auto first = begin( data );
1597 return array( name, first, std::next( first, length ) );
1598 }
1599 // =======================================================================
1630 template <class ARRAY>
1631 StatusCode array( const std::string& name, const ARRAY& data ) {
1632 using std::begin;
1633 using std::end;
1634 return array( name, begin( data ), end( data ) );
1635 }
1636 // =======================================================================
1637 public:
1638 // =======================================================================
1687 template <class MATRIX>
1688 StatusCode matrix( const std::string& name, const MATRIX& data, const MIndex& rows, const MIndex& cols ) {
1689 if ( invalid() ) return ErrorCodes::InvalidTuple;
1690 if ( rowWise() ) return ErrorCodes::InvalidOperation;
1691
1692 // get the matrix itself
1693 FMatrix* var = fMatrix( name, rows, cols );
1694 if ( !var ) return ErrorCodes::InvalidColumn;
1695
1697 for ( size_t iCol = 0; iCol < cols; ++iCol ) {
1698 for ( size_t iRow = 0; iRow < rows; ++iRow ) { ( *var )[iRow][iCol] = data[iRow][iCol]; }
1699 };
1700 return StatusCode::SUCCESS;
1701 }
1702 // =======================================================================
1703 public:
1704 // =======================================================================
1721 template <class TYPE>
1722 StatusCode column( const std::string& name, const ROOT::Math::LorentzVector<TYPE>& v ) {
1723 return columns( v, std::make_pair( name + "E", &ROOT::Math::LorentzVector<TYPE>::E ),
1724 std::make_pair( name + "X", &ROOT::Math::LorentzVector<TYPE>::Px ),
1725 std::make_pair( name + "Y", &ROOT::Math::LorentzVector<TYPE>::Py ),
1726 std::make_pair( name + "Z", &ROOT::Math::LorentzVector<TYPE>::Pz ) );
1727 }
1728 // =======================================================================
1745 template <class TYPE, class TAG>
1746 StatusCode column( const std::string& name, const ROOT::Math::DisplacementVector3D<TYPE, TAG>& v ) {
1747 return this->columns( v, std::make_pair( name + "X", &ROOT::Math::DisplacementVector3D<TYPE, TAG>::X ),
1748 std::make_pair( name + "Y", &ROOT::Math::DisplacementVector3D<TYPE, TAG>::Y ),
1749 std::make_pair( name + "Z", &ROOT::Math::DisplacementVector3D<TYPE, TAG>::Z ) );
1750 }
1751 // =======================================================================
1768 template <class TYPE, class TAG>
1769 StatusCode column( const std::string& name, const ROOT::Math::PositionVector3D<TYPE, TAG>& v ) {
1770 return this->columns( v, std::make_pair( name + "X", &ROOT::Math::PositionVector3D<TYPE, TAG>::X ),
1771 std::make_pair( name + "Y", &ROOT::Math::PositionVector3D<TYPE, TAG>::Y ),
1772 std::make_pair( name + "Z", &ROOT::Math::PositionVector3D<TYPE, TAG>::Z ) );
1773 }
1774 // =======================================================================
1783 template <class TYPE, unsigned int D1, unsigned int D2, class REP>
1784 StatusCode matrix( const std::string& name, const ROOT::Math::SMatrix<TYPE, D1, D2, REP>& mtrx ) {
1785 if ( invalid() ) return ErrorCodes::InvalidTuple;
1786 if ( rowWise() ) return ErrorCodes::InvalidOperation;
1787
1788 // get the matrix itself
1789 FMatrix* var = fMatrix( name, (MIndex)D1, (MIndex)D2 );
1790 if ( !var ) return ErrorCodes::InvalidColumn;
1791
1793 for ( size_t iCol = 0; iCol < D2; ++iCol ) {
1794 for ( size_t iRow = 0; iRow < D1; ++iRow ) { ( *var )[iRow][iCol] = mtrx( iRow, iCol ); }
1795 };
1796
1797 return StatusCode::SUCCESS;
1798 }
1799 // =======================================================================
1817 template <class KEY, class VALUE>
1818 StatusCode fmatrix( const std::string& name, const GaudiUtils::VectorMap<KEY, VALUE>& info,
1819 const std::string& length, const size_t maxv = 100 ) {
1820 using Info = std::pair<KEY, VALUE>;
1821 static const std::array<float ( * )( const Info& ), 2> fns = {
1822 {[]( const Info& i ) -> float { return i.first; }, []( const Info& i ) -> float { return i.second; }}};
1823 return fmatrix( name, begin( fns ), end( fns ), begin( info ), end( info ), length, maxv );
1824 }
1825 // =======================================================================
1826 public:
1827 // =======================================================================
1835 template <class TYPE>
1836 StatusCode put( const std::string& name, const TYPE* obj );
1837 // =======================================================================
1838 public:
1839 // =======================================================================
1843 StatusCode write();
1844 // =======================================================================
1846 const std::string& name() const { return m_name; }
1847 // =======================================================================
1851 const NTuple::Tuple* tuple() const { return m_tuple; }
1852 // =======================================================================
1856 NTuple::Tuple* tuple() { return m_tuple; }
1857 // =======================================================================
1859 const CLID& clid() const { return m_clid; }
1860 // =======================================================================
1862 Tuples::Type type() const { return m_type; }
1863 // =======================================================================
1865 bool columnWise() const { return CLID_ColumnWiseTuple == clid(); }
1866 // =======================================================================
1868 bool rowWise() const { return CLID_RowWiseTuple == clid(); }
1869 // =======================================================================
1871 bool evtColType() const { return Tuples::EVTCOL == type(); }
1872 // =======================================================================
1874 bool valid() const { return 0 != tuple(); }
1875 // =======================================================================
1877 bool invalid() const { return !valid(); }
1878 // =======================================================================
1879 public:
1880 // =======================================================================
1886 bool addItem( std::string name, std::string type ) {
1887 return m_items.emplace( std::move( name ), std::move( type ) ).second;
1888 }
1889 // =======================================================================
1894 bool goodItem( const std::string& name ) const { return m_items.end() == m_items.find( name ); }
1895 // =======================================================================
1897 const ItemMap& items() const { return m_items; }
1898 // =======================================================================
1899 public:
1900 // =======================================================================
1901 virtual StatusCode Error( const std::string& msg, const StatusCode sc = StatusCode::FAILURE ) const = 0;
1902 // =======================================================================
1903 virtual StatusCode Warning( const std::string& msg, const StatusCode sc = StatusCode::FAILURE ) const = 0;
1904 // =======================================================================
1905 private:
1906 // =======================================================================
1908 Int* ints( const std::string& name, int minv, int maxv );
1909 // =======================================================================
1911 FArray* fArray( const std::string& name, Int* item );
1912 // =======================================================================
1914 FArray* fArray( const std::string& name, const MIndex& rows );
1915 // =======================================================================
1917 Address* addresses( const std::string& name );
1918 // =======================================================================
1920 FMatrix* fMatrix( const std::string& name, Int* item, const MIndex& cols );
1921 // =======================================================================
1923 FMatrix* fMatrix( const std::string& name, const MIndex& rows, const MIndex& cols );
1924 // =======================================================================
1926 TupleObj( const TupleObj& ) = delete;
1927 TupleObj& operator=( const TupleObj& ) = delete;
1928 // =======================================================================
1929 private:
1930 // =======================================================================
1932 std::string m_name;
1933 // =======================================================================
1935 NTuple::Tuple* m_tuple;
1936 // =======================================================================
1938 CLID m_clid;
1939 // =======================================================================
1941 Tuples::Type m_type;
1942 // =======================================================================
1944 size_t m_refCount = 0;
1945 // =======================================================================
1946 // helper type to define the actual storage types
1947 template <typename T>
1948 using ColumnStorage = GaudiUtils::HashMap<std::string, std::unique_ptr<T>>;
1949 // =======================================================================
1951 mutable ColumnStorage<Bool> m_bools;
1952 // =======================================================================
1954 mutable ColumnStorage<Char> m_chars;
1955 // =======================================================================
1957 mutable ColumnStorage<UChar> m_uchars;
1958 // =======================================================================
1960 mutable ColumnStorage<Short> m_shorts;
1961 // =======================================================================
1963 mutable ColumnStorage<UShort> m_ushorts;
1964 // =======================================================================
1966 mutable ColumnStorage<Int> m_ints;
1967 // =======================================================================
1969 mutable ColumnStorage<UInt> m_uints;
1970 // =======================================================================
1972 mutable ColumnStorage<LongLong> m_longlongs;
1973 // =======================================================================
1975 mutable ColumnStorage<ULongLong> m_ulonglongs;
1976 // =======================================================================
1978 mutable ColumnStorage<Float> m_floats;
1979 // =======================================================================
1981 mutable ColumnStorage<Double> m_doubles;
1982 // =======================================================================
1984 mutable ColumnStorage<Address> m_addresses;
1985 // =======================================================================
1987 mutable ColumnStorage<FArray> m_farrays;
1988 // =======================================================================
1990 mutable ColumnStorage<FArray> m_arraysf;
1991 // =======================================================================
1993 mutable ColumnStorage<FMatrix> m_fmatrices;
1994 // =======================================================================
1996 mutable ColumnStorage<FMatrix> m_matricesf;
1997 // =======================================================================
1999 ItemMap m_items;
2000 // =======================================================================
2001 };
2002 // ==========================================================================
2003 } // end of namespace Tuples
2004
2005 // ============================================================================
2006 // GaudiAlg
2007 // ============================================================================
2008 #include "GaudiAlg/TuplePut.h"
2009 // ============================================================================
2010 // The END
2011 // ============================================================================
2012 #endif // GAUDIALG_TUPLEOBJ_H
Tuples::TupleObj::column
StatusCode column(const std::string &name, const ROOT::Math::DisplacementVector3D< TYPE, TAG > &v)
Useful shortcut to put 3D-Vector directly into N-Tuple:
Definition: TupleObj.h:1746
Tuples::TupleObj::m_arraysf
ColumnStorage< FArray > m_arraysf
the actual storage of all 'FArray' columns (fixed)
Definition: TupleObj.h:1990
GaudiUtils::VectorMap
A bit modified version of 'Loki::AssocVector' associative vector from Loki library by Andrei Alexandr...
Definition: VectorMap.h:102
Tuples::TupleObj::m_clid
CLID m_clid
tuple CLID
Definition: TupleObj.h:1938
Tuples::TupleObj::m_floats
ColumnStorage< Float > m_floats
the actual storage of all 'Float' columns
Definition: TupleObj.h:1978
Tuples::TupleObj::m_addresses
ColumnStorage< Address > m_addresses
the actual storage of all 'Address' columns
Definition: TupleObj.h:1984
Tuples::TupleObj::ItemMap
std::map< std::string, std::string > ItemMap
Definition: TupleObj.h:248
std::copy
T copy(T... args)
Tuples::TupleObj::matrix
StatusCode matrix(const std::string &name, const MATRIX &data, const MIndex &rows, const MIndex &cols)
fill N-Tuple with fixed-size matrix
Definition: TupleObj.h:1688
std::distance
T distance(T... args)
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:109
Tuples::TupleObj::Float
NTuple::Item< float > Float
basic type for float items
Definition: TupleObj.h:230
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Tuples::TupleObj::m_bools
ColumnStorage< Bool > m_bools
the actual storage of all 'bool' columns
Definition: TupleObj.h:1951
std::function
Tuples::TupleObj::m_type
Tuples::Type m_type
tuple 'type'
Definition: TupleObj.h:1941
NTuple::Matrix
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:52
Tuples::TupleObj::Address
NTuple::Item< IOpaqueAddress * > Address
basic type for address items
Definition: TupleObj.h:236
NTuple.h
AvalancheSchedulerErrorTest.scs
scs
Definition: AvalancheSchedulerErrorTest.py:31
Tuples::ErrorCodes
ErrorCodes
Tuple error codes.
Definition: TupleObj.h:91
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
Tuples::TupleObj::clid
const CLID & clid() const
accessor to the N-Tuple CLID
Definition: TupleObj.h:1859
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:35
Tuples::TupleObj::ULongLong
NTuple::Item< unsigned long long > ULongLong
basic type for unsigned long long items
Definition: TupleObj.h:227
Tuples::TupleObj::UShort
NTuple::Item< unsigned short > UShort
basic type for unsigned int items
Definition: TupleObj.h:215
Tuples::TupleObj::invalid
bool invalid() const
invalid pointer to tuple ?
Definition: TupleObj.h:1877
std::end
T end(T... args)
Tuples::TupleObj::fmatrix
StatusCode fmatrix(const std::string &name, const MATRIX &data, size_t rows, const MIndex &cols, const std::string &length, size_t maxv)
Fill N-Tuple with data from variable-size matrix.
Definition: TupleObj.h:1292
Tuples::TupleObj::MIndex
unsigned short MIndex
Definition: TupleObj.h:245
ROOT::Math::PositionVector3D
Definition: IMagneticFieldSvc.h:15
Tuples::TupleObj::m_longlongs
ColumnStorage< LongLong > m_longlongs
the actual storage of all 'long long' columns
Definition: TupleObj.h:1972
Tuples::TupleObj::m_ushorts
ColumnStorage< UShort > m_ushorts
the actual storage of all 'unsigned int' columns
Definition: TupleObj.h:1963
Tuples::ErrorCodes::InvalidItem
Tuples::TupleObj::type
Tuples::Type type() const
accessor to the N-Tuple type
Definition: TupleObj.h:1862
std::map< std::string, std::string >
Tuples::TupleObj::m_name
std::string m_name
name
Definition: TupleObj.h:1932
Tuples::TupleObj::evtColType
bool evtColType() const
Event collection ?
Definition: TupleObj.h:1871
Tuples::TupleObj::tuple
NTuple::Tuple * tuple()
provide the access to underlying Gaudi N-tuple
Definition: TupleObj.h:1856
Tuples::TupleObj::farray
StatusCode farray(const std::string &name, ITERATOR1 &&first, ITERATOR2 &&last, const std::string &length, size_t maxv)
Add an indexed array (of type float) to N-tuple.
Definition: TupleObj.h:876
Tuples::TupleObj::UChar
NTuple::Item< unsigned char > UChar
basic type for unsigned int items
Definition: TupleObj.h:209
Tuples::ErrorCodes::InvalidOperation
SerializeSTL.h
Provide serialization function (output only) for some common STL classes (vectors,...
Tuples::TupleObj::m_uints
ColumnStorage< UInt > m_uints
the actual storage of all 'unsigned int' columns
Definition: TupleObj.h:1969
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:121
std::string
STL class.
Tuples::TupleObj::Short
NTuple::Item< short > Short
basic type for int items
Definition: TupleObj.h:212
Tuples::TupleObj::addItem
bool addItem(std::string name, std::string type)
add the item name into the list of known items
Definition: TupleObj.h:1886
Tuples::TupleObj::m_doubles
ColumnStorage< Double > m_doubles
the actual storage of all 'Double' columns
Definition: TupleObj.h:1981
Tuples::TupleObj::fmatrix
StatusCode fmatrix(const std::string &name, FUN funF, FUN funL, DATA first, DATA last, const std::string &length, size_t maxv)
fill N-Tuple with matrix of "direct-product" of "data-vector" [first,last) and "function-vector" [fun...
Definition: TupleObj.h:1472
Tuples::TupleObj::m_fmatrices
ColumnStorage< FMatrix > m_fmatrices
the actual storage of all 'FArray' columns
Definition: TupleObj.h:1993
Tuples::detail::to_float
constexpr to_< float > to_float
Definition: TupleObj.h:68
Tuples::TupleObj::m_ulonglongs
ColumnStorage< ULongLong > m_ulonglongs
the actual storage of all 'unsigned long long' columns
Definition: TupleObj.h:1975
STATUSCODE_ENUM_DECL
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
Definition: StatusCode.h:239
gaudirun.args
args
Definition: gaudirun.py:307
detail
TupleObj.h GaudiAlg/TupleObj.h namespace with few technical implementations.
VectorMap.h
Tuples::TupleObj
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: TupleObj.h:199
std::next
T next(T... args)
Tuples::TupleObj::array
StatusCode array(const std::string &name, const ARRAY &data)
fill N-Tuple with fixed-size array
Definition: TupleObj.h:1631
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Tuples::ErrorCodes::InvalidTuple
Tuples::TupleObj::m_chars
ColumnStorage< Char > m_chars
the actual storage of all 'Int' columns
Definition: TupleObj.h:1954
Tuples::TupleObj::farray
StatusCode farray(const std::string &name1, const FUNC1 &func1, const std::string &name2, const FUNC2 &func2, const std::string &name3, const FUNC3 &func3, Iterator &&first, Iterator &&last, const std::string &length, size_t maxv)
Put three functions from one data array into LoKi-style N-Tuple simultaneously (effective!...
Definition: TupleObj.h:1182
Tuples::TupleObj::farray
StatusCode farray(const std::string &name, const DATA &data, const std::string &length, const size_t maxv)
Add an indexed array (of type float) to N-tuple.
Definition: TupleObj.h:925
Tuples::TupleObj::FMatrix
NTuple::Matrix< float > FMatrix
basic type for matrix of floats
Definition: TupleObj.h:242
std::ostringstream
STL class.
gaudirun.type
type
Definition: gaudirun.py:142
Tuples::ErrorCodes::InvalidColumn
Tuples::ErrorCodes::TruncateValue
Tuples::TupleObj::matrix
StatusCode matrix(const std::string &name, const ROOT::Math::SMatrix< TYPE, D1, D2, REP > &mtrx)
shortcut to put Smatrix into N-tuple:
Definition: TupleObj.h:1784
Tuples::TupleObj::m_shorts
ColumnStorage< Short > m_shorts
the actual storage of all 'Int' columns
Definition: TupleObj.h:1960
std::make_pair
T make_pair(T... args)
Tuples::TupleObj::m_items
ItemMap m_items
all booked types:
Definition: TupleObj.h:1999
Tuples::TupleObj::Bool
NTuple::Item< bool > Bool
basic type for int items
Definition: TupleObj.h:203
Tuples::TupleObj::Double
NTuple::Item< double > Double
basic type for double items
Definition: TupleObj.h:233
Tuples::TupleObj::m_ints
ColumnStorage< Int > m_ints
the actual storage of all 'Int' columns
Definition: TupleObj.h:1966
Tuples::TupleObj::tuple
const NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
Definition: TupleObj.h:1851
IOTest.end
def end
Definition: IOTest.py:112
Tuples::TupleObj::farray
StatusCode farray(const std::string &name1, const FUNC1 &func1, const std::string &name2, const FUNC2 &func2, Iterator &&first, Iterator &&last, const std::string &length, size_t maxv)
Put two functions from one data array into LoKi-style N-Tuple simultaneously (effective!...
Definition: TupleObj.h:1139
NTuple::Item< bool >
Specialization acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:295
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
Tuples::TupleObj::columnWise
bool columnWise() const
column wise NTuple ?
Definition: TupleObj.h:1865
Tuples::TupleObj::farray_impl
StatusCode farray_impl(FunIterator first_item, FunIterator last_item, DataIterator first, DataIterator last, const std::string &length, size_t maxv)
Put arbitrary number of functions from one data array into LoKi-style N-Tuple simultaneously (effecti...
Definition: TupleObj.h:1049
std::move
T move(T... args)
ROOT::Math::DisplacementVector3D
Definition: IMagneticFieldSvc.h:18
Tuples::TupleObj::fmatrix
StatusCode fmatrix(const std::string &name, DATA first, DATA last, const MIndex &cols, const std::string &length, size_t maxv)
Fill N-Tuple with data from variable-size matrix.
Definition: TupleObj.h:1359
GaudiUtils::details::ostream_joiner
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:37
NTuple::Tuple
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:375
Tuples::TupleObj::column
StatusCode column(const std::string &name, signed char value)
Set the value for the selected tuple column.
Definition: TupleObj.h:703
std::pair
Tuples::TupleObj::LongLong
NTuple::Item< long long > LongLong
basic type for unsigned long long items
Definition: TupleObj.h:224
Tuples::TupleObj::name
const std::string & name() const
get the name
Definition: TupleObj.h:1846
Tuples::EVTCOL
Definition: TupleObj.h:81
Tuples::TupleObj::farray
StatusCode farray(const NamedFunctions &funs, DataIterator first, DataIterator last, const std::string &length, size_t maxv)
Definition: TupleObj.h:1101
Maps.h
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
Tuples::TupleObj::farray
StatusCode farray(const std::string &name1, const FUNC1 &func1, const std::string &name2, const FUNC2 &func2, const std::string &name3, const FUNC3 &func3, const std::string &name4, const FUNC4 &func4, Iterator &&first, Iterator &&last, const std::string &length, size_t maxv)
Put four functions from one data array into LoKi-style N-Tuple simultaneously (effective!...
Definition: TupleObj.h:1229
Tuples::TupleObj::array
StatusCode array(const std::string &name, DATA first, DATA last)
fill N-Tuple with fixed-size array
Definition: TupleObj.h:1533
Containers::array
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
Definition: KeyedObjectManager.h:27
std::vector
STL class.
Tuples::TupleObj::m_tuple
NTuple::Tuple * m_tuple
tuple itself
Definition: TupleObj.h:1935
Tuples::TupleObj::items
const ItemMap & items() const
get the full list of booked items
Definition: TupleObj.h:1897
Tuples::TupleObj::fmatrix
StatusCode fmatrix(const std::string &name, const GaudiUtils::VectorMap< KEY, VALUE > &info, const std::string &length, const size_t maxv=100)
shortcut to put "ExtraInfo" fields of major into N-Tuple
Definition: TupleObj.h:1818
std::cref
T cref(T... args)
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:18
Tuples::TupleObj::rowWise
bool rowWise() const
row wise NTuple ?
Definition: TupleObj.h:1868
std::begin
T begin(T... args)
Tuples::TupleObj::m_matricesf
ColumnStorage< FMatrix > m_matricesf
the actual storage of all 'FMatrix' columns (fixed)
Definition: TupleObj.h:1996
Tuples::TupleObj::farray
StatusCode farray(const std::string &name, const FUNCTION &function, ITERATOR first, ITERATOR last, const std::string &length, size_t maxv)
Put an indexed array into LoKi-style N-Tuple.
Definition: TupleObj.h:992
std::back_inserter
T back_inserter(T... args)
Gaudi::Functional::details::put
Out1 * put(const DataObjectHandle< Out1 > &out_handle, Out2 &&out)
Definition: FunctionalDetails.h:121
std::any_of
T any_of(T... args)
Tuples::TupleObj::farray
StatusCode farray(const Container< NamedFunction > &funs, DataIterator first, DataIterator last, const std::string &length, size_t maxv)
Definition: TupleObj.h:1093
Tuples::TupleObj::Char
NTuple::Item< char > Char
basic type for int items
Definition: TupleObj.h:206
Tuples::detail::const_ref_t
std::add_const_t< typename std::iterator_traits< Iterator >::reference > const_ref_t
Definition: TupleObj.h:71
GaudiUtils::HashMap
Common class providing an architecture-independent hash map.
Definition: HashMap.h:73
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
std::array
STL class.
Tuples::TupleObj::Int
NTuple::Item< int > Int
basic type for int items
Definition: TupleObj.h:218
Tuples.h
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
Tuples::TupleObj::column
StatusCode column(const std::string &name, const ROOT::Math::LorentzVector< TYPE > &v)
Useful shortcut to put LorentzVector directly into N-Tuple:
Definition: TupleObj.h:1722
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:787
Tuples::TupleObj::valid
bool valid() const
valid pointer to tuple ?
Definition: TupleObj.h:1874
std::transform
T transform(T... args)
Tuples::NTUPLE
Definition: TupleObj.h:80
Tuples::TupleObj::FArray
NTuple::Array< float > FArray
basic type for array of floats
Definition: TupleObj.h:239
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:120
std::accumulate
T accumulate(T... args)
TuplePut.h
Implementation file for Tuple::TupleObj::put method.
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
NTuple::Item
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:48
Tuples::TupleObj::array
StatusCode array(const std::string &name, const ARRAY &data, const MIndex &length)
fill N-Tuple with fixed-size array
Definition: TupleObj.h:1591
NTuple::Array
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:50
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:71
Tuples::detail::to_
Definition: TupleObj.h:62
Tuples::Type
Type
the list of available types for ntuples
Definition: TupleObj.h:79
std::ostream
STL class.
Tuples::TupleObj::goodItem
bool goodItem(const std::string &name) const
check the uniqueness of the name
Definition: TupleObj.h:1894
Tuples::TupleObj::UInt
NTuple::Item< unsigned int > UInt
basic type for unsigned int items
Definition: TupleObj.h:221
std::forward
T forward(T... args)
Tuples::TupleObj::m_uchars
ColumnStorage< UChar > m_uchars
the actual storage of all 'unsigned int' columns
Definition: TupleObj.h:1957
std::initializer_list
Tuples::detail::to_::operator()
T operator()(Arg &&i) const
Definition: TupleObj.h:64
std::vector::reserve
T reserve(T... args)
Tuples::ErrorCodes::InvalidObject
StatusCode::code_t
unsigned long code_t
type of StatusCode value
Definition: StatusCode.h:52
GaudiPython.GaudiAlgs.column
column
Definition: GaudiAlgs.py:1191
Tuples::TupleObj::m_farrays
ColumnStorage< FArray > m_farrays
the actual storage of all 'FArray' columns
Definition: TupleObj.h:1987
std::numeric_limits
Tuples
General namespace for Tuple properties.
Definition: Maps.h:33
Tuples::TupleObj::column
StatusCode column(const std::string &name, const ROOT::Math::PositionVector3D< TYPE, TAG > &v)
Useful shortcut to put 3D-Vector directly into N-Tuple:
Definition: TupleObj.h:1769