Go to the documentation of this file.00001 """ Snapkeys are abbreviations that can be used to identify a snap. Snaps do
00002 not have a single unique attribute, which makes them difficult to identify.
00003 Snapkeys solve that problem.
00004
00005 Snapkeys have 3 parts:
00006 block index (int)
00007 container indicator ('e' for emitter or 'c' for collector)
00008 snap order
00009
00010 Example:
00011 snapkey 3e1 means the snap in block index 3's emitter with order 1
00012 """
00013 import re
00014 def parse_snapkey(snapkey):
00015 """ Parses a snapkey into a 3-tuple """
00016 m = re.findall("(^\d+)([ce])(\d+$)",snapkey)
00017 if len(m) == 0:
00018 raise Exception("Invalid snapkey %s"%snapkey)
00019 container_name = "emitter" if m[0][1] == 'e' else "collector" if m[0][1] == 'c' else None
00020 return (int(m[0][0]), container_name, int(m[0][2]))
00021
00022 def gen_snapkey(block_index, container, snap_order):
00023 """ generate a snapkey """
00024 assert(container in ["emitter","collector"])
00025 return "%d%s%d"%(block_index,container[0],snap_order)