21 #include "boost/integer_traits.hpp" 39 struct tuple_type_<typename
Tuples::TupleObj::Float> {
40 static constexpr
const char* fmt =
"F";
41 static constexpr
const char* typ =
"floats";
44 struct tuple_type_<typename
Tuples::TupleObj::Double> {
45 static constexpr
const char* fmt =
"D";
46 static constexpr
const char* typ =
"doubles";
49 struct tuple_type_<typename
Tuples::TupleObj::Bool> {
50 static constexpr
const char* fmt =
"I";
51 static constexpr
const char* typ =
"bools";
54 struct tuple_type_<typename
Tuples::TupleObj::Char> {
55 static constexpr
const char* fmt =
"I";
56 static constexpr
const char* typ =
"chars";
59 struct tuple_type_<typename
Tuples::TupleObj::UChar> {
60 static constexpr
const char* fmt =
"I";
61 static constexpr
const char* typ =
"uchars";
64 struct tuple_type_<typename
Tuples::TupleObj::Short> {
65 static constexpr
const char* fmt =
"I";
66 static constexpr
const char* typ =
"shorts";
69 struct tuple_type_<typename
Tuples::TupleObj::UShort> {
70 static constexpr
const char* fmt =
"I";
71 static constexpr
const char* typ =
"ushorts";
74 struct tuple_type_<typename
Tuples::TupleObj::Int> {
75 static constexpr
const char* fmt =
"I";
76 static constexpr
const char* typ =
"ints";
79 struct tuple_type_<typename
Tuples::TupleObj::UInt> {
80 static constexpr
const char* fmt =
"I";
81 static constexpr
const char* typ =
"uints";
84 struct tuple_type_<typename
Tuples::TupleObj::LongLong> {
85 static constexpr
const char* fmt =
"ULL";
86 static constexpr
const char* typ =
"longlongs";
89 struct tuple_type_<typename
Tuples::TupleObj::ULongLong> {
90 static constexpr
const char* fmt =
"ULL";
91 static constexpr
const char* typ =
"ulonglongs";
94 struct tuple_type_<typename
Tuples::TupleObj::Address> {
95 static constexpr
const char* fmt =
"IOpaqueAddress*";
96 static constexpr
const char* typ =
"addresses";
99 struct tuple_type_<typename
Tuples::TupleObj::FArray> {
100 static constexpr
const char* fmt =
"FArray";
101 static constexpr
const char* typ =
"farray";
104 struct tuple_type_<typename
Tuples::TupleObj::FMatrix> {
105 static constexpr
const char* fmt =
"FMatrix";
106 static constexpr
const char* typ =
"fmatrix";
110 template <
typename C,
typename AddItem>
114 using element_t =
typename C::mapped_type::element_type;
115 using map_t =
struct tuple_type_<element_t>;
116 auto item = container.emplace( name, std::make_unique<element_t>() );
117 if ( !item.second ) {
118 parent->
Error(
std::string{map_t::typ} +
" ('" + name +
"'): item is not inserted" );
120 StatusCode sc = addItem( name, *( item.first->second ) );
122 parent->
Error(
std::string{map_t::typ} +
" ('" + name +
"'): item is not added", sc );
124 if ( !parent->
addItem( name, map_t::fmt ) ) {
125 parent->
Error(
std::string{map_t::typ} +
" ('" + name +
"'): item is not unique" );
127 return item.first->second.get();
130 template <
typename C,
typename... ExtraArgs>
134 using pointer =
typename C::mapped_type::pointer;
136 auto found = map.find( name );
137 return found != map.end() ? found->second.get()
138 : create_( parent, map, name, [&](
const std::string&
n, reference i ) {
139 return parent->
tuple()->
addItem( n, i, std::forward<ExtraArgs>( ea )... );
143 template <
typename Container,
typename UT,
typename... ExtraArgs>
148 auto item = find_or_create( parent, name, container, std::forward<ExtraArgs>( ea )... );
150 *item = std::forward<UT>( value );
155 const char*
name()
const override {
return "Tuples"; }
161 switch ( static_cast<Tuples::ErrorCodes>( code ) ) {
163 return "InvalidTuple";
165 return "InvalidColumn";
167 return "InvalidOperation";
169 return "InvalidObject";
171 return "InvalidItem";
173 return "TruncateValue";
203 for (
auto& entry : m_map ) {
204 if ( entry.second != 0 )
205 std::cout <<
"Tuples::TupleObj WARNING " << m_message <<
"'" << entry.first <<
"' Counts = " << entry.second
220 static Counter s_InstanceCounter{
" Create/Destroy (mis)balance "};
228 : m_name(
std::move( name ) ),
262 auto it1 = value.
begin();
263 auto it2 = value.
begin();
264 while ( value.
end() != it1 && value.
end() != it2 ) {
282 auto tokens = tokenize(
format,
" ,;" );
285 va_start( valist,
format );
288 for (
auto token = tokens.cbegin(); tokens.cend() != token && status.
isSuccess(); ++token ) {
289 double val = va_arg( valist,
double );
290 status =
column( *token, val );
291 if ( status.
isFailure() )
Error(
"fill(): Can not add column '" + *token +
"' " );
306 return column_(
this,
m_addresses, name, address );
317 return column_(
this,
m_floats, name, value );
322 return column_(
this,
m_doubles, name, value );
327 return column_(
this,
m_chars, name, value );
332 return column_(
this,
m_chars, name, value, minv, maxv );
337 return column_(
this,
m_uchars, name, value );
343 return column_(
this,
m_uchars, name, value, minv, maxv );
348 return column_(
this,
m_shorts, name, value );
353 return column_(
this,
m_shorts, name, value, minv, maxv );
358 return column_(
this,
m_ushorts, name, value );
362 unsigned short maxv )
364 return column_(
this,
m_ushorts, name, value, minv, maxv );
369 return column_(
this,
m_ints, name, value );
374 return column_(
this,
m_ints, name, value, minv, maxv );
379 return find_or_create(
this, name,
m_ints, minv, maxv );
384 return column_(
this,
m_uints, name, value );
389 return column_(
this,
m_uints, name, value, minv, maxv );
394 Warning(
"'long' has different sizes on 32/64 bit systems. Casting '" + name +
"' to 'long long'",
397 return column( name, static_cast<long long>( value ) );
402 Warning(
"'long' has different sizes on 32/64 bit systems. Casting '" + name +
"' to 'long long'",
405 return column( name, static_cast<long long>( value ), static_cast<long long>( minv ),
406 static_cast<long long>( maxv ) );
411 Warning(
"'unsigned long' has different sizes on 32/64 bit systems. Casting '" + name +
"' to 'unsigned long long'",
414 return column( name, static_cast<unsigned long long>( value ) );
418 const unsigned long maxv )
420 Warning(
"'unsigned long' has different sizes on 32/64 bit systems. Casting '" + name +
"' to 'unsigned long long'",
423 return column( name, static_cast<unsigned long long>( value ), static_cast<unsigned long long>( minv ),
424 static_cast<unsigned long long>( maxv ) );
434 return column_(
this,
m_longlongs, name, value, minv, maxv );
443 unsigned long long maxv )
445 return column_(
this,
m_ulonglongs, name, value, minv, maxv );
450 return column_(
this,
m_bools, name, value );
459 if (
m_farrays.end() != found )
return found->second.get();
470 if (
m_arraysf.end() != found )
return found->second.get();
482 if (
m_fmatrices.end() != found )
return found->second.get();
495 if (
m_matricesf.end() != found )
return found->second.get();
Int * ints(const std::string &name, int minv, int maxv)
get the column
virtual StatusCode write()=0
Write record of the NTuple (Shortcut of writeRecord)
ColumnStorage< FArray > m_arraysf
the actual storage of all 'FArray' columns (fixed)
ColumnStorage< Float > m_floats
the actual storage of all 'Float' columns
ColumnStorage< Address > m_addresses
the actual storage of all 'Address' columns
const NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
long decrement(const std::string &object)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
ColumnStorage< Bool > m_bools
the actual storage of all 'bool' columns
bool evtColType() const
Event collection ?
long counts(const std::string &object) const
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.
ColumnStorage< LongLong > m_longlongs
the actual storage of all 'longlong' columns
ColumnStorage< UShort > m_ushorts
the actual storage of all 'unsigned int' columns
StatusCode addIndexedItem(const std::string &name, Item< INDEX > &index, Array< TYPE > &array, const RANGE low, const RANGE high)
Add an indexed Array of data to a column wise N tuple with a range.
Counter(std::string msg=" Misbalance ")
ColumnStorage< UInt > m_uints
the actual storage of all 'unsigned int' columns
virtual StatusCode Warning(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const =0
bool addItem(std::string name, std::string type)
add the item name into the list of known items
ColumnStorage< Double > m_doubles
the actual storage of all 'Double' columns
ColumnStorage< FMatrix > m_fmatrices
the actual storage of all 'FArray' columns
ColumnStorage< ULongLong > m_ulonglongs
the actual storage of all 'ulonglong' columns
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.
#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.
ColumnStorage< Char > m_chars
the actual storage of all 'Int' columns
static const Category & default_category() noexcept
Default Gaudi StatusCode category.
std::map< std::string, long > m_map
ColumnStorage< Short > m_shorts
the actual storage of all 'Int' columns
T find_first_of(T...args)
StatusCode write()
write a record to NTuple
ColumnStorage< Int > m_ints
the actual storage of all 'Int' columns
unsigned int CLID
Class ID definition.
constexpr static const auto SUCCESS
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
virtual StatusCode Error(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const =0
ColumnStorage< FMatrix > m_matricesf
the actual storage of all 'FMatrix' columns (fixed)
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
bool invalid() const
invalid pointer to tuple ?
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)
ColumnStorage< UChar > m_uchars
the actual storage of all 'unsigned int' columns
virtual std::string message(code_t code) const
Description for code within this category.
unsigned long code_t
type of StatusCode value
ColumnStorage< FArray > m_farrays
the actual storage of all 'FArray' columns
General namespace for Tuple properties.