def root_frame(self, trim_stem=True):
root_frame = None<EOL>frame_stack = []<EOL>for frame_tuple in self.frame_records:<EOL><INDENT>identifier_stack = frame_tuple[<NUM_LIT:0>]<EOL>time = frame_tuple[<NUM_LIT:1>]<EOL>for stack_depth, frame_identifier in enumerate(identifier_stack):<EOL><INDENT>if stack_depth < len(frame_stack):<EOL><INDENT>if frame_identifier != frame_stack[stack_depth].identifier:<EOL><INDENT>del frame_stack[stack_depth:]<EOL><DEDENT><DEDENT>if stack_depth >= len(frame_stack):<EOL><INDENT>frame = Frame(frame_identifier)<EOL>frame_stack.append(frame)<EOL>if stack_depth == <NUM_LIT:0>:<EOL><INDENT>assert root_frame is None, ASSERTION_MESSAGE<EOL>root_frame = frame<EOL><DEDENT>else:<EOL><INDENT>parent = frame_stack[stack_depth-<NUM_LIT:1>]<EOL>parent.add_child(frame)<EOL><DEDENT><DEDENT><DEDENT>del frame_stack[stack_depth+<NUM_LIT:1>:]  <EOL>frame_stack[-<NUM_LIT:1>].add_child(SelfTimeFrame(self_time=time))<EOL><DEDENT>if root_frame is None:<EOL><INDENT>return None<EOL><DEDENT>if trim_stem:<EOL><INDENT>root_frame = self._trim_stem(root_frame)<EOL><DEDENT>return root_frame<EOL>
Parses the internal frame records and returns a tree of Frame objects