ATLAS Offline Software
Public Types | Public Member Functions | Private Attributes | List of all members
IdentifiableValueCache< T > Class Template Reference

This class is to provide an event wide MT container for concurrent storing of basic types, like ints This is a version of the identifiable container optimized for basic types The cache is designed for event level storage and concurrent writing. More...

#include <IdentifiableValueCache.h>

Collaboration diagram for IdentifiableValueCache< T >:

Public Types

typedef std::true_type thread_safe
 

Public Member Functions

const T & emptyValue () const
 Return the empty value that is interpreted as an empty entry. More...
 
 IdentifiableValueCache (const IdentifiableValueCache &)=delete
 
 IdentifiableValueCache (size_t maxSize, T emptyValuein)
 Pass the maximum hash to size the cache and the defaultValue which will be interpreted as an empty value. More...
 
void forceReset ()
 Forceable empty the container, DO NOT USE THIS IN MT ENVIRONMENT. More...
 
size_t maxSize () const
 Return the maxSize of the collection. More...
 
 ~IdentifiableValueCache ()=default
 
retrieve (size_t i)
 Retrieve the Value stored in that hash. More...
 
retrieve (size_t i) const
 As above, but no cache extension. More...
 
bool present (size_t i)
 Returns true if the value is set to anything but the emptyValue. More...
 
bool present (size_t i) const
 As above, but no cache extension. More...
 
bool setOrDrop (size_t i, const T &value)
 Set the given hash to the value. More...
 
std::vector< std::pair< size_t, T > > getAll () const
 Make a vector of hashes and values, convenient for iteration and other uses. More...
 
const std::vector< std::atomic< T > > & rawReadAccess () const
 

Private Attributes

std::vector< std::atomic< T > > m_vec
 
constm_emptyValue
 

Detailed Description

template<class T>
class IdentifiableValueCache< T >

This class is to provide an event wide MT container for concurrent storing of basic types, like ints This is a version of the identifiable container optimized for basic types The cache is designed for event level storage and concurrent writing.

Definition at line 19 of file IdentifiableValueCache.h.

Member Typedef Documentation

◆ thread_safe

template<class T >
typedef std::true_type IdentifiableValueCache< T >::thread_safe

Definition at line 23 of file IdentifiableValueCache.h.

Constructor & Destructor Documentation

◆ IdentifiableValueCache() [1/2]

template<class T >
IdentifiableValueCache< T >::IdentifiableValueCache ( const IdentifiableValueCache< T > &  )
delete

◆ IdentifiableValueCache() [2/2]

template<class T >
IdentifiableValueCache< T >::IdentifiableValueCache ( size_t  maxSize,
emptyValuein 
)
inline

Pass the maximum hash to size the cache and the defaultValue which will be interpreted as an empty value.

Definition at line 34 of file IdentifiableValueCache.h.

35  : m_vec(maxSize), m_emptyValue(std::move(emptyValuein))
36  {
37  for(auto &x : m_vec) x.store(emptyValue(), std::memory_order_relaxed);
38  }

◆ ~IdentifiableValueCache()

template<class T >
IdentifiableValueCache< T >::~IdentifiableValueCache ( )
default

Member Function Documentation

◆ emptyValue()

template<class T >
const T& IdentifiableValueCache< T >::emptyValue ( ) const
inline

Return the empty value that is interpreted as an empty entry.

Definition at line 26 of file IdentifiableValueCache.h.

26  {
27  return m_emptyValue;
28  }

◆ forceReset()

template<class T >
void IdentifiableValueCache< T >::forceReset

Forceable empty the container, DO NOT USE THIS IN MT ENVIRONMENT.

Definition at line 85 of file IdentifiableValueCache.h.

85  {
86  for(auto &x : m_vec) x.store(emptyValue(), std::memory_order_relaxed);
87 }

◆ getAll()

template<class T >
std::vector< std::pair< size_t, T > > IdentifiableValueCache< T >::getAll

Make a vector of hashes and values, convenient for iteration and other uses.

Definition at line 75 of file IdentifiableValueCache.h.

75  {
76  std::vector<std::pair<size_t, T>> list;
77  for(size_t i =0; i<m_vec.size(); i++){
78  T item = m_vec[i].load(std::memory_order_relaxed);
79  if(item!=m_emptyValue) list.emplace_back(i, std::move(item));
80  }
81  return list;
82 }

◆ maxSize()

template<class T >
size_t IdentifiableValueCache< T >::maxSize ( ) const
inline

Return the maxSize of the collection.

Definition at line 44 of file IdentifiableValueCache.h.

44 { return m_vec.size(); }

◆ present() [1/2]

template<class T >
bool IdentifiableValueCache< T >::present ( size_t  i)
inline

Returns true if the value is set to anything but the emptyValue.

Definition at line 55 of file IdentifiableValueCache.h.

55 { return m_vec.at(i).load() != emptyValue(); }

◆ present() [2/2]

template<class T >
bool IdentifiableValueCache< T >::present ( size_t  i) const
inline

As above, but no cache extension.

Definition at line 58 of file IdentifiableValueCache.h.

58 { return i < maxSize() and m_vec[i] != emptyValue() ? true : false; }

◆ rawReadAccess()

template<class T >
const std::vector<std::atomic<T> >& IdentifiableValueCache< T >::rawReadAccess ( ) const
inline

Definition at line 66 of file IdentifiableValueCache.h.

66 { return m_vec; }

◆ retrieve() [1/2]

template<class T >
T IdentifiableValueCache< T >::retrieve ( size_t  i)
inline

Retrieve the Value stored in that hash.

Definition at line 49 of file IdentifiableValueCache.h.

49 { return m_vec.at(i).load(); }

◆ retrieve() [2/2]

template<class T >
T IdentifiableValueCache< T >::retrieve ( size_t  i) const
inline

As above, but no cache extension.

Definition at line 52 of file IdentifiableValueCache.h.

52 { return i < maxSize() ? static_cast<T>(m_vec[i]) : emptyValue() ; }

◆ setOrDrop()

template<class T >
bool IdentifiableValueCache< T >::setOrDrop ( size_t  i,
const T &  value 
)

Set the given hash to the value.

Definition at line 90 of file IdentifiableValueCache.h.

90  {
91  T val = emptyValue();
92  return m_vec.at(i).compare_exchange_strong(val, value);
93 }

Member Data Documentation

◆ m_emptyValue

template<class T >
const T IdentifiableValueCache< T >::m_emptyValue
private

Definition at line 70 of file IdentifiableValueCache.h.

◆ m_vec

template<class T >
std::vector<std::atomic<T> > IdentifiableValueCache< T >::m_vec
private

Definition at line 69 of file IdentifiableValueCache.h.


The documentation for this class was generated from the following file:
athena.value
value
Definition: athena.py:124
IdentifiableValueCache::emptyValue
const T & emptyValue() const
Return the empty value that is interpreted as an empty entry.
Definition: IdentifiableValueCache.h:26
IdentifiableValueCache::m_emptyValue
const T m_emptyValue
Definition: IdentifiableValueCache.h:70
x
#define x
lumiFormat.i
int i
Definition: lumiFormat.py:85
IdentifiableValueCache::m_vec
std::vector< std::atomic< T > > m_vec
Definition: IdentifiableValueCache.h:69
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
item
Definition: ItemListSvc.h:43
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
IdentifiableValueCache::maxSize
size_t maxSize() const
Return the maxSize of the collection.
Definition: IdentifiableValueCache.h:44
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35