def compute_reportingsets_for_tabreportdef(self, tabreport_def: TabReportDef):
        """Augment the definition of a table report with calculated ReportingSets."""
        start_time = datetime.datetime.now()
        tabdef_count = len(tabreport_def)
        tabreport_def.fill_contents_inert()
        tabdef_counter = 0
        for tabdef_name in tabreport_def.tabdef_order:
            tabdef = tabreport_def[tabdef_name]
            tabdef_counter += 1
            rs = None
            if self._caching_enabled and self._caching_mode in ('r', 'rw'):
                rs_dump = "{}/rs_{}.rsd".format(self._cache_directory, tabdef_name)
                try:
                    with open(rs_dump, 'rb') as f:
                        rs = pickle.load(f)
                    logging.info("\t\t{} has been loaded.\t\t{}/{}".format(tabdef_name,
                                                                           tabdef_counter,
                                                                           tabdef_count))
                except FileNotFoundError:
                    logging.info("\t\t{} not found in cache.".format(tabdef_name))

            if not rs:
                logging.info("\t\t{} is being calculated.\t\t{}/{}, \t\truntime: {} ".format(tabdef_name,
                                                                                             tabdef_counter,
                                                                                             tabdef_count,
                                                                                             str(datetime.datetime.now() - start_time)))
                import time
                time.sleep(1)
                if tabdef.table_head:
                    self.result_subsplits = []      # TODO warum self, warum nicht local
                    for head in tabdef.table_head:
                        if isinstance(head, TabHead):
                            for subhead in head:
                                self.result_subsplits.append(subhead)
                        elif isinstance(head, CodePlan):
                            self.result_subsplits.append(head)
                        else:
                            raise TypeError('Only TabHead or CodePlan allowed as a table head. Found: ', type(head))
                if tabdef.database_table:
                    self.database_table = tabdef.database_table
                else:
                    raise Exception("No database_table in TabDef defined!")
                if tabdef.aggr_variables:
                    self.variables_calculation_avg = tabdef.aggr_variables[0]  # unclear?
                rs = self.build_rs_frequs(variables_calculation=tabdef.variables, variables_calculation_avg=self.variables_calculation_avg)
                if tabdef.split_main:
                    rs.split_main = tabdef.split_main
                    rs.split_main.variables = tabdef.variables
                if tabdef.title:
                    rs.title = tabdef.title
                if tabdef.title_sub:
                    rs.content_misc['subTitle'] = tabdef.title_sub
                if self._caching_enabled and self._caching_mode in ('w', 'rw'):
                    f = open("{}/rs_{}.rsd".format(self._cache_directory, tabdef_name), 'wb')
                    pickle.dump(rs, f)
                    f.close()
            tabdef.reportingset = rs
        self.log_info("Tabreport calculated. Duration: {}".format(str(datetime.datetime.now() - start_time)))
    def export_tabreport(self, tabreport: TabReportDef, output_name: str = 'tabband', testmode: bool = False):
        """
        :param tabreport:
        :param output_name:
        :param testmode:
        :return:
        """
        tabreport.fill_contents_inert()
        tex = r"""
\begin{{document}}
\makebox(600,300)[l]{{}}\\
\Large{{{preTitle}}}\\
\\
\Huge{{{title}}}
\\
\\
\normalsize
{subTitle}
\listoftables
\newpage
\clearpage
\ofoot{{\pagemark}}
\ifoot{{{footer}}}
""".format(preTitle=self._convert_symbols2tex(tabreport.title_pre)  # XXX funktionen auslagern
           , title=self._convert_symbols2tex(tabreport.title)
           , subTitle=self._convert_symbols2tex(tabreport.title_sub)
           , footer=self._convert_symbols2tex(tabreport.footer))
        for tabdef_name in tabreport.tabdef_order:
            tabdef = tabreport[tabdef_name]
            if tabdef.filter_rs:
                if tabdef.filter_rs and isinstance(tabdef.filter_rs, str):
                    tabdef.reportingset.content_misc['filterText'] = tabdef.filter_rs
                else:
                    raise Exception('WTF')  # TODO ausbessern
                tabdef.reportingset.content_misc['filterText'] = tabdef.filter_rs  # .label
            if tabdef.section:
                tabdef.reportingset.content_misc['section'] = tabdef.section
            if tabdef.reporting_columns:
                self.columns_reporting = tabdef.reportingColumns
            if tabdef.reportingset:
                if tabdef.table_head:
                    for head in tabdef.table_head:
                        if self.enable_headSplitting is not True:
                            if isinstance(head, CodePlan) or (isinstance(head, TabHead) and head.is_subhead):
                                tex += self._build_table_tex(tabdef.reportingset, head)
                            else:
                                print(type(head))  # TODO ausbessern
                                raise Exception("WTF")
                        else:
                            head_new = self.split_head(head, len(self.columns_reporting))
                            for subhead in head_new:  # # neue list comp
                                if type(subhead) == TabHead:
                                    tex += ''.join(
                                        [self._build_table_tex(tabdef.reportingset, subSubhead) for subSubhead in
                                         subhead])
                                elif type(subhead) == CodePlan:
                                    tex += self._build_table_tex(tabdef.reportingset, head)
                                else:
                                    print(subhead)
                                    print(type(subhead))  # TODO ausbessern
                                    raise Exception('WTF')
                else:
                    tex += self._build_table_tex(tabdef.reportingset)
                    # Test fuer trennseite:
                    #            tex += r"""
                    # \newpage
                    # \clearpage
                    # \makebox(600,300)[l]{}\\
                    # #\Huge{Trennseite}
                    # \\
                    # \\
                    # \normalsize """
        tex += """
\end{document}"""
        if not testmode:
            self.tex_table(tex, output_name)