33 #ifndef LSST_AP_CHUNK_H
34 #define LSST_AP_CHUNK_H
40 #include "boost/noncopyable.hpp"
41 #include "boost/static_assert.hpp"
58 static boost::uint32_t
const MAGIC = 0xdecade14;
84 template <
int MaxBlocksPerChunk>
245 template <
typename AllocatorT,
typename DataT,
typename TraitsT = DataTraits<DataT> >
263 static int const ENTRIES_PER_BLOCK_LOG2 = TraitsT::ENTRIES_PER_BLOCK_LOG2;
264 static int const MAX_BLOCKS = TraitsT::MAX_BLOCKS_PER_CHUNK;
265 static std::size_t
const BLOCK_SIZE =
266 (
sizeof(DataT) +
sizeof(
ChunkEntryFlag)) << ENTRIES_PER_BLOCK_LOG2;
270 ChunkRef(Descriptor * desc, AllocatorT *
all) : _descriptor(desc), _allocator(all) {}
277 boost::int64_t getId()
const {
278 return _descriptor->_chunkId;
280 int getVisitId()
const {
281 return _descriptor->_visitId;
283 bool isUsable()
const {
284 return _descriptor->_usable;
287 _descriptor->_usable =
true;
291 DataT
const &
get(
int const i)
const {
292 assert(i >= 0 && i < _descriptor->_size);
293 return *
reinterpret_cast<DataT
const *
>(map(
294 _descriptor->_blocks[i >> ENTRIES_PER_BLOCK_LOG2] +
296 (i & ((1 << ENTRIES_PER_BLOCK_LOG2) - 1))*
sizeof(DataT)
301 DataT
const * getBlock(
int const b)
const {
302 assert(b >= 0 && b < _descriptor->_numBlocks);
303 return reinterpret_cast<DataT
const *
>(map(
304 _descriptor->_blocks[b] + (
sizeof(
ChunkEntryFlag) << ENTRIES_PER_BLOCK_LOG2)
309 DataT * getBlock(
int const b) {
310 assert(b >= 0 && b < _descriptor->_numBlocks);
311 return reinterpret_cast<DataT *
>(map(
312 _descriptor->_blocks[b] + (
sizeof(
ChunkEntryFlag) << ENTRIES_PER_BLOCK_LOG2)
318 assert(i >= 0 && i < _descriptor->_size);
320 _descriptor->_blocks[i >> ENTRIES_PER_BLOCK_LOG2] +
327 assert(b >= 0 && b < _descriptor->_numBlocks);
328 return reinterpret_cast<ChunkEntryFlag const *
>(map(_descriptor->_blocks[b]));
333 assert(b >= 0 && b < _descriptor->_numBlocks);
334 return reinterpret_cast<ChunkEntryFlag *
>(map(_descriptor->_blocks[b]));
338 void insert(DataT
const & data) {
339 insert(data, IN_DELTA | UNCOMMITTED | INSERTED);
343 void remove(
int const i) {
344 assert(i >= 0 && i < _descriptor->_size);
346 _descriptor->_blocks[i >> ENTRIES_PER_BLOCK_LOG2] +
349 if ((*f & DELETED) == 0) {
350 *f |= DELETED | UNCOMMITTED;
356 return _descriptor->_size;
361 return _descriptor->_delta;
365 int capacity()
const {
366 return _descriptor->_numBlocks << ENTRIES_PER_BLOCK_LOG2;
371 return _descriptor->_nextBlock;
375 int entries(
int const b)
const {
376 assert(b >= 0 && b < _descriptor->_nextBlock);
377 return (b < _descriptor->_nextBlock - 1) ? (1 << ENTRIES_PER_BLOCK_LOG2) : _descriptor->_index;
382 _descriptor->clear();
385 void reserve(
int const n);
386 bool pack(
int const i = 0);
388 void commit(
bool clearDelta =
false);
390 void read(std::string
const & name,
bool const compressed);
391 void readDelta(std::string
const & name,
bool const compressed);
394 std::string
const & name,
395 bool const overwrite,
396 bool const compressed,
397 bool const withDelta =
true
400 std::string
const & name,
401 bool const overwrite,
402 bool const compressed
410 BOOST_STATIC_ASSERT(TraitsT::ENTRIES_PER_BLOCK_LOG2 >= 9);
412 Descriptor * _descriptor;
413 AllocatorT * _allocator;
416 unsigned char * map(std::size_t
const off) {
417 return reinterpret_cast<unsigned char *
>(_allocator) + off;
421 unsigned char const * map(std::size_t
const off)
const {
422 return reinterpret_cast<unsigned char const *
>(_allocator) + off;
426 int const *
const deletes,
427 int const numDeletes,
437 int const n = (1 << ENTRIES_PER_BLOCK_LOG2)
444 #endif // LSST_AP_CHUNK_H
table::Key< table::Array< double > > cd
bool operator<(ChunkDescriptor const &cd) const
unsigned char ChunkEntryFlag
int _chunkId
Identifier for the chunk.
A fixed capacity FIFO buffer for integers.
int _numBlocks
Number of memory blocks allocated.
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, bool >::type all(Scalar const &scalar)
int getNextInChain() const
std::size_t _curBlockOffset
Offset of the current block.
int _nextChunk
Index of the next chunk in the same hash bucket as this one.
void setNextInChain(int const id)
Fifo< MAX_VISITS_IN_FLIGHT > _interestedParties
FIFO of visits to a FOV that overlaps the chunk.
std::size_t _blocks[MaxBlocksPerChunk]
List of memory block offsets for allocated blocks.
Master header file for the association pipeline.
A generic descriptor containing state for different kinds of chunks.
int _delta
Index of first entry marked IN_DELTA.
Compile time constants related to data types to be stored in chunks.
int _index
Index of the next free entry in the current block.
afw::table::Key< double > b
int _size
Total number of entries.
int _nextBlock
Index of the next block to insert into.
int _visitId
Identifier for the visit that currently owns the chunk.