Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-24355: Make Instrument registration idempotent. #258

Merged
merged 1 commit into from
Oct 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 15 additions & 12 deletions python/lsst/obs/lsst/_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,21 @@ def register(self, registry):
# The maximum values below make Gen3's ObservationDataIdPacker produce
# outputs that match Gen2's ccdExposureId.
obsMax = self.translatorClass.max_detector_exposure_id()
registry.insertDimensionData("instrument",
{"name": self.getName(),
"detector_max": self.translatorClass.DETECTOR_MAX,
"visit_max": obsMax,
"exposure_max": obsMax,
"class_name": getFullTypeName(self),
})

records = [self.extractDetectorRecord(detector) for detector in self.getCamera()]
registry.insertDimensionData("detector", *records)

self._registerFilters(registry)
with registry.transaction():
registry.syncDimensionData(
"instrument",
{
"name": self.getName(),
"detector_max": self.translatorClass.DETECTOR_MAX,
"visit_max": obsMax,
"exposure_max": obsMax,
"class_name": getFullTypeName(self),
}
)
for detector in self.getCamera():
registry.syncDimensionData("detector", self.extractDetectorRecord(detector))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the bulk insert version disappear or something? Previously it built all the records and did one insert, here it does a separate sync for each detector.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. syncDimensionData doesn't do bulk. It probably could be made to now with enough effort, but that's a bigger change than I wanted to make on this ticket, and I think for an operation as rare as instrument registration ought to be, a few hundred single-row insert operations is not a big problem. I figured being able to add new detectors (and check for consistency with all existing ones) was more valuable than performance in this context.

A no-op sync is not free, though, and I've tried to document that wherever I could. If people throw calls to Instrument.register and the like everywhere (especially TestCase.setUp) we will regret it.


self._registerFilters(registry)

def extractDetectorRecord(self, camGeomDetector):
"""Create a Gen3 Detector entry dict from a cameraGeom.Detector.
Expand Down