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

obs_base Tickets/dm 7468 #26

Merged
merged 7 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
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
48 changes: 29 additions & 19 deletions python/lsst/obs/base/cameraMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,21 @@ def __init__(self, policy, repositoryDir,

self.rootStorage = dafPersist.Storage.makeFromURI(uri=root)

# If the calibRoot is passed in, use that. If not and it's indicated in the policy, use that. And
# otherwise, the calibs are in the regular root.
# If the location indicated by the calib root does not exist, do not create it.
# If the calibRoot is passed in, use that. If not and it's indicated in
# the policy, use that. And otherwise, the calibs are in the regular
# root.
# If the location indicated by the calib root does not exist, do not
# create it.
calibStorage = None
if calibRoot is not None and dafPersist.Storage.storageExists(uri=calibRoot):
calibStorage = dafPersist.Storage.makeFromURI(uri=calibRoot)
elif 'calibRoot' in policy:
calibRoot = policy['calibRoot']
calibRoot = dafPersist.LogicalLocation(calibRoot).locString()
if dafPersist.Storage.exists(uri=calibRoot):
calibStorage = dafPersist.Storage.makeFromURI(uri=calibRoot)
if calibRoot is not None:
calibRoot = dafPersist.Storage.absolutePath(root, calibRoot)
calibStorage = dafPersist.Storage.makeFromURI(uri=calibRoot,
create=False)
else:
calibRoot = policy.get('calibRoot', None)
if calibRoot:
calibStorage = dafPersist.Storage.makeFromURI(uri=calibRoot,
create=False)
if calibStorage is None:
calibStorage = self.rootStorage

Expand Down Expand Up @@ -499,8 +503,7 @@ def _search(self, path):
object can't be found. If the input argument path contained an HDU
indicator, the returned path will also contain the HDU indicator.
"""
# it would be better if storage was an instance, instead of having to demux the root URI every time.
return dafPersist.Storage.search(self.root, path)
return self.rootStorage.search(path)

def backup(self, datasetType, dataId):
"""Rename any existing object with the given type and dataId.
Expand Down Expand Up @@ -766,10 +769,13 @@ def _setupRegistry(self, name, description, path, policy, policyKey, storage, se

# Old Butler API was to indicate the registry WITH the repo folder, New Butler expects the registry to
# be in the repo folder. To support Old API, check to see if path starts with root, and if so, strip
# root from path.
root = storage.root
if path and (path.startswith(root)):
path = path[len(root + '/'):]
# root from path. Currently only works with PosixStorage
try:
root = storage.root
if path and (path.startswith(root)):
path = path[len(root + '/'):]
except AttributeError:
pass

# determine if there is an sqlite registry and if not, try the posix registry.
registry = None
Expand Down Expand Up @@ -810,10 +816,14 @@ def search(filename, description):
if newPath is not None:
path = newPath
self.log.debug("Loading %s registry from %s", description, path)
registry = dafPersist.Registry.create(storage.getLocalFile(path))
localFileObj = storage.getLocalFile(path)
registry = dafPersist.Registry.create(localFileObj.name)
elif not registry and posixIfNoSql:
self.log.info("Loading Posix %s registry from %s", description, storage.root)
registry = dafPersist.PosixRegistry(storage.root)
try:
self.log.info("Loading Posix %s registry from %s", description, storage.root)
registry = dafPersist.PosixRegistry(storage.root)
except:
registry = None

return registry

Expand Down
2 changes: 1 addition & 1 deletion python/lsst/obs/base/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def map(self, mapper, dataId, write=False):
if ext and path.endswith(ext):
continue # if the path already ends with the extension
extPath = path + ext if ext else path
newPath = self.rootStorage.search(self.rootStorage.root, extPath)
newPath = self.rootStorage.instanceSearch(extPath)
if newPath:
path = newPath
break
Expand Down
2 changes: 1 addition & 1 deletion tests/testCameraMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class MinMapper2(lsst.obs.base.CameraMapper):
def __init__(self, **kwargs):
policy = dafPersist.Policy(os.path.join(testDir, "MinMapper2.paf"))
lsst.obs.base.CameraMapper.__init__(self, policy=policy, repositoryDir=testDir,
registry=os.path.join(testDir, "cfhtls.sqlite3"), **kwargs)
registry="cfhtls.sqlite3", **kwargs)
return

def _transformId(self, dataId):
Expand Down
4 changes: 2 additions & 2 deletions tests/testOutputRoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ def testReuseOutputRoot(self):
outputs=testOutput)
self.assertTrue(os.path.exists(testOutput))
self.assertTrue(os.path.isdir(testOutput))
cfg = dafPersist.Storage.getRepositoryCfg(testOutput)
cfg = dafPersist.Storage().getRepositoryCfg(testOutput)
self.assertEqual(cfg.parents, [testPath])
del butler

butler = dafPersist.Butler(inputs={'root': testOutput, 'mapper': MinMapper1},
outputs=testOutput2)
self.assertTrue(os.path.exists(testOutput2))
self.assertTrue(os.path.isdir(testOutput2))
cfg = dafPersist.Storage.getRepositoryCfg(testOutput2)
cfg = dafPersist.Storage().getRepositoryCfg(testOutput2)
self.assertEqual(cfg.parents, [testOutput])
del butler

Expand Down