LSSTApplications  11.0-24-g0a022a1,14.0+77,15.0,15.0+1
LSSTDataManagementBasePackage
Public Member Functions | List of all members
lsst.datarel.datasetScanner.DatasetScanner Class Reference
Inheritance diagram for lsst.datarel.datasetScanner.DatasetScanner:
lsst.datarel.datasetScanner.HfsScanner

Public Member Functions

def __init__ (self, dataset, camera, cameraMapper)
 
def walk (self, root, rules=None)
 

Detailed Description

File system scanner for a dataset known to a camera mapper.

Definition at line 399 of file datasetScanner.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.datarel.datasetScanner.DatasetScanner.__init__ (   self,
  dataset,
  camera,
  cameraMapper 
)

Definition at line 403 of file datasetScanner.py.

403  def __init__(self, dataset, camera, cameraMapper):
404  if not isinstance(cameraMapper, lsst.daf.butlerUtils.CameraMapper):
405  raise TypeError('Expecting a lsst.daf.butlerUtils.CameraMapper!')
406  if dataset not in cameraMapper.mappings:
407  raise NotFoundError('Unknown dataset ' + str(dataset))
408  HfsScanner.__init__(self, cameraMapper.mappings[dataset].template)
409  camera = camera.lower()
410  if camera not in _keyTypes:
411  raise RuntimeError('{} camera not supported yet'.format(camera))
412  for k in self._formatKeys:
413  if k not in _keyTypes[camera]:
414  raise RuntimeError('{} is not a valid dataId key for camera {}'.format(k, camera))
415  self._formatKeys[k].munge = _mungeFunctions[camera]
416 
def __init__(self, needLockOnRead=True, data=None, cond=None)
Definition: SharedData.py:53
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:134

Member Function Documentation

◆ walk()

def lsst.datarel.datasetScanner.HfsScanner.walk (   self,
  root,
  rules = None 
)
inherited
Generator that descends the given root directory in top-down
fashion, matching paths corresponding to the template and satisfying
the given rule list. The generator yields tuples of the form
(path, dataId), where path is a dataset file name relative to root,
and dataId is a key value dictionary identifying the file.

Definition at line 281 of file datasetScanner.py.

281  def walk(self, root, rules=None):
282  """Generator that descends the given root directory in top-down
283  fashion, matching paths corresponding to the template and satisfying
284  the given rule list. The generator yields tuples of the form
285  (path, dataId), where path is a dataset file name relative to root,
286  and dataId is a key value dictionary identifying the file.
287  """
288  oneFound = False
289  while os.path.exists(root) and not oneFound:
290  stack = [(0, root, rules, {})]
291  while stack:
292  depth, path, rules, dataId = stack.pop()
293  if os.path.isfile(path):
294  continue
295  pc = self._pathComponents[depth]
296  if pc.simple:
297  # No need to list directory contents
298  entries = [pc.regex]
299  if not os.path.exists(os.path.join(path, pc.regex)):
300  continue
301  else:
302  entries = os.listdir(path)
303  depth += 1
304  for e in entries:
305  subRules = rules
306  subDataId = dataId
307  if not pc.simple:
308  # make sure e matches path component regular expression
309  m = pc.regex.match(e)
310  if not m:
311  continue
312  # got a match - update dataId with new key values (if any)
313  try:
314  for i, k in enumerate(pc.keys):
315  subDataId = self._formatKeys[k].munge(k, m.group(i + 1), subDataId)
316  except:
317  # Munger raises if value is invalid for key, so
318  # not really a match
319  continue
320  if subRules and pc.keys:
321  # have dataId rules and saw new keys; filter rule list
322  for k in subDataId:
323  newRules = []
324  for r in subRules:
325  if k not in r or subDataId[k] in r[k]:
326  newRules.append(r)
327  subRules = newRules
328  if not subRules:
329  continue # no rules matched
330  # Have path matching template and at least one rule
331  p = os.path.join(path, e)
332  if depth < len(self._pathComponents):
333  # recurse
334  stack.append((depth, p, subRules, subDataId))
335  elif depth == len(self._pathComponents):
336  if os.path.isfile(p):
337  # found a matching file, yield it
338  yield os.path.relpath(p, root), subDataId
339  oneFound = True
340  # end while stack
341  root = os.path.join(root, "_parent")
342 
343 
344 # -- Camera specific dataId mungers ----
345 

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