コード例 #1
0
ファイル: tasks.py プロジェクト: sognetic/b2luigi
class Basf2Task(b2luigi.DispatchableTask):
    git_hash = b2luigi.Parameter(default=get_basf2_git_hash())

    def get_output_file_target(self, *args, **kwargs):
        file_name = self.get_output_file_name(*args, **kwargs)
        if os.path.splitext(file_name)[-1] == ".root":
            return ROOTLocalTarget(file_name)
        return super().get_output_file_target(*args, **kwargs)

    def get_serialized_parameters(self):
        serialized_parameters = get_serialized_parameters(self)

        # Git hash should go to the front
        return_dict = collections.OrderedDict()
        return_dict["git_hash"] = serialized_parameters["git_hash"]

        for key, value in serialized_parameters.items():
            return_dict[key] = value

        return return_dict
コード例 #2
0
    def process(self):
        assert get_basf2_git_hash() == self.git_hash

        try:
            import basf2
            import ROOT
        except ImportError:
            raise ImportError("Can not find ROOT or basf2. Can not use the basf2 task.")

        if self.num_processes:
            basf2.set_nprocesses(self.num_processes)

        if self.max_event:
            ROOT.Belle2.Environment.Instance().setNumberEventsOverride(self.max_event)

        path = self.create_path()

        path.add_module("Progress")
        basf2.print_path(path)
        basf2.process(path)

        print(basf2.statistics)
コード例 #3
0
ファイル: gbasf2.py プロジェクト: FelixMetzner/b2luigi
    def _build_gbasf2_submit_command(self):
        """
        Function to create the gbasf2 submit command to pass to run_with_gbasf2
        from the task options and attributes.
        """
        gbasf2_release = get_setting("gbasf2_release",
                                     default=get_basf2_git_hash(),
                                     task=self.task)
        gbasf2_additional_files = get_setting("gbasf2_additional_files",
                                              default=[],
                                              task=self.task)
        assert not isinstance(
            gbasf2_additional_files, str
        ), "gbasf2_additional_files should be a list or tuple, not a string."
        gbasf2_input_sandbox_files = [os.path.basename(self.pickle_file_path)
                                      ] + gbasf2_additional_files
        gbasf2_command_str = (
            f"gbasf2 {self.wrapper_file_path} -f {' '.join(gbasf2_input_sandbox_files)} "
            + f"-p {self.gbasf2_project_name} -s {gbasf2_release} ")

        gbasf2_input_dataset = get_setting("gbasf2_input_dataset",
                                           default=False,
                                           task=self.task)
        if gbasf2_input_dataset is not False:
            gbasf2_command_str += f" -i {gbasf2_input_dataset} "

        gbasf2_n_repition_jobs = get_setting("gbasf2_n_repition_job",
                                             default=False,
                                             task=self.task)
        if gbasf2_n_repition_jobs is not False:
            gbasf2_command_str += f" --repetition {gbasf2_n_repition_jobs} "

        # now add some additional optional options to the gbasf2 job submission string

        # whether to ask user for confirmation before submitting job
        force_submission = get_setting("gbasf2_force_submission",
                                       default=True,
                                       task=self.task)
        if force_submission:
            gbasf2_command_str += " --force "

        # estimated cpu time per sub-job in minutes
        cpu_minutes = get_setting("gbasf2_cputime",
                                  default=False,
                                  task=self.task)
        if cpu_minutes is not False:
            gbasf2_command_str += f" --cputime {cpu_minutes} "

        # estimated number or processed events per second
        evtpersec = get_setting("gbasf2_evtpersec",
                                default=False,
                                task=self.task)
        if evtpersec is not False:
            gbasf2_command_str += f" --evtpersec {evtpersec} "

        # gbasf2 job priority
        priority = get_setting("gbasf2_priority",
                               default=False,
                               task=self.task)
        if priority is not False:
            assert 0 <= priority <= 10, "Priority should be integer between 0 and 10."
            gbasf2_command_str += f" --priority {priority} "

        # gbasf2 job type (e.g. User, Production, ...)
        jobtype = get_setting("gbasf2_jobtype", default=False, task=self.task)
        if jobtype is not False:
            gbasf2_command_str += f" --jobtype {jobtype} "

        # additional basf2 options to use on grid
        basf2opt = get_setting("gbasf2_basf2opt",
                               default=False,
                               task=self.task)
        if basf2opt is not False:
            gbasf2_command_str += f" --basf2opt='{basf2opt}' "

        # optional string of additional parameters to append to gbasf2 command
        gbasf2_additional_params = get_setting("gbasf2_additional_params",
                                               default=False,
                                               task=self.task)
        if basf2opt is not False:
            gbasf2_command_str += f" {gbasf2_additional_params} "

        gbasf2_command = shlex.split(gbasf2_command_str)
        return gbasf2_command