30 namespace cameraGeom {
57 auto i = _nameDict.find(
name);
58 if (i == _nameDict.end()) {
66 auto i = _idDict.find(
id);
67 if (i == _idDict.end()) {
75 for (
auto const &
detector : detectorList) {
80 if (_idDict.size() < detectorList.
size()) {
83 if (_nameDict.size() < detectorList.
size()) {
90 auto idIter = _idDict.find(
detector->getId());
91 auto nameIter = _nameDict.find(
detector->getName());
92 if (idIter == _idDict.end()) {
93 if (nameIter == _nameDict.end()) {
109 if (nameIter == _nameDict.end()) {
128 template <
typename T>
130 auto nameIter = _nameDict.find(
name);
131 if (nameIter == _nameDict.end()) {
137 auto idIter = _idDict.find(nameIter->second->getId());
138 assert(idIter != _idDict.end());
139 _nameDict.erase(nameIter);
140 _idDict.erase(idIter);
143 template <
typename T>
145 auto idIter = _idDict.find(
id);
146 if (idIter == _idDict.end()) {
152 auto nameIter = _nameDict.find(idIter->second->getName());
153 assert(nameIter != _nameDict.end());
154 _nameDict.erase(nameIter);
155 _idDict.erase(idIter);
163 class PersistenceHelper {
166 static PersistenceHelper
const & get() {
167 static PersistenceHelper
const instance;
175 table::io::InputArchive
const & archive,
176 table::io::CatalogVector
const & catalogs
181 result.reserve(catalogs.front().size());
182 for (
auto const & record : catalogs.front()) {
183 int archiveId = record.get(
detector);
184 result.push_back(archive.get<Detector>(archiveId));
191 PersistenceHelper() :
193 detector(
schema.addField<int>(
"detector",
"archive ID of Detector in a DetectorCollection"))
196 PersistenceHelper(PersistenceHelper
const &) =
delete;
197 PersistenceHelper(PersistenceHelper &&) =
delete;
199 PersistenceHelper &
operator=(PersistenceHelper
const &) =
delete;
200 PersistenceHelper &
operator=(PersistenceHelper &&) =
delete;
210 for (
auto const &
detector : detectorList) {
220 Factory() : table::io::PersistableFactory(
"DetectorCollection") {}
243 return "DetectorCollection";
247 return "lsst.afw.cameraGeom";
251 auto const &
keys = PersistenceHelper::get();
253 for (
auto const & pair :
getIdMap()) {
254 auto record = cat.
addNew();
255 record->set(
keys.detector, handle.
put(pair.second));
265 template class PersistableFacade<cameraGeom::DetectorCollection>;
table::Key< std::string > name
table::Key< int > detector
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
std::shared_ptr< Persistable > read(InputArchive const &archive, CatalogVector const &catalogs) const override
Construct a new object from the given InputArchive and vector of catalogs.
static Factory const registration
An abstract base class for collections of Detectors and specific subclasses thereof.
void remove(std::string const &name)
IdMap const & getIdMap() const noexcept
Get a map keyed and ordered by ID.
DetectorCollectionBase() noexcept=default
std::vector< std::shared_ptr< Detector const > > List
std::shared_ptr< T > operator[](std::string const &name) const
Implement the [name] operator.
virtual ~DetectorCollectionBase() noexcept=0
std::shared_ptr< T > get(std::string const &name, std::shared_ptr< T > def=nullptr) const
Retrieve a detector by name, or fall back to a default.
void add(std::shared_ptr< T > detector)
Add a detector to the collection.
An immutable collection of Detectors that can be accessed by name or ID.
DetectorCollection(List const &list)
virtual ~DetectorCollection() noexcept
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
A representation of a detector in a mosaic camera.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
A vector of catalogs used by Persistable.
An object passed to Persistable::write to allow it to persist itself.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
int put(Persistable const *obj, bool permissive=false)
Save an object to the archive and return a unique ID that can be used to retrieve it from an InputArc...
A base class for factory classes used to reconstruct objects from records.
void include(Point2D const &point) noexcept
Expand this to ensure that this->contains(point).
Reports attempts to access elements using an invalid key.
Reports errors that are due to events beyond the control of the program.
CameraSys const FOCAL_PLANE
Focal plane coordinates: Position on a 2-d planar approximation to the focal plane (x,...
std::string getPersistenceName() const override
FilterProperty & operator=(FilterProperty const &)=default
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
A base class for image defects.