Go to the documentation of this file.
12 #ifndef GAUDIALG_TUPLEOBJ_H
13 #define GAUDIALG_TUPLEOBJ_H 1
21 #include <fmt/format.h>
43 #include "Math/Point3D.h"
44 #include "Math/SMatrix.h"
45 #include "Math/SVector.h"
46 #include "Math/Vector3D.h"
47 #include "Math/Vector4D.h"
75 template <
typename Arg>
77 return T( std::forward<Arg>( i ) );
82 template <
typename Iterator>
83 using const_ref_t = std::add_const_t<typename std::iterator_traits<Iterator>::reference>;
363 StatusCode column( std::string_view
name,
unsigned short value,
unsigned short minv,
unsigned short maxv );
439 StatusCode column( std::string_view
name,
unsigned char value,
unsigned char minv,
unsigned char maxv );
515 StatusCode column( std::string_view
name,
unsigned int value,
unsigned int minv,
unsigned int maxv );
593 StatusCode column( std::string_view
name,
unsigned long value,
unsigned long minv,
unsigned long maxv );
670 unsigned long long maxv );
772 template <
typename Value,
typename... Args>
776 this->
column( std::get<0>(
args ), std::invoke( std::get<1>(
args ), value ) )... };
806 template <
typename Arg,
typename... Args>
808 constexpr
auto separators =
" ,;";
810 auto token =
fmt.substr( 0,
fmt.find_first_of( separators ) );
813 if ( !token.empty() ) {
816 return column( token, arg ).andThen( [&] {
817 if constexpr (
sizeof...( Args ) != 0 ) {
return fill(
fmt,
args... ); }
820 if (
fmt.find_first_not_of( separators ) != std::string_view::npos )
821 throw std::runtime_error{
"TupleObj::fill: bad format -- too few arguments for specified format" };
824 }
else if ( !
fmt.empty() ) {
829 throw std::runtime_error{
"TupleObj::fill: bad format -- too many arguments for specified format" };
885 template <
typename ITERATOR1,
typename ITERATOR2>
888 return farray(
name,
detail::to_float, std::forward<ITERATOR1>( first ), std::forward<ITERATOR2>( last ), length,
934 template <
class DATA>
1001 template <
class FUNCTION,
class ITERATOR>
1003 std::string_view length,
size_t maxv ) {
1009 Warning(
fmt::format(
"farray('{}'): array is overflow, skip extra entries",
name ) )
1015 Int* len =
ints( length, 0, maxv );
1027 [&](
auto&& i ) {
return std::invoke(
function,
std::forward<decltype( i )>( i ) ); } );
1059 template <
typename FunIterator,
typename DataIterator>
1061 std::string_view length,
size_t maxv ) {
1070 [](
std::ostream& os,
const auto& i ) -> decltype(
auto ) {
return os << i.first; } );
1071 Warning(
"farray('" + os.str() +
"'): array overflow, skipping extra entries" ).ignore();
1076 Int* len =
ints( length, 0, maxv );
1086 [&](
const auto& item ) {
return this->fArray( item.first, len ); } );
1092 for (
size_t index = 0; first != last; ++first, ++
index ) {
1093 auto item = first_item;
1094 for (
auto& var : vars ) { ( *var )[
index] = std::invoke( ( item++ )->
second, *first ); }
1103 typename = std::enable_if_t<!std::is_convertible_v<Container<NamedFunction>, std::string_view>>>
1104 StatusCode farray(
const Container<NamedFunction>& funs, DataIterator first, DataIterator last,
1105 std::string_view length,
size_t maxv ) {
1106 return farray_impl( funs.begin(), funs.end(), std::forward<DataIterator>( first ),
1107 std::forward<DataIterator>( last ), length, maxv );
1110 template <
typename NamedFunctions,
typename DataIterator,
1111 typename = std::enable_if_t<!std::is_convertible_v<NamedFunctions, std::string_view>>>
1112 StatusCode farray(
const NamedFunctions& funs, DataIterator first, DataIterator last, std::string_view length,
1114 return farray_impl( funs.begin(), funs.end(), std::forward<DataIterator>( first ),
1115 std::forward<DataIterator>( last ), length, maxv );
1149 template <
class FUNC1,
class FUNC2,
class Iterator>
1150 StatusCode farray( std::string_view name1,
const FUNC1& func1, std::string_view name2,
const FUNC2& func2,
1151 Iterator&& first,
Iterator&& last, std::string_view length,
size_t maxv ) {
1152 return farray( { { name1,
std::cref( func1 ) }, { name2,
std::cref( func2 ) } }, std::forward<Iterator>( first ),
1153 std::forward<Iterator>( last ), length, maxv );
1192 template <
class FUNC1,
class FUNC2,
class FUNC3,
class Iterator>
1193 StatusCode farray( std::string_view name1,
const FUNC1& func1, std::string_view name2,
const FUNC2& func2,
1194 std::string_view name3,
const FUNC3& func3,
Iterator&& first,
Iterator&& last,
1195 std::string_view length,
size_t maxv ) {
1197 std::forward<Iterator>( first ), std::forward<Iterator>( last ), length, maxv );
1239 template <
class FUNC1,
class FUNC2,
class FUNC3,
class FUNC4,
class Iterator>
1240 StatusCode farray( std::string_view name1,
const FUNC1& func1, std::string_view name2,
const FUNC2& func2,
1241 std::string_view name3,
const FUNC3& func3, std::string_view name4,
const FUNC4& func4,
1242 Iterator&& first,
Iterator&& last, std::string_view length,
size_t maxv ) {
1243 return farray( { { name1,
std::cref( func1 ) },
1247 std::forward<Iterator>( first ), std::forward<Iterator>( last ), length, maxv );
1302 template <
class MATRIX>
1304 std::string_view length,
size_t maxv ) {
1309 if ( rows >= maxv ) {
1310 Warning(
fmt::format(
"fmatrix('{}'): matrix is overflow, skip extra items",
name ) ).ignore();
1311 rows = ( 0 < maxv ) ? ( maxv - 1 ) : 0;
1315 Int* len =
ints( length, 0, maxv );
1326 for (
size_t iCol = 0; iCol < cols; ++iCol ) {
1327 for (
MIndex iRow = 0; iRow < rows; ++iRow ) { ( *var )[iRow][iCol] = data[iRow][iCol]; }
1369 template <
class DATA>
1376 if ( first + maxv < last ) {
1377 Warning(
fmt::format(
"fmatrix('{}'): matrix is overflow, skip extra items",
name ) ).ignore();
1378 last = first + maxv;
1382 Int* len =
ints( length, 0, maxv );
1386 *len = last - first;
1394 for ( ; first != last; ++first ) {
1396 for (
MIndex iCol = 0; iCol < cols; ++iCol ) { ( *var )[iRow][iCol] = ( *first )[iCol]; }
1482 template <
class FUN,
class DATA>
1490 Warning(
fmt::format(
"fmatrix('{}'): matrix is overflow, skip extra items",
name ) ).ignore();
1495 Int* len =
ints( length, 0, maxv );
1509 for ( ; first != last; ++first ) {
1511 for ( FUN fun = funF; fun < funL; ++fun ) { ( *var )[iRow][fun - funF] = std::invoke( *fun, *first ); }
1543 template <
class DATA>
1601 template <
class ARRAY>
1607 auto first =
begin( data );
1641 template <
class ARRAY>
1698 template <
class MATRIX>
1708 for (
size_t iCol = 0; iCol < cols; ++iCol ) {
1709 for (
size_t iRow = 0; iRow < rows; ++iRow ) { ( *var )[iRow][iCol] = data[iRow][iCol]; }
1732 template <
class TYPE>
1756 template <
class TYPE,
class TAG>
1779 template <
class TYPE,
class TAG>
1794 template <
class TYPE,
unsigned int D1,
unsigned int D2,
class REP>
1804 for (
size_t iCol = 0; iCol < D2; ++iCol ) {
1805 for (
size_t iRow = 0; iRow < D1; ++iRow ) { ( *var )[iRow][iCol] = mtrx( iRow, iCol ); }
1828 template <
class KEY,
class VALUE>
1830 const size_t maxv = 100 ) {
1832 static const std::array<float ( * )(
const Info& ), 2> fns = {
1833 { [](
const Info& i ) ->
float {
return i.first; }, [](
const Info& i ) ->
float {
return i.second; } } };
1846 template <
class TYPE>
1876 bool columnWise()
const {
return CLID_ColumnWiseTuple == clid(); }
1879 bool rowWise()
const {
return CLID_RowWiseTuple == clid(); }
1885 bool valid()
const {
return 0 != tuple(); }
1919 Int*
ints( std::string_view
name,
int minv,
int maxv );
1955 size_t m_refCount = 0;
1958 template <
typename T>
1965 auto i = m_map.
find( sv );
1966 return i != m_map.
end() ? &i->second.first :
nullptr;
1973 if ( !b )
return {
static_cast<T*
>(
nullptr ),
false };
1974 auto nh = m_map.extract( i );
1975 nh.key() = nh.mapped().second;
1977 return { &r.position->second.first, r.inserted };
2044 #endif // GAUDIALG_TUPLEOBJ_H
std::unordered_map< std::string_view, std::pair< T, std::string > > m_map
Tuples::Type m_type
tuple 'type'
StatusCode column(std::string_view name, const ROOT::Math::PositionVector3D< TYPE, TAG > &v)
Useful shortcut to put 3D-Vector directly into N-Tuple:
Tuples::Type type() const
accessor to the N-Tuple type
StatusCode columns(Value &&value, Args &&... args)
Set the values for several columns simultaneously, for the same object Non-existing columns will be a...
ColumnStorage< Short > m_shorts
the actual storage of all 'Int' columns
ColumnStorage< FMatrix > m_fmatrices
the actual storage of all 'FArray' columns
const NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
StatusCode matrix(std::string_view name, const MATRIX &data, const MIndex &rows, const MIndex &cols)
fill N-Tuple with fixed-size matrix
virtual StatusCode Error(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const =0
ColumnStorage< FArray > m_arraysf
the actual storage of all 'FArray' columns (fixed)
T back_inserter(T... args)
bool evtColType() const
Event collection ?
StatusCode column(std::string_view name, const ROOT::Math::LorentzVector< TYPE > &v)
Useful shortcut to put LorentzVector directly into N-Tuple:
StatusCode fill(std::string_view fmt, Arg arg, Args... args)
Set the values for several columns simultaneously.
StatusCode farray_impl(FunIterator first_item, FunIterator last_item, DataIterator first, DataIterator last, std::string_view length, size_t maxv)
Put arbitrary number of functions from one data array into LoKi-style N-Tuple simultaneously (effecti...
T operator()(Arg &&i) const
unsigned long code_t
type of StatusCode value
StatusCode array(std::string_view name, DATA first, DATA last)
fill N-Tuple with fixed-size array
ColumnStorage< Float > m_floats
the actual storage of all 'Float' columns
Address * addresses(std::string_view name)
get the column
StatusCode fmatrix(std::string_view name, const GaudiUtils::VectorMap< KEY, VALUE > &info, std::string_view length, const size_t maxv=100)
shortcut to put "ExtraInfo" fields of major into N-Tuple
StatusCode farray(std::string_view name1, const FUNC1 &func1, std::string_view name2, const FUNC2 &func2, std::string_view name3, const FUNC3 &func3, Iterator &&first, Iterator &&last, std::string_view length, size_t maxv)
Put three functions from one data array into LoKi-style N-Tuple simultaneously (effective!...
ColumnStorage< Bool > m_bools
the actual storage of all 'bool' columns
StatusCode matrix(std::string_view name, const ROOT::Math::SMatrix< TYPE, D1, D2, REP > &mtrx)
shortcut to put Smatrix into N-tuple:
StatusCode farray(std::string_view name1, const FUNC1 &func1, std::string_view name2, const FUNC2 &func2, std::string_view name3, const FUNC3 &func3, std::string_view name4, const FUNC4 &func4, Iterator &&first, Iterator &&last, std::string_view length, size_t maxv)
Put four functions from one data array into LoKi-style N-Tuple simultaneously (effective!...
StatusCode fmatrix(std::string_view name, DATA first, DATA last, const MIndex &cols, std::string_view length, size_t maxv)
Fill N-Tuple with data from variable-size matrix.
ColumnStorage< FMatrix > m_matricesf
the actual storage of all 'FMatrix' columns (fixed)
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
TupleObj(const TupleObj &)=delete
delete the copy constructor and assignment
ItemMap m_items
all booked types:
NTuple::Tuple * tuple()
provide the access to underlying Gaudi N-tuple
double * begin(CLHEP::HepVector &v)
bool valid() const
valid pointer to tuple ?
StatusCode fmatrix(std::string_view name, const MATRIX &data, size_t rows, const MIndex &cols, std::string_view length, size_t maxv)
Fill N-Tuple with data from variable-size matrix.
unsigned int CLID
Class ID definition.
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
ColumnStorage< Address > m_addresses
the actual storage of all 'Address' columns
constexpr to_< float > to_float
bool goodItem(std::string_view name) const
check the uniqueness of the name
StatusCode column(std::string_view name, const ROOT::Math::DisplacementVector3D< TYPE, TAG > &v)
Useful shortcut to put 3D-Vector directly into N-Tuple:
ColumnStorage< LongLong > m_longlongs
the actual storage of all 'long long' columns
StatusCode array(std::string_view name, const ARRAY &data, const MIndex &length)
fill N-Tuple with fixed-size array
ColumnStorage< UShort > m_ushorts
the actual storage of all 'unsigned int' columns
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Class acting as a smart pointer holding a N tuple _Item.
ColumnStorage< FArray > m_farrays
the actual storage of all 'FArray' columns
std::pair< T *, bool > emplace(std::string_view k, T v=T{})
bool addItem(std::string name, std::string type)
add the item name into the list of known items
const CLID & clid() const
accessor to the N-Tuple CLID
ColumnStorage< Double > m_doubles
the actual storage of all 'Double' columns
virtual StatusCode Warning(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const =0
ColumnStorage< Int > m_ints
the actual storage of all 'Int' columns
StatusCode array(std::string_view name, const ARRAY &data)
fill N-Tuple with fixed-size array
ColumnStorage< ULongLong > m_ulonglongs
the actual storage of all 'unsigned long long' columns
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
StatusCode column(std::string_view name, signed char value)
Set the value for the selected tuple column.
constexpr static const auto SUCCESS
bool invalid() const
invalid pointer to tuple ?
StatusCode farray(std::string_view name, const FUNCTION &function, ITERATOR first, ITERATOR last, std::string_view length, size_t maxv)
Put an indexed array into LoKi-style N-Tuple.
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
Abstract base class which allows the user to interact with the actual N tuple implementation.
bool valid(Iterator begin, Iterator end)
check the validness of the trees or nodes
std::add_const_t< typename std::iterator_traits< Iterator >::reference > const_ref_t
StatusCode farray(std::string_view name1, const FUNC1 &func1, std::string_view name2, const FUNC2 &func2, Iterator &&first, Iterator &&last, std::string_view length, size_t maxv)
Put two functions from one data array into LoKi-style N-Tuple simultaneously (effective!...
StatusCode farray(const NamedFunctions &funs, DataIterator first, DataIterator last, std::string_view length, size_t maxv)
ColumnStorage< UChar > m_uchars
the actual storage of all 'unsigned int' columns
StatusCode fmatrix(std::string_view name, FUN funF, FUN funL, DATA first, DATA last, std::string_view length, size_t maxv)
fill N-Tuple with matrix of "direct-product" of "data-vector" [first,last) and "function-vector" [fun...
NTuple::Tuple * m_tuple
tuple itself
const ItemMap & items() const
get the full list of booked items
StatusCode farray(std::string_view name, ITERATOR1 &&first, ITERATOR2 &&last, std::string_view length, size_t maxv)
Add an indexed array (of type float) to N-tuple.
ColumnStorage< UInt > m_uints
the actual storage of all 'unsigned int' columns
bool rowWise() const
row wise NTuple ?
TupleObj & operator=(const TupleObj &)=delete
GAUDI_API void fill(AIDA::IHistogram1D *histo, const double value, const double weight=1.0)
simple function to fill AIDA::IHistogram1D objects
Specialization acting as a smart pointer holding a N tuple _Item.
constexpr static const auto FAILURE
StatusCode farray(const Container< NamedFunction > &funs, DataIterator first, DataIterator last, std::string_view length, size_t maxv)
T * find(std::string_view sv)
StatusCode farray(std::string_view name, const DATA &data, std::string_view length, const size_t maxv)
Add an indexed array (of type float) to N-tuple.
bool columnWise() const
column wise NTuple ?
std::map< std::string, std::string, std::less<> > ItemMap
ColumnStorage< Char > m_chars
the actual storage of all 'Int' columns
const std::string & name() const
get the name
auto put(const DataObjectHandle< Out1 > &out_handle, Out2 &&out)
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Class acting as a smart pointer holding a N tuple _Item.
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator