39 # define __attribute__(x)
44 #include "boost/serialization/shared_ptr.hpp"
45 #include <boost/archive/binary_iarchive.hpp>
46 #include <boost/archive/binary_oarchive.hpp>
47 #include <boost/archive/text_iarchive.hpp>
48 #include <boost/archive/text_oarchive.hpp>
67 static void execTrace(std::string s,
int level =
EXEC_TRACE) {
71 namespace afwGeom = lsst::afw::geom;
72 namespace afwForm = lsst::afw::formatters;
74 namespace dafBase = lsst::daf::base;
75 namespace dafPersist = lsst::daf::persistence;
77 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
80 static std::string
name();
85 static std::string
name =
"ExposureU";
90 static std::string
name =
"ExposureI";
95 static std::string
name =
"ExposureF";
100 static std::string
name =
"ExposureD";
105 static std::string
name =
"ExposureL";
109 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
112 VariancePixelT>::registration(
117 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
120 lsst::daf::persistence::Formatter(typeid(this)), _policy(policy) {
123 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
129 static std::string lookupFilterName(
139 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
140 (
boost::format(
"Unable to get name for filter id: %d") % filterId).str());
144 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
145 (
boost::format(
"Multiple names for filter id: %d") % filterId).str());
156 template <
typename T>
157 static void setColumn(
159 std::string
const& colName,
161 std::string
const& propName
163 if (!source->exists(propName)) {
166 db->
setColumn<T>(colName, source->get<T>(propName));
174 template <
typename T1,
typename T2>
175 static void setColumn(
177 std::string
const& colName,
179 std::string
const& propName
181 if (!source->exists(propName)) {
184 db->
setColumn<T1>(colName,
static_cast<T1
>(source->get<T2>(propName)));
188 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
193 execTrace(
"ExposureFormatter write start");
197 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Persisting non-Exposure");
200 execTrace(
"ExposureFormatter write BoostStorage");
203 execTrace(
"ExposureFormatter write end");
207 execTrace(
"ExposureFormatter write FitsStorage");
211 execTrace(
"ExposureFormatter write end");
214 execTrace(
"ExposureFormatter write DbStorage");
219 ip->
getWcs()->getFitsMetadata();
224 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
225 "Unable to retrieve metadata from MaskedImage's Image");
229 std::string itemName = additionalData->get<std::string>(
"itemName");
230 std::string tableName = itemName;
231 if (_policy->exists(itemName)) {
233 if (itemPolicy->exists(
"TableName")) {
234 tableName = itemPolicy->getString(
"TableName");
237 if (tableName !=
"Raw_Amp_Exposure" &&
238 tableName !=
"Science_Amp_Exposure") {
239 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
240 "Unknown table name for persisting Exposure to DbStorage: " +
241 tableName +
"for item " + itemName);
253 if (tableName ==
"Raw_Amp_Exposure") {
254 db->
setColumn<
long long>(
"rawAmpExposureId", ampExposureId);
255 db->
setColumn<
long long>(
"rawCCDExposureId", ccdExposureId);
256 db->
setColumn<
long long>(
"rawFPAExposureId", fpaExposureId);
259 db->
setColumn<
long long>(
"scienceAmpExposureId", ampExposureId);
260 db->
setColumn<
long long>(
"scienceCCDExposureId", ccdExposureId);
261 db->
setColumn<
long long>(
"scienceFPAExposureId", fpaExposureId);
262 db->
setColumn<
long long>(
"rawAmpExposureId", ampExposureId);
270 setColumn<std::string>(db,
"url",
271 additionalData,
"StorageLocation.FitsStorage");
275 setColumn<std::string>(db,
"ctype1", wcsProps,
"CTYPE1");
276 setColumn<std::string>(db,
"ctype2", wcsProps,
"CTYPE2");
277 setColumn<float, double>(db,
"crpix1", wcsProps,
"CRPIX1");
278 setColumn<float, double>(db,
"crpix2", wcsProps,
"CRPIX2");
279 setColumn<double>(db,
"crval1", wcsProps,
"CRVAL1");
280 setColumn<double>(db,
"crval2", wcsProps,
"CRVAL2");
281 if (tableName ==
"Raw_Amp_Exposure") {
282 setColumn<double>(db,
"cd11", wcsProps,
"CD1_1");
283 setColumn<double>(db,
"cd21", wcsProps,
"CD2_1");
284 setColumn<double>(db,
"cd12", wcsProps,
"CD1_2");
285 setColumn<double>(db,
"cd22", wcsProps,
"CD2_2");
288 setColumn<double>(db,
"cd1_1", wcsProps,
"CD1_1");
289 setColumn<double>(db,
"cd2_1", wcsProps,
"CD2_1");
290 setColumn<double>(db,
"cd1_2", wcsProps,
"CD1_2");
291 setColumn<double>(db,
"cd2_2", wcsProps,
"CD2_2");
295 if (tableName ==
"Science_Amp_Exposure") {
297 setColumn<float, double>(db,
"photoFlam", dp,
"PHOTFLAM");
298 setColumn<float, double>(db,
"photoZP", dp,
"PHOTZP");
304 execTrace(
"ExposureFormatter write end");
307 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for Exposure");
310 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
314 execTrace(
"ExposureFormatter read start");
316 execTrace(
"ExposureFormatter read BoostStorage");
321 execTrace(
"ExposureFormatter read end");
324 execTrace(
"ExposureFormatter read FitsStorage");
327 if (additionalData->exists(
"llcX")) {
328 int llcX = additionalData->get<
int>(
"llcX");
329 int llcY = additionalData->get<
int>(
"llcY");
330 int width = additionalData->get<
int>(
"width");
331 int height = additionalData->get<
int>(
"height");
335 if(additionalData->exists(
"imageOrigin")){
336 std::string originStr = additionalData->get<std::string>(
"imageOrigin");
337 if(originStr ==
"LOCAL") {
339 }
else if (originStr ==
"PARENT") {
343 lsst::pex::exceptions::RuntimeError,
344 (
boost::format(
"Unknown ImageOrigin type %s specified in additional"
345 "data for retrieving Exposure from fits")%originStr
354 execTrace(
"ExposureFormatter read end");
357 execTrace(
"ExposureFormatter read DbStorage");
361 std::string itemName = additionalData->get<std::string>(
"itemName");
362 std::string tableName = itemName;
363 if (_policy->exists(itemName)) {
365 _policy->getPolicy(itemName);
366 if (itemPolicy->exists(
"TableName")) {
367 tableName = itemPolicy->getString(
"TableName");
370 if (tableName !=
"Raw_Amp_Exposure" &&
371 tableName !=
"Science_Amp_Exposure") {
372 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
373 "Unknown table name for retrieving Exposure from DbStorage: " +
374 tableName +
" for item " + itemName);
379 db->
condParam<int64_t>(
"id", additionalData->getAsInt64(
"ampExposureId"));
380 if (tableName ==
"Raw_Amp_Exposure") {
389 if (tableName ==
"Science_Amp_Exposure") {
410 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unable to retrieve row");
414 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Non-unique Exposure retrieved");
428 std::string filterName = lookupFilterName(db, filterId);
429 dp->set(
"FILTER", filterName);
437 execTrace(
"ExposureFormatter read end");
440 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for Exposure");
443 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
452 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for Exposure");
455 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
template <
class Archive>
460 execTrace(
"ExposureFormatter delegateSerialize start");
464 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-Exposure");
468 execTrace(
"ExposureFormatter delegateSerialize end");
471 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
474 VariancePixelT>::createInstance(
481 #define INSTANTIATE(I, M, V) \
482 template class afwForm::ExposureFormatter<I, M, V>; \
483 template void afwForm::ExposureFormatter<I, M, V>::delegateSerialize<boost::archive::text_oarchive>( \
484 boost::archive::text_oarchive &, unsigned int const, dafBase::Persistable *); \
485 template void afwForm::ExposureFormatter<I, M, V>::delegateSerialize<boost::archive::text_iarchive>( \
486 boost::archive::text_iarchive &, unsigned int const, dafBase::Persistable *); \
487 template void afwForm::ExposureFormatter<I, M, V>::delegateSerialize<boost::archive::binary_oarchive>( \
488 boost::archive::binary_oarchive &, unsigned int const, dafBase::Persistable *); \
489 template void afwForm::ExposureFormatter<I, M, V>::delegateSerialize<boost::archive::binary_iarchive>( \
490 boost::archive::binary_iarchive &, unsigned int const, dafBase::Persistable *);
virtual void outColumn(std::string const &columnName, bool isExpr=false)
table::Key< std::string > name
void setColumn(std::string const &columnName, T const &value)
Include files required for standard LSST Exception handling.
daf_persistence package header file
A class to contain the data, WCS, and other information needed to describe an image of the sky...
boost::uint16_t MaskPixel
virtual boost::archive::text_iarchive & getIArchive(void)
boost::shared_ptr< PropertySet > Ptr
virtual std::string const & getPath(void)
virtual void setQueryWhere(std::string const &whereClause)
boost::shared_ptr< Policy > Ptr
#define INSTANTIATE(MATCH)
definition of the Trace messaging facilities
T const & getColumnByPos(int pos)
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.
limited backward compatibility to the DC2 run-time trace facilities
Class for FITS file storage.
bool columnIsNull(int pos)
void condParam(std::string const ¶mName, T const &value)
An integer coordinate rectangle.
Class for database storage.
table::Key< table::Array< Kernel::Pixel > > image
void ImageT ImageT int float saturatedPixelValue int const width
lsst::daf::base::PropertySet::Ptr getMetadata() const
Return flexible metadata.
MaskedImageT _maskedImage
void ImageT ImageT int float saturatedPixelValue int const height
boost::shared_ptr< Wcs const > getWcs() const
virtual void setTableForQuery(std::string const &tableName, bool isExpr=false)
#define LSST_EXCEPT(type,...)
virtual boost::archive::text_oarchive & getOArchive(void)
boost::shared_ptr< Storage > Ptr
Class for boost::serialization storage.
Base class for all persistable classes.
virtual void finishQuery(void)
virtual void setTableForInsert(std::string const &tableName)
float VariancePixel
! default type for Masks and MaskedImage Masks
virtual void setColumnToNull(std::string const &columnName)