Пример #1
0
    def __init__(self, task_id, input_info):
        '''Class to handle the execution of the preprocessing job.

        Args:
            task_id (int): Current task ID.
            input_info (str/path): Path to the database configuration file.

        Raises:
            FileNotFoundError: If required input file is not found in database.
        '''
        self._logger = utils.condor_logger('preprocess')
        self._dest_path = Path('results', str(task_id))
        self._dest_path.mkdir(parents=True, exist_ok=True)

        self.task_id = task_id
        # read database config
        cf = configparser.ConfigParser()
        cf.optionxform = str
        cf.read(input_info)
        self.cf = cf
        self.db = SixDB(cf['db_info'].items())
        db_type = cf['db_info']['db_type']
        self.db_type = db_type.lower()

        mask_keys = list(cf['mask'].keys())
        outputs = self.db.select('preprocess_wu',
                                 mask_keys,
                                 where=f'task_id={self.task_id}')

        if not outputs[0]:
            content = "Data not found for preprocess task %s!" % task_id
            raise FileNotFoundError(content)

        self.madx_cfg = cf['madx']
        self.mask_cfg = dict(zip(mask_keys, outputs[0]))
        self._decomp_templates()

        output_files = self.madx_cfg["output_files"]
        output_files = json.loads(output_files)
        self.madx_out = output_files

        self.oneturn_flag = self.madx_cfg.getboolean('oneturn')
        self.coll_flag = self.madx_cfg.getboolean('collimation')

        if self.oneturn_flag:
            self.six_cfg = cf['sixtrack']
            self.fort_cfg = cf['fort3']
        else:
            self.six_cfg = {}
            self.fort_cfg = {}
        if self.coll_flag:
            self.coll_cfg = cf['collimation']
        else:
            self.coll_cfg = {}
        # close db to avoid unexpected timeouts
        self.db.close()
Пример #2
0
            self.sixtrack_prep_job(fort_dic,
                                   source_prefix=None,
                                   output_file='fort.3')
            self.boinc_submit(job_name)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('task_id', type=str,
                        help='Current work unit ID')
    parser.add_argument('input_info', type=str,
                        help='Path to the db config file.')
    args = parser.parse_args()
    group_name = args.task_id
    task_ids = group_name.split('-')
    LOGGER = utils.condor_logger('sixtrack')
    for task_id in task_ids:
        job = TrackingJob(task_id, args.input_info, group_name, LOGGER)
        try:
            job.run()
        except Exception as e:
            if job.db_type == 'mysql':
                job.db.open()
                job_table = {}
                where = "task_id"
                job_table['status'] = 'incomplete'
                job_table['mtime'] = int(time.time() * 1E7)
                job.db.update('sixtrack_wu', job_table,
                              where=f'task_id={job.task_id}')
            raise e
        finally: