2 #ifndef GAUDIALG_TUPLEOBJ_H
3 #define GAUDIALG_TUPLEOBJ_H 1
18 #include "GaudiKernel/NTuple.h"
19 #include "GaudiKernel/VectorMap.h"
23 #include "GaudiAlg/Tuples.h"
24 #include "GaudiAlg/Maps.h"
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"
60 template <
typename T>
struct to_ {
61 template <
typename Arg>
63 {
return T(std::forward<Arg>(
i)); }
240 typedef std::map<std::string,std::string>
ItemMap ;
254 const CLID& clid = CLID_ColumnWiseTuple ,
363 unsigned short value );
383 unsigned short value ,
384 unsigned short minv ,
385 unsigned short maxv );
447 unsigned char value );
467 unsigned char value ,
469 unsigned char maxv );
531 unsigned int value );
617 unsigned long value );
637 unsigned long value ,
639 unsigned long maxv );
701 unsigned long long value );
721 unsigned long long value ,
722 unsigned long long minv ,
723 unsigned long long maxv );
748 std::numeric_limits<signed char>::min() ,
749 std::numeric_limits<signed char>::max() ) ;
889 template <
typename ITERATOR1,
typename ITERATOR2>
893 const std::string& length ,
897 std::forward<ITERATOR1>(first), std::forward<ITERATOR2>(last),
943 template <
class DATA>
946 const std::string& length ,
1012 template <
class FUNCTION,
class ITERATOR>
1014 const FUNCTION&
function ,
1017 const std::string& length ,
1024 if( std::distance(first,last) > static_cast<std::ptrdiff_t>(maxv) ) {
1026 + name +
"'): array is overflow, skip extra entries") ;
1027 last = std::next(first,maxv);
1031 Int* len = ints( length , 0 , maxv ) ;
1035 *len = std::distance(first,last);
1038 FArray* var = fArray ( name , len ) ;
1042 std::transform( first, last,
std::begin(*var), std::cref(
function) );
1078 template <
class FUNC1,
class FUNC2,
class DATA>
1080 const FUNC1& func1 ,
1081 const std::string& name2 ,
1082 const FUNC2& func2 ,
1085 const std::string& length ,
1092 if( std::distance(first,last) > static_cast<std::ptrdiff_t>(maxv) )
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) ;
1102 Int* len = ints ( length , 0 , maxv ) ;
1106 *len = std::distance(first,last);
1109 FArray* var1 = fArray ( name1 , len ) ;
1113 FArray* var2 = fArray ( name2 , len ) ;
1118 for( ; first != last ; ++first )
1120 ( *var1 ) [ index ] = func1 ( *first ) ;
1121 ( *var2 ) [ index ] = func2 ( *first ) ;
1164 template <
class FUNC1,
class FUNC2,
class FUNC3,
class DATA>
1166 const FUNC1& func1 ,
1167 const std::string& name2 ,
1168 const FUNC2& func2 ,
1169 const std::string& name3 ,
1170 const FUNC3& func3 ,
1173 const std::string& length ,
1180 if( (
size_t)std::distance(first,last) > maxv )
1185 + name3 +
"'): array is overflow, skip extra entries").ignore() ;
1186 last = std::next(first, maxv) ;
1190 Int* len = ints ( length , 0 , maxv ) ;
1194 *len = std::distance(first,last);
1197 FArray* var1 = fArray ( name1 , len ) ;
1201 FArray* var2 = fArray ( name2 , len ) ;
1205 FArray* var3 = fArray ( name3 , len ) ;
1210 for( ; first != last ; ++first )
1212 ( *var1 ) [ index ] = (float)func1 ( *first ) ;
1213 ( *var2 ) [ index ] = (float)func2 ( *first ) ;
1214 ( *var3 ) [ index ] = (float)func3 ( *first ) ;
1259 template <
class FUNC1,
class FUNC2,
class FUNC3,
class FUNC4,
class DATA>
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 ,
1270 const std::string& length ,
1277 if( std::distance(first,last) > static_cast<std::ptrdiff_t>(maxv) )
1283 + name4 +
"'): array is overflow, skip extra entries").ignore() ;
1284 last = std::next(first, maxv);
1288 Int* len = ints ( length , 0 , maxv ) ;
1292 *len = std::distance(first,last);
1295 FArray* var1 = fArray ( name1 , len ) ;
1299 FArray* var2 = fArray ( name2 , len ) ;
1303 FArray* var3 = fArray ( name3 , len ) ;
1307 FArray* var4 = fArray ( name4 , len ) ;
1312 for( ; first != last ; ++first )
1314 ( *var1 ) [ index ] = func1 ( *first );
1315 ( *var2 ) [ index ] = func2 ( *first );
1316 ( *var3 ) [ index ] = func3 ( *first );
1317 ( *var4 ) [ index ] = func4 ( *first );
1376 template <
class MATRIX>
1378 const MATRIX& data ,
1380 const MIndex& cols ,
1381 const std::string& length ,
1390 Warning (
"fmatrix('"+name+
"'): matrix is overflow, skip extra items").ignore() ;
1391 rows = ( 0 < maxv ) ? ( maxv - 1 ) : 0 ;
1395 Int* len = ints( length , 0 , maxv ) ;
1402 FMatrix* var = fMatrix ( name , len , cols ) ;
1406 for (
size_t iCol = 0 ; iCol < cols ; ++iCol )
1408 for ( MIndex iRow = 0 ; iRow < rows ; ++iRow )
1409 { (*var)[ iRow ] [ iCol ] = data[ iRow ][ iCol ] ; }
1451 template <
class DATA>
1455 const MIndex& cols ,
1456 const std::string& length ,
1463 if ( first + maxv < last )
1465 Warning(
"fmatrix('"+name+
"'): matrix is overflow, skip extra items").ignore() ;
1466 last = first + maxv ;
1470 Int* len = ints( length , 0 , maxv ) ;
1474 *len = last - first ;
1477 FMatrix* var = fMatrix ( name , len , cols ) ;
1482 for ( ; first != last ; ++first )
1485 for ( MIndex iCol = 0 ; iCol < cols ; ++iCol )
1486 { (*var)[ iRow ] [ iCol ] = (float)((*first)[ iCol ]) ; }
1572 template <
class FUN,
class DATA>
1578 const std::string& length ,
1585 if ( std::distance(first,last) > static_cast<std::ptrdiff_t>(maxv) )
1587 Warning(
"fmatrix('"+name+
"'): matrix is overflow, skip extra items").ignore() ;
1588 last = std::next(first, maxv) ;
1592 Int* len = ints( length , 0 , maxv ) ;
1596 *len = std::distance(first,last);
1599 auto cols = std::distance(funF,funL);
1600 FMatrix* var = fMatrix ( name , len , cols ) ;
1605 for ( ; first != last ; ++first )
1608 for ( FUN
fun = funF ;
fun < funL ; ++
fun )
1609 { (*var)[ iRow ] [
fun - funF ] = (*fun) ( *first ) ; }
1641 template <
class DATA>
1651 auto length = std::distance(first,last);
1654 FArray* var = fArray ( name , length ) ;
1701 template <
class ARRAY>
1704 const MIndex& length )
1710 auto first =
begin(data);
1711 return array( name, first, std::next( first, length ) );
1744 template <
class ARRAY>
1802 template <
class MATRIX>
1804 const MATRIX& data ,
1805 const MIndex& rows ,
1806 const MIndex& cols )
1812 FMatrix* var = fMatrix ( name , rows , cols ) ;
1816 for (
size_t iCol = 0 ; iCol < cols ; ++iCol )
1818 for (
size_t iRow = 0 ; iRow < rows ; ++iRow )
1819 { (*var)[iRow][iCol] = data[iRow][iCol]; }
1842 template <
class TYPE>
1845 const ROOT::Math::LorentzVector<TYPE>& v )
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 () ) ;
1856 sc3.isFailure () ? sc3 :
1876 template <
class TYPE,
class TAG>
1878 (
const std::string& name ,
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 () ) ;
1908 template <
class TYPE,
class TAG>
1910 (
const std::string& name ,
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 () ) ;
1932 template <
class TYPE,
unsigned int D1,
unsigned int D2,
class REP>
1934 (
const std::string& name ,
1935 const ROOT::Math::SMatrix<TYPE,D1,D2,REP>& mtrx )
1941 FMatrix* var = fMatrix ( name , (MIndex)D1 , (MIndex)D2 ) ;
1945 for (
size_t iCol = 0 ; iCol < D2 ; ++iCol )
1947 for (
size_t iRow = 0 ; iRow < D1 ; ++iRow )
1948 { (*var)[iRow][iCol] = mtrx(iRow,iCol) ; }
1971 template <
class KEY,
class VALUE>
1973 (
const std::string& name ,
1975 const std::string& length ,
1976 const size_t maxv = 100 )
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,
1997 template <
class TYPE>
1999 (
const std::string& name ,
const TYPE* obj ) ;
2009 const std::string&
name()
const {
return m_name ; }
2029 unsigned long addRef () {
return ++m_refCount ; }
2044 bool columnWise()
const {
return CLID_ColumnWiseTuple == clid() ; }
2047 bool rowWise ()
const {
return CLID_RowWiseTuple == clid() ; }
2053 bool valid ()
const {
return 0 != tuple() ; }
2067 {
return m_items.emplace ( std::move(name) , std::move(type) ).second ; }
2074 {
return m_items.end() == m_items.find ( name ) ; }
2077 const ItemMap&
items()
const {
return m_items ; }
2082 (
const std::string&
msg ,
2086 (
const std::string&
msg ,
2092 Bool* bools (
const std::string& name ) ;
2095 Float* floats (
const std::string& name ) ;
2098 Double* doubles (
const std::string& name ) ;
2101 Char* chars (
const std::string& name ) ;
2104 Char* chars (
const std::string& name ,
2109 UChar* uchars (
const std::string& name ) ;
2112 UChar* uchars (
const std::string& name ,
2113 unsigned char minv ,
2114 unsigned char maxv ) ;
2117 Short* shorts (
const std::string& name ) ;
2120 Short* shorts (
const std::string& name ,
2125 UShort* ushorts (
const std::string& name ) ;
2128 UShort* ushorts (
const std::string& name ,
2129 unsigned short minv ,
2130 unsigned short maxv ) ;
2133 Int* ints (
const std::string& name ) ;
2136 Int* ints (
const std::string& name ,
2141 UInt* uints (
const std::string& name ) ;
2144 UInt* uints (
const std::string& name ,
2146 unsigned int maxv ) ;
2149 LongLong* longlongs (
const std::string& name );
2152 LongLong* longlongs (
const std::string& name ,
2157 ULongLong* ulonglongs (
const std::string& name ) ;
2160 ULongLong* ulonglongs (
const std::string& name ,
2161 unsigned long long minv ,
2162 unsigned long long maxv ) ;
2165 FArray* fArray (
const std::string& name ,
2169 FArray* fArray (
const std::string& name ,
2170 const MIndex& rows ) ;
2173 Address* addresses (
const std::string& name ) ;
2176 FMatrix* fMatrix (
const std::string& name ,
2178 const MIndex& cols ) ;
2181 FMatrix* fMatrix (
const std::string& name ,
2182 const MIndex& rows ,
2183 const MIndex& cols ) ;
2237 template <
typename T, NTuple::Item<T>* (TupleObj::*fun)(const std::
string&),
typename UT>
2240 auto item = (this->*
fun)( name );
2245 template <
typename T, NTuple::Item<T>* (TupleObj::*fun)(const std::
string&,T,T),
typename UT>
2248 auto item = (this->*
fun)( name, std::forward<UT>(minv),std::forward<UT>(maxv) );
2268 size_t m_refCount = 0;
2327 #include "GaudiAlg/TuplePut.h"
2331 #endif // GAUDIALG_TUPLEOBJ_H
StatusCode farray(const std::string &name1, const FUNC1 &func1, const std::string &name2, const FUNC2 &func2, DATA first, DATA last, const std::string &length, size_t maxv)
Put two functions from one data array into LoKi-style N-Tuple simultaneously (effective!) ...
UShorts m_ushorts
the actual storage of all 'unsigned int' columns
FMatrices m_fmatrices
the actual storage of all 'FArray' columns
A bit modified version of 'Loki::AssocVector' associative vector from Loki library by Andrei Alexandr...
GAUDI_API void fill(AIDA::IHistogram1D *histo, const double value, const double weight=1.0)
simple function to fill AIDA::IHistogram1D objects
const NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
StatusCode matrix(const std::string &name, const MATRIX &data, const MIndex &rows, const MIndex &cols)
fill N-Tuple with fixed-size matrix
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, size_t maxv)
Put three functions from one data array into LoKi-style N-Tuple simultaneously (effective!) ...
GaudiUtils::HashMap< std::string, std::unique_ptr< FMatrix > > FMatrices
the actual storage type for matrix columns
NTuple::Item< float > Float
basic type for float items
bool goodItem(const std::string &name) const
check the uniqueness of the name
bool evtColType() const
Event collection ?
T operator()(Arg &&i) const
Doubles m_doubles
the actual storage of all 'Double' columns
Tuples::Type m_type
tuple 'type'
Class acting as a smart pointer holding a N tuple _Item.
auto begin(reverse_wrapper< T > &w)
NTuple::Item< IOpaqueAddress * > Address
basic type for address items
FMatrices m_matricesf
the actual storage of all 'FMatrix' columns (fixed)
Floats m_floats
the actual storage of all 'Float' columns
NTuple::Item< unsigned long long > ULongLong
basic type for unsigned long long items
FArrays m_farrays
the actual storage of all 'FArray' columns
NTuple::Item< unsigned short > UShort
basic type for unsigned int items
StatusCode fmatrix(const std::string &name, const MATRIX &data, size_t rows, const MIndex &cols, const std::string &length, size_t maxv)
Fill N-Tuple with data from variable-size matrix.
bool isFailure() const
Test for a status code of FAILURE.
GaudiUtils::HashMap< std::string, std::unique_ptr< LongLong > > LongLongs
the actual storage type for longlong columns
NTuple::Tuple * tuple()
provide the access to underlying Gaudi N-tuple
FArrays m_arraysf
the actual storage of all 'FArray' columns (fixed)
GaudiUtils::HashMap< std::string, std::unique_ptr< Address > > Addresses
the actual storage type for address columns
StatusCode farray(const std::string &name, ITERATOR1 &&first, ITERATOR2 &&last, const std::string &length, size_t maxv)
Add an indexed array (of type float) to N-tuple.
NTuple::Item< unsigned char > UChar
basic type for unsigned int items
Bools m_bools
the actual storage of all 'bool' columns
bool columnWise() const
column wise NTuple ?
NTuple::Item< short > Short
basic type for int items
Chars m_chars
the actual storage of all 'Int' columns
bool addItem(std::string name, std::string type)
add the item name into the list of known items
StatusCode fmatrix(const std::string &name, FUN funF, FUN funL, DATA first, DATA last, const std::string &length, size_t maxv)
fill N-Tuple with matrix of "direct-product" of "data-vector" [first,last) and "function-vector" [fun...
ULongLongs m_ulonglongs
the actual storage of all 'ulonglong' columns
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
auto end(reverse_wrapper< T > &w)
StatusCode array(const std::string &name, const ARRAY &data)
fill N-Tuple with fixed-size array
This class is used for returning status codes from appropriate routines.
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.
NTuple::Matrix< float > FMatrix
basic type for matrix of floats
UInts m_uints
the actual storage of all 'unsigned int' columns
StatusCode column_(const std::string &name, UT &&value)
ItemMap m_items
all booked types:
NTuple::Item< bool > Bool
basic type for int items
NTuple::Item< double > Double
basic type for double items
Specialization acting as a smart pointer holding a N tuple _Item.
Ints m_ints
the actual storage of all 'Int' columns
GaudiUtils::HashMap< std::string, std::unique_ptr< UShort > > UShorts
the actual storage type for unsigned short columns
LongLongs m_longlongs
the actual storage of all 'longlong' columns
unsigned int CLID
Class ID definition.
bool valid() const
valid pointer to tuple ?
StatusCode fmatrix(const std::string &name, DATA first, DATA last, const MIndex &cols, const std::string &length, size_t maxv)
Fill N-Tuple with data from variable-size matrix.
unsigned long addRef()
add the reference to TupleObj
unsigned long refCount() const
return the reference counter
bool rowWise() const
row wise NTuple ?
Abstract base class which allows the user to interact with the actual N tuple implementation.
StatusCode column(const std::string &name, signed char value)
Set the value for the selected tuple column.
ErrorCodes
Tuple error codes.
NTuple::Item< long long > LongLong
basic type for unsigned long long items
Addresses m_addresses
the actual storage of all 'Address' columns
GaudiUtils::HashMap< std::string, std::unique_ptr< FArray > > FArrays
the actual storage type for array columns
GaudiUtils::HashMap< std::string, std::unique_ptr< Float > > Floats
the actual storage type for float columns
StatusCode array(const std::string &name, DATA first, DATA last)
fill N-Tuple with fixed-size array
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
GaudiUtils::HashMap< std::string, std::unique_ptr< Double > > Doubles
the actual storage type for float columns
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, size_t maxv)
Put four functions from one data array into LoKi-style N-Tuple simultaneously (effective!) ...
Tuples::Type type() const
accessor to the N-Tuple type
StatusCode farray(const std::string &name, const FUNCTION &function, ITERATOR first, ITERATOR last, const std::string &length, size_t maxv)
Put an indexed array into LoKi-style N-Tuple.
double fun(const std::vector< double > &x)
NTuple::Item< char > Char
basic type for int items
Common class providing an architecture-independent hash map.
NTuple::Item< int > Int
basic type for int items
StatusCode column_(const std::string &name, UT &&value, UT &&minv, UT &&maxv)
GaudiUtils::HashMap< std::string, std::unique_ptr< Char > > Chars
the actual storage type for short columns
Shorts m_shorts
the actual storage of all 'Int' columns
bool invalid() const
invalid pointer to tuple ?
const ItemMap & items() const
get the full list of booked items
NTuple::Array< float > FArray
basic type for array of floats
Opaque address interface definition.
GaudiUtils::HashMap< std::string, std::unique_ptr< UInt > > UInts
the actual storage type for unsigned integer columns
Class acting as a smart pointer holding a N tuple _Item.
NTuple::Tuple * m_tuple
tuple itself
const CLID & clid() const
accessor to the N-Tuple CLID
GaudiUtils::HashMap< std::string, std::unique_ptr< Int > > Ints
the actual storage type for integer columns
StatusCode array(const std::string &name, const ARRAY &data, const MIndex &length)
fill N-Tuple with fixed-size array
GaudiUtils::HashMap< std::string, std::unique_ptr< Short > > Shorts
the actual storage type for short columns
Class acting as a smart pointer holding a N tuple _Item.
std::map< std::string, std::string > ItemMap
Type
the list of available types for ntuples
const std::string & name() const
get the name
NTuple::Item< unsigned int > UInt
basic type for unsigned int items
GaudiUtils::HashMap< std::string, std::unique_ptr< ULongLong > > ULongLongs
the actual storage type for ulonglong columns
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
UChars m_uchars
the actual storage of all 'unsigned int' columns
GaudiUtils::HashMap< std::string, std::unique_ptr< Bool > > Bools
the actual storage type for short columns
GaudiUtils::HashMap< std::string, std::unique_ptr< UChar > > UChars
the actual storage type for unsigned short columns
General namespace for Tuple properties.