Example #1
0
def set_calib(db_url, instrument, seg, alias, calib):

    dict = json.loads(calib)

    create = True
    dbname = 'configDB'

    mycdb = cdb.configdb(db_url,
                         instrument,
                         create,
                         root='configDB',
                         user=instrument + 'opr',
                         password='******')
    mycdb.add_device_config('hsdcal')

    top = cdict()

    top.setAlg('calib', [0, 0, 0])

    help_str = "No help at this time"
    top.set("help:RO", help_str, 'CHARSTR')

    for k, v in dict['expert'].items():
        top.set("expert." + k, v, 'UINT16')

    mycdb.add_alias(alias)

    name = seg.split('_')[0]
    segn = int(seg.split('_')[1])
    top.setInfo('hsd', name, segn, 'serial1234', 'No comment')
    mycdb.modify_device(alias, top)
Example #2
0
    def update(self):
        global countdn
        # check for config save
        if countdn > 0:
            countdn -= 1
            if countdn == 0 and self._db:
                # save config
                db_url, db_name, db_instrument, db_alias = self._db.split(
                    ',', 4)
                mycdb = cdb.configdb(db_url, db_instrument, True, db_name)
                mycdb.add_device_config('xpm')

                top = cdict()
                top.setInfo('xpm', self._name, None, 'serial1234',
                            'No comment')
                top.setAlg('config', [0, 0, 0])

                lock.acquire()
                top.set('XTPG.CuDelay', self._xpm.CuGenerator.cuDelay.get(),
                        'UINT32')
                top.set('XTPG.CuBeamCode',
                        self._xpm.CuGenerator.cuBeamCode.get(), 'UINT8')
                top.set('XTPG.CuInput',
                        self._xpm.AxiSy56040.OutputConfig[0].get(), 'UINT8')
                v = []
                for i in range(8):
                    self._xpm.XpmApp.partition.set(i)
                    v.append(self._xpm.XpmApp.l0Delay.get())
                top.set('PART.L0Delay', v, 'UINT32')
                lock.release()

                if not db_alias in mycdb.get_aliases():
                    mycdb.add_alias(db_alias)
                mycdb.modify_device(db_alias, top)
Example #3
0
def epixhr2x2_scan_keys(update):
    logging.debug('epixhr2x2_scan_keys')
    global ocfg
    global base
    global segids

    cfg = {}
    copy_reconfig_keys(cfg, ocfg, json.loads(update))
    # Apply to expert
    pixelMapChanged = user_to_expert(base, cfg, full=False)
    #  Retain mandatory fields for XTC translation
    for key in ('detType:RO', 'detName:RO', 'detId:RO', 'doc:RO', 'alg:RO'):
        copy_config_entry(cfg, ocfg, key)
        copy_config_entry(cfg[':types:'], ocfg[':types:'], key)

    topname = cfg['detName:RO'].split('_')

    scfg = {}

    #  Rename the complete config detector
    scfg[0] = cfg.copy()
    scfg[0]['detName:RO'] = topname[0] + 'hw_' + topname[1]

    if pixelMapChanged:
        gain_mode = cfg['user']['gain_mode']
        if gain_mode == 5:
            pixelConfigUsr = np.array(cfg['user']['pixel_map'], dtype=np.uint8)
        else:
            mapv, trbit = gain_mode_map(gain_mode)
            pixelConfigUsr = np.zeros(
                (2 * elemRowsD, 2 * elemCols), dtype=np.uint8) + mapv

        pixelConfigMap = user_to_rogue(pixelConfigUsr)
        trbit = [
            cfg['expert']['EpixHR'][f'Hr10kTAsic{i}']['trbit']
            for i in range(4)
        ]

        cbase = base['cam']
        for seg in range(1):
            id = segids[seg]
            top = cdict()
            top.setAlg('config', [2, 0, 0])
            top.setInfo(detType='epixhr2x2',
                        detName=topname[0],
                        detSegm=int(topname[1]),
                        detId=id,
                        doc='No comment')
            top.set('asicPixelConfig', pixelConfigUsr)
            top.set('trbit', trbit, 'UINT8')
            scfg[seg + 1] = top.typed_json()

    result = []
    for i in range(len(scfg)):
        result.append(json.dumps(scfg[i]))

    return result
Example #4
0
    def update(self, cycle):

        #  The following section will throw an exception if the CuInput PV is not set properly
        if cycle < 10:
            print('pvseq in %d' % (10 - cycle))
        elif cycle == 10:
            self._seq = PVSeq(provider, self._name + ':SEQENG:0', self._ip,
                              Engine(0, self._xpm.SeqEng_0))

            self._pv_dumpSeq = SharedPV(initial=NTScalar('I').wrap(0),
                                        handler=CmdH(self._seq._eng.dump))
            provider.add(self._name + ':DumpSeq', self._pv_dumpSeq)

        global countdn
        # check for config save
        if countdn > 0:
            countdn -= 1
            if countdn == 0 and self._db:
                # save config
                print('Updating {}'.format(self._db))
                db_url, db_name, db_instrument, db_alias = self._db.split(
                    ',', 4)
                mycdb = cdb.configdb(db_url,
                                     db_instrument,
                                     True,
                                     db_name,
                                     user=db_instrument + 'opr',
                                     password='******')
                mycdb.add_device_config('xpm')

                top = cdict()
                top.setInfo('xpm', self._name, None, 'serial1234',
                            'No comment')
                top.setAlg('config', [0, 0, 0])

                lock.acquire()
                top.set('XTPG.CuDelay', self._xpm.CuGenerator.cuDelay.get(),
                        'UINT32')
                top.set('XTPG.CuBeamCode',
                        self._xpm.CuGenerator.cuBeamCode.get(), 'UINT8')
                top.set('XTPG.CuInput',
                        self._xpm.AxiSy56040.OutputConfig[0].get(), 'UINT8')
                v = []
                for i in range(8):
                    self._xpm.XpmApp.partition.set(i)
                    v.append(self._xpm.XpmApp.l0Delay.get())
                top.set('PART.L0Delay', v, 'UINT32')
                lock.release()

                if not db_alias in mycdb.get_aliases():
                    mycdb.add_alias(db_alias)

                try:
                    mycdb.modify_device(db_alias, top)
                except:
                    pass
Example #5
0
def epixquad_scan_keys(update):
    print('epixquad_scan_keys')
    global ocfg
    global base
    global segids

    cfg = {}
    copy_reconfig_keys(cfg, ocfg, json.loads(update))
    # Apply to expert
    pixelMapChanged = user_to_expert(base, cfg, full=False)
    #  Retain mandatory fields for XTC translation
    for key in ('detType:RO', 'detName:RO', 'detId:RO', 'doc:RO', 'alg:RO'):
        copy_config_entry(cfg, ocfg, key)
        copy_config_entry(cfg[':types:'], ocfg[':types:'], key)

    topname = cfg['detName:RO'].split('_')

    scfg = {}

    #  Rename the complete config detector
    scfg[0] = cfg.copy()
    scfg[0]['detName:RO'] = topname[0] + 'hw_' + topname[1]

    if pixelMapChanged:
        a = np.array(cfg['user']['pixel_map'], dtype=np.uint8)
        pixelConfigMap = np.reshape(a, (16, 178, 192))
        trbit = [
            cfg['expert']['EpixQuad'][f'Epix10kaSaci{i}']['trbit']
            for i in range(16)
        ]

        cbase = base['cam']
        for seg in range(4):
            id = segids[seg]
            top = cdict()
            top.setAlg('config', [2, 0, 0])
            top.setInfo(detType='epix10ka',
                        detName=topname[0],
                        detSegm=seg + 4 * int(topname[1]),
                        detId=id,
                        doc='No comment')
            top.set('asicPixelConfig',
                    pixelConfigMap[4 * seg:4 * seg + 4, :176].tolist(),
                    'UINT8')
            top.set('trbit', trbit[4 * seg:4 * seg + 4], 'UINT8')
            scfg[seg + 1] = top.typed_json()

    result = []
    for i in range(len(scfg)):
        result.append(json.dumps(scfg[i]))

    return result
Example #6
0
def epix100_cdict():

    top = cdict()
    top.setAlg('config', [2,0,0])

    #top.set("firmwareBuild:RO"  , "-", 'CHARSTR')
    #top.set("firmwareVersion:RO",   0, 'UINT32')

    #help_str  = "-- user interface --"
    #help_str += "\nstart_ns     : exposure start (nanoseconds)"
    #help_str += "\ngate_ns     : exposure time (nanoseconds)"
    #top.set("help.user:RO", help_str, 'CHARSTR')

    # set to 88000 to get triggerDelay larger than zero when
    # L0Delay is 81 (used by TMO)
    top.set("user.start_ns" , 88000, 'UINT32') # taken from epixHR
    top.set("user.gate_ns" , 154000, 'UINT32') # taken from lcls1 xpptut15 run 260
    # add daqtriggerdelay and runtriggerdelay?

    # timing system
    top.set('expert.DevPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.PauseThreshold',16,'UINT32')
    top.set('expert.cfgyaml:RO','NoYaml','CHARSTR')

    return top
Example #7
0
def write_to_daq_config_db(args):

    #database contains collections which are sets of documents (aka json objects).
    #each type of device has a collection.  The elements of that collection are configurations of that type of device.
    #e.g. there will be OPAL, EVR, and YUNGFRAU will be collections.  How they are configured will be a document contained within that collection
    #Each hutch is also a collection.  Documents contained within these collection have an index, alias, and list of devices with configuration IDs
    #How is the configuration of a state is described by the hutch and the alias found.  E.g. TMO and BEAM.  TMO is a collection.
    #BEAM is an alias of some of the documents in that collection. The document with the matching alias and largest index is the current
    #configuration for that hutch and alias.
    #When a device is configured, the device has a unique name OPAL7.  Need to search through document for one that has an NAME called OPAL7.  This will have
    #have two fields "collection" and ID field (note how collection here is a field. ID points to a unique document).  This collection field and
    #ID point to the actuall Mongo DB collection and document

    create = True
    dbname = 'configDB'  #this is the name of the database running on the server.  Only client care about this name.

    mycdb = cdb.configdb(
        'https://pswww.slac.stanford.edu/ws-auth/devconfigdb/ws/',
        args.inst,
        create,
        root=dbname,
        user=args.user,
        password=args.password)
    mycdb.add_alias(args.alias)
    mycdb.add_device_config('timetool')

    top = cdict()
    top.setInfo('timetool', args.name, args.segm, args.id, 'No comment')
    top.setAlg('config', [2, 0, 0])

    top.set("firmwareBuild:RO", "-", 'CHARSTR')
    top.set("firmwareVersion:RO", 0, 'UINT32')

    help_str = "-- user interface --"
    help_str += "\nstart_ns : nanoseconds from fiducial to exposure start"
    help_str += "\ngate_ns  : nanoseconds from exposure start to stop"
    top.set("help:RO", help_str, 'CHARSTR')

    #Create a user interface that is an abstraction of the common inputs
    top.set("user.start_ns", 107649, 'UINT32')
    top.set("user.gate_ns", 1000, 'UINT32')
    #top.set("user.raw.prescale"    , 2, 'UINT32')
    #top.set("user.fex.prescale_bkg", 3, 'UINT32')
    #top.set("user.fex.prescale_bkg", 3, 'UINT32')
    #top.set("user.fex.fir_coeff0"", 1., 'DOUBLE')

    #There are many rogue fields, but only a handful need to be configured.  what are they?
    #1)  the FIR coefficients.  after accounting for parabolic fitting detection
    #2)  start and stop?
    #3)  main by pass. (still isn't working with FEX in hardware, but does in simulation.)
    #4)  all prescalers.  This has potential to crash linux kernel during hi rate and low prescaling.  How to add protection?  Slow ramp?
    #5)  low pass on background
    #6)  op code (now called readout group). there's no rogue counter part of this yet.
    #7)  the load coefficients bit needs to set to one for the FIR coefficients to be written.
    #8)  camera rate and soft or hard trigger. The soft trigger is for offline testing.  For users or just for me?
    #9)  the batcher bypass so soft trigger doesn't halt.

    # timing system
    top.set(
        'expert.TimeToolKcu1500.Kcu1500Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer[0].PauseThreshold',
        16, 'UINT32')
    top.set(
        'expert.TimeToolKcu1500.Kcu1500Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer[0].TriggerDelay',
        42, 'UINT32')
    top.set(
        'expert.TimeToolKcu1500.Kcu1500Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer[0].Partition',
        0, 'UINT32')

    # prescaling
    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Prescale.DialInPreScaling",
        2, 'UINT32')  # prescaled raw data
    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Fex.background_prescaler.DialInPreScaling",
        3, 'UINT32'
    )  # prescaled raw backgrounds (may consider accumulated backgrounds instead)

    # initial fir filter
    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Fex.FIR.CoefficientSet0",
        "7f7f7f7f", 'CHARSTR')  #high part of step
    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Fex.FIR.CoefficientSet1",
        "7f7f7f7f", 'CHARSTR')  #high part of step
    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Fex.FIR.CoefficientSet2",
        "7f7f7f7f", 'CHARSTR')  #high part of step
    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Fex.FIR.CoefficientSet3",
        "7f7f7f7f", 'CHARSTR')  #high part of step
    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Fex.FIR.CoefficientSet4",
        "81818181", 'CHARSTR')  #low  part of step
    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Fex.FIR.CoefficientSet5",
        "81818181", 'CHARSTR')  #low  part of step
    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Fex.FIR.CoefficientSet6",
        "81818181", 'CHARSTR')  #low  part of step
    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Fex.FIR.CoefficientSet7",
        "81818181", 'CHARSTR')  #low  part of step

    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Fex.FIR.LoadCoefficients",
        "1", 'CHARSTR'
    )  #low  part of step.  Having a value of 1  causes a segfault in pgpread_timetool.cc.  But not in tt_config.py.

    # time constants
    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Fex.FrameIIR.TimeConstant",
        8, 'UINT32')

    # subtraction enabled
    top.set(
        "expert.TimeToolKcu1500.Application.AppLane[0].Fex.FrameSubtractor.SubtractionActive",
        0, 'UINT32')  #turn background subtract on

    # Feb[0] refers to pgp lane, Ch[0][,1] refers to camera link channel from Feb (these should be abstracted)
    # UartOpal1000 is camType; sets serial registers
    # ClinkTop.LinkMode is Base,Medium,Full,Deca
    # ClinkTop.DataMode is 8b,10b,12b,14b,16b,24b,30b,36b
    # ClinkTop.FrameMode is None,Line,Frame
    # ClinkTop.TapCount
    # All serial commands are enumerated as registers
    top.set('expert.ClinkFeb[0].TrigCtrl[0].EnableTrig', 1,
            'UINT8')  # rogue wants 'bool'
    top.set('expert.ClinkFeb[0].TrigCtrl[0].InvCC', 0,
            'UINT8')  # rogue wants 'bool'
    top.set('expert.ClinkFeb[0].TrigCtrl[0].TrigMap', 0,
            'UINT32')  # ChanA/ChanB
    top.set('expert.ClinkFeb[0].TrigCtrl[0].TrigMask', 1, 'UINT32')  # CC1
    top.set('expert.ClinkFeb[0].TrigCtrl[0].TrigPulseWidth', 32.768, 'FLOAT')

    top.set("expert.ClinkFeb[0].ClinkTop.PllConfig[0]", '80MHz', 'CHARSTR')
    top.set("expert.ClinkFeb[0].ClinkTop.PllConfig[1]", '80MHz', 'CHARSTR')
    top.set("expert.ClinkFeb[0].ClinkTop.PllConfig[2]", '80MHz', 'CHARSTR')

    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].LinkMode", 3,
            'UINT32')  # Full mode
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].DataMode", 1, 'UINT32')  # 8-bit
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].FrameMode", 1, 'UINT32')  # Line
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].TapCount", 8, 'UINT32')  #
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].DataEn", 1,
            'UINT8')  # rogue wants 'bool'
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].Blowoff", 0,
            'UINT8')  # rogue wants 'bool'
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].BaudRate", 9600,
            'UINT32')  # bps
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].SerThrottle", 30000, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].SwControlValue", 0,
            'UINT32')  # Frame
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].SwControlEn", 0,
            'UINT32')  # Frame

    # Piranha Settings
    #commands can be sent manually using cl.ClinkFeb0.ClinkTop.Ch0.UartPiranha4._tx.sendString('GCP')
    #to manually query a camera hardware setting cl.ClinkFeb0.ClinkTop.Ch0.UartPiranha4._tx.sendString('get stm')

    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.CLS", 0, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.CLM", 2, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.DST", 0, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.FFM", 0, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.FRS", 2, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.LPC", 0, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.ROI[0]", 1,
            'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.ROI[1]", 2048,
            'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SAC", 1, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SAD[0]", 1,
            'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SAD[1]", 1,
            'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SAD[2]", 2048,
            'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SAM", 0, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SBH", 1, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SBR", 9600,
            'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SBV", 1, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SCD", 0, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SEM", 1, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SET", 5000,
            'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SMM", 0, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SPF", 0, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SSB", 0, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SSF", 2, 'UINT32')
    #top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SSG",1,'UINT32') # requires two arguments (selector,gain)
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.STG", 2, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.STM", 1, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.SVM", 0, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.USD", 1, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.USL", 1, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartPiranha4.USS", 1, 'UINT32')

    #the object hierarchy paths (e.g. cl.TimeToolKcu1500.Application.AppLane[0]... yadayadayada) for a device can be found by implementing
    #pr.generateAddressMap where pr comes from "import rogue as pr".  For this to work, one has to be logged onto the machine hosting the firmware
    #that interacts with rogue.  This particular register map can be found in the lcls2-pcie-apps directory cloned from https://github.com/slaclab/lcls2-pcie-apps.

    mycdb.modify_device(args.alias, top)
Example #8
0
def epixhr2x2_config(base, connect_str, cfgtype, detname, detsegm, rog):
    global ocfg
    global group
    global segids

    group = rog

    #    _checkADCs()

    #
    #  Retrieve the full configuration from the configDB
    #
    cfg = get_config(connect_str, cfgtype, detname, detsegm)
    ocfg = cfg

    #  Translate user settings to the expert fields
    writePixelMap = user_to_expert(base, cfg, full=True)

    #  Apply the expert settings to the device
    pbase = base['pci']
    pbase.StopRun()
    time.sleep(0.01)

    config_expert(base, cfg, writePixelMap)

    time.sleep(0.01)
    pbase.StartRun()

    #  Add some counter resets here
    reset_counters(base)

    #  Enable triggers to continue monitoring
    epixhr2x2_internal_trigger(base)

    #  Capture the firmware version to persist in the xtc
    cbase = base['cam']
    firmwareVersion = cbase.Core.AxiVersion.FpgaVersion.get()

    ocfg = cfg

    #
    #  Create the segment configurations from parameters required for analysis
    #
    trbit = [
        cfg['expert']['EpixHR'][f'Hr10kTAsic{i}']['trbit'] for i in range(4)
    ]

    topname = cfg['detName:RO'].split('_')

    scfg = {}
    segids = {}

    #  Rename the complete config detector
    scfg[0] = cfg.copy()
    scfg[0]['detName:RO'] = topname[0] + 'hw_' + topname[1]

    #  User pixel map is assumed to be 288x384 in standard element orientation
    gain_mode = cfg['user']['gain_mode']
    if gain_mode == 5:
        pixelConfigUsr = np.array(cfg['user']['pixel_map'], dtype=np.uint8)
    else:
        mapv, trbit = gain_mode_map(gain_mode)
        pixelConfigUsr = np.zeros(
            (2 * elemRowsD, 2 * elemCols), dtype=np.uint8) + mapv
    pixelConfigMap = user_to_rogue(pixelConfigUsr)

    for seg in range(1):
        #  Construct the ID
        #        carrierId = [ cbase.SystemRegs.CarrierIdLow [seg].get(),
        #                      cbase.SystemRegs.CarrierIdHigh[seg].get() ]
        carrierId = [0, 0]
        digitalId = [0, 0]
        analogId = [0, 0]
        id = '%010d-%010d-%010d-%010d-%010d-%010d-%010d' % (
            firmwareVersion, carrierId[0], carrierId[1], digitalId[0],
            digitalId[1], analogId[0], analogId[1])
        segids[seg] = id
        top = cdict()
        top.setAlg('config', [2, 0, 0])
        top.setInfo(detType='epixhr2x2',
                    detName=topname[0],
                    detSegm=seg + int(topname[1]),
                    detId=id,
                    doc='No comment')
        top.set('asicPixelConfig', pixelConfigUsr)
        top.set('trbit', [trbit for i in range(4)], 'UINT8')
        scfg[seg + 1] = top.typed_json()

    result = []
    for i in seglist:
        logging.debug('json seg {}  detname {}'.format(i,
                                                       scfg[i]['detName:RO']))
        result.append(json.dumps(scfg[i]))

    return result
Example #9
0
def opal_cdict():

    #database contains collections which are sets of documents (aka json objects).
    #each type of device has a collection.  The elements of that collection are configurations of that type of device.
    #e.g. there will be OPAL, EVR, and YUNGFRAU will be collections.  How they are configured will be a document contained within that collection
    #Each hutch is also a collection.  Documents contained within these collection have an index, alias, and list of devices with configuration IDs
    #How is the configuration of a state is described by the hutch and the alias found.  E.g. TMO and BEAM.  TMO is a collection.
    #BEAM is an alias of some of the documents in that collection. The document with the matching alias and largest index is the current
    #configuration for that hutch and alias.
    #When a device is configured, the device has a unique name OPAL7.  Need to search through document for one that has an NAME called OPAL7.  This will have
    #have two fields "collection" and ID field (note how collection here is a field. ID points to a unique document).  This collection field and
    #ID point to the actuall Mongo DB collection and document

    top = cdict()
    top.setAlg('config', [2, 0, 0])

    top.set("firmwareBuild:RO", "-", 'CHARSTR')
    top.set("firmwareVersion:RO", 0, 'UINT32')

    help_str = "-- user interface --"
    help_str += "\nstart_ns : nanoseconds from fiducial to exposure start"
    help_str += "\ngate_ns  : nanoseconds of exposure; rounded up to 10 microseconds"
    top.set("help:RO", help_str, 'CHARSTR')

    top.define_enum('binEnum', {'x%d' % (2**key): key for key in range(4)})

    #Create a user interface that is an abstraction of the common inputs
    top.set("user.start_ns", 92000, 'UINT32')
    top.set("user.gate_ns", 10000, 'UINT32')
    top.set("user.black_level", 32, 'UINT32')
    top.set("user.vertical_bin", 0, 'binEnum')

    # timing system
    top.set(
        'expert.ClinkPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.PauseThreshold',
        16, 'UINT32')
    top.set(
        'expert.ClinkPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.TriggerDelay',
        42, 'UINT32')
    top.set(
        'expert.ClinkPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.Partition:RO',
        0, 'UINT32')

    top.define_enum(
        'rateEnum', {
            '929kHz': 0,
            '71kHz': 1,
            '10kHz': 2,
            '1kHz': 3,
            '100Hz': 4,
            '10Hz': 5,
            '1Hz': 6
        })
    top.set(
        'expert.ClinkPcie.Hsio.TimingRx.XpmMiniWrapper.XpmMini.Config_L0Select_RateSel',
        6, 'rateEnum')

    # Feb[0] refers to pgp lane, Ch[0][,1] refers to camera link channel from Feb (these should be abstracted)
    # UartOpal1000 is camType; sets serial registers
    # ClinkTop.LinkMode is Base,Medium,Full,Deca
    # ClinkTop.DataMode is 8b,10b,12b,14b,16b,24b,30b,36b
    # ClinkTop.FrameMode is None,Line,Frame
    # ClinkTop.TapCount
    # All serial commands are enumerated as registers
    top.set('expert.ClinkFeb.TrigCtrl.EnableTrig', 1,
            'UINT8')  # rogue wants 'bool'
    top.set('expert.ClinkFeb.TrigCtrl.InvCC', 0, 'UINT8')  # rogue wants 'bool'
    top.set('expert.ClinkFeb.TrigCtrl.TrigMap', 0, 'UINT32')  # ChanA/ChanB
    top.set('expert.ClinkFeb.TrigCtrl.TrigMask', 1, 'UINT32')  # CC1
    top.set('expert.ClinkFeb.TrigCtrl.TrigPulseWidth', 32.768, 'FLOAT')

    top.set("expert.ClinkFeb.ClinkTop.PllConfig0", '80MHz', 'CHARSTR')
    top.set("expert.ClinkFeb.ClinkTop.PllConfig1", '80MHz', 'CHARSTR')
    top.set("expert.ClinkFeb.ClinkTop.PllConfig2", '80MHz', 'CHARSTR')

    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.LinkMode", 1,
            'UINT32')  # Base mode
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.DataMode", 3, 'UINT32')  # 12-bit
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.FrameMode", 2, 'UINT32')  # Frame
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.TapCount", 2, 'UINT32')  #
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.DataEn", 1,
            'UINT8')  # rogue wants 'bool'
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.Blowoff", 0,
            'UINT8')  # rogue wants 'bool'
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.BaudRate", 57600,
            'UINT32')  # bps
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.SerThrottle", 10000, 'UINT32')
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.SwControlValue", 0,
            'UINT32')  # Frame
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.SwControlEn", 0,
            'UINT32')  # Frame

    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.BL", 32,
            'UINT32')  # black level
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.GA", 100,
            'UINT32')  # digital gain, percent
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.VBIN", 0,
            'UINT32')  # vertical binning (powers-of-two)[0..3]
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.VR", 1,
            'UINT32')  # vertical remapping (top-to-bottom, left-to-right)
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.MI", 0,
            'UINT32')  # output mirroring (hor=b0, ver=b1)
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.OR", 12,
            'UINT32')  # output resolution, bits
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.TP", 0,
            'UINT32')  # test pattern on/off
    #    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.OLUTE",  0,'UINT32')  # output lookup table enable on/off (not implemented)
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.DPE", 0,
            'UINT32')  # defect pixel correction on/off
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.OVL", 1,
            'UINT32')  # overlay frame counter and integration time
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.OFS", 1,
            'UINT32')  # color cameras only
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.Red", 100,
            'UINT32')  # red gain
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.Green", 100,
            'UINT32')  # green gain
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartOpal1000.Blue", 100,
            'UINT32')  # blue gain

    return top
Example #10
0
args = parser.parse_args()

# these are the current default values, but put them here to be explicit
create = False
dbname = 'configDB'

mycdb = cdb.configdb('https://pswww.slac.stanford.edu/ws-auth/devconfigdb/ws/',
                     args.inst, create, dbname)

# this needs to be called once per detType at the
# "beginning of time" to create the collection name (same as detType
# in top.setInfo).  It doesn't hurt to call it again if the collection
# already exists, however.
mycdb.add_device_config('teb')

top = cdict()

top.setInfo('teb', args.name, args.segm, args.id, 'No comment')
top.setAlg('tebConfig', [0, 0, 1])

top.set('soname', 'libtmoTeb.so', 'CHARSTR')

# This is a required entry:
top.set('prescale', 1, 'UINT32')

top.set('persistValue', 0xdeadbeef, 'UINT32')
top.set('monitorValue', 0x12345678, 'UINT32')

mycdb.add_alias(args.alias)
mycdb.modify_device(args.alias, top)
mycdb.print_configs()
Example #11
0
def epixhr2x2_update(update):
    logging.debug('epixhr2x2_update')
    global ocfg
    global base
    ##
    ##  Having problems with partial configuration
    ##
    # extract updates
    cfg = {}
    update_config_entry(cfg, ocfg, json.loads(update))
    #  Apply to expert
    writePixelMap = user_to_expert(base, cfg, full=False)
    #  Apply config
    #    config_expert(base, cfg, writePixelMap)
    ##
    ##  Try full configuration
    ##
    #    ncfg = get_config(base['connect_str'],base['cfgtype'],base['detname'],base['detsegm'])
    ncfg = ocfg.copy()
    update_config_entry(ncfg, ocfg, json.loads(update))
    _writePixelMap = user_to_expert(base, ncfg, full=True)
    ##  This kills the asic readout
    pbase = base['pci']
    pbase.StopRun()
    time.sleep(0.01)
    config_expert(base, ncfg, _writePixelMap, secondPass=True)
    time.sleep(0.01)
    pbase.StartRun()
    ##  End of Try full

    #  Enable triggers to continue monitoring
    epixhr2x2_internal_trigger(base)

    #  Retain mandatory fields for XTC translation
    for key in ('detType:RO', 'detName:RO', 'detId:RO', 'doc:RO', 'alg:RO'):
        copy_config_entry(cfg, ocfg, key)
        copy_config_entry(cfg[':types:'], ocfg[':types:'], key)

    topname = cfg['detName:RO'].split('_')

    scfg = {}

    #  Rename the complete config detector
    scfg[0] = cfg.copy()
    scfg[0]['detName:RO'] = topname[0] + 'hw_' + topname[1]

    scfg[0] = cfg

    if writePixelMap:
        gain_mode = cfg['user']['gain_mode']
        if gain_mode == 5:
            pixelConfigUsr = np.array(cfg['user']['pixel_map'], dtype=np.uint8)
        else:
            mapv, trbit = gain_mode_map(gain_mode)
            pixelConfigUsr = np.zeros(
                (2 * elemRowsD, 2 * elemCols), dtype=np.uint8) + mapv

        pixelConfigMap = user_to_rogue(pixelConfigUsr)
        try:
            trbit = [
                cfg['expert']['EpixHR'][f'Hr10kTAsic{i}']['trbit']
                for i in range(4)
            ]
        except:
            trbit = None

        cbase = base['cam']
        for seg in range(1):
            id = segids[seg]
            top = cdict()
            top.setAlg('config', [2, 0, 0])
            top.setInfo(detType='epixhr2x2',
                        detName=topname[0],
                        detSegm=seg + int(topname[1]),
                        detId=id,
                        doc='No comment')
            top.set('asicPixelConfig', pixelConfigUsr)
            if trbit is not None:
                top.set('trbit', trbit, 'UINT8')
            scfg[seg + 1] = top.typed_json()

    result = []
    for i in range(len(scfg)):
        result.append(json.dumps(scfg[i]))

    logging.debug('update complete')

    return result
Example #12
0
def piranha4_cdict():

    #database contains collections which are sets of documents (aka json objects).
    #each type of device has a collection.  The elements of that collection are configurations of that type of device.
    #e.g. there will be OPAL, EVR, and JUNGFRAU will be collections.  How they are configured will be a document contained within that collection
    #Each hutch is also a collection.  Documents contained within these collection have an index, alias, and list of devices with configuration IDs
    #How is the configuration of a state is described by the hutch and the alias found.  E.g. TMO and BEAM.  TMO is a collection.
    #BEAM is an alias of some of the documents in that collection. The document with the matching alias and largest index is the current
    #configuration for that hutch and alias.
    #When a device is configured, the device has a unique name OPAL7.  Need to search through document for one that has an NAME called OPAL7.  This will have
    #have two fields "collection" and ID field (note how collection here is a field. ID points to a unique document).  This collection field and
    #ID point to the actuall Mongo DB collection and document

    top = cdict()
    top.setAlg('config', [2,0,0])

    top.set("firmwareBuild:RO"  , "-", 'CHARSTR')
    top.set("firmwareVersion:RO",   0, 'UINT32')

    help_str  = "-- user interface --"
    help_str += "\nstart_ns : nanoseconds from fiducial to exposure start"
    help_str += "\ngate_ns  : nanoseconds of exposure; rounded up to 10 microseconds"
    top.set("help:RO", help_str, 'CHARSTR')

    top.define_enum('clmEnum',   {'Base':0, 'Med':1, 'Full':2})
    top.define_enum('clsEnum',   {'85MHz':0, '66MHz':1})
    top.define_enum('dstEnum',   {'Line':0, 'Area':1})
    top.define_enum('binEnum',   {'1':1, '2':2})
    top.define_enum('dirEnum',   {'Fwd':0, 'Rev':1, 'Ext':2})
    top.define_enum('expEnum',   {'Int':0, 'Ext':1})
    top.define_enum('offOnEnum', {'Off':0, 'On':1})
    top.define_enum('pixEnum',   {'8_bits':0, '10_bits':1, '12_bits':2})
    top.define_enum('tpEnum',    {'Sensor_Video':0, 'Ramp':1})

    #Create a user interface that is an abstraction of the common inputs
    top.set("user.start_ns", 110000, 'UINT32')
    top.set("user.gate_ns" ,   4000, 'UINT32')
    top.set("user.black_level",   0, 'UINT32')
    top.set("user.vertical_bin",  1, 'binEnum')

    # timing system
    top.set('expert.ClinkPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.PauseThreshold',16,'UINT32')
    top.set('expert.ClinkPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.TriggerDelay',42,'UINT32')
    top.set('expert.ClinkPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.Partition:RO',0,'UINT32')

    top.define_enum('rateEnum', {'929kHz':0, '71kHz':1, '10kHz':2, '1kHz':3, '100Hz':4, '10Hz':5, '1Hz':6})
    top.set('expert.ClinkPcie.Hsio.TimingRx.XpmMiniWrapper.XpmMini.Config_L0Select_RateSel',6,'rateEnum')

    # Feb[0] refers to pgp lane, Ch[0],[1] refers to camera link channel from Feb (these should be abstracted)
    # UartPiranha4 is camType; sets serial registers
    # ClinkTop.LinkMode is Disable,Base,Medium,Full
    # ClinkTop.DataMode is None,8b,10b,12b
    # ClinkTop.FrameMode is None,Line,Frame
    # ClinkTop.TapCount
    # All serial commands are enumerated as registers
    top.set('expert.ClinkFeb.TrigCtrl.EnableTrig', 1, 'UINT8')   # rogue wants 'bool'
    top.set('expert.ClinkFeb.TrigCtrl.InvCC'     , 0, 'UINT8')   # rogue wants 'bool'
    top.set('expert.ClinkFeb.TrigCtrl.TrigMap'   , 0, 'UINT32')  # ChanA/ChanB
    top.set('expert.ClinkFeb.TrigCtrl.TrigMask'  , 1, 'UINT32')  # CC1
    top.set('expert.ClinkFeb.TrigCtrl.TrigPulseWidth', 4.000, 'FLOAT')  #32.768, 'FLOAT')

    top.set("expert.ClinkFeb.ClinkTop.PllConfig0"      ,'85MHz','CHARSTR')
    top.set("expert.ClinkFeb.ClinkTop.PllConfig1"      ,'85MHz','CHARSTR')
    top.set("expert.ClinkFeb.ClinkTop.PllConfig2"      ,'85MHz','CHARSTR')

    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.LinkMode"    ,      2,'UINT32')   # Medium mode
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.DataMode"    ,      3,'UINT32')   # 12-bit: Requires Base or Medium LinkMode
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.FrameMode"    ,     1,'UINT32')   # Line
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.TapCount"    ,      4,'UINT32')   #
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.DataEn"    ,        1,'UINT8')   # rogue wants 'bool'
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.Blowoff"    ,       0,'UINT8')   # rogue wants 'bool'
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.BaudRate"      , 9600,'UINT32')   # bps
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.SerThrottle"   ,30000,'UINT32')
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.SwControlValue",    0,'UINT32')   # Frame
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.SwControlEn"   ,    0,'UINT32')   # Frame

    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.SEM",        0,'expEnum')   # Internal Exposure Mode for quick commanding (?!)
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.CLM",        1,'clmEnum')   # Camera Link Mode <0:Base 1:Med 2:Full>
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.CLS",        0,'clsEnum')   # Camera Link Speed  <0 - 85MHz, 1 - 66MHz>
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.DST",        0,'dstEnum')   # Device Scan Type <0 - Line Scan, 1 - Area Scan>
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.SSB",        0, 'UINT32')   # Contrast Offset <DN>
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.SSG", '0 f1.0','CHARSTR')   # Gain <0:System 1:Bottom Line 2:Top Line>  f<gain>
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.SBV",        1,'binEnum')   # Vertical Binning <1|2> pixels
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.SBH",        1,'binEnum')   # Horizontal Binning <1|2> pixels
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.SCD",        0,'dirEnum')   # Direction <0:Fwd, 1:Rev 2:Ext>
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.SMM",        0,'offOnEnum') # Mirroring <0:Off 1:On>
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.SPF",        2,'pixEnum')   # Pixel Format <0:8 bits 1:10 bits 2:12 bits>
    #top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.SVM",        0,'tpEnum')    # Test Pattern <0-1>
    #top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.SSF",        1, 'UINT32')   # Internal Line Rate <Hz>; Requires 'STM 0'
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.STM",        0,'offOnEnum') # Internal Trigger <0:Off 1:On>, to be toggled by code if desired
    top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.SET",     4000, 'UINT32')   # Exposure Time <ns>; Min value is 4 us; Requires 'SEM 0'
    #top.set("expert.ClinkFeb.ClinkTop.ClinkCh.UartPiranha4.SEM",        1,'expEnum')   # Exposure Mode <0:Int 1:Ext>; Last as it slows commanding down

    return top
def epix100_cdict(data_from_yaml):
    root = EpixBoard()

    with EpixBoard() as root:
        tree_dict = root.treeDict()

    for entry in ("runControl", "dataWriter"):
        if entry in data_from_yaml["ePixBoard"]:
            del (data_from_yaml["ePixBoard"][entry])

    current_entry_path = []
    entry_list = []
    for key, value in data_from_yaml.items():
        get_configuration_values(key, value, current_entry_path, entry_list)

    type_conversion_dict = {
        "bool": "boolEnum",
        "uint1": "UINT8",
        "uint2": "UINT8",
        "uint3": "UINT8",
        "uint4": "UINT8",
        "uint5": "UINT8",
        "uint6": "UINT8",
        "uint7": "UINT8",
        "uint8": "UINT8",
        "uint10": "UINT16",
        "uint13": "UINT16",
        "uint16": "UINT16",
        "uint31": "UINT32",
        "uint32": "UINT32",
    }

    top = cdict()
    top.setAlg('config', [2, 0, 0])
    top.define_enum('boolEnum', {'False': 0, 'True': 1})

    for entry in entry_list:
        temp_path = f"expert.{'.'.join(entry[0][1:])}"
        configdb_path = re.sub("\[(.*?)\]", "_\\1", temp_path)
        info = retrieve_rogue_information(entry[0], tree_dict)
        if info['class'] == 'LinkVariable':
            print(f"Skipping {configdb_path}: Linked Variable")
            continue
        original_type = info["typeStr"].lower()
        original_value = entry[1]
        if info["ndType"] != None:
            array_type = info["ndType"]
            temp_configdb_value = [
                entry for entry in original_value.split("[")[1].split("]")
                [0].split(",")
            ]
            if "x" in temp_configdb_value[0]:
                num_base = 16
            else:
                num_base = 10
            temp_configdb_value2 = [
                int(entry, base=num_base) for entry in temp_configdb_value
            ]
            configdb_type = type_conversion_dict[str(array_type).lower()]
            configdb_value = list(
                np.array(temp_configdb_value2, dtype=array_type))
        else:
            if original_type in type_conversion_dict:
                configdb_type = type_conversion_dict[original_type]
            else:
                print(
                    f"Type unknown, please define the psana type: {original_type}"
                )
                print(info)
                sys.exit(0)
            if info["enum"] != None:
                if configdb_type == "boolEnum":
                    if original_value == True:
                        configdb_value = 1
                    elif original_value == False:
                        configdb_value = 0
                elif original_value in info["enum"].values():
                    dict_keys = list(info["enum"].keys())
                    dict_values = list(info["enum"].values())
                    index = dict_values.index(original_value)
                    configdb_value = dict_keys[index]
            else:
                configdb_value = original_value
        print(
            f"Writing into database: {configdb_path}, {configdb_value}, {configdb_type}"
        )
        top.set(f"{configdb_path}", configdb_value,
                f"{configdb_type}")  # taken from epixHR

    #top.set("firmwareBuild:RO"  , "-", 'CHARSTR')
    #top.set("firmwareVersion:RO",   0, 'UINT32')

    #help_str  = "-- user interface --"
    #help_str += "\nstart_ns     : exposure start (nanoseconds)"
    #help_str += "\ngate_ns     : exposure time (nanoseconds)"
    #top.set("help.user:RO", help_str, 'CHARSTR')

    # set to 88000 to get triggerDelay larger than zero when
    # L0Delay is 81 (used by TMO)
    top.set("user.start_ns", 88000, 'UINT32')  # taken from epixHR
    top.set("user.gate_ns", 154000,
            'UINT32')  # taken from lcls1 xpptut15 run 260
    # add daqtriggerdelay and runtriggerdelay?

    # timing system
    top.set(
        'expert.DevPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.PauseThreshold',
        16, 'UINT32')
    top.set('expert.cfgyaml:RO', 'NoYaml', 'CHARSTR')

    return top
Example #14
0
def epixhr2x2_cdict():

    top = cdict()
    top.setAlg('config', [2,0,0])

    #top.set("firmwareBuild:RO"  , "-", 'CHARSTR')
    #top.set("firmwareVersion:RO",   0, 'UINT32')

    help_str  = "-- user interface --"
    help_str += "\nstart_ns     : nanoseconds to exposure start"
    help_str += "\ngain_mode    : High/Med/Low/AutoHiLo/AutoMedLo/Map"
    help_str += "\npixel_map    : 3D-map of pixel gain/inj settings"
    #top.set("help.user:RO", help_str, 'CHARSTR')

    pixelMap = np.zeros((elemRows*2,elemCols*2),dtype=np.uint8)
    top.set("user.pixel_map", pixelMap)

    top.set("user.start_ns" , 107749, 'UINT32')

    top.define_enum('gainEnum', {'High':0, 'Medium':1, 'Low':2, 'AutoHiLo':3, 'AutoMedLo':4, 'Map':5})
    top.set("user.gain_mode",      0, 'gainEnum')  

    top.set("user.asic_enable"  , 0xf, 'UINT32')

    # timing system
    top.set('expert.DevPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.PauseThreshold',16,'UINT32')
    top.set('expert.DevPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.TriggerDelay',42,'UINT32')
    top.set('expert.DevPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.Partition',0,'UINT32')

    top.define_enum('rateEnum', {'929kHz':0, '71kHz':1, '10kHz':2, '1kHz':3, '100Hz':4, '10Hz':5, '1Hz':6})
    top.set('expert.DevPcie.Hsio.TimingRx.XpmMiniWrapper.XpmMini.Config_L0Select_RateSel',6,'rateEnum')

    top.define_enum('boolEnum', {'False':0, 'True':1})

    base = 'expert.EpixHR.MMCMRegisters.'
    for i in range(7):
        path = base+'CLKOUT{}'.format(i)
        top.set(path+'PhaseMux' , 0, 'UINT8')
        top.set(path+'HighTime' , 2, 'UINT8')
        top.set(path+'LowTime'  , 2, 'UINT8')
        if i==0:
            top.set(path+'Frac'     , 2, 'UINT8')
            top.set(path+'FracEn'   , 1, 'UINT8')
        top.set(path+'Edge'     , 0, 'UINT8')
        top.set(path+'NoCount'  , 0, 'UINT8')
        top.set(path+'DelayTime', 0, 'UINT8')

    base = 'expert.EpixHR.TriggerRegisters.'
    top.set(base+'AutoDaqEn'        , 0, 'boolEnum')
    top.set(base+'AutoRunEn'        , 0, 'boolEnum')
    top.set(base+'AutoTrigPeriod'   , 270000, 'UINT32')
    top.set(base+'PgpTrigEn'        , 1, 'boolEnum')
    top.set(base+'RunTriggerEnable' , 0, 'boolEnum')
    top.set(base+'RunTriggerDelay'  , 0, 'UINT32')
    top.set(base+'DaqTriggerEnable' , 0, 'boolEnum')
    top.set(base+'DaqTriggerDelay'  , 0, 'UINT32')
    
    #  There might be Json2Xtc problems with boolEnum in this object
    for i in range(4):
        base = 'expert.EpixHR.Hr10kTAsic{}.'.format(i)
        top.set(base+'shvc_DAC'      , 0, 'UINT8')
        top.set(base+'fastPP_enable' , 0, 'boolEnum')
        top.set(base+'PulserSync'    , 0, 'boolEnum')
        top.set(base+'Pll_RO_Reset'  , 0, 'boolEnum')
        top.set(base+'Pll_Itune'     , 0, 'UINT8')
        top.set(base+'Pll_KVCO'      , 0, 'UINT8')
        top.set(base+'Pll_filter1LSB', 0, 'UINT8')
        top.set(base+'Pll_filter1MSB', 0, 'UINT8')
        top.set(base+'Pulser'        , 0, 'UINT16')
        top.set(base+'pbit'          , 0, 'boolEnum')
        top.set(base+'atest'         , 0, 'boolEnum')
        top.set(base+'test'          , 0, 'boolEnum')
        top.set(base+'sab_test'      , 0, 'boolEnum')
        top.set(base+'hrtest'        , 0, 'boolEnum')
        top.set(base+'PulserR'       , 0, 'boolEnum')
        top.set(base+'DigMon1'       , 0, 'UINT8')
        top.set(base+'DigMon2'       , 0, 'UINT8')
        top.set(base+'PulserDac'     , 0, 'UINT8')
        top.set(base+'MonostPulser'  , 0, 'UINT8')
        top.set(base+'RefGenB'       , 0, 'UINT8')
        top.set(base+'Dm1En'         , 0, 'boolEnum')
        top.set(base+'Dm2En'         , 0, 'boolEnum')
        top.set(base+'emph_bd'       , 0, 'UINT8')
        top.set(base+'emph_bc'       , 0, 'UINT8')
        top.set(base+'VRef_DAC'      , 0, 'UINT8')
        top.set(base+'VRefLow'       , 0, 'UINT8')
        top.set(base+'trbit'         , 0, 'boolEnum')
        top.set(base+'TpsMux'        , 0, 'UINT8')
        top.set(base+'RoMonost'      , 0, 'UINT8')
        top.set(base+'TpsGr'         , 0, 'UINT8')
        top.set(base+'Balcony_clk'   , 0, 'UINT8')
        top.set(base+'PpOcbS2d'      , 0, 'boolEnum')
        top.set(base+'Ocb'           , 0, 'UINT8')
        top.set(base+'Monost'        , 0, 'UINT8')
        top.set(base+'mTest'         , 0, 'boolEnum')
        top.set(base+'Preamp'        , 0, 'UINT8')
        top.set(base+'S2D_1_b'       , 0, 'UINT8')
        top.set(base+'Vld1_b'        , 0, 'UINT8')
        top.set(base+'CompTH_DAC'    , 0, 'UINT8')
        top.set(base+'TC'            , 0, 'UINT8')
        top.set(base+'S2d'           , 0, 'UINT8')
        top.set(base+'S2dDacBias'    , 0, 'UINT8')
        top.set(base+'Tsd_Tser'      , 0, 'UINT8')
        top.set(base+'Tps_DAC'       , 0, 'UINT8')
        top.set(base+'PLL_RO_filter2', 0, 'UINT8')
        top.set(base+'PLL_RO_divider', 0, 'UINT8')
        top.set(base+'TestBe'        , 0, 'boolEnum')
        top.set(base+'RSTreg'        , 0, 'boolEnum')
        top.set(base+'DelExec'       , 0, 'boolEnum')
        top.set(base+'DelCCKReg'     , 0, 'boolEnum')
        top.set(base+'RO_rst_en'     , 0, 'boolEnum')
        top.set(base+'SlvdsBit'      , 0, 'boolEnum')
        top.set(base+'FELmode'       , 0, 'boolEnum')
        top.set(base+'CompEnOn'      , 0, 'boolEnum')
        top.set(base+'RowStartAddr'  , 0, 'UINT8')
        top.set(base+'RowStopAddr'   , 0, 'UINT8')
        top.set(base+'ColStartAddr'  , 0, 'UINT8')
        top.set(base+'ColStopAddr'   , 0, 'UINT8')
        top.set(base+'DCycle_DAC'    , 0, 'UINT8')
        top.set(base+'DCycle_en'     , 0, 'boolEnum')
        top.set(base+'DCycle_bypass' , 0, 'boolEnum')
        top.set(base+'Debug_bit'     , 0, 'UINT8')
        top.set(base+'OSRsel'        , 0, 'boolEnum')
        top.set(base+'SecondOrder'   , 0, 'boolEnum')
        top.set(base+'DHg'           , 0, 'boolEnum')
        top.set(base+'RefGenC'       , 0, 'UINT8')
        top.set(base+'dbus_del_sel'  , 0, 'boolEnum')
        top.set(base+'SDclk_b'       , 0, 'UINT8')
        top.set(base+'SDrst_b'       , 0, 'UINT8')
        top.set(base+'Filter_DAC'    , 0, 'UINT8')
        top.set(base+'Rodis01'       , 0, 'UINT8')
        top.set(base+'CompEn'        , 0, 'UINT8')
        top.set(base+'Pixel_CB'      , 0, 'UINT8')
        top.set(base+'rodis34'       , 0, 'UINT8')
        top.set(base+'rowCK2matrix_delay' , 0, 'UINT8')
        top.set(base+'ro_mode'       , 0, 'UINT8')
        top.set(base+'rodis5'        , 0, 'UINT8')
        top.set(base+'pipoclk_delay' , 0, 'UINT8')
        top.set(base+'WritePixelData', 0, 'UINT8')

    base = 'expert.EpixHR.RegisterControl.'
    top.define_enum('debugSelEnum', {'Asic01DM':0, 
                                     'AsicSync':1,
                                     'AsicAcq':2,
                                     'AsicSR0':3,
                                     'SaciClk':4,
                                     'SaciCmd':5,
                                     'SaciResp':6,
                                     'SaciSelL0':7,
                                     'SaciSelL1':8,
                                     'AsicRdClk':9,
                                     'deserClk':10,
                                     'WFdacDin':11,
                                     'WFdacSclk':12,
                                     'WFdacCsl':13,
                                     'WFdacLdacL':14,
                                     'WFdacCrtlL':15,
                                     'AsicGRst':16,
                                     'AsicR0':17,
                                     'SlowAdcDin':18,
                                     'SlowAdcDrdy':19,
                                     'SlowAdcDout':20,
                                     'slowAdcRefClk':21,
                                     'pgpTrigger':22,
                                     'acqStart':23})
    top.set(base+'Version'          , 0, 'UINT32')
    top.set(base+'GlblRstPolarity'  , 0, 'boolEnum')
    top.set(base+'ClkSyncEn'        , 0, 'boolEnum')
    top.set(base+'SyncPolarity'     , 0, 'boolEnum')
    top.set(base+'SyncDelay'        , 0, 'UINT32')
    top.set(base+'SyncWidth'        , 0, 'UINT32')
    top.set(base+'SR0Polarity'      , 0, 'boolEnum')
    top.set(base+'SR0Delay1'        , 0, 'UINT32')
    top.set(base+'SR0Width1'        , 0, 'UINT32')
    top.set(base+'ePixAdcSHPeriod'  , 0, 'UINT16')
    top.set(base+'ePixAdcSHOffset'  , 0, 'UINT16')
    top.set(base+'AcqPolarity'      , 0, 'boolEnum')
    top.set(base+'AcqDelay1'        , 0, 'UINT32')
    top.set(base+'AcqWidth1'        , 0, 'UINT32')
    top.set(base+'AcqDelay2'        , 0, 'UINT32')
    top.set(base+'AcqWidth2'        , 0, 'UINT32')
    top.set(base+'R0Polarity'       , 0, 'boolEnum')
    top.set(base+'R0Delay'          , 0, 'UINT32')
    top.set(base+'R0Width'          , 0, 'UINT32')
    top.set(base+'PPbePolarity'     , 0, 'boolEnum')
    top.set(base+'PPbeDelay'        , 0, 'UINT32')
    top.set(base+'PPbeWidth'        , 0, 'UINT32')
    top.set(base+'PpmatPolarity'    , 0, 'boolEnum')
    top.set(base+'PpmatDelay'       , 0, 'UINT32')
    top.set(base+'PpmatWidth'       , 0, 'UINT32')
    top.set(base+'SaciSyncPolarity' , 0, 'boolEnum')
    top.set(base+'SaciSyncDelay'    , 0, 'UINT32')
    top.set(base+'SaciSyncWidth'    , 0, 'UINT32')
    top.set(base+'ResetCounters'    , 0, 'boolEnum')
    top.set(base+'AsicPwrEnable'    , 0, 'boolEnum')
    top.set(base+'AsicPwrManual'    , 0, 'boolEnum')
    top.set(base+'AsicPwrManualDig' , 0, 'boolEnum')
    top.set(base+'AsicPwrManualAna' , 0, 'boolEnum')
    top.set(base+'AsicPwrManualIo'  , 0, 'boolEnum')
    top.set(base+'AsicPwrManualFpga', 0, 'boolEnum')
    top.set(base+'DebugSel_TG'      , 0, 'debugSelEnum')
    top.set(base+'DebugSel_MPS'     , 0, 'debugSelEnum')
    top.set(base+'StartupReq'       , 0, 'boolEnum')

    base = 'expert.EpixHR.PowerSupply.'
    top.set(base+'DigitalEn', 1, 'boolEnum')
    top.set(base+'AnalogEn' , 1, 'boolEnum')

    base = 'expert.EpixHR.HSDac.'
    top.set(base+'WFEnabled'       , 0, 'boolEnum')
    top.set(base+'run'             , 0, 'boolEnum')
    top.set(base+'externalUpdateEn', 0, 'boolEnum')
    top.set(base+'waveformSource'  , 0, 'boolEnum')
    top.set(base+'WFEnabled'       , 0, 'UINT8')
    top.set(base+'samplingCounter' , 0, 'UINT16')
    top.set(base+'DacValue'        , 0, 'UINT16')
    top.set(base+'DacChannel'      , 0, 'UINT8')
    top.set(base+'rCStartValue'    , 0, 'UINT16')
    top.set(base+'rCStopValue'     , 0, 'UINT16')
    top.set(base+'rCStep'          , 0, 'UINT16')

    base = 'expert.EpixHR.SlowDacs.'
    for i in range(5):
        top.set(base+'dac_{}'.format(i), 0, 'UINT16')
    top.set(base+'dummy', 0, 'UINT32')

    base = 'expert.EpixHR.Oscilloscope.'
    top.define_enum('trigPolarityEnum', {'Falling':0, 'Rising':1})
    top.define_enum('trigChannelEnum' , {'TrigReg':0, 
                                         'ThresholdChA':1, 
                                         'ThresholdChB':2,
                                         'AcqStart':3,
                                         'AsicAcq':4,
                                         'AsicR0':5,
                                         'AsicRoClk':6,
                                         'AsicPpmat':7,
                                         'PgpTrigger':8,
                                         'AsicSync':9,
                                         'AsicGR':10,
                                         'AsicSaciSel0':11,
                                         'AsicSaciSel1':12})
    top.define_enum('trigModeEnum', {'Disable':0, 'Axil':1, 'Trig':2 })
    top.define_enum('inputChannelEnum', {'Asic0TpsMux':0,
                                         'Asic1TpsMux':1,
                                         'Asic1TpsMux':2,
                                         'Asic3TpsMux':3})
    top.set(base+'ArmReg'          , 0, 'boolEnum')
    top.set(base+'TrigReg'         , 0, 'boolEnum')
    top.set(base+'ScopeEnable'     , 0, 'boolEnum')
    top.set(base+'TriggerEdge'     , 0, 'trigPolarityEnum')
    top.set(base+'TriggerChannel'  , 0, 'trigChannelEnum')
    top.set(base+'TriggerMode'     , 0, 'trigModeEnum')
    top.set(base+'TriggerAdcThresh', 0, 'UINT16')
    top.set(base+'TriggerHoldoff'  , 0, 'UINT16')
    top.set(base+'TriggerOffset'   , 0, 'UINT16')
    top.set(base+'TraceLength'     , 0, 'UINT16')
    top.set(base+'SkipSamples'     , 0, 'UINT16')
    top.set(base+'InputChannelA'   , 0, 'inputChannelEnum')
    top.set(base+'InputChannelB'   , 0, 'inputChannelEnum')
    top.set(base+'TriggerDelay'    , 0, 'UINT16')

    base = 'expert.EpixHR.FastADCsDebug.'
    for i in range(4):
        top.set(base+'DelayAdc{}_'.format(i)    , 0, 'UINT16')
    top.set(base+'DelayAdcF_', 0, 'UINT16')
    top.set(base+'lockedCountRst', 0, 'boolEnum')
    top.set(base+'FreezeDebug'   , 0, 'boolEnum')

    base = 'expert.EpixHR.Ad9249Config_Adc_0.'
    top.define_enum('ExtPwdnEnum',{'FullPowerDown':0,'Standby':1})
    top.define_enum('IntPwdnEnum',{'ChipRun':0, 'FullPowerDown':1, 'Standby':2, 'DigitalReset':3 })
    top.define_enum('OffOnEnum',{'Off':0, 'On':1})
    top.define_enum('UserTestModeEnum',{ 'single':0, 'alternate':1, 'single_once':2, 'alternate_once':3 })
    top.define_enum('OutputTestModeEnum', { 'Off':0, 'MidscaleShort':1, 'PosFS':2, 'NegFS':3, 'AltCheckerBoard':4, 'PN23':5, 'PN9':6, 'OneZeroWordToggle':7, 'UserInput':8, 'OneZeroBitToggle':9 })
    top.define_enum('ClockDivideChEnum',{ '{}'.format(i+1):i for i in range(8)})
    top.define_enum('OutputFormatEnum', { 'TwosComplement':0, 'OffsetBinary':1})
    top.set(base+'ExternalPdwnMode', 0, 'ExtPwdnEnum')
    top.set(base+'InternalPdwnMode', 0, 'IntPwdnEnum')
    top.set(base+'DutyCycleStabilizer', 0, 'OffOnEnum')
    top.set(base+'ClockDivide', 0, 'ClockDivideChEnum')
    top.set(base+'ChopMode', 0, 'OffOnEnum')
    #top.set(base+'DevIndexMask_DataCh', [0x0,0x0], 'UINT8')
    #top.set(base+'DevIndexMask_FCO', 0x0, 'UINT8')
    #top.set(base+'DevIndexMask_DCO', 0x0, 'UINT8')
    top.set(base+'UserTestModeCfg', 0, 'UserTestModeEnum')
    top.set(base+'OutputTestMode', 0, 'OutputTestModeEnum')
    top.set(base+'OffsetAdjust', 0, 'UINT8')
    top.set(base+'OutputInvert', 0, 'boolEnum')
    top.set(base+'OutputFormat', 1, 'OutputFormatEnum')
    top.set(base+'UserPatt1Lsb', 0, 'UINT8')
    top.set(base+'UserPatt1Msb', 0, 'UINT8')
    top.set(base+'UserPatt2Lsb', 0, 'UINT8')
    top.set(base+'UserPatt2Msb', 0, 'UINT8')
    top.set(base+'LvdsLsbFirst', 0, 'boolEnum')

    base = 'expert.EpixHR.SlowAdcRegisters.'
    top.set(base+'StreamEn', 0, 'boolEnum')
    top.set(base+'StreamPeriod', 0, 'UINT32')

    base = 'expert.EpixHR.SspLowSpeedDecoderReg.'
    top.set(base+'EnUsrDlyCfg'          , 0, 'UINT8')
    top.set(base+'UsrDlyCfg'            , 0, 'UINT16')
    top.set(base+'MinEyeWidth'          , 0, 'UINT8')
    top.set(base+'LockingCntCfg'        , 0, 'UINT32')
    top.set(base+'BypFirstBerDet'       , 0, 'UINT8')
    top.set(base+'Polarity'             , 0, 'UINT32')
    top.set(base+'GearBoxSlaveBitOrder' , 0, 'UINT8')
    top.set(base+'GearBoxMasterBitOrder', 0, 'UINT8')
    top.set(base+'MaskOffCodeErr'       , 0, 'UINT8')
    top.set(base+'MaskOffDispErr'       , 0, 'UINT8')
    top.set(base+'MaskOffOutOfSync'     , 0, 'UINT8')
    top.set(base+'LockOnIdleOnly'       , 0, 'UINT8')
    top.set(base+'RollOverEn'           , 0, 'UINT8')

    for i in range(4):
        base = 'expert.EpixHR.PacketRegisters{}.'.format(i)
        top.set(base+'asicDataReq'     , 0, 'UINT16')
        top.set(base+'DisableLane'     , 0, 'UINT8')
        top.set(base+'EnumerateDisLane', 0, 'UINT8')
        top.set(base+'gainBitRemapped' , 0, 'UINT8')

    return top
Example #15
0
def write_to_daq_config_db(args):

    #database contains collections which are sets of documents (aka json objects).
    #each type of device has a collection.  The elements of that collection are configurations of that type of device.
    #e.g. there will be OPAL, EVR, and YUNGFRAU will be collections.  How they are configured will be a document contained within that collection
    #Each hutch is also a collection.  Documents contained within these collection have an index, alias, and list of devices with configuration IDs
    #How is the configuration of a state is described by the hutch and the alias found.  E.g. TMO and BEAM.  TMO is a collection.
    #BEAM is an alias of some of the documents in that collection. The document with the matching alias and largest index is the current
    #configuration for that hutch and alias.
    #When a device is configured, the device has a unique name OPAL7.  Need to search through document for one that has an NAME called OPAL7.  This will have
    #have two fields "collection" and ID field (note how collection here is a field. ID points to a unique document).  This collection field and
    #ID point to the actuall Mongo DB collection and document

    create = True
    dbname = 'configDB'  #this is the name of the database running on the server.  Only client care about this name.

    mycdb = cdb.configdb(
        'https://pswww.slac.stanford.edu/ws-auth/devconfigdb/ws/',
        args.inst,
        create,
        root=dbname,
        user=args.user,
        password=args.password)
    mycdb.add_alias(args.alias)
    mycdb.add_device_config('opal')

    top = cdict()
    top.setInfo('opal', args.name, args.segm, args.id, 'No comment')
    top.setAlg('config', [2, 0, 0])

    top.set("firmwareBuild:RO", "-", 'CHARSTR')
    top.set("firmwareVersion:RO", 0, 'UINT32')

    help_str = "-- user interface --"
    help_str += "\nstart_ns : nanoseconds from fiducial to exposure start"
    help_str += "\ngate_ns  : nanoseconds of exposure; rounded up to 10 microseconds"
    top.set("help:RO", help_str, 'CHARSTR')

    top.define_enum('binEnum', {'x%d' % (2**key): key for key in range(4)})

    #Create a user interface that is an abstraction of the common inputs
    top.set("user.start_ns", 107749, 'UINT32')
    top.set("user.gate_ns", 100, 'UINT32')
    top.set("user.black_level", 32, 'UINT32')
    top.set("user.vertical_bin", 0, 'binEnum')

    # timing system
    top.set(
        'expert.ClinkPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer[0].PauseThreshold',
        16, 'UINT32')
    top.set(
        'expert.ClinkPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer[0].TriggerDelay',
        42, 'UINT32')
    top.set(
        'expert.ClinkPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer[0].Partition',
        0, 'UINT32')

    top.define_enum(
        'rateEnum', {
            '929kHz': 0,
            '71kHz': 1,
            '10kHz': 2,
            '1kHz': 3,
            '100Hz': 4,
            '10Hz': 5,
            '1Hz': 6
        })
    top.set(
        'expert.ClinkPcie.Hsio.TimingRx.XpmMiniWrapper.XpmMini.Config_L0Select_RateSel',
        6, 'rateEnum')

    # Feb[0] refers to pgp lane, Ch[0][,1] refers to camera link channel from Feb (these should be abstracted)
    # UartOpal1000 is camType; sets serial registers
    # ClinkTop.LinkMode is Base,Medium,Full,Deca
    # ClinkTop.DataMode is 8b,10b,12b,14b,16b,24b,30b,36b
    # ClinkTop.FrameMode is None,Line,Frame
    # ClinkTop.TapCount
    # All serial commands are enumerated as registers
    top.set('expert.ClinkFeb[0].TrigCtrl[0].EnableTrig', 1,
            'UINT8')  # rogue wants 'bool'
    top.set('expert.ClinkFeb[0].TrigCtrl[0].InvCC', 0,
            'UINT8')  # rogue wants 'bool'
    top.set('expert.ClinkFeb[0].TrigCtrl[0].TrigMap', 0,
            'UINT32')  # ChanA/ChanB
    top.set('expert.ClinkFeb[0].TrigCtrl[0].TrigMask', 1, 'UINT32')  # CC1
    top.set('expert.ClinkFeb[0].TrigCtrl[0].TrigPulseWidth', 32.768, 'FLOAT')

    top.set("expert.ClinkFeb[0].ClinkTop.PllConfig[0]", '80MHz', 'CHARSTR')
    top.set("expert.ClinkFeb[0].ClinkTop.PllConfig[1]", '80MHz', 'CHARSTR')
    top.set("expert.ClinkFeb[0].ClinkTop.PllConfig[2]", '80MHz', 'CHARSTR')

    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].LinkMode", 1,
            'UINT32')  # Base mode
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].DataMode", 3,
            'UINT32')  # 12-bit
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].FrameMode", 2,
            'UINT32')  # Frame
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].TapCount", 2, 'UINT32')  #
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].DataEn", 1,
            'UINT8')  # rogue wants 'bool'
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].Blowoff", 0,
            'UINT8')  # rogue wants 'bool'
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].BaudRate", 57600,
            'UINT32')  # bps
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].SerThrottle", 10000, 'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].SwControlValue", 0,
            'UINT32')  # Frame
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].SwControlEn", 0,
            'UINT32')  # Frame

    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.BL", 32,
            'UINT32')  # black level
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.GA", 100,
            'UINT32')  # digital gain, percent
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.VBIN", 0,
            'UINT32')  # vertical binning (powers-of-two)[0..3]
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.VR", 1,
            'UINT32')  # vertical remapping (top-to-bottom, left-to-right)
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.MI", 0,
            'UINT32')  # output mirroring (hor=b0, ver=b1)
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.OR", 12,
            'UINT32')  # output resolution, bits
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.TP", 0,
            'UINT32')  # test pattern on/off
    #    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.OLUTE",  0,'UINT32')  # output lookup table enable on/off (not implemented)
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.DPE", 0,
            'UINT32')  # defect pixel correction on/off
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.OVL", 1,
            'UINT32')  # overlay frame counter and integration time
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.MO", 1,
            'UINT32')  # operating mode continuous, triggered
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.CCE[0]", 0,
            'UINT32')  # trigger on CC1
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.CCE[1]", 0,
            'UINT32')  # polarity 0=rise-to-fall 1=fall-to-rise
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.FP", 0,
            'UINT32')  # frame period, continuous mode, 10 us units
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.IT", 1,
            'UINT32')  # integration time, 10 us units (< FP-10 and 32000)
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.CCFS[0]", 0,
            'UINT32')  # only relevant for modes 2,3
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.CCFS[1]", 0,
            'UINT32')  # only relevant for modes 2,3
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.OFS", 1,
            'UINT32')  # color cameras only
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.WB[0]", 100,
            'UINT32')  # red gain
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.WB[1]", 100,
            'UINT32')  # green gain
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.WB[2]", 100,
            'UINT32')  # blue gain

    #    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.FSE",0,'UINT32')      # flash strobe enable (not implemented)
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.FSM", 0,
            'UINT32')  # flash strobe mode
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.FST[0]", 0,
            'UINT32')  # flash stroble timing
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.FST[1]", 0,
            'UINT32')
    top.set("expert.ClinkFeb[0].ClinkTop.Ch[0].UartOpal1000.FSP", 1,
            'UINT32')  # flash strobe polarity

    #the object hierarchy paths (e.g. cl.TimeToolKcu1500.Application.AppLane0... yadayadayada) for a device can be found by implementing
    #pr.generateAddressMap where pr comes from "import rogue as pr".  For this to work, one has to be logged onto the machine hosting the firmware
    #that interacts with rogue.  This particular register map can be found in the lcls2-pcie-apps directory cloned from https://github.com/slaclab/lcls2-pcie-apps.

    mycdb.modify_device(args.alias, top)
Example #16
0
def epixquad_config(base, connect_str, cfgtype, detname, detsegm, rog):
    global ocfg
    global group
    global segids

    group = rog

    _checkADCs()

    #
    #  Retrieve the full configuration from the configDB
    #
    cfg = get_config(connect_str, cfgtype, detname, detsegm)
    ocfg = cfg

    #  Translate user settings to the expert fields
    user_to_expert(base, cfg, full=True)

    #  Apply the expert settings to the device
    config_expert(base, cfg)

    pbase = base['pci']
    pbase.StartRun()

    #  Add some counter resets here
    reset_counters(base)

    #  Capture the firmware version to persist in the xtc
    cbase = base['cam']
    firmwareVersion = cbase.AxiVersion.FpgaVersion.get()

    ocfg = cfg

    #
    #  Create the segment configurations from parameters required for analysis
    #
    trbit = [
        cfg['expert']['EpixQuad'][f'Epix10kaSaci{i}']['trbit']
        for i in range(16)
    ]

    topname = cfg['detName:RO'].split('_')

    scfg = {}
    segids = {}

    #  Rename the complete config detector
    scfg[0] = cfg.copy()
    scfg[0]['detName:RO'] = topname[0] + 'hw_' + topname[1]

    a = np.array(cfg['user']['pixel_map'], dtype=np.uint8)
    pixelConfigMap = np.reshape(a, (16, 178, 192))

    for seg in range(4):
        #  Construct the ID
        carrierId = [
            cbase.SystemRegs.CarrierIdLow[seg].get(),
            cbase.SystemRegs.CarrierIdHigh[seg].get()
        ]
        digitalId = [0, 0]
        analogId = [0, 0]
        id = '%010d-%010d-%010d-%010d-%010d-%010d-%010d' % (
            firmwareVersion, carrierId[0], carrierId[1], digitalId[0],
            digitalId[1], analogId[0], analogId[1])
        segids[seg] = id
        top = cdict()
        top.setAlg('config', [2, 0, 0])
        top.setInfo(detType='epix10ka',
                    detName=topname[0],
                    detSegm=seg + 4 * int(topname[1]),
                    detId=id,
                    doc='No comment')
        top.set('asicPixelConfig',
                pixelConfigMap[4 * seg:4 * seg + 4, :176].tolist(),
                'UINT8')  # only the rows which have readable pixels
        top.set('trbit', trbit[4 * seg:4 * seg + 4], 'UINT8')
        scfg[seg + 1] = top.typed_json()

    result = []
    for i in seglist:
        print('json seg {}  detname {}'.format(i, scfg[i]['detName:RO']))
        result.append(json.dumps(scfg[i]))

    return result
Example #17
0
def epixquad_cdict():

    top = cdict()
    top.setAlg('config', [2, 0, 0])

    #top.set("firmwareBuild:RO"  , "-", 'CHARSTR')
    #top.set("firmwareVersion:RO",   0, 'UINT32')

    help_str = "-- user interface --"
    help_str += "\nstart_ns     : nanoseconds to exposure start"
    help_str += "\ngate_ns      : nanoseconds of exposure window"
    help_str += "\ngain_mode    : High/Med/Low/AutoHiLo/AutoMedLo/Map"
    help_str += "\npixel_map    : 3D-map of pixel gain/inj settings"
    #top.set("help.user:RO", help_str, 'CHARSTR')

    pixelMap = np.zeros((16, 178, 192), dtype=np.uint8)
    top.set("user.pixel_map", pixelMap)

    top.set("user.start_ns", 107749, 'UINT32')
    top.set("user.gate_ns", 100000, 'UINT32')

    top.define_enum('gainEnum', {
        'High': 0,
        'Medium': 1,
        'Low': 2,
        'AutoHiLo': 3,
        'AutoMedLo': 4,
        'Map': 5
    })
    top.set("user.gain_mode", 0, 'gainEnum')

    # timing system
    top.set(
        'expert.DevPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.PauseThreshold',
        16, 'UINT32')
    top.set(
        'expert.DevPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.TriggerDelay',
        42, 'UINT32')
    top.set(
        'expert.DevPcie.Hsio.TimingRx.TriggerEventManager.TriggerEventBuffer.Partition',
        0, 'UINT32')

    top.define_enum(
        'rateEnum', {
            '929kHz': 0,
            '71kHz': 1,
            '10kHz': 2,
            '1kHz': 3,
            '100Hz': 4,
            '10Hz': 5,
            '1Hz': 6
        })
    top.set(
        'expert.DevPcie.Hsio.TimingRx.XpmMiniWrapper.XpmMini.Config_L0Select_RateSel',
        6, 'rateEnum')

    top.define_enum('boolEnum', {'False': 0, 'True': 1})
    ##    top.define_enum('trigSrcEnum', {'PGP':0, 'TTL':1, 'Cmd':2, 'Auto':3 })
    base = 'expert.EpixQuad.SystemRegs.'
    ##    top.set(base+'AutoTrigEn' , 0, 'boolEnum')
    ##    top.set(base+'AutoTrigPer', 270000, 'UINT32')
    top.set(base + 'DcDcEnable', 0xf, 'UINT8')
    top.set(base + 'AsicAnaEn', 1, 'boolEnum')
    top.set(base + 'AsicDigEn', 1, 'boolEnum')
    top.set(base + 'DdrVttEn', 0, 'boolEnum')
    ##    top.set(base+'TrigSrcSel' , 0, 'trigSrcEnum')
    ##    top.set(base+'TrigEn'     , 1, 'boolEnum')
    top.set(base + 'AsicMask', 0xffff, 'UINT16')

    base = 'expert.EpixQuad.AcqCore.'
    top.set(base + 'AcqToAsicR0Delay', 0, 'UINT32')
    top.set(base + 'AsicR0Width', 0x1e, 'UINT32')
    top.set(base + 'AsicR0ToAsicAcq', 0x2710, 'UINT32')
    top.set(base + 'AsicAcqWidth', 0x2710, 'UINT32')
    top.set(base + 'AsicAcqLToPPmatL', 0x3e8, 'UINT32')
    top.set(base + 'AsicPpmatToReadout', 0x0, 'UINT32')
    top.set(base + 'AsicRoClkHalfT', 0x3, 'UINT32')
    top.set(base + 'AsicAcqForce', 0, 'boolEnum')
    top.set(base + 'AsicAcqValue', 0, 'boolEnum')
    top.set(base + 'AsicR0Force', 0, 'boolEnum')
    top.set(base + 'AsicR0Value', 0, 'boolEnum')
    top.set(base + 'AsicPpmatForce', 1, 'boolEnum')
    top.set(base + 'AsicPpmatValue', 1, 'boolEnum')
    top.set(base + 'AsicSyncForce', 0, 'boolEnum')
    top.set(base + 'AsicSyncValue', 0, 'boolEnum')
    top.set(base + 'AsicRoClkForce', 0, 'boolEnum')
    top.set(base + 'AsicRoClkValue', 0, 'boolEnum')
    top.set(base + 'AsicSyncInjEn', 1, 'boolEnum')
    top.set(base + 'AsicSyncInjDly', 0x3e8, 'UINT32')
    top.set(base + 'DbgOutSel0', 0, 'UINT32')
    top.set(base + 'DbgOutSel1', 0, 'UINT32')
    top.set(base + 'DbgOutSel2', 0, 'UINT32')
    top.set(base + 'DummyAcqEn', 0, 'boolEnum')  # ghost correction?

    base = 'expert.EpixQuad.RdoutCore.'
    ##    top.set(base+'RdoutEn', 1, 'boolEnum')
    top.set(base + 'AdcPipelineDelay', 0x44, 'UINT32')
    top.set(base + 'TestData', 0, 'boolEnum')
    top.set(base + 'OverSampleEn', 0, 'boolEnum')
    top.set(base + 'OverSampleSize', 0, 'UINT8')

    top.define_enum('scopeTrigMode', {'Disable': 0, 'Axil': 1, 'Trig': 2})
    base = 'expert.EpixQuad.PseudoScopeCore.'
    top.set(base + 'ScopeEn', 0, 'boolEnum')
    top.set(base + 'TrigEdge', 0, 'boolEnum')
    top.set(base + 'TrigChannel', 4, 'UINT8')
    top.set(base + 'TrigMode', 2, 'UINT8')
    top.set(base + 'TrigAdcThreshold', 0, 'UINT16')
    top.set(base + 'TrigHoldoff', 0, 'UINT16')
    top.set(base + 'TrigOffset', 0x46a, 'UINT16')
    top.set(base + 'TrigDelay', 0, 'UINT16')
    top.set(base + 'TraceLength', 0x1f40, 'UINT16')
    top.set(base + 'SkipSamples', 0, 'UINT16')
    top.set(base + 'InChannelA', 0x10, 'UINT8')
    top.set(base + 'InChannelB', 0x11, 'UINT8')

    base = 'expert.EpixQuad.VguardDac.'
    top.set(base + 'VguardDacRaw', 0, 'UINT16')

    for i in range(16):
        base = 'expert.EpixQuad.Epix10kaSaci{}.'.format(i)
        top.set(base + 'CompTH_DAC', 0x22, 'UINT8')
        top.set(base + 'CompEn0', 0, 'UINT8')
        top.set(base + 'CompEn1', 1, 'UINT8')
        top.set(base + 'CompEn2', 1, 'UINT8')
        top.set(base + 'PulserSync', 1, 'boolEnum')
        top.set(base + 'PixelDummy', 0x22, 'UINT8')
        top.set(base + 'Pulser', 0, 'UINT16')
        top.set(base + 'pbit', 0, 'boolEnum')
        top.set(base + 'atest', 0, 'boolEnum')
        top.set(base + 'test', 0, 'boolEnum')
        top.set(base + 'sab_test', 0, 'boolEnum')
        top.set(base + 'hrtest', 0, 'boolEnum')
        top.set(base + 'PulserR', 0, 'boolEnum')
        top.set(base + 'DigMon1', 0, 'UINT8')
        top.set(base + 'DigMon2', 1, 'UINT8')
        top.set(base + 'PulserDac', 3, 'UINT8')
        top.set(base + 'MonostPulser', 0, 'UINT8')
        top.set(base + 'Dm1En', 0, 'boolEnum')
        top.set(base + 'Dm2En', 0, 'boolEnum')
        top.set(base + 'emph_bd', 0, 'UINT8')
        top.set(base + 'emph_bc', 0, 'UINT8')
        top.set(base + 'VRef', 0x13, 'UINT8')
        top.set(base + 'VRefLow', 0x3, 'UINT8')
        top.set(base + 'TpsTComp', 1, 'boolEnum')
        top.set(base + 'TpsMux', 0, 'UINT8')
        top.set(base + 'RoMonost', 0x3, 'UINT8')
        top.set(base + 'TpsGr', 0x3, 'UINT8')
        top.set(base + 'S2d0Gr', 0x3, 'UINT8')
        top.set(base + 'PpOcbS2d', 1, 'boolEnum')
        top.set(base + 'Ocb', 0x3, 'UINT8')
        top.set(base + 'Monost', 0x3, 'UINT8')
        top.set(base + 'FastppEnable', 0, 'boolEnum')
        top.set(base + 'Preamp', 0x4, 'UINT8')
        top.set(base + 'PixelCb', 0x4, 'UINT8')
        top.set(base + 'Vld1_b', 0x1, 'UINT8')
        top.set(base + 'S2dTComp', 0, 'boolEnum')
        top.set(base + 'FilterDac', 0x11, 'UINT8')
        top.set(base + 'TestLVDTransmitter', 0, 'boolEnum')
        top.set(base + 'TC', 0, 'UINT8')
        top.set(base + 'S2d', 0x3, 'UINT8')
        top.set(base + 'S2dDacBias', 0x3, 'UINT8')
        top.set(base + 'TpsTcDac', 0, 'UINT8')
        top.set(base + 'TpsDac', 0x10, 'UINT8')
        top.set(base + 'S2d0TcDac', 0x1, 'UINT8')
        top.set(base + 'S2d0Dac', 0x14, 'UINT8')
        top.set(base + 'TestBe', 0, 'boolEnum')
        top.set(base + 'IsEn', 0, 'boolEnum')
        top.set(base + 'DelExec', 0, 'boolEnum')
        top.set(base + 'DelCckRef', 0, 'boolEnum')
        top.set(base + 'RO_rst_en', 1, 'boolEnum')
        top.set(base + 'SlvdsBit', 1, 'boolEnum')
        top.set(base + 'FELmode', 1, 'boolEnum')
        top.set(base + 'CompEnOn', 0, 'boolEnum')
        top.set(base + 'RowStartAddr', 0, 'UINT16')
        top.set(base + 'RowStopAddr', 0xb1, 'UINT16')
        top.set(base + 'ColStartAddr', 0, 'UINT16')
        top.set(base + 'ColStopAddr', 0x2f, 'UINT16')
        top.set(base + 'S2d1Gr', 0x3, 'UINT8')
        top.set(base + 'S2d2Gr', 0x3, 'UINT8')
        top.set(base + 'S2d3Gr', 0x3, 'UINT8')
        top.set(base + 'trbit', 0, 'boolEnum')
        top.set(base + 'S2d1TcDac', 0x1, 'UINT8')
        top.set(base + 'S2d1Dac', 0x12, 'UINT8')
        top.set(base + 'S2d2TcDac', 0x1, 'UINT8')
        top.set(base + 'S2d2Dac', 0x12, 'UINT8')
        top.set(base + 'S2d3TcDac', 0x1, 'UINT8')
        top.set(base + 'S2d3Dac', 0x12, 'UINT8')

    #top.set('expert.EpixQuad.SaciConfigCore.', 0, 'UINT32')

    top.define_enum('ExtPwdnEnum', {'FullPowerDown': 0, 'Standby': 1})
    top.define_enum('IntPwdnEnum', {
        'ChipRun': 0,
        'FullPowerDown': 1,
        'Standby': 2,
        'DigitalReset': 3
    })
    top.define_enum('OffOnEnum', {'Off': 0, 'On': 1})
    top.define_enum('UserTestModeEnum', {
        'single': 0,
        'alternate': 1,
        'single_once': 2,
        'alternate_once': 3
    })
    top.define_enum(
        'OutputTestModeEnum', {
            'Off': 0,
            'MidscaleShort': 1,
            'PosFS': 2,
            'NegFS': 3,
            'AltCheckerBoard': 4,
            'PN23': 5,
            'PN9': 6,
            'OneZeroWordToggle': 7,
            'UserInput': 8,
            'OneZeroBitToggle': 9
        })
    top.define_enum('ClockDivideChEnum',
                    {'{}'.format(i + 1): i
                     for i in range(8)})
    top.define_enum('OutputFormatEnum', {
        'TwosComplement': 0,
        'OffsetBinary': 1
    })

    #for i in range(10):
    if False:
        base = 'expert.EpixQuad.Ad9249Readout[{}].'.format(i)
        top.set(base + 'FrameDelay', 0, 'UINT16')
        top.set(base + 'Invert', 0, 'boolEnum')
        for i in range(8):
            top.set(base + f'ChannelDelay[{i}]', 0, 'UINT16')

        base = 'expert.EpixQuad.Ad9249Config[{}].'.format(i)
        #top.set(base+'ChipId:RO', '', 'CHARSTR')
        top.set(base + 'ExternalPdwnMode', 0, 'ExtPwdnEnum')
        top.set(base + 'InternalPdwnMode', 0, 'IntPwdnEnum')
        top.set(base + 'DutyCycleStabilizer', 0, 'OffOnEnum')
        top.set(base + 'ClockDivide', 0, 'ClockDivideChEnum')
        top.set(base + 'ChopMode', 0, 'OffOnEnum')
        #top.set(base+'DevIndexMask_DataCh', [0x0,0x0], 'UINT8')
        #top.set(base+'DevIndexMask_FCO', 0x0, 'UINT8')
        #top.set(base+'DevIndexMask_DCO', 0x0, 'UINT8')
        top.set(base + 'UserTestModeCfg', 0, 'UserTestModeEnum')
        top.set(base + 'OutputTestMode', 0, 'OutputTestModeEnum')
        top.set(base + 'OffsetAdjust', 0, 'UINT8')
        top.set(base + 'OutputInvert', 0, 'boolEnum')
        top.set(base + 'OutputFormat', 1, 'OutputFormatEnum')
        top.set(base + 'UserPatt1Lsb', 0, 'UINT8')
        top.set(base + 'UserPatt1Msb', 0, 'UINT8')
        top.set(base + 'UserPatt2Lsb', 0, 'UINT8')
        top.set(base + 'UserPatt2Msb', 0, 'UINT8')
        top.set(base + 'LvdsLsbFirst', 0, 'boolEnum')

    base = 'expert.EpixQuad.Ad9249Tester.'
    top.set(base + 'TestChannel', 0, 'UINT32')
    top.set(base + 'TestDataMask', 0, 'UINT32')
    top.set(base + 'TestPattern', 0, 'UINT32')
    top.set(base + 'TestSamples', 0, 'UINT32')
    top.set(base + 'TestTimeout', 0, 'UINT32')
    top.set(base + 'TestRequest', 0, 'boolEnum')

    return top
Example #18
0
def epixquad_update(update):
    print('epixquad_update')
    global ocfg
    global base
    # extract updates
    cfg = {}
    update_config_entry(cfg, ocfg, json.loads(update))
    #  Apply to expert
    writePixelMap = user_to_expert(base, cfg, full=False)
    #  Apply config
    config_expert(base, cfg, writePixelMap)
    #  Retain mandatory fields for XTC translation
    for key in ('detType:RO', 'detName:RO', 'detId:RO', 'doc:RO', 'alg:RO'):
        copy_config_entry(cfg, ocfg, key)
        copy_config_entry(cfg[':types:'], ocfg[':types:'], key)

    topname = cfg['detName:RO'].split('_')

    scfg = {}

    #  Rename the complete config detector
    scfg[0] = cfg.copy()
    scfg[0]['detName:RO'] = topname[0] + 'hw_' + topname[1]

    scfg[0] = cfg

    if writePixelMap:
        a = np.array(cfg['user']['pixel_map'], dtype=np.uint8)
        pixelConfigMap = np.reshape(a, (16, 178, 192))
        try:
            trbit = [
                cfg['expert']['EpixQuad'][f'Epix10kaSaci[{i}]']['trbit']
                for i in range(16)
            ]
        except:
            trbit = None

        cbase = base['cam']
        firmwareVersion = cbase.AxiVersion.FpgaVersion.get()
        for seg in range(4):
            carrierId = [
                cbase.SystemRegs.CarrierIdLow[seg].get(),
                cbase.SystemRegs.CarrierIdHigh[seg].get()
            ]
            digitalId = [0, 0]
            analogId = [0, 0]
            id = '%010d-%010d-%010d-%010d-%010d-%010d-%010d' % (
                firmwareVersion, carrierId[0], carrierId[1], digitalId[0],
                digitalId[1], analogId[0], analogId[1])
            top = cdict()
            top.setAlg('config', [2, 0, 0])
            top.setInfo(detType='epix',
                        detName=topname[0],
                        detSegm=seg + 4 * int(topname[1]),
                        detId=id,
                        doc='No comment')
            top.set('asicPixelConfig',
                    pixelConfigMap[4 * seg:4 * seg + 4].tolist(), 'UINT8')
            if trbit is not None:
                top.set('trbit', trbit[4 * seg:4 * seg + 4], 'UINT8')
            scfg[seg + 1] = top.typed_json()

    result = []
    for i in range(len(scfg)):
        result.append(json.dumps(scfg[i]))

#    for i in range(len(scfg)):
#        base['log'].write('--update-- {}\n'.format(i))
#        base['log'].write(result[i])

    return result
Example #19
0
def epixquad_config(base, connect_str, cfgtype, detname, detsegm, rog):
    global ocfg
    global group
    group = rog

    #
    #  Retrieve the full configuration from the configDB
    #
    cfg = get_config(connect_str, cfgtype, detname, detsegm)
    ocfg = cfg

    #  Translate user settings to the expert fields
    user_to_expert(base, cfg, full=True)

    #  Apply the expert settings to the device
    config_expert(base, cfg)

    pbase = base['pci']
    #pbase.DevPcie.Hsio.TimingRx.XpmMiniWrapper.XpmMini.HwEnable.set(True)
    #getattr(pbase.DevPcie.Hsio.TimingRx.TriggerEventManager,f'TriggerEventBuffer[{lane}]').MasterEnable.set(True)
    #getattr(pbase.DevPcie.Application,'AppLane[%d]'%lane).EventBuilder.Blowoff.set(False)
    pbase.StartRun()

    #  Capture the firmware version to persist in the xtc
    cbase = base['cam']
    firmwareVersion = cbase.AxiVersion.FpgaVersion.get()
    #cfg['firmwareVersion:RO'] = cbase.AxiVersion.FpgaVersion.get()
    #cfg['firmwareBuild:RO'  ] = cbase.AxiVersion.BuildStamp.get()

    #    print('--Configuring AsicMatrix for injection--')
    #    cbase.SetAsicMatrixTest()

    ocfg = cfg
    #return [json.dumps(cfg)]

    #
    #  Create the segment configurations from parameters required for analysis
    #
    trbit = [
        cfg['expert']['EpixQuad'][f'Epix10kaSaci[{i}]']['trbit']
        for i in range(16)
    ]

    topname = cfg['detName:RO'].split('_')

    scfg = {}

    #  Rename the complete config detector
    scfg[0] = cfg.copy()
    scfg[0]['detName:RO'] = topname[0] + 'hw_' + topname[1]

    a = np.array(cfg['user']['pixel_map'], dtype=np.uint8)
    pixelConfigMap = np.reshape(a, (16, 178, 192))

    for seg in range(4):
        #  Construct the ID
        carrierId = [
            cbase.SystemRegs.CarrierIdLow[seg].get(),
            cbase.SystemRegs.CarrierIdHigh[seg].get()
        ]
        digitalId = [0, 0]
        analogId = [0, 0]
        id = '%010d-%010d-%010d-%010d-%010d-%010d-%010d' % (
            firmwareVersion, carrierId[0], carrierId[1], digitalId[0],
            digitalId[1], analogId[0], analogId[1])
        top = cdict()
        top.setAlg('config', [2, 0, 0])
        top.setInfo(detType='epix',
                    detName=topname[0],
                    detSegm=seg + 4 * int(topname[1]),
                    detId=id,
                    doc='No comment')
        top.set('asicPixelConfig',
                pixelConfigMap[4 * seg:4 * seg + 4, :176].tolist(),
                'UINT8')  # only the rows which have readable pixels
        top.set('trbit', trbit[4 * seg:4 * seg + 4], 'UINT8')
        scfg[seg + 1] = top.typed_json()

    result = []
    for i in range(5):
        print('json seg {}  detname {}'.format(i, scfg[i]['detName:RO']))
        result.append(json.dumps(scfg[i]))
    return result