|
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. |
@@ -38,34 +36,47 @@ def parse_bin_label(label): |
38 | 36 |
|
39 | 37 |
|
40 | 38 | def ask_user_selection(group): |
41 | | - """Prompt user to select bin(s) for this selection group.""" |
| 39 | + """ |
| 40 | + Prompt user to select bin(s) for this selection group. |
| 41 | + - If minimal selections contain exactly 1 entry → auto-select it. |
| 42 | + - Optional selections remain user-selectable. |
| 43 | + """ |
| 44 | + selection_name = group[0].get("SelectionName", "unknown") |
| 45 | + |
42 | 46 | # Separate minimal and optional bins |
43 | 47 | minimal_bins = [b for b in group if b.get("MinimalCut", "0") == "1" and b.get("OptionalCut", "0") == "0"] |
44 | 48 | optional_bins = [b for b in group if b.get("OptionalCut", "0") == "1"] |
45 | 49 |
|
46 | 50 | selected_bins = [] |
47 | 51 |
|
48 | | - # Minimal selection (cannot skip, 0 = loosest minimal) |
| 52 | + # Minimal selection |
49 | 53 | 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.") |
| 54 | + if len(minimal_bins) == 1: |
| 55 | + # autoselect minimal OPTION |
| 56 | + only = minimal_bins[0] |
| 57 | + print(f"\nSelection: {selection_name} — only one minimal option → auto-selecting: {only.get('Value','')}") |
| 58 | + selected_bins.append(only) |
| 59 | + else: |
| 60 | + # Multiple → ask user |
| 61 | + print(f"\nSelection: {selection_name}") |
| 62 | + for idx, b in enumerate(minimal_bins): |
| 63 | + print(f" [{idx}] {b.get('Value', '')}") |
| 64 | + while True: |
| 65 | + sel_input = input("Enter index for minimal cut (0 = loosest minimal): ") |
| 66 | + if sel_input.strip() == "": |
| 67 | + sel_input = "0" |
| 68 | + try: |
| 69 | + sel_idx = int(sel_input) |
| 70 | + if 0 <= sel_idx < len(minimal_bins): |
| 71 | + selected_bins.append(minimal_bins[sel_idx]) |
| 72 | + break |
| 73 | + except ValueError: |
| 74 | + pass |
| 75 | + print("Invalid input. Please enter a valid index.") |
65 | 76 |
|
66 | 77 | # Optional selection (can skip with 0) |
67 | 78 | if optional_bins: |
68 | | - print(f"Selection: {group[0].get('SelectionName', 'unknown')} (optional selection, 0 to skip)") |
| 79 | + print(f"Selection: {selection_name} (optional selection, 0 to skip)") |
69 | 80 | for idx, b in enumerate(optional_bins, start=1): |
70 | 81 | print(f" [{idx}] {b.get('Value', '')}") |
71 | 82 | while True: |
@@ -145,10 +156,22 @@ def main(rootfile_path, tdir_path="femto-producer"): |
145 | 156 | continue |
146 | 157 | bitmask |= 1 << int(pos) |
147 | 158 |
|
| 159 | + print("\n=======================================") |
| 160 | + print("Summary of your selections:") |
| 161 | + print("=======================================\n") |
| 162 | + |
| 163 | + summary = {} |
| 164 | + for b in selected_bins: |
| 165 | + sel = b.get("SelectionName", "unknown") |
| 166 | + summary.setdefault(sel, []).append(b.get("Value", "")) |
| 167 | + |
| 168 | + for sel, values in summary.items(): |
| 169 | + print(f" {sel}: {', '.join(values)}") |
| 170 | + |
148 | 171 | print("\nFinal selected bitmask:") |
149 | | - print(f"Decimal: {bitmask}") |
150 | | - print(f"Binary: {bin(bitmask)}") |
151 | | - print(f"Hex: {hex(bitmask)}") |
| 172 | + print(f" Decimal: {bitmask}") |
| 173 | + print(f" Binary: {bin(bitmask)}") |
| 174 | + print(f" Hex: {hex(bitmask)}") |
152 | 175 |
|
153 | 176 |
|
154 | 177 | if __name__ == "__main__": |
|
0 commit comments