31 #include "boost/integer_traits.hpp" 48 struct tuple_type_<typename
Tuples::TupleObj::Float> {
49 static constexpr
const char* fmt =
"F";
50 static constexpr
const char* typ =
"floats";
53 struct tuple_type_<typename
Tuples::TupleObj::Double> {
54 static constexpr
const char* fmt =
"D";
55 static constexpr
const char* typ =
"doubles";
58 struct tuple_type_<typename
Tuples::TupleObj::Bool> {
59 static constexpr
const char* fmt =
"I";
60 static constexpr
const char* typ =
"bools";
63 struct tuple_type_<typename
Tuples::TupleObj::Char> {
64 static constexpr
const char* fmt =
"I";
65 static constexpr
const char* typ =
"chars";
68 struct tuple_type_<typename
Tuples::TupleObj::UChar> {
69 static constexpr
const char* fmt =
"I";
70 static constexpr
const char* typ =
"uchars";
73 struct tuple_type_<typename
Tuples::TupleObj::Short> {
74 static constexpr
const char* fmt =
"I";
75 static constexpr
const char* typ =
"shorts";
78 struct tuple_type_<typename
Tuples::TupleObj::UShort> {
79 static constexpr
const char* fmt =
"I";
80 static constexpr
const char* typ =
"ushorts";
83 struct tuple_type_<typename
Tuples::TupleObj::Int> {
84 static constexpr
const char* fmt =
"I";
85 static constexpr
const char* typ =
"ints";
88 struct tuple_type_<typename
Tuples::TupleObj::UInt> {
89 static constexpr
const char* fmt =
"I";
90 static constexpr
const char* typ =
"uints";
93 struct tuple_type_<typename
Tuples::TupleObj::LongLong> {
94 static constexpr
const char* fmt =
"ULL";
95 static constexpr
const char* typ =
"longlongs";
98 struct tuple_type_<typename
Tuples::TupleObj::ULongLong> {
99 static constexpr
const char* fmt =
"ULL";
100 static constexpr
const char* typ =
"ulonglongs";
103 struct tuple_type_<typename
Tuples::TupleObj::Address> {
104 static constexpr
const char* fmt =
"IOpaqueAddress*";
105 static constexpr
const char* typ =
"addresses";
108 struct tuple_type_<typename
Tuples::TupleObj::FArray> {
109 static constexpr
const char* fmt =
"FArray";
110 static constexpr
const char* typ =
"farray";
113 struct tuple_type_<typename
Tuples::TupleObj::FMatrix> {
114 static constexpr
const char* fmt =
"FMatrix";
115 static constexpr
const char* typ =
"fmatrix";
119 template <
typename C,
typename AddItem>
122 using element_t =
typename C::mapped_type::element_type;
123 using map_t =
struct tuple_type_<element_t>;
124 auto item = container.emplace(
name, std::make_unique<element_t>() );
125 if ( !item.second ) { parent->
Error(
std::string{map_t::typ} +
" ('" +
name +
"'): item is not inserted" ); }
131 return item.first->second.get();
134 template <
typename C,
typename... ExtraArgs>
136 ExtraArgs&&... ea ) {
137 using pointer =
typename C::mapped_type::pointer;
138 using reference = std::add_lvalue_reference_t<std::remove_pointer_t<pointer>>;
140 return found !=
map.end() ? found->second.get()
142 return parent->
tuple()->
addItem(
n, i, std::forward<ExtraArgs>( ea )... );
146 template <
typename Container,
typename UT,
typename... ExtraArgs>
148 ExtraArgs&&... ea ) {
150 auto item = find_or_create( parent,
name, container, std::forward<ExtraArgs>( ea )... );
152 *item = std::forward<UT>( value );
157 const char*
name()
const override {
return "Tuples"; }
162 switch ( static_cast<Tuples::ErrorCodes>( code ) ) {
164 return "InvalidTuple";
166 return "InvalidColumn";
168 return "InvalidOperation";
170 return "InvalidObject";
172 return "InvalidItem";
174 return "TruncateValue";
200 for (
auto& entry :
m_map ) {
201 if ( entry.second != 0 )
202 std::cout <<
"Tuples::TupleObj WARNING " <<
m_message <<
"'" << entry.first <<
"' Counts = " << entry.second
217 static Counter s_InstanceCounter{
" Create/Destroy (mis)balance "};
225 : m_name(
std::move(
name ) ), m_tuple( tuple ), m_clid( clid ), m_type(
type ) {
234 Tuples::Local::s_InstanceCounter.
decrement( m_name );
241 return tuple()->write();
251 auto it1 = value.
begin();
252 auto it2 = value.
begin();
253 while ( value.
end() != it1 && value.
end() != it2 ) {
270 auto tokens = tokenize(
format,
" ,;" );
273 va_start( valist,
format );
276 for (
auto token = tokens.
cbegin(); tokens.
cend() != token && status.
isSuccess(); ++token ) {
277 double val = va_arg( valist,
double );
278 status =
column( *token, val );
279 if ( status.
isFailure() ) Error(
"fill(): Can not add column '" + *token +
"' " );
293 return column_(
this, m_addresses,
name, address );
303 return column_(
this, m_floats,
name, value );
307 return column_(
this, m_doubles,
name, value );
311 return column_(
this, m_chars,
name, value );
315 return column_(
this, m_chars,
name, value, minv, maxv );
319 return column_(
this, m_uchars,
name, value );
323 unsigned char maxv ) {
324 return column_(
this, m_uchars,
name, value, minv, maxv );
328 return column_(
this, m_shorts,
name, value );
332 return column_(
this, m_shorts,
name, value, minv, maxv );
336 return column_(
this, m_ushorts,
name, value );
340 unsigned short maxv ) {
341 return column_(
this, m_ushorts,
name, value, minv, maxv );
345 return column_(
this, m_ints,
name, value );
349 return column_(
this, m_ints,
name, value, minv, maxv );
353 return find_or_create(
this,
name, m_ints, minv, maxv );
357 return column_(
this, m_uints,
name, value );
361 unsigned int maxv ) {
362 return column_(
this, m_uints,
name, value, minv, maxv );
366 Warning(
"'long' has different sizes on 32/64 bit systems. Casting '" +
name +
"' to 'long long'",
369 return column(
name, static_cast<long long>( value ) );
373 Warning(
"'long' has different sizes on 32/64 bit systems. Casting '" +
name +
"' to 'long long'",
376 return column(
name, static_cast<long long>( value ), static_cast<long long>( minv ),
377 static_cast<long long>( maxv ) );
381 Warning(
"'unsigned long' has different sizes on 32/64 bit systems. Casting '" +
name +
"' to 'unsigned long long'",
384 return column(
name, static_cast<unsigned long long>( value ) );
388 const unsigned long maxv ) {
389 Warning(
"'unsigned long' has different sizes on 32/64 bit systems. Casting '" +
name +
"' to 'unsigned long long'",
392 return column(
name, static_cast<unsigned long long>( value ), static_cast<unsigned long long>( minv ),
393 static_cast<unsigned long long>( maxv ) );
397 return column_(
this, m_longlongs,
name, value );
401 return column_(
this, m_longlongs,
name, value, minv, maxv );
405 return column_(
this, m_ulonglongs,
name, value );
409 unsigned long long maxv ) {
410 return column_(
this, m_ulonglongs,
name, value, minv, maxv );
414 return column_(
this, m_bools,
name, value );
421 auto found = m_farrays.find(
name );
422 if ( m_farrays.end() != found )
return found->second.get();
423 return create_(
this, m_farrays,
name,
424 [&](
const std::string&
n,
FArray& i ) {
return this->tuple()->addIndexedItem(
n, *length, i ); } );
431 auto found = m_arraysf.find(
name );
432 if ( m_arraysf.end() != found )
return found->second.get();
433 return create_(
this, m_arraysf,
name,
442 auto found = m_fmatrices.find(
name );
443 if ( m_fmatrices.end() != found )
return found->second.get();
445 return this->tuple()->addIndexedItem(
n, *length, cols, i );
454 auto found = m_matricesf.find(
name );
455 if ( m_matricesf.end() != found )
return found->second.get();
456 return create_(
this, m_matricesf,
name,
457 [&](
const std::string&
n,
FMatrix& i ) {
return this->tuple()->addItem(
n, rows, cols, i ); } );
Int * ints(const std::string &name, int minv, int maxv)
get the column
long decrement(const std::string &object)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Header file for class TupleObj.
Class acting as a smart pointer holding a N tuple _Item.
StatusCode fill(const char *format...)
Set the values for several columns simultaneously.
The category assigned to a StatusCode.
StatusCode column(const std::string &name, float value)
Set the value for selected tuple column.
ErrorCodes
Tuple error codes.
constexpr static const auto SUCCESS
virtual const char * name() const =0
Name of the category.
bool invalid() const
invalid pointer to tuple ?
Counter(std::string msg=" Misbalance ")
bool addItem(std::string name, std::string type)
add the item name into the list of known items
struct GAUDI_API map
Parametrisation class for map-like implementation.
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
TupleObj(std::string name, NTuple::Tuple *tuple, const CLID &clid=CLID_ColumnWiseTuple, const Tuples::Type type=Tuples::NTUPLE)
Standard constructor.
virtual std::string message(code_t code) const
Description for code within this category.
#define STATUSCODE_ENUM_IMPL(...)
Assign a category to the StatusCode enum declared with STATUSCODE_ENUM_DECL( ENUM )
This class is used for returning status codes from appropriate routines.
virtual bool isRecoverable(code_t code) const
Is code considered recoverable ?
static const Category & default_category() noexcept
Default Gaudi StatusCode category.
std::map< std::string, long > m_map
T find_first_of(T... args)
StatusCode write()
write a record to NTuple
const NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
long counts(const std::string &object) const
unsigned int CLID
Class ID definition.
virtual StatusCode Error(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const =0
Abstract base class which allows the user to interact with the actual N tuple implementation.
FArray * fArray(const std::string &name, Int *item)
get the column
const StatusCode & ignore() const
Ignore/check StatusCode.
StatusCode addItem(const std::string &name, Item< TYPE > &itm)
Add a scalar data item a N tuple.
FMatrix * fMatrix(const std::string &name, Int *item, const MIndex &cols)
get the column
Opaque address interface definition.
Class acting as a smart pointer holding a N tuple _Item.
Class acting as a smart pointer holding a N tuple _Item.
Type
the list of available types for ntuples
long increment(const std::string &object)
unsigned long code_t
type of StatusCode value
General namespace for Tuple properties.
T emplace_back(T... args)