21 #include "boost/integer_traits.hpp" 38 struct tuple_type_<typename
Tuples::TupleObj::Float> {
39 static constexpr
const char* fmt =
"F";
40 static constexpr
const char* typ =
"floats";
43 struct tuple_type_<typename
Tuples::TupleObj::Double> {
44 static constexpr
const char* fmt =
"D";
45 static constexpr
const char* typ =
"doubles";
48 struct tuple_type_<typename
Tuples::TupleObj::Bool> {
49 static constexpr
const char* fmt =
"I";
50 static constexpr
const char* typ =
"bools";
53 struct tuple_type_<typename
Tuples::TupleObj::Char> {
54 static constexpr
const char* fmt =
"I";
55 static constexpr
const char* typ =
"chars";
58 struct tuple_type_<typename
Tuples::TupleObj::UChar> {
59 static constexpr
const char* fmt =
"I";
60 static constexpr
const char* typ =
"uchars";
63 struct tuple_type_<typename
Tuples::TupleObj::Short> {
64 static constexpr
const char* fmt =
"I";
65 static constexpr
const char* typ =
"shorts";
68 struct tuple_type_<typename
Tuples::TupleObj::UShort> {
69 static constexpr
const char* fmt =
"I";
70 static constexpr
const char* typ =
"ushorts";
73 struct tuple_type_<typename
Tuples::TupleObj::Int> {
74 static constexpr
const char* fmt =
"I";
75 static constexpr
const char* typ =
"ints";
78 struct tuple_type_<typename
Tuples::TupleObj::UInt> {
79 static constexpr
const char* fmt =
"I";
80 static constexpr
const char* typ =
"uints";
83 struct tuple_type_<typename
Tuples::TupleObj::LongLong> {
84 static constexpr
const char* fmt =
"ULL";
85 static constexpr
const char* typ =
"longlongs";
88 struct tuple_type_<typename
Tuples::TupleObj::ULongLong> {
89 static constexpr
const char* fmt =
"ULL";
90 static constexpr
const char* typ =
"ulonglongs";
93 struct tuple_type_<typename
Tuples::TupleObj::Address> {
94 static constexpr
const char* fmt =
"IOpaqueAddress*";
95 static constexpr
const char* typ =
"addresses";
98 struct tuple_type_<typename
Tuples::TupleObj::FArray> {
99 static constexpr
const char* fmt =
"FArray";
100 static constexpr
const char* typ =
"farray";
103 struct tuple_type_<typename
Tuples::TupleObj::FMatrix> {
104 static constexpr
const char* fmt =
"FMatrix";
105 static constexpr
const char* typ =
"fmatrix";
109 template <
typename C,
typename AddItem>
112 using element_t =
typename C::mapped_type::element_type;
113 using map_t =
struct tuple_type_<element_t>;
114 auto item = container.emplace( name, std::make_unique<element_t>() );
115 if ( !item.second ) { parent->
Error(
std::string{map_t::typ} +
" ('" + name +
"'): item is not inserted" ); }
116 StatusCode sc = addItem( name, *( item.first->second ) );
118 if ( !parent->
addItem( name, map_t::fmt ) ) {
119 parent->
Error(
std::string{map_t::typ} +
" ('" + name +
"'): item is not unique" );
121 return item.first->second.get();
124 template <
typename C,
typename... ExtraArgs>
126 ExtraArgs&&... ea ) {
127 using pointer =
typename C::mapped_type::pointer;
129 auto found = map.find( name );
130 return found != map.end() ? found->second.get()
131 : create_( parent, map, name, [&](
const std::string&
n, reference i ) {
132 return parent->
tuple()->
addItem( n, i, std::forward<ExtraArgs>( ea )... );
136 template <
typename Container,
typename UT,
typename... ExtraArgs>
138 ExtraArgs&&... ea ) {
140 auto item = find_or_create( parent, name, container, std::forward<ExtraArgs>( ea )... );
142 *item = std::forward<UT>( value );
147 const char*
name()
const override {
return "Tuples"; }
152 switch ( static_cast<Tuples::ErrorCodes>( code ) ) {
154 return "InvalidTuple";
156 return "InvalidColumn";
158 return "InvalidOperation";
160 return "InvalidObject";
162 return "InvalidItem";
164 return "TruncateValue";
190 for (
auto& entry : m_map ) {
191 if ( entry.second != 0 )
192 std::cout <<
"Tuples::TupleObj WARNING " << m_message <<
"'" << entry.first <<
"' Counts = " << entry.second
207 static Counter s_InstanceCounter{
" Create/Destroy (mis)balance "};
215 : m_name(
std::move( name ) ), m_tuple( tuple ), m_clid( clid ), m_type( type ) {
241 auto it1 = value.
begin();
242 auto it2 = value.
begin();
243 while ( value.
end() != it1 && value.
end() != it2 ) {
260 auto tokens = tokenize(
format,
" ,;" );
263 va_start( valist,
format );
266 for (
auto token = tokens.cbegin(); tokens.cend() != token && status.
isSuccess(); ++token ) {
267 double val = va_arg( valist,
double );
268 status =
column( *token, val );
269 if ( status.
isFailure() )
Error(
"fill(): Can not add column '" + *token +
"' " );
283 return column_(
this,
m_addresses, name, address );
293 return column_(
this,
m_floats, name, value );
297 return column_(
this,
m_doubles, name, value );
301 return column_(
this,
m_chars, name, value );
305 return column_(
this,
m_chars, name, value, minv, maxv );
309 return column_(
this,
m_uchars, name, value );
313 unsigned char maxv ) {
314 return column_(
this,
m_uchars, name, value, minv, maxv );
318 return column_(
this,
m_shorts, name, value );
322 return column_(
this,
m_shorts, name, value, minv, maxv );
326 return column_(
this,
m_ushorts, name, value );
330 unsigned short maxv ) {
331 return column_(
this,
m_ushorts, name, value, minv, maxv );
335 return column_(
this,
m_ints, name, value );
339 return column_(
this,
m_ints, name, value, minv, maxv );
343 return find_or_create(
this, name,
m_ints, minv, maxv );
347 return column_(
this,
m_uints, name, value );
351 unsigned int maxv ) {
352 return column_(
this,
m_uints, name, value, minv, maxv );
356 Warning(
"'long' has different sizes on 32/64 bit systems. Casting '" + name +
"' to 'long long'",
359 return column( name, static_cast<long long>( value ) );
363 Warning(
"'long' has different sizes on 32/64 bit systems. Casting '" + name +
"' to 'long long'",
366 return column( name, static_cast<long long>( value ), static_cast<long long>( minv ),
367 static_cast<long long>( maxv ) );
371 Warning(
"'unsigned long' has different sizes on 32/64 bit systems. Casting '" + name +
"' to 'unsigned long long'",
374 return column( name, static_cast<unsigned long long>( value ) );
378 const unsigned long maxv ) {
379 Warning(
"'unsigned long' has different sizes on 32/64 bit systems. Casting '" + name +
"' to 'unsigned long long'",
382 return column( name, static_cast<unsigned long long>( value ), static_cast<unsigned long long>( minv ),
383 static_cast<unsigned long long>( maxv ) );
391 return column_(
this,
m_longlongs, name, value, minv, maxv );
399 unsigned long long maxv ) {
400 return column_(
this,
m_ulonglongs, name, value, minv, maxv );
404 return column_(
this,
m_bools, name, value );
412 if (
m_farrays.end() != found )
return found->second.get();
422 if (
m_arraysf.end() != found )
return found->second.get();
433 if (
m_fmatrices.end() != found )
return found->second.get();
445 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.
constexpr static const auto SUCCESS
ColumnStorage< LongLong > m_longlongs
the actual storage of all 'long long' 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 'unsigned long long' 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.
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.