39 # define __attribute__(x)
48 #include "boost/serialization/shared_ptr.hpp"
49 #include <boost/archive/binary_iarchive.hpp>
50 #include <boost/archive/binary_oarchive.hpp>
51 #include <boost/archive/text_iarchive.hpp>
52 #include <boost/archive/text_oarchive.hpp>
72 namespace afwGeom = lsst::afw::geom;
73 namespace afwForm = lsst::afw::formatters;
75 namespace dafBase = lsst::daf::base;
76 namespace dafPersist = lsst::daf::persistence;
78 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
81 static std::string
name();
86 static std::string
name =
"ExposureU";
91 static std::string
name =
"ExposureI";
96 static std::string
name =
"ExposureF";
101 static std::string
name =
"ExposureD";
106 static std::string
name =
"ExposureL";
110 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
113 VariancePixelT>::registration(
118 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
121 lsst::daf::persistence::Formatter(typeid(this)), _policy(policy) {
124 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
130 static std::string lookupFilterName(
140 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
141 (
boost::format(
"Unable to get name for filter id: %d") % filterId).str());
145 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
146 (
boost::format(
"Multiple names for filter id: %d") % filterId).str());
157 template <
typename T>
158 static void setColumn(
160 std::string
const& colName,
162 std::string
const& propName
164 if (!source->exists(propName)) {
167 db->
setColumn<T>(colName, source->get<T>(propName));
175 template <
typename T1,
typename T2>
176 static void setColumn(
178 std::string
const& colName,
180 std::string
const& propName
182 if (!source->exists(propName)) {
185 db->
setColumn<T1>(colName,
static_cast<T1
>(source->get<T2>(propName)));
189 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
194 LOGL_DEBUG(_log,
"ExposureFormatter write start");
198 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Persisting non-Exposure");
201 LOGL_DEBUG(_log,
"ExposureFormatter write BoostStorage");
204 LOGL_DEBUG(_log,
"ExposureFormatter write end");
208 LOGL_DEBUG(_log,
"ExposureFormatter write FitsStorage");
212 LOGL_DEBUG(_log,
"ExposureFormatter write end");
215 LOGL_DEBUG(_log,
"ExposureFormatter write DbStorage");
220 ip->
getWcs()->getFitsMetadata();
225 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
226 "Unable to retrieve metadata from MaskedImage's Image");
230 std::string itemName = additionalData->get<std::string>(
"itemName");
231 std::string tableName = itemName;
232 if (_policy->exists(itemName)) {
234 if (itemPolicy->exists(
"TableName")) {
235 tableName = itemPolicy->getString(
"TableName");
238 if (tableName !=
"Raw_Amp_Exposure" &&
239 tableName !=
"Science_Amp_Exposure") {
240 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
241 "Unknown table name for persisting Exposure to DbStorage: " +
242 tableName +
"for item " + itemName);
254 if (tableName ==
"Raw_Amp_Exposure") {
255 db->
setColumn<
long long>(
"rawAmpExposureId", ampExposureId);
256 db->
setColumn<
long long>(
"rawCCDExposureId", ccdExposureId);
257 db->
setColumn<
long long>(
"rawFPAExposureId", fpaExposureId);
260 db->
setColumn<
long long>(
"scienceAmpExposureId", ampExposureId);
261 db->
setColumn<
long long>(
"scienceCCDExposureId", ccdExposureId);
262 db->
setColumn<
long long>(
"scienceFPAExposureId", fpaExposureId);
263 db->
setColumn<
long long>(
"rawAmpExposureId", ampExposureId);
271 setColumn<std::string>(db,
"url",
272 additionalData,
"StorageLocation.FitsStorage");
276 setColumn<std::string>(db,
"ctype1", wcsProps,
"CTYPE1");
277 setColumn<std::string>(db,
"ctype2", wcsProps,
"CTYPE2");
278 setColumn<float, double>(db,
"crpix1", wcsProps,
"CRPIX1");
279 setColumn<float, double>(db,
"crpix2", wcsProps,
"CRPIX2");
280 setColumn<double>(db,
"crval1", wcsProps,
"CRVAL1");
281 setColumn<double>(db,
"crval2", wcsProps,
"CRVAL2");
282 if (tableName ==
"Raw_Amp_Exposure") {
283 setColumn<double>(db,
"cd11", wcsProps,
"CD1_1");
284 setColumn<double>(db,
"cd21", wcsProps,
"CD2_1");
285 setColumn<double>(db,
"cd12", wcsProps,
"CD1_2");
286 setColumn<double>(db,
"cd22", wcsProps,
"CD2_2");
289 setColumn<double>(db,
"cd1_1", wcsProps,
"CD1_1");
290 setColumn<double>(db,
"cd2_1", wcsProps,
"CD2_1");
291 setColumn<double>(db,
"cd1_2", wcsProps,
"CD1_2");
292 setColumn<double>(db,
"cd2_2", wcsProps,
"CD2_2");
296 if (tableName ==
"Science_Amp_Exposure") {
298 setColumn<float, double>(db,
"photoFlam", dp,
"PHOTFLAM");
299 setColumn<float, double>(db,
"photoZP", dp,
"PHOTZP");
305 LOGL_DEBUG(_log,
"ExposureFormatter write end");
308 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for Exposure");
311 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
315 LOGL_DEBUG(_log,
"ExposureFormatter read start");
317 LOGL_DEBUG(_log,
"ExposureFormatter read BoostStorage");
322 LOGL_DEBUG(_log,
"ExposureFormatter read end");
325 LOGL_DEBUG(_log,
"ExposureFormatter read FitsStorage");
328 if (additionalData->exists(
"llcX")) {
329 int llcX = additionalData->get<
int>(
"llcX");
330 int llcY = additionalData->get<
int>(
"llcY");
331 int width = additionalData->get<
int>(
"width");
332 int height = additionalData->get<
int>(
"height");
336 if(additionalData->exists(
"imageOrigin")){
337 std::string originStr = additionalData->get<std::string>(
"imageOrigin");
338 if(originStr ==
"LOCAL") {
340 }
else if (originStr ==
"PARENT") {
344 lsst::pex::exceptions::RuntimeError,
345 (
boost::format(
"Unknown ImageOrigin type %s specified in additional"
346 "data for retrieving Exposure from fits")%originStr
355 LOGL_DEBUG(_log,
"ExposureFormatter read end");
358 LOGL_DEBUG(_log,
"ExposureFormatter read DbStorage");
362 std::string itemName = additionalData->get<std::string>(
"itemName");
363 std::string tableName = itemName;
364 if (_policy->exists(itemName)) {
366 _policy->getPolicy(itemName);
367 if (itemPolicy->exists(
"TableName")) {
368 tableName = itemPolicy->getString(
"TableName");
371 if (tableName !=
"Raw_Amp_Exposure" &&
372 tableName !=
"Science_Amp_Exposure") {
373 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
374 "Unknown table name for retrieving Exposure from DbStorage: " +
375 tableName +
" for item " + itemName);
380 db->
condParam<int64_t>(
"id", additionalData->getAsInt64(
"ampExposureId"));
381 if (tableName ==
"Raw_Amp_Exposure") {
390 if (tableName ==
"Science_Amp_Exposure") {
411 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unable to retrieve row");
415 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Non-unique Exposure retrieved");
429 std::string filterName = lookupFilterName(db, filterId);
430 dp->set(
"FILTER", filterName);
438 LOGL_DEBUG(_log,
"ExposureFormatter read end");
441 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for Exposure");
444 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
453 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for Exposure");
456 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
template <
class Archive>
461 LOGL_DEBUG(_log,
"ExposureFormatter delegateSerialize start");
465 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-Exposure");
469 LOGL_DEBUG(_log,
"ExposureFormatter delegateSerialize end");
472 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
475 VariancePixelT>::createInstance(
482 #define INSTANTIATE(I, M, V) \
483 template class afwForm::ExposureFormatter<I, M, V>; \
484 template void afwForm::ExposureFormatter<I, M, V>::delegateSerialize<boost::archive::text_oarchive>( \
485 boost::archive::text_oarchive &, unsigned int const, dafBase::Persistable *); \
486 template void afwForm::ExposureFormatter<I, M, V>::delegateSerialize<boost::archive::text_iarchive>( \
487 boost::archive::text_iarchive &, unsigned int const, dafBase::Persistable *); \
488 template void afwForm::ExposureFormatter<I, M, V>::delegateSerialize<boost::archive::binary_oarchive>( \
489 boost::archive::binary_oarchive &, unsigned int const, dafBase::Persistable *); \
490 template void afwForm::ExposureFormatter<I, M, V>::delegateSerialize<boost::archive::binary_iarchive>( \
491 boost::archive::binary_iarchive &, unsigned int const, dafBase::Persistable *);
std::shared_ptr< Policy > Ptr
bool columnIsNull(int pos)
Determine if the value of a column is NULL.
void condParam(std::string const ¶mName, T const &value)
Bind a value to a WHERE condition parameter.
table::Key< std::string > name
daf_persistence package header file
Include files required for standard LSST Exception handling.
virtual void setTableForQuery(std::string const &tableName, bool isExpr=false)
Set the table to query (single-table queries only).
A class to contain the data, WCS, and other information needed to describe an image of the sky...
void writeFits(std::string const &fileName) const
Write an Exposure to a regular multi-extension FITS file.
Implementation of the WCS standard for a any projection.
virtual void setQueryWhere(std::string const &whereClause)
Set the condition for the WHERE clause of the query.
Class for FITS file storage.
virtual boost::archive::text_oarchive & getOArchive(void)
Get a boost::serialization archive suitable for output.
virtual bool next(void)
Move to the next (first) row of the query result.
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
An integer coordinate rectangle.
Class for database storage.
table::Key< table::Array< Kernel::Pixel > > image
LSST DM logging module built on log4cxx.
void ImageT ImageT int float saturatedPixelValue int const width
lsst::daf::base::PropertySet::Ptr getMetadata() const
Return flexible metadata.
virtual void setTableForInsert(std::string const &tableName)
Set the table to insert rows into.
std::shared_ptr< Storage > Ptr
virtual void outColumn(std::string const &columnName, bool isExpr=false)
Request a column in the query output.
MaskedImageT _maskedImage
void ImageT ImageT int float saturatedPixelValue int const height
void setColumn(std::string const &columnName, T const &value)
Set the value to insert in a given column.
virtual boost::archive::text_iarchive & getIArchive(void)
Get a boost::serialization archive suitable for input.
boost::shared_ptr< Wcs const > getWcs() const
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
virtual std::string const & getPath(void)
Return the pathname for the FITS file.
virtual void query(void)
Execute the query.
T const & getColumnByPos(int pos)
Get the value of a column of the query result row by position.
virtual void finishQuery(void)
Indicate that query processing is finished.
virtual void setColumnToNull(std::string const &columnName)
Set a given column to NULL.
Class for boost::serialization storage.
Base class for all persistable classes.
std::shared_ptr< PropertySet > Ptr
#define LOG_GET(logger)
Returns a Log object associated with logger.
float VariancePixel
! default type for Masks and MaskedImage Masks