Skip to content

Commit

Permalink
revert new progress bar, since no ROOT 6.30 for CS8 (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
harrypuuter committed Jan 24, 2024
1 parent 5b6cdfc commit cb66320
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion code_generation/analysis_template.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ROOT::RDF::RResultPtr<ROOT::RDF::RCutFlowReport>> cutReports;
Expand Down
2 changes: 1 addition & 1 deletion code_generation/analysis_template_friends.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
34 changes: 34 additions & 0 deletions code_generation/code_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<std::mutex> 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,
Expand Down

0 comments on commit cb66320

Please sign in to comment.