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()
139 return parent->
tuple()->
addItem( n, i, std::forward<ExtraArgs>( ea )... );
143 template <
typename Container,
typename UT,
typename... ExtraArgs>
150 auto item = find_or_create( parent, name, container, std::forward<ExtraArgs>( ea )... );
154 *item = std::forward<UT>( value );
179 for (
auto& entry : m_map ) {
180 if ( entry.second != 0 )
181 std::cout <<
"Tuples::TupleObj WARNING " << m_message <<
"'" << entry.first <<
"' Counts = " << entry.second
196 static Counter s_InstanceCounter{
" Create/Destroy (mis)balance "};
204 : m_name(
std::move( name ) ),
254 auto it1 = value.
begin();
255 auto it2 = value.
begin();
256 while ( value.
end() != it1 && value.
end() != it2 ) {
276 auto tokens = tokenize(
format,
" ,;" );
279 va_start( valist,
format );
282 for (
auto token = tokens.cbegin(); tokens.cend() != token && status.
isSuccess(); ++token ) {
283 double val = va_arg( valist,
double );
284 status =
column( *token, val );
286 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 );
460 return found->second.get();
473 return found->second.get();
487 return found->second.get();
502 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)
UShorts m_ushorts
the actual storage of all 'unsigned int' columns
FMatrices m_fmatrices
the actual storage of all 'FArray' columns
const NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
void release()
release the reference to TupleObj if reference counter becomes zero, object will be automatically del...
long decrement(const std::string &object)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
bool evtColType() const
Event collection ?
long counts(const std::string &object) const
Header file for class TupleObj.
Doubles m_doubles
the actual storage of all 'Double' columns
Class acting as a smart pointer holding a N tuple _Item.
StatusCode fill(const char *format...)
Set the values for several columns simultaneously.
bool isSuccess() const
Test for a status code of SUCCESS.
StatusCode column(const std::string &name, float value)
Set the value for selected tuple column.
FMatrices m_matricesf
the actual storage of all 'FMatrix' columns (fixed)
TupleObj()=delete
delete the default/copy constructor and assignment
Floats m_floats
the actual storage of all 'Float' columns
FArrays m_farrays
the actual storage of all 'FArray' columns
size_t m_refCount
reference counter
bool isFailure() const
Test for a status code of FAILURE.
FArrays m_arraysf
the actual storage of all 'FArray' columns (fixed)
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 ")
Bools m_bools
the actual storage of all 'bool' columns
virtual StatusCode Warning(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const =0
Chars m_chars
the actual storage of all 'Int' columns
bool addItem(std::string name, std::string type)
add the item name into the list of known items
ULongLongs 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.
This class is used for returning status codes from appropriate routines.
UInts m_uints
the actual storage of all 'unsigned int' columns
std::map< std::string, long > m_map
iterator find(const key_type &key)
T find_first_of(T...args)
StatusCode write()
write a record to NTuple
Ints m_ints
the actual storage of all 'Int' columns
unsigned int CLID
Class ID definition.
LongLongs m_longlongs
the actual storage of all 'longlong' columns
unsigned long refCount() const
return the reference counter
Abstract base class which allows the user to interact with the actual N tuple implementation.
virtual ~TupleObj()
destructor is protected
Addresses m_addresses
the actual storage of all 'Address' columns
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
typename std::tuple_element< N, Tuple >::type element_t
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
Shorts m_shorts
the actual storage of all 'Int' columns
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)
TO * reference(FROM *from)
UChars m_uchars
the actual storage of all 'unsigned int' columns
General namespace for Tuple properties.