LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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 }
STL class.
table::Key< table::Array< std::uint8_t > > bytes
Definition: Transform.cc:199

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

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

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

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

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

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

◆ 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 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
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 }