|
| 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() |
0 commit comments