Skip to content

Commit 2e4aeea

Browse files
authored
Make dl_train.py self contained (alisw#1003)
1 parent cc0818d commit 2e4aeea

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

machine_learning_hep/utils/dl_train.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
#!/bin/env python3
22

3-
"""This script downloads AO2Ds from a hyperloop train"""
3+
"""This script downloads AO2Ds from an ALICE hyperloop train run"""
44

55
import argparse
66
import os
7-
import subprocess
7+
from pathlib import PurePosixPath
88
import sys
99

1010
import requests # pylint: disable=import-error
1111

12+
try:
13+
from alienpy import alien, xrd_core
14+
except ImportError:
15+
print("Failed to import alien -> no alien support")
16+
1217
if __name__ == "__main__":
1318
parser = argparse.ArgumentParser(description="Download AO2Ds from hyperloop train")
1419
parser.add_argument("train_id", type=int, help="train ID")
20+
parser.add_argument("--prefix", "-p", default="/data2/MLhep/trains/")
1521
parser.add_argument("--dry-run", "-n", action="store_true", help="dry run")
1622
args = parser.parse_args()
1723

@@ -29,13 +35,21 @@
2935
sys.exit(1)
3036
outputdirs = [d["outputdir"] for d in train_spec.json()["jobResults"]]
3137

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()
3441

3542
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)
4053
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

Comments
 (0)