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
Classes | Typedefs | Functions
lsst::ap::detail Namespace Reference

@ endcond More...

Classes

struct  BootstrapLock
 Mutual exclusion lock suitable for initializing shared memory objects. More...
 
class  ObjectMatchProcessor
 Processor for lists of objects matching a difference source. More...
 
struct  MovingObjectPredictionMatchProcessor
 Processor for matches between moving object predictions and difference sources. More...
 
struct  DiscardKnownVariableFilter
 Filter which discards difference sources matching known variable objects. More...
 
struct  DiscardLargeEllipseFilter
 Filter which discards predicted moving objects with large position error ellipses. More...
 
struct  NewObjectCreator
 Records ids of difference sources with no matches. More...
 
struct  BitTraits
 
struct  BitTraits< uint8_t >
 
struct  BitTraits< uint16_t >
 
struct  BitTraits< uint32_t >
 
struct  BitTraits< uint64_t >
 
class  HashedSet
 A set of up to NumEntries elements of type EntryT, hashed by an integer identifier. More...
 
class  BlockAllocator
 A thread-safe memory block allocator that uses a Bitset to track which blocks (out of a fixed size pool of blocks) are in-use/free. More...
 
class  Visit
 State for a single visit to a field of view. More...
 
class  VisitTracker
 Tracks a set of visits. More...
 
class  SubManager
 Helper class for managing chunks of a particular type. More...
 
class  ChunkManagerImpl
 A manager for a set of chunks of a single type. More...
 

Typedefs

typedef BlockAllocator
< SharedMutex, Object
ObjAllocator
 
typedef ChunkManagerImpl
< SharedMutex, Object
ObjChunkMgr
 
typedef
SharedObjectChunkManager::ObjectChunk 
ObjectChunk
 
typedef std::vector< ObjectChunkObjectChunkVector
 
typedef ZoneEntry< ObjectChunkObjectEntry
 
typedef ZoneEntry< DiaSourceChunkDiaSourceEntry
 
typedef Ellipse
< MovingObjectPrediction > 
MovingObjectEllipse
 

Functions

template<typename ManagerT >
ManagerT * getSingleton (char const *const shmObjName, char const *const shmLockName)
 
std::pair< double, double > correctProperMotion (Object const &obj, double const epoch)
 
template<typename EntryT >
void buildZoneIndex (ZoneIndex< EntryT > &index, std::vector< typename EntryT::Chunk > const &chunks, double const epoch)
 
template<typename WordT >
int wordForBit (int const i)
 
template<typename WordT >
WordT maskForBit (int const i)
 
template<typename WordT >
bool setBits (int *const indexes, WordT *const words, int const numBitsToSet, int const numBits)
 
template<typename WordT >
void resetBits (WordT *const words, int const *const indexes, int const numBitsToReset, int const numBits)
 
int hash (boost::uint32_t key)
 
int hash (int key)
 

Detailed Description

@ endcond

Typedef Documentation

Definition at line 116 of file Stages.cc.

typedef Ellipse<MovingObjectPrediction> lsst::ap::detail::MovingObjectEllipse

Definition at line 118 of file Stages.cc.

Definition at line 59 of file ChunkManager.cc.

Definition at line 67 of file ChunkManager.cc.

Definition at line 111 of file Stages.cc.

Definition at line 113 of file Stages.cc.

Definition at line 115 of file Stages.cc.

Function Documentation

template<typename EntryT >
void lsst::ap::detail::buildZoneIndex ( ZoneIndex< EntryT > &  index,
std::vector< typename EntryT::Chunk > const &  chunks,
double const  epoch 
)

Definition at line 383 of file Stages.cc.

387  {
388  typedef typename EntryT::Data Data;
389  typedef typename EntryT::Chunk Chunk;
390  typedef std::vector<Chunk> ChunkVector;
391  typedef typename ChunkVector::const_iterator ChunkIterator;
392  typedef typename ChunkVector::size_type Size;
393 
394  index.clear();
395  if (chunks.empty()) {
396  return;
397  }
398 
399  Stopwatch watch(true);
400 
401  // determine stripe bounds for the input chunks
402  ZoneStripeChunkDecomposition const & zsc = index.getDecomposition();
403  int minStripe = 0x7FFFFFFF;
404  int maxStripe = -1 - minStripe;
405  ChunkIterator const end(chunks.end());
406  for (ChunkIterator c(chunks.begin()); c != end; ++c) {
407  int const stripeId = ZoneStripeChunkDecomposition::chunkToStripe(c->getId());
408  if (stripeId > maxStripe) {
409  maxStripe = stripeId;
410  }
411  if (stripeId < minStripe) {
412  minStripe = stripeId;
413  }
414  }
415  assert(maxStripe >= minStripe && "invalid stripe bounds for chunk list");
416 
417  // Partition input chunks into stripes
418  int const numStripes = maxStripe - minStripe + 1;
419  boost::scoped_array<ChunkVector> stripes(new ChunkVector[numStripes]);
420  for (ChunkIterator c(chunks.begin()); c != end; ++c) {
421  int const stripeId = ZoneStripeChunkDecomposition::chunkToStripe(c->getId());
422  assert(stripeId >= minStripe && stripeId <= maxStripe && "stripe id out of bounds");
423  stripes[stripeId - minStripe].push_back(*c);
424  }
425 
426  double minDec = zsc.getStripeDecMin(minStripe) - 0.001;
427  double maxDec = zsc.getStripeDecMax(maxStripe) + 0.001;
428  index.setDecBounds(std::max(minDec, -90.0), std::min(maxDec, 90.0));
429 
430  // Loop over stripes. Note that due to proper motion, objects from
431  // different stripes can end up in the same zone. Objects are never
432  // migrated across chunks/stripes; rather, their J2000 coordinates
433  // determine the chunks that they will belong to. As time goes on,
434  // the spatial extent of a chunk will grow, where the rate of growth
435  // is bounded by Barnard's star with a proper motion of ~10.5 arcsec/year.
436  // When intersecting the bounding circle of a FOV with chunk boundaries
437  // to determine which chunks must be loaded for association, the bounding
438  // circle must be padded to ensure all relevant objects are loaded.
439  try {
440  for (int s = 0; s < numStripes; ++s) {
441  ChunkVector & vec = stripes[s];
442  Size const numChunks = vec.size();
443 
444  // Loop over chunks in stripe
445  for (Size c = 0; c < numChunks; ++c) {
446  Chunk * const ch = &vec[c];
447  int const numBlocks = ch->blocks();
448  int i = 0;
449 
450  // loop over blocks in chunk
451  for (int b = 0; b < numBlocks; ++b) {
452  int const numEntries = ch->entries(b);
453  Data * const block = ch->getBlock(b);
454  ChunkEntryFlag const * const flags = ch->getFlagBlock(b);
455 
456  // loop over entries in block
457  for (int e = 0; e < numEntries; ++e, ++i) {
458  if ((flags[e] & Chunk::DELETED) == 0) {
459  std::pair<double, double> pos = correctProperMotion(block[e], epoch);
460  index.insert(pos.first, pos.second, &block[e], ch, i);
461  }
462  }
463  }
464  }
465  }
466  } catch(...) {
467  index.clear();
468  throw LSST_EXCEPT(ex::RuntimeError, "Failed to build zone index");
469  }
470 
471  watch.stop();
472  Log log(Log::getDefaultLog(), "lsst.ap");
473  int numElements = static_cast<int>(index.size());
474  Rec(log, Log::INFO) << "inserted elements into zone index" <<
475  Prop<int>("numElements", numElements) <<
476  Prop<double>("time", watch.seconds()) << Rec::endr;
477 
478  // zone structure is filled, sort individual zones (on right ascension)
479  watch.start();
480  index.sort();
481  watch.stop();
482  Rec(log, Log::INFO) << "sorted zone index" <<
483  Prop<int>("numElements", numElements) <<
484  Prop<double>("time", watch.seconds()) << Rec::endr;
485 }
CsvWriter & endr(CsvWriter &w)
Definition: Csv.cc:330
LogRec Rec
Definition: Log.h:838
unsigned char ChunkEntryFlag
Definition: Chunk.h:142
a place to record messages and descriptions of the state of processing.
Definition: Log.h:154
double min
Definition: attributes.cc:216
def log
Definition: log.py:85
double max
Definition: attributes.cc:218
int INFO
Definition: log.py:37
std::pair< double, double > correctProperMotion(Object const &obj, double const epoch)
Definition: Stages.cc:149
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
afw::table::Key< double > b
std::pair<double, double> lsst::ap::detail::correctProperMotion ( Object const &  obj,
double const  epoch 
)
Returns
the proper motion corrected position of the given object

Definition at line 149 of file Stages.cc.

149  {
150  static double const RAD_PER_MAS = (RADIANS_PER_DEGREE/360000.0);
151  // (rad/mas)*(sec/year)/(km/AU)
152  static double const SCALE = RAD_PER_MAS*(365.25*86400/149597870.691);
153 
154  double ra = radians(obj.getRa()); // rad
155  double decl = radians(obj.getDec()); // rad
156 
157  // Convert ra, dec to unit vector in cartesian coordinate system
158  double const sinDecl = std::sin(decl);
159  double const cosDecl = std::cos(decl);
160  double const sinRa = std::sin(ra);
161  double const cosRa = std::cos(ra);
162  double x = cosRa * cosDecl;
163  double y = sinRa * cosDecl;
164  double z = sinDecl;
165 
166  // compute space motion vector (radians per year)
167  double const pmRa = obj.getMuRa()*RAD_PER_MAS/cosDecl;
168  double const pmDecl = obj.getMuDecl()*RAD_PER_MAS;
169  // divide radial velociy by distance to source
170  double const w = obj.getParallax()*obj.getRadialVelocity()*SCALE;
171 
172  double const mx = - pmRa*y - pmDecl*cosRa + x*w;
173  double const my = pmRa*x - pmDecl*sinRa + y*w;
174  double const mz = pmDecl*cosDecl + z*w;
175 
176  // Linear interpolation of position
177  double const dt = (epoch - obj.getEpoch()) * (1/365.25); // julian years
178  x += mx*dt;
179  y += my*dt;
180  z += mz*dt;
181 
182  // Store unit vector for corrected position, convert back to
183  // spherical coords and store scaled integer ra/dec
184  double d2 = x*x + y*y;
185  ra = (d2 == 0.0) ? 0 : degrees(std::atan2(y, x));
186  decl = (z == 0.0) ? 0 : degrees(std::atan2(z, std::sqrt(d2)));
187  if (ra < 0.0) {
188  ra += 360.0;
189  }
190  return std::make_pair(ra, decl);
191 }
int y
AngleUnit const radians
constant with units of radians
Definition: Angle.h:91
AngleUnit const degrees
Definition: Angle.h:92
double w
Definition: CoaddPsf.cc:57
int x
template<typename ManagerT >
ManagerT* lsst::ap::detail::getSingleton ( char const *const  shmObjName,
char const *const  shmLockName 
)

Definition at line 129 of file ChunkManager.cc.

129  {
130 
131  static Mutex mutex;
132  static ManagerT * singleton = 0;
133 
134  ScopedLock<Mutex> lck(mutex);
135  if (singleton != 0) {
136  return singleton;
137  }
138 
139  // Block interference from other processes
140  BootstrapLock blck(shmLockName);
141 
142  std::size_t const pageSize = static_cast<std::size_t>(::getpagesize());
143  std::size_t const numBytes = (ManagerT::size() + pageSize - 1) & ~(pageSize - 1);
144 
145  // 1. try to create shared memory object
146  int fd = ::shm_open(shmObjName, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
147 
148  if (fd == -1) {
149 
150  // failed ...
151  if (errno != EEXIST) {
152  throw LSST_EXCEPT(ex::RuntimeError,
153  (boost::format("shm_open(): failed to create shared memory object %1%, errno: %2%")
154  % shmObjName % errno).str());
155  }
156  // because the shared memory object already exists -- so try to open existing object instead
157  fd = ::shm_open(shmObjName, O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
158  if (fd == -1) {
159  throw LSST_EXCEPT(ex::RuntimeError,
160  (boost::format("shm_open(): failed to open existing shared memory object %1%, errno: %2%")
161  % shmObjName % errno).str());
162  }
163  ScopeGuard g(boost::bind(::close, fd));
164 
165  void * mem = ::mmap(0, numBytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
166  if (mem == 0) {
167  throw LSST_EXCEPT(ex::RuntimeError,
168  (boost::format("mmap(): failed to map %1% bytes of shared memory object %2%, errno: %3%")
169  % numBytes % shmObjName % errno).str());
170  }
171  singleton = static_cast<ManagerT *>(mem);
172  g.dismiss();
173 
174  } else {
175 
176  // shared memory object was created (initially of zero size)
177  ScopeGuard g1(boost::bind(::shm_unlink, shmObjName));
178  ScopeGuard g2(boost::bind(::close, fd));
179 
180  // set size of shared memory object
181  if (::ftruncate(fd, numBytes) != 0) {
182  throw LSST_EXCEPT(ex::RuntimeError,
183  (boost::format(
184  "ftruncate(): failed to set size of shared memory object %1% to %2% bytes, errno: %3%")
185  % shmObjName % numBytes % errno).str());
186  }
187 
188  // map shared memory object
189  void * mem = ::mmap(0, numBytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
190  if (mem == 0) {
191  throw LSST_EXCEPT(ex::RuntimeError,
192  (boost::format("mmap(): failed to map %1% bytes of shared memory object %2%, errno: %3%")
193  % numBytes % shmObjName % errno).str());
194  }
195  ScopeGuard g3(boost::bind(::munmap, mem, numBytes));
196 
197  new (mem) ManagerT();
198  singleton = static_cast<ManagerT *>(mem);
199  g3.dismiss();
200  g2.dismiss();
201  g1.dismiss();
202  }
203 
204  // Try to lock chunk pages into memory to avoid swapping, but ignore failure to do so
205  // - Solaris : process must be run as root
206  // - Linux/Darwin : process must be run as root or RLIMIT_MEMLOCK should be set to a large value
207  ::mlock(static_cast<void *>(singleton), numBytes);
208 
209  // Note: we rely on the system to munmap and close the file descriptor above at process exit.
210 
211  return singleton;
212 }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int lsst::ap::detail::hash ( boost::uint32_t  key)
inline

Returns the 32 bit hash of a 32 bit value using Thomas Wang's mixing function.

Definition at line 55 of file ChunkManagerImpl.cc.

55  {
56  key = (~key) + (key << 15); // key = (key << 15) - key - 1;
57  key = key ^ (key >> 12);
58  key = key + (key << 2);
59  key = key ^ (key >> 4);
60  key = key * 2057; // key = (key + (key << 3)) + (key << 11);
61  key = key ^ (key >> 16);
62  return static_cast<int>(key);
63 }
int lsst::ap::detail::hash ( int  key)
inline

Definition at line 65 of file ChunkManagerImpl.cc.

65  {
66  return hash(static_cast<boost::uint32_t>(key));
67 }
int hash(boost::uint32_t key)
template<typename WordT >
WordT lsst::ap::detail::maskForBit ( int const  i)
inline

Definition at line 84 of file Bitset.h.

84  {
85  return static_cast<WordT>(1) << (i & (BitTraits<WordT>::BITS_PER_WORD - 1));
86 }
template<typename WordT >
void lsst::ap::detail::resetBits ( WordT *const  words,
int const *const  indexes,
int const  numBitsToReset,
int const  numBits 
)

Given the array words containing numBits bits and a list of numBitsToReset indexes, resets (to zero) the bit at each index.

Parameters
[in,out]wordsA memory buffer containing at least numBits bits
[in]indexesAn array of at least numBitsToReset integers, each corresponding to the index of a single bit to reset (to zero).
[in]numBitsToResetThe number of bits to reset (to zero)
[in]numBitsThe number of bits in words

Definition at line 212 of file Bitset.cc.

217  {
218  assert(words != 0 && numBits > 0 && "null or empty bitset");
219  assert(indexes != 0 && numBitsToReset >= 0 && "null or empty index array");
220 
221  for (int i = 0; i < numBitsToReset; ++i) {
222  int const j = indexes[i];
223  assert(j >= 0 && j < numBits);
224  words[wordForBit<WordT>(j)] &= ~ maskForBit<WordT>(j);
225  }
226 }
template<typename WordT >
bool lsst::ap::detail::setBits ( int *const  indexes,
WordT *const  words,
int const  numBitsToSet,
int const  numBits 
)

Attempts to find at least numBitsToSet zero bits in the array words (containing at least numBits bits). If numBitsToSet zero bits cannot be found, false is returned. Otherwise, the first numBitsToSet zero bits in words are set to one and true is returned. The indexes of the bits which were set to one are stored in the indexes array.

Parameters
[out]indexesAn array of at least numBitsToSet integers, which is filled with the indexes of zero bits that were set (to one).
[in,out]wordsA memory buffer containing at least numBits bits
[in]numBitsToSetThe number of bits to reset (to zero)
[in]numBitsThe number of bits in words
Returns
true if numBitsToSet zero bits were found and set to one in words, false otherwise.

Definition at line 149 of file Bitset.cc.

154  {
155  assert(words != 0 && numBits > 0 && "null or empty bitset");
156  assert(indexes != 0 && numBitsToSet > 0 && "null or empty index array");
157 
158  bool const special = (numBits & (BitTraits<WordT>::BITS_PER_WORD - 1)) > 0;
159  WordT const last = ~(maskForBit<WordT>(numBits) - 1);
160  int const nwords = (numBits + (BitTraits<WordT>::BITS_PER_WORD - 1)) >>
161  BitTraits<WordT>::BITS_PER_WORD_LOG2;
162 
163  int zeroes = numBitsToSet;
164  int i;
165  for (i = 0; i < nwords - special && zeroes > 0; ++i) {
166  zeroes -= BitTraits<WordT>::BITS_PER_WORD -
167  populationCount(static_cast<WordT>(words[i] & BitTraits<WordT>::WORD_MASK));
168  }
169  if (zeroes > 0 && special) {
170  zeroes -= BitTraits<WordT>::BITS_PER_WORD -
171  populationCount(static_cast<WordT>((words[i] & BitTraits<WordT>::WORD_MASK) | last));
172  }
173  if (zeroes > 0) {
174  // didn't find enough zeroes
175  return false;
176  }
177 
178  zeroes = 0;
179  for (int i = 0; zeroes < numBitsToSet; ++i) {
180  WordT w = words[i] & BitTraits<WordT>::WORD_MASK;
181  if (w == BitTraits<WordT>::WORD_MASK) {
182  continue;
183  }
184  WordT mask = 1;
185  for (int j = 0; j < BitTraits<WordT>::BITS_PER_WORD; ++j, mask <<= 1) {
186  if ((w & mask) == 0) {
187  indexes[zeroes++] = (i << BitTraits<WordT>::BITS_PER_WORD_LOG2) + j;
188  w |= mask;
189  if (zeroes == numBitsToSet) {
190  break;
191  }
192  }
193  }
194  words[i] = w;
195  }
196 
197  return true;
198 }
double w
Definition: CoaddPsf.cc:57
template<typename WordT >
int lsst::ap::detail::wordForBit ( int const  i)
inline

Definition at line 79 of file Bitset.h.

79  {
80  return (i >> BitTraits<WordT>::BITS_PER_WORD_LOG2);
81 }