LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | 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 boost::shared_ptr
< Persistence
Ptr
 
- Public Types inherited from lsst::daf::base::Citizen
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)
 
virtual Storage::Ptr getPersistStorage (std::string const &storageType, LogicalLocation const &location)
 
virtual Storage::Ptr getRetrieveStorage (std::string const &storageType, LogicalLocation const &location)
 
virtual void persist (lsst::daf::base::Persistable const &persistable, Storage::List const &storageList, lsst::daf::base::PropertySet::Ptr additionalData)
 
virtual
lsst::daf::base::Persistable::Ptr 
retrieve (std::string const &persistableType, Storage::List const &storageList, lsst::daf::base::PropertySet::Ptr additionalData)
 
virtual
lsst::daf::base::Persistable
unsafeRetrieve (std::string const &persistableType, Storage::List const &storageList, lsst::daf::base::PropertySet::Ptr additionalData)
 
lsst::pex::policy::Policy::Ptr getPolicy () const
 
- Public Member Functions inherited from lsst::daf::base::Citizen
 Citizen (const std::type_info &)
 
 Citizen (Citizen const &)
 
 ~Citizen ()
 
Citizenoperator= (Citizen const &)
 
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)
 
- Static Public Member Functions inherited from lsst::daf::base::Citizen
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...
 
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...
 
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...
 
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...
 

Private Member Functions

 Persistence (lsst::pex::policy::Policy::Ptr policy)
 
 Persistence (Persistence const &)
 
Persistenceoperator= (Persistence const &)
 
Storage::Ptr _getStorage (std::string const &storageType, LogicalLocation const &location, bool persist)
 

Private Attributes

lsst::pex::policy::Policy::Ptr _policy
 Pointer to Policy used to configure Persistence. More...
 

Detailed Description

Class implementing object persistence.

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

Definition at line 68 of file Persistence.h.

Member Typedef Documentation

Definition at line 70 of file Persistence.h.

Constructor & Destructor Documentation

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

Destructor.

Definition at line 66 of file Persistence.cc.

66  {
67 }
lsst::daf::persistence::Persistence::Persistence ( lsst::pex::policy::Policy::Ptr  policy)
explicitprivate

Constructor.

Parameters
[in]policyPolicy to configure the Persistence object

Definition at line 60 of file Persistence.cc.

60  :
61  lsst::daf::base::Citizen(typeid(*this)), _policy(policy) {
62 }
lsst::pex::policy::Policy::Ptr _policy
Pointer to Policy used to configure Persistence.
Definition: Persistence.h:103
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:56
lsst::daf::persistence::Persistence::Persistence ( Persistence const &  )
private

Member Function Documentation

Storage::Ptr lsst::daf::persistence::Persistence::_getStorage ( std::string const &  storageType,
LogicalLocation const &  location,
bool  persist 
)
private

Create a Storage subclass configured for a particular access.

Parameters
[in]storageTypeName of Storage subclass as registered in StorageRegistry
[in]locationLocation to persist to or retrieve from (subclass-specific)
[in]persistTrue if persisting, false if retrieving

Definition at line 76 of file Persistence.cc.

78  {
80  if (_policy && _policy->exists(storageType)) {
81  policyPtr = _policy->getPolicy(storageType);
82  }
83  return Storage::createInstance(storageType, location, persist, policyPtr);
84 }
boost::shared_ptr< Policy > Ptr
Definition: Policy.h:172
static Ptr createInstance(std::string const &name, LogicalLocation const &location, bool persist, lsst::pex::policy::Policy::Ptr policy)
Definition: Storage.cc:75
lsst::pex::policy::Policy::Ptr _policy
Pointer to Policy used to configure Persistence.
Definition: Persistence.h:103
virtual void persist(lsst::daf::base::Persistable const &persistable, Storage::List const &storageList, lsst::daf::base::PropertySet::Ptr additionalData)
Definition: Persistence.cc:112
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 }
Persistence(lsst::pex::policy::Policy::Ptr policy)
Definition: Persistence.cc:60
boost::shared_ptr< Persistence > Ptr
Definition: Persistence.h:70
Storage::Ptr lsst::daf::persistence::Persistence::getPersistStorage ( std::string const &  storageType,
LogicalLocation const &  location 
)
virtual

Create a Storage subclass configured to persist to a location.

Parameters
[in]storageTypeName of Storage 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 }
Storage::Ptr _getStorage(std::string const &storageType, LogicalLocation const &location, bool persist)
Definition: Persistence.cc:76
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 }
lsst::pex::policy::Policy::Ptr _policy
Pointer to Policy used to configure Persistence.
Definition: Persistence.h:103
Storage::Ptr lsst::daf::persistence::Persistence::getRetrieveStorage ( std::string const &  storageType,
LogicalLocation const &  location 
)
virtual

Create a Storage subclass configured to retrieve from a location.

Parameters
[in]storageTypeName of Storage 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 }
Storage::Ptr _getStorage(std::string const &storageType, LogicalLocation const &location, bool persist)
Definition: Persistence.cc:76
Persistence& lsst::daf::persistence::Persistence::operator= ( Persistence const &  )
private
void lsst::daf::persistence::Persistence::persist ( lsst::daf::base::Persistable const &  persistable,
Storage::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 Storage
125  // in turn. Commit the transactions (in order) when all writing is
126  // complete.
127  for (Storage::List::const_iterator it = storageList.begin();
128  it != storageList.end(); ++it) {
129  (*it)->startTransaction();
130  f->write(&persistable, *it, additionalData);
131  }
132  for (Storage::List::const_iterator it = storageList.begin();
133  it != storageList.end(); ++it) {
134  (*it)->endTransaction();
135  }
136 }
boost::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
boost::shared_ptr< Policy > Ptr
Definition: Policy.h:172
lsst::pex::policy::Policy::Ptr _policy
Pointer to Policy used to configure Persistence.
Definition: Persistence.h:103
static Formatter::Ptr lookupFormatter(std::string const &persistableType, lsst::pex::policy::Policy::Ptr policy)
Definition: Formatter.cc:84
lsst::daf::base::Persistable::Ptr lsst::daf::persistence::Persistence::retrieve ( std::string const &  persistableType,
Storage::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 Storages
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, Storage::List const &storageList, lsst::daf::base::PropertySet::Ptr additionalData)
Definition: Persistence.cc:147
boost::shared_ptr< Persistable > Ptr
Definition: Persistable.h:76
lsst::daf::base::Persistable * lsst::daf::persistence::Persistence::unsafeRetrieve ( std::string const &  persistableType,
Storage::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 Storage; then update
159  // from each additional Storage in turn.
160  lsst::daf::base::Persistable* persistable = 0;
161  for (Storage::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 (Storage::List::const_iterator it = storageList.begin();
171  it != storageList.end(); ++it) {
172  (*it)->endTransaction();
173  }
174  return persistable;
175 }
boost::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
boost::shared_ptr< Policy > Ptr
Definition: Policy.h:172
lsst::pex::policy::Policy::Ptr _policy
Pointer to Policy used to configure Persistence.
Definition: Persistence.h:103
static Formatter::Ptr lookupFormatter(std::string const &persistableType, lsst::pex::policy::Policy::Ptr policy)
Definition: Formatter.cc:84
Base class for all persistable classes.
Definition: Persistable.h:74

Member Data Documentation

lsst::pex::policy::Policy::Ptr lsst::daf::persistence::Persistence::_policy
private

Pointer to Policy used to configure Persistence.

Definition at line 103 of file Persistence.h.


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