defisRefPath(path):
return path.startswith("/REF")
defisTheoryPath(path):
return path.startswith("/THY")
defisRawPath(path):
return path.startswith("/RAW")
defisRawAO(ao):
return isRawPath(ao.path())
defisTheoryAO(ao):
return isTheoryPath(ao.path())
defstripOptions(path):
import re
return re.sub(r':\w+=[^:/]+', "", path)
defstripWeightName(path):
import re
return re.sub(r'\[.*\]', "", path)
defextractWeightName(path):
import re
re_weight = re.compile(r".*\[(.*?)\].*")
m = re_weight.match(path)
ifnot m:
return""else:
return m.group(1)
defextractOptionString(path):
import re
re_opts = re.compile(r"^.*(:\w+=[^:/]+)+")
m = re_opts.match(path)
ifnot m:
return"" opts =list(m.groups())
for i inrange(len(opts)):
opts[i] = opts[i].strip(':')
return" ["+",".join(opts) +"]"defisRefAO(ao):
returnint(ao.annotation("IsRef")) ==1or isRefPath(ao.path())
defisTmpPath(path):
return"/_"in path #< match *any* underscore-prefixed path componentdefisTmpAO(ao):
return isTmpPath(ao.path())
classAOPath(object):
"""
Object representation of analysis object path structures.
TODO: move to YODA?
"""import re
re_aopath = re.compile(r"^(/[^\[\]\@\#]+)(\[[A-Za-z\d\._=\s+-]+\])?(#\d+|@[\d\.]+)?$")
def __init__(self, path):
self.origpath = path
m = self.re_aopath.match(path)
ifnot m:
raise ValueError("Supplied path '%s' does not meet required structure"% path)
self._basepath = m.group(1)
self._varid = m.group(2).lstrip("[").rstrip("]") if m.group(2) elseNone self._binid =int(m.group(3).lstrip("#")) if m.group(3) elseNone self._isref = isRefPath(self._basepath)
defbasepath(self, keepref=False):
"Main 'Unix-like' part of the AO path, optionally including a /REF prefix" p = self._basepath.rstrip("/")
ifnot keepref and p.startswith("/REF"):
p = p[4:]
return p
defvarpath(self, keepref=False, defaultvarid=None):
"The basepath, plus any bracketed variation identifier" p = self.basepath(keepref)
if self.varid(defaultvarid) isnotNone:
p +="[%s]"%str(self.varid(defaultvarid))
return p
defbinpath(self, keepref=False, defaultbinid=None, defaultvarid=None):
"The varpath, plus any #-prefixed bin number identifier" p = self.varpath(keepref, defaultvarid)
if self.binid(defaultbinid) isnotNone:
p +="#%d"% self.binid(defaultbinid)
return p
defbasepathparts(self, keepref=False):
"List of basepath components, split by forward slashes"return self.basepath(keepref).strip("/").split("/")
# TODO: basepathhead, basepathtaildefdirname(self, keepref=False):
"The non-final (i.e. dir-like) part of the basepath"import os
return os.path.dirname(self.basepath(keepref))
defdirnameparts(self, keepref=False):
"List of dirname components, split by forward slashes"return self.dirname(keepref).strip("/").split("/")
defbasename(self):
"The final (i.e. file-like) part of the basepath"import os
return os.path.basename(self._basepath)
defvarid(self, default=None):
"The variation identifier (without brackets) if there is one, otherwise None"return self._varid if self._varid isnotNoneelse default
defbinid(self, default=None):
"The bin identifier (without #) if there is one, otherwise None"return self._binid if self._binid isnotNoneelse default
defisref(self):
"Is there a /REF prefix in the original path?"return self._isref
defistmp(self):
"Do any basepath components start with an underscore, used to hide them from plotting?"return isTmpPath(self.basepath())
defisraw(self):
"Do any basepath components start with /RAW, used to hide them from plotting?"return isRawPath(self.basepath())