Пример #1
0
 def htcondor_job_config(self, config, job_num, branches):
     # render_data is rendered into all files sent with a job
     config.render_variables["analysis_path"] = os.getenv("ANALYSIS_PATH")
     # tell the job config if GPUs are requested
     if not law.is_no_param(self.htcondor_gpus):
         config.custom_config = [("request_gpus", self.htcondor_gpus)]
     return config
Пример #2
0
 def htcondor_job_config(self, config, job_num, branches):
     # render_variables are rendered into all files sent with a job
     config.render_variables["analysis_path"] = os.getenv("ANALYSIS_PATH")
     # copy the entire environment
     config.custom_content.append(("getenv", "true"))
     # tell the job config if GPUs are requested
     if not law.is_no_param(self.htcondor_gpus):
         config.custom_content.append(("request_gpus", self.htcondor_gpus))
     return config
Пример #3
0
    def modify_param_values(cls, params):
        params = AnalysisTask.modify_param_values(params)
        if "workflow" in params and law.is_no_param(params["workflow"]):
            grid_ce = params["grid_ce"]

            # figure out ce version
            if grid_ce[0] in cls.arc_ce_map:
                workflow = "arc"
            elif grid_ce[0] in cls.glite_ce_map:
                workflow = "glite"
            elif grid_ce[0] in cls.htcondor_ce_map:
                workflow = "htcondor"
            else:
                raise ValueError("Unknown computing element type {}".format(grid_ce[0]))

            ces = []
            for ce in grid_ce:
                ces.append(getattr(cls, workflow + "_ce_map").get(ce, ce))
            params[workflow + "_ce"] = tuple(law.util.flatten(ces))
            params["workflow"] = workflow
        return params
Пример #4
0
    def run(self):
        lfn = self.input()["lfns"].random_target().load()[self.branch_data]

        setup_files_dir, setup_files = self.requires()["files"].localize()

        # create the temporary dir to run in
        tmp_dir = law.LocalDirectoryTarget(is_tmp=True)
        tmp_dir.touch()

        # manage jes files
        data_src = self.dataset_inst.data_source
        jes_versions = self.config_inst.get_aux("jes_version")[data_src]
        jes_levels = self.config_inst.get_aux("jes_levels")[data_src]
        jes_ranges = law.util.flatten(tpl[:2] for tpl in jes_versions)
        jes_files_dict = setup_files["jes_files"][data_src]
        jes_files = law.util.flatten(
            [[jes_files_dict[version][level] for level in jes_levels]
             for _, _, version in jes_versions])
        jes_unc_files = [
            jes_files_dict[version]["Uncertainty"]
            for _, _, version in jes_versions
        ]
        jes_unc_src_file = setup_files[
            "jes_unc_src_file"] if self.dataset_inst.is_mc else ""

        # determine the xrd redirector and download the file
        redirector = xrd_redirectors[1]  #determine_xrd_redirector(lfn)
        xrd_url = "root://{}/{}".format(redirector, lfn)

        if self.stream_input_file:
            input_file = xrd_url
        else:
            input_file = "input_file.root"
            cmd = "xrdcp {} {}".format(xrd_url, input_file)
            for _ in range(self.xrdcp_attempts):
                with self.publish_step(
                        "download input file from {} ...".format(xrd_url)):
                    code = law.util.interruptable_popen(
                        cmd,
                        shell=True,
                        cwd=tmp_dir.path,
                        executable="/bin/bash")[0]
                    if code == 0:
                        break
            else:
                raise Exception("xrdcp failed")
            input_file = "file://" + os.path.join(tmp_dir.path, input_file)

        # cmsRun argument helper
        def cmsRunArg(key, value):
            return " ".join("{}={}".format(key, v)
                            for v in law.util.make_list(value))

        output = self.output()
        # get global tag from dataset if defined, otherwise take default from config
        global_tag = self.dataset_inst.get_aux(
            "global_tag",
            self.config_inst.get_aux("global_tag")[data_src])
        with output["tree"].localize("w") as tmp_tree, output["meta"].localize(
                "w") as tmp_meta:
            args = [
                ("inputFiles", input_file),
                ("outputFile", tmp_tree.path),
                ("campaign", self.config_inst.campaign.name),
                ("metaDataFile", tmp_meta.path),
                ("isData", self.dataset_inst.is_data),
                ("globalTag", global_tag),
                ("lumiFile", setup_files["lumi_file"]),
                ("metFilters",
                 self.config_inst.get_aux("metFilters")[data_src]),
                ("jesFiles", jes_files),
                ("jesRanges", jes_ranges),
                ("jesUncFiles", jes_unc_files),
                ("jesUncSrcFile", jes_unc_src_file),
                ("jesUncSources",
                 self.config_inst.get_aux("jes_sources_{}".format(
                     self.config_inst.get_aux("jes_scheme")))),
                ("jerPtResolutionFile",
                 setup_files["jer_files"]["PtResolution"]),
                ("jerScaleFactorFile", setup_files["jer_files"]["SF"]),
                ("deepCSVWP", self.config_inst.get_aux("working_points")
                 ["deepcsv"]["medium"]),
                ("deepJetWP", self.config_inst.get_aux("working_points")
                 ["deepjet"]["medium"]),
            ]

            # triggers
            for channel_inst, triggers in self.config_inst.get_aux(
                    "triggers").items():
                # special rules may apply for real datasets as triggers can be run dependent
                if self.dataset_inst.is_data:
                    d_ch = self.config_inst.get_aux("dataset_channels")[
                        self.dataset_inst]
                    if d_ch == channel_inst:
                        triggers = self.config_inst.get_aux(
                            "data_triggers").get(self.dataset_inst, triggers)
                args.append((channel_inst.name + "Triggers", triggers))

            # lepton channel for data
            if self.dataset_inst.is_data:
                ch = self.config_inst.get_aux("dataset_channels")[
                    self.dataset_inst].name
                args.append(("leptonChannel", ch))

            # max events
            if not law.is_no_param(self.max_events):
                args.append(("maxEvents", self.max_events))

            # build the cmsRun command
            cfg_file = "treeMaker_cfg.py"
            cmd = "cmsRun " + law.util.rel_path(__file__, "files", cfg_file)
            cmd += " " + " ".join(cmsRunArg(*tpl) for tpl in args)

            # create environment
            env = os.environ.copy()
            env["CMSSW_SEARCH_PATH"] += ":" + setup_files_dir.path
            print("running command: {}".format(cmd))
            for obj in law.util.readable_popen(cmd,
                                               shell=True,
                                               executable="/bin/bash",
                                               cwd=tmp_dir.path,
                                               env=env):
                if isinstance(obj, six.string_types):
                    print(obj)
                    if obj.startswith("Begin processing the"):
                        self._publish_message(obj)
                else:
                    if obj.returncode != 0:
                        raise Exception("cmsRun failed")

            if not tmp_tree.exists():
                raise Exception("output file not exising after cmsRun")
 def store_parts_opt(self):
     parts = tuple()
     if not law.is_no_param(self.version):
         parts += (self.version, )
     return parts