def main(argv=None):
    if argv == None:
        argv = sys.argv[1:]
    optParser = optparse.OptionParser()
    optParser.description = """All-in-one Alignment Validation.
This will run various validation procedures either on batch queues or interactively.
If no name is given (-N parameter) a name containing time and date is created automatically.
To merge the outcome of all validation procedures run TkAlMerge.sh in your validation's directory.
"""
    optParser.add_option(
        "-n",
        "--dryRun",
        dest="dryRun",
        action="store_true",
        default=False,
        help=
        "create all scripts and cfg File but do not start jobs (default=False)"
    )
    optParser.add_option(
        "--getImages",
        dest="getImages",
        action="store_true",
        default=True,
        help="get all Images created during the process (default= True)")
    defaultConfig = "TkAlConfig.ini"
    optParser.add_option(
        "-c",
        "--config",
        dest="config",
        default=defaultConfig,
        help=
        "configuration to use (default TkAlConfig.ini) this can be a comma-seperated list of all .ini file you want to merge",
        metavar="CONFIG")
    optParser.add_option(
        "-N",
        "--Name",
        dest="Name",
        help="Name of this validation (default: alignmentValidation_DATE_TIME)",
        metavar="NAME")
    optParser.add_option(
        "-r",
        "--restrictTo",
        dest="restrictTo",
        help=
        "restrict validations to given modes (comma seperated) (default: no restriction)",
        metavar="RESTRICTTO")
    optParser.add_option("-d",
                         "--debug",
                         dest="debugMode",
                         action="store_true",
                         default=False,
                         help="run the tool to get full traceback of errors",
                         metavar="DEBUG")

    (options, args) = optParser.parse_args(argv)

    if not options.restrictTo == None:
        options.restrictTo = options.restrictTo.split(",")

    options.config = [ os.path.abspath( iniFile ) for iniFile in \
                       options.config.split( "," )]

    config = BetterConfigParser()
    outputIniFileSet = set(config.read(options.config))
    failedIniFiles = [
        iniFile for iniFile in options.config
        if iniFile not in outputIniFileSet
    ]

    # Check for missing ini file
    if options.config == [os.path.abspath(defaultConfig)]:
        if (not os.path.exists(defaultConfig)):
            raise AllInOneError("Default 'ini' file '%s' not found!\n"
                                "You can specify another name with the "
                                "command line option '-c'/'--config'." %
                                (defaultConfig))
    else:
        for iniFile in failedIniFiles:
            if not os.path.exists(iniFile):
                raise AllInOneError("'%s' does not exist. Please check for "
                                    "typos in the filename passed to the "
                                    "'-c'/'--config' option!" % (iniFile))
            else:
                raise AllInOneError(("'%s' does exist, but parsing of the "
                                     "content failed!") % iniFile)

    # get the job name
    if options.Name == None:
        existingValDirs = fnmatch.filter(
            os.walk('.').next()[1], "alignmentValidation_*")
        if len(existingValDirs) > 0:
            options.Name = existingValDirs[-1]
        else:
            print("Cannot guess last working directory!")
            print("Please use the parameter '-N' or '--Name' to specify "
                  "the task for which you want a status report.")
            return 1

    # set output path
    outPath = os.path.abspath(options.Name)

    general = config.getGeneral()
    config.set("internals", "workdir",
               os.path.join(general["workdir"], options.Name))
    config.set("internals", "scriptsdir", outPath)
    config.set("general", "datadir",
               os.path.join(general["datadir"], options.Name))
    config.set("general", "logdir",
               os.path.join(general["logdir"], options.Name))
    config.set(
        "general", "eosdir",
        os.path.join("AlignmentValidation", general["eosdir"], options.Name))

    if not os.path.exists(outPath):
        os.makedirs(outPath)
    elif not os.path.isdir(outPath):
        raise AllInOneError(
            "the file %s is in the way rename the Job or move it away" %
            outPath)

    # replace default templates by the ones specified in the "alternateTemplates" section
    loadTemplates(config)

    #save backup configuration file
    backupConfigFile = open(os.path.join(outPath, "usedConfiguration.ini"),
                            "w")
    config.write(backupConfigFile)

    #copy proxy, if there is one
    try:
        proxyexists = int(getCommandOutput2("voms-proxy-info --timeleft")) > 10
    except RuntimeError:
        proxyexists = False

    if proxyexists:
        shutil.copyfile(
            getCommandOutput2("voms-proxy-info --path").strip(),
            os.path.join(outPath, ".user_proxy"))

    validations = []
    jobs = []
    for validation in config.items("validation"):
        validation = validation[0].split("-")
        alignmentList = [validation[1]]
        validationsToAdd = [(validation[0],alignment) \
                                for alignment in alignmentList]
        validations.extend(validationsToAdd)

    for validation in validations:

        job = ValidationJobMultiIOV(validation, config, options, outPath,
                                    len(validations))
        if (job.optionMultiIOV == True):
            jobs.extend(job)
        else:
            jobs.extend(ValidationJob(validation, config, options, 1))

    for job in jobs:
        if job.needsproxy and not proxyexists:
            raise AllInOneError(
                "At least one job needs a grid proxy, please init one.")

    lmap(lambda job: job.createJob(), jobs)

    validations = [job.getValidation() for job in jobs]
    validations = flatten(validations)

    createMergeScript(outPath, validations, options)

    lmap(lambda job: job.runJob(), jobs)

    if options.dryRun:
        pass
    else:
        ValidationJobMultiIOV.runCondorJobs(outPath)
    def __performMultiIOV(self, validation, alignments, config, options,
                          outPath):
        validations = []
        if self.valType == "compare":
            alignmentsList = alignments.split(",")
            firstAlignList = alignmentsList[0].split()
            firstAlignName = firstAlignList[0].strip()
            secondAlignList = alignmentsList[1].split()
            secondAlignName = secondAlignList[0].strip()
            compareAlignments = "%s" % firstAlignName + "_vs_%s" % secondAlignName
            sectionMultiIOV = "multiIOV:compare"
            if not self.config.has_section(sectionMultiIOV):
                raise AllInOneError(
                    "section'[%s]' not found. Please define the dataset" %
                    sectionMultiIOV)
            iovList = self.config.get(sectionMultiIOV, "iovs")
            iovList = re.sub(r"\s+", "", iovList, flags=re.UNICODE).split(",")
            for iov in iovList:
                tmpConfig = BetterConfigParser()
                tmpConfig.read(options.config)
                general = tmpConfig.getGeneral()
                tmpConfig.add_section("IOV")
                tmpConfig.set("IOV", "iov", iov)
                tmpConfig.set(
                    "internals", "workdir",
                    os.path.join(
                        general["workdir"], options.Name, self.valType +
                        "_%s" % compareAlignments + "_%s" % iov))
                tmpConfig.set(
                    "internals", "scriptsdir",
                    os.path.join(
                        outPath, self.valType + "_%s" % compareAlignments +
                        "_%s" % iov))
                tmpConfig.set(
                    "general", "datadir",
                    os.path.join(
                        general["datadir"], options.Name, self.valType +
                        "_%s" % compareAlignments + "_%s" % iov))
                tmpConfig.set(
                    "general", "logdir",
                    os.path.join(
                        general["logdir"], options.Name, self.valType +
                        "_%s" % compareAlignments + "_%s" % iov))
                tmpConfig.set(
                    "general", "eosdir",
                    os.path.join(
                        "AlignmentValidation", general["eosdir"], options.Name,
                        self.valType + "_%s" % compareAlignments +
                        "_%s" % iov))
                tmpOptions = copy.deepcopy(options)
                tmpOptions.Name = os.path.join(
                    options.Name,
                    self.valType + "_%s" % compareAlignments + "_%s" % iov)
                tmpOptions.config = tmpConfig
                newOutPath = os.path.abspath(tmpOptions.Name)
                if not os.path.exists(newOutPath):
                    os.makedirs(newOutPath)
                elif not os.path.isdir(newOutPath):
                    raise AllInOneError(
                        "the file %s is in the way rename the Job or move it away"
                        % newOutPath)
                job = ValidationJob(validation, tmpConfig, tmpOptions,
                                    len(iovList))
                validations.append(job)

            return validations

        if "preexisting" in self.valType:
            preexistingValType = self.valType
            preexistingValSection = self.valSection
            preexistingEosdir = self.config.get(self.valSection, "eosdirName")
            originalValType = preexistingValType.replace('preexisting', '')
            originalValName = self.config.get(self.valSection,
                                              "originalValName")
            self.valSection = originalValType + ":" + originalValName
            originalAlignment = self.valName

        datasetList = self.config.get(self.valSection, "dataset")
        datasetList = re.sub(r"\s+", "", datasetList,
                             flags=re.UNICODE).split(",")
        for dataset in datasetList:
            sectionMultiIOV = "multiIOV:%s" % dataset
            if not self.config.has_section(sectionMultiIOV):
                raise AllInOneError(
                    "section'[%s]' not found. Please define the dataset" %
                    sectionMultiIOV)
            else:
                datasetBaseName = self.config.get(sectionMultiIOV, "dataset")
                iovList = self.config.get(sectionMultiIOV, "iovs")
                iovList = re.sub(r"\s+", "", iovList,
                                 flags=re.UNICODE).split(",")
                for iov in iovList:
                    datasetName = datasetBaseName + "_since%s" % iov
                    tmpConfig = BetterConfigParser()
                    tmpConfig.read(options.config)
                    general = tmpConfig.getGeneral()
                    if "preexisting" in self.valType:
                        valType = originalValType
                        valName = originalValName
                    else:
                        valType = self.valType
                        valName = self.valName
                    tmpConfig.add_section("IOV")
                    tmpConfig.set("IOV", "iov", iov)
                    tmpConfig.set(self.valSection, "dataset", datasetName)
                    tmpConfig.set(
                        "internals", "workdir",
                        os.path.join(general["workdir"], options.Name,
                                     valType + "_" + valName + "_%s" % iov))
                    tmpConfig.set(
                        "internals", "scriptsdir",
                        os.path.join(outPath,
                                     valType + "_" + valName + "_%s" % iov))
                    tmpConfig.set(
                        "general", "datadir",
                        os.path.join(general["datadir"], options.Name,
                                     valType + "_" + valName + "_%s" % iov))
                    tmpConfig.set(
                        "general", "logdir",
                        os.path.join(general["logdir"], options.Name,
                                     valType + "_" + valName + "_%s" % iov))
                    tmpConfig.set(
                        "general", "eosdir",
                        os.path.join("AlignmentValidation", general["eosdir"],
                                     options.Name,
                                     valType + "_" + valName + "_%s" % iov))
                    if "preexisting" in self.valType:
                        if self.valType == "preexistingoffline":
                            validationClassName = "AlignmentValidation"
                        #elif self.valType == "preexistingmcValidate":
                        #    validationClassName = "MonteCarloValidation"
                        #elif self.valType == "preexistingsplit":
                        #    validationClassName = "TrackSplittingValidation"
                        #elif self.valType == "preexistingprimaryvertex":
                        #    validationClassName = "PrimaryVertexValidation"
                        else:
                            raise AllInOneError(
                                "Unknown validation mode for preexisting option:'%s'"
                                % self.valType)
                        preexistingEosdirPath = os.path.join(
                            "AlignmentValidation", preexistingEosdir,
                            valType + "_" + valName + "_%s" % iov)
                        file = "/eos/cms/store/group/alca_trackeralign/AlignmentValidation/" + "%s" % preexistingEosdirPath + "/%s" % validationClassName + "_%s" % originalValName + "_%s" % originalAlignment + ".root"
                        tmpConfig.set(preexistingValSection, "file", file)
                    tmpOptions = copy.deepcopy(options)
                    tmpOptions.Name = os.path.join(
                        options.Name, valType + "_" + valName + "_%s" % iov)
                    tmpOptions.config = tmpConfig
                    newOutPath = os.path.abspath(tmpOptions.Name)
                    if not os.path.exists(newOutPath):
                        os.makedirs(newOutPath)
                    elif not os.path.isdir(newOutPath):
                        raise AllInOneError(
                            "the file %s is in the way rename the Job or move it away"
                            % newOutPath)
                    job = ValidationJob(validation, tmpConfig, tmpOptions,
                                        len(iovList))
                    validations.append(job)

        return validations
示例#3
0
def main(argv = None):
    if argv == None:
       argv = sys.argv[1:]
    optParser = optparse.OptionParser()
    optParser.description = """All-in-one Alignment Validation.
This will run various validation procedures either on batch queues or interactively.
If no name is given (-N parameter) a name containing time and date is created automatically.
To merge the outcome of all validation procedures run TkAlMerge.sh in your validation's directory.
"""
    optParser.add_option("-n", "--dryRun", dest="dryRun", action="store_true", default=False,
                         help="create all scripts and cfg File but do not start jobs (default=False)")
    optParser.add_option( "--getImages", dest="getImages", action="store_true", default=True,
                          help="get all Images created during the process (default= True)")
    defaultConfig = "TkAlConfig.ini"
    optParser.add_option("-c", "--config", dest="config", default = defaultConfig,
                         help="configuration to use (default TkAlConfig.ini) this can be a comma-seperated list of all .ini file you want to merge", metavar="CONFIG")
    optParser.add_option("-N", "--Name", dest="Name",
                         help="Name of this validation (default: alignmentValidation_DATE_TIME)", metavar="NAME")
    optParser.add_option("-r", "--restrictTo", dest="restrictTo",
                         help="restrict validations to given modes (comma seperated) (default: no restriction)", metavar="RESTRICTTO")
    optParser.add_option("-s", "--status", dest="crabStatus", action="store_true", default = False,
                         help="get the status of the crab jobs", metavar="STATUS")
    optParser.add_option("-d", "--debug", dest="debugMode", action="store_true",
                         default = False,
                         help="run the tool to get full traceback of errors",
                         metavar="DEBUG")
    optParser.add_option("-m", "--autoMerge", dest="autoMerge", action="store_true", default = False,
                         help="submit TkAlMerge.sh to run automatically when all jobs have finished (default=False)."
                              " Works only for batch jobs")

    (options, args) = optParser.parse_args(argv)

    if not options.restrictTo == None:
        options.restrictTo = options.restrictTo.split(",")
    
    options.config = [ os.path.abspath( iniFile ) for iniFile in \
                       options.config.split( "," ) ]
    config = BetterConfigParser()
    outputIniFileSet = set( config.read( options.config ) )
    failedIniFiles = [ iniFile for iniFile in options.config if iniFile not in outputIniFileSet ]

    # Check for missing ini file
    if options.config == [ os.path.abspath( defaultConfig ) ]:
        if ( not options.crabStatus ) and \
               ( not os.path.exists( defaultConfig ) ):
                raise AllInOneError, ( "Default 'ini' file '%s' not found!\n"
                                       "You can specify another name with the "
                                       "command line option '-c'/'--config'."
                                       %( defaultConfig ))
    else:
        for iniFile in failedIniFiles:
            if not os.path.exists( iniFile ):
                raise AllInOneError, ( "'%s' does not exist. Please check for "
                                       "typos in the filename passed to the "
                                       "'-c'/'--config' option!"
                                       %( iniFile ) )
            else:
                raise AllInOneError, ( "'%s' does exist, but parsing of the "
                                       "content failed!" ) % iniFile

    # get the job name
    if options.Name == None:
        if not options.crabStatus:
            options.Name = "alignmentValidation_%s"%(datetime.datetime.now().strftime("%y%m%d_%H%M%S"))
        else:
            existingValDirs = fnmatch.filter( os.walk( '.' ).next()[1],
                                              "alignmentValidation_*" )
            if len( existingValDirs ) > 0:
                options.Name = existingValDirs[-1]
            else:
                print "Cannot guess last working directory!"
                print ( "Please use the parameter '-N' or '--Name' to specify "
                        "the task for which you want a status report." )
                return 1

    # set output path
    outPath = os.path.abspath( options.Name )

    # Check status of submitted jobs and return
    if options.crabStatus:
        os.chdir( outPath )
        crabLogDirs = fnmatch.filter( os.walk('.').next()[1], "crab.*" )
        if len( crabLogDirs ) == 0:
            print "Found no crab tasks for job name '%s'"%( options.Name )
            return 1
        theCrab = crabWrapper.CrabWrapper()
        for crabLogDir in crabLogDirs:
            print
            print "*" + "=" * 78 + "*"
            print ( "| Status report and output retrieval for:"
                    + " " * (77 - len( "Status report and output retrieval for:" ) )
                    + "|" )
            taskName = crabLogDir.replace( "crab.", "" )
            print "| " + taskName + " " * (77 - len( taskName ) ) + "|"
            print "*" + "=" * 78 + "*"
            print
            crabOptions = { "-getoutput":"",
                            "-c": crabLogDir }
            try:
                theCrab.run( crabOptions )
            except AllInOneError, e:
                print "crab:  No output retrieved for this task."
            crabOptions = { "-status": "",
                            "-c": crabLogDir }
            theCrab.run( crabOptions )
        return
示例#4
0
def main(argv=None):
    if argv == None:
        argv = sys.argv[1:]
    optParser = optparse.OptionParser()
    optParser.description = """All-in-one Alignment Validation.
This will run various validation procedures either on batch queues or interactively.
If no name is given (-N parameter) a name containing time and date is created automatically.
To merge the outcome of all validation procedures run TkAlMerge.sh in your validation's directory.
"""
    optParser.add_option(
        "-n",
        "--dryRun",
        dest="dryRun",
        action="store_true",
        default=False,
        help=
        "create all scripts and cfg File but do not start jobs (default=False)"
    )
    optParser.add_option(
        "--getImages",
        dest="getImages",
        action="store_true",
        default=True,
        help="get all Images created during the process (default= True)")
    defaultConfig = "TkAlConfig.ini"
    optParser.add_option(
        "-c",
        "--config",
        dest="config",
        default=defaultConfig,
        help=
        "configuration to use (default TkAlConfig.ini) this can be a comma-seperated list of all .ini file you want to merge",
        metavar="CONFIG")
    optParser.add_option(
        "-N",
        "--Name",
        dest="Name",
        help="Name of this validation (default: alignmentValidation_DATE_TIME)",
        metavar="NAME")
    optParser.add_option(
        "-r",
        "--restrictTo",
        dest="restrictTo",
        help=
        "restrict validations to given modes (comma seperated) (default: no restriction)",
        metavar="RESTRICTTO")
    optParser.add_option("-s",
                         "--status",
                         dest="crabStatus",
                         action="store_true",
                         default=False,
                         help="get the status of the crab jobs",
                         metavar="STATUS")
    optParser.add_option("-d",
                         "--debug",
                         dest="debugMode",
                         action="store_true",
                         default=False,
                         help="run the tool to get full traceback of errors",
                         metavar="DEBUG")
    optParser.add_option(
        "-m",
        "--autoMerge",
        dest="autoMerge",
        action="store_true",
        default=False,
        help=
        "submit TkAlMerge.sh to run automatically when all jobs have finished (default=False)."
        " Works only for batch jobs")
    optParser.add_option(
        "--mergeOfflineParallel",
        dest="mergeOfflineParallel",
        action="store_true",
        default=False,
        help=
        "Enable parallel merging of offline data. Best used with -m option. Only works with lxBatch-jobmode",
        metavar="MERGE_PARALLEL")

    (options, args) = optParser.parse_args(argv)

    if not options.restrictTo == None:
        options.restrictTo = options.restrictTo.split(",")

    options.config = [ os.path.abspath( iniFile ) for iniFile in \
                       options.config.split( "," ) ]
    config = BetterConfigParser()
    outputIniFileSet = set(config.read(options.config))
    failedIniFiles = [
        iniFile for iniFile in options.config
        if iniFile not in outputIniFileSet
    ]

    # Check for missing ini file
    if options.config == [os.path.abspath(defaultConfig)]:
        if ( not options.crabStatus ) and \
               ( not os.path.exists( defaultConfig ) ):
            raise AllInOneError("Default 'ini' file '%s' not found!\n"
                                "You can specify another name with the "
                                "command line option '-c'/'--config'." %
                                (defaultConfig))
    else:
        for iniFile in failedIniFiles:
            if not os.path.exists(iniFile):
                raise AllInOneError("'%s' does not exist. Please check for "
                                    "typos in the filename passed to the "
                                    "'-c'/'--config' option!" % (iniFile))
            else:
                raise AllInOneError(("'%s' does exist, but parsing of the "
                                     "content failed!") % iniFile)

    # get the job name
    if options.Name == None:
        if not options.crabStatus:
            options.Name = "alignmentValidation_%s" % (
                datetime.datetime.now().strftime("%y%m%d_%H%M%S"))
        else:
            existingValDirs = fnmatch.filter(
                os.walk('.').next()[1], "alignmentValidation_*")
            if len(existingValDirs) > 0:
                options.Name = existingValDirs[-1]
            else:
                print("Cannot guess last working directory!")
                print("Please use the parameter '-N' or '--Name' to specify "
                      "the task for which you want a status report.")
                return 1

    # set output path
    outPath = os.path.abspath(options.Name)

    # Check status of submitted jobs and return
    if options.crabStatus:
        os.chdir(outPath)
        crabLogDirs = fnmatch.filter(os.walk('.').next()[1], "crab.*")
        if len(crabLogDirs) == 0:
            print("Found no crab tasks for job name '%s'" % (options.Name))
            return 1
        theCrab = crabWrapper.CrabWrapper()
        for crabLogDir in crabLogDirs:
            print()
            print("*" + "=" * 78 + "*")
            print("| Status report and output retrieval for:" + " " *
                  (77 - len("Status report and output retrieval for:")) + "|")
            taskName = crabLogDir.replace("crab.", "")
            print("| " + taskName + " " * (77 - len(taskName)) + "|")
            print("*" + "=" * 78 + "*")
            print()
            crabOptions = {"-getoutput": "", "-c": crabLogDir}
            try:
                theCrab.run(crabOptions)
            except AllInOneError as e:
                print("crab:  No output retrieved for this task.")
            crabOptions = {"-status": "", "-c": crabLogDir}
            theCrab.run(crabOptions)
        return

    general = config.getGeneral()
    config.set("internals", "workdir",
               os.path.join(general["workdir"], options.Name))
    config.set("internals", "scriptsdir", outPath)
    config.set("general", "datadir",
               os.path.join(general["datadir"], options.Name))
    config.set("general", "logdir",
               os.path.join(general["logdir"], options.Name))
    config.set(
        "general", "eosdir",
        os.path.join("AlignmentValidation", general["eosdir"], options.Name))

    if not os.path.exists(outPath):
        os.makedirs(outPath)
    elif not os.path.isdir(outPath):
        raise AllInOneError(
            "the file %s is in the way rename the Job or move it away" %
            outPath)

    # replace default templates by the ones specified in the "alternateTemplates" section
    loadTemplates(config)

    #save backup configuration file
    backupConfigFile = open(os.path.join(outPath, "usedConfiguration.ini"),
                            "w")
    config.write(backupConfigFile)

    #copy proxy, if there is one
    try:
        proxyexists = int(getCommandOutput2("voms-proxy-info --timeleft")) > 10
    except RuntimeError:
        proxyexists = False

    if proxyexists:
        shutil.copyfile(
            getCommandOutput2("voms-proxy-info --path").strip(),
            os.path.join(outPath, ".user_proxy"))

    validations = []
    for validation in config.items("validation"):
        alignmentList = [validation[1]]
        validationsToAdd = [(validation[0],alignment) \
                                for alignment in alignmentList]
        validations.extend(validationsToAdd)
    jobs = [ ValidationJob( validation, config, options) \
                 for validation in validations ]
    for job in jobs:
        if job.needsproxy and not proxyexists:
            raise AllInOneError(
                "At least one job needs a grid proxy, please init one.")
    map(lambda job: job.createJob(), jobs)
    validations = [job.getValidation() for job in jobs]

    if options.mergeOfflineParallel:
        parallelMergeObjects = createMergeScript(
            outPath, validations, options)['parallelMergeObjects']
    else:
        createMergeScript(outPath, validations, options)

    print()
    map(lambda job: job.runJob(), jobs)

    if options.autoMerge and ValidationJob.jobCount == ValidationJob.batchCount and config.getGeneral(
    )["jobmode"].split(",")[0] == "lxBatch":
        print(">             Automatically merging jobs when they have ended")
        # if everything is done as batch job, also submit TkAlMerge.sh to be run
        # after the jobs have finished

        #if parallel merge scripts: manage dependencies
        if options.mergeOfflineParallel and parallelMergeObjects != {}:
            initID = parallelMergeObjects["init"].runJob(config).split(
                "<")[1].split(">")[0]
            parallelIDs = []
            for parallelMergeScript in parallelMergeObjects["parallel"]:
                parallelMergeScript.addDependency(initID)
                for job in jobs:
                    if isinstance(
                            job.validation, OfflineValidation
                    ) and "TkAlMerge" + job.validation.alignmentToValidate.name == parallelMergeScript.name:
                        parallelMergeScript.addDependency(job.JobId)
                parallelIDs.append(
                    parallelMergeScript.runJob(config).split("<")[1].split(">")
                    [0])
            parallelMergeObjects["continue"].addDependency(parallelIDs)
            parallelMergeObjects["continue"].addDependency(
                ValidationJob.batchJobIds)
            parallelMergeObjects["continue"].runJob(config)

        else:
            repMap = {
                "commands":
                config.getGeneral()["jobmode"].split(",")[1],
                "jobName":
                "TkAlMerge",
                "logDir":
                config.getGeneral()["logdir"],
                "script":
                "TkAlMerge.sh",
                "bsub":
                "/afs/cern.ch/cms/caf/scripts/cmsbsub",
                "conditions":
                '"' + " && ".join([
                    "ended(" + jobId + ")"
                    for jobId in ValidationJob.batchJobIds
                ]) + '"'
            }
            for ext in ("stdout", "stderr", "stdout.gz", "stderr.gz"):
                oldlog = "%(logDir)s/%(jobName)s." % repMap + ext
                if os.path.exists(oldlog):
                    os.remove(oldlog)

            #issue job
            getCommandOutput2("%(bsub)s %(commands)s "
                              "-o %(logDir)s/%(jobName)s.stdout "
                              "-e %(logDir)s/%(jobName)s.stderr "
                              "-w %(conditions)s "
                              "%(logDir)s/%(script)s" % repMap)
示例#5
0
def main(argv=None):
    if argv == None:
        argv = sys.argv[1:]
    optParser = optparse.OptionParser()
    optParser.description = """All-in-one Alignment Validation.
This will run various validation procedures either on batch queues or interactviely. 
If no name is given (-N parameter) a name containing time and date is created automatically.
To merge the outcome of all validation procedures run TkAlMerge.sh in your validation's directory.
"""
    optParser.add_option(
        "-n",
        "--dryRun",
        dest="dryRun",
        action="store_true",
        default=False,
        help=
        "create all scripts and cfg File but do not start jobs (default=False)"
    )
    optParser.add_option(
        "--getImages",
        dest="getImages",
        action="store_true",
        default=False,
        help="get all Images created during the process (default= False)")
    defaultConfig = "TkAlConfig.ini"
    optParser.add_option(
        "-c",
        "--config",
        dest="config",
        default=defaultConfig,
        help=
        "configuration to use (default TkAlConfig.ini) this can be a comma-seperated list of all .ini file you want to merge",
        metavar="CONFIG")
    optParser.add_option(
        "-N",
        "--Name",
        dest="Name",
        help="Name of this validation (default: alignmentValidation_DATE_TIME)",
        metavar="NAME")
    optParser.add_option(
        "-r",
        "--restrictTo",
        dest="restrictTo",
        help=
        "restrict validations to given modes (comma seperated) (default: no restriction)",
        metavar="RESTRICTTO")
    optParser.add_option("-s",
                         "--status",
                         dest="crabStatus",
                         action="store_true",
                         default=False,
                         help="get the status of the crab jobs",
                         metavar="STATUS")
    optParser.add_option("-d",
                         "--debug",
                         dest="debugMode",
                         action="store_true",
                         default=False,
                         help="run the tool to get full traceback of errors",
                         metavar="DEBUG")
    optParser.add_option(
        "-m",
        "--autoMerge",
        dest="autoMerge",
        action="store_true",
        default=False,
        help=
        "submit TkAlMerge.sh to run automatically when all jobs have finished (default=False)."
        " Works only for batch jobs")

    (options, args) = optParser.parse_args(argv)

    if not options.restrictTo == None:
        options.restrictTo = options.restrictTo.split(",")

    options.config = [ os.path.abspath( iniFile ) for iniFile in \
                       options.config.split( "," ) ]
    config = BetterConfigParser()
    outputIniFileSet = set(config.read(options.config))
    failedIniFiles = [
        iniFile for iniFile in options.config
        if iniFile not in outputIniFileSet
    ]

    # Check for missing ini file
    if options.config == [os.path.abspath(defaultConfig)]:
        if ( not options.crabStatus ) and \
               ( not os.path.exists( defaultConfig ) ):
            raise AllInOneError, ("Default 'ini' file '%s' not found!\n"
                                  "You can specify another name with the "
                                  "command line option '-c'/'--config'." %
                                  (defaultConfig))
    else:
        for iniFile in failedIniFiles:
            if not os.path.exists(iniFile):
                raise AllInOneError, ("'%s' does not exist. Please check for "
                                      "typos in the filename passed to the "
                                      "'-c'/'--config' option!" % (iniFile))
            else:
                raise AllInOneError, ("'%s' does exist, but parsing of the "
                                      "content failed!")

    # get the job name
    if options.Name == None:
        if not options.crabStatus:
            options.Name = "alignmentValidation_%s" % (
                datetime.datetime.now().strftime("%y%m%d_%H%M%S"))
        else:
            existingValDirs = fnmatch.filter(
                os.walk('.').next()[1], "alignmentValidation_*")
            if len(existingValDirs) > 0:
                options.Name = existingValDirs[-1]
            else:
                print "Cannot guess last working directory!"
                print(
                    "Please use the parameter '-N' or '--Name' to specify "
                    "the task for which you want a status report.")
                return 1

    # set output path
    outPath = os.path.abspath(options.Name)

    # Check status of submitted jobs and return
    if options.crabStatus:
        os.chdir(outPath)
        crabLogDirs = fnmatch.filter(os.walk('.').next()[1], "crab.*")
        if len(crabLogDirs) == 0:
            print "Found no crab tasks for job name '%s'" % (options.Name)
            return 1
        theCrab = crabWrapper.CrabWrapper()
        for crabLogDir in crabLogDirs:
            print
            print "*" + "=" * 78 + "*"
            print("| Status report and output retrieval for:" + " " *
                  (77 - len("Status report and output retrieval for:")) + "|")
            taskName = crabLogDir.replace("crab.", "")
            print "| " + taskName + " " * (77 - len(taskName)) + "|"
            print "*" + "=" * 78 + "*"
            print
            crabOptions = {"-getoutput": "", "-c": crabLogDir}
            try:
                theCrab.run(crabOptions)
            except AllInOneError, e:
                print "crab:  No output retrieved for this task."
            crabOptions = {"-status": "", "-c": crabLogDir}
            theCrab.run(crabOptions)
        return
示例#6
0
def main(argv = None):
    if argv == None:
       argv = sys.argv[1:]
    optParser = optparse.OptionParser()
    optParser.description = """All-in-one Alignment Validation.
This will run various validation procedures either on batch queues or interactively.
If no name is given (-N parameter) a name containing time and date is created automatically.
To merge the outcome of all validation procedures run TkAlMerge.sh in your validation's directory.
"""
    optParser.add_option("-n", "--dryRun", dest="dryRun", action="store_true", default=False,
                         help="create all scripts and cfg File but do not start jobs (default=False)")
    optParser.add_option( "--getImages", dest="getImages", action="store_true", default=True,
                          help="get all Images created during the process (default= True)")
    defaultConfig = "TkAlConfig.ini"
    optParser.add_option("-c", "--config", dest="config", default = defaultConfig,
                         help="configuration to use (default TkAlConfig.ini) this can be a comma-seperated list of all .ini file you want to merge", metavar="CONFIG")
    optParser.add_option("-N", "--Name", dest="Name",
                         help="Name of this validation (default: alignmentValidation_DATE_TIME)", metavar="NAME")
    optParser.add_option("-r", "--restrictTo", dest="restrictTo",
                         help="restrict validations to given modes (comma seperated) (default: no restriction)", metavar="RESTRICTTO")
    optParser.add_option("-s", "--status", dest="crabStatus", action="store_true", default = False,
                         help="get the status of the crab jobs", metavar="STATUS")
    optParser.add_option("-d", "--debug", dest="debugMode", action="store_true",
                         default = False,
                         help="run the tool to get full traceback of errors",
                         metavar="DEBUG")
    optParser.add_option("-m", "--autoMerge", dest="autoMerge", action="store_true", default = False,
                         help="submit TkAlMerge.sh to run automatically when all jobs have finished (default=False)."
                              " Works only for batch jobs")

    (options, args) = optParser.parse_args(argv)

    if not options.restrictTo == None:
        options.restrictTo = options.restrictTo.split(",")

    options.config = [ os.path.abspath( iniFile ) for iniFile in \
                       options.config.split( "," ) ]
    config = BetterConfigParser()
    outputIniFileSet = set( config.read( options.config ) )
    failedIniFiles = [ iniFile for iniFile in options.config if iniFile not in outputIniFileSet ]

    # Check for missing ini file
    if options.config == [ os.path.abspath( defaultConfig ) ]:
        if ( not options.crabStatus ) and \
               ( not os.path.exists( defaultConfig ) ):
                raise AllInOneError( "Default 'ini' file '%s' not found!\n"
                                       "You can specify another name with the "
                                       "command line option '-c'/'--config'."
                                       %( defaultConfig ))
    else:
        for iniFile in failedIniFiles:
            if not os.path.exists( iniFile ):
                raise AllInOneError( "'%s' does not exist. Please check for "
                                       "typos in the filename passed to the "
                                       "'-c'/'--config' option!"
                                       %( iniFile ))
            else:
                raise AllInOneError(( "'%s' does exist, but parsing of the "
                                       "content failed!" ) % iniFile)

    # get the job name
    if options.Name == None:
        if not options.crabStatus:
            options.Name = "alignmentValidation_%s"%(datetime.datetime.now().strftime("%y%m%d_%H%M%S"))
        else:
            existingValDirs = fnmatch.filter( os.walk( '.' ).next()[1],
                                              "alignmentValidation_*" )
            if len( existingValDirs ) > 0:
                options.Name = existingValDirs[-1]
            else:
                print "Cannot guess last working directory!"
                print ( "Please use the parameter '-N' or '--Name' to specify "
                        "the task for which you want a status report." )
                return 1

    # set output path
    outPath = os.path.abspath( options.Name )

    # Check status of submitted jobs and return
    if options.crabStatus:
        os.chdir( outPath )
        crabLogDirs = fnmatch.filter( os.walk('.').next()[1], "crab.*" )
        if len( crabLogDirs ) == 0:
            print "Found no crab tasks for job name '%s'"%( options.Name )
            return 1
        theCrab = crabWrapper.CrabWrapper()
        for crabLogDir in crabLogDirs:
            print
            print "*" + "=" * 78 + "*"
            print ( "| Status report and output retrieval for:"
                    + " " * (77 - len( "Status report and output retrieval for:" ) )
                    + "|" )
            taskName = crabLogDir.replace( "crab.", "" )
            print "| " + taskName + " " * (77 - len( taskName ) ) + "|"
            print "*" + "=" * 78 + "*"
            print
            crabOptions = { "-getoutput":"",
                            "-c": crabLogDir }
            try:
                theCrab.run( crabOptions )
            except AllInOneError as e:
                print "crab:  No output retrieved for this task."
            crabOptions = { "-status": "",
                            "-c": crabLogDir }
            theCrab.run( crabOptions )
        return

    general = config.getGeneral()
    config.set("internals","workdir",os.path.join(general["workdir"],options.Name) )
    config.set("internals","scriptsdir",outPath)
    config.set("general","datadir",os.path.join(general["datadir"],options.Name) )
    config.set("general","logdir",os.path.join(general["logdir"],options.Name) )
    config.set("general","eosdir",os.path.join("AlignmentValidation", general["eosdir"], options.Name) )

    if not os.path.exists( outPath ):
        os.makedirs( outPath )
    elif not os.path.isdir( outPath ):
        raise AllInOneError("the file %s is in the way rename the Job or move it away"%outPath)

    # replace default templates by the ones specified in the "alternateTemplates" section
    loadTemplates( config )

    #save backup configuration file
    backupConfigFile = open( os.path.join( outPath, "usedConfiguration.ini" ) , "w"  )
    config.write( backupConfigFile )

    #copy proxy, if there is one
    try:
        proxyexists = int(getCommandOutput2("voms-proxy-info --timeleft")) > 10
    except RuntimeError:
        proxyexists = False

    if proxyexists:
        shutil.copyfile(getCommandOutput2("voms-proxy-info --path").strip(), os.path.join(outPath, ".user_proxy"))

    validations = []
    for validation in config.items("validation"):
        alignmentList = [validation[1]]
        validationsToAdd = [(validation[0],alignment) \
                                for alignment in alignmentList]
        validations.extend(validationsToAdd)
    jobs = [ ValidationJob( validation, config, options) \
                 for validation in validations ]
    for job in jobs:
        if job.needsproxy and not proxyexists:
            raise AllInOneError("At least one job needs a grid proxy, please init one.")
    map( lambda job: job.createJob(), jobs )
    validations = [ job.getValidation() for job in jobs ]

    createMergeScript(outPath, validations)

    print
    map( lambda job: job.runJob(), jobs )

    if options.autoMerge:
        # if everything is done as batch job, also submit TkAlMerge.sh to be run
        # after the jobs have finished
        if ValidationJob.jobCount == ValidationJob.batchCount and config.getGeneral()["jobmode"].split(",")[0] == "lxBatch":
            print ">             Automatically merging jobs when they have ended"
            repMap = {
                "commands": config.getGeneral()["jobmode"].split(",")[1],
                "jobName": "TkAlMerge",
                "logDir": config.getGeneral()["logdir"],
                "script": "TkAlMerge.sh",
                "bsub": "/afs/cern.ch/cms/caf/scripts/cmsbsub",
                "conditions": '"' + " && ".join(["ended(" + jobId + ")" for jobId in ValidationJob.batchJobIds]) + '"'
                }
            for ext in ("stdout", "stderr", "stdout.gz", "stderr.gz"):
                oldlog = "%(logDir)s/%(jobName)s."%repMap + ext
                if os.path.exists(oldlog):
                    os.remove(oldlog)

            getCommandOutput2("%(bsub)s %(commands)s "
                              "-o %(logDir)s/%(jobName)s.stdout "
                              "-e %(logDir)s/%(jobName)s.stderr "
                              "-w %(conditions)s "
                              "%(logDir)s/%(script)s"%repMap)