|
1 | 1 | #!/bin/env python3 |
2 | 2 |
|
3 | | -"""This script downloads AO2Ds from a hyperloop train""" |
| 3 | +"""This script downloads AO2Ds from an ALICE hyperloop train run""" |
4 | 4 |
|
5 | 5 | import argparse |
6 | 6 | import os |
7 | | -import subprocess |
| 7 | +from pathlib import PurePosixPath |
8 | 8 | import sys |
9 | 9 |
|
10 | 10 | import requests # pylint: disable=import-error |
11 | 11 |
|
| 12 | +try: |
| 13 | + from alienpy import alien, xrd_core |
| 14 | +except ImportError: |
| 15 | + print("Failed to import alien -> no alien support") |
| 16 | + |
12 | 17 | if __name__ == "__main__": |
13 | 18 | parser = argparse.ArgumentParser(description="Download AO2Ds from hyperloop train") |
14 | 19 | parser.add_argument("train_id", type=int, help="train ID") |
| 20 | + parser.add_argument("--prefix", "-p", default="/data2/MLhep/trains/") |
15 | 21 | parser.add_argument("--dry-run", "-n", action="store_true", help="dry run") |
16 | 22 | args = parser.parse_args() |
17 | 23 |
|
|
29 | 35 | sys.exit(1) |
30 | 36 | outputdirs = [d["outputdir"] for d in train_spec.json()["jobResults"]] |
31 | 37 |
|
32 | | - TBASE = f"/data2/MLhep/trains/{args.train_id}" |
33 | | - SCRIPT = "/home/jklein/alisw.bak/Run3Analysisvalidation/exec/download_from_grid.sh" |
| 38 | + TBASE = PurePosixPath(args.prefix) / str(args.train_id) |
| 39 | + |
| 40 | + a = alien.AliEn() |
34 | 41 |
|
35 | 42 | for outputdir in outputdirs: |
36 | | - PATH = f"{outputdir}/AOD" |
37 | | - CMD = f"{SCRIPT} {PATH} {TBASE}/{PATH} AO2D.root" |
38 | | - if args.dry_run: |
39 | | - print(f"Dry run: {CMD}") |
| 43 | + PATH = PurePosixPath(f"{outputdir}") / "AOD" |
| 44 | + CMD_FIND = f"find {PATH} AO2D.root" |
| 45 | + ret = a.run(CMD_FIND) |
| 46 | + if ret.exitcode == 0: |
| 47 | + SRC = ret.out.split() |
| 48 | + DST = ["file:" + str(PurePosixPath(TBASE) / file.lstrip("/")) for file in SRC] |
| 49 | + for s, d in zip(SRC, DST): |
| 50 | + print(f"Copying {s} to {d}") |
| 51 | + if not args.dry_run: |
| 52 | + xrd_core.DO_XrootdCp(a.wb(), api_src=SRC, api_dst=DST) |
40 | 53 | else: |
41 | | - subprocess.run(CMD, shell=True, check=False, stdout=sys.stdout, stderr=sys.stderr) |
| 54 | + print(f"Failed to run search: {CMD_FIND}\n{ret.out}") |
| 55 | + continue |
0 commit comments