Beispiel #1
0
def main():
    run = 144247  # Recent run where CSC gas state was bad.
    run = 136379
    run = 155112  # Recent long run (Sat May 15th, 11am -> Sun 16th 8am), 632 lbs
    run = 156463
    #run = 155669 # MDT NConfig goes below 600
    from sys import argv
    args = argv[1:]
    if args:
        run = int(args[0])
    since, until = RunLumi(run, 0), RunLumi(run + 1, 0)

    with timer("Read LBLB"):
        lblb = fetch_iovs("LBLB", since, until, with_channel=False)
        lbtime = inverse_lblb(lblb)

    #system = SCT() # Works, very slightly discrepant for the config.
    #system = Pixels() # Works
    #system = Tile() # Works
    #system = CSC() # Needs globals fixing
    #system = TDQ() # Works, needs further testing
    #system = RPC() # Works
    #system = LAr() # Works, but produces slightly different result. Original gives:
    # DCSOFL_VAL(since=(155112:  167), until=(155112:  176), channel=215, Code=2L)

    #system = TRT() # Unresolved discrepancies: Wrong NConfig, NWorking off by one in run 155112.

    system = MDT()  # Seems to work
    #system = Magnets() # Needs to be finished
    #system = Lucid() # Needs to be written

    #print system.mapping.keys()

    with timer("Calculate result for %s" % system):
        result = system.run(lbtime)

    print "Done."
    print
    #print result[0]

    print "Run range:", since, "to", until
    print "DCSC2 intervals of validity:"
    pprint_objects(result[:30])
    print

    output_channels = system.mapping.keys()
    iovs = fetch_iovs("DCSOFL", since, until, output_channels)

    #print hex(hash(tuple(iovs))), hex(hash(tuple(result)))

    print "Original DCSC intervals of validity:"
    pprint_objects(iovs[:30])

    return

    compare_iovs(iovs, result)
def calculate_idbs(run_range):
    # List of lumiblocks to run over
    lbtime = inverse_lblb(fetch_iovs("LBLB", runs=run_range))

    idbs = IDBS()
    idbs.input_db = "COOLOFL_INDET/CONDBR2"

    result_iovs = idbs.run(lbtime)

    print "Will write the following:"
    pprint_objects(result_iovs)
    for entry in result_iovs:
        print entry.since.run, entry.since.lumi, "->", entry.until.lumi, entry.Code

    write_iovs("idbs_test.db/CONDBR2::/GLOBAL/DETSTATUS/DCSOFL", result_iovs,
               dcsofl_cool_record())
Beispiel #3
0
    def dump(self, filename=None):
        """
        Dump defects to a file given by filename or stdout if no filename given
        """

        from DQUtils.utils import pprint_objects

        if filename is not None:
            f = open(filename.replace('.db', '.txt'), "w")
            # If not defects then nothing will be in the database and we write an empty file
            if len(self.iovs):
                pprint_objects(
                    self.db.retrieve(primary_only=True, nonpresent=True), f)
            f.close()
        else:
            if len(self.iovs):
                self.iovs.pprint()
            else:
                print '\nNo DQ defects'

        #         with open(filename.replace('.db', '.txt'), "w") as f:
        #             pprint_objects(self.db.retrieve(), f)

        return
Beispiel #4
0
def go(iov, systems, db, indb, timewise=False):
    """
    Run the DCS calculator for `run` on the `systems` specified, saving the 
    result to the `database`.
    """
    since, until = iov

    with timer("Read LBLB"):
        # fetch lumi block info
        lblb = fetch_iovs("LBLB",
                          since,
                          until,
                          with_channel=False,
                          database='COOLONL_TRIGGER/%s' % indb)
        assert lblb, "No luminosity blocks for desired range. [%s, %s)" % (
            since, until)

        # lumi block time info
        lbtime = inverse_lblb(lblb)

        # run_iovs is....?
        if timewise:
            run_iovs = run_iovs_from_lblb(lbtime)
        else:
            run_iovs = run_iovs_from_lblb(lblb)

    log.debug("Will process %i LBs over %i runs", len(lblb), len(run_iovs))

    log.info("DCSC2 will run over range: %r %s", tuple(run_iovs.range_iov),
             "(%i lbs)" % len(lblb))

    # Initialize the system objects
    # This changes 'systems' from a list of types to a list of subdetector objects
    systems = [
        system() for system in systems
        if not getattr(system, "__DISABLED__", False)
    ]

    # Run systems sequentially for this range
    result_iovs = run_sequential(systems, lbtime, run_iovs)

    # Run parallel is broken because of the use of closures to implement the
    # defect translation.
    #result_iovs = run_parallel(systems, lbtime, run_iovs, parallel)

    if log.isEnabledFor(logging.DEBUG):
        pprint_objects(result_iovs)

    log.info("Calculation complete")

    if db != "None":
        with timer("write result (%i iovs)" % len(result_iovs)):
            log.debug("Writing result (%i iovs)", len(result_iovs))
            defect_iovs = filter(lambda iov: isinstance(iov, DefectIOV),
                                 result_iovs)
            dcsofl_iovs = filter(lambda iov: not isinstance(iov, DefectIOV),
                                 result_iovs)
            if len(defect_iovs) > 0:
                ddb = DefectsDB(db, read_only=False, create=True)
                defect_names = set(i.channel for i in defect_iovs)
                for defect in defect_names:
                    if defect in ddb.defect_id_map:
                        continue
                    ddb.create_defect(defect, "Created by DCSCalculator2")
                with ddb.storage_buffer:
                    for iov in defect_iovs:
                        ddb.insert(iov.channel, iov.since, iov.until,
                                   iov.comment, 'sys:defectcalculator',
                                   iov.present)
            #disable DCSOFL
            #dest = "%s::/GLOBAL/DETSTATUS/DCSOFL" % db
            #write_iovs(dest, dcsofl_iovs, dcsofl_cool_record(), create=True)

    args = len(result_iovs), hash(result_iovs)
    log.info("Success. Calculated %i iovs. Result hash: 0x%0x8." % args)