|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -#!/usr/bin/env python3 |
4 | | - |
5 | 3 | # Copyright 2019-2025 CERN and copyright holders of ALICE O2. |
6 | 4 | # See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
7 | 5 | # All rights not expressly granted are reserved. |
@@ -37,50 +35,84 @@ def parse_bin_label(label): |
37 | 35 | return result |
38 | 36 |
|
39 | 37 |
|
| 38 | +def format_value_with_comment(b): |
| 39 | + """Return Value plus optional (comment=...) suffix.""" |
| 40 | + val = b.get("Value", "") |
| 41 | + comment = b.get("Comment", "") |
| 42 | + if comment and comment.upper() != "X": |
| 43 | + return f"{val} (comment={comment})" |
| 44 | + return val |
| 45 | + |
| 46 | + |
40 | 47 | def ask_user_selection(group): |
41 | | - """Prompt user to select bin(s) for this selection group.""" |
| 48 | + """ |
| 49 | + Prompt user to select bin(s) for this selection group. |
| 50 | + - If minimal selections contain exactly 1 entry → auto-select it. |
| 51 | + - Optional selections remain user-selectable. |
| 52 | + """ |
| 53 | + selection_name = group[0].get("SelectionName", "unknown") |
| 54 | + |
42 | 55 | # Separate minimal and optional bins |
43 | 56 | minimal_bins = [b for b in group if b.get("MinimalCut", "0") == "1" and b.get("OptionalCut", "0") == "0"] |
44 | 57 | optional_bins = [b for b in group if b.get("OptionalCut", "0") == "1"] |
45 | 58 |
|
46 | 59 | selected_bins = [] |
47 | 60 |
|
48 | | - # Minimal selection (cannot skip, 0 = loosest minimal) |
| 61 | + # ----- Minimal selection ----- |
49 | 62 | if minimal_bins: |
50 | | - print(f"\nSelection: {group[0].get('SelectionName', 'unknown')}") |
51 | | - for idx, b in enumerate(minimal_bins): |
52 | | - print(f" [{idx}] {b.get('Value', '')}") |
53 | | - while True: |
54 | | - sel_input = input("Enter index for minimal cut (0 = loosest minimal): ") |
55 | | - if sel_input.strip() == "": |
56 | | - sel_input = "0" |
57 | | - try: |
58 | | - sel_idx = int(sel_input) |
59 | | - if 0 <= sel_idx < len(minimal_bins): |
60 | | - selected_bins.append(minimal_bins[sel_idx]) |
61 | | - break |
62 | | - except ValueError: |
63 | | - pass |
64 | | - print("Invalid input. Please enter a valid index.") |
65 | | - |
66 | | - # Optional selection (can skip with 0) |
| 63 | + if len(minimal_bins) == 1: |
| 64 | + only = minimal_bins[0] |
| 65 | + print( |
| 66 | + f"\nSelection: {selection_name} — only one minimal option → auto-selecting: " |
| 67 | + f"{format_value_with_comment(only)}" |
| 68 | + ) |
| 69 | + selected_bins.append(only) |
| 70 | + else: |
| 71 | + print(f"\nSelection: {selection_name}") |
| 72 | + for idx, b in enumerate(minimal_bins): |
| 73 | + print(f" [{idx}] {format_value_with_comment(b)}") |
| 74 | + while True: |
| 75 | + sel_input = input("Enter index for minimal cut (0 = loosest minimal): ") |
| 76 | + if sel_input.strip() == "": |
| 77 | + sel_input = "0" |
| 78 | + try: |
| 79 | + sel_idx = int(sel_input) |
| 80 | + if 0 <= sel_idx < len(minimal_bins): |
| 81 | + choice = minimal_bins[sel_idx] |
| 82 | + selected_bins.append(choice) |
| 83 | + print(f"Selected: {format_value_with_comment(choice)}") |
| 84 | + break |
| 85 | + except ValueError: |
| 86 | + pass |
| 87 | + print("Invalid input. Please enter a valid index.") |
| 88 | + |
| 89 | + # ----- Optional selection ----- |
67 | 90 | if optional_bins: |
68 | | - print(f"Selection: {group[0].get('SelectionName', 'unknown')} (optional selection, 0 to skip)") |
| 91 | + print(f"\nSelection: {selection_name} (optional selection, 0 to skip)") |
69 | 92 | for idx, b in enumerate(optional_bins, start=1): |
70 | | - print(f" [{idx}] {b.get('Value', '')}") |
| 93 | + print(f" [{idx}] {format_value_with_comment(b)}") |
| 94 | + |
71 | 95 | while True: |
72 | 96 | sel_input = input("Enter indices separated by space (0 to skip): ") |
73 | 97 | if not sel_input.strip() or sel_input.strip() == "0": |
| 98 | + print("Selected: (skipped)") |
74 | 99 | break |
| 100 | + |
75 | 101 | try: |
76 | 102 | indices = [int(x) for x in sel_input.split()] |
77 | 103 | if all(0 <= i <= len(optional_bins) for i in indices): |
| 104 | + chosen = [] |
78 | 105 | for i in indices: |
79 | 106 | if i != 0: |
80 | | - selected_bins.append(optional_bins[i - 1]) |
| 107 | + b = optional_bins[i - 1] |
| 108 | + selected_bins.append(b) |
| 109 | + chosen.append(format_value_with_comment(b)) |
| 110 | + |
| 111 | + print("Selected: " + ", ".join(chosen)) |
81 | 112 | break |
82 | 113 | except ValueError: |
83 | 114 | pass |
| 115 | + |
84 | 116 | print("Invalid input. Please enter valid indices separated by space.") |
85 | 117 |
|
86 | 118 | return selected_bins |
@@ -145,10 +177,22 @@ def main(rootfile_path, tdir_path="femto-producer"): |
145 | 177 | continue |
146 | 178 | bitmask |= 1 << int(pos) |
147 | 179 |
|
| 180 | + print("\n=======================================") |
| 181 | + print("Summary of your selections:") |
| 182 | + print("=======================================\n") |
| 183 | + |
| 184 | + summary = {} |
| 185 | + for b in selected_bins: |
| 186 | + sel = b.get("SelectionName", "unknown") |
| 187 | + summary.setdefault(sel, []).append(format_value_with_comment(b)) |
| 188 | + |
| 189 | + for sel, values in summary.items(): |
| 190 | + print(f" {sel}: {', '.join(values)}") |
| 191 | + |
148 | 192 | print("\nFinal selected bitmask:") |
149 | | - print(f"Decimal: {bitmask}") |
150 | | - print(f"Binary: {bin(bitmask)}") |
151 | | - print(f"Hex: {hex(bitmask)}") |
| 193 | + print(f" Decimal: {bitmask}") |
| 194 | + print(f" Binary: {bin(bitmask)}") |
| 195 | + print(f" Hex: {hex(bitmask)}") |
152 | 196 |
|
153 | 197 |
|
154 | 198 | if __name__ == "__main__": |
|
0 commit comments