Skip to content

Commit

Permalink
chore: change progress bar for add histograms (#101)
Browse files Browse the repository at this point in the history
* Small fixes for the linter and drop_branches

* More little fixes

* linter fix

* linter

* changed hadd progress bar

* formatting
  • Loading branch information
zbilodea authored Jul 2, 2024
1 parent 06ee606 commit 8e4f1df
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/hepconvert/histogram_adding.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,11 @@ def add_histograms(
keys = file.keys(filter_classname="TH[1|2|3][I|S|F|D|C]", cycle=False)
if progress_bar is not False:
tqdm = _utils.check_tqdm()
file_bar = progress_bar
hist_bar = tqdm.tqdm(desc="Histograms added")
number_of_items = len(files)
if progress_bar is True:
file_bar = tqdm.tqdm(desc="Files added")
hist_bar = tqdm.tqdm(desc="Histograms added")
else:
hist_bar = None
file_bar.reset(number_of_items)
file_bar = tqdm.tqdm(desc="Files summed")
file_bar.reset(number_of_items)

if same_names:
if union:
for i, _value in enumerate(files[1:]):
Expand Down Expand Up @@ -491,8 +487,6 @@ def add_histograms(
msg = f"File: {input_file} does not exist or is corrupt."
raise FileNotFoundError(msg) from None
if same_names:
if progress_bar and hist_bar:
hist_bar.reset(len(keys))
for key in keys:
try:
in_file[key]
Expand All @@ -510,15 +504,10 @@ def add_histograms(
else:
h_sum = _hadd_3d(hists, in_file, key, first)

if progress_bar:
hist_bar.update(n=1)

if h_sum is not None:
hists[key] = h_sum
else:
n_keys = in_file.keys(filter_classname="TH[1|2|3][I|S|F|D|C]", cycle=False)
if progress_bar:
hist_bar.reset(len(n_keys))
for i, _value in enumerate(keys):
if len(in_file[n_keys[i]].axes) == 1:
h_sum = _hadd_1d(out_file, in_file, keys[i], first, n_key=n_keys[i])
Expand All @@ -531,8 +520,6 @@ def add_histograms(

if h_sum is not None:
out_file[keys[i]] = h_sum
if progress_bar:
hist_bar.update(n=1)
if progress_bar:
file_bar.update(n=1)

Expand Down

0 comments on commit 8e4f1df

Please sign in to comment.