Skip to content

Commit 83b4390

Browse files
authored
Merge pull request #54 from fact-project/submit_runlist
Submit runlist
2 parents 207238e + e64c69d commit 83b4390

4 files changed

Lines changed: 80 additions & 5 deletions

File tree

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ It sets up the necessary port forwarding and proxy to speak to the non-isdc worl
7070

7171
## Submit runs:
7272

73-
Fire up erna_console and enter:
73+
We provide a script `erna_submit_runlist` to submit a csv runlist into the
74+
automatic processing.
75+
76+
77+
Alternatively, you can use the erna_console and enter:
7478

7579
```python
7680
files = (
@@ -82,9 +86,9 @@ files = (
8286
print("files.count():", files.count())
8387

8488
# We only select Jar.id and Jar.version to not download the 20 MB binary blob
85-
jar = Jar.select(Jar.id, Jar.version).where(jar.version == '0.17.2').get()
89+
jar = Jar.select(Jar.id, Jar.version).where(Jar.version == '0.17.2').get()
8690
xml = XML.get(name='std_analysis', jar=jar)
8791
queue = Queue.get(name='fact_short')
8892

89-
insert_jobs(files, xml=xml, jar=jar, queue=queue)
93+
insert_new_jobs(files, xml=xml, jar=jar, queue=queue)
9094
```

erna/automatic_processing/database_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,13 @@ def insert_new_job(
181181
@requires_database_connection
182182
def insert_new_jobs(raw_data_files, jar, xml, queue, progress=True, **kwargs):
183183

184+
if isinstance(raw_data_files, list):
185+
total = len(raw_data_files)
186+
else:
187+
total = raw_data_files.count()
188+
184189
failed_files = []
185-
for f in tqdm(raw_data_files, total=raw_data_files.count(), disable=not progress):
190+
for f in tqdm(raw_data_files, total=total, disable=not progress):
186191
try:
187192
insert_new_job(f, jar=jar, xml=xml, queue=queue, **kwargs)
188193
except peewee.IntegrityError:

erna/scripts/submit_runlist.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import click
2+
import pandas as pd
3+
4+
from ..automatic_processing.database_utils import insert_new_jobs
5+
from ..utils import load_config
6+
from datetime import date
7+
8+
from ..automatic_processing.database import (
9+
database,
10+
RawDataFile,
11+
Jar,
12+
XML,
13+
Queue,
14+
Job,
15+
)
16+
17+
18+
@click.command()
19+
@click.argument('runlist')
20+
@click.argument('jar')
21+
@click.argument('xml')
22+
@click.option(
23+
'-p', '--priority', default=5, type=int,
24+
help='Priority of the jobs, lower value means more important'
25+
)
26+
@click.option(
27+
'-q', '--queue', default='fact_short',
28+
help='Name of the queue to use'
29+
)
30+
@click.option('--config', '-c', help='Path to the yaml config file')
31+
def main(runlist, jar, xml, priority, queue, config):
32+
'''
33+
Submit automatic processing jobs for a given runlist
34+
35+
Arguments
36+
37+
RUNLIST: csv file with columns `night, run_id`
38+
JAR: version of the fact-tools jar
39+
XML: Name of the xml file to use
40+
41+
Jar and XML must be uploaded to the processing db using erna_upload
42+
'''
43+
config = load_config(config)
44+
45+
database.init(**config['processing_database'])
46+
47+
jar = Jar.select(Jar.id, Jar.version).where(Jar.version == jar).get()
48+
xml = XML.get(name=xml, jar=jar)
49+
queue = Queue.get(name=queue)
50+
51+
runs = pd.read_csv(runlist)
52+
runs['year'] = runs['night'] // 10000
53+
runs['month'] = ((runs['night'] % 10000) // 100)
54+
runs['day'] = (runs['night'] % 100)
55+
56+
files = [
57+
RawDataFile.get(night=date(row.year, row.month, row.day), run_id=row.run_id)
58+
for row in runs.itertuples()
59+
]
60+
61+
insert_new_jobs(files, xml=xml, jar=jar, queue=queue)
62+
63+
64+
if __name__ == '__main__':
65+
main()

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='erna',
5-
version='0.6.0',
5+
version='0.7.0',
66
description='Easy RuN Access. Tools that help to do batch processing of FACT data',
77
url='https://github.com/fact-project/erna',
88
author='Kai Brügge, Jens Buss, Maximilian Nöthe',
@@ -60,6 +60,7 @@
6060
'erna_automatic_processing_executor = erna.automatic_processing.executor:main',
6161
'erna_automatic_processing = erna.automatic_processing.__main__:main',
6262
'erna_gather_fits = erna.scripts.gather_fits:main',
63+
'erna_submit_runlist = erna.scripts.submit_runlist:main',
6364
],
6465
},
6566
setup_requires=['pytest-runner'],

0 commit comments

Comments
 (0)