LSSTApplications  20.0.0
LSSTDataManagementBasePackage
Functions
lsst::afw::formatters Namespace Reference

Functions

bool extractOptionalFlag (std::shared_ptr< lsst::daf::base::PropertySet const > const &properties, std::string const &name)
 Returns true if and only if properties is non-null and contains a unique property with the given name that has type bool and a value of true. More...
 
std::string const getItemName (std::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
 Extracts and returns the string-valued "itemName" property from the given data property object. More...
 
int extractSliceId (std::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
 
int64_t extractFpaExposureId (std::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
 
int64_t extractCcdExposureId (std::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
 
int64_t extractAmpExposureId (std::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
 
int extractVisitId (std::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
 
int extractCcdId (std::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
 
int extractAmpId (std::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
 
int countFitsHeaderCards (lsst::daf::base::PropertySet const &prop)
 
ndarray::Array< std::uint8_t, 1, 1 > stringToBytes (std::string const &str)
 Encode a std::string as a vector of uint8. More...
 
std::string bytesToString (ndarray::Array< std::uint8_t const, 1, 1 > const &bytes)
 Decode a std::string from a vector of uint8 returned by stringToBytes. More...
 

Function Documentation

◆ bytesToString()

std::string lsst::afw::formatters::bytesToString ( ndarray::Array< std::uint8_t const, 1, 1 > const &  bytes)

Decode a std::string from a vector of uint8 returned by stringToBytes.

Definition at line 173 of file Utils.cc.

173  {
174  auto nchars = bytes.size() * sizeof(std::uint8_t) / sizeof(char);
175  char const* charCArr = reinterpret_cast<char const*>(bytes.getData());
176  return std::string(charCArr, nchars);
177 }

◆ countFitsHeaderCards()

int lsst::afw::formatters::countFitsHeaderCards ( lsst::daf::base::PropertySet const &  prop)

Definition at line 160 of file Utils.cc.

160 { return prop.paramNames(false).size(); }

◆ extractAmpExposureId()

int64_t lsst::afw::formatters::extractAmpExposureId ( std::shared_ptr< lsst::daf::base::PropertySet const > const &  properties)

Definition at line 132 of file Utils.cc.

132  {
133  if (properties->isArray("ampExposureId")) {
134  throw LSST_EXCEPT(ex::RuntimeError, "\"ampExposureId\" property has multiple values");
135  }
136  int64_t ampExposureId = properties->getAsInt64("ampExposureId");
137  if (ampExposureId < 0) {
138  throw LSST_EXCEPT(ex::RangeError, "negative \"ampExposureId\"");
139  }
140  return ampExposureId;
141 }

◆ extractAmpId()

int lsst::afw::formatters::extractAmpId ( std::shared_ptr< lsst::daf::base::PropertySet const > const &  properties)

Definition at line 107 of file Utils.cc.

107  {
108  if (properties->isArray("ampId")) {
109  throw LSST_EXCEPT(ex::RuntimeError, "\"ampId\" property has multiple values");
110  }
111  int ampId = properties->getAsInt("ampId");
112  if (ampId < 0) {
113  throw LSST_EXCEPT(ex::RangeError, "negative \"ampId\"");
114  }
115  if (ampId > 63) {
116  throw LSST_EXCEPT(ex::RangeError, "\"ampId\" is too large");
117  }
118  return (extractCcdId(properties) << 6) + ampId;
119 }

◆ extractCcdExposureId()

int64_t lsst::afw::formatters::extractCcdExposureId ( std::shared_ptr< lsst::daf::base::PropertySet const > const &  properties)

Definition at line 121 of file Utils.cc.

121  {
122  if (properties->isArray("ccdExposureId")) {
123  throw LSST_EXCEPT(ex::RuntimeError, "\"ccdExposureId\" property has multiple values");
124  }
125  int64_t ccdExposureId = properties->getAsInt64("ccdExposureId");
126  if (ccdExposureId < 0) {
127  throw LSST_EXCEPT(ex::RangeError, "negative \"ccdExposureId\"");
128  }
129  return ccdExposureId;
130 }

◆ extractCcdId()

int lsst::afw::formatters::extractCcdId ( std::shared_ptr< lsst::daf::base::PropertySet const > const &  properties)

Definition at line 93 of file Utils.cc.

93  {
94  if (properties->isArray("ccdId")) {
95  throw LSST_EXCEPT(ex::RuntimeError, "\"ccdId\" property has multiple values");
96  }
97  int ccdId = properties->getAsInt("ccdId");
98  if (ccdId < 0) {
99  throw LSST_EXCEPT(ex::RangeError, "negative \"ccdId\"");
100  }
101  if (ccdId > 255) {
102  throw LSST_EXCEPT(ex::RangeError, "\"ccdId\" is too large");
103  }
104  return static_cast<int>(ccdId);
105 }

◆ extractFpaExposureId()

int64_t lsst::afw::formatters::extractFpaExposureId ( std::shared_ptr< lsst::daf::base::PropertySet const > const &  properties)

Definition at line 79 of file Utils.cc.

79  {
80  if (properties->isArray("fpaExposureId")) {
81  throw LSST_EXCEPT(ex::RuntimeError, "\"fpaExposureId\" property has multiple values");
82  }
83  int64_t fpaExposureId = properties->getAsInt64("fpaExposureId");
84  if (fpaExposureId < 0) {
85  throw LSST_EXCEPT(ex::RangeError, "negative \"fpaExposureId\"");
86  }
87  if ((fpaExposureId & 0xfffffffe00000000LL) != 0LL) {
88  throw LSST_EXCEPT(ex::RangeError, "\"fpaExposureId\" is too large");
89  }
90  return fpaExposureId;
91 }

◆ extractOptionalFlag()

bool lsst::afw::formatters::extractOptionalFlag ( std::shared_ptr< lsst::daf::base::PropertySet const > const &  properties,
std::string const &  name 
)

Returns true if and only if properties is non-null and contains a unique property with the given name that has type bool and a value of true.

Definition at line 153 of file Utils.cc.

153  {
154  if (properties && properties->exists(name)) {
155  return properties->getAsBool(name);
156  }
157  return false;
158 }

◆ extractSliceId()

int lsst::afw::formatters::extractSliceId ( std::shared_ptr< lsst::daf::base::PropertySet const > const &  properties)

Definition at line 51 of file Utils.cc.

51  {
52  if (properties->isArray("sliceId")) {
53  throw LSST_EXCEPT(ex::RuntimeError, "\"sliceId\" property has multiple values");
54  }
55  int sliceId = properties->getAsInt("sliceId");
56  if (sliceId < 0) {
57  throw LSST_EXCEPT(ex::RangeError, "negative \"sliceId\"");
58  }
59  if (properties->exists("universeSize") && !properties->isArray("universeSize")) {
60  int universeSize = properties->getAsInt("universeSize");
61  if (sliceId >= universeSize) {
62  throw LSST_EXCEPT(ex::RangeError, "\"sliceId\" must be less than \"universeSize \"");
63  }
64  }
65  return sliceId;
66 }

◆ extractVisitId()

int lsst::afw::formatters::extractVisitId ( std::shared_ptr< lsst::daf::base::PropertySet const > const &  properties)

Definition at line 68 of file Utils.cc.

68  {
69  if (properties->isArray("visitId")) {
70  throw LSST_EXCEPT(ex::RuntimeError, "\"visitId\" property has multiple values");
71  }
72  int visitId = properties->getAsInt("visitId");
73  if (visitId < 0) {
74  throw LSST_EXCEPT(ex::RangeError, "negative \"visitId\"");
75  }
76  return visitId;
77 }

◆ getItemName()

std::string const lsst::afw::formatters::getItemName ( std::shared_ptr< lsst::daf::base::PropertySet const > const &  properties)

Extracts and returns the string-valued "itemName" property from the given data property object.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorIf the given pointer is null, or the PropertySet pointed to does not contain a unique property named "itemName".

Definition at line 143 of file Utils.cc.

143  {
144  if (!properties) {
145  throw LSST_EXCEPT(ex::InvalidParameterError, "Null std::shared_ptr<PropertySet>");
146  }
147  if (properties->isArray("itemName")) {
148  throw LSST_EXCEPT(ex::InvalidParameterError, "\"itemName\" property has multiple values");
149  }
150  return properties->getAsString("itemName");
151 }

◆ stringToBytes()

ndarray::Array< std::uint8_t, 1, 1 > lsst::afw::formatters::stringToBytes ( std::string const &  str)

Encode a std::string as a vector of uint8.

Definition at line 162 of file Utils.cc.

162  {
163  auto nbytes = str.size() * sizeof(char) / sizeof(std::uint8_t);
164  std::uint8_t const* byteCArr = reinterpret_cast<std::uint8_t const*>(str.data());
165  auto shape = ndarray::makeVector(nbytes);
166  auto strides = ndarray::makeVector(1);
167  // Make an Array that shares memory with `str` (and does not free that memory when destroyed),
168  // then return a copy; this is simpler than manually copying the data into a newly allocated array
169  ndarray::Array<std::uint8_t const, 1, 1> localArray = ndarray::external(byteCArr, shape, strides);
170  return ndarray::copy(localArray);
171 }
lsst::daf::base::PropertySet::getAsInt
int getAsInt(std::string const &name) const
Get the last value for a bool/char/short/int property name (possibly hierarchical).
lsst::daf::base::PropertySet::getAsBool
bool getAsBool(std::string const &name) const
Get the last value for a bool property name (possibly hierarchical).
std::string
STL class.
lsst::pex::exceptions::RangeError
Reports when the result of an operation cannot be represented by the destination type.
Definition: Runtime.h:115
lsst::daf::base::PropertySet::isArray
bool isArray(std::string const &name) const
Determine if a name (possibly hierarchical) has multiple values.
lsst::daf::base::PropertySet::exists
bool exists(std::string const &name) const
Determine if a name (possibly hierarchical) exists.
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
lsst::afw::formatters::extractCcdId
int extractCcdId(std::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
Definition: Utils.cc:93
lsst::daf::base::PropertySet::getAsInt64
int64_t getAsInt64(std::string const &name) const
Get the last value for a bool/char/short/int/int64_t property name (possibly hierarchical).
lsst::daf::base::PropertySet::getAsString
std::string getAsString(std::string const &name) const
Get the last value for a string property name (possibly hierarchical).
std::uint8_t
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
bytes
table::Key< table::Array< std::uint8_t > > bytes
Definition: Transform.cc:199
lsst::pex::exceptions::InvalidParameterError
Reports invalid arguments.
Definition: Runtime.h:66
lsst::pex::exceptions::RuntimeError
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104