LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | Protected Member Functions | List of all members
lsst::afw::cameraGeom::Camera::Builder Class Reference

A helper class for creating and modifying cameras. More...

#include <Camera.h>

Inheritance diagram for lsst::afw::cameraGeom::Camera::Builder:
lsst::afw::cameraGeom::DetectorCollectionBase< Detector::InCameraBuilder >

Public Types

using NameMap = std::unordered_map< std::string, std::shared_ptr< Detector::InCameraBuilder > >
 
using IdMap = std::map< int, std::shared_ptr< Detector::InCameraBuilder > >
 
using List = std::vector< std::shared_ptr< Detector::InCameraBuilder > >
 

Public Member Functions

virtual ~Builder () noexcept
 
 Builder (std::string const &name)
 Construct a Builder for a completely new Camera with the given name. More...
 
 Builder (Camera const &camera)
 Construct a Builder with the state of an existing Camera. More...
 
std::shared_ptr< Camera const > finish () const
 Construct a new Camera from the state of the Builder. More...
 
std::string getName () const
 Return the name of the camera. More...
 
void setName (std::string const &name)
 Set the name of the camera. More...
 
std::string getPupilFactoryName () const
 Return the fully-qualified name of the Python class that provides this Camera's PupilFactory. More...
 
void setPupilFactoryName (std::string const &pupilFactoryName)
 Set the fully-qualified name of the Python class that provides this Camera's PupilFactory. More...
 
void setTransformFromFocalPlaneTo (CameraSys const &toSys, std::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > transform)
 Set the transformation from FOCAL_PLANE to the given coordinate system. More...
 
bool discardTransformFromFocalPlaneTo (CameraSys const &toSys)
 Remove any transformation from FOCAL_PLANE to the given coordinate system. More...
 
std::shared_ptr< Detector::InCameraBuilderadd (std::string const &name, int id)
 Add a new Detector with the given name and ID. More...
 
void remove (std::string const &name)
 Remove the detector with the given name or ID. More...
 
void remove (int id)
 
NameMap const & getNameMap () const noexcept
 Get a map keyed and ordered by name. More...
 
IdMap const & getIdMap () const noexcept
 Get a map keyed and ordered by ID. More...
 
std::size_t size () const noexcept
 Get the number of detectors. More...
 
bool empty () const noexcept
 Determine if the collection contains any detectors. More...
 
std::shared_ptr< Detector::InCameraBuilderoperator[] (std::string const &name) const
 Implement the [name] operator. More...
 
std::shared_ptr< Detector::InCameraBuilderoperator[] (int id) const
 Implement the [id] operator. More...
 
std::shared_ptr< Detector::InCameraBuilderget (std::string const &name, std::shared_ptr< Detector::InCameraBuilder > def=nullptr) const
 Retrieve a detector by name, or fall back to a default. More...
 
std::shared_ptr< Detector::InCameraBuilderget (int id, std::shared_ptr< Detector::InCameraBuilder > def=nullptr) const
 Retrieve a detector by ID, or fall back to a default. More...
 

Protected Member Functions

void add (std::shared_ptr< Detector::InCameraBuilder > detector)
 Add a detector to the collection. More...
 

Detailed Description

A helper class for creating and modifying cameras.

Camera and Camera::Builder have no direct inheritance relationship, but both inherit from different specializations of DetectorCollectionBase, so their container-of-detectors interfaces can generally be used the same way in both Python and templated C++.

Definition at line 208 of file Camera.h.

Member Typedef Documentation

◆ IdMap

Definition at line 53 of file DetectorCollection.h.

◆ List

Definition at line 54 of file DetectorCollection.h.

◆ NameMap

Definition at line 52 of file DetectorCollection.h.

Constructor & Destructor Documentation

◆ ~Builder()

lsst::afw::cameraGeom::Camera::Builder::~Builder ( )
virtualdefaultnoexcept

◆ Builder() [1/2]

lsst::afw::cameraGeom::Camera::Builder::Builder ( std::string const &  name)
explicit

Construct a Builder for a completely new Camera with the given name.

Definition at line 204 of file Camera.cc.

204 : _name(name) {}
table::Key< std::string > name
Definition: Camera.cc:123

◆ Builder() [2/2]

lsst::afw::cameraGeom::Camera::Builder::Builder ( Camera const &  camera)
explicit

Construct a Builder with the state of an existing Camera.

Definition at line 206 of file Camera.cc.

206  :
207  _name(camera.getName()),
208  _pupilFactoryName(camera.getPupilFactoryName())
209 {
210  // Add Detector Builders for all Detectors; does not (yet) include
211  // coordinate transform information.
212  for (auto const & pair : camera.getIdMap()) {
213  BaseCollection::add(Camera::makeDetectorBuilder(*pair.second));
214  }
215  // Iterate over connections in TransformMap, distributing them between the
216  // Camera Builder and the Detector Builders.
217  for (auto const & connection : camera.getTransformMap()->getConnections()) {
218  // asserts below are on Detector, Camera, and TransformMap invariants:
219  // - Connections should always be from native sys to something else.
220  // - The only connections between full-camera and per-detector sys
221  // should be from the camera native sys (FOCAL_PLANE) to the
222  // detector native sys (PIXELS).
223  // - When TransformMap standardizes connections, it should maintain
224  // these directions, as that's consistent with "pointing away" from
225  // the overall reference sys (the camera native sys).
226  if (connection.fromSys.hasDetectorName()) {
227  assert(connection.toSys.getDetectorName() == connection.fromSys.getDetectorName());
228  auto detector = (*this)[connection.fromSys.getDetectorName()];
229  assert(connection.fromSys == detector->getNativeCoordSys());
230  detector->setTransformFromPixelsTo(CameraSysPrefix(connection.toSys.getSysName()),
231  connection.transform);
232  } else {
233  assert(connection.fromSys == getNativeCameraSys());
234  if (!connection.toSys.hasDetectorName()) {
235  _connections.push_back(connection);
236  }
237  // We ignore the FOCAL_PLANE to PIXELS transforms transforms, as
238  // those are always regenerated from the Orientation when we
239  // rebuild the Camera.
240  }
241  }
242 }
table::Key< int > detector
void add(std::shared_ptr< Detector::InCameraBuilder > detector)
Add a detector to the collection.

Member Function Documentation

◆ add() [1/2]

Add a detector to the collection.

Parameters
[in]detectorNew detector to add to the collection.
Exceptions
pex::exceptions::RuntimeErrorThrown if the ID and/or name conflict with those of detectors already in the collection.
Exception Safety
Strong for pex::exceptions::RuntimeError, weak (collection is made empty) otherwise.

Definition at line 135 of file DetectorCollection.cc.

89  {
90  auto idIter = _idDict.find(detector->getId());
91  auto nameIter = _nameDict.find(detector->getName());
92  if (idIter == _idDict.end()) {
93  if (nameIter == _nameDict.end()) {
94  try {
95  _idDict.emplace(detector->getId(), detector);
96  _nameDict.emplace(detector->getName(), detector);
97  } catch (...) {
98  _idDict.clear();
99  _nameDict.clear();
100  throw;
101  }
102  } else {
103  throw LSST_EXCEPT(
104  pex::exceptions::RuntimeError,
105  (boost::format("Detector name %s is not unique.") % detector->getName()).str()
106  );
107  }
108  } else {
109  if (nameIter == _nameDict.end()) {
110  throw LSST_EXCEPT(
111  pex::exceptions::RuntimeError,
112  (boost::format("Detector ID %s is not unique.") % detector->getId()).str()
113  );
114  } else {
115  if (nameIter->second != detector) {
116  assert(idIter->second != detector);
117  throw LSST_EXCEPT(
118  pex::exceptions::RuntimeError,
119  (boost::format("Detector name %s and ID %s are not unique.") % detector->getName()
120  % detector->getId()).str()
121  );
122  }
123  // detector is already present; do nothing
124  }
125  }
126 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
T clear(T... args)
T emplace(T... args)
T end(T... args)
T find(T... args)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ add() [2/2]

std::shared_ptr< Detector::InCameraBuilder > lsst::afw::cameraGeom::Camera::Builder::add ( std::string const &  name,
int  id 
)

Add a new Detector with the given name and ID.

This is the only way to create a completely new detector (as opposed to a copy of an existing one), and it permanently sets that Detector's name and ID.

Exceptions
pex::exceptions::RuntimeErrorThrown if the ID and/or name conflict with those of detectors already in the collection.
Exception Safety
Strong for pex::exceptions::RuntimeError, none otherwise.

Definition at line 329 of file Camera.cc.

329  {
330  auto detector = makeDetectorBuilder(name, id);
332  return detector;
333 }

◆ discardTransformFromFocalPlaneTo()

bool lsst::afw::cameraGeom::Camera::Builder::discardTransformFromFocalPlaneTo ( CameraSys const &  toSys)

Remove any transformation from FOCAL_PLANE to the given coordinate system.

Parameters
toSysCoordinate system this transform returns points in.
Returns
true if a transform was removed; false otherwise.

Definition at line 320 of file Camera.cc.

320  {
321  auto iter = findConnection(_connections.begin(), _connections.end(), toSys);
322  if (iter != _connections.end()) {
323  _connections.erase(iter);
324  return true;
325  }
326  return false;
327 }

◆ empty()

bool lsst::afw::cameraGeom::DetectorCollectionBase< Detector::InCameraBuilder >::empty ( ) const
inlinenoexceptinherited

Determine if the collection contains any detectors.

Definition at line 72 of file DetectorCollection.h.

72 { return _idDict.empty(); }
T empty(T... args)

◆ finish()

std::shared_ptr< Camera const > lsst::afw::cameraGeom::Camera::Builder::finish ( ) const

Construct a new Camera from the state of the Builder.

Definition at line 246 of file Camera.cc.

246  {
247  // Make a big vector of all coordinate transform connections;
248  // start with general transforms for the camera as a whole:
249  std::vector<TransformMap::Connection> connections(_connections);
250  // Loop over detectors and add the transforms from FOCAL_PLANE
251  // to PIXELS (via the Orientation), and then any extra transforms
252  // from PIXELS to other things.
253  for (auto const & pair : getIdMap()) {
254  auto const & detectorBuilder = *pair.second;
255  connections.push_back(
256  TransformMap::Connection{
257  detectorBuilder.getOrientation().makeFpPixelTransform(detectorBuilder.getPixelSize()),
258  getNativeCameraSys(),
259  detectorBuilder.getNativeCoordSys()
260  }
261  );
262  connections.insert(connections.end(),
263  getDetectorBuilderConnections(detectorBuilder).begin(),
264  getDetectorBuilderConnections(detectorBuilder).end());
265  }
266  // Make a single big TransformMap.
267  auto transformMap = TransformMap::make(getNativeCameraSys(), connections);
268  // Make actual Detector objects, giving each the full TransformMap.
269  DetectorList detectors;
270  detectors.reserve(size());
271  for (auto const & pair : getIdMap()) {
272  auto const & detectorBuilder = *pair.second;
273  detectors.push_back(detectorBuilder.finish(transformMap));
274  }
275  return std::shared_ptr<Camera>(new Camera(_name, std::move(detectors), std::move(transformMap),
276  _pupilFactoryName));
277 }
int end
table::Key< int > transformMap
Definition: Camera.cc:125
T begin(T... args)
Camera(Camera const &)=delete
DetectorCollection::List DetectorList
Definition: Camera.h:48
std::size_t size() const noexcept
Get the number of detectors.
IdMap const & getIdMap() const noexcept
Get a map keyed and ordered by ID.
static std::shared_ptr< TransformMap const > make(CameraSys const &reference, Transforms const &transforms)
Construct a TransformMap with all transforms relative to a single reference CameraSys.
T move(T... args)
T reserve(T... args)

◆ get() [1/2]

Retrieve a detector by ID, or fall back to a default.

Parameters
[in]iddetector id
[in]defdefault detector to return. This defaults to nullptr.
Returns
pointer to detector entry if the entry exists, else return the default value

Definition at line 110 of file DetectorCollection.cc.

65  {
66  auto i = _idDict.find(id);
67  if (i == _idDict.end()) {
68  return def;
69  }
70  return i->second;
71 }

◆ get() [2/2]

Retrieve a detector by name, or fall back to a default.

Parameters
[in]namedetector name
[in]defdefault detector to return. This defaults to nullptr.
Returns
pointer to detector entry if the entry exists, else return the default value

Definition at line 99 of file DetectorCollection.cc.

56  {
57  auto i = _nameDict.find(name);
58  if (i == _nameDict.end()) {
59  return def;
60  }
61  return i->second;
62 }
table::Key< std::string > name
Definition: Amplifier.cc:116

◆ getIdMap()

IdMap const& lsst::afw::cameraGeom::DetectorCollectionBase< Detector::InCameraBuilder >::getIdMap ( ) const
inlinenoexceptinherited

Get a map keyed and ordered by ID.

Definition at line 62 of file DetectorCollection.h.

62 { return _idDict; }

◆ getName()

std::string lsst::afw::cameraGeom::Camera::Builder::getName ( ) const
inline

Return the name of the camera.

Definition at line 230 of file Camera.h.

230 { return _name; }

◆ getNameMap()

NameMap const& lsst::afw::cameraGeom::DetectorCollectionBase< Detector::InCameraBuilder >::getNameMap ( ) const
inlinenoexceptinherited

Get a map keyed and ordered by name.

Definition at line 59 of file DetectorCollection.h.

59 { return _nameDict; }

◆ getPupilFactoryName()

std::string lsst::afw::cameraGeom::Camera::Builder::getPupilFactoryName ( ) const
inline

Return the fully-qualified name of the Python class that provides this Camera's PupilFactory.

Definition at line 236 of file Camera.h.

236 { return _pupilFactoryName; }

◆ operator[]() [1/2]

Implement the [id] operator.

Parameters
[in]iddetector name
Returns
pointer to detector entry

Definition at line 88 of file DetectorCollection.cc.

46  {
47  auto det = get(id);
48  if (det == nullptr) {
49  throw LSST_EXCEPT(pex::exceptions::NotFoundError,
50  (boost::format("Detector with ID %s not found") % id).str());
51  }
52  return det;
53 }
table::Key< int > id
Definition: Detector.cc:162

◆ operator[]() [2/2]

Implement the [name] operator.

Parameters
[in]namedetector name
Returns
pointer to detector entry

Definition at line 80 of file DetectorCollection.cc.

36  {
37  auto det = get(name);
38  if (det == nullptr) {
39  throw LSST_EXCEPT(pex::exceptions::NotFoundError,
40  (boost::format("Detector with name %s not found") % name).str());
41  }
42  return det;
43 }

◆ remove() [1/2]

void lsst::afw::cameraGeom::Camera::Builder::remove ( int  id)
inline

Definition at line 284 of file Camera.h.

◆ remove() [2/2]

void lsst::afw::cameraGeom::Camera::Builder::remove ( std::string const &  name)
inline

Remove the detector with the given name or ID.

Wrapped as __delitem__ in Python.

Exceptions
pex::exceptions::NotFoundErrorif no such detector exists.

Definition at line 283 of file Camera.h.

283 { return BaseCollection::remove(name); }

◆ setName()

void lsst::afw::cameraGeom::Camera::Builder::setName ( std::string const &  name)
inline

Set the name of the camera.

Definition at line 233 of file Camera.h.

233 { _name = name; }

◆ setPupilFactoryName()

void lsst::afw::cameraGeom::Camera::Builder::setPupilFactoryName ( std::string const &  pupilFactoryName)
inline

Set the fully-qualified name of the Python class that provides this Camera's PupilFactory.

Definition at line 239 of file Camera.h.

239 { _pupilFactoryName = pupilFactoryName; }
table::Key< std::string > pupilFactoryName
Definition: Camera.cc:124

◆ setTransformFromFocalPlaneTo()

void lsst::afw::cameraGeom::Camera::Builder::setTransformFromFocalPlaneTo ( CameraSys const &  toSys,
std::shared_ptr< afw::geom::TransformPoint2ToPoint2 const >  transform 
)

Set the transformation from FOCAL_PLANE to the given coordinate system.

Parameters
toSysCoordinate system this transform returns points in.
transformTransform from FOCAL_PLANE to toSys.

If a transform already exists from FOCAL_PLANE to toSys, it is overwritten.

Definition at line 299 of file Camera.cc.

302  {
303  if (toSys.hasDetectorName()) {
304  throw LSST_EXCEPT(
305  pex::exceptions::LogicError,
306  (boost::format("%s should be added to Detector %s, not Camera") %
307  toSys.getSysName() % toSys.getDetectorName()).str()
308  );
309  }
310  auto iter = findConnection(_connections.begin(), _connections.end(), toSys);
311  if (iter == _connections.end()) {
312  _connections.push_back(
313  TransformMap::Connection{transform, getNativeCameraSys(), toSys}
314  );
315  } else {
316  iter->transform = transform;
317  }
318 }
lsst::geom::Point2D transform(lsst::geom::Point2D const &point, CameraSys const &fromSys, CameraSys const &toSys) const
Transform a point from one camera coordinate system to another.
Definition: Camera.cc:83

◆ size()

Get the number of detectors.

Renamed to __len__ in Python.

Definition at line 67 of file DetectorCollection.h.

67 { return _idDict.size(); }
T size(T... args)

The documentation for this class was generated from the following files: