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 <cstddef>
10 #include <set>
11 #include <string>
12 #include <limits>
13 #include <array>
14 #include <functional>
15 // ============================================================================
16 // GaudiKernel
17 // ============================================================================
18 #include "GaudiKernel/NTuple.h"
19 #include "GaudiKernel/VectorMap.h"
20 // ============================================================================
21 // GaudiAlg
22 // ============================================================================
23 #include "GaudiAlg/Tuples.h"
24 #include "GaudiAlg/Maps.h"
25 // ============================================================================
26 // ROOT
27 // ============================================================================
28 #include "Math/Point3D.h"
29 #include "Math/Vector3D.h"
30 #include "Math/Vector4D.h"
31 #include "Math/SVector.h"
32 #include "Math/SMatrix.h"
33 
34 // ============================================================================
35 // forward declaration
36 // ============================================================================
37 // GaudiKernel
38 // ============================================================================
39 class IOpaqueAddress ;
40 // ============================================================================
49 // ============================================================================
57 namespace Tuples
58 {
59  namespace implementation_detail {
60  template <typename T> struct to_ {
61  template <typename Arg>
62  T operator()(Arg&& i) const
63  { return T(std::forward<Arg>(i)); }
64  };
65  constexpr struct to_<float> to_float {};
66  }
67  // ==========================================================================
73  enum Type
74  {
75  NTUPLE , // Analysis nTuple
76  EVTCOL // Event Collection
77  };
78  // ==========================================================================
86  enum ErrorCodes
87  {
88  InvalidTuple = 100 ,
92  InvalidItem ,
93  TruncateValue = 200
94  };
95  // ==========================================================================
190  class GAUDI_API TupleObj
191  {
192  public:
193  // ========================================================================
195  typedef NTuple::Item<bool> Bool ;
196  // ========================================================================
198  typedef NTuple::Item<char> Char ;
199  // ========================================================================
201  typedef NTuple::Item<unsigned char> UChar ;
202  // ========================================================================
204  typedef NTuple::Item<short> Short ;
205  // ========================================================================
207  typedef NTuple::Item<unsigned short> UShort ;
208  // ========================================================================
210  typedef NTuple::Item<int> Int ;
211  // ========================================================================
213  typedef NTuple::Item<unsigned int> UInt ;
214  // ========================================================================
216  typedef NTuple::Item<long long> LongLong ;
217  // ========================================================================
219  typedef NTuple::Item<unsigned long long> ULongLong ;
220  // ========================================================================
222  typedef NTuple::Item<float> Float ;
223  // ========================================================================
225  typedef NTuple::Item<double> Double ;
226  // ========================================================================
228  typedef NTuple::Item<IOpaqueAddress*> Address ;
229  // ========================================================================
231  typedef NTuple::Array<float> FArray ;
232  // ========================================================================
234  typedef NTuple::Matrix<float> FMatrix ;
235  // ========================================================================
236  // the actual type for variable size matrix indices
237  typedef unsigned short MIndex ;
238  // ========================================================================
239  // the map of all items
240  typedef std::map<std::string,std::string> ItemMap ;
241  // ========================================================================
242  protected:
243  // ========================================================================
251  TupleObj
252  ( std::string name ,
253  NTuple::Tuple* tuple ,
254  const CLID& clid = CLID_ColumnWiseTuple ,
255  const Tuples::Type type = Tuples::NTUPLE ) ;
256  // ========================================================================
257  protected:
258  // ========================================================================
260  virtual ~TupleObj();
261  // ========================================================================
262  public:
263  // ========================================================================
279  StatusCode column ( const std::string& name ,
280  float value );
281  // ========================================================================
282  public:
283  // ========================================================================
300  StatusCode column ( const std::string& name ,
301  double value );
302  // ========================================================================
303  public:
304  // ========================================================================
320  StatusCode column ( const std::string& name ,
321  short value );
322  // ========================================================================
340  StatusCode column ( const std::string& name ,
341  short value ,
342  short minv ,
343  short maxv );
344  // ========================================================================
345  public:
346  // ========================================================================
362  StatusCode column ( const std::string& name ,
363  unsigned short value );
364  // ========================================================================
382  StatusCode column ( const std::string& name ,
383  unsigned short value ,
384  unsigned short minv ,
385  unsigned short maxv );
386  // ========================================================================
387  public:
388  // ========================================================================
404  StatusCode column ( const std::string& name ,
405  char value );
406  // ========================================================================
424  StatusCode column ( const std::string& name ,
425  char value ,
426  char minv ,
427  char maxv );
428  // ========================================================================
429  public:
430  // ========================================================================
446  StatusCode column ( const std::string& name ,
447  unsigned char value );
448  // ========================================================================
466  StatusCode column ( const std::string& name ,
467  unsigned char value ,
468  unsigned char minv ,
469  unsigned char maxv );
470  // ========================================================================
471  public:
472  // ========================================================================
488  StatusCode column ( const std::string& name ,
489  int value );
490  // ========================================================================
508  StatusCode column ( const std::string& name ,
509  int value ,
510  int minv ,
511  int maxv );
512  // ========================================================================
513  public:
514  // ========================================================================
530  StatusCode column ( const std::string& name ,
531  unsigned int value );
532  // ========================================================================
550  StatusCode column ( const std::string& name ,
551  unsigned int value ,
552  unsigned int minv ,
553  unsigned int maxv );
554  // ========================================================================
555  public:
556  // ========================================================================
573  StatusCode column ( const std::string& name ,
574  long value );
575  // ========================================================================
593  StatusCode column ( const std::string& name ,
594  long value ,
595  long minv ,
596  long maxv );
597  // ========================================================================
598  public:
599  // ========================================================================
616  StatusCode column ( const std::string& name ,
617  unsigned long value );
618  // ========================================================================
636  StatusCode column ( const std::string& name ,
637  unsigned long value ,
638  unsigned long minv ,
639  unsigned long maxv );
640  // ========================================================================
641  public:
642  // ========================================================================
658  StatusCode column ( const std::string& name ,
659  long long value );
660  // ========================================================================
678  StatusCode column ( const std::string& name ,
679  long long value ,
680  long long minv ,
681  long long maxv );
682  // ========================================================================
683  public:
684  // ========================================================================
700  StatusCode column ( const std::string& name ,
701  unsigned long long value );
702  // ========================================================================
720  StatusCode column ( const std::string& name ,
721  unsigned long long value ,
722  unsigned long long minv ,
723  unsigned long long maxv );
724  // ========================================================================
725  public:
726  // ========================================================================
742  StatusCode column ( const std::string& name ,
743  signed char value )
744  {
745  return column
746  ( name ,
747  value ,
748  std::numeric_limits<signed char>::min() ,
749  std::numeric_limits<signed char>::max() ) ;
750  }
751  // ========================================================================
752  public:
753  // ========================================================================
768  StatusCode column ( const std::string& name ,
769  bool value );
770  // ========================================================================
771  public:
772  // ========================================================================
791  StatusCode column ( const std::string& name ,
792  IOpaqueAddress* address ) ;
793  // ========================================================================
810  StatusCode column ( IOpaqueAddress* address ) ;
811  // ========================================================================
812  public:
813  // ========================================================================
837  StatusCode fill( const char* format ... ) ;
838  // =======================================================================
839  public:
840  // =======================================================================
889  template <typename ITERATOR1,typename ITERATOR2>
890  StatusCode farray ( const std::string& name ,
891  ITERATOR1&& first ,
892  ITERATOR2&& last ,
893  const std::string& length ,
894  size_t maxv )
895  {
896  return farray( name, implementation_detail::to_float,
897  std::forward<ITERATOR1>(first), std::forward<ITERATOR2>(last),
898  length, maxv );
899  }
900  // =======================================================================
943  template <class DATA>
944  StatusCode farray ( const std::string& name ,
945  const DATA& data ,
946  const std::string& length ,
947  const size_t maxv )
948  { return farray ( name , std::begin(data) , std::end(data) , length , maxv ) ; }
949  // =======================================================================
1012  template <class FUNCTION, class ITERATOR>
1013  StatusCode farray ( const std::string& name ,
1014  const FUNCTION& function ,
1015  ITERATOR first ,
1016  ITERATOR last ,
1017  const std::string& length ,
1018  size_t maxv )
1019  {
1020  if ( invalid () ) { return InvalidTuple ; }
1021  if ( rowWise () ) { return InvalidOperation ; }
1022 
1023  // adjust the length
1024  if( std::distance(first,last) > static_cast<std::ptrdiff_t>(maxv) ) {
1025  Warning("farray('"
1026  + name + "'): array is overflow, skip extra entries") ;
1027  last = std::next(first,maxv);
1028  }
1029 
1030  // get the length item
1031  Int* len = ints( length , 0 , maxv ) ;
1032  if( !len ) { return InvalidColumn ; }
1033 
1034  // adjust the length
1035  *len = std::distance(first,last);
1036 
1037  // get the array itself
1038  FArray* var = fArray ( name , len ) ;
1039  if( !var ) { return InvalidColumn ; }
1040 
1041  // fill the array
1042  std::transform( first, last, std::begin(*var), std::cref(function) );
1043 
1044  return StatusCode::SUCCESS ;
1045  }
1046  // =======================================================================
1078  template <class FUNC1, class FUNC2, class DATA>
1079  StatusCode farray ( const std::string& name1 ,
1080  const FUNC1& func1 ,
1081  const std::string& name2 ,
1082  const FUNC2& func2 ,
1083  DATA first ,
1084  DATA last ,
1085  const std::string& length ,
1086  size_t maxv )
1087  {
1088  if ( invalid () ) { return InvalidTuple ; }
1089  if ( rowWise () ) { return InvalidOperation ; }
1090 
1091  // adjust the lenfth
1092  if( std::distance(first,last) > static_cast<std::ptrdiff_t>(maxv) )
1093  {
1094  Warning("farray('"
1095  + name1 + ","
1096  + name2 + "'): array is overflow, skip extra entries").ignore() ;
1097  Warning("farray('"+name1+"'): array is overflow, skip extra items").ignore() ;
1098  last = std::next(first, maxv) ;
1099  }
1100 
1101  // get the length item
1102  Int* len = ints ( length , 0 , maxv ) ;
1103  if ( !len ) { return InvalidColumn ; }
1104 
1105  // adjust the length
1106  *len = std::distance(first,last);
1107 
1108  // get the array itself
1109  FArray* var1 = fArray ( name1 , len ) ;
1110  if ( !var1 ) { return InvalidColumn ; }
1111 
1112  // get the array itself
1113  FArray* var2 = fArray ( name2 , len ) ;
1114  if ( !var2 ) { return InvalidColumn ; }
1115 
1116  // fill the array
1117  size_t index = 0 ;
1118  for( ; first != last ; ++first )
1119  {
1120  ( *var1 ) [ index ] = func1 ( *first ) ;
1121  ( *var2 ) [ index ] = func2 ( *first ) ;
1122  ++index ;
1123  }
1124 
1125  return StatusCode::SUCCESS ;
1126  }
1127  // =======================================================================
1164  template <class FUNC1, class FUNC2, class FUNC3, class DATA>
1165  StatusCode farray ( const std::string& name1 ,
1166  const FUNC1& func1 ,
1167  const std::string& name2 ,
1168  const FUNC2& func2 ,
1169  const std::string& name3 ,
1170  const FUNC3& func3 ,
1171  DATA first ,
1172  DATA last ,
1173  const std::string& length ,
1174  size_t maxv )
1175  {
1176  if ( invalid () ) { return InvalidTuple ; }
1177  if ( rowWise () ) { return InvalidOperation ; }
1178 
1179  // adjust the length
1180  if( (size_t)std::distance(first,last) > maxv )
1181  {
1182  Warning("farray('"
1183  + name1 + ","
1184  + name2 + ","
1185  + name3 + "'): array is overflow, skip extra entries").ignore() ;
1186  last = std::next(first, maxv) ;
1187  }
1188 
1189  // get the length item
1190  Int* len = ints ( length , 0 , maxv ) ;
1191  if( !len ) { return InvalidColumn ; }
1192 
1193  // adjust the length
1194  *len = std::distance(first,last);
1195 
1196  // get the array itself
1197  FArray* var1 = fArray ( name1 , len ) ;
1198  if( !var1 ) { return InvalidColumn ; }
1199 
1200  // get the array itself
1201  FArray* var2 = fArray ( name2 , len ) ;
1202  if( !var2 ) { return InvalidColumn ; }
1203 
1204  // get the array itself
1205  FArray* var3 = fArray ( name3 , len ) ;
1206  if( !var3 ) { return InvalidColumn ; }
1207 
1208  // fill the array
1209  size_t index = 0 ;
1210  for( ; first != last ; ++first )
1211  {
1212  ( *var1 ) [ index ] = (float)func1 ( *first ) ;
1213  ( *var2 ) [ index ] = (float)func2 ( *first ) ;
1214  ( *var3 ) [ index ] = (float)func3 ( *first ) ;
1215  ++index ;
1216  }
1217  return StatusCode::SUCCESS ;
1218  }
1219  // =======================================================================
1259  template <class FUNC1, class FUNC2, class FUNC3, class FUNC4, class DATA>
1260  StatusCode farray ( const std::string& name1 ,
1261  const FUNC1& func1 ,
1262  const std::string& name2 ,
1263  const FUNC2& func2 ,
1264  const std::string& name3 ,
1265  const FUNC3& func3 ,
1266  const std::string& name4 ,
1267  const FUNC4& func4 ,
1268  DATA first ,
1269  DATA last ,
1270  const std::string& length ,
1271  size_t maxv )
1272  {
1273  if ( invalid () ) { return InvalidTuple ; }
1274  if ( rowWise () ) { return InvalidOperation ; }
1275 
1276  // adjust the length
1277  if( std::distance(first,last) > static_cast<std::ptrdiff_t>(maxv) )
1278  {
1279  Warning("farray('"
1280  + name1 + ","
1281  + name2 + ","
1282  + name3 + ","
1283  + name4 + "'): array is overflow, skip extra entries").ignore() ;
1284  last = std::next(first, maxv);
1285  }
1286 
1287  // get the length item
1288  Int* len = ints ( length , 0 , maxv ) ;
1289  if( !len ) { return InvalidColumn ; }
1290 
1291  // adjust the length
1292  *len = std::distance(first,last);
1293 
1294  // get the array itself
1295  FArray* var1 = fArray ( name1 , len ) ;
1296  if( !var1 ) { return InvalidColumn ; }
1297 
1298  // get the array itself
1299  FArray* var2 = fArray ( name2 , len ) ;
1300  if( !var2 ) { return InvalidColumn ; }
1301 
1302  // get the array itself
1303  FArray* var3 = fArray ( name3 , len ) ;
1304  if( !var3 ) { return InvalidColumn ; }
1305 
1306  // get the array itself
1307  FArray* var4 = fArray ( name4 , len ) ;
1308  if( !var4 ) { return InvalidColumn ; }
1309 
1310  // fill the array
1311  size_t index = 0 ;
1312  for( ; first != last ; ++first )
1313  {
1314  ( *var1 ) [ index ] = func1 ( *first );
1315  ( *var2 ) [ index ] = func2 ( *first );
1316  ( *var3 ) [ index ] = func3 ( *first );
1317  ( *var4 ) [ index ] = func4 ( *first );
1318  ++index ;
1319  }
1320 
1321  return StatusCode::SUCCESS ;
1322  }
1323  // =======================================================================
1324  public:
1325  // =======================================================================
1376  template <class MATRIX>
1377  StatusCode fmatrix ( const std::string& name ,
1378  const MATRIX& data ,
1379  size_t rows ,
1380  const MIndex& cols ,
1381  const std::string& length ,
1382  size_t maxv )
1383  {
1384  if ( invalid () ) { return InvalidTuple ; }
1385  if ( rowWise () ) { return InvalidOperation ; }
1386 
1387  // adjust the length
1388  if ( rows >= maxv )
1389  {
1390  Warning ( "fmatrix('"+name+"'): matrix is overflow, skip extra items").ignore() ;
1391  rows = ( 0 < maxv ) ? ( maxv - 1 ) : 0 ;
1392  }
1393 
1394  // get the length item
1395  Int* len = ints( length , 0 , maxv ) ;
1396  if ( !len ) { return InvalidColumn; }
1397 
1398  // adjust the length item
1399  *len = rows ;
1400 
1401  // get the array itself
1402  FMatrix* var = fMatrix ( name , len , cols ) ;
1403  if ( !var ) { return InvalidColumn ; }
1404 
1406  for ( size_t iCol = 0 ; iCol < cols ; ++iCol )
1407  {
1408  for ( MIndex iRow = 0 ; iRow < rows ; ++iRow )
1409  { (*var)[ iRow ] [ iCol ] = data[ iRow ][ iCol ] ; }
1410  }
1411 
1412  return StatusCode::SUCCESS ;
1413  }
1414  // =======================================================================
1451  template <class DATA>
1452  StatusCode fmatrix ( const std::string& name ,
1453  DATA first ,
1454  DATA last ,
1455  const MIndex& cols ,
1456  const std::string& length ,
1457  size_t maxv )
1458  {
1459  if ( invalid () ) { return InvalidTuple ; }
1460  if ( rowWise () ) { return InvalidOperation ; }
1461 
1462  // adjust the length
1463  if ( first + maxv < last )
1464  {
1465  Warning("fmatrix('"+name+"'): matrix is overflow, skip extra items").ignore() ;
1466  last = first + maxv ;
1467  }
1468 
1469  // get the length item
1470  Int* len = ints( length , 0 , maxv ) ;
1471  if ( !len ) { return InvalidColumn; }
1472 
1473  // adjust the length item
1474  *len = last - first ;
1475 
1476  // get the array itself
1477  FMatrix* var = fMatrix ( name , len , cols ) ;
1478  if ( !var ) { return InvalidColumn ; }
1479 
1481  size_t iRow = 0 ;
1482  for ( ; first != last ; ++first )
1483  {
1484  //
1485  for ( MIndex iCol = 0 ; iCol < cols ; ++iCol )
1486  { (*var)[ iRow ] [ iCol ] = (float)((*first)[ iCol ]) ; }
1487  //
1488  ++iRow ;
1489  }
1490 
1491  return StatusCode::SUCCESS ;
1492  }
1493  // =======================================================================
1572  template <class FUN,class DATA>
1573  StatusCode fmatrix ( const std::string& name ,
1574  FUN funF ,
1575  FUN funL ,
1576  DATA first ,
1577  DATA last ,
1578  const std::string& length ,
1579  size_t maxv )
1580  {
1581  if ( invalid () ) { return InvalidTuple ; }
1582  if ( rowWise () ) { return InvalidOperation ; }
1583 
1584  // adjust the length
1585  if ( std::distance(first,last) > static_cast<std::ptrdiff_t>(maxv) )
1586  {
1587  Warning("fmatrix('"+name+"'): matrix is overflow, skip extra items").ignore() ;
1588  last = std::next(first, maxv) ;
1589  }
1590 
1591  // get the length item
1592  Int* len = ints( length , 0 , maxv ) ;
1593  if ( !len ) { return InvalidColumn; }
1594 
1595  // adjust the length item
1596  *len = std::distance(first,last);
1597 
1598  // get the array itself
1599  auto cols = std::distance(funF,funL);
1600  FMatrix* var = fMatrix ( name , len , cols ) ;
1601  if ( !var ) { return InvalidColumn ; }
1602 
1604  size_t iRow = 0 ;
1605  for ( ; first != last ; ++first )
1606  {
1607  //
1608  for ( FUN fun = funF ; fun < funL ; ++fun )
1609  { (*var)[ iRow ] [ fun - funF ] = (*fun) ( *first ) ; }
1610  //
1611  ++iRow;
1612  }
1613 
1614  return StatusCode::SUCCESS ;
1615  }
1616  // =======================================================================
1617  public:
1618  // =======================================================================
1641  template <class DATA>
1642  StatusCode array ( const std::string& name ,
1643  DATA first ,
1644  DATA last )
1645 
1646  {
1647  if ( invalid () ) { return InvalidTuple ; }
1648  if ( rowWise () ) { return InvalidOperation ; }
1649 
1650  // get the length (fixed!)
1651  auto length = std::distance(first,last);
1652 
1653  // get the array itself
1654  FArray* var = fArray ( name , length ) ;
1655  if ( !var ) { return InvalidColumn ; }
1656 
1658  std::copy( first, last, std::begin(*var) );
1659 
1660  return StatusCode::SUCCESS ;
1661  }
1662  // =======================================================================
1701  template <class ARRAY>
1702  StatusCode array ( const std::string& name ,
1703  const ARRAY& data ,
1704  const MIndex& length )
1705  {
1706  using std::begin; // allow data to be eg. CLHEP::HepVector (which does not define HepVector::begin()!,
1707  // in which case ADL prefers CLHEP::begin (yah! at least they (now) use a namespace)
1708  // so one just to insure double* CLHEP::begin(CLHEP::HepVector& v) { return &v[0]; }
1709  // is visible when this function gets instantiated for CLHEP::HepVector...
1710  auto first = begin(data);
1711  return array( name, first, std::next( first, length ) );
1712  }
1713  // =======================================================================
1744  template <class ARRAY>
1745  StatusCode array ( const std::string& name ,
1746  const ARRAY& data )
1747  {
1748  using std::begin; using std::end;
1749  return array ( name , begin(data) , end(data) ) ;
1750  }
1751  // =======================================================================
1752  public:
1753  // =======================================================================
1802  template <class MATRIX>
1803  StatusCode matrix ( const std::string& name ,
1804  const MATRIX& data ,
1805  const MIndex& rows ,
1806  const MIndex& cols )
1807  {
1808  if ( invalid () ) { return InvalidTuple ; }
1809  if ( rowWise () ) { return InvalidOperation ; }
1810 
1811  // get the matrix itself
1812  FMatrix* var = fMatrix ( name , rows , cols ) ;
1813  if ( !var ) { return InvalidColumn ; }
1814 
1816  for ( size_t iCol = 0 ; iCol < cols ; ++iCol )
1817  {
1818  for ( size_t iRow = 0 ; iRow < rows ; ++iRow )
1819  { (*var)[iRow][iCol] = data[iRow][iCol]; }
1820  };
1821  return StatusCode::SUCCESS ;
1822  }
1823  // =======================================================================
1824  public:
1825  // =======================================================================
1842  template <class TYPE>
1843  StatusCode column
1844  ( const std::string& name ,
1845  const ROOT::Math::LorentzVector<TYPE>& v )
1846  {
1847  if ( invalid() ) { return InvalidTuple ; }
1848  // fill all separate columns:
1849  StatusCode sc1 = this -> column ( name + "E" , v.E () ) ;
1850  StatusCode sc2 = this -> column ( name + "X" , v.Px () ) ;
1851  StatusCode sc3 = this -> column ( name + "Y" , v.Py () ) ;
1852  StatusCode sc4 = this -> column ( name + "Z" , v.Pz () ) ;
1853  return
1854  sc1.isFailure () ? sc1 :
1855  sc2.isFailure () ? sc2 :
1856  sc3.isFailure () ? sc3 :
1857  sc4.isFailure () ? sc4 : StatusCode(StatusCode::SUCCESS) ;
1858  }
1859  // =======================================================================
1876  template <class TYPE,class TAG>
1877  StatusCode column
1878  ( const std::string& name ,
1880  {
1881  if ( invalid() ) { return InvalidTuple ; }
1883  StatusCode sc1 = this -> column ( name + "X" , v.X () ) ;
1884  StatusCode sc2 = this -> column ( name + "Y" , v.Y () ) ;
1885  StatusCode sc3 = this -> column ( name + "Z" , v.Z () ) ;
1886  return
1887  sc1.isFailure () ? sc1 :
1888  sc2.isFailure () ? sc2 :
1889  sc3.isFailure () ? sc3 : StatusCode(StatusCode::SUCCESS) ;
1890  }
1891  // =======================================================================
1908  template <class TYPE,class TAG>
1909  StatusCode column
1910  ( const std::string& name ,
1912  {
1913  if ( invalid() ) { return InvalidTuple ; }
1915  StatusCode sc1 = this -> column ( name + "X" , v.X () ) ;
1916  StatusCode sc2 = this -> column ( name + "Y" , v.Y () ) ;
1917  StatusCode sc3 = this -> column ( name + "Z" , v.Z () ) ;
1918  return
1919  sc1.isFailure () ? sc1 :
1920  sc2.isFailure () ? sc2 :
1921  sc3.isFailure () ? sc3 : StatusCode(StatusCode::SUCCESS) ;
1922  }
1923  // =======================================================================
1932  template <class TYPE,unsigned int D1,unsigned int D2,class REP>
1933  StatusCode matrix
1934  ( const std::string& name ,
1935  const ROOT::Math::SMatrix<TYPE,D1,D2,REP>& mtrx )
1936  {
1937  if ( invalid () ) { return InvalidTuple ; }
1938  if ( rowWise () ) { return InvalidOperation ; }
1939 
1940  // get the matrix itself
1941  FMatrix* var = fMatrix ( name , (MIndex)D1 , (MIndex)D2 ) ;
1942  if ( !var ) { return InvalidColumn ; }
1943 
1945  for ( size_t iCol = 0 ; iCol < D2 ; ++iCol )
1946  {
1947  for ( size_t iRow = 0 ; iRow < D1 ; ++iRow )
1948  { (*var)[iRow][iCol] = mtrx(iRow,iCol) ; }
1949  };
1950 
1951  return StatusCode::SUCCESS ;
1952  }
1953  // =======================================================================
1971  template <class KEY, class VALUE>
1972  StatusCode fmatrix
1973  ( const std::string& name ,
1974  const GaudiUtils::VectorMap<KEY,VALUE>& info ,
1975  const std::string& length ,
1976  const size_t maxv = 100 )
1977  {
1978  using Info = std::pair<KEY,VALUE>;
1979  static const std::array< std::function<float(const Info&)>, 2>
1980  fns = { [](const Info& i) { return i.first; } ,
1981  [](const Info& i) { return i.second; } };
1982  return fmatrix( name,
1983  std::begin(fns), std::end(fns),
1984  std::begin(info), std::end(info),
1985  length,maxv );
1986  }
1987  // =======================================================================
1988  public:
1989  // =======================================================================
1997  template <class TYPE>
1998  StatusCode put
1999  ( const std::string& name , const TYPE* obj ) ;
2000  // =======================================================================
2001  public:
2002  // =======================================================================
2006  StatusCode write () ;
2007  // =======================================================================
2009  const std::string& name() const { return m_name ; }
2010  // =======================================================================
2014  const NTuple::Tuple* tuple() const { return m_tuple ; }
2015  // =======================================================================
2019  NTuple::Tuple* tuple() { return m_tuple ; }
2020  // =======================================================================
2024  unsigned long refCount() const { return m_refCount ; }
2025  // =======================================================================
2029  unsigned long addRef () { return ++m_refCount ; }
2030  // =======================================================================
2035  void release () ;
2036  // =======================================================================
2038  const CLID& clid() const { return m_clid ; }
2039  // =======================================================================
2041  Tuples::Type type() const { return m_type ; }
2042  // =======================================================================
2044  bool columnWise() const { return CLID_ColumnWiseTuple == clid() ; }
2045  // =======================================================================
2047  bool rowWise () const { return CLID_RowWiseTuple == clid() ; }
2048  // =======================================================================
2050  bool evtColType() const { return Tuples::EVTCOL == type() ; }
2051  // =======================================================================
2053  bool valid () const { return 0 != tuple() ; }
2054  // =======================================================================
2056  bool invalid () const { return ! valid() ; }
2057  // =======================================================================
2058  public:
2059  // =======================================================================
2065  bool addItem ( std::string name ,
2066  std::string type )
2067  { return m_items.emplace ( std::move(name) , std::move(type) ).second ; }
2068  // =======================================================================
2073  bool goodItem ( const std::string& name ) const
2074  { return m_items.end() == m_items.find ( name ) ; }
2075  // =======================================================================
2077  const ItemMap& items() const { return m_items ; }
2078  // =======================================================================
2079  public:
2080  // =======================================================================
2081  virtual StatusCode Error
2082  ( const std::string& msg ,
2083  const StatusCode sc = StatusCode::FAILURE ) const = 0 ;
2084  // =======================================================================
2085  virtual StatusCode Warning
2086  ( const std::string& msg ,
2087  const StatusCode sc = StatusCode::FAILURE ) const = 0 ;
2088  // =======================================================================
2089  private:
2090  // =======================================================================
2092  Bool* bools ( const std::string& name ) ;
2093  // =======================================================================
2095  Float* floats ( const std::string& name ) ;
2096  // =======================================================================
2098  Double* doubles ( const std::string& name ) ;
2099  // =======================================================================
2101  Char* chars ( const std::string& name ) ;
2102  // =======================================================================
2104  Char* chars ( const std::string& name ,
2105  const char minv ,
2106  const char maxv ) ;
2107  // =======================================================================
2109  UChar* uchars ( const std::string& name ) ;
2110  // =======================================================================
2112  UChar* uchars ( const std::string& name ,
2113  unsigned char minv ,
2114  unsigned char maxv ) ;
2115  // =======================================================================
2117  Short* shorts ( const std::string& name ) ;
2118  // =======================================================================
2120  Short* shorts ( const std::string& name ,
2121  short minv ,
2122  short maxv ) ;
2123  // =======================================================================
2125  UShort* ushorts ( const std::string& name ) ;
2126  // =======================================================================
2128  UShort* ushorts ( const std::string& name ,
2129  unsigned short minv ,
2130  unsigned short maxv ) ;
2131  // =======================================================================
2133  Int* ints ( const std::string& name ) ;
2134  // =======================================================================
2136  Int* ints ( const std::string& name ,
2137  int minv ,
2138  int maxv ) ;
2139  // =======================================================================
2141  UInt* uints ( const std::string& name ) ;
2142  // =======================================================================
2144  UInt* uints ( const std::string& name ,
2145  unsigned int minv ,
2146  unsigned int maxv ) ;
2147  // =======================================================================
2149  LongLong* longlongs ( const std::string& name );
2150  // =======================================================================
2152  LongLong* longlongs ( const std::string& name ,
2153  long long minv ,
2154  long long maxv ) ;
2155  // =======================================================================
2157  ULongLong* ulonglongs ( const std::string& name ) ;
2158  // =======================================================================
2160  ULongLong* ulonglongs ( const std::string& name ,
2161  unsigned long long minv ,
2162  unsigned long long maxv ) ;
2163  // =======================================================================
2165  FArray* fArray ( const std::string& name ,
2166  Int* item ) ;
2167  // =======================================================================
2169  FArray* fArray ( const std::string& name ,
2170  const MIndex& rows ) ;
2171  // =======================================================================
2173  Address* addresses ( const std::string& name ) ;
2174  // =======================================================================
2176  FMatrix* fMatrix ( const std::string& name ,
2177  Int* item ,
2178  const MIndex& cols ) ;
2179  // =======================================================================
2181  FMatrix* fMatrix ( const std::string& name ,
2182  const MIndex& rows ,
2183  const MIndex& cols ) ;
2184  // =======================================================================
2185  private:
2186  // =======================================================================
2188  TupleObj () = delete;
2189  TupleObj ( const TupleObj& ) = delete;
2190  TupleObj& operator= ( const TupleObj& ) = delete;
2191  // =======================================================================
2192  private:
2193  // =======================================================================
2196  // =======================================================================
2199  // =======================================================================
2202  // =======================================================================
2205  // =======================================================================
2208  // =======================================================================
2211  // =======================================================================
2214  // =======================================================================
2217  // =======================================================================
2220  // =======================================================================
2223  // =======================================================================
2226  // =======================================================================
2229  // =======================================================================
2232  // =======================================================================
2235  // =======================================================================
2236  private:
2237  template <typename T, NTuple::Item<T>* (TupleObj::*fun)(const std::string&), typename UT>
2238  StatusCode column_(const std::string& name, UT&& value) {
2239  if ( invalid() ) { return InvalidTuple ; }
2240  auto item = (this->*fun)( name );
2241  if ( !item ) { return InvalidColumn ; }
2242  *item = std::forward<UT>(value);
2243  return StatusCode::SUCCESS ;
2244  }
2245  template <typename T, NTuple::Item<T>* (TupleObj::*fun)(const std::string&,T,T), typename UT>
2246  StatusCode column_(const std::string& name, UT&& value, UT&& minv, UT&& maxv) {
2247  if ( invalid() ) { return InvalidTuple ; }
2248  auto item = (this->*fun)( name, std::forward<UT>(minv),std::forward<UT>(maxv) );
2249  if ( !item ) { return InvalidColumn ; }
2250  *item = std::forward<UT>(value);
2251  return StatusCode::SUCCESS ;
2252  }
2253 
2254  // =======================================================================
2256  std::string m_name ;
2257  // =======================================================================
2259  NTuple::Tuple* m_tuple ;
2260  // =======================================================================
2262  CLID m_clid ;
2263  // =======================================================================
2265  Tuples::Type m_type ;
2266  // =======================================================================
2268  size_t m_refCount = 0;
2269  // =======================================================================
2271  mutable Bools m_bools ;
2272  // =======================================================================
2274  mutable Chars m_chars ;
2275  // =======================================================================
2277  mutable UChars m_uchars ;
2278  // =======================================================================
2280  mutable Shorts m_shorts ;
2281  // =======================================================================
2283  mutable UShorts m_ushorts ;
2284  // =======================================================================
2286  mutable Ints m_ints ;
2287  // =======================================================================
2289  mutable UInts m_uints ;
2290  // =======================================================================
2292  mutable LongLongs m_longlongs ;
2293  // =======================================================================
2295  mutable ULongLongs m_ulonglongs ;
2296  // =======================================================================
2298  mutable Floats m_floats ;
2299  // =======================================================================
2301  mutable Doubles m_doubles ;
2302  // =======================================================================
2304  mutable Addresses m_addresses ;
2305  // =======================================================================
2307  mutable FArrays m_farrays ;
2308  // =======================================================================
2310  mutable FArrays m_arraysf ;
2311  // =======================================================================
2313  mutable FMatrices m_fmatrices ;
2314  // =======================================================================
2316  mutable FMatrices m_matricesf ;
2317  // =======================================================================
2319  ItemMap m_items ;
2320  // =======================================================================
2321  } ;
2322  // ==========================================================================
2323 } // end of namespace Tuples
2324 // ============================================================================
2325 // GaudiAlg
2326 // ============================================================================
2327 #include "GaudiAlg/TuplePut.h"
2328 // ============================================================================
2329 // The END
2330 // ============================================================================
2331 #endif // GAUDIALG_TUPLEOBJ_H
2332 // ============================================================================
A bit modified version of 'Loki::AssocVector' associative vector from Loki library by Andrei Alexandr...
Definition: VectorMap.h:107
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:36
T operator()(Arg &&i) const
Definition: TupleObj.h:62
#define GAUDI_API
Definition: Kernel.h:107
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:44
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Specialization acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:297
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:370
ErrorCodes
Tuple error codes.
Definition: TupleObj.h:86
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
Common class providing an architecture-independent hash map.
Definition: HashMap.h:77
tuple item
print s1,s2
Definition: ana.py:146
Opaque address interface definition.
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:42
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:43
list i
Definition: ana.py:128
Type
the list of available types for ntuples
Definition: TupleObj.h:73
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:120
string type
Definition: gaudirun.py:151
General namespace for Tuple properties.
Definition: Maps.h:34