Go to the documentation of this file.
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";
54 static constexpr
const char*
fmt =
"D";
55 static constexpr
const char* typ =
"doubles";
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";
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>
120 auto create_(
Tuples::TupleObj* parent, C& container, std::string_view
name, AddItem addItem ) {
121 using map_t =
struct tuple_type_<typename C::element_type>;
122 auto [iter, ok] = container.emplace( name );
134 template <
typename C,
typename... ExtraArgs>
137 return found !=
map.end() ? &*found : create_( parent,
map,
name, [&]( std::string_view
n,
auto& i ) {
138 return parent->
tuple()->addItem(
std::string{
n }, i, std::forward<ExtraArgs>( ea )... );
142 template <
typename Container,
typename UT,
typename... ExtraArgs>
144 ExtraArgs&&... ea ) {
146 auto item = find_or_create( parent,
name, container, std::forward<ExtraArgs>( ea )... );
148 *item = std::forward<UT>( value );
153 const char*
name()
const override {
return "Tuples"; }
160 return "InvalidTuple";
162 return "InvalidColumn";
164 return "InvalidOperation";
166 return "InvalidObject";
168 return "InvalidItem";
170 return "TruncateValue";
193 long counts( std::string_view
object )
const {
return get(
object ); }
196 for (
auto& entry :
m_map ) {
197 if ( entry.second != 0 )
198 std::cout <<
"Tuples::TupleObj WARNING " <<
m_message <<
"'" << entry.first <<
"' Counts = " << entry.second
204 long&
get( std::string_view sv ) {
209 long get( std::string_view sv )
const {
223 static Counter s_InstanceCounter{
" Create/Destroy (mis)balance " };
231 : m_name(
std::move(
name ) ), m_tuple( tuple ), m_clid( clid ), m_type(
type ) {
240 Tuples::Local::s_InstanceCounter.
decrement( m_name );
247 return tuple()->write();
258 return column_(
this, m_addresses,
name, address );
268 return column_(
this, m_floats,
name, value );
272 return column_(
this, m_doubles,
name, value );
276 return column_(
this, m_chars,
name, value );
280 return column_(
this, m_chars,
name, value, minv, maxv );
284 return column_(
this, m_uchars,
name, value );
288 unsigned char maxv ) {
289 return column_(
this, m_uchars,
name, value, minv, maxv );
293 return column_(
this, m_shorts,
name, value );
297 return column_(
this, m_shorts,
name, value, minv, maxv );
301 return column_(
this, m_ushorts,
name, value );
305 unsigned short maxv ) {
306 return column_(
this, m_ushorts,
name, value, minv, maxv );
312 return column_(
this, m_ints,
name, value, minv, maxv );
316 return find_or_create(
this,
name, m_ints, minv, maxv );
320 return column_(
this, m_uints,
name, value );
324 return column_(
this, m_uints,
name, value, minv, maxv );
328 Warning(
fmt::format(
"'long' has different sizes on 32/64 bit systems. Casting '{}' to 'long long'",
name ),
331 return column(
name,
static_cast<long long>( value ) );
335 Warning(
fmt::format(
"'long' has different sizes on 32/64 bit systems. Casting '{}' to 'long long'",
name ),
338 return column(
name,
static_cast<long long>( value ),
static_cast<long long>( minv ),
339 static_cast<long long>( maxv ) );
344 "'unsigned long' has different sizes on 32/64 bit systems. Casting '{}' to 'unsigned long long'",
name ),
347 return column(
name,
static_cast<unsigned long long>( value ) );
351 const unsigned long maxv ) {
353 "'unsigned long' has different sizes on 32/64 bit systems. Casting '{}' to 'unsigned long long'",
name ),
356 return column(
name,
static_cast<unsigned long long>( value ),
static_cast<unsigned long long>( minv ),
357 static_cast<unsigned long long>( maxv ) );
361 return column_(
this, m_longlongs,
name, value );
365 return column_(
this, m_longlongs,
name, value, minv, maxv );
369 return column_(
this, m_ulonglongs,
name, value );
373 unsigned long long maxv ) {
374 return column_(
this, m_ulonglongs,
name, value, minv, maxv );
378 return column_(
this, m_bools,
name, value );
385 auto found = m_farrays.find(
name );
386 if ( m_farrays.end() != found )
return &*found;
387 return create_(
this, m_farrays,
name, [&]( std::string_view
n,
FArray& i ) {
388 return this->tuple()->addIndexedItem(
std::string{
n }, *length, i );
396 auto found = m_arraysf.find(
name );
397 if ( m_arraysf.end() != found )
return &*found;
398 return create_(
this, m_arraysf,
name, [&]( std::string_view
n,
FArray& i ) {
399 return this->tuple()->addItem(
std::string{
n }, rows, i );
408 auto found = m_fmatrices.find(
name );
409 if ( m_fmatrices.end() != found )
return &*found;
410 return create_(
this, m_fmatrices,
name, [&]( std::string_view
n,
FMatrix& i ) {
411 return this->tuple()->addIndexedItem(
std::string{
n }, *length, cols, i );
420 auto found = m_matricesf.find(
name );
421 if ( m_matricesf.end() != found )
return &*found;
422 return create_(
this, m_matricesf,
name, [&]( std::string_view
n,
FMatrix& i ) {
423 return this->tuple()->addItem(
std::string{
n }, rows, cols, i );
long & get(std::string_view sv)
static const Category & default_category() noexcept
Default Gaudi StatusCode category.
StatusCode column(std::string_view name, float value)
Set the value for selected tuple column.
const NTuple::Tuple * tuple() const
provide the access to underlying Gaudi N-tuple
virtual StatusCode Error(const std::string &msg, const StatusCode sc=StatusCode::FAILURE) const =0
TupleObj(std::string name, NTuple::Tuple *tuple, const CLID &clid=CLID_ColumnWiseTuple, const Tuples::Type type=Tuples::NTUPLE)
Standard constructor.
Counter(std::string msg=" Misbalance ")
unsigned long code_t
type of StatusCode value
long increment(std::string_view object)
struct GAUDI_API map
Parametrisation class for map-like implementation.
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
long counts(std::string_view object) const
unsigned int CLID
Class ID definition.
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Class acting as a smart pointer holding a N tuple _Item.
Int * ints(std::string_view name, int minv, int maxv)
get the column
bool addItem(std::string name, std::string type)
add the item name into the list of known items
constexpr static const auto SUCCESS
bool invalid() const
invalid pointer to tuple ?
Abstract base class which allows the user to interact with the actual N tuple implementation.
#define STATUSCODE_ENUM_IMPL(...)
Assign a category to the StatusCode enum declared with STATUSCODE_ENUM_DECL( ENUM )
long decrement(std::string_view object)
StatusCode write()
write a record to NTuple
virtual const char * name() const =0
Name of the category.
FMatrix * fMatrix(std::string_view name, Int *item, const MIndex &cols)
get the column
virtual bool isRecoverable(code_t code) const
Is code considered recoverable ?
FArray * fArray(std::string_view name, Int *item)
get the column
std::map< std::string, long, std::less<> > m_map
virtual std::string message(code_t code) const
Description for code within this category.
long get(std::string_view sv) const