ATLAS Offline Software
Loading...
Searching...
No Matches
SG::AuxVectorData::Cache Class Reference

Manage cache of pointers to aux element vectors. More...

#include <AuxVectorData.h>

Collaboration diagram for SG::AuxVectorData::Cache:

Public Member Functions

 Cache ()
 Cache manager constructor.
 Cache (Cache &&rhs)
 Cache manager move constructor.
Cacheoperator= (Cache &&rhs)
 Cache manager move assignment.
 ~Cache ()
 Cache manager destructor.
void * cachePtr (SG::auxid_t auxid)
 Test to see if auxid is valid in the cache.
void * getDataArray (SG::auxid_t auxid, AuxVectorData &parent)
 Return a pointer to the start of an aux data vector.
const void * getDataArray (SG::auxid_t auxid, const AuxVectorData &parent)
 Return a const pointer to the start of an aux data vector.
const void * getDataArrayAllowMissing (SG::auxid_t auxid, const AuxVectorData &parent)
 Return a const pointer to the start of an aux data vector.
void * getDecorationArray (SG::auxid_t auxid, const AuxVectorData &parent)
 Return a pointer to the start of an aux decoration vector.
const AuxDataSpanBasegetDataSpan (SG::auxid_t auxid, const AuxVectorData &parent)
 Return a reference to a description of this vector's start+size.
void swap (Cache &other)
 Swap this cache object with another.
void clear ()
 Clear the cache (and free any old cache vectors).
void clear (SG::auxid_t auxid)
 Clear the cached pointer for a single variable.
void store (SG::auxid_t auxid, void *ptr)
 Store a pointer for auxid in the cache.

Public Attributes

void ** m_cache [2]
 Pointer to the cache vector.
size_t m_cache_len
 Length of the cache vector.
std::vector< void ** > m_allcache
 All cache vectors that have been allocated.

Private Member Functions

 Cache (const Cache &)
Cacheoperator= (const Cache &)

Detailed Description

Manage cache of pointers to aux element vectors.

See the thread-safety comments at the start of this file for notes on what's going on here.

Definition at line 729 of file AuxVectorData.h.

Constructor & Destructor Documentation

◆ Cache() [1/3]

SG::AuxVectorData::Cache::Cache ( )

Cache manager constructor.

Definition at line 507 of file AuxVectorData.cxx.

508 : m_cache(),
509 m_cache_len(0)
510{
511}
void ** m_cache[2]
Pointer to the cache vector.
size_t m_cache_len
Length of the cache vector.

◆ Cache() [2/3]

SG::AuxVectorData::Cache::Cache ( Cache && rhs)

Cache manager move constructor.

Parameters
rhsThe cache from which to copy.

Definition at line 518 of file AuxVectorData.cxx.

519 : m_cache_len (rhs.m_cache_len),
520 m_allcache (std::move (rhs.m_allcache))
521{
522 m_cache[0] = rhs.m_cache[0];
523 m_cache[1] = rhs.m_cache[1];
524 rhs.m_cache[0] = 0;
525 rhs.m_cache[1] = 0;
526 rhs.m_cache_len = 0;
527}
std::vector< void ** > m_allcache
All cache vectors that have been allocated.

◆ ~Cache()

SG::AuxVectorData::Cache::~Cache ( )

Cache manager destructor.

Definition at line 554 of file AuxVectorData.cxx.

555{
556 for (size_t i=0; i < m_allcache.size(); i++) delete [] m_allcache[i];
557}

◆ Cache() [3/3]

SG::AuxVectorData::Cache::Cache ( const Cache & )
private

Member Function Documentation

◆ cachePtr()

void * SG::AuxVectorData::Cache::cachePtr ( SG::auxid_t auxid)

Test to see if auxid is valid in the cache.

Returns
If auxid is valid, return the pointer to the vector, else 0.

◆ clear() [1/2]

void SG::AuxVectorData::Cache::clear ( )

Clear the cache (and free any old cache vectors).

Definition at line 575 of file AuxVectorData.cxx.

576{
577 if (m_cache_len > 0) {
578 if (m_allcache.size() > 1) {
579 for (size_t i=0; i < m_allcache.size()-1; i++)
580 delete [] m_allcache[i];
581 m_allcache[0] = m_allcache.back();
582 m_allcache.resize(1);
583 }
584 std::fill (m_cache[0], m_cache[0] + m_cache_len, static_cast<void*>(0));
585 }
586}

◆ clear() [2/2]

void SG::AuxVectorData::Cache::clear ( SG::auxid_t auxid)

Clear the cached pointer for a single variable.

Parameters
auxidID of the variable to clear.

Not really safe to use if another thread may be accessing the same variable.

Definition at line 596 of file AuxVectorData.cxx.

597{
598 if (auxid < m_cache_len) {
599 m_cache[0][auxid] = nullptr;
600 }
601}
SG::auxid_t auxid() const
Return the aux id for this variable.

◆ getDataArray() [1/2]

void * SG::AuxVectorData::Cache::getDataArray ( SG::auxid_t auxid,
AuxVectorData & parent )

Return a pointer to the start of an aux data vector.

Parameters
auxidThe desired aux data item.
parentThe containing AuxVectorData object.

This will return a pointer to the start of the data for aux data item auxid. If the item doesn't exist, it will be created. Errors are signaled by raising an exception.

◆ getDataArray() [2/2]

const void * SG::AuxVectorData::Cache::getDataArray ( SG::auxid_t auxid,
const AuxVectorData & parent )

Return a const pointer to the start of an aux data vector.

Parameters
auxidThe desired aux data item.
parentThe containing AuxVectorData object.

This will return a pointer to the start of the data for aux data item auxid. Errors are signaled by raising an exception.

◆ getDataArrayAllowMissing()

const void * SG::AuxVectorData::Cache::getDataArrayAllowMissing ( SG::auxid_t auxid,
const AuxVectorData & parent )

Return a const pointer to the start of an aux data vector.

Parameters
auxidThe desired aux data item.
parentThe containing AuxVectorData object.

This will return a pointer to the start of the data for aux data item auxid. If the item does not exist, this will return nullptr rather than raising an exception.

◆ getDataSpan()

const AuxDataSpanBase * SG::AuxVectorData::Cache::getDataSpan ( SG::auxid_t auxid,
const AuxVectorData & parent )

Return a reference to a description of this vector's start+size.

Parameters
auxidThe desired aux data item.

◆ getDecorationArray()

void * SG::AuxVectorData::Cache::getDecorationArray ( SG::auxid_t auxid,
const AuxVectorData & parent )

Return a pointer to the start of an aux decoration vector.

Parameters
auxidThe desired aux decoration item.
parentThe containing AuxVectorData object.

This will return a pointer to the start of the data for aux decoration item auxid. If the item doesn't exist, it will be created. Errors are signaled by raising an exception.

The difference between getDecorationArray and getDataArray is that getDecorationArray takes a const container as input, but returns a non-const pointer. This will only succeed if either the container is not locked or the item was first accessed as a decoration.

◆ operator=() [1/2]

AuxVectorData::Cache & SG::AuxVectorData::Cache::operator= ( Cache && rhs)

Cache manager move assignment.

Parameters
rhsThe cache from which to copy.

Definition at line 534 of file AuxVectorData.cxx.

535{
536 if (this != &rhs) {
537 clear();
538 m_cache_len = rhs.m_cache_len;
539 m_allcache = std::move (rhs.m_allcache);
540
541 m_cache[0] = rhs.m_cache[0];
542 m_cache[1] = rhs.m_cache[1];
543 rhs.m_cache[0] = 0;
544 rhs.m_cache[1] = 0;
545 rhs.m_cache_len = 0;
546 }
547 return *this;
548}
void clear()
Clear the cache (and free any old cache vectors).

◆ operator=() [2/2]

Cache & SG::AuxVectorData::Cache::operator= ( const Cache & )
private

◆ store()

void SG::AuxVectorData::Cache::store ( SG::auxid_t auxid,
void * ptr )

Store a pointer for auxid in the cache.

Parameters
auxidThe aux data item being stored.
ptrPointer to the start of the aux vector for auxid.

Definition at line 609 of file AuxVectorData.cxx.

610{
611 // We must be holding the container lock m_mutex to call this.
612
613 if (auxid >= m_cache_len) {
614 // We need to expand the cache vector. Allocate a new one.
615 size_t newlen =
616 std::max (static_cast<SG::auxid_t>(AuxVectorData::s_minCacheLen),
617 (auxid+1)*3/2);
618 void** newcache = new void*[newlen];
619 m_allcache.push_back (newcache);
620 void** oldcache = m_cache[0];
621
622 // Copy old vector to the new one and clear the remainder.
623 std::copy (oldcache, oldcache + m_cache_len, newcache);
624 std::fill (newcache + m_cache_len, newcache + newlen,
625 static_cast<void*>(0));
626
627 // The above writes must be visible before we update the cache pointers.
629
630 // Store so that other threads can see it.
631 // The stores to m_cache must happen before the store to m_cache_len;
632 // we use a fence to ensure this.
633 m_cache[0] = newcache;
634 m_cache[1] = newcache;
636 m_cache_len = newlen;
637 }
638
639 // We have room in the cache vector now. Store the pointer.
640 m_cache[0][auxid] = ptr;
641}
void fence_seq_cst()
A sequentially-consistent fence.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
void * ptr(T *p)
Definition SGImplSvc.cxx:74

◆ swap()

void SG::AuxVectorData::Cache::swap ( Cache & other)

Swap this cache object with another.

Parameters
otherThe cache object with which to swap.

Definition at line 564 of file AuxVectorData.cxx.

565{
566 m_allcache.swap (other.m_allcache);
567 std::swap (m_cache, other.m_cache);
568 std::swap (m_cache_len, other.m_cache_len);
569}
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)

Member Data Documentation

◆ m_allcache

std::vector<void**> SG::AuxVectorData::Cache::m_allcache

All cache vectors that have been allocated.

Definition at line 871 of file AuxVectorData.h.

◆ m_cache

void** SG::AuxVectorData::Cache::m_cache[2]

Pointer to the cache vector.

The two pointers here are the same; see the thread-safety discussion in the file header above.

Definition at line 862 of file AuxVectorData.h.

◆ m_cache_len

size_t SG::AuxVectorData::Cache::m_cache_len

Length of the cache vector.

Definition at line 865 of file AuxVectorData.h.


The documentation for this class was generated from the following files: