diff --git a/code_generation/analysis_template.cxx b/code_generation/analysis_template.cxx index 51953df3..1c4a5c80 100644 --- a/code_generation/analysis_template.cxx +++ b/code_generation/analysis_template.cxx @@ -107,7 +107,7 @@ int main(int argc, char *argv[]) { // initialize df ROOT::RDataFrame df0(basetree, input_files); - ROOT::RDF::Experimental::AddProgressBar(df0); + // ROOT::RDF::Experimental::AddProgressBar(df0); ROOT 6.30 not available for CS8 on lcg Logger::get("main")->info("Starting Setup of Dataframe with {} events", nevents); std::vector> cutReports; diff --git a/code_generation/analysis_template_friends.cxx b/code_generation/analysis_template_friends.cxx index 03ae7ff5..160774c4 100644 --- a/code_generation/analysis_template_friends.cxx +++ b/code_generation/analysis_template_friends.cxx @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) { } // initialize df ROOT::RDataFrame df0(dataset); - ROOT::RDF::Experimental::AddProgressBar(df0); + // ROOT::RDF::Experimental::AddProgressBar(df0); ROOT 6.30 not available for CS8 on lcg // print all available branches to the log Logger::get("main")->debug("Available branches:"); for (auto const &branch : df0.GetColumnNames()) { diff --git a/code_generation/code_generation.py b/code_generation/code_generation.py index 50ae5f6c..3672265d 100644 --- a/code_generation/code_generation.py +++ b/code_generation/code_generation.py @@ -347,6 +347,7 @@ def write_code(self, calls: str, includes: str, run_commands: str) -> None: ) .replace("{ANALYSISTAG}", '"Analysis={}"'.format(self.analysis_name)) .replace("{CONFIGTAG}", '"Config={}"'.format(self.config_name)) + .replace("{PROGRESS_CALLBACK}", self.set_process_tracking()) .replace("{OUTPUT_QUANTITIES}", self.set_output_quantities()) .replace("{SHIFT_QUANTITIES_MAP}", self.set_shift_quantities_map()) .replace("{QUANTITIES_SHIFT_MAP}", self.set_quantities_shift_map()) @@ -547,6 +548,8 @@ def generate_run_commands(self) -> str: outputname=self._outputfiles_generated[scope], outputstring=outputstring, ) + # add code for tracking the progress + runcommands += self.set_process_tracking() # add code for the time taken for the dataframe setup runcommands += self.set_setup_printout() # add trigger of dataframe execution, for nonempty scopes @@ -681,6 +684,37 @@ def zero_events_fallback(self) -> str: return printout + def set_process_tracking(self) -> str: + """This function replaces the template placeholder for the process tracking with the correct process tracking. + + Returns: + The code to be added to the template + """ + tracking = "" + scope = self.scopes[-1] + tracking += " ULong64_t {scope}_processed = 0;\n".format(scope=scope) + tracking += " std::mutex {scope}_bar_mutex;\n".format(scope=scope) + tracking += " auto c_{scope} = df{counter}_{scope}.Count();\n".format( + counter=self.main_counter[scope], scope=scope + ) + tracking += " c_{scope}.OnPartialResultSlot(quantile, [&{scope}_bar_mutex, &{scope}_processed, &quantile, &nevents](unsigned int /*slot*/, ULong64_t /*_c*/) {{".format( + scope=scope + ) + tracking += ( + "\n std::lock_guard lg({scope}_bar_mutex);\n".format( + scope=scope + ) + ) + tracking += " {scope}_processed += quantile;\n".format(scope=scope) + tracking += " float percentage = 100 * (float){scope}_processed / (float)nevents;\n".format( + scope=scope + ) + tracking += ' Logger::get("main")->info("{{0:d}} / {{1:d}} ({{2:.2f}} %) Events processed ...", {scope}_processed, nevents, percentage);\n'.format( + scope=scope + ) + tracking += " });\n" + return tracking + def set_shift_quantities_map(self) -> str: """ This function is used to generate a mapping of all quantities and the shifts,