Skip to content
Snippets Groups Projects
Commit e23633c0 authored by Daniel Speckhard's avatar Daniel Speckhard
Browse files

merged changes.

parents 85bf33ef 22024d2b
No related branches found
No related tags found
No related merge requests found
......@@ -131,6 +131,8 @@ class LocalBackend(object):
# Check the type
dtype_str = dataManager.metaInfo.dtypeStr
if dtype_str is None:
raise TypeError("The metainfo '{}' does not define a dtypeStr".format(metaName))
single_types = self.single_value_type_for_metainfo_type(dtype_str)
actual_numpy_type = type(value)
if actual_numpy_type not in single_types:
......@@ -319,14 +321,14 @@ class Results(object):
if metainfo is None:
raise LookupError("The metainfo name '{}' does not exist in the metainfo environment. Check for typos or try updating the metainfo git package.".format(metaname))
def traverse(self):
def traverse(self, root_section='section_run'):
"""A generator function for traversing the data in the parser results.
This generator returns a tuple of three item: the metainfo name, the
event type, and the event value.
"""
root = self._sectionmanagers["section_run"]
for x in self.traverse_recursive("section_run", root.openSections):
root = self._sectionmanagers[root_section]
for x in self.traverse_recursive(root_section, root.openSections):
yield x
def traverse_recursive(self, name, open_sections):
......@@ -625,7 +627,7 @@ class SectionManager(object):
gI = gIndex
try:
self.openSections[gI].addValue(valueMetaInfo, value)
except KeyError:
except (KeyError, IndexError):
raise Exception("Cannot add value for metadata %s to section %d (%d) of %s, as it is not open" % (valueMetaInfo.name, gI, gIndex, self.metaInfo.name))
def setArrayValues(self, valueMetaInfo, value, offset=None, gIndex=-1):
......@@ -635,7 +637,7 @@ class SectionManager(object):
gI = gIndex
try:
self.openSections[gI].setArrayValues(valueMetaInfo, value, offset)
except KeyError:
except (KeyError, IndexError):
raise Exception("Cannot set array values for metadata %s to section %d (%d) of %s, as it is not open" % (valueMetaInfo.name, gI, gIndex, self.metaInfo.name))
def addArrayValues(self, valueMetaInfo, value, gIndex=-1, **kwargs):
......@@ -644,8 +646,8 @@ class SectionManager(object):
else:
gI = gIndex
try:
self.openSections[gI].addArrayValues(valueMetaInfo, value, **kwargs)
except KeyError:
self.openSections[gI].addArrayValues(valueMetaInfo, value)
except (KeyError, IndexError):
raise Exception("Cannot add array values for metadata %s to section %d (%d) of %s, as it is not open" % (valueMetaInfo.name, gI, gIndex, self.metaInfo.name))
......
......@@ -10,6 +10,7 @@ import json
import os, re
from nomadcore.json_support import jsonCompactS, jsonCompactD, jsonIndentD
from io import open
import nomad_meta_info
"""objects to handle a local InfoKinds with unique name (think self written json)"""
class InfoKindEl(object):
......@@ -183,14 +184,20 @@ class RelativeDependencySolver(object):
self.deps = {}
def __call__(self, infoKindEnv, source, dep):
if "relativePath" not in dep:
raise Exception('Invalid dependency for relativeDependencySolver there must be a relativePath')
basePath = source.get('path')
if "metainfoPath" in dep:
basePath = nomad_meta_info.__file__
path = dep["metainfoPath"]
elif "relativePath" in dep:
basePath = source.get('path')
path = dep["relativePath"]
else:
raise Exception('Invalid dependency for relativeDependencySolver there must be a relativePath or metainfoPath')
if basePath:
baseDir = os.path.dirname(os.path.abspath(basePath))
else:
baseDir = os.getcwd()
dPath = os.path.realpath(os.path.join(baseDir, dep['relativePath']))
dPath = os.path.realpath(os.path.join(baseDir, path))
if dPath in self.deps:
return self.deps[dPath]
depInfo = None
......@@ -456,7 +463,7 @@ class InfoKindEnv(object):
def toJsonList(self, withGids):
infoKinds = list(self.infoKinds.keys())
infoKinds.sort(lambda x, y: self.compareKeys(x.name, y.name))
# infoKinds.sort(lambda x, y: self.compareKeys(x.name, y.name))
return [self.infoKinds[x].toDict(self,
self if withGids else None) for x in infoKinds]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment