21 #include "boost/integer_traits.hpp" 34 template <
typename T>
struct tuple_type_ ;
36 template <>
struct tuple_type_<typename
Tuples::TupleObj::Float>
37 {
static constexpr
const char* fmt =
"F";
38 static constexpr
const char* typ =
"floats"; };
39 template <>
struct tuple_type_<typename
Tuples::TupleObj::Double>
40 {
static constexpr
const char* fmt =
"D";
41 static constexpr
const char* typ =
"doubles"; };
42 template <>
struct tuple_type_<typename
Tuples::TupleObj::Bool>
43 {
static constexpr
const char* fmt =
"I";
44 static constexpr
const char* typ =
"bools";};
45 template <>
struct tuple_type_<typename
Tuples::TupleObj::Char>
46 {
static constexpr
const char* fmt =
"I";
47 static constexpr
const char* typ =
"chars";};
48 template <>
struct tuple_type_<typename
Tuples::TupleObj::UChar>
49 {
static constexpr
const char* fmt =
"I";
50 static constexpr
const char* typ =
"uchars";};
51 template <>
struct tuple_type_<typename
Tuples::TupleObj::Short>
52 {
static constexpr
const char* fmt =
"I";
53 static constexpr
const char* typ =
"shorts";};
54 template <>
struct tuple_type_<typename
Tuples::TupleObj::UShort>
55 {
static constexpr
const char* fmt =
"I";
56 static constexpr
const char* typ =
"ushorts";};
57 template <>
struct tuple_type_<typename
Tuples::TupleObj::Int>
58 {
static constexpr
const char* fmt =
"I";
59 static constexpr
const char* typ =
"ints";};
60 template <>
struct tuple_type_<typename
Tuples::TupleObj::UInt>
61 {
static constexpr
const char* fmt =
"I";
62 static constexpr
const char* typ =
"uints";};
63 template <>
struct tuple_type_<typename
Tuples::TupleObj::LongLong>
64 {
static constexpr
const char* fmt =
"ULL";
65 static constexpr
const char* typ =
"longlongs";};
66 template <>
struct tuple_type_<typename
Tuples::TupleObj::ULongLong>
67 {
static constexpr
const char* fmt =
"ULL";
68 static constexpr
const char* typ =
"ulonglongs";};
69 template <>
struct tuple_type_<typename
Tuples::TupleObj::Address>
70 {
static constexpr
const char* fmt =
"IOpaqueAddress*" ;
71 static constexpr
const char* typ =
"addresses";};
72 template <>
struct tuple_type_<typename
Tuples::TupleObj::FArray>
73 {
static constexpr
const char* fmt =
"FArray";
74 static constexpr
const char* typ =
"farray";};
75 template <>
struct tuple_type_<typename
Tuples::TupleObj::FMatrix>
76 {
static constexpr
const char* fmt =
"FMatrix";
77 static constexpr
const char* typ =
"fmatrix"; };
80 template <
typename C,
typename AddItem>
82 using element_t =
typename C::mapped_type::element_type;
83 using map_t =
struct tuple_type_<
element_t> ;
84 auto item = container.emplace( name , std::make_unique<element_t>() ) ;
86 { parent->
Error (
std::string{map_t::typ} +
" ('" + name +
"'): item is not inserted" ) ; }
87 StatusCode sc = addItem( name , *(item.first->second) );
89 { parent->
Error (
std::string{map_t::typ} +
" ('" + name +
"'): item is not added", sc ) ; }
90 if ( !parent->
addItem(name,map_t::fmt) )
91 { parent->
Error (
std::string{map_t::typ} +
" ('" + name +
"'): item is not unique" ) ; }
92 return item.first->second.get() ;
95 template <
typename C,
typename... ExtraArgs>
98 using pointer =
typename C::mapped_type::pointer;
100 auto found = map.find(name);
101 return found != map.end() ? found->second.get()
102 : create_(parent, map ,name,
104 {
return parent->
tuple()->
addItem(n,i, std::forward<ExtraArgs>(ea)...); });
107 template <
typename Container,
typename UT,
typename ... ExtraArgs>
110 auto item = find_or_create( parent, name, container, std::forward<ExtraArgs>(ea)...);
112 *item = std::forward<UT>(value);
126 : m_message (
std::move(
msg) )
139 for (
auto& entry : m_map )
142 <<
"Tuples::TupleObj WARNING " << m_message
143 <<
"'" << entry.first <<
"' Counts = " << entry.second
158 static Counter s_InstanceCounter{
" Create/Destroy (mis)balance " };
177 Tuples::Local::s_InstanceCounter.
increment ( m_name ) ;
185 Tuples::Local::s_InstanceCounter.
decrement ( m_name ) ;
195 if( refCount() > 0 ) { --m_refCount; }
197 if( 0 == refCount() )
delete this;
205 return tuple()->
write() ;
218 auto it1 = value.
begin() ;
219 auto it2 = value.
begin() ;
220 while( value.
end() != it1 && value.
end() != it2 )
224 separators.begin () ,
225 separators.end () ) ;
241 auto tokens = tokenize( format ,
" ,;" );
244 va_start( valist , format ) ;
247 for(
auto token = tokens.cbegin() ;
248 tokens.cend() != token && status.
isSuccess() ; ++token )
250 double val = va_arg( valist ,
double );
251 status =
column( *token , val );
253 { Error (
"fill(): Can not add column '" + *token +
"' " ) ; }
270 {
return Error (
"column('" + name +
272 return column_(
this, m_addresses, name, address);
281 return column (
"Address" , address ) ;
288 return column_(
this, m_floats,name,value);
294 return column_(
this, m_doubles, name,value);
300 return column_(
this, m_chars, name, value);
308 return column_(
this, m_chars, name,value,minv,maxv);
312 unsigned char value )
314 return column_(
this, m_uchars, name,value);
318 unsigned char value ,
322 return column_(
this, m_uchars, name,value,minv,maxv);
328 return column_(
this, m_shorts, name,value);
336 return column_(
this, m_shorts, name, value, minv, maxv);
340 const unsigned short value )
342 return column_(
this, m_ushorts, name, value );
346 unsigned short value ,
347 unsigned short minv ,
348 unsigned short maxv )
350 return column_(
this, m_ushorts, name, value, minv, maxv );
356 return column_(
this, m_ints, name, value );
364 return column_(
this, m_ints, name,value,minv,maxv);
371 return find_or_create(
this, name, m_ints, minv, maxv );
377 return column_(
this, m_uints, name,value);
385 return column_(
this, m_uints, name,value,minv,maxv);
391 Warning(
"'long' has different sizes on 32/64 bit systems. Casting '" +
393 return column( name, static_cast<long long>(value) );
401 Warning(
"'long' has different sizes on 32/64 bit systems. Casting '" +
404 static_cast<long long>(value),
405 static_cast<long long>(minv),
406 static_cast<long long>(maxv) );
410 const unsigned long value )
412 Warning(
"'unsigned long' has different sizes on 32/64 bit systems. Casting '" +
414 return column( name, static_cast<unsigned long long>(value) );
418 const unsigned long value ,
419 const unsigned long minv ,
420 const unsigned long maxv )
422 Warning(
"'unsigned long' has different sizes on 32/64 bit systems. Casting '" +
425 static_cast<unsigned long long>(value),
426 static_cast<unsigned long long>(minv),
427 static_cast<unsigned long long>(maxv) );
431 const long long value )
433 return column_(
this, m_longlongs, name,value);
441 return column_(
this, m_longlongs, name,value,minv,maxv);
445 unsigned long long value )
447 return column_(
this, m_ulonglongs, name,value);
451 unsigned long long value ,
452 unsigned long long minv ,
453 unsigned long long maxv )
455 return column_(
this, m_ulonglongs, name,value,minv,maxv);
461 return column_(
this, m_bools, name,value);
471 auto found = m_farrays.find( name ) ;
472 if( m_farrays.end() != found ) {
return found->second.get() ; }
473 return create_(
this, m_farrays, name,
485 auto found = m_arraysf.find( name ) ;
486 if( m_arraysf.end() != found ) {
return found->second.get() ; }
487 return create_(
this, m_arraysf, name,
489 {
return this->tuple()->
addItem(n,rows,i); });
501 auto found = m_fmatrices.find( name ) ;
502 if( m_fmatrices.end() != found ) {
return found->second.get() ; }
503 return create_(
this, m_fmatrices, name,
517 auto found = m_matricesf.find( name ) ;
518 if( m_matricesf.end() != found ) {
return found->second.get() ; }
519 return create_(
this, m_matricesf, name,
521 {
return this->tuple()->
addItem(n,rows,cols,i); });
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)
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(...)".
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.
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.
TupleObj()=delete
delete the default/copy constructor and assignment
std::map< std::string, long > m_map
bool isFailure() const
Test for a status code of FAILURE.
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 ")
bool addItem(std::string name, std::string type)
add the item name into the list of known items
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.
T find_first_of(T...args)
StatusCode write()
write a record to NTuple
unsigned int CLID
Class ID definition.
Abstract base class which allows the user to interact with the actual N tuple implementation.
virtual ~TupleObj()
destructor is protected
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
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)
General namespace for Tuple properties.