ATLAS Offline Software
Public Member Functions | Public Attributes | Private Member Functions | List of all members
SG::AuxVectorData::Cache Class Reference

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

Collaboration diagram for SG::AuxVectorData::Cache:

Public Member Functions

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

Public Attributes

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

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 671 of file AuxVectorData.h.

Constructor & Destructor Documentation

◆ Cache() [1/3]

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

Cache manager constructor.

Definition at line 432 of file AuxVectorData.cxx.

433  : m_cache(),
434  m_cache_len(0)
435 {
436 }

◆ Cache() [2/3]

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

Cache manager move constructor.

Parameters
rhsThe cache from which to copy.

Definition at line 443 of file AuxVectorData.cxx.

444  : m_cache_len (rhs.m_cache_len),
445  m_allcache (std::move (rhs.m_allcache))
446 {
447  m_cache[0] = rhs.m_cache[0];
448  m_cache[1] = rhs.m_cache[1];
449  rhs.m_cache[0] = 0;
450  rhs.m_cache[1] = 0;
451  rhs.m_cache_len = 0;
452 }

◆ ~Cache()

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

Cache manager destructor.

Definition at line 479 of file AuxVectorData.cxx.

480 {
481  for (size_t i=0; i < m_allcache.size(); i++) delete [] m_allcache[i];
482 }

◆ 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 500 of file AuxVectorData.cxx.

501 {
502  if (m_cache_len > 0) {
503  if (m_allcache.size() > 1) {
504  for (size_t i=0; i < m_allcache.size()-1; i++)
505  delete [] m_allcache[i];
506  m_allcache[0] = m_allcache.back();
507  m_allcache.resize(1);
508 }
509  std::fill (m_cache[0], m_cache[0] + m_cache_len, static_cast<void*>(0));
510  }
511 }

◆ 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 521 of file AuxVectorData.cxx.

522 {
523  if (auxid < m_cache_len) {
524  m_cache[0][auxid] = nullptr;
525  }
526 }

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

◆ 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 459 of file AuxVectorData.cxx.

460 {
461  if (this != &rhs) {
462  clear();
463  m_cache_len = rhs.m_cache_len;
464  m_allcache = std::move (rhs.m_allcache);
465 
466  m_cache[0] = rhs.m_cache[0];
467  m_cache[1] = rhs.m_cache[1];
468  rhs.m_cache[0] = 0;
469  rhs.m_cache[1] = 0;
470  rhs.m_cache_len = 0;
471  }
472  return *this;
473 }

◆ 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 534 of file AuxVectorData.cxx.

535 {
536  // We must be holding the container lock m_mutex to call this.
537 
538  if (auxid >= m_cache_len) {
539  // We need to expand the cache vector. Allocate a new one.
540  size_t newlen =
541  std::max (static_cast<SG::auxid_t>(AuxVectorData::s_minCacheLen),
542  (auxid+1)*3/2);
543  void** newcache = new void*[newlen];
544  m_allcache.push_back (newcache);
545  void** oldcache = m_cache[0];
546 
547  // Copy old vector to the new one and clear the remainder.
548  std::copy (oldcache, oldcache + m_cache_len, newcache);
549  std::fill (newcache + m_cache_len, newcache + newlen,
550  static_cast<void*>(0));
551 
552  // The above writes must be visible before we update the cache pointers.
554 
555  // Store so that other threads can see it.
556  // The stores to m_cache must happen before the store to m_cache_len;
557  // we use a fence to ensure this.
558  m_cache[0] = newcache;
559  m_cache[1] = newcache;
561  m_cache_len = newlen;
562  }
563 
564  // We have room in the cache vector now. Store the pointer.
565  m_cache[0][auxid] = ptr;
566 }

◆ 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 489 of file AuxVectorData.cxx.

490 {
491  m_allcache.swap (other.m_allcache);
492  std::swap (m_cache, other.m_cache);
493  std::swap (m_cache_len, other.m_cache_len);
494 }

Member Data Documentation

◆ m_allcache

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

All cache vectors that have been allocated.

Definition at line 805 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 796 of file AuxVectorData.h.

◆ m_cache_len

size_t SG::AuxVectorData::Cache::m_cache_len

Length of the cache vector.

Definition at line 799 of file AuxVectorData.h.


The documentation for this class was generated from the following files:
max
#define max(a, b)
Definition: cfImp.cxx:41
SG::AuxVectorData::Cache::m_cache
void ** m_cache[2]
Pointer to the cache vector.
Definition: AuxVectorData.h:796
SG::AuxVectorData::Cache::m_allcache
std::vector< void ** > m_allcache
All cache vectors that have been allocated.
Definition: AuxVectorData.h:805
AthContainers_detail::fence_seq_cst
void fence_seq_cst()
A sequentially-consistent fence.
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
SG::AuxVectorData::Cache::m_cache_len
size_t m_cache_len
Length of the cache vector.
Definition: AuxVectorData.h:799
lumiFormat.i
int i
Definition: lumiFormat.py:92
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
SG::AuxVectorData::Cache::clear
void clear()
Clear the cache (and free any old cache vectors).
Definition: AuxVectorData.cxx:500
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
lumiFormat.fill
fill
Definition: lumiFormat.py:111
calibdata.copy
bool copy
Definition: calibdata.py:27