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 Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
lsst::daf::persistence::PropertySetFormatter Class Reference

Formatter for persistence of PropertySet instances. More...

#include <PropertySetFormatter.h>

Inheritance diagram for lsst::daf::persistence::PropertySetFormatter:
lsst::daf::persistence::Formatter lsst::daf::base::Citizen

Public Member Functions

virtual ~PropertySetFormatter (void)
 
virtual void write (dafBase::Persistable const *persistable, dafPersist::Storage::Ptr storage, dafBase::PropertySet::Ptr additionalData)
 
virtual dafBase::Persistableread (dafPersist::Storage::Ptr storage, dafBase::PropertySet::Ptr additionalData)
 
virtual void update (dafBase::Persistable *persistable, dafPersist::Storage::Ptr storage, dafBase::PropertySet::Ptr additionalData)
 
- Public Member Functions inherited from lsst::daf::persistence::Formatter
virtual ~Formatter (void)
 
virtual void write (lsst::daf::base::Persistable const *persistable, Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)=0
 
virtual
lsst::daf::base::Persistable
read (Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)=0
 
virtual void update (lsst::daf::base::Persistable *persistable, Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)=0
 
- 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

template<class Archive >
static void delegateSerialize (Archive &ar, unsigned int const version, dafBase::Persistable *persistable)
 
- Static Public Member Functions inherited from lsst::daf::persistence::Formatter
static Formatter::Ptr lookupFormatter (std::string const &persistableType, lsst::pex::policy::Policy::Ptr policy)
 
static Formatter::Ptr lookupFormatter (std::type_info const &persistableType, 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

 PropertySetFormatter (pexPolicy::Policy::Ptr policy)
 

Static Private Member Functions

static Formatter::Ptr createInstance (pexPolicy::Policy::Ptr policy)
 

Private Attributes

pexPolicy::Policy::Ptr _policy
 

Static Private Attributes

static FormatterRegistration registration
 

Additional Inherited Members

- Public Types inherited from lsst::daf::persistence::Formatter
typedef boost::shared_ptr
< Formatter
Ptr
 
typedef Ptr(* FactoryPtr )(lsst::pex::policy::Policy::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)
 
- Protected Member Functions inherited from lsst::daf::persistence::Formatter
 Formatter (std::type_info const &type)
 

Detailed Description

Formatter for persistence of PropertySet instances.

Definition at line 58 of file PropertySetFormatter.h.

Constructor & Destructor Documentation

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

Minimal destructor.

Definition at line 95 of file PropertySetFormatter.cc.

95  {
96 }
lsst::daf::persistence::PropertySetFormatter::PropertySetFormatter ( pexPolicy::Policy::Ptr  policy)
private

Constructor.

Parameters
[in]policyPolicy for configuring this Formatter

Definition at line 88 of file PropertySetFormatter.cc.

89  :
90  dafPersist::Formatter(typeid(*this)), _policy(policy) {
91 }
Abstract base class for all formatters.
Definition: Formatter.h:79

Member Function Documentation

dafPersist::Formatter::Ptr lsst::daf::persistence::PropertySetFormatter::createInstance ( pexPolicy::Policy::Ptr  policy)
staticprivate

Factory method for PropertySetFormatter.

Parameters
[in]policyPolicy for configuring the PropertySetFormatter
Returns
Shared pointer to a new instance

Definition at line 251 of file PropertySetFormatter.cc.

252  {
254 }
boost::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
Formatter for persistence of PropertySet instances.
template<class Archive >
void lsst::daf::persistence::PropertySetFormatter::delegateSerialize ( Archive &  ar,
unsigned int const  version,
dafBase::Persistable persistable 
)
static

Serialize a PropertySet to a Boost archive. Handles text or XML archives, input or output.

Parameters
[in,out]arBoost archive
[in]versionVersion of the PropertySet class
[in,out]persistablePointer to the PropertySet as a Persistable

Definition at line 115 of file PropertySetFormatter.cc.

116  {
118  dynamic_cast<dafBase::PropertySet*>(persistable);
119  if (ps == 0) {
120  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-PropertySet");
121  }
122  ar & make_nvp("base",
123  boost::serialization::base_object<dafBase::Persistable>(*ps));
124 
125  std::vector<std::string> names;
126  size_t nNames;
127  if (Archive::is_saving::value) {
128  names = ps->paramNames(false);
129  nNames = names.size();
130  }
131  ar & make_nvp("nitems", nNames);
132 
133  char type;
134  std::string name;
135  for (size_t i = 0; i < nNames; ++i) {
136  if (Archive::is_saving::value) {
137  name = names[i];
138  std::type_info const& id(ps->typeOf(name));
139 
140  if (id == typeid(bool)) type = 'b';
141  else if (id == typeid(char)) type = 'c';
142  else if (id == typeid(signed char)) type = 'y';
143  else if (id == typeid(unsigned char)) type = 'C';
144  else if (id == typeid(short)) type = 'w';
145  else if (id == typeid(unsigned short)) type = 'W';
146  else if (id == typeid(int)) type = 'i';
147  else if (id == typeid(unsigned int)) type = 'I';
148  else if (id == typeid(long)) type = 'l';
149  else if (id == typeid(unsigned long)) type = 'L';
150  else if (id == typeid(long long)) type = 'x';
151  else if (id == typeid(unsigned long long)) type = 'X';
152  else if (id == typeid(float)) type = 'f';
153  else if (id == typeid(double)) type = 'd';
154  else if (id == typeid(std::string)) type = 's';
155  else if (id == typeid(dafBase::DateTime)) type = 'T';
156  else if (id == typeid(dafBase::Persistable::Ptr)) type = 'p';
157  else {
158  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
159  name +
160  ": Unknown type in PropertySet serialize");
161  }
162  }
163 
164  ar & make_nvp("name", name);
165  ar & make_nvp("type", type);
166  switch (type) {
167  case 'b': serializeItem<Archive, bool>(ar, name, ps); break;
168  case 'c': serializeItem<Archive, char>(ar, name, ps); break;
169  case 'y': serializeItem<Archive, signed char>(ar, name, ps); break;
170  case 'C': serializeItem<Archive, unsigned char>(ar, name, ps); break;
171  case 'w': serializeItem<Archive, short>(ar, name, ps); break;
172  case 'W': serializeItem<Archive, unsigned short>(ar, name, ps); break;
173  case 'i': serializeItem<Archive, int>(ar, name, ps); break;
174  case 'I': serializeItem<Archive, unsigned int>(ar, name, ps); break;
175  case 'l': serializeItem<Archive, long>(ar, name, ps); break;
176  case 'L': serializeItem<Archive, unsigned long>(ar, name, ps); break;
177  case 'x': serializeItem<Archive, long long>(ar, name, ps); break;
178  case 'X': serializeItem<Archive, unsigned long long>(ar, name, ps); break;
179  case 'f': serializeItem<Archive, float>(ar, name, ps); break;
180  case 'd': serializeItem<Archive, double>(ar, name, ps); break;
181  case 's': serializeItem<Archive, std::string>(ar, name, ps); break;
182  case 'T': serializeDateTime<Archive>(ar, name, ps); break;
183  case 'p': serializeItem<Archive, dafBase::Persistable::Ptr>(ar, name, ps); break;
184  default:
185  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
186  std::string("Unknown type reading PropertySet") +
187  type + ", name = " + name);
188  }
189  }
190 }
std::vector< std::string > paramNames(bool topLevelOnly=true) const
Definition: PropertySet.cc:142
Class for handling dates/times, including MJD, UTC, and TAI.
Definition: DateTime.h:58
table::Key< std::string > name
Definition: ApCorrMap.cc:71
boost::shared_ptr< Persistable > Ptr
Definition: Persistable.h:76
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
std::type_info const & typeOf(std::string const &name) const
Definition: PropertySet.cc:227
Class for storing generic metadata.
Definition: PropertySet.h:82
int id
Definition: CR.cc:151
dafBase::Persistable * lsst::daf::persistence::PropertySetFormatter::read ( dafPersist::Storage::Ptr  storage,
dafBase::PropertySet::Ptr  additionalData 
)
virtual

Definition at line 218 of file PropertySetFormatter.cc.

219  {
220  execTrace("PropertySetFormatter read start");
222  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
223  execTrace("PropertySetFormatter read BoostStorage");
224  dafPersist::BoostStorage* boost =
225  dynamic_cast<dafPersist::BoostStorage*>(storage.get());
226  boost->getIArchive() & *ps;
227  execTrace("PropertySetFormatter read end");
228  return ps;
229  }
230  else if (typeid(*storage) == typeid(dafPersist::XmlStorage)) {
231  execTrace("PropertySetFormatter read XmlStorage");
233  dynamic_cast<dafPersist::XmlStorage*>(storage.get());
234  xml->getIArchive() & make_nvp("propertySet", *ps);
235  execTrace("PropertySetFormatter read end");
236  return ps;
237  }
238  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for PropertySet");
239 }
Class for XML file storage.
Definition: XmlStorage.h:57
virtual boost::archive::text_iarchive & getIArchive(void)
virtual boost::archive::xml_iarchive & getIArchive(void)
Definition: XmlStorage.cc:114
lsst::daf::base::PropertySet PropertySet
Definition: Wcs.cc:58
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Class for storing generic metadata.
Definition: PropertySet.h:82
Class for boost::serialization storage.
Definition: BoostStorage.h:58
void lsst::daf::persistence::PropertySetFormatter::update ( dafBase::Persistable persistable,
dafPersist::Storage::Ptr  storage,
dafBase::PropertySet::Ptr  additionalData 
)
virtual

Definition at line 241 of file PropertySetFormatter.cc.

243  {
244  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unexpected call to update for PropertySet");
245 }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void lsst::daf::persistence::PropertySetFormatter::write ( dafBase::Persistable const *  persistable,
dafPersist::Storage::Ptr  storage,
dafBase::PropertySet::Ptr  additionalData 
)
virtual

Definition at line 98 of file PropertySetFormatter.cc.

101  {
102  execTrace("PropertySetFormatter write start");
103  dafBase::PropertySet const* ps =
104  dynamic_cast<dafBase::PropertySet const*>(persistable);
105  if (ps == 0) {
106  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-PropertySet");
107  }
108  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
109  execTrace("PropertySetFormatter write BoostStorage");
110  dafPersist::BoostStorage* boost =
111  dynamic_cast<dafPersist::BoostStorage*>(storage.get());
112  boost->getOArchive() & *ps;
113  execTrace("PropertySetFormatter write end");
114  return;
115  }
116  else if (typeid(*storage) == typeid(dafPersist::XmlStorage)) {
117  execTrace("PropertySetFormatter write XmlStorage");
119  dynamic_cast<dafPersist::XmlStorage*>(storage.get());
120  xml->getOArchive() & make_nvp("propertySet", *ps);
121  execTrace("PropertySetFormatter write end");
122  return;
123  }
124  else if (typeid(*storage) == typeid(dafPersist::DbStorage)) {
125  execTrace("PropertySetFormatter write DbStorage");
127  dynamic_cast<dafPersist::DbStorage*>(storage.get());
128 
129  std::string itemName = additionalData->getAsString("itemName");
130  std::string tableName = itemName;
131  pexPolicy::Policy::Ptr itemPolicy;
132  if (_policy && _policy->exists(itemName)) {
133  itemPolicy = _policy->getPolicy(itemName);
134  if (itemPolicy->exists("TableName")) {
135  tableName = itemPolicy->getString("TableName");
136  }
137  }
138  db->setTableForInsert(tableName);
139 
140  std::vector<std::string> list;
141  if (itemPolicy && itemPolicy->exists("KeyList")) {
142  pexPolicy::Policy::StringArray const& array(
143  itemPolicy->getStringArray("KeyList"));
144  for (pexPolicy::Policy::StringArray::const_iterator it =
145  array.begin(); it != array.end(); ++it) {
146  list.push_back(*it);
147  }
148  }
149  else {
150  list = ps->paramNames(false);
151  }
152 
153  for (std::vector<std::string>::const_iterator it = list.begin();
154  it != list.end(); ++it) {
155  std::string::size_type split = it->find('=');
156  std::string colName;
157  std::string key;
158  if (split == std::string::npos) {
159  colName = key = *it;
160  }
161  else {
162  colName = it->substr(0, split);
163  key = it->substr(split + 1);
164  }
165 
166  if (!ps->exists(key)) {
167  db->setColumnToNull(colName);
168  continue;
169  }
170 
171  std::type_info const& type(ps->typeOf(key));
172 
173  if (type == typeid(bool)) {
174  db->setColumn<bool>(colName, ps->get<bool>(key));
175  }
176  else if (type == typeid(char)) {
177  db->setColumn<char>(colName, ps->get<char>(key));
178  }
179  else if (type == typeid(short)) {
180  db->setColumn<short>(colName, ps->get<short>(key));
181  }
182  else if (type == typeid(int)) {
183  db->setColumn<int>(colName, ps->get<int>(key));
184  }
185  else if (type == typeid(long)) {
186  db->setColumn<long>(colName, ps->get<long>(key));
187  }
188  else if (type == typeid(long long)) {
189  db->setColumn<long long>(colName, ps->get<long long>(key));
190  }
191  else if (type == typeid(float)) {
192  db->setColumn<float>(colName, ps->get<float>(key));
193  }
194  else if (type == typeid(double)) {
195  db->setColumn<double>(colName, ps->get<double>(key));
196  }
197  else if (type == typeid(std::string)) {
198  db->setColumn<std::string>(colName, ps->get<std::string>(key));
199  }
200  else if (type == typeid(dafBase::DateTime)) {
202  colName, ps->get<dafBase::DateTime>(key));
203  }
204  else {
205  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
206  std::string("Unknown type ") + type.name() +
207  " in PropertySetFormatter write");
208  }
209  }
210  db->insertRow();
211  execTrace("PropertySetFormatter write end");
212  return;
213  }
214 
215  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for PropertySet");
216 }
std::vector< std::string > paramNames(bool topLevelOnly=true) const
Definition: PropertySet.cc:142
Class for XML file storage.
Definition: XmlStorage.h:57
Class for handling dates/times, including MJD, UTC, and TAI.
Definition: DateTime.h:58
void setColumn(std::string const &columnName, T const &value)
Definition: DbStorage.cc:152
boost::shared_ptr< Policy > Ptr
Definition: Policy.h:172
Class for database storage.
Definition: DbStorage.h:63
std::vector< std::string > StringArray
Definition: Policy.h:181
T get(std::string const &name) const
Definition: PropertySet.cc:246
virtual void insertRow(void)
Definition: DbStorage.cc:166
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
virtual boost::archive::text_oarchive & getOArchive(void)
virtual boost::archive::xml_oarchive & getOArchive(void)
Definition: XmlStorage.cc:107
std::type_info const & typeOf(std::string const &name) const
Definition: PropertySet.cc:227
Class for storing generic metadata.
Definition: PropertySet.h:82
Class for boost::serialization storage.
Definition: BoostStorage.h:58
virtual void setTableForInsert(std::string const &tableName)
Definition: DbStorage.cc:143
bool exists(std::string const &name) const
Definition: PropertySet.cc:190
virtual void setColumnToNull(std::string const &columnName)
Definition: DbStorage.cc:159

Member Data Documentation

pexPolicy::Policy::Ptr lsst::daf::persistence::PropertySetFormatter::_policy
private

Definition at line 80 of file PropertySetFormatter.h.

dafPersist::FormatterRegistration lsst::daf::persistence::PropertySetFormatter::registration
staticprivate

Register this Formatter subclass through a static instance of FormatterRegistration.

Definition at line 84 of file PropertySetFormatter.h.


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