def testRun(self): registry = self.makeRegistry() # Check insertion and retrieval with two different collections for collection in ["one", "two"]: run = registry.makeRun(collection) self.assertIsInstance(run, Run) self.assertEqual(run.collection, collection) # Test retrieval by collection runCpy1 = registry.getRun(collection=run.collection) self.assertEqual(runCpy1, run) # Test retrieval by (run/execution) id runCpy2 = registry.getRun(id=run.id) self.assertEqual(runCpy2, run) # Non-existing collection should return None self.assertIsNone(registry.getRun(collection="bogus")) # Non-existing id should return None self.assertIsNone(registry.getRun(id=100)) # Inserting with a preexisting collection should fail with self.assertRaises(ConflictingDefinitionError): registry.makeRun("one") # Insert a new Run and check that ensureRun silently ignores it collection = "dummy" run = registry.makeRun(collection) registry.ensureRun(run) # Calling ensureRun with a different Run with the same id should fail run2 = Run(collection="hello") run2._id = run.id with self.assertRaises(ConflictingDefinitionError): registry.ensureRun(run2) run2._id = None # Now it should work registry.ensureRun(run2) self.assertEqual(run2, registry.getRun(id=run2.id))
def makeDatasetRef(self, datasetTypeName, dimensions, storageClass, dataId, id=None, run=None): """Make a DatasetType and wrap it in a DatasetRef for a test""" datasetType = DatasetType(datasetTypeName, dimensions, storageClass) if id is None: self.id += 1 id = self.id if run is None: run = Run(id=1, collection="dummy") return DatasetRef(datasetType, dataId, id=id, run=run)
def __init__(self, config=None, *, butler, **kwds): super().__init__(config, **kwds) self.butler = butler self.datasetType = self.getDatasetType() self.dimensions = butler.registry.dimensions.extract(["Instrument", "Detector", "PhysicalFilter", "Visit", "Exposure"]) # Dictionary of {Dimension: set(DataId)} indicating Dimension entries # we know are in the Registry. self.dimensionEntriesDone = {k: set() for k in self.dimensions} # Cache of Instrument instances retrieved from Registry; needed to look # up formatters. self.instrumentCache = {} # (Possibly) create a Run object for the "stash": where we put datasets # that lose conflicts. Note that this doesn't actually add this Run # to the Registry; we only do that on first use. self.stashRun = Run(self.config.stash) if self.config.stash is not None else None
def _makeQuanta(self, config): """Create set of Quanta """ universe = DimensionUniverse() run = Run(collection=1, environment=None, pipeline=None) connections = config.connections.ConnectionsClass(config=config) dstype0 = connections.input.makeDatasetType(universe) dstype1 = connections.output.makeDatasetType(universe) quanta = [] for visit in range(100): quantum = Quantum(run=run) quantum.addPredictedInput( self._makeDSRefVisit(dstype0, visit, universe)) quantum.addOutput(self._makeDSRefVisit(dstype1, visit, universe)) quanta.append(quantum) return quanta
def _makeQuanta(self, config): """Create set of Quanta """ universe = DimensionUniverse.fromConfig() run = Run(collection=1, environment=None, pipeline=None) descriptor = pipeBase.DatasetTypeDescriptor.fromConfig(config.input) dstype0 = descriptor.makeDatasetType(universe) descriptor = pipeBase.DatasetTypeDescriptor.fromConfig(config.output) dstype1 = descriptor.makeDatasetType(universe) quanta = [] for visit in range(100): quantum = Quantum(run=run, task=None) quantum.addPredictedInput(self._makeDSRefVisit(dstype0, visit)) quantum.addOutput(self._makeDSRefVisit(dstype1, visit)) quanta.append(quantum) return quanta