Example #1
0
def main(argv = None):
    """Main routine of the script.

    Arguments:
    - `argv`: arguments passed to the main routine
    """

    if argv == None:
        argv = sys.argv[1:]

    parser = argparse.ArgumentParser(
        description="Prepare input db file for MillePede workflow.")
    parser.add_argument("-g", "--global-tag", dest="global_tag", required=True,
                        metavar="TAG",
                        help="global tag to extract the alignment payloads")
    parser.add_argument("-r", "--run-number", dest="run_number", required=True,
                        metavar="INTEGER", type=int,
                        help="run number to select IOV")
    parser.add_argument("-o", "--output-db", dest="output_db",
                        default="alignment_input.db", metavar="PATH",
                        help="name of the output file (default: '%(default)s')")
    args = parser.parse_args(argv)

    inputs = mps_tools.get_tags(args.global_tag,
                                ["TrackerAlignmentRcd",
                                 "TrackerSurfaceDeformationRcd",
                                 "TrackerAlignmentErrorExtendedRcd"])
    for inp in inputs.itervalues():
        inp["iovs"] = mps_tools.get_iovs(inp["connect"], inp["tag"])
    mps_tools.create_single_iov_db(inputs, args.run_number, args.output_db)
Example #2
0
def check_iov_definition(cms_process, first_run):
    """
    Check consistency of input alignment payloads and IOV definition.
    Returns a dictionary with the information needed to override possibly
    problematic input taken from the global tag.

    Arguments:
    - `cms_process`: cms.Process object containing the CMSSW configuration
    - `first_run`: first run for start geometry
    """

    print "Checking consistency of IOV definition..."
    iovs = mps_tools.make_unique_runranges(cms_process.AlignmentProducer)

    inputs = {
        "TrackerAlignmentRcd": None,
        "TrackerSurfaceDeformationRcd": None,
        "TrackerAlignmentErrorExtendedRcd": None,
    }

    for condition in cms_process.GlobalTag.toGet.value():
        if condition.record.value() in inputs:
            inputs[condition.record.value()] = {
                "tag":
                condition.tag.value(),
                "connect": ("pro" if not condition.hasParameter("connect") else
                            condition.connect.value())
            }

    inputs_from_gt = [record for record in inputs if inputs[record] is None]
    inputs.update(
        mps_tools.get_tags(cms_process.GlobalTag.globaltag.value(),
                           inputs_from_gt))

    if first_run != iovs[0]:  # simple consistency check
        if iovs[0] == 1 and len(iovs) == 1:
            print "Single IOV output detected in configuration and",
            print "'FirstRunForStartGeometry' is not 1."
            print "Creating single IOV output from input conditions in run",
            print str(first_run) + "."
            for inp in inputs:
                inputs[inp]["problematic"] = True
        else:
            print "Value of 'FirstRunForStartGeometry' has to match first",
            print "defined output IOV:",
            print first_run, "!=", iovs[0]
            sys.exit(1)

    for inp in inputs.itervalues():
        inp["iovs"] = mps_tools.get_iovs(inp["connect"], inp["tag"])

    # check consistency of input with output
    problematic_gt_inputs = {}
    input_indices = {
        key: len(value["iovs"]) - 1
        for key, value in inputs.iteritems()
    }
    for iov in reversed(iovs):
        for inp in inputs:
            if inputs[inp].pop("problematic", False):
                problematic_gt_inputs[inp] = inputs[inp]
            if inp in problematic_gt_inputs: continue
            if input_indices[inp] < 0:
                print "First output IOV boundary at run", iov,
                print "is before the first input IOV boundary at",
                print inputs[inp]["iovs"][0], "for '" + inp + "'."
                print "Please check your run range selection."
                sys.exit(1)
            input_iov = inputs[inp]["iovs"][input_indices[inp]]
            if iov < input_iov:
                if inp in inputs_from_gt:
                    problematic_gt_inputs[inp] = inputs[inp]
                    print "Found problematic input taken from global tag."
                    print "Input IOV boundary at run", input_iov,
                    print "for '" + inp + "' is within output IOV starting with",
                    print "run", str(iov) + "."
                    print "Deriving an alignment with coarse IOV granularity",
                    print "starting from finer granularity leads to wrong",
                    print "results."
                    print "A single IOV input using the IOV of",
                    print "'FirstRunForStartGeometry' (" + str(
                        first_run) + ") is",
                    print "automatically created and used."
                    continue
                print "Found input IOV boundary at run", input_iov,
                print "for '" + inp + "' which is within output IOV starting with",
                print "run", str(iov) + "."
                print "Deriving an alignment with coarse IOV granularity",
                print "starting from finer granularity leads to wrong results."
                print "Please check your run range selection."
                sys.exit(1)
            elif iov == input_iov:
                input_indices[inp] -= 1

    # check consistency of 'TrackerAlignmentRcd' with other inputs
    input_indices = {
        key: len(value["iovs"]) - 1
        for key, value in inputs.iteritems()
        if (key != "TrackerAlignmentRcd") and (
            inp not in problematic_gt_inputs)
    }
    for iov in reversed(inputs["TrackerAlignmentRcd"]["iovs"]):
        for inp in input_indices:
            input_iov = inputs[inp]["iovs"][input_indices[inp]]
            if iov < input_iov:
                print "Found input IOV boundary at run", input_iov,
                print "for '" + inp + "' which is within 'TrackerAlignmentRcd'",
                print "IOV starting with run", str(iov) + "."
                print "Deriving an alignment with inconsistent IOV boundaries",
                print "leads to wrong results."
                print "Please check your input IOVs."
                sys.exit(1)
            elif iov == input_iov:
                input_indices[inp] -= 1

    print "IOV consistency check successful."
    print "-" * 60

    return problematic_gt_inputs
Example #3
0
def check_iov_definition(cms_process, first_run):
    """
    Check consistency of input alignment payloads and IOV definition.
    Returns a dictionary with the information needed to override possibly
    problematic input taken from the global tag.

    Arguments:
    - `cms_process`: cms.Process object containing the CMSSW configuration
    - `first_run`: first run for start geometry
    """

    print "Checking consistency of IOV definition..."
    iovs = mps_tools.make_unique_runranges(cms_process.AlignmentProducer)

    inputs = {
        "TrackerAlignmentRcd": None,
        "TrackerSurfaceDeformationRcd": None,
        "TrackerAlignmentErrorExtendedRcd": None,
    }

    for condition in cms_process.GlobalTag.toGet.value():
        if condition.record.value() in inputs:
            inputs[condition.record.value()] = {
                "tag": condition.tag.value(),
                "connect": ("pro"
                            if not condition.hasParameter("connect")
                            else condition.connect.value())
            }

    inputs_from_gt = [record for record in inputs if inputs[record] is None]
    inputs.update(mps_tools.get_tags(cms_process.GlobalTag.globaltag.value(),
                                     inputs_from_gt))


    if first_run != iovs[0]:     # simple consistency check
        if iovs[0] == 1 and len(iovs) == 1:
            print "Single IOV output detected in configuration and",
            print "'FirstRunForStartGeometry' is not 1."
            print "Creating single IOV output from input conditions in run",
            print str(first_run)+"."
            for inp in inputs: inputs[inp]["problematic"] = True
        else:
            print "Value of 'FirstRunForStartGeometry' has to match first",
            print "defined output IOV:",
            print first_run, "!=", iovs[0]
            sys.exit(1)


    for inp in inputs.itervalues():
        inp["iovs"] = mps_tools.get_iovs(inp["connect"], inp["tag"])

    # check consistency of input with output
    problematic_gt_inputs = {}
    input_indices = {key: len(value["iovs"]) -1
                     for key,value in inputs.iteritems()}
    for iov in reversed(iovs):
        for inp in inputs:
            if inputs[inp].pop("problematic", False):
                problematic_gt_inputs[inp] = inputs[inp]
            if inp in problematic_gt_inputs: continue
            if input_indices[inp] < 0:
                print "First output IOV boundary at run", iov,
                print "is before the first input IOV boundary at",
                print inputs[inp]["iovs"][0], "for '"+inp+"'."
                print "Please check your run range selection."
                sys.exit(1)
            input_iov = inputs[inp]["iovs"][input_indices[inp]]
            if iov < input_iov:
                if inp in inputs_from_gt:
                    problematic_gt_inputs[inp] = inputs[inp]
                    print "Found problematic input taken from global tag."
                    print "Input IOV boundary at run",input_iov,
                    print "for '"+inp+"' is within output IOV starting with",
                    print "run", str(iov)+"."
                    print "Deriving an alignment with coarse IOV granularity",
                    print "starting from finer granularity leads to wrong",
                    print "results."
                    print "A single IOV input using the IOV of",
                    print "'FirstRunForStartGeometry' ("+str(first_run)+") is",
                    print "automatically created and used."
                    continue
                print "Found input IOV boundary at run",input_iov,
                print "for '"+inp+"' which is within output IOV starting with",
                print "run", str(iov)+"."
                print "Deriving an alignment with coarse IOV granularity",
                print "starting from finer granularity leads to wrong results."
                print "Please check your run range selection."
                sys.exit(1)
            elif iov == input_iov:
                input_indices[inp] -= 1

    # check consistency of 'TrackerAlignmentRcd' with other inputs
    input_indices = {key: len(value["iovs"]) -1
                     for key,value in inputs.iteritems()
                     if (key != "TrackerAlignmentRcd")
                     and (inp not in problematic_gt_inputs)}
    for iov in reversed(inputs["TrackerAlignmentRcd"]["iovs"]):
        for inp in input_indices:
            input_iov = inputs[inp]["iovs"][input_indices[inp]]
            if iov < input_iov:
                print "Found input IOV boundary at run",input_iov,
                print "for '"+inp+"' which is within 'TrackerAlignmentRcd'",
                print "IOV starting with run", str(iov)+"."
                print "Deriving an alignment with inconsistent IOV boundaries",
                print "leads to wrong results."
                print "Please check your input IOVs."
                sys.exit(1)
            elif iov == input_iov:
                input_indices[inp] -= 1

    print "IOV consistency check successful."
    print "-"*60

    return problematic_gt_inputs