LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst::ap::detail::SubManager< MutexT, DataT, TraitsT > Class Template Reference

Helper class for managing chunks of a particular type. More...

#include <ChunkManagerImpl.h>

Inheritance diagram for lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >:

Public Types

typedef BlockAllocator< MutexT,
DataT, TraitsT > 
Allocator
 
typedef ChunkRef< Allocator,
DataT, TraitsT > 
Chunk
 
typedef ChunkDescriptor
< TraitsT::MAX_BLOCKS_PER_CHUNK > 
Descriptor
 

Public Member Functions

 SubManager (unsigned char const *const ref, std::size_t const offset)
 
int size () const
 Returns the number of chunks under management. More...
 
int space () const
 Returns the number of additional chunks that could be handled by this manager. More...
 
void createOrRegisterInterest (std::vector< Chunk > &toRead, std::vector< Chunk > &toWaitFor, int const visitId, std::vector< int > const &chunkIds)
 
bool checkForOwnership (std::vector< Chunk > &toRead, std::vector< Chunk > &toWaitFor, int const visitId)
 
void getChunks (std::vector< Chunk > &chunks, std::vector< int > const &chunkIds)
 
bool relinquishOwnership (int const visitId, bool const rollback, VisitTracker const &tracker)
 
void print (std::ostream &os) const
 
void print (int const chunkId, std::ostream &os) const
 
void printVisit (int const visitId, std::ostream &os) const
 

Public Attributes

HashedSet< Descriptor, NUM_CHUNKS_chunks
 
Allocator _allocator
 

Static Public Attributes

static int const NUM_CHUNKS = TraitsT::MAX_CHUNKS_PER_FOV * MAX_VISITS_IN_FLIGHT
 

Detailed Description

template<typename MutexT, typename DataT, typename TraitsT = DataTraits<DataT>>
class lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >

Helper class for managing chunks of a particular type.

To be used exclusively by chunk manager implementations.

Definition at line 219 of file ChunkManagerImpl.h.

Member Typedef Documentation

template<typename MutexT , typename DataT , typename TraitsT = DataTraits<DataT>>
typedef BlockAllocator<MutexT, DataT, TraitsT> lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::Allocator

Definition at line 221 of file ChunkManagerImpl.h.

template<typename MutexT , typename DataT , typename TraitsT = DataTraits<DataT>>
typedef ChunkRef<Allocator, DataT, TraitsT> lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::Chunk

Definition at line 222 of file ChunkManagerImpl.h.

template<typename MutexT , typename DataT , typename TraitsT = DataTraits<DataT>>
typedef ChunkDescriptor<TraitsT::MAX_BLOCKS_PER_CHUNK> lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::Descriptor

Definition at line 223 of file ChunkManagerImpl.h.

Constructor & Destructor Documentation

template<typename MutexT , typename DataT , typename TraitsT = DataTraits<DataT>>
lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::SubManager ( unsigned char const *const  ref,
std::size_t const  offset 
)
inline

Definition at line 234 of file ChunkManagerImpl.h.

234 : _allocator(ref, offset) {}

Member Function Documentation

template<typename MutexT , typename DataT , typename TraitsT >
bool lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::checkForOwnership ( std::vector< Chunk > &  toRead,
std::vector< Chunk > &  toWaitFor,
int const  visitId 
)

Checks to see whether the chunks in the toWaitFor list are owned by the given visit. Any chunks that have had their ownership transferred to the given visit are removed from toWaitFor. Of these chunks, the subset that were not completely read into memory (that is, whose previous owners failed while reading them in) are appended to toRead.

Parameters
[out]toReadSet to the list of chunks now owned by the given visit, but which must be re-read from disk.
[in,out]toWaitForThe list of chunks for which ownership must be checked. Any chunks now owned by the given visit are removed from the list by the call.
[in]visitIdAn identifier for a visit to a FOV.
Returns
true if and only if all the chunks initially in the toWaitFor list now belong to the given visit.

Definition at line 464 of file ChunkManagerImpl.cc.

468  {
469  std::size_t size = toWaitFor.size();
470  std::size_t i = 0;
471 
472  while (i < size) {
473  Chunk & c = toWaitFor[i];
474  if (c.getVisitId() != visitId) {
475  ++i;
476  } else {
477  if (!c.isUsable()) {
478  c.clear();
479  toRead.push_back(c);
480  }
481  // deletes element i in O(1) time (but changes element ordering)
482  --size;
483  if (i < size) {
484  toWaitFor[i] = toWaitFor[size];
485  }
486  toWaitFor.pop_back();
487  }
488  }
489  return toWaitFor.empty();
490 }
int size() const
Returns the number of chunks under management.
ChunkRef< Allocator, DataT, TraitsT > Chunk
template<typename MutexT , typename DataT , typename TraitsT >
void lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::createOrRegisterInterest ( std::vector< Chunk > &  toRead,
std::vector< Chunk > &  toWaitFor,
int const  visitId,
std::vector< int > const &  chunkIds 
)

Registers the given visit as an interested party of each of the given chunks. If any of the given identifiers doesn't correspond to a chunk, an empty chunk is created. Newly created chunks are stored in the toRead list (indicating data for them must be read from disk), previously existing chunks are returned in the toWaitFor list (indicating that the visit must wait until it owns those instances before processing can begin).

Parameters
[out]toReadSet to the list of chunks that were not found in memory and must be read in from disk.
[out]toWaitForSet to the list of chunks instances that are already in memory and must be waited on.
[in]visitIdThe visit to register interest or create chunks for.
[in]chunkIdsA list of identifiers for chunks required by the visit. Assumed to be duplicate free.
Exceptions
lsst::pex::exceptions:::MemoryErrorThrown if there is insufficient space to track all requested chunks.

Definition at line 420 of file ChunkManagerImpl.cc.

425  {
426  std::vector<int>::const_iterator const end = chunkIds.end();
427  for (std::vector<int>::const_iterator i = chunkIds.begin(); i != end; ++i) {
428  std::pair<Descriptor *, bool> p(_chunks.findOrInsert(*i));
429  if (p.second) {
430  // new chunk descriptor was allocated
431  if (p.first == 0) {
432  throw LSST_EXCEPT(lsst::pex::exceptions::MemoryError,
433  "too many chunks in flight");
434  }
435  p.first->_visitId = visitId;
436  p.first->_usable = false;
437  toRead.push_back(Chunk(p.first, &_allocator));
438  } else {
439  // existing chunk descriptor was found
440  assert(p.first != 0);
441  p.first->_interestedParties.enqueue(visitId);
442  toWaitFor.push_back(Chunk(p.first, &_allocator));
443  }
444  }
445 }
ChunkRef< Allocator, DataT, TraitsT > Chunk
HashedSet< Descriptor, NUM_CHUNKS > _chunks
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename MutexT , typename DataT , typename TraitsT >
void lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::getChunks ( std::vector< Chunk > &  chunks,
std::vector< int > const &  chunkIds 
)

Returns a chunk for each of the given identifiers that corresponds to a chunk managed by this SubManager.

Parameters
[out]chunksSet to the list of chunk instances managed by this SubManager and with an identifier in chunkIds.
[in]chunkIdsThe list of chunk identifiers to return chunk instances for. Assumed to be duplicate free.

Definition at line 503 of file ChunkManagerImpl.cc.

506  {
507  std::vector<int>::const_iterator const end = chunkIds.end();
508  for (std::vector<int>::const_iterator i = chunkIds.begin(); i != end; ++i) {
509  Descriptor * d = _chunks.find(*i);
510  if (d != 0) {
511  chunks.push_back(Chunk(d, &_allocator));
512  }
513  }
514 }
int d
Definition: KDTree.cc:89
ChunkDescriptor< TraitsT::MAX_BLOCKS_PER_CHUNK > Descriptor
ChunkRef< Allocator, DataT, TraitsT > Chunk
HashedSet< Descriptor, NUM_CHUNKS > _chunks
template<typename MutexT , typename DataT , typename TraitsT >
void lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::print ( std::ostream &  os) const

Definition at line 627 of file ChunkManagerImpl.cc.

627  {
628  Descriptor const * const end = _chunks.end();
629  std::vector<Descriptor const *> v;
630  v.reserve(_chunks.size());
631  for (Descriptor const * beg = _chunks.begin(); beg != end; ++beg) {
632  if (beg->_chunkId != -1) {
633  v.push_back(beg);
634  }
635  }
636  std::sort(v.begin(), v.end(), PtrLessThan<Descriptor>());
637  os << " Chunks with an owner";
638  if (v.empty()) {
639  os << ": None";
640  } else {
641  os << ":\n";
642  os << " Owned by visit " << v[0]->_visitId << ":\n";
643  printChunks(os, v);
644  }
645  os << std::endl;
646 }
ChunkDescriptor< TraitsT::MAX_BLOCKS_PER_CHUNK > Descriptor
HashedSet< Descriptor, NUM_CHUNKS > _chunks
template<typename MutexT , typename DataT , typename TraitsT >
void lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::print ( int const  chunkId,
std::ostream &  os 
) const

Definition at line 650 of file ChunkManagerImpl.cc.

650  {
651  Descriptor const * c = _chunks.find(chunkId);
652  os << " [" << c->_chunkId << "] chunk " <<
653  ZoneStripeChunkDecomposition::chunkToSequence(chunkId) << " in stripe " <<
655  if (c == 0) {
656  os << ": not being tracked\n";
657  } else {
658  os << ":\n " << (c->_usable ? "usable" : "unusable") << "\n ";
659  if (c->_interestedParties.empty()) {
660  os << "un";
661  }
662  os << "interesting\n ";
663  int sz = c->_size;
664  os << sz << " entries in " << c->_nextBlock << " blocks (" <<
665  c->_numBlocks << " allocated)\n ";
666  if (sz <= c->_delta) {
667  sz = 0;
668  } else {
669  sz -= c->_delta;
670  }
671  os << sz << " entries in delta\n";
672  }
673  os << std::endl;
674 }
ChunkDescriptor< TraitsT::MAX_BLOCKS_PER_CHUNK > Descriptor
HashedSet< Descriptor, NUM_CHUNKS > _chunks
static int chunkToSequence(int const chunkId)
Definition: SpatialUtil.h:169
static int chunkToStripe(int const chunkId)
Definition: SpatialUtil.h:164
template<typename MutexT , typename DataT , typename TraitsT >
void lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::printVisit ( int const  visitId,
std::ostream &  os 
) const

Definition at line 678 of file ChunkManagerImpl.cc.

678  {
679  Descriptor const * const end = _chunks.end();
680  std::vector<Descriptor const *> v;
681  v.reserve(_chunks.size());
682  for (Descriptor const * beg = _chunks.begin(); beg != end; ++beg) {
683  if (beg->_chunkId != -1 && beg->_visitId == visitId) {
684  v.push_back(beg);
685  }
686  }
687  std::sort(v.begin(), v.end(), PtrLessThan<Descriptor>());
688  os << " Chunks belonging to visit " << visitId;
689  if (v.empty()) {
690  os << ": None";
691  } else {
692  os << ":\n";
693  printChunks(os, v);
694  }
695  os << std::endl;
696 }
ChunkDescriptor< TraitsT::MAX_BLOCKS_PER_CHUNK > Descriptor
HashedSet< Descriptor, NUM_CHUNKS > _chunks
template<typename MutexT , typename DataT , typename TraitsT >
bool lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::relinquishOwnership ( int const  visitId,
bool const  rollback,
VisitTracker const &  tracker 
)

Relinquishes ownership of any chunks owned by the given visit (each chunk is passed on to its first interested party that is still in flight).

Parameters
[in]visitIdThe visit owning the chunks to relinquish ownership of.
[in]rollbackFlag indicating whether or not in-memory changes to a chunk should be rolled back (true) or committed (false) prior to relinquishing ownership.
[in]trackerTracks the status of visits (whether or not a visit is in flight, and if so, whether or not it has failed).
Returns
true if any chunks changed hands.

Definition at line 531 of file ChunkManagerImpl.cc.

535  {
536  bool change = false;
537  Descriptor * const end = _chunks.end();
538  for (Descriptor * i = _chunks.begin(); i != end; ++i) {
539  if (i->getId() != -1 && i->_visitId == visitId) {
540  bool foundSuccessor = false;
541  while (!i->_interestedParties.empty()) {
542  int const nextVisitId = static_cast<int>(i->_interestedParties.dequeue());
543  if (tracker.isValid(nextVisitId)) {
544  i->_visitId = nextVisitId;
545  change = true;
546  foundSuccessor = true;
547  break;
548  }
549  }
550  if (foundSuccessor) {
551  Chunk c(i, &_allocator);
552  if (rollback) {
553  c.rollback();
554  } else {
555  c.commit();
556  }
557  } else {
558  // deallocate chunk
559  _allocator.free(i->_blocks, i->_numBlocks);
560  _chunks.erase(i->getId());
561  }
562  }
563  }
564  return change;
565 }
void free(std::size_t const *const blockOffsets, int const n)
ChunkDescriptor< TraitsT::MAX_BLOCKS_PER_CHUNK > Descriptor
ChunkRef< Allocator, DataT, TraitsT > Chunk
HashedSet< Descriptor, NUM_CHUNKS > _chunks
template<typename MutexT , typename DataT , typename TraitsT = DataTraits<DataT>>
int lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::size ( ) const
inline

Returns the number of chunks under management.

Definition at line 237 of file ChunkManagerImpl.h.

237 { return _chunks.size(); }
HashedSet< Descriptor, NUM_CHUNKS > _chunks
template<typename MutexT , typename DataT , typename TraitsT = DataTraits<DataT>>
int lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::space ( ) const
inline

Returns the number of additional chunks that could be handled by this manager.

Definition at line 239 of file ChunkManagerImpl.h.

239 { return _chunks.space(); }
HashedSet< Descriptor, NUM_CHUNKS > _chunks

Member Data Documentation

template<typename MutexT , typename DataT , typename TraitsT = DataTraits<DataT>>
Allocator lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::_allocator

Definition at line 230 of file ChunkManagerImpl.h.

template<typename MutexT , typename DataT , typename TraitsT = DataTraits<DataT>>
HashedSet<Descriptor, NUM_CHUNKS> lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::_chunks

Definition at line 229 of file ChunkManagerImpl.h.

template<typename MutexT , typename DataT , typename TraitsT = DataTraits<DataT>>
int const lsst::ap::detail::SubManager< MutexT, DataT, TraitsT >::NUM_CHUNKS = TraitsT::MAX_CHUNKS_PER_FOV * MAX_VISITS_IN_FLIGHT
static

Definition at line 227 of file ChunkManagerImpl.h.


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