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 ) {
138 return item.first->second.get();
141 template <
typename C,
typename... ExtraArgs>
143 ExtraArgs&&... ea ) {
144 using pointer =
typename C::mapped_type::pointer;
145 using reference = std::add_lvalue_reference_t<std::remove_pointer_t<pointer>>;
147 return found !=
map.end() ? found->second.get()
149 return parent->tuple()->addItem(
n, i, std::forward<ExtraArgs>( ea )... );
153 template <
typename Container,
typename UT,
typename... ExtraArgs>
155 ExtraArgs&&... ea ) {
157 auto item = find_or_create(
parent,
name, container, std::forward<ExtraArgs>( ea )... );
159 *item = std::forward<UT>( value );
164 const char*
name()
const override {
return "Tuples"; }
169 switch ( static_cast<Tuples::ErrorCodes>( code ) ) {
171 return "InvalidTuple";
173 return "InvalidColumn";
175 return "InvalidOperation";
177 return "InvalidObject";
179 return "InvalidItem";
181 return "TruncateValue";
207 for (
auto& entry :
m_map ) {
208 if ( entry.second != 0 )
209 std::cout <<
"Tuples::TupleObj WARNING " <<
m_message <<
"'" << entry.first <<
"' Counts = " << entry.second
224 static Counter s_InstanceCounter{
" Create/Destroy (mis)balance "};
232 : m_name(
std::move(
name ) ), m_tuple( tuple ), m_clid( clid ), m_type(
type ) {
241 Tuples::Local::s_InstanceCounter.
decrement( m_name );
248 return tuple()->write();
258 auto it1 = value.
begin();
259 auto it2 = value.
begin();
260 while ( value.end() != it1 && value.end() != it2 ) {
263 tokens.
emplace_back( value, it1 - value.begin(), it2 - it1 );
277 auto tokens = tokenize(
format,
" ,;" );
280 va_start( valist,
format );
283 for (
auto token = tokens.
cbegin(); tokens.
cend() != token && status.
isSuccess(); ++token ) {
284 double val = va_arg( valist,
double );
285 status =
column( *token, val );
287 Error(
"fill(): Can not add column '" + *token +
"' " ).ignore( );
301 return column_(
this, m_addresses,
name, address );
311 return column_(
this, m_floats,
name, value );
315 return column_(
this, m_doubles,
name, value );
319 return column_(
this, m_chars,
name, value );
323 return column_(
this, m_chars,
name, value, minv, maxv );
327 return column_(
this, m_uchars,
name, value );
331 unsigned char maxv ) {
332 return column_(
this, m_uchars,
name, value, minv, maxv );
336 return column_(
this, m_shorts,
name, value );
340 return column_(
this, m_shorts,
name, value, minv, maxv );
344 return column_(
this, m_ushorts,
name, value );
348 unsigned short maxv ) {
349 return column_(
this, m_ushorts,
name, value, minv, maxv );
353 return column_(
this, m_ints,
name, value );
357 return column_(
this, m_ints,
name, value, minv, maxv );
361 return find_or_create(
this,
name, m_ints, minv, maxv );
365 return column_(
this, m_uints,
name, value );
369 unsigned int maxv ) {
370 return column_(
this, m_uints,
name, value, minv, maxv );
374 Warning(
"'long' has different sizes on 32/64 bit systems. Casting '" +
name +
"' to 'long long'",
377 return column(
name, static_cast<long long>( value ) );
381 Warning(
"'long' has different sizes on 32/64 bit systems. Casting '" +
name +
"' to 'long long'",
384 return column(
name, static_cast<long long>( value ), static_cast<long long>( minv ),
385 static_cast<long 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 ) );
396 const unsigned long maxv ) {
397 Warning(
"'unsigned long' has different sizes on 32/64 bit systems. Casting '" +
name +
"' to 'unsigned long long'",
400 return column(
name, static_cast<unsigned long long>( value ), static_cast<unsigned long long>( minv ),
401 static_cast<unsigned long long>( maxv ) );
405 return column_(
this, m_longlongs,
name, value );
409 return column_(
this, m_longlongs,
name, value, minv, maxv );
413 return column_(
this, m_ulonglongs,
name, value );
417 unsigned long long maxv ) {
418 return column_(
this, m_ulonglongs,
name, value, minv, maxv );
422 return column_(
this, m_bools,
name, value );
429 auto found = m_farrays.find(
name );
430 if ( m_farrays.end() != found )
return found->second.get();
431 return create_(
this, m_farrays,
name,
432 [&](
const std::string&
n,
FArray& i ) {
return this->tuple()->addIndexedItem(
n, *length, i ); } );
439 auto found = m_arraysf.find(
name );
440 if ( m_arraysf.end() != found )
return found->second.get();
441 return create_(
this, m_arraysf,
name,
450 auto found = m_fmatrices.find(
name );
451 if ( m_fmatrices.end() != found )
return found->second.get();
453 return this->tuple()->addIndexedItem(
n, *length, cols, i );
462 auto found = m_matricesf.find(
name );
463 if ( m_matricesf.end() != found )
return found->second.get();
464 return create_(
this, m_matricesf,
name,
465 [&](
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.
Counter(std::string msg=" Misbalance ")
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
long counts(const std::string &object) const
unsigned int CLID
Class ID definition.
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.
const Gaudi::Algorithm & parent
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)