ATLAS Offline Software
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
CxxUtils Namespace Reference

Namespaces

 detail
 Portable implementations.
 
 fpcompare
 
 fpcompare_fn
 
 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  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  ConcurrentPtrSet
 A set of pointers, allowing concurrent, lockless queries. More...
 
class  ConcurrentStrToValMap
 Hash map from strings 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  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  RedirStderr
 
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. More...
 
template<class T >
using vec_aligned_vector = aligned_vector< T, 64 >
 A std::vector with alignment sufficient for any vector instructions on this platform. More...
 
template<class T >
using CachedUniquePtr = CachedUniquePtrT< const T >
 
template<typename T , size_t N>
using vec = typename vecDetail::vec_typedef< T, N >::type
 Define a nice alias for the vectorized type. More...
 
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. More...
 
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. More...
 
template<typename T , size_t N>
using ivec = vec_fb< typename boost::int_t< sizeof(T) *8 >::exact, N >
 

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 >
void fromArrayrep (const CaloRec::Arrayrep &rep, T &x)
 Helper to convert from an @x Arrayrep to a scalar type. More...
 
template<unsigned int N>
void fromArrayrep (const CaloRec::Arrayrep &rep, CxxUtils::Array< N > &x)
 Helper to convert from an @x Arrayrep to an Array. More...
 
template<class T >
const T * as_const_ptr (const T *p)
 Helper for getting a const version of a pointer. More...
 
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. More...
 
template<class T >
atomic_fetch_max (std::atomic< T > *a, T v, std::memory_order memorder=std::memory_order_seq_cst)
 Atomically calculate maximum. More...
 
template<class T >
atomic_fetch_min (std::atomic< T > *a, T v, std::memory_order memorder=std::memory_order_seq_cst)
 Atomically calculate minimum. More...
 
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. More...
 
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. More...
 
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. More...
 
unsigned count_trailing_zeros (unsigned x)
 Count number of trailing zeros. More...
 
unsigned count_trailing_zeros (unsigned long x)
 
unsigned count_trailing_zeros (unsigned long long x)
 
unsigned count_leading_zeros (unsigned x)
 Count number of leading zeros. More...
 
unsigned count_leading_zeros (unsigned long x)
 
unsigned count_leading_zeros (unsigned long long x)
 
unsigned count_ones (unsigned x)
 Count number of set bits. More...
 
unsigned count_ones (unsigned long x)
 
unsigned count_ones (unsigned long long x)
 
template<typename T >
int maxSetBit (const T x)
 Returns the position (counting from the left hand side) of the last set bit. More...
 
template<class KEY , class VALUE , template< class > class UPDATER, class HASHER = std::hash<KEY>, class MATCHER = std::equal_to<KEY>, detail::ConcurrentHashmapVal_t NULLVAL = 0, detail::ConcurrentHashmapVal_t TOMBSTONE = NULLVAL>
 ATH_REQUIRES (detail::IsConcurrentHashmapPayload< KEY > &&detail::IsConcurrentHashmapPayload< VALUE > &&detail::IsUpdater< UPDATER > &&detail::IsHash< HASHER, KEY > &&detail::IsBinaryPredicate< MATCHER, KEY >) class ConcurrentMap
 Hash map from integers/pointers allowing concurrent, lockless reads. More...
 
template<class RANGE , class KEY , class T , class COMPARE , template< class > class UPDATER>
 ATH_REQUIRES (detail::IsUpdater< UPDATER > &&detail::IsConcurrentRangeCompare< COMPARE, RANGE, KEY, typename UPDATER< int >::Context_t >) class ConcurrentRangeMap
 Map from range to payload object, allowing concurrent, lockless reads. More...
 
template<class VALUE , template< class > class UPDATER>
 ATH_REQUIRES (detail::IsConcurrentHashmapPayload< VALUE > &&detail::IsUpdater< UPDATER >) class ConcurrentStrMap
 Hash map from strings allowing concurrent, lockless reads. More...
 
template<class KEY , class VALUE , template< class > class UPDATER, class HASHER = std::hash<KEY>, class MATCHER = std::equal_to<KEY>, detail::ConcurrentHashmapVal_t NULLVAL = 0>
 ATH_REQUIRES (detail::IsConcurrentHashmapPayload< KEY > &&detail::IsUpdater< UPDATER > &&detail::IsHash< HASHER, KEY > &&detail::IsBinaryPredicate< MATCHER, KEY >) class ConcurrentToValMap
 Hash map from pointers/integers to arbitrary objects allowing concurrent, lockless reads. More...
 
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. More...
 
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. More...
 
template<class InputIterator , class OutputIterator >
 ATH_REQUIRES (std::input_iterator< InputIterator > &&std::output_iterator< OutputIterator, typename std::iterator_traits< InputIterator >::value_type >) inline OutputIterator copy_bounded(InputIterator begi
 Copy a range with bounds restriction. More...
 
template<class InputRange , class OutputRange >
auto copy_bounded (const InputRange &input, OutputRange &output) -> decltype(std::begin(output))
 Copy a range with bounds restriction. More...
 
template<class InputRange , class OutputRange >
auto copy_bounded (const InputRange &input, OutputRange &&output) -> decltype(std::begin(output))
 Copy a range with bounds restriction. More...
 
void deleteCRCTable (CxxUtils::CRCTable *table)
 Delete a CRCTable object. More...
 
std::unique_ptr< CRCTablemakeCRCTable (uint64_t p, uint64_t initial=0xffffffffffffffff)
 Initialize CRC tables and constants. More...
 
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. More...
 
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. More...
 
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. More...
 
uint64_t crc64 (const CRCTable &table, const char *data, size_t data_len)
 Find the CRC-64 of a string,. More...
 
uint64_t crc64 (const char *data, size_t data_len)
 Find the CRC-64 of a string, with the default CRC. More...
 
uint64_t crc64 (const std::string &s)
 Find the CRC-64 of a string, using the default polynomial. More...
 
uint64_t crc64addint (uint64_t crc, uint64_t x)
 Extend a previously-calculated CRC to include an int. More...
 
std::string crc64format (uint64_t crc)
 Format a CRC-64 as a string. More...
 
std::string crc64digest (const std::string &str)
 Return a CRC-64 digest of a string. More...
 
void exctrace (const std::exception &e, IOFD fd=IOFD_INVALID)
 Print out information for the last exception. More...
 
uint16_t htole16 (uint16_t x)
 
uint32_t htole32 (uint32_t x)
 
uint64_t htole64 (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. More...
 
uint32_t get_unaligned32 (const uint8_t *ATH_RESTRICT &p)
 Read a 4-byte little-endian value from a possibly unaligned pointer. More...
 
uint64_t get_unaligned64 (const uint8_t *ATH_RESTRICT &p)
 Read a 8-byte little-endian value from a possibly unaligned pointer. More...
 
float get_unaligned_float (const uint8_t *ATH_RESTRICT &p)
 Read little-endian float value from a possibly unaligned pointer. More...
 
double get_unaligned_double (const uint8_t *ATH_RESTRICT &p)
 Read little-endian float value from a possibly unaligned pointer. More...
 
template<class T >
get_unaligned (const uint8_t *ATH_RESTRICT &p)
 Define templated versions of the above functions. More...
 
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. More...
 
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. More...
 
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. More...
 
template<class T >
ones (unsigned int n)
 Return a bit mask with the lower n bits set. More...
 
template<typename T >
wrapToPi (T phi)
 Wrap angle in radians to [-pi, pi]. More...
 
template<typename T >
deltaPhi (T phiA, T phiB)
 Return difference phiA - phiB in range [-pi, pi]. More...
 
template<typename T >
phiMean (T phiA, T phiB)
 Calculate average of two angles. More...
 
template<typename T >
phiBisect (T phiA, T phiB)
 Bisect (average) the angle spanned by phiA and phiB. More...
 
void prefetchOne (const void *address)
 Generic prefetch method. More...
 
template<size_t N>
void prefetchN (const void *ptr)
 Prefetch an N-byte block of memory. More...
 
template<typename T >
void prefetchObj (const T *ptr)
 Generic prefetch of the object of specific types (sizes). More...
 
template<typename Iter >
void prefetchNext (Iter iter, Iter endIter)
 Prefetch next object in sequence. More...
 
template<typename Iter >
void prefetchTwo (Iter iter, Iter endIter)
 Prefetch two objects. More...
 
template<class T >
auto make_reverse_wrapper (T &r)
 Make a reverse_wrapper for a given container-like object. More...
 
template<class T >
 span (T *ptr, std::size_t sz) -> span< T >
 A couple needed deduction guides. More...
 
template<class T >
 span (T *beg, T *end) -> span< T >
 
template<class CONTAINER >
auto make_span (CONTAINER &c)
 Helper to make a span from a container. More...
 
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. More...
 
bool starts_with (const char *s, const char *prefix)
 Test whether one null-terminated byte string starts with another. More...
 
bool starts_with (const std::string &s, const char *prefix)
 Test whether one string starts with another. More...
 
bool starts_with (const std::string &s, const std::string &prefix)
 Test whether one string starts with another. More...
 
bool ends_with (const char *s, const char *suffix)
 Test whether one null-terminated byte string ends with another. More...
 
bool ends_with (const std::string &s, const char *suffix)
 Test whether one string starts ends another. More...
 
bool ends_with (const std::string &s, const std::string &suffix)
 Test whether one string ends with another. More...
 
std::string strformat (const char *fmt,...)
 return a std::string according to a format fmt and varargs More...
 
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. More...
 
double atof (std::string_view str)
 Converts a string into a double / float. More...
 
std::string_view eraseWhiteSpaces (std::string_view str)
 Removes all trailing and starting whitespaces from a string. More...
 
std::vector< std::string > tokenize (const std::string &the_str, std::string_view delimiters)
 Splits the string into smaller substrings. More...
 
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 ubsan_suppress (void(*func)())
 Helper for suppressing ubsan warnings. More...
 
template<class VEC >
constexpr ATH_ALWAYS_INLINE size_t vec_size ()
 Return the number of elements in a vectorized type. More...
 
template<class VEC >
constexpr ATH_ALWAYS_INLINE size_t vec_size (const VEC &)
 Return the number of elements in a vectorized type. More...
 
template<typename VEC , typename T >
ATH_ALWAYS_INLINE void vbroadcast (VEC &v, T x)
 Copy a scalar to each element of a vectorized type. More...
 
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)
 
template<size_t... Indices, typename VEC , typename VEC1 >
ATH_ALWAYS_INLINE void vpermute (VEC1 &dst, const VEC &src)
 vpermute function. More...
 
template<size_t... Indices, typename VEC , typename VEC1 >
ATH_ALWAYS_INLINE void vpermute2 (VEC1 &dst, const VEC &src1, const VEC &src2)
 vpermute2 function. More...
 
template<typename T , size_t N>
ivec< T, N > operator! (const vec_fb< T, N > &a)
 Negation. More...
 
template<typename T , size_t N>
ivec< T, N > operator&& (const vec_fb< T, N > &a, const vec_fb< T, N > &b)
 V1 && V2. More...
 
template<typename T , size_t N, class U >
ivec< T, N > operator&& (U a, const vec_fb< T, N > &b)
 S && V. More...
 
template<typename T , size_t N, class U >
ivec< T, N > operator&& (const vec_fb< T, N > &a, U b)
 V && S. More...
 
template<typename T , size_t N>
ivec< T, N > operator|| (const vec_fb< T, N > &a, const vec_fb< T, N > &b)
 V1 || V2. More...
 
std::string clean_allocator (std::string f)
 Clean ‘allocator’ template arguments from the function f. More...
 
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

InputIterator endi
 
InputIterator OutputIterator bego
 
InputIterator OutputIterator OutputIterator endo
 
constexpr size_t dynamic_extent = static_cast<size_t>(-1)
 Used to specify a subrange of indefinite size in subspan(). More...
 
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>? No more than const-conversion. More...
 
const CRCTable defaultCRCTable (0xad93d23594c935a9)
 

Typedef Documentation

◆ aligned_vector

template<class T , size_t Alignment = 1>
using CxxUtils::aligned_vector = typedef 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.

◆ CachedUniquePtr

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

Definition at line 114 of file CachedUniquePtr.h.

◆ ivec

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

Definition at line 53 of file vec_fb.h.

◆ vec

template<typename T , size_t N>
using CxxUtils::vec = typedef 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 = typedef 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 = typedef 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 = typedef 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 };

◆ 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 }

◆ ATH_REQUIRES() [1/5]

template<class KEY , class VALUE , template< class > class UPDATER, class HASHER = std::hash<KEY>, class MATCHER = std::equal_to<KEY>, detail::ConcurrentHashmapVal_t NULLVAL = 0, detail::ConcurrentHashmapVal_t TOMBSTONE = NULLVAL>
CxxUtils::ATH_REQUIRES ( detail::IsConcurrentHashmapPayload< KEY > &&detail::IsConcurrentHashmapPayload< VALUE > &&detail::IsUpdater< UPDATER > &&detail::IsHash< HASHER, KEY > &&detail::IsBinaryPredicate< MATCHER, KEY >  )

Hash map from integers/pointers allowing concurrent, lockless reads.

This class implements a hash map. Both the key and mapped types may be pointers or any numeric type that can fit in a uintptr_t. (However, using floating types for the key is not recommended.) It allows for concurrent access from many threads. Reads can proceed without taking out a lock, while writes are serialized with each other. Thus, this is appropriate for maps which are read-mostly.

This is based on ConcurrentHashmapImpl.

Besides the mapped key and value types, this class is templated on an UPDATER class, which is used to manage the underlying memory. See IsUpdater.h for details. (AthenaKernel/RCUUpdater is a concrete version that should work in the context of Athena.)

The operations used for calculating the hash of the keys and comparing keys can be customized with the HASHER and MATCHER template arguments (though the defaults should usually be fine).

One value of the key must be reserved as a null value, which no real keys may take. By default this is ‘0’, but it may be customized with the NULLVAL template argument. The map may optionally support erasures (via tombstones). To allow this, a second reserved key value must be identified and specified by the TOMBSTONE template argument. Note that the type of the NULLPTR and TOMBSTONE template arguments is a uintptr_t, not KEY.

This mostly supports the interface of std::unordered_map, with a few differences / omissions:

  • Dereferencing the iterator returns a structure by value, not a reference.
  • No try_emplace.
  • No insert methods with hints.
  • No operator==.
  • Nothing dealing with the bucket/node interface or merge().

Performance: This is the result from running the test with –perf on my machine, with gcc 13.0.0

ConcurrentMap lookup: 0.843s wall, 0.840s user + 0.000s system = 0.840s CPU (99.6%) iterate: 0.551s wall, 0.540s user + 0.000s system = 0.540s CPU (97.9%) UnorderedMap lookup: 1.890s wall, 1.870s user + 0.000s system = 1.870s CPU (99.0%) iterate: 0.966s wall, 0.970s user + 0.000s system = 0.970s CPU (100.4%) concurrent_unordered_map lookup: 3.718s wall, 3.690s user + 0.010s system = 3.700s CPU (99.5%) iterate: 5.719s wall, 5.690s user + 0.000s system = 5.690s CPU (99.5%) ck_ht lookup: 1.471s wall, 1.460s user + 0.000s system = 1.460s CPU (99.2%) iterate: 1.519s wall, 1.500s user + 0.000s system = 1.500s CPU (98.7%)

The timing for the lookup test of UnorderedMap is probably overly-optimistic, since the test doesn't do any locking in that case.

Representation type in the underlying map.

The underlying uint->uint hash table.

Standard STL types.

Updater object.

Context type.

Type for external locking.

Ensure that the underlying map can store our types.

Constructor.

Parameters
updaterObject used to manage memory (see comments at the start of the class).
capacityThe initial table capacity. (Will be rounded up to a power of two.)
ctxExecution context.

Constructor from another map.

Parameters
updaterObject used to manage memory (see comments at the start of the class).
capacityThe initial table capacity of the new table. (Will be rounded up to a power of two.)
ctxExecution context.

(Not really a copy constructor since we need to pass updater.)

Constructor from a range.

Parameters
fStart iterator for the range.
lEnd iterator for the range.
updaterObject used to manage memory (see comments at the start of the class).
capacityThe initial table capacity of the new table. (Will be rounded up to a power of two.)
ctxExecution context.

Constructor from a range of pairs.

Copy / move / assign not supported.

Destructor.

Return the number of items currently in the map.

Test if the map is currently empty.

Return the current size (capacity) of the hash table.

The number of erased elements in the current table.

Value structure for iterators.

Iterator class.

This uses boost::iterator_facade to define the methods required by an STL iterator in terms of the private methods below.

Since dereference() will be returning a const_iterator_value by value, we also need to override the reference type.

Constructor.

Parameters
itIterator of the underlying table.

Test if this iterator is valid.

This should be the same as testing for != end().

Required by iterator_facade.

iterator_facade requirement: Increment the iterator.

iterator_facade requirement: Decrement the iterator.

iterator_facade requirement: Equality test.

iterator_facade requirement: Dereference the iterator.

The iterator on the underlying table.

A range defined by two iterators.

Return an iterator range covering the entire map.

Iterator at the start of the map.

Iterator at the end of the map.

Iterator at the start of the map.

Iterator at the end of the map.

Test if a key is in the container.

Parameters
keyThe key to test.

Return the number of times a given key is in the container.

Parameters
keyThe key to test.

Returns either 0 or 1, depending on whether or not the key is in the map.

Look up an element in the map.

Parameters
keyThe element to find.

Returns either an iterator referencing the found element or end().

Look up an element in the map.

Parameters
keyThe element to find.

Returns the value associated with the key. Throws std::out_of_range if the key does not exist in the map.

Return a range of iterators with entries matching key.

Parameters
keyThe element to find.

As keys are unique in this container, this is either a single-element range, or both iterators are equal to end().

Take a lock on the container.

Take a lock on the container. The lock can then be passed to insertion methods, allowing to factor out the locking inside loops. The lock will be released when the lock object is destroyed.

Add an element to the map.

Parameters
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map, with external locking.

Parameters
lockThe lock object returned from lock().
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map, or overwrite an existing one.

Parameters
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map, or overwrite an existing one, with external locking.

Parameters
lockThe lock object returned from lock().
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map.

Parameters
pThe item to add. Should be a pair where first is the key and second is the integer value.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

For external locking, use emplace().

Insert a range of elements to the map.

Parameters
firstStart of the range.
lastEnd of the range.

The range should be a sequence of pairs where first is the string key and second is the integer value.

Erase an entry from the table.

Parameters
keyThe key to erase.

Mark the corresponding entry as deleted. Return true on success, false on failure (key not found).

The tombstone value must be different from the null value.

This may cause the key type returned by an iterator to change asynchronously to the tombstone value.

Erase an entry from the table, with external locking.

Parameters
lockThe lock object returned from lock().
keyThe key to erase.

Mark the corresponding entry as deleted. Return true on success, false on failure (key not found).

The tombstone value must be different from the null value.

This may cause the key type returned by an iterator to change asynchronously to the tombstone value.

Increase the table capacity.

Parameters
capacityThe new table capacity.
ctxExecution context.

No action will be taken if capacity is smaller than the current capacity.

Increase the table capacity.

Parameters
capacityThe new table capacity.

No action will be taken if capacity is smaller than the current capacity.

Erase the table and change the capacity.

Parameters
capacityThe new table capacity.
ctxExecution context.

Erase the table (don't change the capacity).

Parameters
ctxExecution context.

Erase the table in-place.

This method avoids allocating a new version of the table. However, it is not safe to use concurrently — no other threads may be accessing the container at the same time, either for read or write.

Called when this thread is no longer referencing anything from this container.

Parameters
ctxExecution context.

Swap this container with another.

Parameters
otherThe container with which to swap.

This will also call swap on the Updater object; hence, the Updater object must also support swap. The Hasher and Matcher instances are NOT swapped.

This operation is NOT thread-safe. No other threads may be accessing either container during this operation.

Access the Updater instance.

Convert an underlying key value to this type's key value.

Parameters
valThe underlying key value.

Convert this type's key value to an underlying key value.

Parameters
kThe key.

Convert an underlying mapped value to this type's mapped value.

Parameters
valThe underlying mapped value.

Convert this type's mapped value to an underlying mapped value.

Parameters
valThe mapped value.

Do a lookup in the table.

Parameters
keyThe key to look up.

Returns an iterator of the underlying map pointing at the found entry or end();

Insert / overwrite an entry in the table.

Parameters
keyThe key of the new item to add.
valThe value of the new item to add.
overwriteIf true, allow overwriting an existing entry.
ctxExecution context.

The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Insert / overwrite an entry in the table, with external locking.

Parameters
lockThe lock object returned from lock().
keyThe key of the new item to add.
valThe value of the new item to add.
overwriteIf true, allow overwriting an existing entry.
ctxExecution context.

The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

The underlying hash table.

Definition at line 94 of file ConcurrentMap.h.

100 {
101 private:
104 
105  // Translate between the Hasher/Matcher provided (which take KEY arguments)
106  // and what we need to give to the underlying implementation
107  // (which takes a uintptr_t).
108  struct Hasher
109  {
110  size_t operator() (val_t k) const {
111  return m_h (keyAsKey (k));
112  }
113  HASHER m_h;
114  };
115  struct Matcher
116  {
117  bool operator() (val_t a, val_t b) const {
118  return m_m (keyAsKey (a), keyAsKey (b));
119  }
120  MATCHER m_m;
121  };
122 
124  using Impl_t = typename detail::ConcurrentHashmapImpl<UPDATER,
125  Hasher,
126  Matcher,
127  NULLVAL,
128  TOMBSTONE>;
129 
130 
131 public:
133  using key_type = KEY;
134  using mapped_type = VALUE;
135  using size_type = size_t;
137  using Updater_t = typename Impl_t::Updater_t;
139  using Context_t = typename Updater_t::Context_t;
141  using Lock_t = typename Impl_t::Lock_t;
142 
144  static_assert( sizeof(typename Impl_t::val_t) >= sizeof(key_type) );
145  static_assert( sizeof(typename Impl_t::val_t) >= sizeof(mapped_type) );
146 
147 
156  ConcurrentMap (Updater_t&& updater,
157  size_type capacity = 64,
158  const Context_t& ctx = Updater_t::defaultContext());
159 
170  ConcurrentMap (const ConcurrentMap& other,
171  Updater_t&& updater,
172  size_t capacity = 64,
173  const Context_t& ctx = Updater_t::defaultContext());
174 
175 
188  template <class InputIterator>
189  ConcurrentMap (InputIterator f,
190  InputIterator l,
191  Updater_t&& updater,
192  size_type capacity = 64,
193  const Context_t& ctx = Updater_t::defaultContext());
194 
195 
197  ConcurrentMap (const ConcurrentMap& other) = delete;
198  ConcurrentMap (ConcurrentMap&& other) = delete;
199  ConcurrentMap& operator= (const ConcurrentMap& other) = delete;
200  ConcurrentMap& operator= (ConcurrentMap&& other) = delete;
201 
202 
206  ~ConcurrentMap() = default;
207 
208 
212  size_type size() const;
213 
214 
218  bool empty() const;
219 
220 
224  size_t capacity() const;
225 
226 
230  size_t erased() const;
231 
232 
236  using const_iterator_value = std::pair<const key_type, mapped_type>;
237 
238 
248  class const_iterator
249  : public boost::iterator_facade<const_iterator,
250  const const_iterator_value,
251  std::bidirectional_iterator_tag,
252  const const_iterator_value>
253  {
254  public:
259  const_iterator (typename Impl_t::const_iterator it);
260 
261 
267  bool valid() const;
268 
269 
270  private:
272  friend class boost::iterator_core_access;
273 
274 
278  void increment();
279 
280 
284  void decrement();
285 
286 
290  bool equal (const const_iterator& other) const;
291 
292 
296  const const_iterator_value dereference() const;
297 
298 
300  typename Impl_t::const_iterator m_impl;
301  };
302 
303 
305  typedef boost::iterator_range<const_iterator> const_iterator_range;
306 
307 
311  const_iterator_range range() const;
312 
313 
317  const_iterator begin() const;
318 
319 
323  const_iterator end() const;
324 
325 
329  const_iterator cbegin() const;
330 
331 
335  const_iterator cend() const;
336 
337 
342  bool contains (key_type key) const;
343 
344 
351  size_type count (key_type key) const;
352 
353 
360  const_iterator find (key_type key) const;
361 
362 
370  mapped_type at (key_type key) const;
371 
372 
380  std::pair<const_iterator, const_iterator>
381  equal_range (key_type key) const;
382 
383 
392  Lock_t lock();
393 
394 
406  std::pair<const_iterator, bool>
407  emplace (key_type key, mapped_type val,
408  const Context_t& ctx = Updater_t::defaultContext());
409 
410 
423  std::pair<const_iterator, bool>
424  emplace (const Lock_t& lock,
425  key_type key, mapped_type val,
426  const Context_t& ctx = Updater_t::defaultContext());
427 
428 
440  std::pair<const_iterator, bool>
441  insert_or_assign (key_type key, mapped_type val,
442  const Context_t& ctx = Updater_t::defaultContext());
443 
444 
458  std::pair<const_iterator, bool>
459  insert_or_assign (const Lock_t& lock,
460  key_type key, mapped_type val,
461  const Context_t& ctx = Updater_t::defaultContext());
462 
463 
477  template <class PAIR>
478  std::pair<const_iterator, bool> insert (const PAIR& p);
479 
480 
489  template <class InputIterator>
490  void insert (InputIterator first, InputIterator last);
491 
492 
505  bool erase (key_type key);
506 
507 
521  bool erase (const Lock_t& lock, key_type key);
522 
523 
532  void reserve (size_type capacity,
533  const Context_t& ctx = Updater_t::defaultContext());
534 
535 
543  void rehash (size_type capacity);
544 
545 
551  void clear (size_t capacity,
552  const Context_t& ctx = Updater_t::defaultContext());
553 
554 
559  void clear (const Context_t& ctx = Updater_t::defaultContext());
560 
561 
570  void forceClear();
571 
572 
578  void quiescent (const Context_t& ctx);
579 
580 
592  void swap (ConcurrentMap& other);
593 
594 
598  Updater_t& updater();
599 
600 
601 private:
606  static key_type keyAsKey (val_t val);
607 
608 
613  static val_t keyAsVal (key_type k);
614 
615 
620  static mapped_type mappedAsMapped (val_t val);
621 
622 
627  static val_t mappedAsVal (mapped_type val);
628 
629 
637  typename Impl_t::const_iterator get (key_type key) const;
638 
639 
651  std::pair<const_iterator, bool>
652  put (key_type key,
653  mapped_type val,
654  bool overwrite = true,
655  const Context_t& ctx = Updater_t::defaultContext());
656 
657 
670  std::pair<const_iterator, bool>
671  put (const Lock_t& lock,
672  key_type key,
673  mapped_type val,
674  bool overwrite = true,
675  const Context_t& ctx = Updater_t::defaultContext());
676 
677 
679  Impl_t m_impl;
680 };

◆ ATH_REQUIRES() [2/5]

template<class KEY , class VALUE , template< class > class UPDATER, class HASHER = std::hash<KEY>, class MATCHER = std::equal_to<KEY>, detail::ConcurrentHashmapVal_t NULLVAL = 0>
CxxUtils::ATH_REQUIRES ( detail::IsConcurrentHashmapPayload< KEY > &&detail::IsUpdater< UPDATER > &&detail::IsHash< HASHER, KEY > &&detail::IsBinaryPredicate< MATCHER, KEY >  )

Hash map from pointers/integers to arbitrary objects allowing concurrent, lockless reads.

This class implements a hash map, using keys that may be pointers or any integer type that can fit in an uintptr_t. The mapped type is arbitrary. It allows for concurrent access from many threads. Reads can proceed without taking out a lock, while writes are serialized with each other. Thus, this is appropriate for maps which are read-mostly.

This class includes non-const references that can be used to obtain non-const references to the mapped objects. Howeer, the mapped objects must themselves the thread-safe in order to safely modify them in a multithreaded context.

This is based on ConcurrentHashmapImpl.

Besides the key and mapped value types, this class is templated on an UPDATER class, which is used to manage the underlying memory. See IsUpdater.h for details. (AthenaKernel/RCUUpdater is a concrete version that should work in the context of Athena.)

The operations used for calculating the hash of the keys and comparing keys can be customized with the HASHER and MATCHER template arguments (though the defaults should usually be fine).

One value of the key must be reserved as a null value, which no real keys may take. By default this is ‘0’, but it may be customized with the NULLVAL template argument. Note that the type of the NULLPTR template argument is a uintptr_t, not KEY.

This mostly supports the interface of std::unordered_map, with a few differences / omissions:

  • Dereferencing the iterator returns a structure by value, not a reference.
  • No try_emplace.
  • No insert methods with hints.
  • No clear / erase / overwrite. Those could be implemented if needed (but would require some extra complexity in the memory management).
  • No operator==.
  • Nothing dealing with the bucket/node interface or merge().

The mapped value can be given as any of:

  • A value or const reference. In that case, it needs to be copy-constructable.
  • A rvalue-reference. In that case, it needs to be movable.
  • A unique_ptr to an instance.

I.e., any of these should work:

CxxUtils::ConcurrentToValMap<int, Payload> map;
const Payload p (1);
map.emplace (1, p); // By value / const reference
map.emplace (2, Payload (2)); // By rvalue-reference.
// Could also move() an instance.
map.emplace (3, std::make_unique<Payload> (3)); // By unique_ptr.

Representation type in the underlying map.

The underlying uint->uint hash table.

Standard STL types.

Updater object.

Context type.

Constructor.

Parameters
updaterObject used to manage memory (see comments at the start of the class).
capacityThe initial table capacity. (Will be rounded up to a power of two.)
ctxExecution context.

Constructor from another map.

Parameters
updaterObject used to manage memory (see comments at the start of the class).
capacityThe initial table capacity of the new table. (Will be rounded up to a power of two.)
ctxExecution context.

(Not really a copy constructor since we need to pass updater.)

Constructor from a range.

Parameters
fStart iterator for the range.
lEnd iterator for the range.
updaterObject used to manage memory (see comments at the start of the class).
capacityThe initial table capacity of the new table. (Will be rounded up to a power of two.)
ctxExecution context.

Constructor from a range of pairs.

Copy / move / assign not supported.

Destructor.

Return the number of items currently in the map.

Test if the map is currently empty.

Return the current size (capacity) of the hash table.

Value structures for iterators.

For a map from K to V, a STL-style iterator should dereference to a std::pair<const K, V>. However, we don't actually store an object like that anywhere. In order to be able to have STL-like iterators, we instead use a pair where the second element is a const reference to the mapped value. We will return this by value when we deference an iterator. (The compiler should be able to optimize out the redundant packing and unpacking of fields.)

Const iterator class.

This uses boost::iterator_facade to define the methods required by an STL iterator in terms of the private methods below.

Since dereference() will be returning a const_iterator_value by value, we also need to override the reference type.

Constructor.

Parameters
itIterator of the underlying table.

Conversion from non-const iterator (for interoperability).

Parameters
otherThe other iterator.

Test if this iterator is valid.

This should be the same as testing for != end().

Required by iterator_facade.

iterator_facade requirement: Increment the iterator.

iterator_facade requirement: Decrement the iterator.

iterator_facade requirement: Equality test.

iterator_facade requirement: Equality test. (Interoperability.)

iterator_facade requirement: Dereference the iterator.

The iterator on the underlying table.

Iterator class.

This uses boost::iterator_facade to define the methods required by an STL iterator in terms of the private methods below.

Since dereference() will be returning a iterator_value by value, we also need to override the reference type.

From this, we can get a non-const reference to the mapped object. The mapped object must be thread-safe itself in order to safely make any changes to it.

Constructor.

Parameters
itIterator of the underlying table.

Test if this iterator is valid.

This should be the same as testing for != end().

Required by iterator_facade.

iterator_facade requirement: Increment the iterator.

iterator_facade requirement: Decrement the iterator.

iterator_facade requirement: Equality test.

iterator_facade requirement: Equality test. (Interoperability.)

iterator_facade requirement: Dereference the iterator.

The iterator on the underlying table.

A range defined by two iterators.

Return an iterator range covering the entire map.

Return an iterator range covering the entire map.

The mapped objects must themselves be thread-safe in order to make any changes to them through the returned iterators.

Iterator at the start of the map.

Iterator at the end of the map.

Iterator at the start of the map.

The mapped objects must themselves be thread-safe in order to make any changes to them through the returned iterators.

Iterator at the end of the map.

The mapped objects must themselves be thread-safe in order to make any changes to them through the returned iterators.

Iterator at the start of the map.

Iterator at the end of the map.

Test if a key is in the container.

Parameters
keyThe key to test.

Return the number of times a given key is in the container.

Parameters
keyThe key to test.

Returns either 0 or 1, depending on whether or not the key is in the map.

Look up an element in the map.

Parameters
keyThe element to find.

Returns either an iterator referencing the found element or end().

Look up an element in the map.

Parameters
keyThe element to find.

Returns either an iterator referencing the found element or end().

The mapped object must itself be thread-safe in order to make any changes to it through the returned iterator.

Look up an element in the map.

Parameters
keyThe element to find.

Returns the value associated with the key. Throws std::out_of_range if the key does not exist in the map.

Look up an element in the map.

Parameters
keyThe element to find.

Returns the value associated with the key. Throws std::out_of_range if the key does not exist in the map.

This returns a non-const reference to the mapped object. The mapped object must be thread-safe itself in order to safely make any changes to it.

Return a range of iterators with entries matching key.

Parameters
keyThe element to find.

As keys are unique in this container, this is either a single-element range, or both iterators are equal to end().

Return a range of iterators with entries matching key.

Parameters
keyThe element to find.

As keys are unique in this container, this is either a single-element range, or both iterators are equal to end().

The mapped objects must themselves be thread-safe in order to make any changes to them through the returned iterators.

Add an element to the map.

Parameters
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map.

Parameters
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map.

Parameters
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map.

Parameters
pThe item to add. Should be a pair where first is the string key and second is the integer value.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map.

Parameters
pThe item to add. Should be a pair where first is the string key and second is the integer value.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Insert a range of elements to the map.

Parameters
firstStart of the range.
lastEnd of the range.
ctxExecution context.

The range should be a sequence of pairs where first is the string key and second is the integer value.

Increase the table capacity.

Parameters
capacityThe new table capacity.
ctxExecution context.

No action will be taken if capacity is smaller than the current capacity.

Increase the table capacity.

Parameters
capacityThe new table capacity.

No action will be taken if capacity is smaller than the current capacity.

Called when this thread is no longer referencing anything from this container.

Parameters
ctxExecution context.

Swap this container with another.

Parameters
otherThe container with which to swap.

This will also call swap on the Updater object; hence, the Updater object must also support swap.

This operation is NOT thread-safe. No other threads may be accessing either container during this operation.

Access the Updater instance.

Convert an underlying key value to this type's key value.

Parameters
valThe underlying key value.

Convert this type's key value to an underlying key value.

Parameters
kThe key.

Convert an underlying mapped value a pointer to this type's mapped value.

Parameters
valThe underlying mapped value.

Convert this type's mapped value to an underlying mapped value.

Parameters
valThe mapped value.

Do a lookup in the table.

Parameters
keyThe key to look up.

Returns an iterator of the underlying map pointing at the found entry or end();

Insert an entry in the table.

Parameters
keyThe key of the new item to add.
valThe new mapped value to add.
ctxExecution context.

The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

The underlying hash table.

Definition at line 98 of file ConcurrentToValMap.h.

103 {
104 private:
107 
108  // Translate between the Hasher/Matcher provided (which take KEY arguments)
109  // and what we need to give to the underlying implementation
110  // (which takes a uintptr_t).
111  struct Hasher
112  {
113  size_t operator() (val_t k) const {
114  return m_h (keyAsKey (k));
115  }
116  HASHER m_h;
117  };
118  struct Matcher
119  {
120  bool operator() (val_t a, val_t b) const {
121  return m_m (keyAsKey (a), keyAsKey (b));
122  }
123  MATCHER m_m;
124  };
125 
127  using Impl_t = typename detail::ConcurrentHashmapImpl<UPDATER,
128  Hasher,
129  Matcher,
130  NULLVAL>;
131 
132 
133 public:
135  using key_type = KEY;
136  using mapped_type = VALUE;
137  using size_type = size_t;
139  using Updater_t = typename Impl_t::Updater_t;
141  using Context_t = typename Updater_t::Context_t;
142 
143 
152  ConcurrentToValMap (Updater_t&& updater,
153  size_type capacity = 64,
154  const Context_t& ctx = Updater_t::defaultContext());
155 
156 
167  ConcurrentToValMap (const ConcurrentToValMap& other,
168  Updater_t&& updater,
169  size_t capacity = 64,
170  const Context_t& ctx = Updater_t::defaultContext());
171 
172 
185  template <class InputIterator>
186  ConcurrentToValMap (InputIterator f,
187  InputIterator l,
188  Updater_t&& updater,
189  size_type capacity = 64,
190  const Context_t& ctx = Updater_t::defaultContext());
191 
192 
194  ConcurrentToValMap (const ConcurrentToValMap& other) = delete;
195  ConcurrentToValMap (ConcurrentToValMap&& other) = delete;
196  ConcurrentToValMap& operator= (const ConcurrentToValMap& other) = delete;
197  ConcurrentToValMap& operator= (ConcurrentToValMap&& other) = delete;
198 
199 
203  ~ConcurrentToValMap();
204 
205 
209  size_type size() const;
210 
211 
215  bool empty() const;
216 
217 
221  size_t capacity() const;
222 
223 
236  using const_iterator_value = std::pair<const key_type, const mapped_type&>;
237  using iterator_value = std::pair<const key_type, mapped_type&>;
238 
239  class const_iterator;
240  class iterator;
241 
242 
252  class const_iterator
253  : public boost::iterator_facade<const_iterator,
254  const const_iterator_value,
255  std::bidirectional_iterator_tag,
256  const const_iterator_value>
257  {
258  public:
263  const_iterator (typename Impl_t::const_iterator it);
264 
265 
270  const_iterator (const iterator& other);
271 
272 
278  bool valid() const;
279 
280 
281  private:
283  friend class boost::iterator_core_access;
284  friend class iterator;
285 
286 
290  void increment();
291 
292 
296  void decrement();
297 
298 
302  bool equal (const const_iterator& other) const;
303 
304 
308  bool equal (const iterator& other) const;
309 
310 
314  const const_iterator_value dereference() const;
315 
316 
318  typename Impl_t::const_iterator m_impl;
319  };
320 
321 
335  class iterator
336  : public boost::iterator_facade<iterator,
337  const iterator_value,
338  std::bidirectional_iterator_tag,
339  const iterator_value>
340  {
341  public:
346  iterator (typename Impl_t::const_iterator it);
347 
348 
354  bool valid() const;
355 
356 
357  private:
359  friend class boost::iterator_core_access;
360  friend class const_iterator;
361 
362 
366  void increment();
367 
368 
372  void decrement();
373 
374 
378  bool equal (const iterator& other) const;
379 
380 
384  bool equal (const const_iterator& other) const;
385 
386 
390  const iterator_value dereference() const;
391 
392 
394  typename Impl_t::const_iterator m_impl;
395  };
396 
397 
399  typedef boost::iterator_range<const_iterator> const_iterator_range;
400  typedef boost::iterator_range<iterator> iterator_range;
401 
402 
406  const_iterator_range range() const;
407 
408 
415  iterator_range range();
416 
417 
421  const_iterator begin() const;
422 
423 
427  const_iterator end() const;
428 
429 
436  iterator begin();
437 
438 
445  iterator end();
446 
447 
451  const_iterator cbegin() const;
452 
453 
457  const_iterator cend() const;
458 
459 
464  bool contains (const key_type key) const;
465 
466 
473  size_type count (const key_type key) const;
474 
475 
482  const_iterator find (const key_type key) const;
483 
484 
494  iterator find (const key_type key);
495 
496 
504  const mapped_type& at (const key_type key) const;
505 
506 
518  mapped_type& at (const key_type key);
519 
520 
528  std::pair<const_iterator, const_iterator>
529  equal_range (const key_type key) const;
530 
531 
542  std::pair<iterator, iterator>
543  equal_range (const key_type key);
544 
545 
557  std::pair<const_iterator, bool>
558  emplace (key_type key, const mapped_type& val,
559  const Context_t& ctx = Updater_t::defaultContext());
560 
561 
573  std::pair<const_iterator, bool>
574  emplace (key_type key, mapped_type&& val,
575  const Context_t& ctx = Updater_t::defaultContext());
576 
577 
589  std::pair<const_iterator, bool>
590  emplace (key_type key, std::unique_ptr<mapped_type> val,
591  const Context_t& ctx = Updater_t::defaultContext());
592 
593 
606  template <class PAIR>
607  std::pair<const_iterator, bool> insert (const PAIR& p,
608  const Context_t& ctx = Updater_t::defaultContext());
609 
610 
623  template <class PAIR>
624  std::pair<const_iterator, bool> insert (PAIR&& p,
625  const Context_t& ctx = Updater_t::defaultContext());
626 
627 
637  template <class InputIterator>
638  void insert (InputIterator first, InputIterator last,
639  const Context_t& ctx = Updater_t::defaultContext());
640 
641 
650  void reserve (size_type capacity,
651  const Context_t& ctx = Updater_t::defaultContext());
652 
653 
661  void rehash (size_type capacity);
662 
663 
669  void quiescent (const Context_t& ctx);
670 
671 
682  void swap (ConcurrentToValMap& other);
683 
684 
688  Updater_t& updater();
689 
690 
691 private:
696  static key_type keyAsKey (val_t val);
697 
698 
703  static val_t keyAsVal (key_type k);
704 
705 
711  static mapped_type* mappedAsMapped (val_t val);
712 
713 
718  static val_t mappedAsVal (mapped_type* val);
719 
720 
728  typename Impl_t::const_iterator get (const key_type key) const;
729 
730 
741  std::pair<const_iterator, bool>
742  put (const key_type key,
743  std::unique_ptr<mapped_type> val,
744  const Context_t& ctx = Updater_t::defaultContext());
745 
746 
748  Impl_t m_impl;
749 };

◆ ATH_REQUIRES() [3/5]

template<class VALUE , template< class > class UPDATER>
CxxUtils::ATH_REQUIRES ( detail::IsConcurrentHashmapPayload< VALUE > &&detail::IsUpdater< UPDATER >  )

Hash map from strings allowing concurrent, lockless reads.

This class implements a hash map from strings. The mapped type may be a pointer or any numeric type that can fit in a uintptr_t. It allows for concurrent access from many threads. Reads can proceed without taking out a lock, while writes are serialized with each other. Thus, this is appropriate for maps which are read-mostly.

This is based on ConcurrentHashmapImpl.

Besides the mapped value type, this class is templated on an UPDATER class, which is used to manage the underlying memory. See IsUpdater.h for details. (AthenaKernel/RCUUpdater is a concrete version that should work in the context of Athena.)

This mostly supports the interface of std::unordered_map, with a few differences / omissions:

  • Dereferencing the iterator returns a structure by value, not a reference.
  • No try_emplace.
  • No insert methods with hints.
  • No clear(). Could be implemented if really needed; we would need to be able to attach the key strings to be deleted to the old table instance.
  • No erase() methods. In addition to what's needed for clear(), the underlying hash table would need to support tombstones.
  • No operator==.
  • Nothing dealing with the bucket/node interface or merge().

Possible improvements:

  • We could speed up lookups further by storing the hash along with the string. That way, we should almost always not have to do the full string comparison more than once.
  • We could use a more efficient allocator for the string keys that we need to save. That could in particular help for updates, where currently we always need to allocate a string, and then need to delete it if it turns out we're doing an update rather than in insertion.

The underlying uint->uint hash table.

Representation type in the underlying map.

Standard STL types.

Updater object.

Context type.

Type for external locking.

Ensure that the underlying map can store our mapped_type.

Constructor.

Parameters
updaterObject used to manage memory (see comments at the start of the class).
capacityThe initial table capacity. (Will be rounded up to a power of two.)
ctxExecution context.

Constructor from another map.

Parameters
updaterObject used to manage memory (see comments at the start of the class).
capacityThe initial table capacity of the new table. (Will be rounded up to a power of two.)
ctxExecution context.

(Not really a copy constructor since we need to pass updater.)

Constructor from a range.

Parameters
fStart iterator for the range.
lEnd iterator for the range.
updaterObject used to manage memory (see comments at the start of the class).
capacityThe initial table capacity of the new table. (Will be rounded up to a power of two.)
ctxExecution context.

Constructor from a range of pairs.

Copy / move / assign not supported.

Destructor.

Return the number of items currently in the map.

Test if the map is currently empty.

Return the current size (capacity) of the hash table.

Value structure for iterators.

For a map from K to V, a STL-style iterator should dereference to a std::pair<const K, V>. However, we don't actually store an object like that anywhere. In order to be able to have STL-like iterators, we instead use a pair where the first element is a const reference to the std::string key. We will return this by value when we deference an iterator. (The compiler should be able to optimize out the redundant packing and unpacking of fields.)

Iterator class.

This uses boost::iterator_facade to define the methods required by an STL iterator in terms of the private methods below.

Since dereference() will be returning a const_iterator_value by value, we also need to override the reference type.

Constructor.

Parameters
itIterator of the underlying table.

Test if this iterator is valid.

This should be the same as testing for != end().

Required by iterator_facade.

iterator_facade requirement: Increment the iterator.

iterator_facade requirement: Decrement the iterator.

iterator_facade requirement: Equality test.

iterator_facade requirement: Dereference the iterator.

The iterator on the underlying table.

A range defined by two iterators.

Return an iterator range covering the entire map.

Iterator at the start of the map.

Iterator at the end of the map.

Iterator at the start of the map.

Iterator at the end of the map.

Test if a key is in the container.

Parameters
keyThe key to test.

Return the number of times a given key is in the container.

Parameters
keyThe key to test.

Returns either 0 or 1, depending on whether or not the key is in the map.

Look up an element in the map.

Parameters
keyThe element to find.

Returns either an iterator referencing the found element or end().

Look up an element in the map.

Parameters
keyThe element to find.

Returns the value associated with the key. Throws std::out_of_range if the key does not exist in the map.

Return a range of iterators with entries matching key.

Parameters
keyThe element to find.

As keys are unique in this container, this is either a single-element range, or both iterators are equal to end().

Take a lock on the container.

Take a lock on the container. The lock can then be passed to insertion methods, allowing to factor out the locking inside loops. The lock will be released when the lock object is destroyed.

Add an element to the map.

Parameters
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map, with external locking.

Parameters
lockThe lock object returned from lock().
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map.

Parameters
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map, with external locking.

Parameters
lockThe lock object returned from lock().
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map, or overwrite an existing one.

Parameters
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map, or overwrite an existing one, with external locking.

Parameters
lockThe lock object returned from lock().
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map, or overwrite an existing one.

Parameters
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map, or overwrite an existing one, with external locking.

Parameters
lockThe lock object returned from lock().
keyThe key of the new item to add.
valThe value of the new item to add.
ctxExecution context.

This will overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Add an element to the map.

Parameters
pThe item to add. Should be a pair where first is the string key and second is the integer value.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

For external locking, use emplace().

Add an element to the map.

Parameters
pThe item to add. Should be a pair where first is the string key and second is the integer value.
ctxExecution context.

This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Insert a range of elements to the map.

Parameters
firstStart of the range.
lastEnd of the range.
ctxExecution context.

The range should be a sequence of pairs where first is the string key and second is the integer value.

Increase the table capacity.

Parameters
capacityThe new table capacity.
ctxExecution context.

No action will be taken if capacity is smaller than the current capacity.

Increase the table capacity.

Parameters
capacityThe new table capacity.

No action will be taken if capacity is smaller than the current capacity.

Called when this thread is no longer referencing anything from this container.

Parameters
ctxExecution context.

Swap this container with another.

Parameters
otherThe container with which to swap.

This will also call swap on the Updater object; hence, the Updater object must also support swap.

This operation is NOT thread-safe. No other threads may be accessing either container during this operation.

Access the Updater instance.

Convert an underlying key value to a string pointer.

Parameters
valThe underlying key value.

Convert a string pointer to an underlying key value.

Parameters
sThe string pointer.

Convert an underlying mapped value to this type's mapped value.

Parameters
valThe underlying mapped value.

Convert this type's mapped value to an underlying mapped value.

Parameters
valThe mapped value.

Do a lookup in the table.

Parameters
keyThe key to look up.

Returns an iterator of the underlying map pointing at the found entry or end();

Insert / overwrite an entry in the table.

Parameters
keyThe key of the new item to add.
valThe value of the new item to add.
overwriteIf true, allow overwriting an existing entry.
ctxExecution context.

The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Insert / overwrite an entry in the table, with external locking.

Parameters
lockThe lock object returned from lock().
valThe value of the new item to add.
overwriteIf true, allow overwriting an existing entry.
ctxExecution context.

The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.

Hash functional for keys.

The key can be either a std::string or the representation type used by the underlying map.

Hash function from the underlying representation type.

Hash function from a std::string.

Hash functional.

Matching functional for keys.

Compare two keys (as the underlying representation type) for equality.

The underlying hash table.

Definition at line 75 of file ConcurrentStrMap.h.

78 {
79 private:
81  struct Hasher;
82  struct Matcher;
83  using Impl_t = typename detail::ConcurrentHashmapImpl<UPDATER, Hasher, Matcher>;
86 
87 
88 public:
90  using key_type = std::string;
91  using mapped_type = VALUE;
92  using size_type = size_t;
94  using Updater_t = typename Impl_t::Updater_t;
96  using Context_t = typename Updater_t::Context_t;
98  using Lock_t = typename Impl_t::Lock_t;
99 
101  static_assert( sizeof(typename Impl_t::val_t) >= sizeof(mapped_type) );
102 
103 
112  ConcurrentStrMap (Updater_t&& updater,
113  size_type capacity = 64,
114  const Context_t& ctx = Updater_t::defaultContext());
115 
126  ConcurrentStrMap (const ConcurrentStrMap& other,
127  Updater_t&& updater,
128  size_t capacity = 64,
129  const Context_t& ctx = Updater_t::defaultContext());
130 
131 
144  template <class InputIterator>
145  ConcurrentStrMap (InputIterator f,
146  InputIterator l,
147  Updater_t&& updater,
148  size_type capacity = 64,
149  const Context_t& ctx = Updater_t::defaultContext());
150 
151 
153  ConcurrentStrMap (const ConcurrentStrMap& other) = delete;
154  ConcurrentStrMap (ConcurrentStrMap&& other) = delete;
155  ConcurrentStrMap& operator= (const ConcurrentStrMap& other) = delete;
156  ConcurrentStrMap& operator= (ConcurrentStrMap&& other) = delete;
157 
158 
162  ~ConcurrentStrMap();
163 
164 
168  size_type size() const;
169 
170 
174  bool empty() const;
175 
176 
180  size_t capacity() const;
181 
182 
195  using const_iterator_value = std::pair<const key_type&, mapped_type>;
196 
197 
207  class const_iterator
208  : public boost::iterator_facade<const_iterator,
209  const const_iterator_value,
210  std::bidirectional_iterator_tag,
211  const const_iterator_value>
212  {
213  public:
218  const_iterator (typename Impl_t::const_iterator it);
219 
220 
226  bool valid() const;
227 
228 
229  private:
231  friend class boost::iterator_core_access;
232 
233 
237  void increment();
238 
239 
243  void decrement();
244 
245 
249  bool equal (const const_iterator& other) const;
250 
251 
255  const const_iterator_value dereference() const;
256 
257 
259  typename Impl_t::const_iterator m_impl;
260  };
261 
262 
264  typedef boost::iterator_range<const_iterator> const_iterator_range;
265 
266 
270  const_iterator_range range() const;
271 
272 
276  const_iterator begin() const;
277 
278 
282  const_iterator end() const;
283 
284 
288  const_iterator cbegin() const;
289 
290 
294  const_iterator cend() const;
295 
296 
301  bool contains (const key_type& key) const;
302 
303 
310  size_type count (const key_type& key) const;
311 
312 
319  const_iterator find (const key_type& key) const;
320 
321 
329  mapped_type at (const std::string& key) const;
330 
331 
339  std::pair<const_iterator, const_iterator>
340  equal_range (const key_type& key) const;
341 
342 
351  Lock_t lock();
352 
353 
365  std::pair<const_iterator, bool>
366  emplace (const key_type& key, mapped_type val,
367  const Context_t& ctx = Updater_t::defaultContext());
368 
369 
382  std::pair<const_iterator, bool>
383  emplace (const Lock_t& lock,
384  const key_type& key, mapped_type val,
385  const Context_t& ctx = Updater_t::defaultContext());
386 
387 
399  std::pair<const_iterator, bool>
400  emplace (key_type&& key, mapped_type val,
401  const Context_t& ctx = Updater_t::defaultContext());
402 
403 
416  std::pair<const_iterator, bool>
417  emplace (const Lock_t& lock,
418  key_type&& key, mapped_type val,
419  const Context_t& ctx = Updater_t::defaultContext());
420 
421 
433  std::pair<const_iterator, bool>
434  insert_or_assign (const key_type& key, mapped_type val,
435  const Context_t& ctx = Updater_t::defaultContext());
436 
437 
451  std::pair<const_iterator, bool>
452  insert_or_assign (const Lock_t& lock,
453  const key_type& key, mapped_type val,
454  const Context_t& ctx = Updater_t::defaultContext());
455 
456 
468  std::pair<const_iterator, bool>
469  insert_or_assign (key_type&& key, mapped_type val,
470  const Context_t& ctx = Updater_t::defaultContext());
471 
472 
486  std::pair<const_iterator, bool>
487  insert_or_assign (const Lock_t& lock,
488  key_type&& key, mapped_type val,
489  const Context_t& ctx = Updater_t::defaultContext());
490 
491 
506  template <class PAIR>
507  std::pair<const_iterator, bool> insert (const PAIR& p,
508  const Context_t& ctx = Updater_t::defaultContext());
509 
510 
523  template <class PAIR>
524  std::pair<const_iterator, bool> insert (PAIR&& p,
525  const Context_t& ctx = Updater_t::defaultContext());
526 
527 
537  template <class InputIterator>
538  void insert (InputIterator first, InputIterator last,
539  const Context_t& ctx = Updater_t::defaultContext());
540 
541 
550  void reserve (size_type capacity,
551  const Context_t& ctx = Updater_t::defaultContext());
552 
553 
561  void rehash (size_type capacity);
562 
563 
569  void quiescent (const Context_t& ctx);
570 
571 
582  void swap (ConcurrentStrMap& other);
583 
584 
588  Updater_t& updater();
589 
590 
591 private:
596  static const std::string* keyAsString (val_t val);
597 
598 
603  static val_t keyAsVal (const std::string* s);
604 
605 
610  static mapped_type mappedAsMapped (val_t val);
611 
612 
617  static val_t mappedAsVal (mapped_type val);
618 
619 
627  typename Impl_t::const_iterator get (const key_type& key) const;
628 
629 
641  std::pair<const_iterator, bool>
642  put (std::unique_ptr<key_type> key,
643  mapped_type val,
644  bool overwrite = true,
645  const Context_t& ctx = Updater_t::defaultContext());
646 
647 
659  std::pair<const_iterator, bool>
660  put (const Lock_t& lock,
661  std::unique_ptr<key_type> key,
662  mapped_type val,
663  bool overwrite = true,
664  const Context_t& ctx = Updater_t::defaultContext());
665 
666 
673  struct Hasher
674  {
676  size_t operator() (const val_t p) const;
678  size_t operator() (const std::string& s) const;
680  std::hash<std::string> m_hash;
681  };
682 
683 
687  struct Matcher
688  {
690  bool operator() (const val_t a, const val_t b) const;
691  };
692 
693 
695  Impl_t m_impl;
696 };

◆ ATH_REQUIRES() [4/5]

template<class RANGE , class KEY , class T , class COMPARE , template< class > class UPDATER>
CxxUtils::ATH_REQUIRES ( detail::IsUpdater< UPDATER > &&detail::IsConcurrentRangeCompare< COMPARE, RANGE, KEY, typename UPDATER< int >::Context_t >  )

Map from range to payload object, allowing concurrent, lockless reads.

This class implements a map of sorted ‘range’ objects (though only a single value is actually used) to allocated payload objects. Values can be looked up by a key; the value returned will be the first for which the range is not less than the key. We also support insertions, erasures, and iteration.

The only thing we need to do with the contained pointers is to delete them. Rather than doing that directly, we take a deletion object as an argument to the constructor. This allows one to instantiate this template with void as T, to reduce the amount of generated code. The emplace method takes a unique_ptr as an argument. We define payload_unique_ptr which is a unique_ptr to T that does deletion by calling an arbitrary function. payload_unique_ptr may be initialized from a unique_ptr; to construct one directly, the deletion function should be passed as a second argument to the payload_unique_ptr constructor.

There can be only one writer at a time; this is enforced with internal locks. However, there can be any number of concurrent readers at any time. The reads are lockless (but not necessarily waitless, though this should not be significant in practice). So this is appropriate when reads are much more frequent than writes.

This implementation also assumes that a lookup is most likely to be for the last element in the map, that insertions are most likely to be at the end, and that erasures are most likely to be from the beginning. This class will still work if these assumptions are violated, but it may be much slower. (The use case for which this was targeted was that of conditions containers.)

Template arguments: RANGE - The type of the range object stored with each element. KEY - The type used to look up objects in the container. This may be same as RANGE, but not necessarily. (For example, RANGE may contain start and end times, while KEY may be a single time.) COMPARE - Object used for key comparisons; see below. UPDATER - Object used for memory management; see below.

COMPARE should implement a less-than relation, like a typical STL comparison object, with these signatures:

bool operator() (const KEY& k1, const RANGE& r2) const;
bool operator() (const RANGE& r1, const RANGE& r2) const;
bool inRange (const KEY& k, const RANGE& r) const;
// Test if two ranges overlap, and adjust if needed.
// OLDRANGE is an existing range in the container, and NEWRANGE
// is a new one being added. Return one of:
// 0 -- no overlap between the ranges; NEWRANGE is unmodified.
// 1 -- ranges overlap. NEWRANGE has been adjusted to avoid the overlap.
// If the start of NEWRANGE is changed, it must
// only be moved forward (increased), never backwards.
// -1 -- duplicate: NEWRANGE is entirely inside OLDRANGE.
// Delete the new range.
int overlap (const Context_t& ctx,
const RANGE& oldRange, RANGE& newRange) const;
// Possibly extend an existing range at the end.
// RANGE is the existing range, and NEWRANGE is the range
// being added. Returns one of:
// Required only for extendLastRange --- which see.
// 0 -- no change was made to RANGE.
// 1 -- RANGE was extended.
// -1 -- newRange is a duplicate.
int extendRange (Range& range, const Range& newRange) const;

In order to implement updating concurrently with reading, we need to defer deletion of objects until no thread can be referencing them any more. The policy for this for the internal implementation objects is set by the template UPDATER<T>. For details, see IsUpdater.h.

Deletion of payload objects is managed via the IRangeMapPayloadDeleter object passed to the constructor.

Implementation notes: The values we store are pairs of RANGE, const T*. The data are stored in a vector of such values. We maintain atomic pointers to the first and last valid elements in the map. We can quickly add an element to the end or delete an element from the beginning by adjusting these pointers. Any other changes will require making a new copy of the data vector.

Function to delete a T*

unique_ptr deletion class for a payload object.

We can't use the unique_ptr default because we want to allow instantiating with a void.

Initialize with an explicit deletion function.

Allow initializing a payload_unique_ptr from a std::unique_ptr<U>.

Delete a pointer.

The deletion function.

unique_ptr holding a payload object.

One may initialize an instance of this in one of two ways. First, from another std::unique_ptr:

payload_unique_ptr p = std::unique_ptr<U> (...);

where U* must be convertible to T*. In this case, the pointer will be deleted as a U*. Second, one can supply an explicit deletion function:

T* tp = ...;
payload_unique_ptr p (tp, delfcn);

Holds one version of the map.

This object holds one version of the map. Within a single version, we can add elements to the end or remove elements from the beginning. If we need to make other changes, or to expand the map, we must make a new version and copy the contents. The UPDATER object is then used to install the new version; old versions should be kept until they are no longer referenced by any thread.

Constructor.

Parameters
capacitySize of the data vector to allocate.

Destructor.

Return a pointer to the start of the data vector.

Return the size of the current data vector.

Vector holding the map data.

Constructor.

Parameters
updaterObject used to manage memory (see comments at the start of the class).
payloadDeleterObject for deleting payload objects. This is owned via a shared_ptr.
capacityInitial capacity of the map.
compareComparison object.

Destructor.

Clean up any remaining payload objects.

Return a reference to the payload deleter object.

Return a reference to the payload deleter object.

Search for the first item less than or equal to KEY.

Parameters
keyThe key to search for.
Returns
The value, or nullptr if not found.

Results returned from emplace().

All ok.

New object was added, but overlaps with an existing range.

New object duplicates an existing range, and was not added.

Add a new element to the map.

Parameters
rangeValidity range for this element.
ptrPayload for this element.
tryExtendIf true, then allow an existing range to be extended (see below).
ctxExecution context.

Returns SUCCESS if the new element was successfully inserted. Returns DUPLICATE if the range compared equal to an existing one. In that case, no new element is inserted (and ptr gets deleted). Returns EXTEND if the range of the last element was extended to range. This happens if tryExtend is true, range is equal to the range of the last element (according to m_compare), and the range can be extended according to extendRange. (This will generally mean that the start time of range matches the last range, and end time of range is after the end time of the last range.) In this case, again no new element is inserted and ptr is deleted. Returns OVERLAP if the range of the new element overlaps an existing element (the new element is still inserted).

Erase the first item less than or equal to KEY.

Parameters
keyThe key to search erase.
ctxExecution context.

Extend the range of the last entry of the map.

Parameters
newRangeNew range to use for the last entry.
ctxExecution context.

The range of the last entry in the map is updated to newRange. Does nothing if the map is empty. This will make a new version of implementation data.

The semantics of what it means to extend a range are given by the extendRange method of the COMPARE object (see above).

Returns -1 if there was an error; 1 if the last range was extended; and 0 if nothing was changed.

Update all range objects.

Parameters
rangeUpdaterFunctional to call on each range object.
ctxExecution context.

This will iterate through the list of entries and call rangeUpdater on the RANGE part of each. Be careful: rangeUpdater must not change any part of the range which might affect the sorting of entries.

Remove unused entries from the front of the list.

Parameters
keysList of keys that may still be in use. (Must be sorted.)
trimallIf true, then allow removing all elements in the container. Otherwise, stop when there's one left.

We examine the objects in the container, starting with the earliest one. If none of the keys in keys match the range for this object, then it is removed from the container. We stop when we either find an object with a range matching a key in keys or (if trimall is false) when there is only one object left.

The list keys MUST be sorted.

Removed objects are queued for deletion once all slots have been marked as quiescent.

Returns the number of objects that were removed.

Remove all entries in the container. Mostly for testing — should not normally be used.

Return the current number of elements in the map.

Test if the map is empty.

Return the current capacity of the map.

Return the number times an item was inserted into the map.

Return the maximum size of the map.

Return a range that can be used to iterate over the container.

Called when this thread is no longer referencing anything from this container.

Parameters
ctxExecution context.

Type of the mutex for this container.

Return the begin/last pointers.

Parameters
[in,out]lastCurrent value of last.

Retrieve consistent values of the begin and last pointers. The last pointer should have already been fetched, and may be updated. Usage should be like this:

const_iterator last = m_last;
if (!last) return; // Container empty.
const_iterator begin = getBegin (last);
if (!last) return; // Container empty.

Consistently update both the begin and last pointers.

Parameters
beginNew begin pointer.
endNew end pointer.

Test to see if any keys within keys match r. r Range to test. @break keys List of keys to test. MUST be sorted.

Install a new implementation instance and make it visible.

Parameters
new_implThe new instance.
new_beginBegin pointer for the new instance.
new_endEnd pointer for the new instance. (Usual STL meaning of end. If the instance is empty, then new_end should match new_begin.)
ctxExecution context.

Extend the range of the last entry of the map.

Parameters
Lockobject.
extendedRangeNew range to use for the last entry.
ctxExecution context.

Implementation of extendLastRange; see there for details. Must be called with the lock held.

Updater object. This maintains ownership of the current implementation class and the older versions.

Comparison object.

Payload deleter object. Important: do not discard an object while it's still reachable from the m_begin / m_last range — update the pointers first. Otherwise, the object may be deleted while another thread is still referencing it: thread 1: Discard object. Sets grace mask for both slots. thread 2: Call quiescent(). Clears grace mask for 2. Retrieve the discarded object. thread 1: Adjust pointers. Call quiescent. The discarded object may be deleted at this point while thread 2 is still reading it.

Current version of the implementation class.

Pointers to the first and last elements of the container. m_last is not the usual end pointer; it points at the last element in the container. If the container is empty, then m_last will be null. If these are to both be updated together, it should be done in this order. First, m_begin should be set to null. This marks that there's an update in progress. Then m_last should be set, followed by m_begin. To read both pointers, we first fetch m_last. Then fetch m_begin. Then check that both m_begin is non-null and the previous value we fetched for last matches what's now in m_last. If either condition fails, then re-fetch both pointers.

Some basic statistics.

Mutex protecting the container.

Definition at line 217 of file ConcurrentRangeMap.h.

220 {
221 public:
222  typedef RANGE key_type;
223  typedef const T* mapped_type;
224  typedef std::pair<RANGE, const T*> value_type;
225  typedef const value_type& const_reference;
226  typedef const value_type* const_pointer;
227  typedef size_t size_type;
228  typedef int difference_type;
229  typedef COMPARE key_compare;
230  typedef KEY key_query_type;
231 
232 
234  typedef void delete_function (const T*);
235 
236 
243  struct DeletePayload
244  {
246  // cppcheck-suppress uninitMemberVar // false positive
247  DeletePayload (delete_function* delfcn)
248  : m_delete (delfcn)
249  {
250  }
251 
253  template <class U>
254  static void delfcn (const T* p)
255  {
256  delete reinterpret_cast<const U*>(p);
257  }
258  template <class U>
259  // cppcheck-suppress uninitMemberVar // false positive
260  DeletePayload (const std::default_delete<U>&)
261  {
262  m_delete = delfcn<U>;
263  }
264 
266  void operator() (const T* p) const
267  {
268  m_delete (p);
269  }
270 
272  delete_function* m_delete;
273  };
274 
275 
295  typedef std::unique_ptr<T, DeletePayload> payload_unique_ptr;
296 
297  typedef const value_type* const_iterator;
298  typedef boost::iterator_range<const_iterator> const_iterator_range;
299 
300 
311  class Impl
312  {
313  public:
318  Impl (size_t capacity = 10);
319 
320 
324  ~Impl() = default;
325 
326 
330  value_type* data();
331 
332 
336  size_t capacity() const;
337 
338 
339  private:
341  std::vector<value_type> m_data;
342  };
343 
344  using Updater_t = UPDATER<Impl>;
346 
347 
357  ConcurrentRangeMap (Updater_t&& updater,
358  std::shared_ptr<IPayloadDeleter> payloadDeleter,
359  size_t capacity = 16,
360  const COMPARE& compare = COMPARE());
361 
362 
368  ~ConcurrentRangeMap();
369 
370 
374  IPayloadDeleter& deleter();
375 
376 
380  const IPayloadDeleter& deleter() const;
381 
382 
388  const_iterator find (const key_query_type& key) const;
389 
390 
392  enum class EmplaceResult
393  {
395  SUCCESS,
396 
398  OVERLAP,
399 
401  DUPLICATE,
402 
403  // Existing range was extended to match the new range; new object
404  // was deleted.
405  EXTENDED
406  };
407 
408 
431  EmplaceResult emplace (const RANGE& range,
432  payload_unique_ptr ptr,
433  bool tryExtend = false,
434  const typename Updater_t::Context_t& ctx =
435  Updater_t::defaultContext());
436 
437 
443  void erase (const key_query_type& key,
444  const typename Updater_t::Context_t& ctx =
445  Updater_t::defaultContext());
446 
447 
463  int extendLastRange (const RANGE& newRange,
464  const typename Updater_t::Context_t& ctx =
465  Updater_t::defaultContext());
466 
467 
478  void updateRanges (std::function<void (RANGE&)> rangeUpdater,
479  const typename Updater_t::Context_t& ctx =
480  Updater_t::defaultContext());
481 
482 
503  size_t trim (const std::vector<key_query_type>& keys, bool trimall = false);
504 
505 
510  void clear();
511 
512 
516  size_t size() const;
517 
518 
522  bool empty() const;
523 
524 
528  size_t capacity() const;
529 
530 
534  size_t nInserts() const;
535 
536 
540  size_t maxSize() const;
541 
542 
546  const_iterator_range range() const;
547 
548 
554  void quiescent (const typename Updater_t::Context_t& ctx =
555  Updater_t::defaultContext());
556 
557 
558 private:
560  typedef std::mutex mutex_t;
561  typedef std::lock_guard<mutex_t> lock_t;
562 
563 
579  const_iterator getBegin (const_iterator& last) const;
580 
581 
587  void updatePointers (value_type* new_begin, value_type* new_end);
588 
589 
595  bool anyInRange (const key_type& r,
596  const std::vector<key_query_type>& keys) const;
597 
598 
608  void installImpl (std::unique_ptr<Impl> new_impl,
609  value_type* new_begin,
610  value_type* new_end,
611  const typename Updater_t::Context_t& ctx);
612 
613 
623  int extendImpl (lock_t& lock,
624  const RANGE& extendedRange,
625  const typename Updater_t::Context_t& ctx);
626 
627 
628 
631  Updater_t m_updater;
632 
634  COMPARE m_compare;
635 
647  std::shared_ptr<IPayloadDeleter> m_payloadDeleter;
648 
650  Impl* m_impl;
651 
663  std::atomic<value_type*> m_begin;
664  std::atomic<value_type*> m_last;
665 
667  size_t m_nInserts;
668  size_t m_maxSize;
669 
671  mutex_t m_mutex;
672 };

◆ ATH_REQUIRES() [5/5]

template<class InputIterator , class OutputIterator >
CxxUtils::ATH_REQUIRES ( std::input_iterator< InputIterator > &&std::output_iterator< OutputIterator, typename std::iterator_traits< InputIterator >::value_type )

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.

◆ 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  {
94  return result;
95  }

◆ 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  {
88  return result;
89  }

◆ atomic_bounded_decrement()

template<class T >
T CxxUtils::atomic_bounded_decrement ( std::atomic< T > *  a,
bound = 0,
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;

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 }

◆ atomic_fetch_max()

template<class T >
T CxxUtils::atomic_fetch_max ( std::atomic< T > *  a,
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,
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/2]

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

Definition at line 349 of file span.h.

349 { return s.begin(); }

◆ begin() [2/2]

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

Definition at line 347 of file span.h.

347 { return s.begin(); }

◆ 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 }

◆ 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  }

◆ copy_bounded() [1/2]

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 124 of file copy_bounded.h.

126 {
127  return copy_bounded
130 }

◆ copy_bounded() [2/2]

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 102 of file copy_bounded.h.

104 {
105  return copy_bounded
108 }

◆ 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 32 of file copy_bounded.h.

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

◆ 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 52 of file copy_bounded.h.

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

◆ count_leading_zeros() [1/3]

unsigned CxxUtils::count_leading_zeros ( unsigned long long  x)
inline

Definition at line 118 of file bitscan.h.

118  {
119 #if HAVE_BITCOUNT_INTRINSICS
120  return (x!=0 ? __builtin_clzll(x) : sizeof(x)*CHAR_BIT);
121 #else
122  return detail::clz_portable(x);
123 #endif
124  }

◆ count_leading_zeros() [2/3]

unsigned CxxUtils::count_leading_zeros ( unsigned long  x)
inline

Definition at line 110 of file bitscan.h.

110  {
111 #if HAVE_BITCOUNT_INTRINSICS
112  return (x!=0 ? __builtin_clzl(x) : sizeof(x)*CHAR_BIT);
113 #else
114  return detail::clz_portable(x);
115 #endif
116  }

◆ count_leading_zeros() [3/3]

unsigned CxxUtils::count_leading_zeros ( unsigned  x)
inline

Count number of leading zeros.

Parameters
xNumber to check
Returns
Number of leading zeros, input size in bits if x==0

Definition at line 102 of file bitscan.h.

102  {
103 #if HAVE_BITCOUNT_INTRINSICS
104  return (x!=0 ? __builtin_clz(x) : sizeof(x)*CHAR_BIT);
105 #else
106  return detail::clz_portable(x);
107 #endif
108  }

◆ count_ones() [1/3]

unsigned CxxUtils::count_ones ( unsigned long long  x)
inline

Definition at line 164 of file bitscan.h.

164  {
165 #if HAVE_BITCOUNT_INTRINSICS
166  return __builtin_popcountll(x);
167 #else
169 #endif
170  }

◆ count_ones() [2/3]

unsigned CxxUtils::count_ones ( unsigned long  x)
inline

Definition at line 152 of file bitscan.h.

152  {
153 #if HAVE_BITCOUNT_INTRINSICS
154  return __builtin_popcountl(x);
155 #else
157 #endif
158  }

◆ count_ones() [3/3]

unsigned CxxUtils::count_ones ( unsigned  x)
inline

Count number of set bits.

Parameters
xNumber to check
Returns
Number of bits set in x.

Definition at line 141 of file bitscan.h.

141  {
142 #if HAVE_BITCOUNT_INTRINSICS
143  return __builtin_popcount(x);
144 #else
146 #endif
147  }

◆ count_trailing_zeros() [1/3]

unsigned CxxUtils::count_trailing_zeros ( unsigned long long  x)
inline

Definition at line 88 of file bitscan.h.

88  {
89 #if HAVE_BITCOUNT_INTRINSICS
90  return (x!=0 ? __builtin_ctzll(x) : 0);
91 #else
92  return detail::ctz_portable(x);
93 #endif
94  }

◆ count_trailing_zeros() [2/3]

unsigned CxxUtils::count_trailing_zeros ( unsigned long  x)
inline

Definition at line 80 of file bitscan.h.

80  {
81 #if HAVE_BITCOUNT_INTRINSICS
82  return (x!=0 ? __builtin_ctzl(x) : 0);
83 #else
84  return detail::ctz_portable(x);
85 #endif
86  }

◆ count_trailing_zeros() [3/3]

unsigned CxxUtils::count_trailing_zeros ( unsigned  x)
inline

Count number of trailing zeros.

Parameters
xNumber to check
Returns
Number of trailing zeros, 0 if x==0

Definition at line 72 of file bitscan.h.

72  {
73 #if HAVE_BITCOUNT_INTRINSICS
74  return (x!=0 ? __builtin_ctz(x) : 0);
75 #else
76  return detail::ctz_portable(x);
77 #endif
78  }

◆ 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 }

◆ 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 }

◆ 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 }

◆ 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 }

◆ 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 }

◆ 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 ( phiA,
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  }

◆ 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/2]

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

Definition at line 353 of file span.h.

353 { return s.end(); }

◆ end() [2/2]

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

Definition at line 351 of file span.h.

351 { return s.end(); }

◆ ends_with() [1/3]

bool CxxUtils::ends_with ( const char *  s,
const char *  suffix 
)

Test whether one null-terminated byte string ends with another.

Parameters
snull-terminated byte string in which to search.
suffixSuffix for which to search.

Returns true if null-terminated byte string s starts with suffix.

◆ ends_with() [2/3]

bool CxxUtils::ends_with ( const std::string &  s,
const char *  suffix 
)

Test whether one string starts ends another.

Parameters
sString in which to search.
suffixSuffix for which to search.

Returns true if string s starts with suffix.

◆ ends_with() [3/3]

bool CxxUtils::ends_with ( const std::string &  s,
const std::string &  suffix 
)

Test whether one string ends with another.

Parameters
sString in which to search.
suffixSuffix for which to search.

Returns true if string s ends with suffix.

◆ 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  }

◆ 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 }

◆ 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 >
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 62 of file get_unaligned.h.

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

◆ 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 82 of file get_unaligned.h.

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

◆ get_unaligned64()

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

Read a 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 102 of file get_unaligned.h.

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

◆ get_unaligned< double >()

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

Definition at line 204 of file get_unaligned.h.

205 {
206  return get_unaligned_double (p);
207 }

◆ get_unaligned< float >()

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

Definition at line 196 of file get_unaligned.h.

197 {
198  return get_unaligned_float (p);
199 }

◆ get_unaligned< int16_t >()

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

Definition at line 220 of file get_unaligned.h.

221 {
222  return get_unaligned<uint16_t> (p);
223 }

◆ get_unaligned< int32_t >()

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

Definition at line 228 of file get_unaligned.h.

229 {
230  return get_unaligned<uint32_t> (p);
231 }

◆ get_unaligned< int64_t >()

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

Definition at line 236 of file get_unaligned.h.

237 {
238  return get_unaligned<uint64_t> (p);
239 }

◆ get_unaligned< int8_t >()

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

Definition at line 212 of file get_unaligned.h.

213 {
214  return get_unaligned<uint8_t> (p);
215 }

◆ get_unaligned< uint16_t >()

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

Definition at line 172 of file get_unaligned.h.

173 {
174  return get_unaligned16 (p);
175 }

◆ get_unaligned< uint32_t >()

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

Definition at line 180 of file get_unaligned.h.

181 {
182  return get_unaligned32 (p);
183 }

◆ get_unaligned< uint64_t >()

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

Definition at line 188 of file get_unaligned.h.

189 {
190  return get_unaligned64 (p);
191 }

◆ get_unaligned< uint8_t >()

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

Definition at line 164 of file get_unaligned.h.

165 {
166  return *p++;
167 }

◆ get_unaligned_double()

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

Read 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 144 of file get_unaligned.h.

145 {
146  union {
147  double f;
148  uint64_t i;
149  } cnv;
150  cnv.i = get_unaligned64 (p);
151  return cnv.f;
152 }

◆ get_unaligned_float()

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

Read 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 122 of file get_unaligned.h.

123 {
124  union {
125  float f;
126  uint32_t i;
127  } cnv;
128  cnv.i = get_unaligned32 (p);
129  return cnv.f;
130 }

◆ 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 }

◆ htole16()

uint16_t CxxUtils::htole16 ( uint16_t  x)
inline

Definition at line 41 of file get_unaligned.h.

41 { return x; }

◆ htole32()

uint32_t CxxUtils::htole32 ( uint32_t  x)
inline

Definition at line 42 of file get_unaligned.h.

42 { return x; }

◆ htole64()

uint64_t CxxUtils::htole64 ( uint64_t  x)
inline

Definition at line 43 of file get_unaligned.h.

43 { 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); }

◆ make_span()

template<class 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 338 of file span.h.

339 {
340  return CxxUtils::span (c.data(), c.size());
341 }

◆ 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 }

◆ maxSetBit()

template<typename T >
int CxxUtils::maxSetBit ( const x)

Returns the position (counting from the left hand side) of the last set bit.

Definition at line 172 of file bitscan.h.

172  {
173  return x != 0 ? sizeof(T) * 8 - count_leading_zeros(x) : -1;
174  }

◆ 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 }

◆ 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 = *(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 }

◆ 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 = *(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 
253 
254  h ^= h >> 13;
255  h *= M;
256  h ^= h >> 15;
257 
258  return h;
259 }

◆ 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 = (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 }

◆ 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 ^= ((unsigned const char*)data)[2] << 16;
189  // FALLTHROUGH
190  case 2: h2 ^= ((unsigned const char*)data)[1] << 8;
191  // FALLTHROUGH
192  case 1: h2 ^= ((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 = *(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 = *(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 }

◆ 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 }

◆ ones()

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

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 }

◆ 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,
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&& ( 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 ( phiA,
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  }

◆ phiMean()

template<typename T >
T CxxUtils::phiMean ( phiA,
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  }

◆ 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 }

◆ 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 }

◆ 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 {
110  prefetchN<sizeof(T)> (ptr);
111 }

◆ 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 }

◆ 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 >
constexpr std::enable_if_t<is_bitmask_v<E>, E&> CxxUtils::reset ( E &  lhs,
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 243 of file bitmask.h.

244 {
245  lhs &= ~rhs;
246  return lhs;
247 }

◆ 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  size_t pagesize = sysconf (_SC_PAGESIZE);
116 
117  procmaps m;
118 
119  // Print page by page.
120  while (n > 0) {
121  uintptr_t iptr = reinterpret_cast<uintptr_t>(ptr);
122  size_t thispage = ((iptr + pagesize) & ~(pagesize-1)) - iptr;
123  if (thispage > n) {
124  thispage = n;
125  }
126  const procmaps::Entry* ent = m.getEntry (ptr);
127  if (ent && ent->readable) {
128  hexdump (s, ptr, thispage, offset);
129  }
130  else {
131  boost::io::ios_all_saver saver (s);
132  std::hex (s);
133  s.fill ('0');
134  s << std::setw(16) << reinterpret_cast<uintptr_t>(ptr) - offset
135  << " --- is not readable\n";
136  if (ent) {
137  thispage = std::max (ent->endAddress - iptr, thispage);
138  }
139  }
140  ptr += thispage;
141  n -= thispage;
142  }
143 }

◆ set()

template<class E >
constexpr std::enable_if_t<is_bitmask_v<E>, E&> CxxUtils::set ( E &  lhs,
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 224 of file bitmask.h.

225 {
226  lhs |= rhs;
227  return lhs;
228 }

◆ 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 }

◆ starts_with() [1/3]

bool CxxUtils::starts_with ( const char *  s,
const char *  prefix 
)

Test whether one null-terminated byte string starts with another.

Parameters
snull-terminated byte string in which to search.
prefixPrefix for which to search.

Returns true if null-terminated byte string s starts with prefix.

◆ starts_with() [2/3]

bool CxxUtils::starts_with ( const std::string &  s,
const char *  prefix 
)

Test whether one string starts with another.

Parameters
sString in which to search.
prefixPrefix for which to search.

Returns true if string s starts with prefix.

◆ starts_with() [3/3]

bool CxxUtils::starts_with ( const std::string &  s,
const std::string &  prefix 
)

Test whether one string starts with another.

Parameters
sString in which to search.
prefixPrefix for which to search.

Returns true if string s starts with prefix.

◆ 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 }

◆ test()

template<class E >
constexpr std::enable_if_t<is_bitmask_v<E>, bool> CxxUtils::test ( lhs,
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 262 of file bitmask.h.

263 {
264  typedef std::underlying_type_t<E>underlying;
265  return static_cast<underlying> (lhs & rhs) != 0;
266 }

◆ 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  }

◆ 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(); });

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 385 of file vec.h.

385  {
386  static_assert(std::is_integral<vec_type_t<VEC>>::value,
387  "vec elements must be of integral type. Aka vec must be "
388  "compatible with a mask");
389  VEC alltrue;
390 #if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
391  // fallback compares to 0 when false
392  // and 1 when is true
393  vbroadcast(alltrue, vec_type_t<VEC>{1});
394 #else
395  // For the gnu vector extensions
396  // Vectors are compared element-wise producing 0 when comparison is false
397  // and -1 (constant of the appropriate type where all bits are set) otherwise.
398  vbroadcast(alltrue, vec_type_t<VEC>{-1});
399 #endif
400  return std::memcmp(&mask, &alltrue, sizeof(VEC)) == 0;
401 }

◆ vany()

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

Definition at line 353 of file vec.h.

353  {
354  static_assert(std::is_integral<vec_type_t<VEC>>::value,
355  "vec elements must be of integral type. Aka vec must be "
356  "compatible with a mask");
357  VEC zero;
358  vbroadcast(zero,vec_type_t<VEC>{0});
359  return std::memcmp(&mask, &zero, sizeof(VEC)) != 0;
360 }

◆ vbroadcast()

template<typename VEC , typename T >
ATH_ALWAYS_INLINE void CxxUtils::vbroadcast ( VEC &  v,
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 }

◆ vconvert()

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

Definition at line 407 of file vec.h.

408 {
409  static_assert((vec_size<VEC1>() == vec_size<VEC2>()),
410  "vconvert dst and src have different number of elements");
411 
412 #if !HAVE_CONVERT_VECTOR || WANT_VECTOR_FALLBACK
413  typedef vec_type_t<VEC1> ELT;
414  constexpr size_t N = vec_size<VEC1>();
415  for (size_t i = 0; i < N; ++i) {
416  dst[i] = static_cast<ELT>(src[i]);
417  }
418 #else
419  dst = __builtin_convertvector(src, VEC1);
420 #endif
421 }

◆ vec_size() [1/2]

template<class VEC >
constexpr ATH_ALWAYS_INLINE 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 >
constexpr ATH_ALWAYS_INLINE 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  std::memcpy(&dst, src, sizeof(VEC));
275 }

◆ vmax()

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

Definition at line 334 of file vec.h.

335 {
336 #if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
337  constexpr size_t N = vec_size<VEC>();
338  for (size_t i = 0; i < N; ++i) {
339  dst[i] = a[i] > b[i] ? a[i] : b[i];
340  }
341 #else
342  dst = a > b ? a : b;
343 #endif
344 }

◆ vmin()

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

Definition at line 315 of file vec.h.

316 {
317 #if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
318  constexpr size_t N = vec_size<VEC>();
319  for (size_t i = 0; i < N; ++i) {
320  dst[i] = a[i] < b[i] ? a[i] : b[i];
321  }
322 #else
323  dst = a < b ? a : b;
324 #endif
325 }

◆ vnone()

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

Definition at line 369 of file vec.h.

369  {
370  static_assert(std::is_integral<vec_type_t<VEC>>::value,
371  "vec elements must be of integral type. Aka vec must be "
372  "compatible with a mask");
373  VEC zero;
374  vbroadcast(zero,vec_type_t<VEC>{0});
375  return std::memcmp(&mask, &zero, sizeof(VEC)) == 0;
376 }

◆ 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 430 of file vec.h.

431 {
432 
433  static_assert((sizeof...(Indices) == vec_size<VEC1>()),
434  "vpermute number of indices different than return vector size");
435  static_assert(std::is_same<vec_type_t<VEC>, vec_type_t<VEC1>>::value,
436  "vpermute type of input and output vector elements differ");
438  Indices >= 0 && Indices < vec_size<VEC>())...>::value,
439  "vpermute value of a mask index is outside the allowed range");
440 
441 #if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
442  dst = VEC1{ src[Indices]... };
443 #else
444  dst = __builtin_shufflevector(src, src, Indices...);
445 #endif
446 }

◆ 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 455 of file vec.h.

456 {
457  static_assert(
458  (sizeof...(Indices) == vec_size<VEC1>()),
459  "vpermute2 number of indices different than return vector size");
460  static_assert(std::is_same<vec_type_t<VEC>, vec_type_t<VEC1>>::value,
461  "vpermute2 type of input and output vector elements differ");
462  constexpr size_t N = vec_size<VEC>();
464  Indices >= 0 && Indices < 2 * N)...>::value,
465  "vpermute2 value of a mask index is outside the allowed range");
466 
467 #if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
468  VEC1 tmp;
469  size_t pos{0};
470  for (auto index: { Indices... }) {
471  if (index < N) {
472  tmp[pos] = src1[index];
473  } else {
474  tmp[pos] = src2[index - N];
475  }
476  ++pos;
477  }
478  dst = tmp;
479 #else
480  dst = __builtin_shufflevector(src1, src2, Indices...);
481 #endif
482 }

◆ 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 297 of file vec.h.

297  {
298 #if !HAVE_VECTOR_SIZE_ATTRIBUTE || WANT_VECTOR_FALLBACK
299  constexpr size_t N = vec_size<VEC>();
300  for (size_t i = 0; i < N; ++i) {
301  dst[i] = mask[i] ? a[i] : b[i];
302  }
303 #else
304  dst = mask ? a : b;
305 #endif
306 }

◆ vstore()

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

Definition at line 285 of file vec.h.

286 {
287  std::memcpy(dst, &src, sizeof(VEC));
288 }

◆ wrapToPi()

template<typename T >
T CxxUtils::wrapToPi ( 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  }

Variable Documentation

◆ bego

InputIterator OutputIterator CxxUtils::bego

Definition at line 83 of file copy_bounded.h.

◆ defaultCRCTable

const CRCTable CxxUtils::defaultCRCTable(0xad93d23594c935a9)

◆ dynamic_extent

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

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

Definition at line 33 of file span.h.

◆ endi

InputIterator CxxUtils::endi

Definition at line 82 of file copy_bounded.h.

◆ endo

InputIterator OutputIterator OutputIterator CxxUtils::endo
Initial value:
{
(begi, endi, bego, endo,
typename std::iterator_traits<InputIterator>::iterator_category(),
typename std::iterator_traits<OutputIterator>::iterator_category())

Definition at line 83 of file copy_bounded.h.

◆ valid_span_type_v

template<class T , class U >
constexpr 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 40 of file span.h.

CxxUtils::IRangeMapPayloadDeleter
Helper to delete payload objects for ConcurrentRangeMap.
Definition: ConcurrentRangeMap.h:45
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CxxUtils::VALID
@ VALID
Definition: CachedValue.h:30
beamspotman.r
def r
Definition: beamspotman.py:676
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
CxxUtils::span
span(T *ptr, std::size_t sz) -> span< T >
A couple needed deduction guides.
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
CxxUtils::detail::popcount_portable
unsigned popcount_portable(T x)
Definition: bitscan.h:55
m_data
std::vector< T > m_data
Definition: TrackFindingValidationAlg.cxx:669
CxxUtils::UPDATING
@ UPDATING
Definition: CachedValue.h:29
Amg::compare
std::pair< int, int > compare(const AmgSymMatrix(N) &m1, const AmgSymMatrix(N) &m2, double precision=1e-9, bool relative=false)
compare two matrices, returns the indices of the first element that fails the condition,...
Definition: EventPrimitivesHelpers.h:109
CxxUtils::copy_bounded1
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.
Definition: copy_bounded.h:52
egammaParameters::depth
@ depth
pointing depth of the shower as calculated in egammaqgcld
Definition: egammaParamDefs.h:276
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
CxxUtils::crc64_bytewise
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
beamspotPlotBcids.k
k
Definition: beamspotPlotBcids.py:524
get_generator_info.result
result
Definition: get_generator_info.py:21
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
max
#define max(a, b)
Definition: cfImp.cxx:41
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
CxxUtils::eraseWhiteSpaces
std::string_view eraseWhiteSpaces(std::string_view str)
Removes all trailing and starting whitespaces from a string.
Definition: Control/CxxUtils/Root/StringUtils.cxx:44
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
AthenaPoolExample_WriteJobOptions.seq
seq
Definition: AthenaPoolExample_WriteJobOptions.py:95
CxxUtils::detail::ConcurrentHashmapVal_t
uintptr_t ConcurrentHashmapVal_t
Type used for keys and values — an unsigned big enough to hold a pointer.
Definition: ConcurrentHashmapImpl.h:41
trim
std::string trim(const std::string &str, const std::string &whitespace=" \t")
Definition: BTaggingTruthTaggingTool.cxx:1149
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
index
Definition: index.py:1
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
hist_file_dump.d
d
Definition: hist_file_dump.py:137
make_hlt_rep.rep
rep
Definition: make_hlt_rep.py:32
CxxUtils::tokenize
std::vector< std::string > tokenize(const std::string &the_str, std::string_view delimiters)
Splits the string into smaller substrings.
Definition: Control/CxxUtils/Root/StringUtils.cxx:15
CxxUtils::wrapToPi
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition: phihelper.h:24
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:424
M_PI
#define M_PI
Definition: ActiveFraction.h:11
CxxUtils::hexdump
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
CxxUtils::get_unaligned64
uint64_t get_unaligned64(const uint8_t *ATH_RESTRICT &p)
Read a 8-byte little-endian value from a possibly unaligned pointer.
Definition: get_unaligned.h:102
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
ParticleTest.tp
tp
Definition: ParticleTest.py:25
MurmurHash_mmix
#define MurmurHash_mmix(h, k)
Definition: MurmurHash2.h:29
bound
@ bound
Definition: L1CaloPprPlotManager.h:74
athena.value
value
Definition: athena.py:122
PI
const float PI
Definition: test_isolaitonTool.cxx:61
CxxUtils::CacheLineSize
@ CacheLineSize
Definition: prefetch.h:59
IOVDbNamespace::inRange
bool inRange(const NumericType &val, const std::pair< NumericType, NumericType > &range)
Function to check whether a number is in the inclusive range, given as a pair.
Definition: IOVDbCoolFunctions.h:42
CxxUtils::htole32
uint32_t htole32(uint32_t x)
Definition: get_unaligned.h:42
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
atn_test_sgProducerConsumerDataPool_jobOptions.end
end
Definition: atn_test_sgProducerConsumerDataPool_jobOptions.py:25
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
CxxUtils::CRCTable::m_table
uint64_t m_table[256]
Lookup table for bytewise CRC calculation.
Definition: crc64.cxx:478
read_hist_ntuple.h1
h1
Definition: read_hist_ntuple.py:21
CxxUtils::detail::clz_portable
unsigned clz_portable(T x)
Definition: bitscan.h:45
CxxUtils::INVALID
@ INVALID
Definition: CachedValue.h:28
x
#define x
FPEAudit::lock_t
std::lock_guard< std::mutex > lock_t
Definition: FPEAuditor.cxx:44
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
beamspotPlotBcids.count
int count
Definition: beamspotPlotBcids.py:486
python.AtlRunQueryParser.ap
ap
Definition: AtlRunQueryParser.py:826
CxxUtils::convertToNumber
void convertToNumber(std::string_view str, dType &number)
Definition: Control/CxxUtils/Root/StringUtils.cxx:65
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
CxxUtils::munge_string_name
std::string munge_string_name(const std::string &str_in)
Definition: normalizeFunctionName.cxx:54
CxxUtils::fpcompare::equal
bool equal(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Definition: fpcompare.h:114
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
CxxUtils::get_unaligned_float
float get_unaligned_float(const uint8_t *ATH_RESTRICT &p)
Read little-endian float value from a possibly unaligned pointer.
Definition: get_unaligned.h:122
calibdata.valid
list valid
Definition: calibdata.py:45
CondContStatusCode::DUPLICATE
@ DUPLICATE
RTTAlgmain.data2
data2
Definition: RTTAlgmain.py:54
CondContStatusCode::OVERLAP
@ OVERLAP
python.AthDsoLogger.delimiter
delimiter
Definition: AthDsoLogger.py:71
Generate_dsid_ranseed.seed
seed
Definition: Generate_dsid_ranseed.py:10
python.SystemOfUnits.sr
int sr
Definition: SystemOfUnits.py:113
CxxUtils::stall
void stall()
Emit stall instruction for use in a spin loop.
Definition: stall.h:37
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
CxxUtils::get_unaligned< uint64_t >
uint64_t get_unaligned< uint64_t >(const uint8_t *ATH_RESTRICT &p)
Definition: get_unaligned.h:188
lumiFormat.i
int i
Definition: lumiFormat.py:92
python.DecayParser.buf
buf
print ("=> [%s]"cmd)
Definition: DecayParser.py:27
ret
T ret(T t)
Definition: rootspy.cxx:260
beamspotman.n
n
Definition: beamspotman.py:731
procmaps::Entry::readable
bool readable
Definition: procmaps.h:24
RANGE
#define RANGE(a)
Definition: AmdcDbSvcMakerFromRDB.cxx:533
extractSporadic.h
list h
Definition: extractSporadic.py:97
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
CxxUtils::get_unaligned16
uint16_t get_unaligned16(const uint8_t *ATH_RESTRICT &p)
Read a 2-byte little-endian value from a possibly unaligned pointer.
Definition: get_unaligned.h:62
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
findIdxOfMinimum::Impl
Impl
Definition: GSFFindIndexOfMinimum.h:398
CxxUtils::clean_allocator
std::string clean_allocator(std::string f)
Clean ‘allocator’ template arguments from the function f.
Definition: normalizeFunctionName.cxx:24
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
VALUE
#define VALUE(TESTED)
Definition: expect.h:59
CxxUtils::munge_names
std::string munge_names(const std::string &str_in)
Definition: normalizeFunctionName.cxx:106
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
CxxUtils::bego
InputIterator OutputIterator bego
Definition: copy_bounded.h:83
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
Athena::DebugAids::stacktraceFd
static IOFD stacktraceFd(IOFD fd=IOFD_INVALID)
Set and return the file descriptor for stack trace output.
Definition: SealDebug.cxx:603
AnalysisUtils::Delta::R
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)
Definition: AnalysisMisc.h:50
SH::MetaObject::swap
void swap(MetaObject &a, MetaObject &b)
standard swap
python.KeyStore.clear
def clear(self)
Definition: KeyStore.py:235
CxxUtils::get_unaligned_double
double get_unaligned_double(const uint8_t *ATH_RESTRICT &p)
Read little-endian float value from a possibly unaligned pointer.
Definition: get_unaligned.h:144
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
CxxUtils::crc64
uint64_t crc64(const CRCTable &table, const char *data, size_t data_len)
Find the CRC-64 of a string,.
Definition: crc64.cxx:696
CxxUtils::htole64
uint64_t htole64(uint64_t x)
Definition: get_unaligned.h:43
CxxUtils::count_leading_zeros
unsigned count_leading_zeros(unsigned long long x)
Definition: bitscan.h:118
min
#define min(a, b)
Definition: cfImp.cxx:40
merge.output
output
Definition: merge.py:17
ReadFromCoolCompare.fd
fd
Definition: ReadFromCoolCompare.py:196
dso-stats.pat
pat
Definition: dso-stats.py:39
BIG_CONSTANT
#define BIG_CONSTANT(x)
Definition: MurmurHash2.cxx:34
CxxUtils::prefetchOne
void prefetchOne(const void *address)
Generic prefetch method.
Definition: prefetch.h:73
CondContStatusCode::SUCCESS
@ SUCCESS
CxxUtils::get_unaligned< uint32_t >
uint32_t get_unaligned< uint32_t >(const uint8_t *ATH_RESTRICT &p)
Definition: get_unaligned.h:180
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
remainder
std::vector< std::string > remainder(const std::vector< std::string > &v1, const std::vector< std::string > &v2)
list of entries in a vector that are not in another
Definition: compareFlatTrees.cxx:44
python.selection.number
number
Definition: selection.py:20
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
IOFD_INVALID
#define IOFD_INVALID
Invalid channel descriptor constant.
Definition: SealCommon.h:20
procmaps::Entry::endAddress
unsigned long endAddress
Definition: procmaps.h:23
python.ext.table_printer.table
list table
Definition: table_printer.py:81
CxxUtils::defaultCRCTable
const CRCTable defaultCRCTable(0xad93d23594c935a9)
CxxUtils::endi
InputIterator endi
Definition: copy_bounded.h:82
Range
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
Definition: DetectorDescription/Identifier/Identifier/Range.h:27
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
CxxUtils::begin
auto begin(span< T > &s)
Definition: span.h:347
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
beamspotCoolDiff.l
l
Definition: beamspotCoolDiff.py:354
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
CxxUtils::munge_punct
std::string munge_punct(const std::string &str_in)
Definition: normalizeFunctionName.cxx:84
python.PyAthena.v
v
Definition: PyAthena.py:157
DeMoScan.index
string index
Definition: DeMoScan.py:362
CxxUtils::prefetchObj
void prefetchObj(const T *ptr)
Generic prefetch of the object of specific types (sizes).
Definition: prefetch.h:108
readCCLHist.int
int
Definition: readCCLHist.py:84
fmt
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
MIX
#define MIX(h, k, m)
Definition: MurmurHash2.cxx:321
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
h
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
CxxUtils::detail::ctz_portable
unsigned ctz_portable(T x)
Definition: bitscan.h:35
test_tpcnv_autoload.cnv
cnv
Definition: test_tpcnv_autoload.py:23
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
CxxUtils::crc64format
std::string crc64format(uint64_t crc)
Format a CRC-64 as a string.
Definition: crc64.cxx:746
procmaps
A simple API to access /proc/self/maps info.
Definition: procmaps.h:18
CXXUTILS_PREFETCH_ADDRESS
#define CXXUTILS_PREFETCH_ADDRESS(ADDR)
Definition: prefetch.h:32
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
CxxUtils::endo
InputIterator OutputIterator OutputIterator endo
Definition: copy_bounded.h:84
procmaps::Entry
Definition: procmaps.h:20
DeMoScan.first
bool first
Definition: DeMoScan.py:534
CxxUtils::do_replace
std::string do_replace(std::string s, const std::string &pat, const std::string &rep)
Definition: normalizeFunctionName.cxx:95
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
CxxUtils::vbroadcast
ATH_ALWAYS_INLINE void vbroadcast(VEC &v, T x)
Copy a scalar to each element of a vectorized type.
Definition: vec.h:251
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
CxxUtils::get_unaligned< uint16_t >
uint16_t get_unaligned< uint16_t >(const uint8_t *ATH_RESTRICT &p)
Definition: get_unaligned.h:172
str
Definition: BTagTrackIpAccessor.cxx:11
CxxUtils::copy_bounded
auto copy_bounded(const InputRange &input, OutputRange &&output) -> decltype(std::begin(output))
Copy a range with bounds restriction.
Definition: copy_bounded.h:124
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
calibdata.copy
bool copy
Definition: calibdata.py:27
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
CondContStatusCode::EXTENDED
@ EXTENDED
CxxUtils::get_unaligned< uint8_t >
uint8_t get_unaligned< uint8_t >(const uint8_t *ATH_RESTRICT &p)
Definition: get_unaligned.h:164
CxxUtils::ubsan_suppress
void ubsan_suppress(void(*func)())
Helper for suppressing ubsan warnings.
Definition: ubsan_suppress.cxx:69
value_type
Definition: EDM_MasterSearch.h:11
CxxUtils::get_unaligned32
uint32_t get_unaligned32(const uint8_t *ATH_RESTRICT &p)
Read a 4-byte little-endian value from a possibly unaligned pointer.
Definition: get_unaligned.h:82
CxxUtils::vecDetail::bool_pack_helper::all_true
std::is_same< bool_pack< bs..., true >, bool_pack< true, bs... > > all_true
Definition: vec.h:198
python.compressB64.c
def c
Definition: compressB64.py:93
zero
void zero(TH2 *h)
zero the contents of a 2d histogram
Definition: comparitor.cxx:435
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
CxxUtils::htole16
uint16_t htole16(uint16_t x)
Definition: get_unaligned.h:41
MYWRITE
#define MYWRITE(fd, data, n)
Definition: SealDebug.h:44
MYWRITELIT
#define MYWRITELIT(fd, str)
Definition: exctrace.cxx:35
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37