ATLAS Offline Software
Loading...
Searching...
No Matches
CxxUtils Namespace Reference

Namespaces

namespace  detail
namespace  fpcompare
namespace  fpcompare_fn
namespace  vecDetail

Classes

class  Array
 Read-only multidimensional array. More...
class  Array< 0 >
 Read-only multidimensional array, specialized for N=0. More...
class  ArrayIterator
 Iterator class for Array<N>. More...
class  ArrayIteratorChooser
 Helper for defining iterators over Array's. More...
class  ArrayIteratorChooser< 1 >
 Helper for defining iterators over Array's, specialized for N == 1. More...
class  Arrayrep
 Representation class for Array's. More...
class  ArrayScanner
 Helper class for converting strings to Array's. More...
class  BitPacker
 Pack a set of values bitwise into a stream. More...
class  BitPacker16
 Pack a set of values bitwise into a stream. More...
class  BitPacker8
 Pack a set of values bitwise into a stream. More...
class  BitUnpacker
 Helper to unpack a set of values bitwise from a stream. More...
class  BitUnpacker16
 Helper to unpack a set of values bitwise from a stream. More...
class  BitUnpacker8
 Helper to unpack a set of values bitwise from a stream. More...
union  CachedPointer
 Cached pointer with atomic update. More...
class  CachedUniquePtrT
 Cached pointer with atomic update. More...
class  CachedValue
 Cached value with atomic update. More...
class  ClassName
 Recursively separate out template arguments in a C++ class name. More...
class  CMurmurHash2A
class  ConcurrentBitset
 Variable-sized bitset allowing (mostly) concurrent access. More...
class  ConcurrentMap
 Hash map from integers/pointers allowing concurrent, lockless reads. More...
class  ConcurrentPtrSet
 A set of pointers, allowing concurrent, lockless queries. More...
class  ConcurrentRangeMap
 Map from range to payload object, allowing concurrent, lockless reads. More...
class  ConcurrentStrMap
 Hash map from strings allowing concurrent, lockless reads. More...
class  ConcurrentStrToValMap
 Hash map from strings to arbitrary objects allowing concurrent, lockless reads. More...
class  ConcurrentToValMap
 Hash map from pointers/integers to arbitrary objects allowing concurrent, lockless reads. More...
class  CRCTable
 Precomputed tables and constants for the CRC calculation. More...
struct  extrace_init
class  FloatCompressor
 Class implementing a lossy float compression. More...
class  FloatPacker
 Pack/unpack floating-point data from/to a given number of bits. More...
class  IRangeMapPayloadDeleter
 Helper to delete payload objects for ConcurrentRangeMap. More...
class  iterator_range
 Simple range from a pair of iterators. More...
class  LockedPointer
 A pointer together with a movable lock. More...
class  PackedArray
 An array of unsigned values of some bit size, packed tightly. More...
class  pointer_list
 A fast way to store a variable-sized collection of pointers. More...
class  pointer_list_base
 A fast way to store a variable-sized collection of pointers. More...
class  range_with_at
 Add at() methods to a range class. More...
class  range_with_conv
 Add to a range class conversions to containers. More...
class  RedirStderr
class  RefCountedPtr
 Simple smart pointer for Gaudi-style refcounted objects. More...
class  releasing_iterator
 Adapter to retrieve elements from a unique_ptr iterator via release(). More...
class  reverse_wrapper
 Adapter for a container-like class to be used in a range-for so as to iterate in the reverse direction. More...
class  Ring
 A very simple ring buffer. More...
class  SimpleUpdater
 Simple (non-deleting) Updater implementation. More...
struct  sincos
 Helper to simultaneously calculate sin and cos of the same angle. More...
class  span
 Simplified version of the C++20 std::span. More...
struct  vec_fb
class  WritableArray
 Read-write multidimensional array. More...
class  WritableArray< 0 >
class  WritableArrayData

Typedefs

template<class T, size_t Alignment = 1>
using aligned_vector = std::vector<T, boost::alignment::aligned_allocator<T, Alignment> >
 A std::vector with extra alignment.
template<class T>
using vec_aligned_vector = aligned_vector<T, 64>
 A std::vector with alignment sufficient for any vector instructions on this platform.
template<class T>
using CachedUniquePtr = CachedUniquePtrT<const T>
template<std::ranges::input_range SPAN, class XFORM>
using transform_view_with_at
 Helper to add at() methods to a transform_view.
template<typename T, size_t N>
using vec = typename vecDetail::vec_typedef<T,N>::type
 Define a nice alias for the vectorized type.
template<class VEC>
using vec_type_t = typename vecDetail::vec_type<VEC>::type
 Define a nice alias for the element type of a vectorized type.
template<class VEC>
using vec_mask_type_t = typename vecDetail::vec_mask_type<VEC>::type
 Define a nice alias for the mask type for a vectorized type.
template<typename T, size_t N>
using ivec = vec_fb<typename boost::int_t<sizeof(T) * 8>::exact, N>
typedef float Arrayelt
 The type of an element of an Array.

Enumerations

enum  CacheState : unsigned char { INVALID = 0 , UPDATING = 1 , VALID = 2 }
 State of the cached value; see below. More...
enum  { CacheLineSize = 64 }
 While it is possible to determine cache line size at run time (e.g. More...

Functions

template<unsigned int N>
std::ostream & operator<< (std::ostream &s, const Array< N > &a)
template<class T>
requires std::assignable_from<T&, float>
void fromArrayrep (const CaloRec::Arrayrep &rep, T &x)
 Helper to convert from an @x Arrayrep to a scalar type.
template<unsigned int N>
void fromArrayrep (const CaloRec::Arrayrep &rep, CxxUtils::Array< N > &x)
 Helper to convert from an @x Arrayrep to an Array.
template<class T>
const T * as_const_ptr (const T *p)
 Helper for getting a const version of a pointer.
template<class T>
atomic_bounded_decrement (std::atomic< T > *a, T bound=0, T decr=1, std::memory_order memorder=std::memory_order_seq_cst)
 Atomically decrement a value with a lower bound.
template<class T>
atomic_fetch_max (std::atomic< T > *a, T v, std::memory_order memorder=std::memory_order_seq_cst)
 Atomically calculate maximum.
template<class T>
atomic_fetch_min (std::atomic< T > *a, T v, std::memory_order memorder=std::memory_order_seq_cst)
 Atomically calculate minimum.
std::string base64_encode (const unsigned char *, unsigned int)
std::vector< unsigned char > base64_decode (const std::string &)
template<class E>
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set (E &lhs, E rhs)
 Convenience function to set bits in a class enum bitmask.
template<class E>
constexpr std::enable_if_t< is_bitmask_v< E >, E & > reset (E &lhs, E rhs)
 Convenience function to clear bits in a class enum bitmask.
template<class E>
constexpr std::enable_if_t< is_bitmask_v< E >, bool > test (E lhs, E rhs)
 Convenience function to test bits in a class enum bitmask.
template<std::integral T>
constexpr T byteswap (T value) noexcept
 Reverse the bytes in n.
template<typename T>
bool close_to_zero (T value, T eps=std::numeric_limits< T >::epsilon())
template<class InputIterator, class OutputIterator, class InputTag, class OutputTag>
OutputIterator copy_bounded1 (InputIterator begi, InputIterator endi, OutputIterator bego, OutputIterator endo, const InputTag &, const OutputTag &)
 Copy a range with bounds restriction; generic version.
template<class InputIterator, class OutputIterator>
OutputIterator copy_bounded1 (InputIterator begi, InputIterator endi, OutputIterator bego, OutputIterator endo, const std::random_access_iterator_tag &, const std::random_access_iterator_tag &)
 Copy a range with bounds restriction; random_access_iterator version.
template<std::input_iterator InputIterator, std::output_iterator< typename std::iterator_traits< InputIterator >::value_type > OutputIterator>
OutputIterator copy_bounded (InputIterator begi, InputIterator endi, OutputIterator bego, OutputIterator endo)
 Copy a range with bounds restriction.
template<class InputRange, class OutputRange>
auto copy_bounded (const InputRange &input, OutputRange &output) -> decltype(std::begin(output))
 Copy a range with bounds restriction.
template<class InputRange, class OutputRange>
auto copy_bounded (const InputRange &input, OutputRange &&output) -> decltype(std::begin(output))
 Copy a range with bounds restriction.
void deleteCRCTable (CxxUtils::CRCTable *table)
 Delete a CRCTable object.
std::unique_ptr< CRCTablemakeCRCTable (uint64_t p, uint64_t initial=0xffffffffffffffff)
 Initialize CRC tables and constants.
uint64_t crc64_bytewise (const CRCTable &table, const char *data, size_t data_len)
 Find the CRC-64 of a string, using a byte-by-byte algorithm.
uint64_t crc64_bytewise (const char *data, size_t data_len)
 Find the CRC-64 of a string, using a byte-by-byte algorithm, with the default CRC.
uint64_t crc64_bytewise (const std::string &s)
 Find the CRC-64 of a string, using a byte-by-byte algorithm, with the default CRC.
uint64_t crc64 (const CRCTable &table, const char *data, size_t data_len)
 Find the CRC-64 of a string,.
uint64_t crc64 (const char *data, size_t data_len)
 Find the CRC-64 of a string, with the default CRC.
uint64_t crc64 (const std::string &s)
 Find the CRC-64 of a string, using the default polynomial.
uint64_t crc64addint (uint64_t crc, uint64_t x)
 Extend a previously-calculated CRC to include an int.
std::string crc64format (uint64_t crc)
 Format a CRC-64 as a string.
std::string crc64digest (const std::string &str)
 Return a CRC-64 digest of a string.
void exctrace (const std::exception &e, IOFD fd=IOFD_INVALID)
 Print out information for the last exception.
uint16_t le16toh (uint16_t x)
uint32_t le32toh (uint32_t x)
uint64_t le64toh (uint64_t x)
uint16_t get_unaligned16 (const uint8_t *ATH_RESTRICT &p)
 Read a 2-byte little-endian value from a possibly unaligned pointer.
uint32_t get_unaligned32 (const uint8_t *ATH_RESTRICT &p)
 Read a 4-byte little-endian value from a possibly unaligned pointer.
uint64_t get_unaligned64 (const uint8_t *ATH_RESTRICT &p)
 Read an 8-byte little-endian value from a possibly unaligned pointer.
float get_unaligned_float (const uint8_t *ATH_RESTRICT &p)
 Read a little-endian float value from a possibly unaligned pointer.
double get_unaligned_double (const uint8_t *ATH_RESTRICT &p)
 Read a little-endian double value from a possibly unaligned pointer.
template<class T>
get_unaligned (const uint8_t *ATH_RESTRICT &p)
 Define templated versions of the above functions.
template<>
uint8_t get_unaligned< uint8_t > (const uint8_t *ATH_RESTRICT &p)
template<>
uint16_t get_unaligned< uint16_t > (const uint8_t *ATH_RESTRICT &p)
template<>
uint32_t get_unaligned< uint32_t > (const uint8_t *ATH_RESTRICT &p)
template<>
uint64_t get_unaligned< uint64_t > (const uint8_t *ATH_RESTRICT &p)
template<>
float get_unaligned< float > (const uint8_t *ATH_RESTRICT &p)
template<>
double get_unaligned< double > (const uint8_t *ATH_RESTRICT &p)
template<>
int8_t get_unaligned< int8_t > (const uint8_t *ATH_RESTRICT &p)
template<>
int16_t get_unaligned< int16_t > (const uint8_t *ATH_RESTRICT &p)
template<>
int32_t get_unaligned< int32_t > (const uint8_t *ATH_RESTRICT &p)
template<>
int64_t get_unaligned< int64_t > (const uint8_t *ATH_RESTRICT &p)
void hexdump (std::ostream &s, const void *addr, size_t n, size_t offset=0)
 Make a hex dump of memory.
void safeHexdump (std::ostream &s, const void *addr, size_t n, size_t offset=0)
 Make a hex dump of memory, protected against bad reads.
template<class RANGE, class FUNC>
auto min_transformed_element (RANGE &&r, FUNC &&f)
 Find the minimum transformed element in a range.
template<class RANGE, class FUNC>
auto max_transformed_element (RANGE &&r, FUNC &&f)
 Find the maximum transformed element in a range.
uint32_t MurmurHash2 (const void *key, int len, uint32_t seed)
uint64_t MurmurHash64A (const void *key, int len, uint64_t seed)
uint64_t MurmurHash64B (const void *key, int len, uint64_t seed)
uint32_t MurmurHash2A (const void *key, int len, uint32_t seed)
uint32_t MurmurHashNeutral2 (const void *key, int len, uint32_t seed)
uint32_t MurmurHashAligned2 (const void *key, int len, uint32_t seed)
std::string normalizeFunctionName (const std::string &fname)
 Normalize a pretty-printed C++ function name.
template<class T>
constexpr T ones (unsigned int n)
 Return a bit mask with the lower n bits set.
template<typename T>
wrapToPi (T phi)
 Wrap angle in radians to [-pi, pi].
template<typename T>
deltaPhi (T phiA, T phiB)
 Return difference phiA - phiB in range [-pi, pi].
template<typename T>
phiMean (T phiA, T phiB)
 Calculate average of two angles.
template<typename T>
phiBisect (T phiA, T phiB)
 Bisect (average) the angle spanned by phiA and phiB.
void prefetchOne (const void *address)
 Generic prefetch method.
template<size_t N>
void prefetchN (const void *ptr)
 Prefetch an N-byte block of memory.
template<typename T>
void prefetchObj (const T *ptr)
 Generic prefetch of the object of specific types (sizes).
template<typename Iter>
void prefetchNext (Iter iter, Iter endIter)
 Prefetch next object in sequence.
template<typename Iter>
void prefetchTwo (Iter iter, Iter endIter)
 Prefetch two objects.
template<class T>
auto begin (range_with_at< T > &s)
template<class T>
auto begin (const range_with_at< T > &s)
template<class T>
auto end (range_with_at< T > &s)
template<class T>
auto end (const range_with_at< T > &s)
template<class T>
auto begin (range_with_conv< T > &s)
template<class T>
auto begin (const range_with_conv< T > &s)
template<class T>
auto end (range_with_conv< T > &s)
template<class T>
auto end (const range_with_conv< T > &s)
template<class CONT, class RANGE>
CONT to (RANGE &&r)
template<class T>
auto make_reverse_wrapper (T &r)
 Make a reverse_wrapper for a given container-like object.
uint16_t htole16 (uint16_t x)
uint32_t htole32 (uint32_t x)
uint64_t htole64 (uint64_t x)
void set_unaligned16 (uint8_t *ATH_RESTRICT &p, uint16_t val)
 Write a 2-byte little-endian value to a possibly unaligned pointer.
void set_unaligned32 (uint8_t *ATH_RESTRICT &p, uint32_t val)
 Write a 4-byte little-endian value to a possibly unaligned pointer.
void set_unaligned64 (uint8_t *ATH_RESTRICT &p, uint64_t val)
 Write an 8-byte little-endian value to a possibly unaligned pointer.
void set_unaligned_float (uint8_t *ATH_RESTRICT &p, float val)
 Write a little-endian float value to a possibly unaligned pointer.
void set_unaligned_double (uint8_t *ATH_RESTRICT &p, double val)
 Write a little-endian double value to a possibly unaligned pointer.
template<class T>
void set_unaligned (uint8_t *ATH_RESTRICT &p, T val)
 Define templated versions of the above functions.
template<>
void set_unaligned< uint8_t > (uint8_t *ATH_RESTRICT &p, uint8_t val)
template<>
void set_unaligned< uint16_t > (uint8_t *ATH_RESTRICT &p, uint16_t val)
template<>
void set_unaligned< uint32_t > (uint8_t *ATH_RESTRICT &p, uint32_t val)
template<>
void set_unaligned< uint64_t > (uint8_t *ATH_RESTRICT &p, uint64_t val)
template<>
void set_unaligned< float > (uint8_t *ATH_RESTRICT &p, float f)
template<>
void set_unaligned< double > (uint8_t *ATH_RESTRICT &p, double f)
template<>
void set_unaligned< int8_t > (uint8_t *ATH_RESTRICT &p, int8_t val)
template<>
void set_unaligned< int16_t > (uint8_t *ATH_RESTRICT &p, int16_t val)
template<>
void set_unaligned< int32_t > (uint8_t *ATH_RESTRICT &p, int32_t val)
template<>
void set_unaligned< int64_t > (uint8_t *ATH_RESTRICT &p, int64_t val)
template<class T>
 span (T *ptr, std::size_t sz) -> span< T >
 A couple needed deduction guides.
template<class T>
 span (T *beg, T *end) -> span< T >
template<detail::IsContiguousContainer CONTAINER>
auto make_span (CONTAINER &c)
 Helper to make a span from a container.
template<class T>
auto begin (span< T > &s)
template<class T>
auto begin (const span< T > &s)
template<class T>
auto end (span< T > &s)
template<class T>
auto end (const span< T > &s)
void stall ()
 Emit stall instruction for use in a spin loop.
std::string strformat (const char *fmt,...)
 return a std::string according to a format fmt and varargs
int atoi (std::string_view str)
 Helper functions to unpack numbers decoded in string into integers and doubles The strings are required to contain only digits, a floating point dot, the signs +- or a whitespace Exceptions are thrown otherwise.
double atof (std::string_view str)
 Converts a string into a double / float.
std::string_view eraseWhiteSpaces (std::string_view str)
 Removes all trailing and starting whitespaces from a string.
std::vector< std::string > tokenize (const std::string &the_str, std::string_view delimiters)
 Splits the string into smaller substrings.
std::vector< double > tokenizeDouble (const std::string &the_str, std::string_view delimiter)
std::vector< int > tokenizeInt (const std::string &the_str, std::string_view delimiter)
void throw_out_of_range (const std::string &what, size_t index, size_t size, const void *obj)
 Throw an out_of_range exception.
void throw_out_of_range (const char *what, size_t index, size_t size, const void *obj)
 Throw an out_of_range exception.
void ubsan_suppress (void(*func)())
 Helper for suppressing ubsan warnings.
template<class VEC>
ATH_ALWAYS_INLINE constexpr size_t vec_size ()
 Return the number of elements in a vectorized type.
template<class VEC>
ATH_ALWAYS_INLINE constexpr size_t vec_size (const VEC &)
 Return the number of elements in a vectorized type.
template<typename VEC, typename T>
ATH_ALWAYS_INLINE void vbroadcast (VEC &v, T x)
 Copy a scalar to each element of a vectorized type.
template<typename VEC>
ATH_ALWAYS_INLINE void vload (VEC &dst, vec_type_t< VEC > const *src)
template<typename VEC>
ATH_ALWAYS_INLINE void vstore (vec_type_t< VEC > *dst, const VEC &src)
template<typename VEC>
ATH_ALWAYS_INLINE void vselect (VEC &dst, const VEC &a, const VEC &b, const vec_mask_type_t< VEC > &mask)
template<typename VEC>
ATH_ALWAYS_INLINE void vmin (VEC &dst, const VEC &a, const VEC &b)
template<typename VEC>
ATH_ALWAYS_INLINE void vmax (VEC &dst, const VEC &a, const VEC &b)
template<typename VEC>
ATH_ALWAYS_INLINE bool vany (const VEC &mask)
template<typename VEC>
ATH_ALWAYS_INLINE bool vnone (const VEC &mask)
template<typename VEC>
ATH_ALWAYS_INLINE bool vall (const VEC &mask)
template<typename VEC1, typename VEC2>
ATH_ALWAYS_INLINE void vconvert (VEC1 &dst, const VEC2 &src)
 performs dst is the result of a static cast of each element of src
template<size_t... Indices, typename VEC, typename VEC1>
ATH_ALWAYS_INLINE void vpermute (VEC1 &dst, const VEC &src)
 vpermute function.
template<size_t... Indices, typename VEC, typename VEC1>
ATH_ALWAYS_INLINE void vpermute2 (VEC1 &dst, const VEC &src1, const VEC &src2)
 vpermute2 function.
template<typename T, size_t N>
ivec< T, N > operator! (const vec_fb< T, N > &a)
 Negation.
template<typename T, size_t N>
ivec< T, N > operator&& (const vec_fb< T, N > &a, const vec_fb< T, N > &b)
 V1 && V2.
template<typename T, size_t N, class U>
ivec< T, N > operator&& (U a, const vec_fb< T, N > &b)
 S && V.
template<typename T, size_t N, class U>
ivec< T, N > operator&& (const vec_fb< T, N > &a, U b)
 V && S.
template<typename T, size_t N>
ivec< T, N > operator|| (const vec_fb< T, N > &a, const vec_fb< T, N > &b)
 V1 || V2.
void * xmalloc (size_t size)
 Trapping version of malloc.
std::string clean_allocator (std::string f)
 Clean ‘allocator’ template arguments from the function f.
std::string munge_string_name (const std::string &str_in)
std::string munge_punct (const std::string &str_in)
std::string do_replace (std::string s, const std::string &pat, const std::string &rep)
std::string munge_names (const std::string &str_in)
template<class dType>
void convertToNumber (std::string_view str, dType &number)

Variables

constexpr size_t dynamic_extent = static_cast<size_t>(-1)
 Used to specify a subrange of indefinite size in subspan().
template<class T, class U>
constexpr bool valid_span_type_v = std::is_convertible_v<U(*)[], T(*)[]>
 Is U* a valid type to use to initialize a span<T>?
const CRCTable defaultCRCTable (0xad93d23594c935a9)

Typedef Documentation

◆ aligned_vector

template<class T, size_t Alignment = 1>
using CxxUtils::aligned_vector = std::vector<T, boost::alignment::aligned_allocator<T, Alignment> >

A std::vector with extra alignment.

The alignment for the payload will be at least either that required by T or Alignment, whichever is greater.

Definition at line 39 of file aligned_vector.h.

◆ Arrayelt

typedef float CaloRec::Arrayelt

The type of an element of an Array.

Definition at line 26 of file Control/CxxUtils/CxxUtils/Arrayrep.h.

◆ CachedUniquePtr

template<class T>
using CxxUtils::CachedUniquePtr = CachedUniquePtrT<const T>

Definition at line 114 of file CachedUniquePtr.h.

◆ ivec

template<typename T, size_t N>
using CxxUtils::ivec = vec_fb<typename boost::int_t<sizeof(T) * 8>::exact, N>

Definition at line 53 of file vec_fb.h.

◆ transform_view_with_at

template<std::ranges::input_range SPAN, class XFORM>
using CxxUtils::transform_view_with_at
Initial value:

Helper to add at() methods to a transform_view.

Definition at line 58 of file range_with_at.h.

◆ vec

template<typename T, size_t N>
using CxxUtils::vec = typename vecDetail::vec_typedef<T,N>::type

Define a nice alias for the vectorized type.

Definition at line 207 of file vec.h.

◆ vec_aligned_vector

template<class T>
using CxxUtils::vec_aligned_vector = aligned_vector<T, 64>

A std::vector with alignment sufficient for any vector instructions on this platform.

For now, just hard code 64, which is sufficient for a 512-bit vector, the largest supported by any x86 processors. We may want to make this platform-dependent in the future.

Definition at line 51 of file aligned_vector.h.

◆ vec_mask_type_t

template<class VEC>
using CxxUtils::vec_mask_type_t = typename vecDetail::vec_mask_type<VEC>::type

Define a nice alias for the mask type for a vectorized type.

Definition at line 219 of file vec.h.

◆ vec_type_t

template<class VEC>
using CxxUtils::vec_type_t = typename vecDetail::vec_type<VEC>::type

Define a nice alias for the element type of a vectorized type.

Definition at line 213 of file vec.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

While it is possible to determine cache line size at run time (e.g.

using sysconf(_SC_LEVEL1_DCACHE_LINESIZE) on Linux or sysctlbyname("hw.cachelinesize", ...) on Apple systems) that approach creates more problems: the location that stores cache line size will probably be out of cache when one needs to know it. This is why we use a compile time constant for cache line size. Cache line size is 64 for the current generation of Intel/AMD CPUs.

If an object spans multiple cache lines then prefetching whole object should be done by prefetching at least one address from each of the cache lines that object occupies. How many lines are needed depends on three things: object size, cache line size, and object starting address. If CacheLineSize is lower than the actual line size then more prefetches than necessary will be generated (2, 4, or more per cache line if cache line size is power of 2). This may be somewhat wasteful so this number may need to be adjusted in the far future when all CPUs have wider cache lines.

Enumerator
CacheLineSize 

Definition at line 59 of file prefetch.h.

59{ CacheLineSize = 64 };
@ CacheLineSize
Definition prefetch.h:59

◆ CacheState

enum CxxUtils::CacheState : unsigned char

State of the cached value; see below.

Enumerator
INVALID 
UPDATING 
VALID 

Definition at line 27 of file CachedValue.h.

27 : unsigned char {
28 INVALID = 0,
29 UPDATING = 1,
30 VALID = 2
31};

Function Documentation

◆ as_const_ptr()

template<class T>
const T * CxxUtils::as_const_ptr ( const T * p)
inline

Helper for getting a const version of a pointer.

Parameters
pPointer to convert.

Given T* p, as_const_ptr(p) will return p as a const T*.

This is similar in spirit to std::as_const (which doesn't really do what you might expect for pointers).

Definition at line 32 of file as_const_ptr.h.

33{
34 return p;
35}

◆ atof()

double CxxUtils::atof ( std::string_view str)

Converts a string into a double / float.

Definition at line 91 of file Control/CxxUtils/Root/StringUtils.cxx.

91 {
92 double result{std::numeric_limits<double>::max()};
94 return result;
95 }
void convertToNumber(std::string_view str, dType &number)

◆ atoi()

int CxxUtils::atoi ( std::string_view str)

Helper functions to unpack numbers decoded in string into integers and doubles The strings are required to contain only digits, a floating point dot, the signs +- or a whitespace Exceptions are thrown otherwise.

Converts a string into an integer

Definition at line 85 of file Control/CxxUtils/Root/StringUtils.cxx.

85 {
86 int result{std::numeric_limits<int>::max()};
88 return result;
89 }

◆ atomic_bounded_decrement()

template<class T>
T CxxUtils::atomic_bounded_decrement ( std::atomic< T > * a,
T bound = 0,
T decr = 1,
std::memory_order memorder = std::memory_order_seq_cst )
inline

Atomically decrement a value with a lower bound.

Parameters
aPointer to the atomic value.
boundLower bound for a.
decrThe amount by which to decrement.
memorderMemory ordering.

Atomically decrement A by DECR, provided the result is not less than BOUND. I.e., the atomic equivalent of:

if (a >= bound + decr) a -= decr;
TList * a

Returns in any case the original value of the atomic variable.

Definition at line 41 of file atomic_bounded_decrement.h.

43{
44 T orig = a->load (memorder);
45 // Be careful with the comparison here --- it needs to work for
46 // unsigned values, so we don't want to subtract decr from orig.
47 while (orig >= bound + decr &&
48 !a->compare_exchange_strong (orig, orig - decr, memorder)) {
50 }
51 return orig;
52}
void stall()
Emit stall instruction for use in a spin loop.
Definition stall.h:37

◆ atomic_fetch_max()

template<class T>
T CxxUtils::atomic_fetch_max ( std::atomic< T > * a,
T v,
std::memory_order memorder = std::memory_order_seq_cst )
inline

Atomically calculate maximum.

Parameters
aPointer to the atomic value.
vThe other value.
memorderMemory ordering.

Computes max(*a, v) and stores it in *a. Returns the original value of *a.

Definition at line 42 of file atomic_fetch_minmax.h.

44{
45 T orig = a->load (memorder);
46 while (v > orig && !a->compare_exchange_strong (orig, v, memorder)) {
48 }
49 return orig;
50}

◆ atomic_fetch_min()

template<class T>
T CxxUtils::atomic_fetch_min ( std::atomic< T > * a,
T v,
std::memory_order memorder = std::memory_order_seq_cst )
inline

Atomically calculate minimum.

Parameters
aPointer to the atomic value.
vThe other value.
memorderMemory ordering.

Computes min(*a, v) and stores it in *a. Returns the original value of *a.

Definition at line 63 of file atomic_fetch_minmax.h.

65{
66 T orig = a->load (memorder);
67 while (v < orig && !a->compare_exchange_strong (orig, v, memorder)) {
69 }
70 return orig;
71}

◆ base64_decode()

std::vector< unsigned char > CxxUtils::base64_decode ( const std::string & encoded_string)

Definition at line 97 of file base64.cxx.

97 {
98 int in_len = encoded_string.size();
99 int i = 0;
100 int j = 0;
101 int in_ = 0;
102 unsigned char char_array_4[4], char_array_3[3];
103 std::vector<unsigned char> ret;
104
105 while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
106 char_array_4[i++] = encoded_string[in_]; in_++;
107 if (i ==4) {
108 for (i = 0; i <4; i++)
109 char_array_4[i] = base64_chars.find(char_array_4[i]);
110
111 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
112 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
113 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
114
115 for (i = 0; (i < 3); i++)
116 ret.push_back(char_array_3[i]);
117 i = 0;
118 }
119 }
120
121 if (i) {
122 for (j = i; j <4; j++)
123 char_array_4[j] = 0;
124
125 for (j = 0; j <4; j++)
126 char_array_4[j] = base64_chars.find(char_array_4[j]);
127
128 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
129 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
130 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
131
132 for (j = 0; (j < i - 1); j++) ret.push_back(char_array_3[j]);
133 }
134
135 return ret;
136}

◆ base64_encode()

std::string CxxUtils::base64_encode ( const unsigned char * bytes_to_encode,
unsigned int in_len )

Definition at line 55 of file base64.cxx.

55 {
56 std::string ret;
57 int i = 0;
58 int j = 0;
59 unsigned char char_array_3[3];
60 unsigned char char_array_4[4];
61
62 while (in_len--) {
63 char_array_3[i++] = *(bytes_to_encode++);
64 if (i == 3) {
65 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
66 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
67 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
68 char_array_4[3] = char_array_3[2] & 0x3f;
69
70 for(i = 0; (i <4) ; i++)
71 ret += base64_chars[char_array_4[i]];
72 i = 0;
73 }
74 }
75
76 if (i)
77 {
78 for(j = i; j < 3; j++)
79 char_array_3[j] = '\0';
80
81 char_array_4[0] = ( char_array_3[0] & 0xfc) >> 2;
82 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
83 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
84
85 for (j = 0; (j < i + 1); j++)
86 ret += base64_chars[char_array_4[j]];
87
88 while((i++ < 3))
89 ret += '=';
90
91 }
92
93 return ret;
94
95}

◆ begin() [1/6]

template<class T>
auto CxxUtils::begin ( const range_with_at< T > & s)

Definition at line 67 of file range_with_at.h.

67{ return s.begin(); }

◆ begin() [2/6]

template<class T>
auto CxxUtils::begin ( const range_with_conv< T > & s)

Definition at line 61 of file range_with_conv.h.

61{ return s.begin(); }

◆ begin() [3/6]

template<class T>
auto CxxUtils::begin ( const span< T > & s)

Definition at line 330 of file span.h.

330{ return s.begin(); }

◆ begin() [4/6]

template<class T>
auto CxxUtils::begin ( range_with_at< T > & s)

Definition at line 65 of file range_with_at.h.

65{ return s.begin(); }

◆ begin() [5/6]

template<class T>
auto CxxUtils::begin ( range_with_conv< T > & s)

Definition at line 59 of file range_with_conv.h.

59{ return s.begin(); }

◆ begin() [6/6]

template<class T>
auto CxxUtils::begin ( span< T > & s)

Definition at line 328 of file span.h.

328{ return s.begin(); }

◆ byteswap()

template<std::integral T>
T CxxUtils::byteswap ( T value)
constexprnoexcept

Reverse the bytes in n.

Copied from the example implementation given in https://en.cppreference.com/w/cpp/numeric/byteswap

Definition at line 42 of file byteswap.h.

43{
44 static_assert(std::has_unique_object_representations_v<T>,
45 "T may not have padding bits");
46 auto value_representation = std::bit_cast<std::array<std::byte, sizeof(T)>>(value);
47 std::ranges::reverse(value_representation);
48 return std::bit_cast<T>(value_representation);
49}

◆ clean_allocator()

std::string CxxUtils::clean_allocator ( std::string f)

Clean ‘allocator’ template arguments from the function f.

Parameters
fName of the function to clean.

Definition at line 24 of file normalizeFunctionName.cxx.

25{
26 std::string::size_type ipos = 0;
27 while ((ipos = f.find (", std::allocator", ipos)) != std::string::npos) {
28 const char* p = f.c_str() + ipos + 16;
29 while (isspace (*p)) ++p;
30 if (*p == '<') {
31 ++p;
32 int nest = 1;
33 while (nest > 0 && *p) {
34 if (*p == '<')
35 ++nest;
36 else if (*p == '>')
37 --nest;
38 ++p;
39 }
40 if (nest == 0) {
41 if (ipos > 0 && f[ipos-1] != '>') {
42 while (isspace (*p)) ++p;
43 }
44 f.erase (ipos, p-f.c_str()-ipos);
45 p = f.c_str() + ipos;
46 }
47 }
48 ipos = p - f.c_str();
49 }
50 return f;
51}

◆ close_to_zero()

template<typename T>
bool CxxUtils::close_to_zero ( T value,
T eps = std::numeric_limits<T>::epsilon() )
Examples
/build/atnight/localbuilds/nightlies/main--Doxygen/athena/Control/CxxUtils/CxxUtils/close_to_zero.h.

Definition at line 48 of file close_to_zero.h.

48 {
49 if constexpr (std::is_integral_v<T>) {
50 // For integers, only exact zero is invalid
51 return value == 0;
52 } else if constexpr (std::is_floating_point_v<T>) {
53 return std::abs(value) < eps;
54 } else {
55 static_assert(std::is_arithmetic_v<T>, "close_to_zero: Only arithmetic types supported");
56 return false;
57 }
58 }

◆ convertToNumber()

template<class dType>
void CxxUtils::convertToNumber ( std::string_view str,
dType & number )

Allow for trailing & leading white spaces

To avoid infinite recursion because of string like '42 24' check that white spaces have been indeed removed

Definition at line 65 of file Control/CxxUtils/Root/StringUtils.cxx.

65 {
67 if (str.empty()) {
68 number = 0;
69 return;
70 }
71 if (std::find_if(str.begin(), str.end(), [](const char c){ return std::isspace(c);}) != str.end()) {
72 std::string_view spaceFreeStr = eraseWhiteSpaces(str);
74 if (spaceFreeStr.size() != str.size()) {
75 convertToNumber(spaceFreeStr, number);
76 return;
77 }
78 }
79 if (std::from_chars(str.data(), str.data() + str.size(), number).ec != std::errc{}) {
80 std::stringstream err_except{};
81 err_except<<"CxxUtils::convertToNumber() - The string '"<<str<<"'. Contains unallowed chars";
82 throw std::runtime_error(err_except.str());
83 }
84 }
std::string_view eraseWhiteSpaces(std::string_view str)
Removes all trailing and starting whitespaces from a string.
std::string number(const double &d, const std::string &s)
Definition utils.cxx:186

◆ copy_bounded() [1/3]

template<class InputRange, class OutputRange>
auto CxxUtils::copy_bounded ( const InputRange & input,
OutputRange && output ) -> decltype (std::begin(output))
inline

Copy a range with bounds restriction.

Parameters
inputInput range
outputOutput range

copy_bounded written in terms of iterator ranges.

We have this as a distinct overload in order to be able to pass a CxxUtils::span temporary as the second argument.

Definition at line 121 of file copy_bounded.h.

123{
124 return copy_bounded
125 (std::begin(input), std::end(input),
126 std::begin(output), std::end(output));
127}
OutputIterator copy_bounded(InputIterator begi, InputIterator endi, OutputIterator bego, OutputIterator endo)
Copy a range with bounds restriction.

◆ copy_bounded() [2/3]

template<class InputRange, class OutputRange>
auto CxxUtils::copy_bounded ( const InputRange & input,
OutputRange & output ) -> decltype (std::begin(output))
inline

Copy a range with bounds restriction.

Parameters
inputInput range
outputOutput range

copy_bounded written in terms of iterator ranges.

Definition at line 99 of file copy_bounded.h.

101{
102 return copy_bounded
103 (std::begin(input), std::end(input),
104 std::begin(output), std::end(output));
105}

◆ copy_bounded() [3/3]

template<std::input_iterator InputIterator, std::output_iterator< typename std::iterator_traits< InputIterator >::value_type > OutputIterator>
OutputIterator CxxUtils::copy_bounded ( InputIterator begi,
InputIterator endi,
OutputIterator bego,
OutputIterator endo )
inline

Copy a range with bounds restriction.

Parameters
begiStart of input range.
endiEnd of input range.
begoStart of output range.
endoEnd of output range.

Like std::copy(begi, endi, bego), except that it will not copy more than std::distance(bego, endo) elements.

Copies exactly n = std::min (std::distance(begi,endi), std::distance(bego,endo)) elements. Returns bego + n.

Definition at line 79 of file copy_bounded.h.

81{
82 return copy_bounded1
83 (begi, endi, bego, endo,
84 typename std::iterator_traits<InputIterator>::iterator_category(),
85 typename std::iterator_traits<OutputIterator>::iterator_category());
86}
OutputIterator copy_bounded1(InputIterator begi, InputIterator endi, OutputIterator bego, OutputIterator endo, const InputTag &, const OutputTag &)
Copy a range with bounds restriction; generic version.

◆ copy_bounded1() [1/2]

template<class InputIterator, class OutputIterator, class InputTag, class OutputTag>
OutputIterator CxxUtils::copy_bounded1 ( InputIterator begi,
InputIterator endi,
OutputIterator bego,
OutputIterator endo,
const InputTag & ,
const OutputTag &  )
inline

Copy a range with bounds restriction; generic version.

Definition at line 31 of file copy_bounded.h.

35{
36 while (begi != endi && bego != endo) {
37 *bego = *begi;
38 ++begi;
39 ++bego;
40 }
41 return bego;
42}

◆ copy_bounded1() [2/2]

template<class InputIterator, class OutputIterator>
OutputIterator CxxUtils::copy_bounded1 ( InputIterator begi,
InputIterator endi,
OutputIterator bego,
OutputIterator endo,
const std::random_access_iterator_tag & ,
const std::random_access_iterator_tag &  )
inline

Copy a range with bounds restriction; random_access_iterator version.

Definition at line 51 of file copy_bounded.h.

55{
56 size_t n = std::min (endi-begi, endo-bego);
57 return std::copy (begi, begi+n, bego);
58}

◆ crc64() [1/3]

uint64_t CxxUtils::crc64 ( const char * data,
size_t data_len )

Find the CRC-64 of a string, with the default CRC.

Parameters
dataPointer to the string to hash.
data_lenLength of the string to hash, in bytes.

Definition at line 709 of file crc64.cxx.

711{
712 return crc64 (defaultCRCTable, data, data_len);
713}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
uint64_t crc64(const CRCTable &table, const char *data, size_t data_len)
Find the CRC-64 of a string,.
Definition crc64.cxx:696
const CRCTable defaultCRCTable(0xad93d23594c935a9)

◆ crc64() [2/3]

uint64_t CxxUtils::crc64 ( const CRCTable & table,
const char * data,
size_t data_len )

Find the CRC-64 of a string,.

Parameters
tablePrecomputed CRC tables and constants.
dataPointer to the string to hash.
data_lenLength of the string to hash, in bytes.

This is the default implementation, used on platforms without pclmul.

Definition at line 696 of file crc64.cxx.

699{
700 return crc64_bytewise (table, data, data_len);
701}
uint64_t crc64_bytewise(const CRCTable &table, const char *data, size_t data_len)
Find the CRC-64 of a string, using a byte-by-byte algorithm.
Definition crc64.cxx:560

◆ crc64() [3/3]

uint64_t CxxUtils::crc64 ( const std::string & s)

Find the CRC-64 of a string, using the default polynomial.

Parameters
strThe string to hash.

Definition at line 720 of file crc64.cxx.

721{
722 return crc64 (defaultCRCTable, s.data(), s.size());
723}

◆ crc64_bytewise() [1/3]

uint64_t CxxUtils::crc64_bytewise ( const char * data,
size_t data_len )

Find the CRC-64 of a string, using a byte-by-byte algorithm, with the default CRC.

Parameters
tablePrecomputed CRC tables and constants.
dataPointer to the string to hash.
data_lenLength of the string to hash, in bytes.

Definition at line 580 of file crc64.cxx.

582{
583 return crc64_bytewise (defaultCRCTable, data, data_len);
584}

◆ crc64_bytewise() [2/3]

uint64_t CxxUtils::crc64_bytewise ( const CRCTable & table,
const char * data,
size_t data_len )

Find the CRC-64 of a string, using a byte-by-byte algorithm.

Parameters
tablePrecomputed CRC tables and constants.
dataPointer to the string to hash.
data_lenLength of the string to hash, in bytes.

Definition at line 560 of file crc64.cxx.

563{
564 uint64_t crc = table.m_initial;
565 const char* seq = data;
566 const char* end = seq + data_len;
567 while (seq < end)
568 crc = table.m_table[(crc ^ *seq++) & 0xff] ^ (crc >> 8);
569 return crc;
570}
auto end(range_with_at< T > &s)

◆ crc64_bytewise() [3/3]

uint64_t CxxUtils::crc64_bytewise ( const std::string & s)

Find the CRC-64 of a string, using a byte-by-byte algorithm, with the default CRC.

Parameters
tablePrecomputed CRC tables and constants.
sString to hash.

Definition at line 593 of file crc64.cxx.

594{
595 return crc64_bytewise (defaultCRCTable, s.data(), s.size());
596}

◆ crc64addint()

uint64_t CxxUtils::crc64addint ( uint64_t crc,
uint64_t x )

Extend a previously-calculated CRC to include an int.

Parameters
crcThe previously-calculated CRC.
xThe integer to add.
Returns
The new CRC.

Definition at line 732 of file crc64.cxx.

733{
734 while (x > 0) {
735 crc = defaultCRCTable.m_table[(crc ^ x) & 0xff] ^ (crc >> 8);
736 x >>= 8;
737 }
738 return crc;
739}
#define x

◆ crc64digest()

std::string CxxUtils::crc64digest ( const std::string & str)

Return a CRC-64 digest of a string.

Parameters
strThe string to hash.
Returns
The CRC-64 digest of the string. This is the hash code, expressed as hex as a string.

Definition at line 761 of file crc64.cxx.

762{
763 return crc64format (crc64 (str));
764}
std::string crc64format(uint64_t crc)
Format a CRC-64 as a string.
Definition crc64.cxx:746

◆ crc64format()

std::string CxxUtils::crc64format ( uint64_t crc)

Format a CRC-64 as a string.

Parameters
crcThe CRC to format.

Definition at line 746 of file crc64.cxx.

747{
748 char buf[64];
749 sprintf (buf, "%08X%08X",
750 (unsigned)((crc>>32)&0xffffffff), (unsigned)(crc&0xffffffff));
751 return buf;
752}

◆ deleteCRCTable()

void CxxUtils::deleteCRCTable ( CxxUtils::CRCTable * table)

Delete a CRCTable object.

Delete a CRC table object.

Definition at line 535 of file crc64.cxx.

536{
537 delete table;
538}

◆ deltaPhi()

template<typename T>
T CxxUtils::deltaPhi ( T phiA,
T phiB )
inline

Return difference phiA - phiB in range [-pi, pi].

Definition at line 42 of file phihelper.h.

43 {
44 static_assert(std::is_floating_point<T>::value);
45 return wrapToPi(phiA - phiB);
46 }
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition phihelper.h:24

◆ do_replace()

std::string CxxUtils::do_replace ( std::string s,
const std::string & pat,
const std::string & rep )

Definition at line 95 of file normalizeFunctionName.cxx.

98{
99 std::string::size_type ipos = 0;
100 while ((ipos = s.find (pat, ipos)) != std::string::npos)
101 s.replace (ipos, pat.size(), rep);
102 return s;
103}

◆ end() [1/6]

template<class T>
auto CxxUtils::end ( const range_with_at< T > & s)

Definition at line 71 of file range_with_at.h.

71{ return s.end(); }

◆ end() [2/6]

template<class T>
auto CxxUtils::end ( const range_with_conv< T > & s)

Definition at line 65 of file range_with_conv.h.

65{ return s.end(); }

◆ end() [3/6]

template<class T>
auto CxxUtils::end ( const span< T > & s)

Definition at line 334 of file span.h.

334{ return s.end(); }

◆ end() [4/6]

template<class T>
auto CxxUtils::end ( range_with_at< T > & s)

Definition at line 69 of file range_with_at.h.

69{ return s.end(); }

◆ end() [5/6]

template<class T>
auto CxxUtils::end ( range_with_conv< T > & s)

Definition at line 63 of file range_with_conv.h.

63{ return s.end(); }

◆ end() [6/6]

template<class T>
auto CxxUtils::end ( span< T > & s)

Definition at line 332 of file span.h.

332{ return s.end(); }

◆ eraseWhiteSpaces()

std::string_view CxxUtils::eraseWhiteSpaces ( std::string_view str)

Removes all trailing and starting whitespaces from a string.

Definition at line 44 of file Control/CxxUtils/Root/StringUtils.cxx.

44 {
45 if (str.empty()) return str;
46 size_t begin{0}, end{str.size() -1};
47 while (std::isspace(str[begin])){
48 ++begin;
49 }
50 while (end > 0 && std::isspace(str[end])){
51 --end;
52 }
53 return str.substr(begin, end + 1);
54 }
auto begin(range_with_at< T > &s)

◆ exctrace()

void CxxUtils::exctrace ( const std::exception & e,
IOFD fd = IOFD_INVALID )

Print out information for the last exception.

Prints the supplied exception, plus the backtrace from the last exception, if available.

Parameters
eThe exception to print.
fdThe file descriptor to which to write.

Definition at line 59 of file exctrace.cxx.

60{
61 if (fd == IOFD_INVALID)
63
64 typedef int (*get_last_trace_fn) (int max_depth, void* trace[]);
65 get_last_trace_fn get_last_trace = (get_last_trace_fn) dlsym (RTLD_DEFAULT, "exctrace_get_last_trace");
66
67
68 MYWRITELIT(fd, "Exception: ");
69 MYWRITE(fd, e.what(), strlen (e.what()));
70
71 if (get_last_trace) {
72 void* trace[100];
73 int depth = get_last_trace (std::end(trace)-std::begin(trace), trace);
74
75 MYWRITELIT(fd, "\n");
76 // Index 0 is __cxa_throw. Skip it.
77 for (int i = 1; i < depth; ++i) {
78 unsigned long ip =
79 reinterpret_cast<unsigned long> (trace[i]);
80 // A function that throws may have the call to __cxa_throw
81 // as the last instruction in the function. In that case, the IP
82 // we see here will be one beyond the end of the function,
83 // and we'll report the wrong function. So move back the IP
84 // slightly for the function that threw.
85 if (i == 1) --ip;
86
87 // It's true that stacktraceLine is not really thread-safe.
88 // However, if we're here, things are going south fast anyway,
89 // so we'll just cross our fingers and try to shovel out as much
90 // information as we can.
91 [[maybe_unused]]
92 bool dum ATLAS_THREAD_SAFE = stacktraceLine (fd, ip);
93 }
94 }
95 else
96 MYWRITELIT(fd, " (no backtrace available).\n");
97}
#define IOFD_INVALID
Invalid channel descriptor constant.
Definition SealCommon.h:20
#define MYWRITE(fd, data, n)
Definition SealDebug.h:44
#define ATLAS_THREAD_SAFE
static IOFD stacktraceFd(IOFD fd=IOFD_INVALID)
Set and return the file descriptor for stack trace output.
#define MYWRITELIT(fd, str)
Definition exctrace.cxx:35
std::string depth
tag string for intendation
Definition fastadd.cxx:46

◆ fromArrayrep() [1/2]

template<unsigned int N>
void CxxUtils::fromArrayrep ( const CaloRec::Arrayrep & rep,
CxxUtils::Array< N > & x )

Helper to convert from an @x Arrayrep to an Array.

Parameters
repRepresentation object to convert.
x[out]Result of the conversion.

◆ fromArrayrep() [2/2]

template<class T>
requires std::assignable_from<T&, float>
void CxxUtils::fromArrayrep ( const CaloRec::Arrayrep & rep,
T & x )

Helper to convert from an @x Arrayrep to a scalar type.

Parameters
repRepresentation object to convert.
x[out]Result of the conversion.

◆ get_unaligned()

template<class T>
T CxxUtils::get_unaligned ( const uint8_t *ATH_RESTRICT & p)

Define templated versions of the above functions.

◆ get_unaligned16()

uint16_t CxxUtils::get_unaligned16 ( const uint8_t *ATH_RESTRICT & p)
inline

Read a 2-byte little-endian value from a possibly unaligned pointer.

Parameters
pPointer from which to read. Advanced to the next value.

Reads a little-endian value, regardless of the host byte ordering, and advances the pointer. Should not rely on undefined behavior, regardless of the alignment of p.

If used in a loop, you'll get better code with a restricted pointer.

Definition at line 63 of file get_unaligned.h.

64{
65 uint16_t ret;
66 memcpy (&ret, p, sizeof(ret));
67 p += sizeof(ret);
68 return le16toh (ret);
69}
uint16_t le16toh(uint16_t x)

◆ get_unaligned32()

uint32_t CxxUtils::get_unaligned32 ( const uint8_t *ATH_RESTRICT & p)
inline

Read a 4-byte little-endian value from a possibly unaligned pointer.

Parameters
pPointer from which to read. Advanced to the next value.

Reads a little-endian value, regardless of the host byte ordering, and advances the pointer. Should not rely on undefined behavior, regardless of the alignment of p.

If used in a loop, you'll get better code with a restricted pointer.

Definition at line 83 of file get_unaligned.h.

84{
85 uint32_t ret;
86 memcpy (&ret, p, sizeof(ret));
87 p += sizeof(ret);
88 return le32toh (ret);
89}
uint32_t le32toh(uint32_t x)

◆ get_unaligned64()

uint64_t CxxUtils::get_unaligned64 ( const uint8_t *ATH_RESTRICT & p)
inline

Read an 8-byte little-endian value from a possibly unaligned pointer.

Parameters
pPointer from which to read. Advanced to the next value.

Reads a little-endian value, regardless of the host byte ordering, and advances the pointer. Should not rely on undefined behavior, regardless of the alignment of p.

If used in a loop, you'll get better code with a restricted pointer.

Definition at line 103 of file get_unaligned.h.

104{
105 uint64_t ret;
106 memcpy (&ret, p, sizeof(ret));
107 p += sizeof(ret);
108 return le64toh (ret);
109}
uint64_t le64toh(uint64_t x)

◆ get_unaligned< double >()

template<>
double CxxUtils::get_unaligned< double > ( const uint8_t *ATH_RESTRICT & p)
inline

Definition at line 195 of file get_unaligned.h.

196{
197 return get_unaligned_double (p);
198}
double get_unaligned_double(const uint8_t *ATH_RESTRICT &p)
Read a little-endian double value from a possibly unaligned pointer.

◆ get_unaligned< float >()

template<>
float CxxUtils::get_unaligned< float > ( const uint8_t *ATH_RESTRICT & p)
inline

Definition at line 187 of file get_unaligned.h.

188{
189 return get_unaligned_float (p);
190}
float get_unaligned_float(const uint8_t *ATH_RESTRICT &p)
Read a little-endian float value from a possibly unaligned pointer.

◆ get_unaligned< int16_t >()

template<>
int16_t CxxUtils::get_unaligned< int16_t > ( const uint8_t *ATH_RESTRICT & p)
inline

Definition at line 211 of file get_unaligned.h.

212{
213 return get_unaligned<uint16_t> (p);
214}
uint16_t get_unaligned< uint16_t >(const uint8_t *ATH_RESTRICT &p)

◆ get_unaligned< int32_t >()

template<>
int32_t CxxUtils::get_unaligned< int32_t > ( const uint8_t *ATH_RESTRICT & p)
inline

Definition at line 219 of file get_unaligned.h.

220{
221 return get_unaligned<uint32_t> (p);
222}
uint32_t get_unaligned< uint32_t >(const uint8_t *ATH_RESTRICT &p)

◆ get_unaligned< int64_t >()

template<>
int64_t CxxUtils::get_unaligned< int64_t > ( const uint8_t *ATH_RESTRICT & p)
inline

Definition at line 227 of file get_unaligned.h.

228{
229 return get_unaligned<uint64_t> (p);
230}
uint64_t get_unaligned< uint64_t >(const uint8_t *ATH_RESTRICT &p)

◆ get_unaligned< int8_t >()

template<>
int8_t CxxUtils::get_unaligned< int8_t > ( const uint8_t *ATH_RESTRICT & p)
inline

Definition at line 203 of file get_unaligned.h.

204{
205 return get_unaligned<uint8_t> (p);
206}
uint8_t get_unaligned< uint8_t >(const uint8_t *ATH_RESTRICT &p)

◆ get_unaligned< uint16_t >()

template<>
uint16_t CxxUtils::get_unaligned< uint16_t > ( const uint8_t *ATH_RESTRICT & p)
inline

Definition at line 163 of file get_unaligned.h.

164{
165 return get_unaligned16 (p);
166}
uint16_t get_unaligned16(const uint8_t *ATH_RESTRICT &p)
Read a 2-byte little-endian value from a possibly unaligned pointer.

◆ get_unaligned< uint32_t >()

template<>
uint32_t CxxUtils::get_unaligned< uint32_t > ( const uint8_t *ATH_RESTRICT & p)
inline

Definition at line 171 of file get_unaligned.h.

172{
173 return get_unaligned32 (p);
174}
uint32_t get_unaligned32(const uint8_t *ATH_RESTRICT &p)
Read a 4-byte little-endian value from a possibly unaligned pointer.

◆ get_unaligned< uint64_t >()

template<>
uint64_t CxxUtils::get_unaligned< uint64_t > ( const uint8_t *ATH_RESTRICT & p)
inline

Definition at line 179 of file get_unaligned.h.

180{
181 return get_unaligned64 (p);
182}
uint64_t get_unaligned64(const uint8_t *ATH_RESTRICT &p)
Read an 8-byte little-endian value from a possibly unaligned pointer.

◆ get_unaligned< uint8_t >()

template<>
uint8_t CxxUtils::get_unaligned< uint8_t > ( const uint8_t *ATH_RESTRICT & p)
inline

Definition at line 155 of file get_unaligned.h.

156{
157 return *p++;
158}

◆ get_unaligned_double()

double CxxUtils::get_unaligned_double ( const uint8_t *ATH_RESTRICT & p)
inline

Read a little-endian double value from a possibly unaligned pointer.

Parameters
pPointer from which to read. Advanced to the next value.

Reads a little-endian value, regardless of the host byte ordering, and advances the pointer. Should not rely on undefined behavior, regardless of the alignment of p.

If used in a loop, you'll get better code with a restricted pointer.

Definition at line 140 of file get_unaligned.h.

141{
142 return std::bit_cast<double> (get_unaligned64 (p));
143}

◆ get_unaligned_float()

float CxxUtils::get_unaligned_float ( const uint8_t *ATH_RESTRICT & p)
inline

Read a little-endian float value from a possibly unaligned pointer.

Parameters
pPointer from which to read. Advanced to the next value.

Reads a little-endian value, regardless of the host byte ordering, and advances the pointer. Should not rely on undefined behavior, regardless of the alignment of p.

If used in a loop, you'll get better code with a restricted pointer.

Definition at line 123 of file get_unaligned.h.

124{
125 return std::bit_cast<float> (get_unaligned32 (p));
126}

◆ hexdump()

void CxxUtils::hexdump ( std::ostream & s,
const void * addr,
size_t n,
size_t offset = 0 )

Make a hex dump of memory.

Parameters
sStream to which to write the output.
addrAddress at which to start dumping.
nNumber of byte to dump.
offsetOffset by which to shift the printed address (mostly for testing).

Definition at line 37 of file hexdump.cxx.

38{
39 const char* ptr = reinterpret_cast<const char*> (addr);
40 size_t ipos = 0;
41
42 boost::io::ios_all_saver saver (s);
43 std::hex (s);
44 s.fill ('0');
45
46 char cbuf[width + 1] = {0};
47 union {
48 uint32_t u32;
49 unsigned char uc[4];
50 } bbuf;
51
52 while (n-- > 0) {
53 if ((ipos % width) == 0) {
54 s << std::setw(16) << reinterpret_cast<uintptr_t>(ptr + ipos) - offset << " ";
55 }
56 if ((ipos % 4) == 0) {
57 s << " ";
58 }
59 bbuf.uc[ipos % 4] = ptr[ipos];
60 cbuf[ipos % width] = std::isgraph (ptr[ipos]) ? ptr[ipos] : '.';
61
62 ++ipos;
63 if ((ipos % 4) == 0) {
64 s << std::setw(8) << static_cast<unsigned int>(bbuf.u32);
65 }
66 if ((ipos % width) == 0) {
67 s << " " << cbuf << "\n";
68 }
69 }
70
71 if ((ipos % width) > 0) {
72 unsigned ntrail = (ipos % 4);
73 if (ntrail > 0) {
74 for (unsigned i = ntrail; i < 4; i++) {
75 bbuf.uc[i] = 0;
76 }
77 s << std::setw(2*ntrail) << static_cast<unsigned int>(bbuf.u32);
78 }
79 while ((ipos % width) != 0) {
80 if ((ipos % 4) == 0) {
81 s << " ";
82 }
83 s << " ";
84 cbuf[ipos % width] = ' ';
85 ++ipos;
86 }
87 s << " " << cbuf << "\n";
88 }
89}
const double width
void * ptr(T *p)
Definition SGImplSvc.cxx:74

◆ htole16()

uint16_t CxxUtils::htole16 ( uint16_t x)
inline

Definition at line 42 of file set_unaligned.h.

42{ return x; }

◆ htole32()

uint32_t CxxUtils::htole32 ( uint32_t x)
inline

Definition at line 43 of file set_unaligned.h.

43{ return x; }

◆ htole64()

uint64_t CxxUtils::htole64 ( uint64_t x)
inline

Definition at line 44 of file set_unaligned.h.

44{ return x; }

◆ le16toh()

uint16_t CxxUtils::le16toh ( uint16_t x)
inline

Definition at line 42 of file get_unaligned.h.

42{ return x; }

◆ le32toh()

uint32_t CxxUtils::le32toh ( uint32_t x)
inline

Definition at line 43 of file get_unaligned.h.

43{ return x; }

◆ le64toh()

uint64_t CxxUtils::le64toh ( uint64_t x)
inline

Definition at line 44 of file get_unaligned.h.

44{ return x; }

◆ make_reverse_wrapper()

template<class T>
auto CxxUtils::make_reverse_wrapper ( T & r)

Make a reverse_wrapper for a given container-like object.

Definition at line 46 of file reverse_wrapper.h.

46{ return reverse_wrapper(r); }
Adapter for a container-like class to be used in a range-for so as to iterate in the reverse directio...
int r
Definition globals.cxx:22

◆ make_span()

template<detail::IsContiguousContainer CONTAINER>
auto CxxUtils::make_span ( CONTAINER & c)

Helper to make a span from a container.

Parameters
cThe container for which to make a span. It must have contiguous iterators.

Definition at line 319 of file span.h.

320{
321 return CxxUtils::span (c.data(), c.size());
322}
span(T *ptr, std::size_t sz) -> span< T >
A couple needed deduction guides.

◆ makeCRCTable()

std::unique_ptr< CRCTable > CxxUtils::makeCRCTable ( uint64_t p,
uint64_t initial = 0xffffffffffffffff )

Initialize CRC tables and constants.

Parameters
pPolynomial for the CRC. A 1 in the 2^64 bit is implied.
initialInitial CRC value.

Definition at line 547 of file crc64.cxx.

549{
550 return std::make_unique<CRCTable> (p, initial);
551}

◆ max_transformed_element()

template<class RANGE, class FUNC>
auto CxxUtils::max_transformed_element ( RANGE && r,
FUNC && f )
inline

Find the maximum transformed element in a range.

Parameters
rInput range.
fTransform function.

Evaluates f(x) for each x in r and finds the maximum. Returns a pair (fmax, itmax), where fmax is this maximum value, and itmax is an iterator pointing at the corresponding element in r. If more than one element has the same maximum value, the iterator of the first will be returned.

Precondition: Range r is not empty.

Definition at line 82 of file minmax_transformed_element.h.

83{
84 if (std::ranges::empty (r)) std::abort();
85 auto it = std::ranges::begin(r);
86 auto itmax = it;
87 auto val = f(*it);
88 for (++it; it != std::ranges::end(r); ++it) {
89 auto val2 = f(*it);
90 if (val2 > val) {
91 val = val2;
92 itmax = it;
93 }
94 }
95 return std::make_pair (val, itmax);
96}

◆ min_transformed_element()

template<class RANGE, class FUNC>
auto CxxUtils::min_transformed_element ( RANGE && r,
FUNC && f )
inline

Find the minimum transformed element in a range.

Parameters
rInput range.
fTransform function.

Evaluates f(x) for each x in r and finds the minimum. Returns a pair (fmin, itmin), where fmin is this minimum value, and itmin is an iterator pointing at the corresponding element in r. If more than one element has the same minimum value, the iterator of the first will be returned.

Precondition: Range r is not empty.

Definition at line 50 of file minmax_transformed_element.h.

51{
52 if (std::ranges::empty (r)) std::abort();
53 auto it = std::ranges::begin(r);
54 auto itmin = it;
55 auto val = f(*it);
56 for (++it; it != std::ranges::end(r); ++it) {
57 auto val2 = f(*it);
58 if (val2 < val) {
59 val = val2;
60 itmin = it;
61 }
62 }
63 return std::make_pair (val, itmin);
64}

◆ munge_names()

std::string CxxUtils::munge_names ( const std::string & str_in)

Definition at line 106 of file normalizeFunctionName.cxx.

107{
108 std::string s =
109 do_replace (str_in, "SG::DataProxyStorageData::pointer", "void*");
110 s = do_replace (s, "DPSD::pointer", "void*");
111 s = do_replace (s, "SG::auxid_t", "unsigned long");
112 s = do_replace (s, "auxid_t", "unsigned long");
113 s = do_replace (s, "void* ", "void*");
114 s = do_replace (s, "CLID", "unsigned int");
115
116 if (s.compare (0, 8, "virtual ") == 0)
117 s.erase (0, 8);
118 return s;
119}
std::string do_replace(std::string s, const std::string &pat, const std::string &rep)

◆ munge_punct()

std::string CxxUtils::munge_punct ( const std::string & str_in)

Definition at line 84 of file normalizeFunctionName.cxx.

85{
86 std::string s = str_in;
87 for (size_t i = 0; i < s.size()-1; i++) {
88 if (s[i] == ' ' && (s[i+1] == '*' || s[i+1] == '&'))
89 s.erase (i, 1);
90 }
91 return s;
92}

◆ munge_string_name()

std::string CxxUtils::munge_string_name ( const std::string & str_in)

Definition at line 54 of file normalizeFunctionName.cxx.

55{
56 std::string s = str_in;
57
58 std::string::size_type ipos = 0;
59 while ((ipos = s.find ("std::basic_string<", ipos)) != std::string::npos) {
60 std::string::size_type beg = ipos;
61 ipos += 18;
62 int inest = 1;
63 while (inest > 0 && ipos < s.size()) {
64 if (s[ipos] == '<') ++inest;
65 else if (s[ipos] == '>') --inest;
66 ++ipos;
67 }
68 s.replace (beg, ipos-beg, "std::string");
69 ipos = beg+11;
70 }
71
72 for (size_t i = 0; i < s.size(); i++) {
73 if ((i == 0 || (s[i-1] != ':' && !isalnum(s[i-1]))) &&
74 strncmp (s.c_str()+i, "string", 6) == 0 &&
75 !isalnum(s[i+6]))
76 {
77 s.replace (i, 6, "std::string");
78 }
79 }
80 return s;
81}

◆ MurmurHash2()

uint32_t CxxUtils::MurmurHash2 ( const void * key,
int len,
uint32_t seed )

Definition at line 42 of file MurmurHash2.cxx.

43{
44 // 'm' and 'r' are mixing constants generated offline.
45 // They're not really 'magic', they just happen to work well.
46
47 const uint32_t m = 0x5bd1e995;
48 const int r = 24;
49
50 // Initialize the hash to a 'random' value
51
52 uint32_t h = seed ^ len;
53
54 // Mix 4 bytes at a time into the hash
55
56 const unsigned char * data = (const unsigned char *)key;
57
58 while(len >= 4)
59 {
60 uint32_t k = *reinterpret_cast<const uint32_t*>(data);
61
62 k *= m;
63 k ^= k >> r;
64 k *= m;
65
66 h *= m;
67 h ^= k;
68
69 data += 4;
70 len -= 4;
71 }
72
73 // Handle the last few bytes of the input array
74
75 switch(len)
76 {
77 case 3: h ^= data[2] << 16;
78 // FALLTHROUGH
79 case 2: h ^= data[1] << 8;
80 // FALLTHROUGH
81 case 1: h ^= data[0];
82 h *= m;
83 };
84
85 // Do a few final mixes of the hash to ensure the last few
86 // bytes are well-incorporated.
87
88 h ^= h >> 13;
89 h *= m;
90 h ^= h >> 15;
91
92 return h;
93}
Header file for AthHistogramAlgorithm.

◆ MurmurHash2A()

uint32_t CxxUtils::MurmurHash2A ( const void * key,
int len,
uint32_t seed )

Definition at line 220 of file MurmurHash2.cxx.

221{
222 const uint32_t M = 0x5bd1e995;
223 const int R = 24;
224 uint32_t l = len;
225
226 const unsigned char * data = (const unsigned char *)key;
227
228 uint32_t h = seed;
229
230 while(len >= 4)
231 {
232 uint32_t k = *reinterpret_cast<const uint32_t*>(data);
233
235
236 data += 4;
237 len -= 4;
238 }
239
240 uint32_t t = 0;
241
242 switch(len)
243 {
244 case 3: t ^= data[2] << 16;
245 // FALLTHROUGH
246 case 2: t ^= data[1] << 8;
247 // FALLTHROUGH
248 case 1: t ^= data[0];
249 };
250
251 MurmurHash_mmix(h,t);
252 MurmurHash_mmix(h,l);
253
254 h ^= h >> 13;
255 h *= M;
256 h ^= h >> 15;
257
258 return h;
259}
#define MurmurHash_mmix(h, k)
Definition MurmurHash2.h:29

◆ MurmurHash64A()

uint64_t CxxUtils::MurmurHash64A ( const void * key,
int len,
uint64_t seed )

Definition at line 103 of file MurmurHash2.cxx.

104{
105 const uint64_t m = BIG_CONSTANT(0xc6a4a7935bd1e995);
106 const int r = 47;
107
108 uint64_t h = seed ^ (len * m);
109
110 const uint64_t * data = (const uint64_t *)key;
111 const uint64_t * end = data + (len/8);
112
113 while(data != end)
114 {
115 uint64_t k = *data++;
116
117 k *= m;
118 k ^= k >> r;
119 k *= m;
120
121 h ^= k;
122 h *= m;
123 }
124
125 const unsigned char * data2 = reinterpret_cast<const unsigned char*>(data);
126
127 switch(len & 7)
128 {
129 case 7: h ^= uint64_t(data2[6]) << 48;
130 // FALLTHROUGH
131 case 6: h ^= uint64_t(data2[5]) << 40;
132 // FALLTHROUGH
133 case 5: h ^= uint64_t(data2[4]) << 32;
134 // FALLTHROUGH
135 case 4: h ^= uint64_t(data2[3]) << 24;
136 // FALLTHROUGH
137 case 3: h ^= uint64_t(data2[2]) << 16;
138 // FALLTHROUGH
139 case 2: h ^= uint64_t(data2[1]) << 8;
140 // FALLTHROUGH
141 case 1: h ^= uint64_t(data2[0]);
142 h *= m;
143 };
144
145 h ^= h >> r;
146 h *= m;
147 h ^= h >> r;
148
149 return h;
150}
#define BIG_CONSTANT(x)

◆ MurmurHash64B()

uint64_t CxxUtils::MurmurHash64B ( const void * key,
int len,
uint64_t seed )

Definition at line 155 of file MurmurHash2.cxx.

156{
157 const uint32_t m = 0x5bd1e995;
158 const int r = 24;
159
160 uint32_t h1 = uint32_t(seed) ^ len;
161 uint32_t h2 = uint32_t(seed >> 32);
162
163 const uint32_t * data = (const uint32_t *)key;
164
165 while(len >= 8)
166 {
167 uint32_t k1 = *data++;
168 k1 *= m; k1 ^= k1 >> r; k1 *= m;
169 h1 *= m; h1 ^= k1;
170 len -= 4;
171
172 uint32_t k2 = *data++;
173 k2 *= m; k2 ^= k2 >> r; k2 *= m;
174 h2 *= m; h2 ^= k2;
175 len -= 4;
176 }
177
178 if(len >= 4)
179 {
180 uint32_t k1 = *data++;
181 k1 *= m; k1 ^= k1 >> r; k1 *= m;
182 h1 *= m; h1 ^= k1;
183 len -= 4;
184 }
185
186 switch(len)
187 {
188 case 3: h2 ^= (reinterpret_cast<unsigned const char*>(data))[2] << 16;
189 // FALLTHROUGH
190 case 2: h2 ^= (reinterpret_cast<unsigned const char*>(data))[1] << 8;
191 // FALLTHROUGH
192 case 1: h2 ^= (reinterpret_cast<unsigned const char*>(data))[0];
193 h2 *= m;
194 };
195
196 h1 ^= h2 >> 18; h1 *= m;
197 h2 ^= h1 >> 22; h2 *= m;
198 h1 ^= h2 >> 17; h1 *= m;
199 h2 ^= h1 >> 19; h2 *= m;
200
201 uint64_t h = h1;
202
203 h = (h << 32) | h2;
204
205 return h;
206}

◆ MurmurHashAligned2()

uint32_t CxxUtils::MurmurHashAligned2 ( const void * key,
int len,
uint32_t seed )

Definition at line 324 of file MurmurHash2.cxx.

325{
326 const uint32_t m = 0x5bd1e995;
327 const int r = 24;
328
329 const unsigned char * data = (const unsigned char *)key;
330
331 uint32_t h = seed ^ len;
332
333 int align = (uint64_t)data & 3;
334
335 if(align && (len >= 4))
336 {
337 // Pre-load the temp registers
338
339 uint32_t t = 0, d = 0;
340
341 switch(align)
342 {
343 case 1: t |= data[2] << 16;
344 // FALLTHROUGH
345 case 2: t |= data[1] << 8;
346 // FALLTHROUGH
347 case 3: t |= data[0];
348 }
349
350 t <<= (8 * align);
351
352 data += 4-align;
353 len -= 4-align;
354
355 int sl = 8 * (4-align);
356 int sr = 8 * align;
357
358 // Mix
359
360 while(len >= 4)
361 {
362 d = *reinterpret_cast<const uint32_t *>(data);
363 t = (t >> sr) | (d << sl);
364
365 uint32_t k = t;
366
367 MIX(h,k,m);
368
369 t = d;
370
371 data += 4;
372 len -= 4;
373 }
374
375 // Handle leftover data in temp registers
376
377 d = 0;
378
379 if(len >= align)
380 {
381 switch(align)
382 {
383 case 3: d |= data[2] << 16;
384 // FALLTHROUGH
385 case 2: d |= data[1] << 8;
386 // FALLTHROUGH
387 case 1: d |= data[0];
388 }
389
390 uint32_t k = (t >> sr) | (d << sl);
391 MIX(h,k,m);
392
393 // At this point, we know that len < 4 and align > 0.
394 data += align;
395 len -= align;
396 // So here, we must have 0 >= len < 3.
397
398 //----------
399 // Handle tail bytes
400
401 switch(len)
402 {
403 // can't happen --- see above.
404 //case 3: h ^= data[2] << 16;
405 // FALLTHROUGH
406 case 2: h ^= data[1] << 8;
407 // FALLTHROUGH
408 case 1: h ^= data[0];
409 h *= m;
410 };
411 }
412 else
413 {
414 switch(len)
415 {
416 // len cannot be 3, because align is at most 3.
417 //case 3: d |= data[2] << 16;
418 // FALLTHROUGH
419 case 2: d |= data[1] << 8;
420 // FALLTHROUGH
421 case 1: d |= data[0];
422 // FALLTHROUGH
423 case 0: h ^= (t >> sr) | (d << sl);
424 h *= m;
425 }
426 }
427
428 h ^= h >> 13;
429 h *= m;
430 h ^= h >> 15;
431
432 return h;
433 }
434 else
435 {
436 while(len >= 4)
437 {
438 uint32_t k = *reinterpret_cast<const uint32_t *>(data);
439
440 MIX(h,k,m);
441
442 data += 4;
443 len -= 4;
444 }
445
446 //----------
447 // Handle tail bytes
448
449 switch(len)
450 {
451 case 3: h ^= data[2] << 16;
452 // FALLTHROUGH
453 case 2: h ^= data[1] << 8;
454 // FALLTHROUGH
455 case 1: h ^= data[0];
456 h *= m;
457 };
458
459 h ^= h >> 13;
460 h *= m;
461 h ^= h >> 15;
462
463 return h;
464 }
465}
#define MIX(h, k, m)
setEventNumber uint32_t

◆ MurmurHashNeutral2()

uint32_t CxxUtils::MurmurHashNeutral2 ( const void * key,
int len,
uint32_t seed )

Definition at line 267 of file MurmurHash2.cxx.

268{
269 const uint32_t m = 0x5bd1e995;
270 const int r = 24;
271
272 uint32_t h = seed ^ len;
273
274 const unsigned char * data = (const unsigned char *)key;
275
276 while(len >= 4)
277 {
278 uint32_t k;
279
280 k = data[0];
281 k |= data[1] << 8;
282 k |= data[2] << 16;
283 k |= data[3] << 24;
284
285 k *= m;
286 k ^= k >> r;
287 k *= m;
288
289 h *= m;
290 h ^= k;
291
292 data += 4;
293 len -= 4;
294 }
295
296 switch(len)
297 {
298 case 3: h ^= data[2] << 16;
299 // FALLTHROUGH
300 case 2: h ^= data[1] << 8;
301 // FALLTHROUGH
302 case 1: h ^= data[0];
303 h *= m;
304 };
305
306 h ^= h >> 13;
307 h *= m;
308 h ^= h >> 15;
309
310 return h;
311}

◆ normalizeFunctionName()

std::string CxxUtils::normalizeFunctionName ( const std::string & fname)

Normalize a pretty-printed C++ function name.

Parameters
fnameThe name to normalize.

A C++ compiler can provide a complete printable name of the current function, though for example PRETTY_FUNCTION. This is useful to include in diagnostic messages. However, the exact string generated by different compilers may differ slightly. This can then cause issues if one is trying to compare the output of tests to an expected reference.

This function tries to normalize the function name strings so that they are the same, at least between gcc and clang.

Definition at line 135 of file normalizeFunctionName.cxx.

136{
138}
std::string munge_names(const std::string &str_in)
std::string munge_punct(const std::string &str_in)
std::string clean_allocator(std::string f)
Clean ‘allocator’ template arguments from the function f.
std::string munge_string_name(const std::string &str_in)

◆ ones()

template<class T>
T CxxUtils::ones ( unsigned int n)
inlineconstexpr

Return a bit mask with the lower n bits set.

Definition at line 25 of file ones.h.

26{
27 if (n >= sizeof(T) * 8)
28 return ~static_cast<T>(0);
29 // cppcheck-suppress shiftTooManyBits
30 return (static_cast<T>(1) << n) - 1;
31}

◆ operator!()

template<typename T, size_t N>
ivec< T, N > CxxUtils::operator! ( const vec_fb< T, N > & a)
inline

Negation.

Definition at line 158 of file vec_fb.h.

159{
160 ivec<T, N> c;
161 for (size_t i = 0; i < N; ++i)
162 c.m_arr[i] = a.m_arr[i] == 0;
163 return c;
164}
vec_fb< typename boost::int_t< sizeof(T) *8 >::exact, N > ivec
Definition vec_fb.h:53

◆ operator&&() [1/3]

template<typename T, size_t N>
ivec< T, N > CxxUtils::operator&& ( const vec_fb< T, N > & a,
const vec_fb< T, N > & b )
inline

V1 && V2.

Definition at line 169 of file vec_fb.h.

170{
171 ivec<T, N> c;
172 for (size_t i = 0; i < N; ++i)
173 c.m_arr[i] = (a.m_arr[i] != 0) & (b.m_arr[i] != 0);
174 return c;
175}

◆ operator&&() [2/3]

template<typename T, size_t N, class U>
ivec< T, N > CxxUtils::operator&& ( const vec_fb< T, N > & a,
U b )
inline

V && S.

Definition at line 191 of file vec_fb.h.

192{
193 ivec<T, N> c;
194 for (size_t i = 0; i < N; ++i)
195 c.m_arr[i] = (a.m_arr[i] != 0) & (b ? -1 : 0);
196 return c;
197}

◆ operator&&() [3/3]

template<typename T, size_t N, class U>
ivec< T, N > CxxUtils::operator&& ( U a,
const vec_fb< T, N > & b )
inline

S && V.

Definition at line 180 of file vec_fb.h.

181{
182 ivec<T, N> c;
183 for (size_t i = 0; i < N; ++i)
184 c.m_arr[i] = a ? b.m_arr[i] != 0 : 0;
185 return c;
186}

◆ operator<<()

template<unsigned int N>
std::ostream & CxxUtils::operator<< ( std::ostream & s,
const Array< N > & a )

◆ operator||()

template<typename T, size_t N>
ivec< T, N > CxxUtils::operator|| ( const vec_fb< T, N > & a,
const vec_fb< T, N > & b )
inline

V1 || V2.

Definition at line 202 of file vec_fb.h.

203{
204 ivec<T, N> c;
205 for (size_t i = 0; i < N; ++i)
206 c.m_arr[i] = (a.m_arr[i] != 0) | (b.m_arr[i] != 0);
207 return c;
208}

◆ phiBisect()

template<typename T>
T CxxUtils::phiBisect ( T phiA,
T phiB )
inline

Bisect (average) the angle spanned by phiA and phiB.

The average is calculated by rotating phiA half-way counter-clockwise onto phiB. Note that his method is not symmetric in its arguments. Typical use-cases are to determine the centre of a region in the detector.

The returned value is within the range [-pi, pi].

Definition at line 77 of file phihelper.h.

78 {
79 static_assert(std::is_floating_point<T>::value);
80 T phi = 0.5 * (phiA + phiB);
81 if (phiA > phiB) phi += M_PI;
82 return wrapToPi(phi);
83 }
#define M_PI
Scalar phi() const
phi method

◆ phiMean()

template<typename T>
T CxxUtils::phiMean ( T phiA,
T phiB )
inline

Calculate average of two angles.

The average is calculated as the angle of the sum of the two unit vectors with angles phiA and phiB. As such it always returns the angle in the narrower of the two complimentary regions spanned by phiA and phiB. If the vector sum is zero, return the angle within [-pi/2, pi/2]. This method is symmetric in its arguments except if |mean| equals pi.

The returned value is within the range [-pi, pi].

Definition at line 60 of file phihelper.h.

61 {
62 static_assert(std::is_floating_point<T>::value);
63 const T diff = wrapToPi(phiA - phiB);
64 return wrapToPi(phiB + 0.5 * diff);
65 }
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631

◆ prefetchN()

template<size_t N>
void CxxUtils::prefetchN ( const void * ptr)
inline

Prefetch an N-byte block of memory.

Parameters
[in]ptrStarting address of the block.

Definition at line 85 of file prefetch.h.

86{
87 const char* pp = reinterpret_cast<const char*> (ptr);
88
89 // The compiler will unroll this loop for small N.
90 for (size_t i = 0; i < N; i += CacheLineSize)
91 prefetchOne (pp + i);
92
93 // Issue a prefetch for the last byte as well, in case it crosses
94 // cache lines.
95 prefetchOne (pp + N - 1);
96}
void prefetchOne(const void *address)
Generic prefetch method.
Definition prefetch.h:73

◆ prefetchNext()

template<typename Iter>
void CxxUtils::prefetchNext ( Iter iter,
Iter endIter )
inline

Prefetch next object in sequence.

Parameters
iterCurrent iteration position.
endIterEnd of the sequence.

Iter is a ForwardIterator over pointers.

Prefetches next object in a collection of pointers. Accepts two iterators: the first iterator is the current iteration position, and the second iterator is the end iterator for the whole sequence. The first iterator must not be equal to the end iterator (this is not checked). This increments the iterator and, if not equal to the end, prefetches the complete object referenced by the pointer.

Definition at line 130 of file prefetch.h.

131{
132 if (++iter != endIter)
133 prefetchObj(*iter);
134}
void prefetchObj(const T *ptr)
Generic prefetch of the object of specific types (sizes).
Definition prefetch.h:108

◆ prefetchObj()

template<typename T>
void CxxUtils::prefetchObj ( const T * ptr)
inline

Generic prefetch of the object of specific types (sizes).

Parameters
[in]addressmemory location to prefetch

This method will prefetch as many cache lines as needed to store the object of the specified type in memory. Type is specified as a template argument.

Definition at line 108 of file prefetch.h.

109{
111}
void prefetchN(const void *ptr)
Prefetch an N-byte block of memory.
Definition prefetch.h:85

◆ prefetchOne()

void CxxUtils::prefetchOne ( const void * address)
inline

Generic prefetch method.

Parameters
[in]addressmemory location to prefetch

This is generic method that does not have any extra behavior. It only prefetches the whole cache line which contains the specified memory location. It does not incur any additional overhead and may be the most efficient method for small objects which have a high chance of being on just a single cache line.

Definition at line 73 of file prefetch.h.

74{
76}
#define CXXUTILS_PREFETCH_ADDRESS(ADDR)
Definition prefetch.h:32

◆ prefetchTwo()

template<typename Iter>
void CxxUtils::prefetchTwo ( Iter iter,
Iter endIter )
inline

Prefetch two objects.

Parameters
iterCurrent iteration position.
endIterEnd of the sequence.

Iter is a ForwardIterator over pointers.

Prefetches the current and next objects in a collection of pointers. Accepts two iterators: the first iterator is the current iteration position, and the second is the end iterator for the whole sequence. If the first iterator is not equal to end the iterator, the object to which it points is prefetched. Then the iterator is incremented and, if not equal to the end iterator, the next objects is also prefetched.

Definition at line 154 of file prefetch.h.

155{
156 if (iter != endIter) {
157 prefetchObj(*iter);
158 if (++iter != endIter) {
159 prefetchObj(*iter);
160 }
161 }
162}

◆ reset()

template<class E>
std::enable_if_t< is_bitmask_v< E >, E & > CxxUtils::reset ( E & lhs,
E rhs )
constexpr

Convenience function to clear bits in a class enum bitmask.

Parameters
lhsTarget bitmask.
rhsBits to clear.

Same as lhs &= ~rhs.
This function is enabled only for enumerators that have used the ATH_BITMASK macro.

Definition at line 251 of file bitmask.h.

252{
253 lhs &= ~rhs;
254 return lhs;
255}

◆ safeHexdump()

void CxxUtils::safeHexdump ( std::ostream & s,
const void * addr,
size_t n,
size_t offset = 0 )

Make a hex dump of memory, protected against bad reads.

Parameters
sStream to which to write the output.
addrAddress at which to start dumping.
nNumber of byte to dump.
offsetOffset by which to shift the printed address (mostly for testing).

This function will skip dumping memory pages that are not readable. It may also start dumping slightly before the requested address, in order to start with an alignment of 16.

Definition at line 104 of file hexdump.cxx.

105{
106 const char* ptr = reinterpret_cast<const char*> (addr);
107
108 // Adjust to start at width-byte boundary.
109 size_t nadj = reinterpret_cast<uintptr_t>(ptr) % width;
110 if (nadj > 0) {
111 ptr -= nadj;
112 n += nadj;
113 }
114
115 long pagesize_ret = sysconf (_SC_PAGESIZE);
116 if (pagesize_ret < 0 || pagesize_ret >= 1024*1024*1024) {
117 std::abort();
118 }
119 size_t pagesize = pagesize_ret;
120
121
122 procmaps m;
123
124 // Print page by page.
125 while (n > 0) {
126 uintptr_t iptr = reinterpret_cast<uintptr_t>(ptr);
127 size_t thispage = ((iptr + pagesize) & ~(pagesize-1)) - iptr;
128 if (thispage > n) {
129 thispage = n;
130 }
131 const procmaps::Entry* ent = m.getEntry (ptr);
132 if (ent && ent->readable) {
133 hexdump (s, ptr, thispage, offset);
134 }
135 else {
136 boost::io::ios_all_saver saver (s);
137 std::hex (s);
138 s.fill ('0');
139 s << std::setw(16) << reinterpret_cast<uintptr_t>(ptr) - offset
140 << " --- is not readable\n";
141 if (ent) {
142 thispage = std::max (ent->endAddress - iptr, thispage);
143 }
144 }
145 ptr += thispage;
146 n -= thispage;
147 }
148}
void hexdump(std::ostream &s, const void *addr, size_t n, size_t offset=0)
Make a hex dump of memory.
Definition hexdump.cxx:37
unsigned long endAddress
Definition procmaps.h:23

◆ set()

template<class E>
std::enable_if_t< is_bitmask_v< E >, E & > CxxUtils::set ( E & lhs,
E rhs )
constexpr

Convenience function to set bits in a class enum bitmask.

Parameters
lhsTarget bitmask.
rhsBits to set.

Same as lhs |= rhs.
This function is enabled only for enumerators that have used the ATH_BITMASK macro.

Definition at line 232 of file bitmask.h.

233{
234 lhs |= rhs;
235 return lhs;
236}

◆ set_unaligned()

template<class T>
void CxxUtils::set_unaligned ( uint8_t *ATH_RESTRICT & p,
T val )

Define templated versions of the above functions.

◆ set_unaligned16()

void CxxUtils::set_unaligned16 ( uint8_t *ATH_RESTRICT & p,
uint16_t val )
inline

Write a 2-byte little-endian value to a possibly unaligned pointer.

Parameters
pPointer to which to write. Advanced to the next value.
valValue to write.

Writes a little-endian value, regardless of the host byte ordering, and advances the pointer. Should not rely on undefined behavior, regardless of the alignment of p.

If used in a loop, you'll get better code with a restricted pointer.

Definition at line 64 of file set_unaligned.h.

65{
66 uint16_t tmp = htole16 (val);
67 memcpy (p, &tmp, sizeof(tmp));
68 p += sizeof(tmp);
69}
uint16_t htole16(uint16_t x)

◆ set_unaligned32()

void CxxUtils::set_unaligned32 ( uint8_t *ATH_RESTRICT & p,
uint32_t val )
inline

Write a 4-byte little-endian value to a possibly unaligned pointer.

Parameters
pPointer to which to write. Advanced to the next value.
valValue to write.

Writes a little-endian value, regardless of the host byte ordering, and advances the pointer. Should not rely on undefined behavior, regardless of the alignment of p.

If used in a loop, you'll get better code with a restricted pointer.

Definition at line 84 of file set_unaligned.h.

85{
86 uint32_t tmp = htole32 (val);
87 memcpy (p, &tmp, sizeof(tmp));
88 p += sizeof(tmp);
89}
uint32_t htole32(uint32_t x)

◆ set_unaligned64()

void CxxUtils::set_unaligned64 ( uint8_t *ATH_RESTRICT & p,
uint64_t val )
inline

Write an 8-byte little-endian value to a possibly unaligned pointer.

Parameters
pPointer to which to write. Advanced to the next value.
valValue to write.

Writes a little-endian value, regardless of the host byte ordering, and advances the pointer. Should not rely on undefined behavior, regardless of the alignment of p.

If used in a loop, you'll get better code with a restricted pointer.

Definition at line 104 of file set_unaligned.h.

105{
106 uint64_t tmp = htole64 (val);
107 memcpy (p, &tmp, sizeof(tmp));
108 p += sizeof(tmp);
109}
uint64_t htole64(uint64_t x)

◆ set_unaligned< double >()

template<>
void CxxUtils::set_unaligned< double > ( uint8_t *ATH_RESTRICT & p,
double f )
inline

Definition at line 197 of file set_unaligned.h.

198{
200}
void set_unaligned_double(uint8_t *ATH_RESTRICT &p, double val)
Write a little-endian double value to a possibly unaligned pointer.

◆ set_unaligned< float >()

template<>
void CxxUtils::set_unaligned< float > ( uint8_t *ATH_RESTRICT & p,
float f )
inline

Definition at line 189 of file set_unaligned.h.

190{
191 set_unaligned_float (p, f);
192}
void set_unaligned_float(uint8_t *ATH_RESTRICT &p, float val)
Write a little-endian float value to a possibly unaligned pointer.

◆ set_unaligned< int16_t >()

template<>
void CxxUtils::set_unaligned< int16_t > ( uint8_t *ATH_RESTRICT & p,
int16_t val )
inline

Definition at line 213 of file set_unaligned.h.

214{
215 set_unaligned<uint16_t> (p, std::bit_cast<uint16_t> (val));
216}
void set_unaligned< uint16_t >(uint8_t *ATH_RESTRICT &p, uint16_t val)

◆ set_unaligned< int32_t >()

template<>
void CxxUtils::set_unaligned< int32_t > ( uint8_t *ATH_RESTRICT & p,
int32_t val )
inline

Definition at line 221 of file set_unaligned.h.

222{
223 set_unaligned<uint32_t> (p, std::bit_cast<uint32_t> (val));
224}
void set_unaligned< uint32_t >(uint8_t *ATH_RESTRICT &p, uint32_t val)

◆ set_unaligned< int64_t >()

template<>
void CxxUtils::set_unaligned< int64_t > ( uint8_t *ATH_RESTRICT & p,
int64_t val )
inline

Definition at line 229 of file set_unaligned.h.

230{
231 set_unaligned<uint64_t> (p, std::bit_cast<uint64_t> (val));
232}
void set_unaligned< uint64_t >(uint8_t *ATH_RESTRICT &p, uint64_t val)

◆ set_unaligned< int8_t >()

template<>
void CxxUtils::set_unaligned< int8_t > ( uint8_t *ATH_RESTRICT & p,
int8_t val )
inline

Definition at line 205 of file set_unaligned.h.

206{
207 set_unaligned<uint8_t> (p, std::bit_cast<uint8_t> (val));
208}
void set_unaligned< uint8_t >(uint8_t *ATH_RESTRICT &p, uint8_t val)

◆ set_unaligned< uint16_t >()

template<>
void CxxUtils::set_unaligned< uint16_t > ( uint8_t *ATH_RESTRICT & p,
uint16_t val )
inline

Definition at line 165 of file set_unaligned.h.

166{
167 set_unaligned16 (p, val);
168}
void set_unaligned16(uint8_t *ATH_RESTRICT &p, uint16_t val)
Write a 2-byte little-endian value to a possibly unaligned pointer.

◆ set_unaligned< uint32_t >()

template<>
void CxxUtils::set_unaligned< uint32_t > ( uint8_t *ATH_RESTRICT & p,
uint32_t val )
inline

Definition at line 173 of file set_unaligned.h.

174{
175 set_unaligned32 (p, val);
176}
void set_unaligned32(uint8_t *ATH_RESTRICT &p, uint32_t val)
Write a 4-byte little-endian value to a possibly unaligned pointer.

◆ set_unaligned< uint64_t >()

template<>
void CxxUtils::set_unaligned< uint64_t > ( uint8_t *ATH_RESTRICT & p,
uint64_t val )
inline

Definition at line 181 of file set_unaligned.h.

182{
183 set_unaligned64 (p, val);
184}
void set_unaligned64(uint8_t *ATH_RESTRICT &p, uint64_t val)
Write an 8-byte little-endian value to a possibly unaligned pointer.

◆ set_unaligned< uint8_t >()

template<>
void CxxUtils::set_unaligned< uint8_t > ( uint8_t *ATH_RESTRICT & p,
uint8_t val )
inline

Definition at line 157 of file set_unaligned.h.

158{
159 *p++ = val;
160}

◆ set_unaligned_double()

void CxxUtils::set_unaligned_double ( uint8_t *ATH_RESTRICT & p,
double val )
inline

Write a little-endian double value to a possibly unaligned pointer.

Parameters
pPointer to which to write. Advanced to the next value.
valValue to write.

Writes a little-endian value, regardless of the host byte ordering, and advances the pointer. Should not rely on undefined behavior, regardless of the alignment of p.

If used in a loop, you'll get better code with a restricted pointer.

Definition at line 142 of file set_unaligned.h.

143{
144 set_unaligned64 (p, std::bit_cast<uint64_t> (val));
145}

◆ set_unaligned_float()

void CxxUtils::set_unaligned_float ( uint8_t *ATH_RESTRICT & p,
float val )
inline

Write a little-endian float value to a possibly unaligned pointer.

Parameters
pPointer to which to write. Advanced to the next value.
valValue to write.

Writes a little-endian value, regardless of the host byte ordering, and advances the pointer. Should not rely on undefined behavior, regardless of the alignment of p.

If used in a loop, you'll get better code with a restricted pointer.

Definition at line 124 of file set_unaligned.h.

125{
126 set_unaligned32 (p, std::bit_cast<uint32_t> (val));
127}

◆ span() [1/2]

template<class T>
CxxUtils::span ( T * beg,
T * end ) -> span< T >

◆ span() [2/2]

template<class T>
CxxUtils::span ( T * ptr,
std::size_t sz ) -> span< T >

A couple needed deduction guides.

◆ stall()

void CxxUtils::stall ( )
inline

Emit stall instruction for use in a spin loop.

For best performance of a spin loop (as used for a spinlock or other MT consistency operations), Intel recommends adding a ‘pause’ instruction within the loop on x86(_64) targets. This function provides a portable way of doing this.

Currently a no-op for anything other than x86(_64) + arm. Support for other architectures can be added if it is useful.

Definition at line 37 of file stall.h.

38{
39#if defined(__i386__) || defined(__x86_64__)
40 _mm_pause();
41#elif defined(__aarch64__) && defined(__GNUC__)
42 asm volatile("yield" ::: "memory");
43#endif
44}

◆ strformat()

std::string CxxUtils::strformat ( const char * fmt,
... )

return a std::string according to a format fmt and varargs

Definition at line 49 of file StrFormat.cxx.

50{
51 char *buf = NULL;
52 int nbytes = -1;
53
54 va_list ap;
55 va_start(ap, fmt); /* Initialize the va_list */
56
57 nbytes = vasprintf(&buf, fmt, ap);
58 va_end(ap); /* Cleanup the va_list */
59
60 if (nbytes < 0) {
61 /*buf is undefined when allocation failed
62 * see: http://linux.die.net/man/3/asprintf
63 */
64 // free(buf);
65 throw std::runtime_error("problem while calling vasprintf");
66 }
67
68 CharLiberator guard(buf);
69
70 // help compiler to apply RVO
71 return std::string(buf);
72}
const char *const fmt

◆ test()

template<class E>
std::enable_if_t< is_bitmask_v< E >, bool > CxxUtils::test ( E lhs,
E rhs )
constexpr

Convenience function to test bits in a class enum bitmask.

Parameters
lhsTarget bitmask.
rhsBits to test.

Same as (lhs & rhs) != 0. This function is enabled only for enumerators that have used the ATH_BITMASK macro.

Definition at line 270 of file bitmask.h.

271{
272 typedef std::underlying_type_t<E>underlying;
273 return static_cast<underlying> (lhs & rhs) != 0;
274}

◆ throw_out_of_range() [1/2]

void CxxUtils::throw_out_of_range ( const char * what,
size_t index,
size_t size,
const void * obj )

Throw an out_of_range exception.

Parameters
whatDescription of the error.
indexThe index that was out of range.
sizeThe size of the container.
objPointer to the container (or other relevant object).

Definition at line 43 of file throw_out_of_range.cxx.

45{
46 throw_out_of_range (std::string(what), index, size, obj);
47}
void throw_out_of_range(const std::string &what, size_t index, size_t size, const void *obj)
Throw an out_of_range exception.
Definition index.py:1

◆ throw_out_of_range() [2/2]

void CxxUtils::throw_out_of_range ( const std::string & what,
size_t index,
size_t size,
const void * obj )

Throw an out_of_range exception.

Parameters
whatDescription of the error.
indexThe index that was out of range.
sizeThe size of the container.
objPointer to the container (or other relevant object).

Definition at line 27 of file throw_out_of_range.cxx.

29{
30 throw std::out_of_range (std::format
31 ("CxxUtils::throw_out_of_range {} requested index {} >= {} for object at {}",
32 what, index, size, obj));
33};

◆ to()

template<class CONT, class RANGE>
CONT CxxUtils::to ( RANGE && r)

Definition at line 39 of file ranges.h.

40{
41 return CONT (std::ranges::begin (r), std::ranges::end (r));
42}

◆ tokenize()

std::vector< std::string > CxxUtils::tokenize ( const std::string & the_str,
std::string_view delimiters )

Splits the string into smaller substrings.

Definition at line 15 of file Control/CxxUtils/Root/StringUtils.cxx.

16 {
17
18 std::vector<std::string> tokens{};
19 // Skip delimiters at beginning.
20 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
21 // Find first "non-delimiter".
22 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
23
24 while (std::string::npos != pos || std::string::npos != lastPos) {
25 // Found a token, add it to the vector.
26 tokens.push_back(str.substr(lastPos, pos - lastPos));
27 // Skip delimiters. Note the "not_of"
28 lastPos = str.find_first_not_of(delimiters, pos);
29 // Find next "non-delimiter"
30 pos = str.find_first_of(delimiters, lastPos);
31 }
32 return tokens;
33 }

◆ tokenizeDouble()

std::vector< double > CxxUtils::tokenizeDouble ( const std::string & the_str,
std::string_view delimiter )

Definition at line 34 of file Control/CxxUtils/Root/StringUtils.cxx.

35 {
36 const std::vector<std::string> strTokens = tokenize(the_str, delimiter);
37 std::vector<double> toReturn{};
38 std::transform(strTokens.begin(), strTokens.end(), std::back_inserter(toReturn),
39 [](const std::string& token){
40 return atof(token);
41 });
42 return toReturn;
43 }
std::vector< std::string > tokenize(const std::string &the_str, std::string_view delimiters)
Splits the string into smaller substrings.

◆ tokenizeInt()

std::vector< int > CxxUtils::tokenizeInt ( const std::string & the_str,
std::string_view delimiter )

Definition at line 55 of file Control/CxxUtils/Root/StringUtils.cxx.

56 {
57 const std::vector<std::string> strTokens = tokenize(the_str, delimiter);
58 std::vector<int> toReturn{};
59 std::transform(strTokens.begin(), strTokens.end(), std::back_inserter(toReturn),
60 [](const std::string& token){
61 return atoi(token);
62 });
63 return toReturn;
64 }

◆ ubsan_suppress()

void CxxUtils::ubsan_suppress ( void(* func )())

Helper for suppressing ubsan warnings.

Parameters
funcFunction to call (may be a lambda).

If ubsan is running, temporarily redirect stderr to /dev/null. Then call func.

For example, we sometimes get a bogus ubsan warning from cling initialization. This can be suppressed by adding something like:

CxxUtils::ubsan_suppress ([]() { TInterpreter::Instance(); });
void ubsan_suppress(void(*func)())
Helper for suppressing ubsan warnings.

Definition at line 69 of file ubsan_suppress.cxx.

70{
71 if (dlsym (RTLD_DEFAULT, "__ubsan_handle_add_overflow") != NULL)
72 {
73 RedirStderr redir;
74 func();
75 }
76 else {
77 func();
78 }
79}

◆ vall()

template<typename VEC>
ATH_ALWAYS_INLINE bool CxxUtils::vall ( const VEC & mask)

Definition at line 402 of file vec.h.

402 {
403 static_assert(std::is_integral<vec_type_t<VEC>>::value,
404 "vec elements must be of integral type. Aka vec must be "
405 "compatible with a mask");
406 VEC alltrue;
407#if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
408 // fallback compares to 0 when false
409 // and 1 when is true
410 vbroadcast(alltrue, vec_type_t<VEC>{1});
411 return std::memcmp(mask.m_arr, alltrue.m_arr, sizeof(VEC)) == 0;
412#else
413 // For the gnu vector extensions
414 // Vectors are compared element-wise producing 0 when comparison is false
415 // and -1 (constant of the appropriate type where all bits are set) otherwise.
416 vbroadcast(alltrue, vec_type_t<VEC>{-1});
417 return std::memcmp(&mask, &alltrue, sizeof(VEC)) == 0;
418#endif
419}
typename vecDetail::vec_type< VEC >::type vec_type_t
Define a nice alias for the element type of a vectorized type.
Definition vec.h:213
ATH_ALWAYS_INLINE void vbroadcast(VEC &v, T x)
Copy a scalar to each element of a vectorized type.
Definition vec.h:251

◆ vany()

template<typename VEC>
ATH_ALWAYS_INLINE bool CxxUtils::vany ( const VEC & mask)

Definition at line 362 of file vec.h.

362 {
363 static_assert(std::is_integral<vec_type_t<VEC>>::value,
364 "vec elements must be of integral type. Aka vec must be "
365 "compatible with a mask");
366 VEC zero;
368#if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
369 return std::memcmp(mask.m_arr, zero.m_arr, sizeof(VEC)) != 0;
370#else
371 return std::memcmp(&mask, &zero, sizeof(VEC)) != 0;
372#endif
373}
void zero(TH2 *h)
zero the contents of a 2d histogram

◆ vbroadcast()

template<typename VEC, typename T>
ATH_ALWAYS_INLINE void CxxUtils::vbroadcast ( VEC & v,
T x )

Copy a scalar to each element of a vectorized type.

Definition at line 251 of file vec.h.

252{
253#if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
254 constexpr size_t N = CxxUtils::vec_size<VEC>();
255 for (size_t i = 0; i < N; ++i) {
256 v[i] = x;
257 }
258#else
259 // using - to avoid sign conversions.
260 v = x - VEC{ 0 };
261#endif
262}
ATH_ALWAYS_INLINE constexpr size_t vec_size()
Return the number of elements in a vectorized type.
Definition vec.h:227

◆ vconvert()

template<typename VEC1, typename VEC2>
ATH_ALWAYS_INLINE void CxxUtils::vconvert ( VEC1 & dst,
const VEC2 & src )

performs dst is the result of a static cast of each element of src

Definition at line 428 of file vec.h.

429{
430 static_assert((vec_size<VEC1>() == vec_size<VEC2>()),
431 "vconvert dst and src have different number of elements");
432
433#if !HAVE_CONVERT_VECTOR || WANT_VECTOR_FALLBACK
434 typedef vec_type_t<VEC1> ELT;
435 constexpr size_t N = vec_size<VEC1>();
436 for (size_t i = 0; i < N; ++i) {
437 dst[i] = static_cast<ELT>(src[i]);
438 }
439#else
440 dst = __builtin_convertvector(src, VEC1);
441#endif
442}

◆ vec_size() [1/2]

template<class VEC>
ATH_ALWAYS_INLINE constexpr size_t CxxUtils::vec_size ( )
constexpr

Return the number of elements in a vectorized type.

Definition at line 227 of file vec.h.

228{
229 typedef vec_type_t<VEC> ELT;
230 return sizeof(VEC) / sizeof(ELT);
231}

◆ vec_size() [2/2]

template<class VEC>
ATH_ALWAYS_INLINE constexpr size_t CxxUtils::vec_size ( const VEC & )
constexpr

Return the number of elements in a vectorized type.

Definition at line 239 of file vec.h.

240{
241 typedef vec_type_t<VEC> ELT;
242 return sizeof(VEC) / sizeof(ELT);
243}

◆ vload()

template<typename VEC>
ATH_ALWAYS_INLINE void CxxUtils::vload ( VEC & dst,
vec_type_t< VEC > const * src )

Definition at line 272 of file vec.h.

273{
274
275#if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
276 std::memcpy(dst.m_arr, src, sizeof(VEC));
277#else
278 std::memcpy(&dst, src, sizeof(VEC));
279#endif
280}

◆ vmax()

template<typename VEC>
ATH_ALWAYS_INLINE void CxxUtils::vmax ( VEC & dst,
const VEC & a,
const VEC & b )

Definition at line 343 of file vec.h.

344{
345#if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
346 constexpr size_t N = vec_size<VEC>();
347 for (size_t i = 0; i < N; ++i) {
348 dst[i] = a[i] > b[i] ? a[i] : b[i];
349 }
350#else
351 dst = a > b ? a : b;
352#endif
353}

◆ vmin()

template<typename VEC>
ATH_ALWAYS_INLINE void CxxUtils::vmin ( VEC & dst,
const VEC & a,
const VEC & b )

Definition at line 324 of file vec.h.

325{
326#if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
327 constexpr size_t N = vec_size<VEC>();
328 for (size_t i = 0; i < N; ++i) {
329 dst[i] = a[i] < b[i] ? a[i] : b[i];
330 }
331#else
332 dst = a < b ? a : b;
333#endif
334}

◆ vnone()

template<typename VEC>
ATH_ALWAYS_INLINE bool CxxUtils::vnone ( const VEC & mask)

Definition at line 382 of file vec.h.

382 {
383 static_assert(std::is_integral<vec_type_t<VEC>>::value,
384 "vec elements must be of integral type. Aka vec must be "
385 "compatible with a mask");
386 VEC zero;
388#if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
389 return std::memcmp(mask.m_arr, zero.m_arr, sizeof(VEC)) == 0;
390#else
391 return std::memcmp(&mask, &zero, sizeof(VEC)) == 0;
392#endif
393}

◆ vpermute()

template<size_t... Indices, typename VEC, typename VEC1>
ATH_ALWAYS_INLINE void CxxUtils::vpermute ( VEC1 & dst,
const VEC & src )

vpermute function.

move any element of a vector src into any or multiple position inside dst.

Definition at line 451 of file vec.h.

452{
453
454 static_assert((sizeof...(Indices) == vec_size<VEC1>()),
455 "vpermute number of indices different than return vector size");
456 static_assert(std::is_same<vec_type_t<VEC>, vec_type_t<VEC1>>::value,
457 "vpermute type of input and output vector elements differ");
459 Indices >= 0 && Indices < vec_size<VEC>())...>::value,
460 "vpermute value of a mask index is outside the allowed range");
461
462#if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
463 dst = VEC1{ src[Indices]... };
464#else
465 dst = __builtin_shufflevector(src, src, Indices...);
466#endif
467}
std::is_same< bool_pack< bs..., true >, bool_pack< true, bs... > > all_true
Definition vec.h:198

◆ vpermute2()

template<size_t... Indices, typename VEC, typename VEC1>
ATH_ALWAYS_INLINE void CxxUtils::vpermute2 ( VEC1 & dst,
const VEC & src1,
const VEC & src2 )

vpermute2 function.

move any element of the vectors src1, src2 into any or multiple position inside dst.

Definition at line 476 of file vec.h.

477{
478 static_assert(
479 (sizeof...(Indices) == vec_size<VEC1>()),
480 "vpermute2 number of indices different than return vector size");
481 static_assert(std::is_same<vec_type_t<VEC>, vec_type_t<VEC1>>::value,
482 "vpermute2 type of input and output vector elements differ");
483 constexpr size_t N = vec_size<VEC>();
485 Indices >= 0 && Indices < 2 * N)...>::value,
486 "vpermute2 value of a mask index is outside the allowed range");
487
488#if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
489 VEC1 tmp;
490 size_t pos{0};
491 for (auto index: { Indices... }) {
492 if (index < N) {
493 tmp[pos] = src1[index];
494 } else {
495 tmp[pos] = src2[index - N];
496 }
497 ++pos;
498 }
499 dst = tmp;
500#else
501 dst = __builtin_shufflevector(src1, src2, Indices...);
502#endif
503}
str index
Definition DeMoScan.py:362

◆ vselect()

template<typename VEC>
ATH_ALWAYS_INLINE void CxxUtils::vselect ( VEC & dst,
const VEC & a,
const VEC & b,
const vec_mask_type_t< VEC > & mask )

Definition at line 306 of file vec.h.

306 {
307#if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
308 constexpr size_t N = vec_size<VEC>();
309 for (size_t i = 0; i < N; ++i) {
310 dst[i] = mask[i] ? a[i] : b[i];
311 }
312#else
313 dst = mask ? a : b;
314#endif
315}

◆ vstore()

template<typename VEC>
ATH_ALWAYS_INLINE void CxxUtils::vstore ( vec_type_t< VEC > * dst,
const VEC & src )

Definition at line 290 of file vec.h.

291{
292#if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
293 std::memcpy(dst, src.m_arr, sizeof(VEC));
294#else
295 std::memcpy(dst, &src, sizeof(VEC));
296#endif
297}

◆ wrapToPi()

template<typename T>
T CxxUtils::wrapToPi ( T phi)
inline

Wrap angle in radians to [-pi, pi].

Odd positive (negative) multiples of pi map to (-)pi.

Definition at line 24 of file phihelper.h.

25 {
26 static_assert(std::is_floating_point<T>::value);
27
28 constexpr auto PI = static_cast<T>(M_PI);
29 // For large values this is faster:
30 if (phi < -100 || phi > 100) {
31 return std::remainder(phi, 2 * PI);
32 }
33 while (phi > PI) phi -= 2 * PI;
34 while (phi < -PI) phi += 2 * PI;
35 return phi;
36 }
const float PI

◆ xmalloc()

void * CxxUtils::xmalloc ( size_t size)

Trapping version of malloc.

Parameters
sizeNumber of bytes to allocate.

Calls malloc. Throws a std::bad_alloc exception on failure.

If you're writing new code, you probably don't want to use this! Use make_unique/new or STL containers instead. This is intended for compatiblilty with existing code requiring malloc/free.

Definition at line 31 of file xmalloc.cxx.

32{
33 void* p = malloc (size);
34 if (!p) throw std::bad_alloc();
35 return p;
36}

Variable Documentation

◆ defaultCRCTable

const CRCTable CxxUtils::defaultCRCTable(0xad93d23594c935a9) ( 0xad93d23594c935a9 )

◆ dynamic_extent

size_t CxxUtils::dynamic_extent = static_cast<size_t>(-1)
inlineconstexpr

Used to specify a subrange of indefinite size in subspan().

Definition at line 29 of file span.h.

◆ valid_span_type_v

template<class T, class U>
bool CxxUtils::valid_span_type_v = std::is_convertible_v<U(*)[], T(*)[]>
inlineconstexpr

Is U* a valid type to use to initialize a span<T>?

No more than const-conversion. Same logic as used in libstdc++.

Definition at line 36 of file span.h.