コード例 #1
0
def addFolderUpdate(event):
    """Add COOL folder update to event"""

    ctp_robs = [
        rob for rob in event if rob.source_id().subdetector_id() ==
        eformat.helper.SubDetector.TDAQ_CTP
    ]

    if len(ctp_robs) == 0:
        log.error("Cannot find CTP ROB in event")
        return event

    # Copy event except CTP ROBs
    new_event = eformat.write.FullEventFragment()
    new_event.copy_header(event)
    for r in event:
        if r.source_id().subdetector_id(
        ) != eformat.helper.SubDetector.TDAQ_CTP:
            new_event.append(eformat.write.ROBFragment(r))

    # Set the CTP extra payload
    for rob in ctp_robs:
        x = CTPfragment.ExtraPayload()  # start from empty payload object
        for f in folderList:
            x.updateFolder(f)
        new_ctp_rob = CTPfragment.setHltExtraPayloadWords(
            rob, [d for d in x.serialize()])
        new_event.append(eformat.write.ROBFragment(new_ctp_rob))

    return new_event
コード例 #2
0
def modify(event):

    if event.lvl1_id() == Store.currentL1ID:
        log.debug('Already executed once on this event')
        return event

    Store.eventCounter += 1
    Store.currentL1ID = event.lvl1_id()
    if (Store.eventCounter % Config.eventsPerLB) == 0: Store.currentLB += 1

    newevt = event if isinstance(event, eformat.write.FullEventFragment
                                 ) else eformat.write.FullEventFragment(event)

    # Find CTP ROB
    ctp_robs = [rob for rob in newevt.children() \
                if rob.source_id().subdetector_id() == helper.SubDetector.TDAQ_CTP]

    # Modify LB in CTP fragmnet
    for ctp_rob in ctp_robs:
        CTPfragment.setLumiBlock(ctp_rob, Store.currentLB)

    # Set LB in event object header
    newevt.lumi_block(Store.currentLB)

    log.info("Event %4d, L1ID %10d assigned LB = %d" %
             (Store.eventCounter, event.lvl1_id(), Store.currentLB))

    return newevt if isinstance(
        event, eformat.write.FullEventFragment) else newevt.readonly()
コード例 #3
0
def CTP_Info(event, module_id=1):
    ctp_robs = [rob for rob in event.children() \
                if rob.source_id().subdetector_id() == eformat.helper.SubDetector.TDAQ_CTP \
                and rob.source_id().module_id()==module_id]

    if len(ctp_robs) == 0:
        print "No CTP ROB found"

    for rob in ctp_robs:
        x = CTPfragment.getExtraPayloadObject(rob)
        folderUpdates = CTPfragment.getFolderUpdates(x)
        upd = ''.join([
            '[%d,%d]' % (f.second.folderIndex, f.second.lumiBlock)
            for f in folderUpdates
        ])
        print "ROB 0x%0x, L1ID %10d, LB %4d, Version %d, Bunch %d, HLT counter: %3d, Payload #%d %s L1PSK %d BGK %d COOLUPD %s" % (
            rob.source_id(), event.lvl1_id(), event.lumi_block(),
            CTPfragment.ctpFormatVersion(rob),
            CTPfragment.lvl1AcceptBunch(rob), CTPfragment.hltCounter(rob),
            CTPfragment.numberHltExtraPayloadWords(rob),
            CTPfragment.hltExtraPayloadWords(rob), x.getL1PSK(), x.getBGK(),
            upd)
        for w in ['TBP', 'TAP', 'TAV']:
            items = CTPfragment.decodeTriggerBits(
                CTPfragment.getTriggerWords(rob, w))
            print "ROB 0x%0x, %s: %s" % (rob.source_id(), w,
                                         printL1Items(items, smk))
コード例 #4
0
def Lvl1_Info(event):
    info = event.lvl1_trigger_info()
    nwords = len(info) / 3  # TBP,TAP,TAV
    return [
        CTPfragment.decodeTriggerBits(info[i * nwords:(i + 1) * nwords])
        for i in range(3)
    ]
コード例 #5
0
def modify(event):
    from TrigByteStreamTools import CTPfragment

    if Store.eventCounter == 0:
        Store.currentLB = Config.firstLB

    newevt = event if isinstance(event, eformat.write.FullEventFragment
                                 ) else eformat.write.FullEventFragment(event)
    Store.eventCounter += 1

    if Config.eventsPerLB is not None:
        Store.currentLB = Config.firstLB + Config.incLB * (
            (Store.eventCounter - 1) // Config.eventsPerLB)

        # Find CTP ROB
        ctp_robs = [
            rob for rob in newevt.children()
            if rob.source_id().subdetector_id() == helper.SubDetector.TDAQ_CTP
        ]

        # Modify LB in CTP fragmnet
        for ctp_rob in ctp_robs:
            CTPfragment.setLumiBlock(ctp_rob, Store.currentLB)

        # Set LB in event header
        newevt.lumi_block(Store.currentLB)

    # Set run number
    if Config.runNumber is not None:
        newevt.run_no(Config.runNumber)

    # Modify event time stamp
    if Config.bc_sec is not None:
        newevt.bc_time_seconds(Config.bc_sec)
        newevt.bc_time_nanoseconds(0)

    log.info(
        "Event %4d, L1ID %10d assigned LB = %d, run = %d, bc_time_sec = %d",
        Store.eventCounter, newevt.lvl1_id(), newevt.lumi_block(),
        newevt.run_no(), newevt.bc_time_seconds())

    return newevt if isinstance(
        event, eformat.write.FullEventFragment) else newevt.readonly()
コード例 #6
0
def modify(event):

    event = eformat.write.FullEventFragment(event)
    
    # Modify LB and HLT counter in CTP fragment
    newevt = trigbs_replaceLB.modify(event)
    lb = newevt.lumi_block()

    # Set new prescale key
    if lb in Config.hltCounterChange and psk!=None:
        Store.lastCounterChange = Config.hltCounterChange.pop(lb)
        writePSK(Store.lastCounterChange, psk.next())


    # Find CTP ROBs
    ctp_robs = [rob for rob in newevt.children() if rob.source_id().subdetector_id() == eformat.helper.SubDetector.TDAQ_CTP]

    for ctp_rob in ctp_robs:
        CTPfragment.setHltCounter(ctp_rob, Store.lastCounterChange)
    
    return newevt.readonly()
コード例 #7
0
def modify_general(**kwargs):
    """Prescale L1 items in CTP fragment used by HLT"""
    global prescales

    if prescales is None:
        prescales = loadPrescales(kwargs['configuration'])

    event = kwargs["event"]

    # Set seed based on event time stamp to make it reproducible
    seed = '%s%s' % (event.bc_time_seconds(), event.bc_time_nanoseconds())
    random.seed(zlib.crc32(seed))

    new_event = eformat.write.FullEventFragment()
    new_event.copy_header(event)
    for rob in event:
        if rob.source_id() != eformat.helper.SourceIdentifier(
                eformat.helper.SubDetector.TDAQ_CTP, 1):
            new_event.append_unchecked(rob)
        else:
            data = [d for d in rob.rod_data()]
            v = CTPfragment.ctpFormatVersion(rob)
            TBPpos = CTPfragment._versioned(CTPdataformat, 'TBPpos', v)
            TBPwords = CTPfragment._versioned(CTPdataformat, 'TBPwords', v)
            TAVpos = CTPfragment._versioned(CTPdataformat, 'TAVpos', v)

            L1TBP = CTPfragment.decodeTriggerBits(data[TBPpos:TBPpos +
                                                       TBPwords])
            log.debug('L1TBP: %s', L1TBP)
            newL1TAV = []
            for ctp in L1TBP:
                if prescales[ctp] <= 0:
                    continue
                if random.uniform(0, prescales[ctp]) > 1:
                    continue
                newL1TAV.append(ctp)

            log.debug('New L1TAV: %s', newL1TAV)
            newL1TAVBits = CTPfragment.encodeTriggerBits(newL1TAV, TBPwords)
            for i, value in enumerate(newL1TAVBits):
                data[TAVpos + i] = value

            # Write new CTP ROB
            newrob = eformat.write.ROBFragment(rob)
            newrob.rod_data(data)
            new_event.append(newrob)
            # Update event header
            l1bits = [b for b in event.lvl1_trigger_info()]
            new_event.lvl1_trigger_info(l1bits[0:TBPwords] +
                                        data[TAVpos:TAVpos + TBPwords] * 2)

    return new_event.readonly()
コード例 #8
0
def modify(event):
    event = eformat.write.FullEventFragment(event)

    # Modify LB and HLT counter in CTP fragment
    newevt = trigbs_modifyEvent.modify(event)
    lb = newevt.lumi_block()

    # Write conditions update into CTP fragment
    if lb in Config.lb_updateBeamspot:
        lb_for_update, status = Config.lb_updateBeamspot.pop(lb)

        fe = CTPfragment.FolderEntry()
        fe.folderIndex = 0  # /Indet/Onl/Beampos
        fe.lumiBlock = lb_for_update
        folderList.append(fe)
        log.info('Added COOL folder update to event: folderIndex=%d, LB=%d',
                 fe.folderIndex, fe.lumiBlock)

    return addFolderUpdate(newevt).readonly()
コード例 #9
0
def modify(event):
    event = eformat.write.FullEventFragment(event)

    # Modify LB and HLT counter in CTP fragment
    newevt = trigbs_replaceLB.modify(event)
    lb = newevt.lumi_block()

    # Set new beamspot (randomized by LB number)
    if lb in Config.lb_updateBeamspot:
        lb_for_update, status = Config.lb_updateBeamspot.pop(lb)
        setBeamSpot(newevt.run_no(), lb_for_update, lb / 100.0, 1 + lb / 100.0,
                    -4 - lb / 10.0, status)

        fe = CTPfragment.FolderEntry()
        fe.folderIndex = 0  # /Indet/Onl/Beampos
        fe.lumiBlock = lb_for_update
        folderList.append(fe)
        log.info('Added COOL folder update to event: folderIndex=%d, LB=%d' %
                 (fe.folderIndex, fe.lumiBlock))

    return addFolderUpdate(newevt).readonly()
コード例 #10
0
def modify(event):
    """Fills in the L1R from the most appropriate source (L1/ROS or Dummy)."""

    map = [[eformat.helper.SubDetector.TDAQ_CTP, 0, 1],
           [eformat.helper.SubDetector.TDAQ_MUON_CTP_INTERFACE, 0, 1],
           [eformat.helper.SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI, 136, 168],
           [eformat.helper.SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI, 137, 169],
           [eformat.helper.SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI, 138, 170],
           [eformat.helper.SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI, 139, 171],
           [eformat.helper.SubDetector.TDAQ_CALO_JET_PROC_ROI, 140, 172],
           [eformat.helper.SubDetector.TDAQ_CALO_JET_PROC_ROI, 141, 173]]

    DaqRobs = [None] * len(map)
    L2Robs = [None] * len(map)

    for rob in event:
        cnt = 0
        for match in map:
            if rob.source_id() == eformat.helper.SourceIdentifier(
                    match[0], match[1]):
                DaqRobs[cnt] = rob
            elif rob.source_id() == eformat.helper.SourceIdentifier(
                    match[0], match[2]):
                L2Robs[cnt] = rob
            cnt += 1

    # There are no CTP ROBs, event can not be recovered and should be skipped
    if (not DaqRobs[0]) and (not L2Robs[0]):
        logging.warning(
            ' Plugin "addL1": No DAQ CTP fragment. Event can not be recovered. Event will be skipped. L1 id = %d, Global id = %d '
            % (event.lvl1_id(), event.global_id()))
        return False

    # Workaround for corrupted events
    new_event = eformat.write.FullEventFragment()
    new_event.copy_header(event)
    for rob in event:
        new_event.append_unchecked(rob)

    for idx in range(len(map)):
        if L2Robs[idx]:
            pass
        elif DaqRobs[idx]:

            rob = eformat.write.ROBFragment(DaqRobs[idx])
            rob.source_id(
                eformat.helper.SourceIdentifier(map[idx][0], map[idx][2]))

            daq_data = [r for r in rob.rod_data()]

            if idx == 0:  #CTP DAQ ROD
                # offset to triggered bunch trigger words
                offset = CTPdataformat.NumberTimeWords + CTPfragment.lvl1AcceptBunch(
                    rob) * CTPdataformat.DAQwordsPerBunch
                # Copy leading words (once per fragment)
                data = daq_data[:CTPdataformat.NumberTimeWords]
                # Copy per bunch words
                data += daq_data[offset:offset +
                                 CTPdataformat.DAQwordsPerBunch]
                # Copy extra payload
                data += daq_data[-CTPfragment.numberExtraPayloadWords(rob):]
                rob.rod_data(data)

            elif idx == 1:  #MuCTPi DAQ ROB
                data = []
                if len(DaqRobs[idx].rod_data()) > 0:
                    muctpBC = (DaqRobs[idx].rod_data()[0] >> 18) & 7
                    for word in DaqRobs[idx].rod_data()[1:]:
                        if (word >> 14) & 7 == muctpBC and (word >> 26) & 1:
                            data += [(word & 0x3fff) |
                                     (((word >> 17) & 0x1ff) << 14)]

                if len(data) == 0:
                    rob = eformat.write.ROBFragment()
                    rob.copy_header(DaqRobs[idx])
                    rob.source_id(
                        eformat.helper.SourceIdentifier(
                            map[idx][0], map[idx][2]))
                else:
                    rob.rod_data(data)

            new_event.append(rob)
        else:
            rob = eformat.write.ROBFragment()
            rob.source_id(
                eformat.helper.SourceIdentifier(map[idx][0], map[idx][2]))
            new_event.append(rob)

    return new_event.readonly()