LSSTApplications  11.0-24-g0a022a1,14.0+64,15.0,15.0+1,15.0-1-g14e9bfd,15.0-1-g1eca518,15.0-1-g499c38d,15.0-1-g60afb23,15.0-1-g6668b0b,15.0-1-g788a293,15.0-1-g82223af,15.0-1-ga91101e,15.0-1-gae1598d,15.0-1-gc45031d,15.0-1-gd076f1f,15.0-1-gf4f1c34,15.0-1-gfe1617d,15.0-16-g953e39cab,15.0-2-g2010ef9,15.0-2-g33d94b3,15.0-2-g5218728,15.0-2-g947dc0d,15.0-3-g9103c06,15.0-3-ga03b4ca,15.0-3-ga659d1f3,15.0-3-ga695220+2,15.0-3-gaec6799,15.0-3-gb7a597c,15.0-3-gd5b9ff95,15.0-4-g0478fed+2,15.0-4-g45f767a,15.0-4-gff20472+2,15.0-6-ge2d9597
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Member Functions | List of all members
lsst::afw::geom::Functor Class Referenceabstract

Abstract base class for function objects. More...

#include <Functor.h>

Inheritance diagram for lsst::afw::geom::Functor:
lsst::daf::base::Citizen lsst::afw::geom::LinearFunctor

Public Types

enum  { magicSentinel = 0xdeadbeef }
 
typedef unsigned long memId
 Type of the block's ID. More...
 
typedef memId(* memNewCallback) (const memId cid)
 A function used to register a callback. More...
 
typedef memId(* memCallback) (const Citizen *ptr)
 

Public Member Functions

 Functor (std::string const &name)
 
 Functor (Functor const &)
 
 Functor (Functor &&)
 
Functoroperator= (Functor const &)
 
Functoroperator= (Functor &&)
 
virtual ~Functor ()=default
 
virtual std::shared_ptr< Functorclone () const =0
 
virtual double operator() (double x) const =0
 
virtual double inverse (double y, double tol=1e-10, unsigned int maxiter=1000) const
 
virtual double derivative (double x) const =0
 
std::string repr () const
 Return a string representation of a Citizen. More...
 
void markPersistent (void)
 Mark a Citizen as persistent and not destroyed until process end. More...
 
memId getId () const
 Return the Citizen's ID. More...
 

Static Public Member Functions

static bool hasBeenCorrupted ()
 Check all allocated blocks for corruption. More...
 
static memId getNextMemId ()
 Return the memId of the next object to be allocated. More...
 
static int init ()
 Called once when the memory system is being initialised. More...
 
Census

Provide a list of current Citizens

static int census (int, memId startingMemId=0)
 How many active Citizens are there? More...
 
static void census (std::ostream &stream, memId startingMemId=0)
 Print a list of all active Citizens to stream, sorted by ID. More...
 
static const std::vector< const Citizen * > * census ()
 Return a (newly allocated) std::vector of active Citizens sorted by ID. More...
 
callbackIDs

Set callback Ids.

The old Id is returned

static memId setNewCallbackId (memId id)
 Call the NewCallback when block is allocated. More...
 
static memId setDeleteCallbackId (memId id)
 Call the current DeleteCallback when block is deleted. More...
 
callbacks

Set the New/Delete callback functions; in each case the previously installed callback is returned.

These callback functions return a value which is Added to the previously registered id.

The default callback functions are called default{New,Delete}Callback; you may want to set a break point in these callbacks from your favourite debugger

static memNewCallback setNewCallback (memNewCallback func)
 Set the NewCallback function. More...
 
static memCallback setDeleteCallback (memCallback func)
 Set the DeleteCallback function. More...
 
static memCallback setCorruptionCallback (memCallback func)
 Set the CorruptionCallback function. More...
 

Detailed Description

Abstract base class for function objects.

A default implementation of the inverse(...) member function is provided that computes the inverse of the function using the Newton-Raphson method. Concrete subclasses must therefore implement a derivative(...) member function. In cases where the function is analytically invertible, the inverse(...) function should be re-implemented in the subclass using the analytic expression.

Definition at line 50 of file Functor.h.

Member Typedef Documentation

◆ memCallback

typedef memId(* lsst::daf::base::Citizen::memCallback) (const Citizen *ptr)
inherited

Definition at line 59 of file Citizen.h.

◆ memId

typedef unsigned long lsst::daf::base::Citizen::memId
inherited

Type of the block's ID.

Definition at line 56 of file Citizen.h.

◆ memNewCallback

typedef memId(* lsst::daf::base::Citizen::memNewCallback) (const memId cid)
inherited

A function used to register a callback.

Definition at line 58 of file Citizen.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited
Enumerator
magicSentinel 

Definition at line 86 of file Citizen.h.

Constructor & Destructor Documentation

◆ Functor() [1/3]

lsst::afw::geom::Functor::Functor ( std::string const &  name)
explicit
Parameters
nameThe name of the concrete subclass of this class. Used in the exception message from the inverse(...) member function.

Definition at line 35 of file Functor.cc.

35 : daf::base::Citizen(typeid(this)), _name(name) {}
std::string const & _name
Definition: Mask.cc:576

◆ Functor() [2/3]

lsst::afw::geom::Functor::Functor ( Functor const &  )
default

◆ Functor() [3/3]

lsst::afw::geom::Functor::Functor ( Functor &&  )
default

◆ ~Functor()

virtual lsst::afw::geom::Functor::~Functor ( )
virtualdefault

Member Function Documentation

◆ census() [1/3]

int lsst::daf::base::Citizen::census ( int  ,
memId  startingMemId = 0 
)
staticinherited

How many active Citizens are there?

Parameters
startingMemIdDon't print Citizens with lower IDs

Definition at line 261 of file Citizen.cc.

264  {
265  if (startingMemId == 0) { // easy
266  ReadGuard guard(citizenLock);
267  return _activeCitizens.size();
268  }
269 
270  int n = 0;
271  ReadGuard guard(citizenLock);
272  for (table::iterator cur = _activeCitizens.begin();
273  cur != _activeCitizens.end(); cur++) {
274  if (cur->first->_CitizenId >= startingMemId) {
275  n++;
276  }
277  }
278 
279  return n;
280 }
T end(T... args)
T size(T... args)
T begin(T... args)

◆ census() [2/3]

void lsst::daf::base::Citizen::census ( std::ostream stream,
memId  startingMemId = 0 
)
staticinherited

Print a list of all active Citizens to stream, sorted by ID.

Parameters
streamstream to print to
startingMemIdDon't print Citizens with lower IDs

Definition at line 284 of file Citizen.cc.

287  {
288  ReadGuard guard(citizenLock);
289 
291 
292  for (std::vector<Citizen const *>::const_iterator citizen = leaks->begin(), end = leaks->end();
293  citizen != end; ++citizen) {
294  if ((*citizen)->getId() >= startingMemId) {
295  stream << (*citizen)->repr() << "\n";
296  }
297  }
298 }
STL class.
STL class.
T begin(T... args)
int end
static const std::vector< const Citizen * > * census()
Return a (newly allocated) std::vector of active Citizens sorted by ID.
Definition: Citizen.cc:316

◆ census() [3/3]

std::vector< dafBase::Citizen const * > const * lsst::daf::base::Citizen::census ( )
staticinherited

Return a (newly allocated) std::vector of active Citizens sorted by ID.

You are responsible for deleting it; or you can say std::unique_ptr<std::vector<Citizen const*> const> leaks(Citizen::census()); and not bother (that becomes std::unique_ptr in C++11)

Definition at line 316 of file Citizen.cc.

316  {
319  ReadGuard guard(citizenLock);
320  vec->reserve(_activeCitizens.size());
321 
322  for (table::iterator cur = _activeCitizens.begin();
323  cur != _activeCitizens.end(); cur++) {
324  vec->push_back(dynamic_cast<Citizen const*>(cur->first));
325  }
326 
327  std::sort(vec->begin(), vec->end(), cmpId);
328 
329  return vec;
330 }
T end(T... args)
T push_back(T... args)
T size(T... args)
STL class.
T begin(T... args)
T sort(T... args)
T reserve(T... args)

◆ clone()

virtual std::shared_ptr<Functor> lsst::afw::geom::Functor::clone ( ) const
pure virtual

◆ derivative()

virtual double lsst::afw::geom::Functor::derivative ( double  x) const
pure virtual
Returns
df(x)/dx evaluated at x. This is used in the inverse(...) member function.

Implemented in lsst::afw::geom::LinearFunctor.

◆ getId()

dafBase::Citizen::memId lsst::daf::base::Citizen::getId ( ) const
inherited

Return the Citizen's ID.

Definition at line 218 of file Citizen.cc.

218  {
219  return _CitizenId;
220 }

◆ getNextMemId()

dafBase::Citizen::memId lsst::daf::base::Citizen::getNextMemId ( )
staticinherited

Return the memId of the next object to be allocated.

Definition at line 223 of file Citizen.cc.

223  {
224  return _nextMemId();
225 }

◆ hasBeenCorrupted()

bool lsst::daf::base::Citizen::hasBeenCorrupted ( )
staticinherited

Check all allocated blocks for corruption.

Definition at line 347 of file Citizen.cc.

347  {
348  ReadGuard guard(citizenLock);
349  for (table::iterator cur = _activeCitizens.begin();
350  cur != _activeCitizens.end(); cur++) {
351  if (cur->first->_hasBeenCorrupted()) {
352  return true;
353  }
354  }
355  for (table::iterator cur = _persistentCitizens.begin();
356  cur != _persistentCitizens.end(); cur++) {
357  if (cur->first->_hasBeenCorrupted()) {
358  return true;
359  }
360  }
361 
362  return false;
363 }
T end(T... args)
T begin(T... args)

◆ init()

int lsst::daf::base::Citizen::init ( )
staticinherited

Called once when the memory system is being initialised.

Definition at line 208 of file Citizen.cc.

208  {
209  volatile int dummy = 1;
210  return dummy;
211 }

◆ inverse()

double lsst::afw::geom::Functor::inverse ( double  y,
double  tol = 1e-10,
unsigned int  maxiter = 1000 
) const
virtual
Parameters
ydesired value of functor
tolConvergence tolerance for the Newton-Raphson search such that abs(x_{iter} - x_{iter-1}) < tol.
maxiterMaximum number of iterations in the N-R search.
Returns
The x value such that y = f(x).
Exceptions
lsst::pex::exceptions::OutOfRangeErrorif (tol <= 0) or (tol > 1) or (maxiter < 1).
lsst::pex::exceptions::RuntimeErrorif the number of N-R iterations > maxiter.

Definition at line 42 of file Functor.cc.

42  {
43  // Sanity checks for tol and maxiter.
44  if (tol > 1 || tol <= 0) {
45  throw LSST_EXCEPT(lsst::pex::exceptions::OutOfRangeError, "tol out-of-range, tol <=0 or tol > 1");
46  }
47  if (maxiter < 1) {
48  throw LSST_EXCEPT(lsst::pex::exceptions::OutOfRangeError, "maxiter out-of-range, maxiter < 1");
49  }
50  // Use Newton-Raphson method to find the inverse.
51  double x = y;
52  for (unsigned int iter = 0; iter < maxiter; iter++) {
53  double dx = y - operator()(x);
54  if (std::fabs(dx) < tol) {
55  return x;
56  }
57  x += dx / derivative(x);
58  }
60  "max iteration count exceeded for subclass " + _name);
61  return 0;
62 }
virtual double operator()(double x) const =0
std::string const & _name
Definition: Mask.cc:576
int y
Definition: SpanSet.cc:43
virtual double derivative(double x) const =0
T fabs(T... args)
double x
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46

◆ markPersistent()

void lsst::daf::base::Citizen::markPersistent ( void  )
inherited

Mark a Citizen as persistent and not destroyed until process end.

Definition at line 248 of file Citizen.cc.

248  {
249  WriteGuard guard(citizenLock);
250  _persistentCitizens[this] = _activeCitizens[this];
251  _activeCitizens.erase(this);
252 }
T erase(T... args)

◆ operator()()

virtual double lsst::afw::geom::Functor::operator() ( double  x) const
pure virtual
Returns
y = f(x)

Implemented in lsst::afw::geom::LinearFunctor.

◆ operator=() [1/2]

Functor & lsst::afw::geom::Functor::operator= ( Functor const &  )
default

◆ operator=() [2/2]

Functor & lsst::afw::geom::Functor::operator= ( Functor &&  )
default

◆ repr()

std::string lsst::daf::base::Citizen::repr ( ) const
inherited

Return a string representation of a Citizen.

Definition at line 239 of file Citizen.cc.

239  {
240  return boost::str(boost::format("%d: %08x %s")
241  % _CitizenId
242  % this
243  % lsst::utils::demangleType(_typeName)
244  );
245 }
std::string demangleType(std::string const _typeName)
Definition: Demangle.cc:113
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:134

◆ setCorruptionCallback()

dafBase::Citizen::memCallback lsst::daf::base::Citizen::setCorruptionCallback ( Citizen::memCallback  func)
staticinherited

Set the CorruptionCallback function.

Parameters
funcfunction be called when block is found to be corrupted

Definition at line 426 of file Citizen.cc.

428  {
429  Citizen::memCallback old = _corruptionCallback;
430  _corruptionCallback = func;
431 
432  return old;
433 }
memId(* memCallback)(const Citizen *ptr)
Definition: Citizen.h:59

◆ setDeleteCallback()

dafBase::Citizen::memCallback lsst::daf::base::Citizen::setDeleteCallback ( Citizen::memCallback  func)
staticinherited

Set the DeleteCallback function.

Parameters
funcfunction be called when desired block is deleted

Definition at line 416 of file Citizen.cc.

418  {
419  Citizen::memCallback old = _deleteCallback;
420  _deleteCallback = func;
421 
422  return old;
423 }
memId(* memCallback)(const Citizen *ptr)
Definition: Citizen.h:59

◆ setDeleteCallbackId()

dafBase::Citizen::memId lsst::daf::base::Citizen::setDeleteCallbackId ( Citizen::memId  id)
staticinherited

Call the current DeleteCallback when block is deleted.

Parameters
idDesired ID

Definition at line 381 of file Citizen.cc.

383  {
384  WriteGuard guard(citizenLock);
385  Citizen::memId oldId = _deleteId;
386  _deleteId = id;
387 
388  return oldId;
389 }
unsigned long memId
Type of the block&#39;s ID.
Definition: Citizen.h:56
int id
Definition: CR.cc:155

◆ setNewCallback()

dafBase::Citizen::memNewCallback lsst::daf::base::Citizen::setNewCallback ( Citizen::memNewCallback  func)
staticinherited

Set the NewCallback function.

Parameters
funcThe new function to be called when a designated block is allocated

Definition at line 406 of file Citizen.cc.

408  {
409  Citizen::memNewCallback old = _newCallback;
410  _newCallback = func;
411 
412  return old;
413 }
memId(* memNewCallback)(const memId cid)
A function used to register a callback.
Definition: Citizen.h:58

◆ setNewCallbackId()

dafBase::Citizen::memId lsst::daf::base::Citizen::setNewCallbackId ( Citizen::memId  id)
staticinherited

Call the NewCallback when block is allocated.

Parameters
idDesired ID

Definition at line 370 of file Citizen.cc.

372  {
373  WriteGuard guard(citizenLock);
374  Citizen::memId oldId = _newId;
375  _newId = id;
376 
377  return oldId;
378 }
unsigned long memId
Type of the block&#39;s ID.
Definition: Citizen.h:56
int id
Definition: CR.cc:155

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