docs: def _finalize_hierarchy(self):
          """ This function finalizes the execution of a hierarchy state. It sets the correct status and manages
          the output data handling.
          :return:
          """
          if self.last_child:
              self.last_child.state_execution_status = StateExecutionStatus.INACTIVE
  
          if not self.backward_execution:
              if self.last_error:
                  self.output_data['error'] = copy.deepcopy(self.last_error)
              self.write_output_data()
              self.check_output_data_type()
              self.execution_history.push_return_history_item(self, CallType.CONTAINER, self, self.output_data)
              # add error message from child_state to own output_data
  
          self.state_execution_status = StateExecutionStatus.WAIT_FOR_NEXT_STATE
  
          if self.preempted:
              self.final_outcome = Outcome(-2, "preempted")
  
          self.child_state = None
          self.last_child = None
  
          return self.finalize(self.final_outcome)