Skip to content

Commit f4c720c

Browse files
committed
Update dl_train
1 parent ca2baa7 commit f4c720c

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

machine_learning_hep/utils/dl_train.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
def get_train_spec(train_id: int):
1818
"""Retrieve train spec from hyperloop interface"""
1919
# https://alimonitor.cern.ch/hyperloop/train-run/131050
20-
URL = f"https://alimonitor.cern.ch/alihyperloop-data/trains/train.jsp?train_id={args.train_id}"
20+
url = f"https://alimonitor.cern.ch/alihyperloop-data/trains/train.jsp?train_id={train_id}"
2121
try:
2222
return requests.get(
23-
URL,
23+
url,
2424
verify=False,
2525
cert=(f"/tmp/tokencert_{os.getuid()}.pem", f"/tmp/tokenkey_{os.getuid()}.pem"),
2626
timeout=10,
@@ -30,31 +30,41 @@ def get_train_spec(train_id: int):
3030
raise
3131

3232

33-
def find_ao2ds(a: alien.AliEn, dir: str) -> list[str]:
33+
def find_ao2ds(ali: alien.AliEn, aliendir: str) -> list[str]:
3434
"""Find AO2Ds in train output directory"""
35-
CMD_FIND = f"find {PurePosixPath(dir) / 'AOD'} AO2D.root"
36-
ret = a.run(CMD_FIND)
37-
if ret.exitcode == 0:
38-
return ret.out.split()
39-
else:
40-
print(f"Failed to run search: {CMD_FIND}\n{ret.out}")
35+
cmd_find = f"find {PurePosixPath(aliendir) / 'AOD'} AO2D.root"
36+
print(cmd_find)
37+
ret = ali.run(cmd_find)
38+
if ret.exitcode != 0:
39+
print(f"Failed to run search: {cmd_find}\n{ret.out}")
4140
return []
41+
return ret.out.split()
4242

4343

44-
if __name__ == "__main__":
44+
def main():
45+
"""CLI interface"""
4546
parser = argparse.ArgumentParser(description="Download AO2Ds from hyperloop train")
4647
parser.add_argument("train_id", type=int, help="train ID")
4748
parser.add_argument("--prefix", "-p", default="/data2/MLhep/trains/")
4849
parser.add_argument("--dry-run", "-n", action="store_true", help="dry run")
4950
args = parser.parse_args()
5051

52+
print("Obtaining train spec ..")
5153
train_spec = get_train_spec(args.train_id)
5254
outputdirs = [d["outputdir"] for d in train_spec.json()["jobResults"]]
5355

56+
print("Finding AO2Ds ..")
5457
a = alien.AliEn()
55-
SRC = [dir for outputdir in outputdirs for dir in find_ao2ds(a, outputdir)]
56-
DST = ["file:" + str(PurePosixPath(args.prefix) / str(args.train_id) / file.lstrip("/")) for file in SRC]
57-
for s, d in zip(SRC, DST):
58-
print(f"Copying {s} to {d}")
58+
src = [d for outputdir in outputdirs for d in find_ao2ds(a, outputdir)]
59+
dst = ["file:" + str(PurePosixPath(args.prefix) / str(args.train_id) / file.lstrip("/")) for file in src]
60+
print("Files to copy:")
61+
for s, d in zip(src, dst):
62+
print(f"{s} -> {d}")
63+
5964
if not args.dry_run:
60-
xrd_core.DO_XrootdCp(a.wb(), api_src=SRC, api_dst=DST)
65+
print("Copying ..")
66+
xrd_core.DO_XrootdCp(a.wb(), api_src=src, api_dst=dst)
67+
68+
69+
if __name__ == "__main__":
70+
main()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,4 @@ Repository = "https://github.com/alisw/MachineLearningHEP"
8989

9090
[project.scripts]
9191
mlhep = "machine_learning_hep.steer_analysis:main"
92+
dl_train = "machine_learning_hep.utils.dl_train:main"

0 commit comments

Comments
 (0)