Skip to content

Commit 1f562c2

Browse files
committed
making plough compatible with postprocessing
1 parent 8c96007 commit 1f562c2

2 files changed

Lines changed: 38 additions & 38 deletions

File tree

src/pinefarm/cli/run.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,18 @@ def run_dataset(runner):
190190

191191
# collect results in the output pineappl grid
192192
runner.generate_pineappl()
193-
194-
table.print_table(
195-
table.convolute_grid(
196-
runner.grid, runner.pdf, integrated=isinstance(runner, mg5.Mg5)
197-
),
198-
runner.results(),
199-
runner.dest,
200-
)
201-
202-
# TODO: annotate_version should be a post-processing step
203-
# however at the moment only works in 1-grid cases
204-
runner.annotate_versions()
193+
if not hasattr(runner, "ps_link"):
194+
table.print_table(
195+
table.convolute_grid(
196+
runner.grid, runner.pdf, integrated=isinstance(runner, mg5.Mg5)
197+
),
198+
runner.results(),
199+
runner.dest,
200+
)
201+
202+
# TODO: annotate_version should be a post-processing step
203+
# however at the moment only works in 1-grid cases
204+
runner.annotate_versions()
205205

206206
runner.postprocess()
207207

src/pinefarm/external/plough.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import os
44
import shutil
5-
import subprocess
65
import tarfile
76
import urllib.request
87

@@ -13,7 +12,6 @@
1312
from . import interface
1413

1514
PLOUGHSHARE_LINK_FILENAME = "ploughshare_link.txt"
16-
GRIDS_PROCESSOR = "process_grids.sh"
1715
GRIDS_TMP = "grids"
1816

1917

@@ -28,19 +26,25 @@ def __init__(self, pinecard, theorycard, *args, **kwargs):
2826
self.filename = self.link.rsplit("/")[-1]
2927
self.dir_name = self.filename.rsplit(".", 1)[0]
3028
self.tarball = self.dest / self.filename
31-
self.processor = self.source / GRIDS_PROCESSOR
32-
self.run()
33-
self.generate_pineappl()
34-
self.timestamp = 0
3529

3630
def run(self):
3731
"""Download and extract the .tgz file."""
3832
print("Downloading from ploughshare...")
39-
self.download_to_dest()
33+
try:
34+
self.download_to_dest()
35+
if self.tarball.exists():
36+
print(f"Grids successfully downloaded to {self.tarball}")
37+
else:
38+
raise FileNotFoundError(
39+
f"{self.tarball} not found but the download didn't seem to fail?"
40+
)
41+
except Exception as e:
42+
raise FileNotFoundError(f"{self.tarball} could not be downloaded!") from e
4043
print(f"Grids successfully downloaded to {self.tarball}")
4144
print("Extracting files...")
4245
self.extract_tarball()
43-
print(f"Grids successfully extracted to {self.dir_name}")
46+
print(f"Grids successfully extracted to {self.dest}")
47+
self.cleanup()
4448

4549
def results(self):
4650
"""Results are collected and compared at the pineappl (script) level."""
@@ -51,30 +55,26 @@ def collect_versions(self):
5155
return {}
5256

5357
def generate_pineappl(self):
54-
"""Converts donwloaded grids into pineappl format."""
55-
print("Grid conversion started...")
56-
# the grids are converted and processed here
57-
os.environ["PS_DIR"] = str(self.grids_dir)
58-
# note that filename is also dir_name
59-
os.environ["FILENAME"] = str(self.dir_name)
60-
if os.access(self.processor, os.X_OK):
61-
shutil.copy2(self.processor, self.dest)
62-
subprocess.run("./process_grids.sh", cwd=self.dest, check=True)
63-
(self.dest / "process_grids.sh").unlink()
64-
else:
65-
raise ValueError(
66-
f"Grid conversion file present but not executable: {self.processor}"
67-
)
68-
self.grids = []
69-
for g in self.dest.glob("*.pineappl.lz4"):
70-
self.grids.append(g)
58+
"""Grids are converted in postrun.sh."""
59+
return
7160

7261
def download_to_dest(self):
73-
"""Download the file and move it to the output folder."""
62+
"""Download the file to the output folder."""
7463
urllib.request.urlretrieve(self.link, self.dest / self.filename)
7564

7665
def extract_tarball(self):
7766
"""Extract the contents."""
7867
with tarfile.open(self.tarball, "r:*") as tf:
7968
tf.extractall(self.dest)
8069
self.grids_dir = self.dest / self.dir_name / GRIDS_TMP
70+
grids_list = sorted(os.listdir(self.grids_dir))
71+
for i, grid in enumerate(grids_list):
72+
extension = grid.split(".", 2)[2]
73+
print(extension)
74+
os.rename(self.grids_dir / grid, self.dest / f"grid_{i}.{extension}")
75+
76+
def cleanup(self):
77+
"""Delete unnecessary files and create tmp.pineappl.lz4 to allow postprocessing."""
78+
shutil.rmtree(self.dest / self.dir_name)
79+
self.tarball.unlink()
80+
open(self.dest / "tmp.pineappl.lz4", "x")

0 commit comments

Comments
 (0)