Skip to content
Snippets Groups Projects
testFTSW.py 1.74 KiB
from lli import mem_multi as mem

nErr = 0 

import subprocess, random

def resetCounter():
    mem.write( 0 , 0x00050100 , 0 )
    mem.write( 0 , 0x00050100 , 2 )
    mem.write( 0 , 0x00050100 , 0 )

def readCounter(): 
    status, val = mem.read( 0 , 0x00050120 ) 
    return ( val & 0x1FFE0000 ) >> 17

def readRunNumber(): 
    status, val = mem.read( 0 , 0x00050180 )
    return ( val & 0xFF00 ) >> 8 | ( val & 0x00FF ) << 8

import socket
hname = socket.gethostname()

for nev in range( 100 ): 
    ntrig = random.randint(1,1000)
    resetCounter()
    outputString = ''
    # Send trigger (adapt this line to your system)
    if ( hname == 'belle2daq.local' ):
        outputString = subprocess.check_output( "ssh vme \"trigft -80 pulse 1000 {0}\"".format(ntrig) , shell=True) ### ADD this to suppress output >/dev/null 2>&1" )
    else:   ### KEK 
        outputString = subprocess.check_output( "ssh ttd3 \"trigft -23 pulse 1000 {0}\"".format(ntrig) , shell=True)

    if not 'run' in outputString:
        print "Bad FTSW command" 
        nErr = nErr + 1 
        continue

    runnumber = int( outputString.partition('run')[2].lstrip().split()[0] )

    # wait for data to arrive
    size = 0
    ## temporisation of 2s
    import time
    time.sleep( 2 )

    count = readCounter() 
    if count != ntrig: 
        print 'Error: {0} trigger received, {1} sent'.format( count , ntrig )
        nErr = nErr + 1

    runn = readRunNumber()
    if runn != runnumber:
        print 'Error: {0} run number received, {1} expected'.format( runn , runnumber )
        nErr = nErr + 1

    print 'Event number = {0}, run number = {1}, number of triggers sent = {2}, number of triggers received = {3}'.format(nev,runn,ntrig,count)


print 'number of errors = {0}'.format( nErr )