LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
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 }
table::Key< table::Array< std::uint8_t > > bytes
Definition: python.h:135

◆ 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 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Reports when the result of an operation cannot be represented by the destination type.
Definition: Runtime.h:115
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104

◆ 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 }
int extractCcdId(std::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
Definition: Utils.cc:93

◆ 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 }
table::Key< std::string > name
Definition: Amplifier.cc:116

◆ 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 }
Reports invalid arguments.
Definition: Runtime.h:66

◆ 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 }