LSSTApplications  16.0-1-gce273f5+20,16.0-10-gc1446dd+20,16.0-12-g569485f+3,16.0-13-g5e87145+4,16.0-13-g5f20d24,16.0-13-g80874fd+2,16.0-13-gb122224+11,16.0-13-gd9b1b71+20,16.0-14-g08f9460+3,16.0-15-g77ef378+6,16.0-17-g6a7bfb3b+20,16.0-17-ged3ab9d,16.0-18-gdf247dd+1,16.0-2-g0febb12+16,16.0-2-g839ba83+58,16.0-2-g9d5294e+45,16.0-2-gc6e0ed0+4,16.0-23-ge8a9b866+2,16.0-3-g404ea43+12,16.0-3-gbc759ec+18,16.0-3-gcfd6c53+43,16.0-4-g03cf288+34,16.0-4-g13a27c5+20,16.0-4-g5f3a788+15,16.0-4-g8a0f11a+42,16.0-4-ga3eb747+5,16.0-5-g1991253+20,16.0-5-g1e9226d+3,16.0-5-g865efd9+22,16.0-5-gb3f8a4b+52,16.0-5-gd0f1235+9,16.0-51-gb4b4a8566+2,16.0-7-g6043bfc+8,16.0-7-gd2eeba5+2,16.0-7-gde5bd64+2,16.0-8-g0e813a6,16.0-8-g4dec96c+33,16.0-8-gfd407c0+5,16.0-9-g2f60796+2,master-g5768c874b9+4,w.2018.41
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Member Functions | List of all members
lsst::daf::persistence::Persistence Class Reference

Class implementing object persistence. More...

#include <Persistence.h>

Inheritance diagram for lsst::daf::persistence::Persistence:
lsst::daf::base::Citizen

Public Types

typedef std::shared_ptr< PersistencePtr
 
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

virtual ~Persistence (void)
 Destructor. More...
 
virtual FormatterStorage::Ptr getPersistStorage (std::string const &storageType, LogicalLocation const &location)
 Create a FormatterStorage subclass configured to persist to a location. More...
 
virtual FormatterStorage::Ptr getRetrieveStorage (std::string const &storageType, LogicalLocation const &location)
 Create a FormatterStorage subclass configured to retrieve from a location. More...
 
virtual void persist (lsst::daf::base::Persistable const &persistable, FormatterStorage::List const &storageList, lsst::daf::base::PropertySet::Ptr additionalData)
 Persist a Persistable instance. More...
 
virtual lsst::daf::base::Persistable::Ptr retrieve (std::string const &persistableType, FormatterStorage::List const &storageList, lsst::daf::base::PropertySet::Ptr additionalData)
 Retrieve a Persistable instance. More...
 
virtual lsst::daf::base::PersistableunsafeRetrieve (std::string const &persistableType, FormatterStorage::List const &storageList, lsst::daf::base::PropertySet::Ptr additionalData)
 Retrieve a Persistable instance, returning an unsafe bare pointer. More...
 
lsst::pex::policy::Policy::Ptr getPolicy () const
 Return the policy used to configure the Persistence object. More...
 
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 Ptr getPersistence (lsst::pex::policy::Policy::Ptr policy)
 Create a Persistence object. More...
 
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

Class implementing object persistence.

This class persists and retrieves objects by calling Formatter subclasses with a sequence of FormatterStorage subclasses that have been configured with LogicalLocations. This class handles all transaction semantics by starting per-FormatterStorage transactions, detecting failures, and causing the FormatterStorage subclasses to roll back if necessary.

Definition at line 68 of file Persistence.h.

Member Typedef Documentation

◆ memCallback

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

Definition at line 61 of file Citizen.h.

◆ memId

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

Type of the block's ID.

Definition at line 58 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 60 of file Citizen.h.

◆ Ptr

Definition at line 70 of file Persistence.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited
Enumerator
magicSentinel 

Definition at line 88 of file Citizen.h.

Constructor & Destructor Documentation

◆ ~Persistence()

lsst::daf::persistence::Persistence::~Persistence ( void  )
virtual

Destructor.

Definition at line 66 of file Persistence.cc.

66  {
67 }

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 238 of file Citizen.cc.

240  {
241  if (startingMemId == 0) { // easy
242  ReadGuard guard(citizenLock);
243  return _activeCitizens.size();
244  }
245 
246  int n = 0;
247  ReadGuard guard(citizenLock);
248  for (table::iterator cur = _activeCitizens.begin(); cur != _activeCitizens.end(); cur++) {
249  if (cur->first->_CitizenId >= startingMemId) {
250  n++;
251  }
252  }
253 
254  return n;
255 }
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 259 of file Citizen.cc.

261  {
262  ReadGuard guard(citizenLock);
263 
265 
266  for (std::vector<Citizen const*>::const_iterator citizen = leaks->begin(), end = leaks->end();
267  citizen != end; ++citizen) {
268  if ((*citizen)->getId() >= startingMemId) {
269  stream << (*citizen)->repr() << "\n";
270  }
271  }
272 }
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:287

◆ 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 287 of file Citizen.cc.

287  {
289  ReadGuard guard(citizenLock);
290  vec->reserve(_activeCitizens.size());
291 
292  for (table::iterator cur = _activeCitizens.begin(); cur != _activeCitizens.end(); cur++) {
293  vec->push_back(dynamic_cast<Citizen const*>(cur->first));
294  }
295 
296  std::sort(vec->begin(), vec->end(), cmpId);
297 
298  return vec;
299 }
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)

◆ getId()

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

Return the Citizen's ID.

Definition at line 206 of file Citizen.cc.

206 { return _CitizenId; }

◆ getNextMemId()

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

Return the memId of the next object to be allocated.

Definition at line 209 of file Citizen.cc.

209 { return _nextMemId(); }

◆ getPersistence()

Persistence::Ptr lsst::daf::persistence::Persistence::getPersistence ( lsst::pex::policy::Policy::Ptr  policy)
static

Create a Persistence object.

Parameters
[in]policyPolicy to configure the Persistence object
Returns
Pointer to a Persistence instance

Definition at line 196 of file Persistence.cc.

197  {
198  return Persistence::Ptr(new Persistence(policy));
199 }
std::shared_ptr< Persistence > Ptr
Definition: Persistence.h:70

◆ getPersistStorage()

FormatterStorage::Ptr lsst::daf::persistence::Persistence::getPersistStorage ( std::string const &  storageType,
LogicalLocation const &  location 
)
virtual

Create a FormatterStorage subclass configured to persist to a location.

Parameters
[in]storageTypeName of FormatterStorage subclass as registered in StorageRegistry
[in]locationLocation to persist to (subclass-specific)

Definition at line 91 of file Persistence.cc.

92  {
93  return _getStorage(storageType, location, true);
94 }

◆ getPolicy()

lsst::pex::policy::Policy::Ptr lsst::daf::persistence::Persistence::getPolicy ( ) const

Return the policy used to configure the Persistence object.

Returns
Pointer to Policy

Definition at line 205 of file Persistence.cc.

206 {
207  return _policy;
208 }

◆ getRetrieveStorage()

FormatterStorage::Ptr lsst::daf::persistence::Persistence::getRetrieveStorage ( std::string const &  storageType,
LogicalLocation const &  location 
)
virtual

Create a FormatterStorage subclass configured to retrieve from a location.

Parameters
[in]storageTypeName of FormatterStorage subclass as registered in StorageRegistry
[in]locationLocation to retrieve from (subclass-specific)

Definition at line 101 of file Persistence.cc.

102  {
103  return _getStorage(storageType, location, false);
104 }

◆ hasBeenCorrupted()

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

Check all allocated blocks for corruption.

Definition at line 316 of file Citizen.cc.

316  {
317  ReadGuard guard(citizenLock);
318  for (table::iterator cur = _activeCitizens.begin(); cur != _activeCitizens.end(); cur++) {
319  if (cur->first->_hasBeenCorrupted()) {
320  return true;
321  }
322  }
323  for (table::iterator cur = _persistentCitizens.begin(); cur != _persistentCitizens.end(); cur++) {
324  if (cur->first->_hasBeenCorrupted()) {
325  return true;
326  }
327  }
328 
329  return false;
330 }
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 196 of file Citizen.cc.

196  {
197  volatile int dummy = 1;
198  return dummy;
199 }

◆ markPersistent()

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

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

Definition at line 225 of file Citizen.cc.

225  {
226  WriteGuard guard(citizenLock);
227  _persistentCitizens[this] = _activeCitizens[this];
228  _activeCitizens.erase(this);
229 }
T erase(T... args)

◆ persist()

void lsst::daf::persistence::Persistence::persist ( lsst::daf::base::Persistable const &  persistable,
FormatterStorage::List const &  storageList,
lsst::daf::base::PropertySet::Ptr  additionalData 
)
virtual

Persist a Persistable instance.

Parameters
[in]persistableThe Persistable instance
[in]storageListList of storages to persist to (in order)
[in]additionalDataAdditional information needed to determine the correct place to put data in any of the Storages

Definition at line 112 of file Persistence.cc.

114  {
115  // Get the policies for all Formatters, if present
116  std::string policyName = "Formatter";
118  if (_policy && _policy->exists(policyName)) {
119  policyPtr = _policy->getPolicy(policyName);
120  }
121  // Find the appropriate Formatter.
122  Formatter::Ptr f =
123  Formatter::lookupFormatter(typeid(persistable), policyPtr);
124  // Use the Formatter instance to write the Persistable to each FormatterStorage
125  // in turn. Commit the transactions (in order) when all writing is
126  // complete.
127  for (FormatterStorage::List::const_iterator it = storageList.begin();
128  it != storageList.end(); ++it) {
129  (*it)->startTransaction();
130  f->write(&persistable, *it, additionalData);
131  }
132  for (FormatterStorage::List::const_iterator it = storageList.begin();
133  it != storageList.end(); ++it) {
134  (*it)->endTransaction();
135  }
136 }
std::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
STL class.
static Formatter::Ptr lookupFormatter(std::string const &persistableType, lsst::pex::policy::Policy::Ptr policy)
Lookup Formatter subclass by name of Persistable subclass.
Definition: Formatter.cc:84

◆ repr()

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

Return a string representation of a Citizen.

Definition at line 219 of file Citizen.cc.

219  {
220  return boost::str(boost::format("%d: %08x %s") % _CitizenId % this %
221  lsst::utils::demangleType(_typeName));
222 }
std::string demangleType(std::string const _typeName)
Definition: Demangle.cc:113
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:129

◆ retrieve()

lsst::daf::base::Persistable::Ptr lsst::daf::persistence::Persistence::retrieve ( std::string const &  persistableType,
FormatterStorage::List const &  storageList,
lsst::daf::base::PropertySet::Ptr  additionalData 
)
virtual

Retrieve a Persistable instance.

Parameters
[in]persistableTypeName of Persistable type to be retrieved as registered by its Formatter
[in]storageListList of storages to retrieve from (in order)
[in]additionalDataAdditional information needed to select the correct data from any of the FormatterStorages
Returns
Shared pointer to new Persistable instance

Definition at line 185 of file Persistence.cc.

187  {
189  unsafeRetrieve(persistableType, storageList, additionalData));
190 }
virtual lsst::daf::base::Persistable * unsafeRetrieve(std::string const &persistableType, FormatterStorage::List const &storageList, lsst::daf::base::PropertySet::Ptr additionalData)
Retrieve a Persistable instance, returning an unsafe bare pointer.
Definition: Persistence.cc:147
std::shared_ptr< Persistable > Ptr
Definition: Persistable.h:77

◆ 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 391 of file Citizen.cc.

393  {
394  Citizen::memCallback old = _corruptionCallback;
395  _corruptionCallback = func;
396 
397  return old;
398 }
memId(* memCallback)(const Citizen *ptr)
Definition: Citizen.h:61

◆ 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 381 of file Citizen.cc.

383  {
384  Citizen::memCallback old = _deleteCallback;
385  _deleteCallback = func;
386 
387  return old;
388 }
memId(* memCallback)(const Citizen *ptr)
Definition: Citizen.h:61

◆ 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 347 of file Citizen.cc.

348  {
349  WriteGuard guard(citizenLock);
350  Citizen::memId oldId = _deleteId;
351  _deleteId = id;
352 
353  return oldId;
354 }
unsigned long memId
Type of the block&#39;s ID.
Definition: Citizen.h:58
int id
Definition: CR.cc:143

◆ 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 371 of file Citizen.cc.

373  {
374  Citizen::memNewCallback old = _newCallback;
375  _newCallback = func;
376 
377  return old;
378 }
memId(* memNewCallback)(const memId cid)
A function used to register a callback.
Definition: Citizen.h:60

◆ 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 337 of file Citizen.cc.

338  {
339  WriteGuard guard(citizenLock);
340  Citizen::memId oldId = _newId;
341  _newId = id;
342 
343  return oldId;
344 }
unsigned long memId
Type of the block&#39;s ID.
Definition: Citizen.h:58
int id
Definition: CR.cc:143

◆ unsafeRetrieve()

lsst::daf::base::Persistable * lsst::daf::persistence::Persistence::unsafeRetrieve ( std::string const &  persistableType,
FormatterStorage::List const &  storageList,
lsst::daf::base::PropertySet::Ptr  additionalData 
)
virtual

Retrieve a Persistable instance, returning an unsafe bare pointer.

Intended for use by SWIG/Python only.

Parameters
[in]persistableTypeName of Persistable type to be retrieved as registered by its Formatter
[in]storageListList of storages to retrieve from (in order)
[in]additionalDataAdditional information needed to select the correct data from any of the Storages
Returns
Bare pointer to new Persistable instance

Definition at line 147 of file Persistence.cc.

149  {
150  // Get the policies for all Formatters, if present
151  std::string policyName = "Formatter";
153  if (_policy && _policy->exists(policyName)) {
154  policyPtr = _policy->getPolicy(policyName);
155  }
156  // Find the appropriate Formatter.
157  Formatter::Ptr f = Formatter::lookupFormatter(persistableType, policyPtr);
158  // Use the Formatter instance to read from the first FormatterStorage; then update
159  // from each additional FormatterStorage in turn.
161  for (FormatterStorage::List::const_iterator it = storageList.begin();
162  it != storageList.end(); ++it) {
163  (*it)->startTransaction();
164  if (!persistable) {
165  persistable = f->read(*it, additionalData);
166  } else {
167  f->update(persistable, *it, additionalData);
168  }
169  }
170  for (FormatterStorage::List::const_iterator it = storageList.begin();
171  it != storageList.end(); ++it) {
172  (*it)->endTransaction();
173  }
174  return persistable;
175 }
std::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
STL class.
static Formatter::Ptr lookupFormatter(std::string const &persistableType, lsst::pex::policy::Policy::Ptr policy)
Lookup Formatter subclass by name of Persistable subclass.
Definition: Formatter.cc:84
Base class for all persistable classes.
Definition: Persistable.h:75

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