Skip to content

Commit

Permalink
changed hadd progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
zbilodea committed Jul 2, 2024
1 parent 2630830 commit 97ef13c
Show file tree
Hide file tree
Showing 2 changed files with 11 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
8 changes: 8 additions & 0 deletions tests/test_add_histograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def test_simple(tmp_path):
).all


def test_glob(tmp_path):
hepconvert.add_histograms(
os.path.join(tmp_path, "dest.root"),
"tests/samples/hists", progress_bar=True
)

test_glob("tests/samples/")

def mult_1D(tmp_path, file_paths):
gauss_1 = ROOT.TH1I("name1", "title", 5, -4, 4)
gauss_1.FillRandom("gaus")
Expand Down

0 comments on commit 97ef13c

Please sign in to comment.