All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TupleObj.h
Go to the documentation of this file.
1 // $Id: TupleObj.h,v 1.23 2008/10/27 19:22:20 marcocle Exp $
2 // ============================================================================
3 // CVS tag $Name: $, version $Revision: 1.23 $
4 // ============================================================================
5 #ifndef GAUDIALG_TUPLEOBJ_H
6 #define GAUDIALG_TUPLEOBJ_H 1
7 // ============================================================================
8 // Include files
9 // ============================================================================
10 // STD&STL
11 // ============================================================================
12 #include <set>
13 #include <string>
14 #include <limits>
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 // forward declaration
35 // ============================================================================
36 // GaudiKernel
37 // ============================================================================
38 class IOpaqueAddress ;
39 // ============================================================================
47 // ============================================================================
55 namespace Tuples
56 {
57  // ==========================================================================
63  enum Type
64  {
65  NTUPLE , // Analysis nTuple
66  EVTCOL // Event Collection
67  };
68  // ==========================================================================
77  {
78  InvalidTuple = 100 ,
84  };
85  // ==========================================================================
181  {
182  public:
183  // ========================================================================
186  // ========================================================================
189  // ========================================================================
192  // ========================================================================
195  // ========================================================================
198  // ========================================================================
201  // ========================================================================
204  // ========================================================================
207  // ========================================================================
210  // ========================================================================
213  // ========================================================================
216  // ========================================================================
219  // ========================================================================
222  // ========================================================================
225  // ========================================================================
226  // the actual type for variable size matrix indices
227  typedef unsigned short MIndex ;
228  // ========================================================================
229  // the map of all items
230  typedef std::map<std::string,std::string> ItemMap ;
231  // ========================================================================
232  protected:
233  // ========================================================================
241  TupleObj
242  ( const std::string& name ,
243  NTuple::Tuple* tuple ,
244  const CLID& clid = CLID_ColumnWiseTuple ,
245  const Tuples::Type type = Tuples::NTUPLE ) ;
246  // ========================================================================
247  protected:
248  // ========================================================================
250  virtual ~TupleObj();
251  // ========================================================================
252  public:
253  // ========================================================================
269  StatusCode column ( const std::string& name ,
270  const float value );
271  // ========================================================================
272  public:
273  // ========================================================================
290  StatusCode column ( const std::string& name ,
291  const double value );
292  // ========================================================================
293  public:
294  // ========================================================================
310  StatusCode column ( const std::string& name ,
311  const short value );
312  // ========================================================================
330  StatusCode column ( const std::string& name ,
331  const short value ,
332  const short minv ,
333  const short maxv );
334  // ========================================================================
335  public:
336  // ========================================================================
352  StatusCode column ( const std::string& name ,
353  const unsigned short value );
354  // ========================================================================
372  StatusCode column ( const std::string& name ,
373  const unsigned short value ,
374  const unsigned short minv ,
375  const unsigned short maxv );
376  // ========================================================================
377  public:
378  // ========================================================================
394  StatusCode column ( const std::string& name ,
395  const char value );
396  // ========================================================================
414  StatusCode column ( const std::string& name ,
415  const char value ,
416  const char minv ,
417  const char maxv );
418  // ========================================================================
419  public:
420  // ========================================================================
436  StatusCode column ( const std::string& name ,
437  const unsigned char value );
438  // ========================================================================
456  StatusCode column ( const std::string& name ,
457  const unsigned char value ,
458  const unsigned char minv ,
459  const unsigned char maxv );
460  // ========================================================================
461  public:
462  // ========================================================================
478  StatusCode column ( const std::string& name ,
479  const int value );
480  // ========================================================================
498  StatusCode column ( const std::string& name ,
499  const int value ,
500  const int minv ,
501  const int maxv );
502  // ========================================================================
503  public:
504  // ========================================================================
520  StatusCode column ( const std::string& name ,
521  const unsigned int value );
522  // ========================================================================
540  StatusCode column ( const std::string& name ,
541  const unsigned int value ,
542  const unsigned int minv ,
543  const unsigned int maxv );
544  // ========================================================================
545  public:
546  // ========================================================================
563  StatusCode column ( const std::string& name ,
564  const long value );
565  // ========================================================================
583  StatusCode column ( const std::string& name ,
584  const long value ,
585  const long minv ,
586  const long maxv );
587  // ========================================================================
588  public:
589  // ========================================================================
606  StatusCode column ( const std::string& name ,
607  const unsigned long value );
608  // ========================================================================
626  StatusCode column ( const std::string& name ,
627  const unsigned long value ,
628  const unsigned long minv ,
629  const unsigned long maxv );
630  // ========================================================================
631  public:
632  // ========================================================================
648  StatusCode column ( const std::string& name ,
649  const long long value );
650  // ========================================================================
668  StatusCode column ( const std::string& name ,
669  const long long value ,
670  const long long minv ,
671  const long long maxv );
672  // ========================================================================
673  public:
674  // ========================================================================
690  StatusCode column ( const std::string& name ,
691  const unsigned long long value );
692  // ========================================================================
710  StatusCode column ( const std::string& name ,
711  const unsigned long long value ,
712  const unsigned long long minv ,
713  const unsigned long long maxv );
714  // ========================================================================
715  public:
716  // ========================================================================
732  StatusCode column ( const std::string& name ,
733  const signed char value )
734  {
735  return column
736  ( name ,
737  value ,
739  std::numeric_limits<signed char>::max() ) ;
740  }
741  // ========================================================================
742  public:
743  // ========================================================================
758  StatusCode column ( const std::string& name ,
759  const bool value );
760  // ========================================================================
761  public:
762  // ========================================================================
781  StatusCode column ( const std::string& name ,
782  IOpaqueAddress* address ) ;
783  // ========================================================================
800  StatusCode column ( IOpaqueAddress* address ) ;
801  // ========================================================================
802  public:
803  // ========================================================================
827  StatusCode fill( const char* format ... ) ;
828  // =======================================================================
829  public:
830  // =======================================================================
879  template <class DATA>
880  StatusCode farray ( const std::string& name ,
881  DATA first ,
882  DATA last ,
883  const std::string& length ,
884  const size_t maxv )
885  {
886  if ( invalid () ) { return InvalidTuple ; }
887  if ( rowWise () ) { return InvalidOperation ; }
888 
889  // adjust the length
890  if( first + maxv < last )
891  {
892  Warning( "farray('"+name+"'): array is overflow, skip extra items") ;
893  last = first + maxv ;
894  }
895 
896  // get the length item
897  Int* len = ints( length , 0 , maxv ) ;
898  if( 0 == len ) { return InvalidColumn; }
899 
900  // adjust the length item
901  *len = last - first ;
902 
903  // get the array itself
904  FArray* var = fArray ( name , len ) ;
905  if( 0 == var ) { return InvalidColumn ; }
906 
908  size_t index = 0 ;
909  for( ; first != last ; ++first )
910  { (*var)[ index ] = (float)(*first) ; ++index ; }
911 
912  return StatusCode::SUCCESS ;
913  }
914  // =======================================================================
957  template <class DATA>
958  StatusCode farray ( const std::string& name ,
959  const DATA& data ,
960  const std::string& length ,
961  const size_t maxv )
962  { return farray ( name , data.begin() , data.end() , length , maxv ) ; }
963  // =======================================================================
1026  template <class FUNCTION, class DATA>
1027  StatusCode farray ( const std::string& name ,
1028  const FUNCTION& function ,
1029  DATA first ,
1030  DATA last ,
1031  const std::string& length ,
1032  const size_t maxv )
1033  {
1034  if ( invalid () ) { return InvalidTuple ; }
1035  if ( rowWise () ) { return InvalidOperation ; }
1036 
1037  // adjust the length
1038  if( first + maxv < last )
1039  {
1040  Warning("farray('"
1041  + name + "'): array is overflow, skip extra entries") ;
1042  last = first + maxv ;
1043  }
1044 
1045  // get the length item
1046  Int* len = ints( length , 0 , maxv ) ;
1047  if( 0 == len ) { return InvalidColumn ; }
1048 
1049  // adjust the length
1050  *len = last - first ;
1051 
1052  // get the array itself
1053  FArray* var = fArray ( name , len ) ;
1054  if( 0 == var ) { return InvalidColumn ; }
1055 
1056  // fill the array
1057  size_t index = 0 ;
1058  for( ; first != last ; ++first )
1059  { (*var)[ index ] = function( *first ) ; ++index ; }
1060 
1061  return StatusCode::SUCCESS ;
1062  }
1063  // =======================================================================
1095  template <class FUNC1, class FUNC2, class DATA>
1096  StatusCode farray ( const std::string& name1 ,
1097  const FUNC1& func1 ,
1098  const std::string& name2 ,
1099  const FUNC2& func2 ,
1100  DATA first ,
1101  DATA last ,
1102  const std::string& length ,
1103  const size_t maxv )
1104  {
1105  if ( invalid () ) { return InvalidTuple ; }
1106  if ( rowWise () ) { return InvalidOperation ; }
1107 
1108  // adjust the lenfth
1109  if( first + maxv < last )
1110  {
1111  Warning("farray('"
1112  + name1 + ","
1113  + name2 + "'): array is overflow, skip extra entries").ignore() ;
1114  Warning("farray('"+name1+"'): array is overflow, skip extra items").ignore() ;
1115  last = first + maxv ;
1116  }
1117 
1118  // get the length item
1119  Int* len = ints ( length , 0 , maxv ) ;
1120  if ( 0 == len ) { return InvalidColumn ; }
1121 
1122  // adjust the length
1123  *len = last - first ;
1124 
1125  // get the array itself
1126  FArray* var1 = fArray ( name1 , len ) ;
1127  if ( 0 == var1 ) { return InvalidColumn ; }
1128 
1129  // get the array itself
1130  FArray* var2 = fArray ( name2 , len ) ;
1131  if ( 0 == var2 ) { return InvalidColumn ; }
1132 
1133  // fill the array
1134  size_t index = 0 ;
1135  for( ; first != last ; ++first )
1136  {
1137  ( *var1 ) [ index ] = func1 ( *first ) ;
1138  ( *var2 ) [ index ] = func2 ( *first ) ;
1139  ++index ;
1140  }
1141 
1142  return StatusCode::SUCCESS ;
1143  }
1144  // =======================================================================
1181  template <class FUNC1, class FUNC2, class FUNC3, class DATA>
1182  StatusCode farray ( const std::string& name1 ,
1183  const FUNC1& func1 ,
1184  const std::string& name2 ,
1185  const FUNC2& func2 ,
1186  const std::string& name3 ,
1187  const FUNC3& func3 ,
1188  DATA first ,
1189  DATA last ,
1190  const std::string& length ,
1191  const size_t maxv )
1192  {
1193  if ( invalid () ) { return InvalidTuple ; }
1194  if ( rowWise () ) { return InvalidOperation ; }
1195 
1196  // adjust the length
1197  if( first + maxv < last )
1198  {
1199  Warning("farray('"
1200  + name1 + ","
1201  + name2 + ","
1202  + name3 + "'): array is overflow, skip extra entries").ignore() ;
1203  last = first + maxv ;
1204  }
1205 
1206  // get the length item
1207  Int* len = ints ( length , 0 , maxv ) ;
1208  if( 0 == len ) { return InvalidColumn ; }
1209 
1210  // adjust the length
1211  *len = last - first ;
1212 
1213  // get the array itself
1214  FArray* var1 = fArray ( name1 , len ) ;
1215  if( 0 == var1 ) { return InvalidColumn ; }
1216 
1217  // get the array itself
1218  FArray* var2 = fArray ( name2 , len ) ;
1219  if( 0 == var2 ) { return InvalidColumn ; }
1220 
1221  // get the array itself
1222  FArray* var3 = fArray ( name3 , len ) ;
1223  if( 0 == var3 ) { return InvalidColumn ; }
1224 
1225  // fill the array
1226  size_t index = 0 ;
1227  for( ; first != last ; ++first )
1228  {
1229  ( *var1 ) [ index ] = (float)func1 ( *first ) ;
1230  ( *var2 ) [ index ] = (float)func2 ( *first ) ;
1231  ( *var3 ) [ index ] = (float)func3 ( *first ) ;
1232  ++index ;
1233  }
1234  return StatusCode::SUCCESS ;
1235  }
1236  // =======================================================================
1276  template <class FUNC1, class FUNC2, class FUNC3, class FUNC4, class DATA>
1277  StatusCode farray ( const std::string& name1 ,
1278  const FUNC1& func1 ,
1279  const std::string& name2 ,
1280  const FUNC2& func2 ,
1281  const std::string& name3 ,
1282  const FUNC3& func3 ,
1283  const std::string& name4 ,
1284  const FUNC4& func4 ,
1285  DATA first ,
1286  DATA last ,
1287  const std::string& length ,
1288  const size_t maxv )
1289  {
1290  if ( invalid () ) { return InvalidTuple ; }
1291  if ( rowWise () ) { return InvalidOperation ; }
1292 
1293  // adjust the length
1294  if( first + maxv < last )
1295  {
1296  Warning("farray('"
1297  + name1 + ","
1298  + name2 + ","
1299  + name3 + ","
1300  + name4 + "'): array is overflow, skip extra entries").ignore() ;
1301  last = first + maxv ;
1302  }
1303 
1304  // get the length item
1305  Int* len = ints ( length , 0 , maxv ) ;
1306  if( 0 == len ) { return InvalidColumn ; }
1307 
1308  // adjust the length
1309  *len = last - first ;
1310 
1311  // get the array itself
1312  FArray* var1 = fArray ( name1 , len ) ;
1313  if( 0 == var1 ) { return InvalidColumn ; }
1314 
1315  // get the array itself
1316  FArray* var2 = fArray ( name2 , len ) ;
1317  if( 0 == var2 ) { return InvalidColumn ; }
1318 
1319  // get the array itself
1320  FArray* var3 = fArray ( name3 , len ) ;
1321  if( 0 == var3 ) { return InvalidColumn ; }
1322 
1323  // get the array itself
1324  FArray* var4 = fArray ( name4 , len ) ;
1325  if( 0 == var4 ) { return InvalidColumn ; }
1326 
1327  // fill the array
1328  size_t index = 0 ;
1329  for( ; first != last ; ++first )
1330  {
1331  ( *var1 ) [ index ] = static_cast<float> ( func1 ( *first ) );
1332  ( *var2 ) [ index ] = static_cast<float> ( func2 ( *first ) );
1333  ( *var3 ) [ index ] = static_cast<float> ( func3 ( *first ) );
1334  ( *var4 ) [ index ] = static_cast<float> ( func4 ( *first ) );
1335  ++index ;
1336  }
1337 
1338  return StatusCode::SUCCESS ;
1339  }
1340  // =======================================================================
1341  public:
1342  // =======================================================================
1393  template <class MATRIX>
1394  StatusCode fmatrix ( const std::string& name ,
1395  const MATRIX& data ,
1396  size_t rows ,
1397  const MIndex& cols ,
1398  const std::string& length ,
1399  const size_t maxv )
1400  {
1401  if ( invalid () ) { return InvalidTuple ; }
1402  if ( rowWise () ) { return InvalidOperation ; }
1403 
1404  // adjust the length
1405  if ( rows >= maxv )
1406  {
1407  Warning ( "fmatrix('"+name+"'): matrix is overflow, skip extra items").ignore() ;
1408  rows = ( 0 < maxv ) ? ( maxv - 1 ) : 0 ;
1409  }
1410 
1411  // get the length item
1412  Int* len = ints( length , 0 , maxv ) ;
1413  if ( 0 == len ) { return InvalidColumn; }
1414 
1415  // adjust the length item
1416  *len = rows ;
1417 
1418  // get the array itself
1419  FMatrix* var = fMatrix ( name , len , cols ) ;
1420  if ( 0 == var ) { return InvalidColumn ; }
1421 
1423  for ( size_t iCol = 0 ; iCol < cols ; ++iCol )
1424  {
1425  for ( MIndex iRow = 0 ; iRow < rows ; ++iRow )
1426  { (*var)[ iRow ] [ iCol ] = (float)(data[ iRow ][ iCol ]) ; }
1427  }
1428 
1429  return StatusCode::SUCCESS ;
1430  }
1431  // =======================================================================
1468  template <class DATA>
1469  StatusCode fmatrix ( const std::string& name ,
1470  DATA first ,
1471  DATA last ,
1472  const MIndex& cols ,
1473  const std::string& length ,
1474  const size_t maxv )
1475  {
1476  if ( invalid () ) { return InvalidTuple ; }
1477  if ( rowWise () ) { return InvalidOperation ; }
1478 
1479  // adjust the length
1480  if ( first + maxv < last )
1481  {
1482  Warning("fmatrix('"+name+"'): matrix is overflow, skip extra items").ignore() ;
1483  last = first + maxv ;
1484  }
1485 
1486  // get the length item
1487  Int* len = ints( length , 0 , maxv ) ;
1488  if ( 0 == len ) { return InvalidColumn; }
1489 
1490  // adjust the length item
1491  *len = last - first ;
1492 
1493  // get the array itself
1494  FMatrix* var = fMatrix ( name , len , cols ) ;
1495  if ( 0 == var ) { return InvalidColumn ; }
1496 
1498  size_t iRow = 0 ;
1499  for ( ; first != last ; ++first )
1500  {
1501  //
1502  for ( MIndex iCol = 0 ; iCol < cols ; ++iCol )
1503  { (*var)[ iRow ] [ iCol ] = (float)((*first)[ iCol ]) ; }
1504  //
1505  ++iRow ;
1506  }
1507 
1508  return StatusCode::SUCCESS ;
1509  }
1510  // =======================================================================
1589  template <class FUN,class DATA>
1590  StatusCode fmatrix ( const std::string& name ,
1591  FUN funF ,
1592  FUN funL ,
1593  DATA first ,
1594  DATA last ,
1595  const std::string& length ,
1596  const size_t maxv )
1597  {
1598  if ( invalid () ) { return InvalidTuple ; }
1599  if ( rowWise () ) { return InvalidOperation ; }
1600 
1601  // adjust the length
1602  if ( first + maxv < last )
1603  {
1604  Warning("fmatrix('"+name+"'): matrix is overflow, skip extra items").ignore() ;
1605  last = first + maxv ;
1606  }
1607 
1608  // get the length item
1609  Int* len = ints( length , 0 , maxv ) ;
1610  if ( 0 == len ) { return InvalidColumn; }
1611 
1612  // adjust the length item
1613  *len = last - first ;
1614 
1615  // get the array itself
1616  const size_t cols = funL - funF ;
1617  FMatrix* var = fMatrix ( name , len , cols ) ;
1618  if ( 0 == var ) { return InvalidColumn ; }
1619 
1621  size_t iRow = 0 ;
1622  for ( ; first != last ; ++first )
1623  {
1624  //
1625  for ( FUN fun = funF ; fun < funL ; ++fun )
1626  { (*var)[ iRow ] [ fun - funF ] = (float)((*fun) ( *first )) ; }
1627  //
1628  ++iRow;
1629  }
1630 
1631  return StatusCode::SUCCESS ;
1632  }
1633  // =======================================================================
1634  public:
1635  // =======================================================================
1658  template <class DATA>
1659  StatusCode array ( const std::string& name ,
1660  DATA first ,
1661  DATA last )
1662 
1663  {
1664  if ( invalid () ) { return InvalidTuple ; }
1665  if ( rowWise () ) { return InvalidOperation ; }
1666 
1667  // get the length (fixed!)
1668  const size_t length = last - first ;
1669 
1670  // get the array itself
1671  FArray* var = fArray ( name , length ) ;
1672  if ( 0 == var ) { return InvalidColumn ; }
1673 
1675  size_t iCol = 0 ;
1676  for ( ; first != last ; ++first )
1677  { (*var)[ iCol ] = (float)(*first) ; ++iCol ; }
1678 
1679  return StatusCode::SUCCESS ;
1680  }
1681  // =======================================================================
1720  template <class ARRAY>
1721  StatusCode array ( const std::string& name ,
1722  const ARRAY& data ,
1723  const MIndex& length )
1724  {
1725  if ( invalid () ) { return InvalidTuple ; }
1726  if ( rowWise () ) { return InvalidOperation ; }
1727 
1728  // get the array itself
1729  FArray* var = fArray ( name , length ) ;
1730  if ( 0 == var ) { return InvalidColumn ; }
1731 
1733  for ( size_t index = 0 ; index < length ; ++index )
1734  { (*var)[ index ] = (float) data[index] ; }
1735 
1736  return StatusCode::SUCCESS ;
1737  }
1738  // =======================================================================
1768  template <class ARRAY>
1769  StatusCode array ( const std::string& name ,
1770  const ARRAY& data )
1771  { return array ( name , data.begin() , data.end() ) ; }
1772  // =======================================================================
1773  public:
1774  // =======================================================================
1823  template <class MATRIX>
1824  StatusCode matrix ( const std::string& name ,
1825  const MATRIX& data ,
1826  const MIndex& rows ,
1827  const MIndex& cols )
1828  {
1829  if ( invalid () ) { return InvalidTuple ; }
1830  if ( rowWise () ) { return InvalidOperation ; }
1831 
1832  // get the matrix itself
1833  FMatrix* var = fMatrix ( name , rows , cols ) ;
1834  if ( 0 == var ) { return InvalidColumn ; }
1835 
1837  for ( size_t iCol = 0 ; iCol < cols ; ++iCol )
1838  {
1839  for ( size_t iRow = 0 ; iRow < rows ; ++iRow )
1840  { (*var)[iRow][iCol] = (float)(data[iRow][iCol]) ; }
1841  };
1842  return StatusCode::SUCCESS ;
1843  }
1844  // =======================================================================
1845  public:
1846  // =======================================================================
1863  template <class TYPE>
1864  StatusCode column
1865  ( const std::string& name ,
1866  const ROOT::Math::LorentzVector<TYPE>& v )
1867  {
1868  if ( invalid() ) { return InvalidTuple ; }
1869  // fill all separate columns:
1870  StatusCode sc1 = this -> column ( name + "E" , v.E () ) ;
1871  StatusCode sc2 = this -> column ( name + "X" , v.Px () ) ;
1872  StatusCode sc3 = this -> column ( name + "Y" , v.Py () ) ;
1873  StatusCode sc4 = this -> column ( name + "Z" , v.Pz () ) ;
1874  return
1875  sc1.isFailure () ? sc1 :
1876  sc2.isFailure () ? sc2 :
1877  sc3.isFailure () ? sc3 :
1878  sc4.isFailure () ? sc4 : StatusCode(StatusCode::SUCCESS) ;
1879  }
1880  // =======================================================================
1897  template <class TYPE,class TAG>
1898  StatusCode column
1899  ( const std::string& name ,
1901  {
1902  if ( invalid() ) { return InvalidTuple ; }
1904  StatusCode sc1 = this -> column ( name + "X" , v.X () ) ;
1905  StatusCode sc2 = this -> column ( name + "Y" , v.Y () ) ;
1906  StatusCode sc3 = this -> column ( name + "Z" , v.Z () ) ;
1907  return
1908  sc1.isFailure () ? sc1 :
1909  sc2.isFailure () ? sc2 :
1910  sc3.isFailure () ? sc3 : StatusCode(StatusCode::SUCCESS) ;
1911  }
1912  // =======================================================================
1929  template <class TYPE,class TAG>
1930  StatusCode column
1931  ( const std::string& name ,
1933  {
1934  if ( invalid() ) { return InvalidTuple ; }
1936  StatusCode sc1 = this -> column ( name + "X" , v.X () ) ;
1937  StatusCode sc2 = this -> column ( name + "Y" , v.Y () ) ;
1938  StatusCode sc3 = this -> column ( name + "Z" , v.Z () ) ;
1939  return
1940  sc1.isFailure () ? sc1 :
1941  sc2.isFailure () ? sc2 :
1942  sc3.isFailure () ? sc3 : StatusCode(StatusCode::SUCCESS) ;
1943  }
1944  // =======================================================================
1961  template <class TYPE,unsigned int DIM>
1963  ( const std::string& name ,
1964  const ROOT::Math::SVector<TYPE,DIM>& vect )
1965  {
1966  return this->array( name , vect.begin() , vect.end() ) ;
1967  }
1968  // =======================================================================
1977  template <class TYPE,unsigned int D1,unsigned int D2,class REP>
1978  StatusCode matrix
1979  ( const std::string& name ,
1980  const ROOT::Math::SMatrix<TYPE,D1,D2,REP>& mtrx )
1981  {
1982  if ( invalid () ) { return InvalidTuple ; }
1983  if ( rowWise () ) { return InvalidOperation ; }
1984 
1985  // get the matrix itself
1986  FMatrix* var = fMatrix ( name , (MIndex)D1 , (MIndex)D2 ) ;
1987  if ( 0 == var ) { return InvalidColumn ; }
1988 
1990  for ( size_t iCol = 0 ; iCol < D2 ; ++iCol )
1991  {
1992  for ( size_t iRow = 0 ; iRow < D1 ; ++iRow )
1993  { (*var)[iRow][iCol] = (float) mtrx(iRow,iCol) ; }
1994  };
1995 
1996  return StatusCode::SUCCESS ;
1997  }
1998  // =======================================================================
2016  template <class KEY, class VALUE>
2017  StatusCode fmatrix
2018  ( const std::string& name ,
2019  const GaudiUtils::VectorMap<KEY,VALUE>& info ,
2020  const std::string& length ,
2021  const size_t maxv = 100 )
2022  {
2023 
2024  if ( invalid () ) { return InvalidTuple ; }
2025  if ( rowWise () ) { return InvalidOperation ; }
2026 
2027  typename GaudiUtils::VectorMap<KEY,VALUE>::const_iterator begin = info.begin () ;
2029 
2030  // adjust the length
2031  if ( maxv < info.size() )
2032  {
2033  Warning("fmatrix('"+name+"'): matrix is overflow, skip extra items") ;
2034  end = begin + maxv ;
2035  } ;
2036 
2037  // get the length item
2038  Int* len = ints( length , 0 , maxv ) ;
2039  if ( 0 == len ) { return InvalidColumn; }
2040 
2041  // adjust the length item
2042  *len = end - begin ;
2043 
2044  // get the array itself
2045  FMatrix* var = fMatrix ( name , len , 2 ) ;
2046  if ( 0 == var ) { return InvalidColumn ; }
2047 
2049  size_t iRow = 0 ;
2050  for ( ; begin != end ; ++begin)
2051  {
2052  //
2053  (*var)[iRow][0] = (float) begin->first ;
2054  (*var)[iRow][1] = (float) begin->second ;
2055  //
2056  ++iRow ;
2057  } ;
2058 
2059  return StatusCode::SUCCESS ;
2060  }
2061  // =======================================================================
2062  public:
2063  // =======================================================================
2071  template <class TYPE>
2072  StatusCode put
2073  ( const std::string& name , const TYPE* obj ) ;
2074  // =======================================================================
2075  public:
2076  // =======================================================================
2080  StatusCode write () ;
2081  // =======================================================================
2083  const std::string& name() const { return m_name ; }
2084  // =======================================================================
2088  NTuple::Tuple* tuple() const { return m_tuple ; }
2089  // =======================================================================
2093  unsigned long refCount() const { return m_refCount ; }
2094  // =======================================================================
2098  unsigned long addRef () { return ++m_refCount ; }
2099  // =======================================================================
2104  void release () ;
2105  // =======================================================================
2107  const CLID& clid() const { return m_clid ; }
2108  // =======================================================================
2110  Tuples::Type type() const { return m_type ; }
2111  // =======================================================================
2113  bool columnWise() const { return CLID_ColumnWiseTuple == clid() ; }
2114  // =======================================================================
2116  bool rowWise () const { return CLID_RowWiseTuple == clid() ; }
2117  // =======================================================================
2119  bool evtColType() const { return Tuples::EVTCOL == type() ; }
2120  // =======================================================================
2122  bool valid () const { return 0 != tuple() ; }
2123  // =======================================================================
2125  bool invalid () const { return ! valid() ; }
2126  // =======================================================================
2127  public:
2128  // =======================================================================
2134  bool addItem ( const std::string& name ,
2135  const std::string& type )
2136  { return m_items.insert ( std::make_pair ( name , type ) ).second ; }
2137  // =======================================================================
2142  bool goodItem ( const std::string& name ) const
2143  { return m_items.end() == m_items.find ( name ) ; }
2144  // =======================================================================
2146  const ItemMap& items() const { return m_items ; }
2147  // =======================================================================
2148  public:
2149  // =======================================================================
2150  virtual StatusCode Error
2151  ( const std::string& msg ,
2152  const StatusCode sc = StatusCode::FAILURE ) const = 0 ;
2153  // =======================================================================
2154  virtual StatusCode Warning
2155  ( const std::string& msg ,
2156  const StatusCode sc = StatusCode::FAILURE ) const = 0 ;
2157  // =======================================================================
2158  private:
2159  // =======================================================================
2161  Bool* bools ( const std::string& name ) ;
2162  // =======================================================================
2164  Float* floats ( const std::string& name ) ;
2165  // =======================================================================
2167  Double* doubles ( const std::string& name ) ;
2168  // =======================================================================
2170  Char* chars ( const std::string& name ) ;
2171  // =======================================================================
2173  Char* chars ( const std::string& name ,
2174  const char minv ,
2175  const char maxv ) ;
2176  // =======================================================================
2178  UChar* uchars ( const std::string& name ) ;
2179  // =======================================================================
2181  UChar* uchars ( const std::string& name ,
2182  const unsigned char minv ,
2183  const unsigned char maxv ) ;
2184  // =======================================================================
2186  Short* shorts ( const std::string& name ) ;
2187  // =======================================================================
2189  Short* shorts ( const std::string& name ,
2190  const short minv ,
2191  const short maxv ) ;
2192  // =======================================================================
2194  UShort* ushorts ( const std::string& name ) ;
2195  // =======================================================================
2197  UShort* ushorts ( const std::string& name ,
2198  const unsigned short minv ,
2199  const unsigned short maxv ) ;
2200  // =======================================================================
2202  Int* ints ( const std::string& name ) ;
2203  // =======================================================================
2205  Int* ints ( const std::string& name ,
2206  const int minv ,
2207  const int maxv ) ;
2208  // =======================================================================
2210  UInt* uints ( const std::string& name ) ;
2211  // =======================================================================
2213  UInt* uints ( const std::string& name ,
2214  const unsigned int minv ,
2215  const unsigned int maxv ) ;
2216  // =======================================================================
2218  LongLong* longlongs ( const std::string& name );
2219  // =======================================================================
2221  LongLong* longlongs ( const std::string& name ,
2222  const long long minv ,
2223  const long long maxv ) ;
2224  // =======================================================================
2226  ULongLong* ulonglongs ( const std::string& name ) ;
2227  // =======================================================================
2229  ULongLong* ulonglongs ( const std::string& name ,
2230  const unsigned long long minv ,
2231  const unsigned long long maxv ) ;
2232  // =======================================================================
2234  FArray* fArray ( const std::string& name ,
2235  Int* item ) ;
2236  // =======================================================================
2238  FArray* fArray ( const std::string& name ,
2239  const MIndex& rows ) ;
2240  // =======================================================================
2242  Address* addresses ( const std::string& name ) ;
2243  // =======================================================================
2245  FMatrix* fMatrix ( const std::string& name ,
2246  Int* item ,
2247  const MIndex& cols ) ;
2248  // =======================================================================
2250  FMatrix* fMatrix ( const std::string& name ,
2251  const MIndex& rows ,
2252  const MIndex& cols ) ;
2253  // =======================================================================
2254  private:
2255  // =======================================================================
2257  TupleObj () ;
2258  // =======================================================================
2260  TupleObj ( const TupleObj& ) ;
2261  // =======================================================================
2263  TupleObj& operator= ( const TupleObj& ) ;
2264  // =======================================================================
2265  private:
2266  // =======================================================================
2269  // =======================================================================
2272  // =======================================================================
2275  // =======================================================================
2278  // =======================================================================
2281  // =======================================================================
2284  // =======================================================================
2287  // =======================================================================
2290  // =======================================================================
2293  // =======================================================================
2296  // =======================================================================
2299  // =======================================================================
2302  // =======================================================================
2305  // =======================================================================
2308  // =======================================================================
2309  private:
2310  // =======================================================================
2312  std::string m_name ;
2313  // =======================================================================
2316  // =======================================================================
2319  // =======================================================================
2322  // =======================================================================
2324  size_t m_refCount ;
2325  // =======================================================================
2327  mutable Bools m_bools ;
2328  // =======================================================================
2330  mutable Chars m_chars ;
2331  // =======================================================================
2333  mutable UChars m_uchars ;
2334  // =======================================================================
2336  mutable Shorts m_shorts ;
2337  // =======================================================================
2339  mutable UShorts m_ushorts ;
2340  // =======================================================================
2342  mutable Ints m_ints ;
2343  // =======================================================================
2345  mutable UInts m_uints ;
2346  // =======================================================================
2349  // =======================================================================
2352  // =======================================================================
2354  mutable Floats m_floats ;
2355  // =======================================================================
2357  mutable Doubles m_doubles ;
2358  // =======================================================================
2361  // =======================================================================
2363  mutable FArrays m_farrays ;
2364  // =======================================================================
2366  mutable FArrays m_arraysf ;
2367  // =======================================================================
2370  // =======================================================================
2373  // =======================================================================
2376  // =======================================================================
2377  } ;
2378  // ==========================================================================
2379 } // end of namespace Tuples
2380 // ============================================================================
2381 // GaudiAlg
2382 // ============================================================================
2383 #include "GaudiAlg/TuplePut.h"
2384 // ============================================================================
2385 // The END
2386 // ============================================================================
2387 #endif // GAUDIALG_TUPLEOBJ_H
2388 // ============================================================================
GaudiUtils::HashMap< std::string, Address * > Addresses
the actual storage type for address columns
Definition: TupleObj.h:2301
GaudiUtils::HashMap< std::string, UChar * > UChars
the actual storage type for unsigned short columns
Definition: TupleObj.h:2274
UShorts m_ushorts
the actual storage of all 'unsigned int' columns
Definition: TupleObj.h:2339
FMatrices m_fmatrices
the actual storage of all 'FArray' columns
Definition: TupleObj.h:2369
A bit modified version of 'Loki::AssocVector' associative vector from Loki library by Andrei Alexandr...
Definition: VectorMap.h:110
CLID m_clid
tuple CLID
Definition: TupleObj.h:2318
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:1824
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:133
NTuple::Item< float > Float
basic type for float items
Definition: TupleObj.h:212
bool goodItem(const std::string &name) const
check the uniqueness of the name
Definition: TupleObj.h:2142
bool evtColType() const
Event collection ?
Definition: TupleObj.h:2119
StatusCode farray(const std::string &name1, const FUNC1 &func1, const std::string &name2, const FUNC2 &func2, const std::string &name3, const FUNC3 &func3, DATA first, DATA last, const std::string &length, const size_t maxv)
Put three functions from one data array into LoKi-style N-Tuple simultaneously (effective!) ...
Definition: TupleObj.h:1182
Doubles m_doubles
the actual storage of all 'Double' columns
Definition: TupleObj.h:2357
Tuples::Type m_type
tuple 'type'
Definition: TupleObj.h:2321
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:45
GaudiUtils::HashMap< std::string, Char * > Chars
the actual storage type for short columns
Definition: TupleObj.h:2271
StatusCode fmatrix(const std::string &name, DATA first, DATA last, const MIndex &cols, const std::string &length, const size_t maxv)
Fill N-Tuple with data from variable-size matrix.
Definition: TupleObj.h:1469
GaudiUtils::HashMap< std::string, Bool * > Bools
the actual storage type for short columns
Definition: TupleObj.h:2268
NTuple::Item< IOpaqueAddress * > Address
basic type for address items
Definition: TupleObj.h:218
FMatrices m_matricesf
the actual storage of all 'FMatrix' columns (fixed)
Definition: TupleObj.h:2372
Floats m_floats
the actual storage of all 'Float' columns
Definition: TupleObj.h:2354
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:37
NTuple::Item< unsigned long long > ULongLong
basic type for unsigned long long items
Definition: TupleObj.h:209
FArrays m_farrays
the actual storage of all 'FArray' columns
Definition: TupleObj.h:2363
NTuple::Item< unsigned short > UShort
basic type for unsigned int items
Definition: TupleObj.h:197
GaudiUtils::HashMap< std::string, LongLong * > LongLongs
the actual storage type for longlong columns
Definition: TupleObj.h:2289
size_t m_refCount
reference counter
Definition: TupleObj.h:2324
unsigned short MIndex
Definition: TupleObj.h:227
std::string m_name
name
Definition: TupleObj.h:2312
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
FArrays m_arraysf
the actual storage of all 'FArray' columns (fixed)
Definition: TupleObj.h:2366
NTuple::Item< unsigned char > UChar
basic type for unsigned int items
Definition: TupleObj.h:191
Bools m_bools
the actual storage of all 'bool' columns
Definition: TupleObj.h:2327
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, DATA first, DATA last, const std::string &length, const size_t maxv)
Put four functions from one data array into LoKi-style N-Tuple simultaneously (effective!) ...
Definition: TupleObj.h:1277
bool columnWise() const
column wise NTuple ?
Definition: TupleObj.h:2113
NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
Definition: TupleObj.h:2088
StatusCode farray(const std::string &name, const FUNCTION &function, DATA first, DATA last, const std::string &length, const size_t maxv)
Put an indexed array into LoKi-style N-Tuple.
Definition: TupleObj.h:1027
NTuple::Item< short > Short
basic type for int items
Definition: TupleObj.h:194
Chars m_chars
the actual storage of all 'Int' columns
Definition: TupleObj.h:2330
iterator end() const
"end" iterator for sequential access (const-only version!)
Definition: VectorMap.h:200
ULongLongs m_ulonglongs
the actual storage of all 'ulonglong' columns
Definition: TupleObj.h:2351
string type
Definition: gaudirun.py:126
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: TupleObj.h:180
StatusCode array(const std::string &name, const ARRAY &data)
fill N-Tuple with fixed-size array
Definition: TupleObj.h:1769
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
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:958
NTuple::Matrix< float > FMatrix
basic type for matrix of floats
Definition: TupleObj.h:224
iterator begin() const
"begin" iterator for sequential access (const-only version!)
Definition: VectorMap.h:198
UInts m_uints
the actual storage of all 'unsigned int' columns
Definition: TupleObj.h:2345
GaudiUtils::HashMap< std::string, FMatrix * > FMatrices
the actual storage type for matrix columns
Definition: TupleObj.h:2307
ItemMap m_items
all booked types:
Definition: TupleObj.h:2375
NTuple::Item< bool > Bool
basic type for int items
Definition: TupleObj.h:185
NTuple::Item< double > Double
basic type for double items
Definition: TupleObj.h:215
GaudiUtils::HashMap< std::string, FArray * > FArrays
the actual storage type for array columns
Definition: TupleObj.h:2304
Specialization acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:299
Ints m_ints
the actual storage of all 'Int' columns
Definition: TupleObj.h:2342
unsigned int CLID
Class ID definition.
Definition: ClassID.h:9
LongLongs m_longlongs
the actual storage of all 'longlong' columns
Definition: TupleObj.h:2348
bool valid() const
valid pointer to tuple ?
Definition: TupleObj.h:2122
unsigned long addRef()
add the reference to TupleObj
Definition: TupleObj.h:2098
unsigned long refCount() const
return the reference counter
Definition: TupleObj.h:2093
bool rowWise() const
row wise NTuple ?
Definition: TupleObj.h:2116
StatusCode column(const std::string &name, const signed char value)
Set the value for the selected tuple column.
Definition: TupleObj.h:732
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:367
tuple end
Definition: IOTest.py:101
ErrorCodes
Tuple error codes.
Definition: TupleObj.h:76
NTuple::Item< long long > LongLong
basic type for unsigned long long items
Definition: TupleObj.h:206
Addresses m_addresses
the actual storage of all 'Address' columns
Definition: TupleObj.h:2360
#define min(a, b)
StatusCode array(const std::string &name, DATA first, DATA last)
fill N-Tuple with fixed-size array
Definition: TupleObj.h:1659
bool addItem(const std::string &name, const std::string &type)
add the item name into the list of known items
Definition: TupleObj.h:2134
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
NTuple::Tuple * m_tuple
tuple itself
Definition: TupleObj.h:2315
GaudiUtils::HashMap< std::string, Short * > Shorts
the actual storage type for short columns
Definition: TupleObj.h:2277
_vector::const_iterator const_iterator
visible const_iterator (exported)
Definition: VectorMap.h:151
GaudiUtils::HashMap< std::string, ULongLong * > ULongLongs
the actual storage type for ulonglong columns
Definition: TupleObj.h:2292
Tuples::Type type() const
accessor to the N-Tuple type
Definition: TupleObj.h:2110
GaudiUtils::HashMap< std::string, Double * > Doubles
the actual storage type for float columns
Definition: TupleObj.h:2298
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:27
NTuple::Item< char > Char
basic type for int items
Definition: TupleObj.h:188
GaudiUtils::HashMap< std::string, UInt * > UInts
the actual storage type for unsigned integer columns
Definition: TupleObj.h:2286
NTuple::Item< int > Int
basic type for int items
Definition: TupleObj.h:200
tuple item
print s1,s2
Definition: ana.py:146
StatusCode farray(const std::string &name1, const FUNC1 &func1, const std::string &name2, const FUNC2 &func2, DATA first, DATA last, const std::string &length, const size_t maxv)
Put two functions from one data array into LoKi-style N-Tuple simultaneously (effective!) ...
Definition: TupleObj.h:1096
Shorts m_shorts
the actual storage of all 'Int' columns
Definition: TupleObj.h:2336
bool invalid() const
invalid pointer to tuple ?
Definition: TupleObj.h:2125
const ItemMap & items() const
get the full list of booked items
Definition: TupleObj.h:2146
NTuple::Array< float > FArray
basic type for array of floats
Definition: TupleObj.h:221
Implementation file for Tuple::TupleObj::put method.
Opaque address interface definition.
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:43
const CLID & clid() const
accessor to the N-Tuple CLID
Definition: TupleObj.h:2107
StatusCode array(const std::string &name, const ARRAY &data, const MIndex &length)
fill N-Tuple with fixed-size array
Definition: TupleObj.h:1721
Class acting as a smart pointer holding a N tuple _Item.
Definition: NTuple.h:44
std::map< std::string, std::string > ItemMap
Definition: TupleObj.h:230
#define GAUDI_API
Definition: Kernel.h:108
Type
the list of available types for ntuples
Definition: TupleObj.h:63
const std::string & name() const
get the name
Definition: TupleObj.h:2083
NTuple::Item< unsigned int > UInt
basic type for unsigned int items
Definition: TupleObj.h:203
StatusCode farray(const std::string &name, DATA first, DATA last, const std::string &length, const size_t maxv)
Add an indexed array (of type float) to N-tuple.
Definition: TupleObj.h:880
StatusCode fmatrix(const std::string &name, FUN funF, FUN funL, DATA first, DATA last, const std::string &length, const size_t maxv)
fill N-Tuple with matrix of "direct-product" of "data-vector" [first,last) and "function-vector" [fun...
Definition: TupleObj.h:1590
StatusCode fmatrix(const std::string &name, const MATRIX &data, size_t rows, const MIndex &cols, const std::string &length, const size_t maxv)
Fill N-Tuple with data from variable-size matrix.
Definition: TupleObj.h:1394
GaudiUtils::HashMap< std::string, UShort * > UShorts
the actual storage type for unsigned short columns
Definition: TupleObj.h:2280
UChars m_uchars
the actual storage of all 'unsigned int' columns
Definition: TupleObj.h:2333
GaudiUtils::HashMap< std::string, Int * > Ints
the actual storage type for integer columns
Definition: TupleObj.h:2283
size_type size() const
number of elements
Definition: VectorMap.h:495
GaudiUtils::HashMap< std::string, Float * > Floats
the actual storage type for float columns
Definition: TupleObj.h:2295