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...
 
const AuxDataSpanBasegetDataSpan (SG::auxid_t auxid, const AuxVectorData &parent)
 Return a reference to a description of this vector's start+size. 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 722 of file AuxVectorData.h.

Constructor & Destructor Documentation

◆ Cache() [1/3]

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

Cache manager constructor.

Definition at line 490 of file AuxVectorData.cxx.

491  : m_cache(),
492  m_cache_len(0)
493 {
494 }

◆ Cache() [2/3]

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

Cache manager move constructor.

Parameters
rhsThe cache from which to copy.

Definition at line 501 of file AuxVectorData.cxx.

502  : m_cache_len (rhs.m_cache_len),
503  m_allcache (std::move (rhs.m_allcache))
504 {
505  m_cache[0] = rhs.m_cache[0];
506  m_cache[1] = rhs.m_cache[1];
507  rhs.m_cache[0] = 0;
508  rhs.m_cache[1] = 0;
509  rhs.m_cache_len = 0;
510 }

◆ ~Cache()

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

Cache manager destructor.

Definition at line 537 of file AuxVectorData.cxx.

538 {
539  for (size_t i=0; i < m_allcache.size(); i++) delete [] m_allcache[i];
540 }

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

559 {
560  if (m_cache_len > 0) {
561  if (m_allcache.size() > 1) {
562  for (size_t i=0; i < m_allcache.size()-1; i++)
563  delete [] m_allcache[i];
564  m_allcache[0] = m_allcache.back();
565  m_allcache.resize(1);
566  }
567  std::fill (m_cache[0], m_cache[0] + m_cache_len, static_cast<void*>(0));
568  }
569 }

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

580 {
581  if (auxid < m_cache_len) {
582  m_cache[0][auxid] = nullptr;
583  }
584 }

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

518 {
519  if (this != &rhs) {
520  clear();
521  m_cache_len = rhs.m_cache_len;
522  m_allcache = std::move (rhs.m_allcache);
523 
524  m_cache[0] = rhs.m_cache[0];
525  m_cache[1] = rhs.m_cache[1];
526  rhs.m_cache[0] = 0;
527  rhs.m_cache[1] = 0;
528  rhs.m_cache_len = 0;
529  }
530  return *this;
531 }

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

593 {
594  // We must be holding the container lock m_mutex to call this.
595 
596  if (auxid >= m_cache_len) {
597  // We need to expand the cache vector. Allocate a new one.
598  size_t newlen =
599  std::max (static_cast<SG::auxid_t>(AuxVectorData::s_minCacheLen),
600  (auxid+1)*3/2);
601  void** newcache = new void*[newlen];
602  m_allcache.push_back (newcache);
603  void** oldcache = m_cache[0];
604 
605  // Copy old vector to the new one and clear the remainder.
606  std::copy (oldcache, oldcache + m_cache_len, newcache);
607  std::fill (newcache + m_cache_len, newcache + newlen,
608  static_cast<void*>(0));
609 
610  // The above writes must be visible before we update the cache pointers.
612 
613  // Store so that other threads can see it.
614  // The stores to m_cache must happen before the store to m_cache_len;
615  // we use a fence to ensure this.
616  m_cache[0] = newcache;
617  m_cache[1] = newcache;
619  m_cache_len = newlen;
620  }
621 
622  // We have room in the cache vector now. Store the pointer.
623  m_cache[0][auxid] = ptr;
624 }

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

548 {
549  m_allcache.swap (other.m_allcache);
550  std::swap (m_cache, other.m_cache);
551  std::swap (m_cache_len, other.m_cache_len);
552 }

Member Data Documentation

◆ m_allcache

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

All cache vectors that have been allocated.

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

◆ m_cache_len

size_t SG::AuxVectorData::Cache::m_cache_len

Length of the cache vector.

Definition at line 858 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:855
SG::AuxVectorData::Cache::m_allcache
std::vector< void ** > m_allcache
All cache vectors that have been allocated.
Definition: AuxVectorData.h:864
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
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:858
lumiFormat.i
int i
Definition: lumiFormat.py:85
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
SG::AuxVectorData::Cache::clear
void clear()
Clear the cache (and free any old cache vectors).
Definition: AuxVectorData.cxx:558
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
calibdata.copy
bool copy
Definition: calibdata.py:27