71 """Main code to translate the configuration given by 'top_level' into the
72 final configuration by expanding the regexes using the objects in 'td'"""
73 log.info(
'Translating regexes...')
79 mapping_groups = {
'top_level': top_level}
80 mapping_assessors_final = {}
82 iterate_hcfg(top_level, mapping, mapping_regex, mapping_groups)
83 mapping_assessors_final.update(mapping)
84 for path, g
in mapping_groups.items():
85 newgroup = HanConfigGroup()
86 newgroup.SetName(g.GetName())
87 newgroup.SetPathName(path)
89 mapping_groups_final[path] = newgroup
94 for path, (a, p)
in mapping_regex.items():
99 log.debug(f
'match {p} with {h}')
100 tokenized_path = path.split(
'/')
103 for tok
in tokenized_path[:-1]:
104 formatted_tok = string.Template(tok).
substitute(m.groupdict())
105 orig_fullpath.append(tok)
106 new_fullpath.append(formatted_tok)
107 orig =
'/'.
join(orig_fullpath)
108 target =
'/'.
join(new_fullpath)
109 if target
not in mapping_groups_final:
110 log.debug(f
'Need to adapt {orig} to {target}')
111 if orig
in mapping_groups_final:
112 log.debug(f
'Deleting {orig}')
113 del mapping_groups_final[orig]
114 newgroup = HanConfigGroup()
115 newgroup.SetName(formatted_tok)
116 newgroup.SetPathName(target)
117 oldgroup = mapping_groups[orig]
119 mapping_groups_final[target] = newgroup
121 tok = tokenized_path[-1]
122 orig_fullpath.append(tok)
123 hname = h.split(
'/')[-1]
125 hextra =
'' if '@' not in tok
else (
'@' + tok.rsplit(
'@',1)[1])
127 new_fullpath.append(hname)
128 orig =
'/'.
join(orig_fullpath)
129 target =
'/'.
join(new_fullpath)
130 log.debug(f
'Map from {orig} to {target}')
133 newass.SetName(h + hextra)
134 algrefname = a.GetAlgRefName()
136 if a.GetAlgRefName() !=
"":
137 ref = refmapcache.get(a.GetAlgRefName())
139 ref = config.Get(a.GetAlgRefName())
140 refmapcache[a.GetAlgRefName()] = ref
142 log.error(
'Unable to find references for', orig)
144 if isinstance(ref, ROOT.TMap):
145 algrefnameptr = ref.GetValue(h)
146 algrefname = algrefnameptr.GetString().
Data()
if algrefnameptr
else ""
147 if algrefname
and isinstance(config.Get(algrefname), ROOT.TMap):
148 log.error(f
'Reference for {newass} is somehow still a TMap')
149 copyMetadata(newass, mapping_regex[orig][0], input=h, algrefname=algrefname)
150 mapping_assessors_final[target] = (newass, newass.GetHistPath())
151 log.debug(f
'change {orig} to {target}')
155 for p, (a, _)
in mapping_assessors_final.items():
157 mapping_groups_final[os.path.dirname(p)].AddAssessor(a)
158 except Exception
as e:
159 log.error(f
'Unable to look up assessor parent directory. Full error follows\n{e}: path {p}, assessor {a}, assessor name {a.GetName()}')
162 for _, l2
in sorted(keydepths.items(), reverse=
True):
164 if log.level <= logging.DEBUG:
165 log.debug(f
'Final additions for {p}, {g.GetName()}, {g.GetPathName()} into {os.path.dirname(p)}')
168 mapping_groups_final[os.path.dirname(p)].AddGroup(g)
170 log.error(f
'Unable to attach group to parent. Details: group path {g.GetPathName()}, attempted parent is {os.path.dirname(p)}')
172 for v
in refmapcache.values():
174 if isinstance(v, ROOT.TMap):
177 return mapping_groups_final[
'top_level']