Skip to content
Snippets Groups Projects
Commit e2d26468 authored by Mohamed, Fawzi Roberto (fawzi)'s avatar Mohamed, Fawzi Roberto (fawzi)
Browse files

making caching level automatically recursive

if a section is not forwarded none of the children are
parent 2f70bee0
Branches
Tags
No related merge requests found
...@@ -2,6 +2,7 @@ from builtins import str ...@@ -2,6 +2,7 @@ from builtins import str
from builtins import zip from builtins import zip
from builtins import range from builtins import range
from builtins import object from builtins import object
from functools import reduce
import json import json
import numpy as np import numpy as np
import sys import sys
...@@ -17,17 +18,27 @@ class CachingLevel(object): ...@@ -17,17 +18,27 @@ class CachingLevel(object):
@classmethod @classmethod
def toText(cls, cl): def toText(cls, cl):
if cl == Forward: if cl == cls.Forward:
return "Forward" return "Forward"
elif cl == ForwardAndCache: elif cl == cls.ForwardAndCache:
return "ForwardAndCache" return "ForwardAndCache"
elif cl == Cache: elif cl == cls.Cache:
return "Cache" return "Cache"
elif cl == Ignore: elif cl == cls.Ignore:
return "Ignore" return "Ignore"
else: else:
return "CachingLevel(%s)" % cl return "CachingLevel(%s)" % cl
@classmethod
def restrict(cls, a, b):
"""restricts a keeping in account that it is contained in b (i.e. if b is not forwarded then also a cannot be forwarded)"""
if b == cls.Cache or b == cls.Ignore:
if a == cls.Forward:
return cls.Ignore
elif a == cls.ForwardAndCache:
return cls.Cache
return a
class CachingSection(object): class CachingSection(object):
"""Represents an open section, and can cache values""" """Represents an open section, and can cache values"""
def __init__(self, gIndex, references, storeInSuper = False, activeBackend=None): def __init__(self, gIndex, references, storeInSuper = False, activeBackend=None):
...@@ -256,9 +267,9 @@ class ActiveBackend(object): ...@@ -256,9 +267,9 @@ class ActiveBackend(object):
sectionManagers = {} sectionManagers = {}
for ikNames, ik in metaInfoEnv.infoKinds.items(): for ikNames, ik in metaInfoEnv.infoKinds.items():
if ik.kindStr == "type_section": if ik.kindStr == "type_section":
parentS = list(metaInfoEnv.firstAncestorsByType(ik.name).get("type_section", [[]])[0]) parentS, parentO = list(metaInfoEnv.firstAncestorsByType(ik.name).get("type_section", [[],[]]))
parentS.sort() parentS.sort()
cachingLevel = cachingLevelForMetaName.get(ik.name, defaultSectionCachingLevel) cachingLevel = reduce(CachingLevel.restrict, [cachingLevelForMetaName.get(x, defaultSectionCachingLevel) for x in ([ik.name] + parentS + parentO)])
sectionManagers[ik.name] = CachingSectionManager( sectionManagers[ik.name] = CachingSectionManager(
metaInfo = ik, metaInfo = ik,
parentSectionNames = parentS, parentSectionNames = parentS,
...@@ -275,8 +286,9 @@ class ActiveBackend(object): ...@@ -275,8 +286,9 @@ class ActiveBackend(object):
elif len(superSectionNames) > 1: elif len(superSectionNames) > 1:
raise Exception("MetaInfo of concrete value %s has multiple superSections (%s)" % raise Exception("MetaInfo of concrete value %s has multiple superSections (%s)" %
(ik.name, superSectionNames)) (ik.name, superSectionNames))
dataManagers[ik.name] = CachingDataManager(ik, sectionManagers[superSectionNames[0]], sectionManager = sectionManagers[superSectionNames[0]]
cachingLevelForMetaName.get(ik.name, defaultDataCachingLevel)) dataManagers[ik.name] = CachingDataManager(ik, sectionManager,
CachingLevel.restrict(cachingLevelForMetaName.get(ik.name, defaultDataCachingLevel), CachingLevel.Forward if sectionManager.forwardOpenClose else CachingLevel.Ignore))
return ActiveBackend(metaInfoEnv, sectionManagers, dataManagers, superBackend, propagateStartFinishParsing, default_units, metainfo_units) return ActiveBackend(metaInfoEnv, sectionManagers, dataManagers, superBackend, propagateStartFinishParsing, default_units, metainfo_units)
def appendOnClose(self, sectionName, onClose): def appendOnClose(self, sectionName, onClose):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment