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 Attributes | List of all members
lsst::afw::formatters::WcsFormatter Class Reference

Class implementing persistence and retrieval for Wcs objects. More...

#include <WcsFormatter.h>

Inheritance diagram for lsst::afw::formatters::WcsFormatter:
lsst::daf::persistence::Formatter lsst::daf::base::Citizen

Public Member Functions

virtual ~WcsFormatter (void)
 
virtual void write (lsst::daf::base::Persistable const *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
 
virtual
lsst::daf::base::Persistable
read (lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
 
virtual void update (lsst::daf::base::Persistable *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
 
- Public Member Functions inherited from lsst::daf::persistence::Formatter
virtual ~Formatter (void)
 
- 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
lsst::daf::base::PropertyList::Ptr 
generatePropertySet (lsst::afw::image::Wcs const &wcs)
 
static
lsst::daf::persistence::Formatter::Ptr 
createInstance (lsst::pex::policy::Policy::Ptr policy)
 
template<class Archive >
static void delegateSerialize (Archive &ar, int const version, lsst::daf::base::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

 WcsFormatter (lsst::pex::policy::Policy::Ptr policy)
 

Static Private Attributes

static
lsst::daf::persistence::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

Class implementing persistence and retrieval for Wcs objects.

Definition at line 55 of file WcsFormatter.h.

Constructor & Destructor Documentation

lsst::afw::formatters::WcsFormatter::~WcsFormatter ( void  )
virtual

Definition at line 84 of file WcsFormatter.cc.

84  {
85 }
lsst::afw::formatters::WcsFormatter::WcsFormatter ( lsst::pex::policy::Policy::Ptr  policy)
explicitprivate

Definition at line 79 of file WcsFormatter.cc.

80  :
81  dafPersist::Formatter(typeid(this)) {
82 }
Abstract base class for all formatters.
Definition: Formatter.h:79

Member Function Documentation

dafPersist::Formatter::Ptr lsst::afw::formatters::WcsFormatter::createInstance ( lsst::pex::policy::Policy::Ptr  policy)
static

Definition at line 245 of file WcsFormatter.cc.

246  {
248 }
boost::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
Class implementing persistence and retrieval for Wcs objects.
Definition: WcsFormatter.h:55
template<class Archive >
template void lsst::afw::formatters::WcsFormatter::delegateSerialize ( Archive &  ar,
int const  version,
lsst::daf::base::Persistable persistable 
)
static

Definition at line 179 of file WcsFormatter.cc.

180  {
181  execTrace("WcsFormatter delegateSerialize start");
182  afwImg::Wcs* ip = dynamic_cast<afwImg::Wcs*>(persistable);
183  if (ip == 0) {
184  throw LSST_EXCEPT(pexExcept::RuntimeError, "Serializing non-Wcs");
185  }
186 
187  // Serialize most fields normally
188  ar & ip->_nWcsInfo & ip->_relax;
189  ar & ip->_wcsfixCtrl & ip->_wcshdrCtrl & ip->_nReject;
190  ar & ip->_coordSystem;
191 
192 
193  // If we are loading, create the array of Wcs parameter structs
194  if (Archive::is_loading::value) {
195  ip->_wcsInfo =
196  reinterpret_cast<wcsprm*>(malloc(ip->_nWcsInfo * sizeof(wcsprm)));
197  }
198 
199 
200  for (int i = 0; i < ip->_nWcsInfo; ++i) {
201  // If we are loading, initialize the struct first
202  if (Archive::is_loading::value) {
203  ip->_wcsInfo[i].flag = -1;
204  wcsini(1, 2, &(ip->_wcsInfo[i]));
205  }
206 
207  // Serialize only critical Wcs parameters
208  //wcslib provides support for arrays of wcs', but we only
209  //implement support for one.
210  ar & ip->_wcsInfo[i].naxis;
211  ar & ip->_wcsInfo[i].equinox;
212  ar & ip->_wcsInfo[i].radesys;
213  ar & ip->_wcsInfo[i].crpix[0];
214  ar & ip->_wcsInfo[i].crpix[1];
215  ar & ip->_wcsInfo[i].cd[0];
216  ar & ip->_wcsInfo[i].cd[1];
217  ar & ip->_wcsInfo[i].cd[2];
218  ar & ip->_wcsInfo[i].cd[3];
219  ar & ip->_wcsInfo[i].crval[0];
220  ar & ip->_wcsInfo[i].crval[1];
221  ar & ip->_wcsInfo[i].cunit[0];
222  ar & ip->_wcsInfo[i].cunit[1];
223  ar & ip->_wcsInfo[i].ctype[0];
224  ar & ip->_wcsInfo[i].ctype[1];
225  ar & ip->_wcsInfo[i].altlin;
226 
227  // If we are loading, compute intermediate values given those above
228  if (Archive::is_loading::value) {
229  ip->_wcsInfo[i].flag = 0;
230  wcsset(&(ip->_wcsInfo[i]));
231  }
232  }
233  execTrace("WcsFormatter delegateSerialize end");
234 }
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int _wcshdrCtrl
Controls messages to stderr from wcshdr (0 for none); see wcshdr.h for details.
Definition: Wcs.h:395
int _relax
Degree of permissiveness for wcspih (0 for strict); see wcshdr.h for details.
Definition: Wcs.h:393
int _wcsfixCtrl
Do potentially unsafe translations of non-standard unit strings? 0/1 = no/yes.
Definition: Wcs.h:394
struct wcsprm * _wcsInfo
Definition: Wcs.h:391
coord::CoordSystem _coordSystem
Definition: Wcs.h:397
dafBase::PropertyList::Ptr lsst::afw::formatters::WcsFormatter::generatePropertySet ( lsst::afw::image::Wcs const &  wcs)
static

Definition at line 140 of file WcsFormatter.cc.

140  {
141  // Only generates properties for the first wcsInfo.
143 
144  assert(wcs._wcsInfo); // default ctor is private, so an uninitialized Wcs should not exist in the wild
145 
146  wcsProps->add("NAXIS", wcs._wcsInfo[0].naxis, "number of data axes");
147  wcsProps->add("EQUINOX", wcs._wcsInfo[0].equinox, "Equinox of coordinates");
148  wcsProps->add("RADESYS", std::string(wcs._wcsInfo[0].radesys), "Coordinate system for equinox");
149  wcsProps->add("CRPIX1", wcs._wcsInfo[0].crpix[0], "WCS Coordinate reference pixel");
150  wcsProps->add("CRPIX2", wcs._wcsInfo[0].crpix[1], "WCS Coordinate reference pixel");
151  wcsProps->add("CD1_1", wcs._wcsInfo[0].cd[0], "WCS Coordinate scale matrix");
152  wcsProps->add("CD1_2", wcs._wcsInfo[0].cd[1], "WCS Coordinate scale matrix");
153  wcsProps->add("CD2_1", wcs._wcsInfo[0].cd[2], "WCS Coordinate scale matrix");
154  wcsProps->add("CD2_2", wcs._wcsInfo[0].cd[3], "WCS Coordinate scale matrix");
155  wcsProps->add("CRVAL1", wcs._wcsInfo[0].crval[0], "WCS Ref value (RA in decimal degrees)");
156  wcsProps->add("CRVAL2", wcs._wcsInfo[0].crval[1], "WCS Ref value (DEC in decimal degrees)");
157  wcsProps->add("CUNIT1", std::string(wcs._wcsInfo[0].cunit[0]));
158  wcsProps->add("CUNIT2", std::string(wcs._wcsInfo[0].cunit[1]));
159  //
160  // Some projections need PVi_j keywords. Add them.
161  //
162  for (int i = 0; i != wcs._wcsInfo[0].npv; ++i) {
163  auto const pv = wcs._wcsInfo[0].pv[i];
164  int const ii = pv.i > 0 ? pv.i : (wcs._wcsInfo[0].lat + 1); // 0 => latitude axis (see wcslib/wsc.h)
165  char key[20];
166  sprintf(key, "PV%d_%d", ii, pv.m);
167  wcsProps->add(key, pv.value);
168  }
169 
170  std::string ctype1(wcs._wcsInfo[0].ctype[0]);
171  std::string ctype2(wcs._wcsInfo[0].ctype[1]);
172  wcsProps->add("CTYPE1", ctype1, "WCS Coordinate type");
173  wcsProps->add("CTYPE2", ctype2, "WCS Coordinate type");
174 
175  return wcsProps;
176 }
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
tbl::Key< int > wcs
table::Key< std::string > ctype2
Definition: Wcs.cc:1039
boost::shared_ptr< PropertyList > Ptr
Definition: PropertyList.h:84
table::Key< std::string > ctype1
Definition: Wcs.cc:1038
dafBase::Persistable * lsst::afw::formatters::WcsFormatter::read ( lsst::daf::persistence::Storage::Ptr  storage,
lsst::daf::base::PropertySet::Ptr  additionalData 
)
virtual

Read a Persistable instance from a Storage instance.

Parameters
[in]storagePointer to the Storage instance.
[in]additionalDataAdditional data used to find the proper instance within the Storage.
Returns
Shared pointer to the new Persistable instance.

Implements lsst::daf::persistence::Formatter.

Definition at line 107 of file WcsFormatter.cc.

109  {
110  execTrace("WcsFormatter read start");
111  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
112  afwImg::Wcs* ip = new afwImg::Wcs;
113  execTrace("WcsFormatter read BoostStorage");
114  dafPersist::BoostStorage* boost = dynamic_cast<dafPersist::BoostStorage*>(storage.get());
115  boost->getIArchive() & *ip;
116  execTrace("WcsFormatter read end");
117  return ip;
118  }
119  else if (typeid(*storage) == typeid(dafPersist::FitsStorage)) {
120  execTrace("WcsFormatter read FitsStorage");
121  dafPersist::FitsStorage* fits = dynamic_cast<dafPersist::FitsStorage*>(storage.get());
122  int hdu = additionalData->get<int>("hdu", 0);
124  afwImg::readMetadata(fits->getPath(), hdu);
125  afwImg::Wcs* ip = new afwImg::Wcs(md);
126  execTrace("WcsFormatter read end");
127  return ip;
128  }
129  throw LSST_EXCEPT(pexExcept::RuntimeError, "Unrecognized Storage for Wcs");
130 }
virtual boost::archive::text_iarchive & getIArchive(void)
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
virtual std::string const & getPath(void)
Definition: FitsStorage.cc:109
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
Class for FITS file storage.
Definition: FitsStorage.h:52
lsst::afw::image::Wcs Wcs
Definition: Wcs.cc:60
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
boost::shared_ptr< daf::base::PropertySet > readMetadata(std::string const &fileName, int hdu=0, bool strip=false)
Return the metadata (header entries) from a FITS file.
Class for boost::serialization storage.
Definition: BoostStorage.h:58
void lsst::afw::formatters::WcsFormatter::update ( lsst::daf::base::Persistable persistable,
lsst::daf::persistence::Storage::Ptr  storage,
lsst::daf::base::PropertySet::Ptr  additionalData 
)
virtual

Update an existing Persistable instance with information from an additional Storage instance.

Parameters
[in,out]persistablePointer to the Persistable instance.
[in]storageShared pointer to the additional Storage instance.
[in]additionalDataAdditional data used to find the proper instance within the Storage.

Implements lsst::daf::persistence::Formatter.

Definition at line 132 of file WcsFormatter.cc.

135  {
136  throw LSST_EXCEPT(pexExcept::RuntimeError, "Unexpected call to update for Wcs");
137 }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void lsst::afw::formatters::WcsFormatter::write ( lsst::daf::base::Persistable const *  persistable,
lsst::daf::persistence::Storage::Ptr  storage,
lsst::daf::base::PropertySet::Ptr  additionalData 
)
virtual

Write a Persistable instance to a Storage instance.

Parameters
[in]persistablePointer to the Persistable instance.
[in]storageShared pointer to the Storage instance.
[in]additionalDataAdditional data used to find the proper place to put the instance into the Storage.

Implements lsst::daf::persistence::Formatter.

Definition at line 87 of file WcsFormatter.cc.

90  {
91  execTrace("WcsFormatter write start");
92  afwImg::Wcs const* ip =
93  dynamic_cast<afwImg::Wcs const*>(persistable);
94  if (ip == 0) {
95  throw LSST_EXCEPT(pexExcept::RuntimeError, "Persisting non-Wcs");
96  }
97  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
98  execTrace("WcsFormatter write BoostStorage");
99  dafPersist::BoostStorage* boost = dynamic_cast<dafPersist::BoostStorage*>(storage.get());
100  boost->getOArchive() & *ip;
101  execTrace("WcsFormatter write end");
102  return;
103  }
104  throw LSST_EXCEPT(pexExcept::RuntimeError, "Unrecognized Storage for Wcs");
105 }
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
virtual boost::archive::text_oarchive & getOArchive(void)
Class for boost::serialization storage.
Definition: BoostStorage.h:58

Member Data Documentation

dafPersist::FormatterRegistration lsst::afw::formatters::WcsFormatter::registration
staticprivate

Definition at line 91 of file WcsFormatter.h.


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