esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

C111_MHIP1CARD.MAC
See other macros in category: Other hardware
Description:
    Macros to implement TDC on C111 card through device server
Documentation:
    DESCRIPTION
    These macros implement one C111(TDC) device which is exported by the C111 Linux TACO device server. C111 TACO device server controls access to one C111/P111 TDC card designed by Christian Herve. These macros work with the version V1.4 of C111 device server [which in turn uses version v.0.4.8 of the C111 device driver library]. These macro set does not cover all possible C111 configurations but is written for the specific configuration which is using C111 in MHIP mode. In this mode up to 4 detectors like for ex. APDs can be connected to channels 0-3 (= inputs X1,X2,Y1,Y1) and common start is connected to COM TDC input.
    TDC card is always programmed in Normal mode (test mode has no sense for MHIP mode).

    EXAMPLE
    tdcversion
    (show the version of these macros)
    tdcsetup <device> <RPC timeout>
    (connect to TDC device and powers up ASIC if necessary)
    tdcunsetup
    (remove _tdccleanup from cleanup_always)
    tdcstate
    (state of TDC - idle/running)
    tdcstatus <print>
    (TDC status; if print flag is on, status is printed)
    tdcshow
    (shows most essential config/status fields)
    tdcnewfile <data_dir> <file_prefix> <run_number> (helps defining new file name for saving data outside scans)
    tdcconfig
    (reconfig TDC with the values from the db or interactively set)
    tdctune
    (tune the TDC hardware)
    tdcstattimer <enable_disable> <duration>
    (independently from tdcconfig can dis/enable statistics timer; if no parameters passed, they are set interactively)
    _tdcstatistics
    (read statistics data during acq.)
    tdcregs
    (read value of some C111 registers.)
    tdcsetacqbank <bank_id>
    (independently from tdcconfig can select bank to be used for acquisition; if no parameter passed the acq bank is set interactively)
    tdcswapbanks
    (swap the 2 memory banks)
    tdcinitbank <start_value> <increment_flag>
    (init bank that was selected for acq.; if no parameters passed the init parameters: start_value + increment_flag are set interactively)
    tdcinitbanks <start_value> <increment_flag>
    (init both banks; if no parameters passed the init parameters: start_value + increment_flag are set interactively)
    tdcreadbank
    (read one bank -> the one that is not selected for acquisition)
    tdcreadbanks
    (read both banks)
    tdcsum1b
    (get histogram sum in bank that is not selected for acq)
    tdcsum2b
    (get histogram sum in both banks)
    tdcdata
    (get sum of hits in all 4 histograms, max and digitized chan. at max)
    tdcpower <up/down>
    (power ASIC up or down)
    tdcstart <n>
    (trigger the acquisition on TDC for n seconds (n=0 or if no parameter is passed then acq. is started for "infinite" time)
    tdcstop
    (stop the acquisition on TDC)
    tdcpoll <refresh_period> <read_data_for_display>
    (for finite-time acquisition it polls the state of TDC every refresh_period seconds to see when the acq. is over. It also reads data for display if the seconds flag is on; if no parameters are passed, then the poll period is 3 seconds and data are read for display)
    tdcacq <n> <donotclearflag>
    (make finite-time acquisition for n seconds; if second argument is passed, then the memory is not cleared and data from the new acquisition are cumulated with the data from the previous acq.)
    tdcstatacq <n>
    (make acq. in order to get statistics info; stat timer duration = n secs; acq. stops quickly after stat.timer expiration)
    tdcsave
    (save data to 4 files (1 per TDC input channel) in MCA-like format -> to be used outside counting and scans)
    tdcsave_padi ot tdcsave_jadi
    (save data to 1 file in format for padi/jadi visualization programs
    tdcon
    (switch on TDC acq. in ct and scan)
    tdcoff
    (switch off TDC acq. in ct and scan)
    tdcroishow
    (show the ROI(s) definitions)
    tdcroi <mnemonic> <chan_min> <chan_max>
    (add or modify an ROI)
    tdcroimenu
    (interactively add/remove/modify an ROI)
    tdcroion
    (activate use of ROI counters)
    tdcroioff
    (cancel use of ROI counters)
    tdcsplotrange <xmin> <xmax>
    (define the limit TDC digitized channels for plotting; if no parameters passed, the TDC_PLOTMIN = 0 and TDC_PLOTMAX = TDC_NBCOLS-1)
    tdcplot
    (plots the data for all 4 channels on the same plot (superposed))
    tdcplot0,1,2,3
    (plots the data for one of 4 channels)
    tdctolin/log DD% (changes Y-scale to linear/to logarithmic) ============================================================ Initialization/Setup related macros and functions ============================================================ -------------------------- _tdcvarinit() ---------------------

    DEPENDENCIES
      - The file saveload.mac has to be read in/loaded before
        these macros are used
    


Macros:
    tdcversion
    Usage: tdcversion
    Prints out the version of this software

    tdcsetup
    Usage: tdcsetup
    This macro should normally be invoked at spec session start after C111 macro set was loaded. Connects to TDC device and sets RPC timeout. Usage: tdcsetup <device> <RPC_timeout>

    tdcunsetup
    Usage: tdcunsetup
    Deletes tdc part in cleanup_always

    tdcstatus
    Usage: tdcstatus
    Gives full status information for C111. For brevity did not name this macro tdcgetstatus but tdcstatus

    tdcshow
    Usage: tdcshow
    Show main TDC config/status parameters

    _tdccheckconfig
    Usage: _tdccheckconfig
    Checks that the configuration corresponds to GFD 1D case

    tdcnewfile
    Usage: tdcnewfile [<data-directory> <file-prefix> <run-number>]
    Choose a new directory, file prefix and run/series number for data files when data are saved outside counting and scanning. If the run number is not passed as argument or if the file prefix is changed, the run number is reset to 0. This macro can be used at any moment to change data directory and/or file prefix as defined before in tdcsetup or tdcctscan. Usage: tdcnewfile <data-directory> <file-prefix> <run-number>

    tdcconfig
    Usage: tdcconfig
    Configure C111 TDC either with: - values from the database - or with interactively entered parameters. For brevity did not name this macro tdcsetconfig but tdcconfig

    tdctune
    Usage: tdctune
    Tune + ReConfigure C111 TDC with few new values; i.e. does not cover all parameters but only few which usually need tunning. The following parameters can be changed: - timeout : timeout in ns - skip : Skip flag - set to 0 = ignored for MHIP - extinhfc : External inhibit(0) or Fast Clear Flag(1) Ignored for MHIP = set to 0 (= Ext Inhibit) - offset_x : X offset in ns - set to 0 = ignored for MHIP - offset_y : Y offset in ns - set to 0 = ignored for MHIP - half_res : Half resolution flag - set to 0 = ignored for MHIP - fp_monitor: external signal on front pannel for monitoring - mux_sel : subselection for ASCI monitor

    tdcstattimer
    Usage: tdcstattimer
    Allows to disable or enable statistics timer with certain duration. Statistcs timer disabling/enabling+defining its duration is done among other things in the tdcconfig (= setting config), but this macro can be convenient. It could also use DevC111SetConfig() D.S. command. Usage: tdcstattimer <enable_disable> <duration>

    tdcreadreg
    Usage: tdcreadreg
    Read a register (usefull for debugging) Input: - base adddress reg. index: 0 = AMCC, 1/2 = 1st/2dn group of TDC regs - offs : offset to base

    tdcwritereg
    Usage: tdcwritereg
    Write a register (usefull for debugging) Input: - base adddress reg. index: 0 = AMCC, 1/2 = 1st/2dn group of TDC regs - offs : offset to base - value : register value

    tdcsetacqbank
    Usage: tdcsetacqbank
    Select bank to be used for acquisition. Acq. bank is already selected with tdcconfig, but can be modified with this macro. Usage: tdcsetacqbank <bank_id>

    tdcswapbanks
    Usage: tdcswapbanks
    Swap banks

    tdcinitbank
    Usage: tdcinitbank
    Init bank that is currently selected for acquisition (= bank on port M). Even if user is not using all 4 channels the memory is cleared for all 4 channels. Usage: tdcinitbank <start_value> <increment_flag>

    tdcinitbanks_long
    Usage: tdcinitbanks_long
    Init BOTH banks (start with the one which is already on port M = selected for acquisition, then swap them and clear the other) Even if user is not using all 4 channels the memory is cleared for all 4 channels. Usage: tdcinitbanks_long <start_value> <increment_flag>

    tdcinitbanks
    Usage: tdcinitbanks
    Init BOTH banks. Similar to macro above, but this time more "compact" command ["DevC111InitBothBanks"] is used to make macro short. Usage: tdcinitbanks <start_value> <increment_flag>

    tdcinitwholebank
    Usage: tdcinitwholebank
    Init bank that is currently selected for acquisition (= bank on port M). Complete bank is initialized (= all 128MBytes) Usage: tdcinitwholebank <start_value> <increment_flag>

    tdcinitwholebanks
    Usage: tdcinitwholebanks
    Init BOTH banks. Similar to macro above, but this time more "compact" command ["DevC111InitWholeBanks"] is used to make macro short. Usage: tdcinitwholebanks <start_value> <increment_flag>

    tdcreadbank
    Usage: tdcreadbank
    Read data from ONE bank. The limits for reading out are 0 and TDC_NBCOLS-1. Read all 4 channels.

    tdcreadbanks
    Usage: tdcreadbanks
    Read data from BOTH banks. The limits for reading out are 0 and TDC_NBCOLS-1. Read all 4 channels.

    tdcsum1b
    Usage: tdcsum1b
    Get sum of hits in a histogram(s) from the bank that is not selected for acquisition. Although this set of macros is for MHIP use here general macro (good both for GFD and MHIT/P).

    tdcsum2b
    Usage: tdcsum2b
    Get sum of hits in a histogram(s) from both banks. Although this set of macros is for MHIP use here general macro (good both for GFD and MHIT/P).

    tdcbanksum1b
    Usage: tdcbanksum1b
    Get sum of hits in a complete bank for the bank that is not selected for acquisition. Note that this command takes a lot of time.

    tdcbanksum2b
    Usage: tdcbanksum2b
    Get sum of hits in a complete bank for both banks. Note that this command takes a lot of time.

    tdcdata_old
    Usage: tdcdata_old
    Useful macro for X-check with tdcsum1b/2b. This macro is summing up contents in tdc_datan(n=0->3) for MHIT and tdc_data for GFD. Although this set of macros is for MHIT use here general macro (good both for GFD and MHIT).

    tdcdata
    Usage: tdcdata
    Useful macro for X-check with tdcsum1b/2b. This macro is summing up contents in tdc_datan(n=0->3) for MHIT and tdc_data for GFD. Although this set of macros is for MHIT use here general macro (good both for GFD and MHIT). Since ROI selected for display and readout can be smaller than whole 2D image area (2K*2K pixels for half-resolution 4K*4K pixels for full-resolution) the sum obtained with this macro can be smaller than sum obtained with tdcsum1b/2b. Added in this macro = getting max value and col/row at max value.

    tdcpower
    Usage: tdcpower
    Powers ASIC C111 up or down Usage: tdcpower <up_dn>

    tdcstart
    Usage: tdcstart
    Starts the TDC if it is not running

    tdcstop
    Usage: tdcstop
    Stops the C111 if it is running.

    tdcpoll
    Usage: tdcpoll
    Poll to see when acq. over (only for time limited acq.) Usage: tdcpoll <refresh_period> <read_data_for_display>

    tdcacq_clear
    Usage: tdcacq_clear
    Make a finite-time acquisition where memory in TDC is always cleared so that data from the new acquisition do not cumulate with the data from the previous acquisitons. For short acq. times (< 5 seconds) only 1 bank is used; For longer acq. times (>= 5 seconds) both memory banks are used. Usage: tdcacq_clear <acquisition_time>

    tdcacq1b
    Usage: tdcacq1b
    Make a finite-time acquisition only in 1 bank Memory is cleared before the acquisition. This macro was written to compare the performance of it with the tdcacq macro, where both banks are used. Practically no difference was seen -> so it is more practical to use tdcacq macro and use both banks, which allow to read data during the acquisition for visualization. Usage: tdcacq1b <acquisition_time>

    tdcacq
    Usage: tdcacq
    Make a finite-time acquisition. If pass only 1 parameter (= acq. time) then the TDC memory is always cleared before the acquisition, while if in addition the second parameter is passed the TDC memory is not cleared. Always (= independent of acq. time) both banks are used. If automatic file-saving was selected in tdcconfig (TDC_SAVE) the 4 spectra (1 for each TDC input channel) are saved in MCA-like files with the names: TDC_FILE_PREFIX_N_TDC_RUN_NUMBER, where N is 0,1,2,3 for input channel 0,1,2,3 respectively. If saving in both MCA-like and file for PADI/JADI was selected in tdcconfig(TDC_SAVE_BOTH), then in addition to 4 MCA-like files the file for PADI/JADI is written. Its name is: TDC_FILE_PREFIX_TDC_RUN_NUMBER. Usage: tdcacq <acquisition_time> <donotclearflag>

    tdcstatacq
    Usage: tdcstatacq
    Make a finite-time acquisition to look at statistics Set statistics timer duration shorter than counting time. Usage: tdcstatacq <statistics_timer_duration>

    tdcsave
    Usage: tdcsave
    Save data when acquire outside counting and scanning. Each channel data are saved in its own file, which share in the name the same data directory, the same file prefix, and the same "run" number. They differ in name in channel number (0->4). So it should be possible to read such files with standard tools.

    tdcsave_padi
    Usage: tdcsave_padi
    Save data in a simple ASCII file (when acquire outside scan) Format in the file is such that the data can be then plotted with padi(Python Display) or jadi (Java Display). If the full filename is given as input parameter, then it is used, otherwise the filename is composed from TDC_DATA_DIR, TDC_FILE_PREFIX and TDC_RUN_NUMBER. Usage: tdcsave_padi <filename>

    tdcsave_padi1
    Usage: tdcsave_padi1
    Save data of ONLY ONE channel in a simple ASCII file (when acquire outside scan) Format in the file is such that the data can be then plotted with padi(Python Display) or jadi (Java Display). If the full filename is given as input parameter, then it is used, otherwise the filename is composed from TDC_DATA_DIR, TDC_FILE_PREFIX and TDC_RUN_NUMBER. Usage: tdcsave_padi1 <filename>

    tdcsave_old
    Usage: tdcsave_old
    Save data in a simple ASCII file (when acquire outside scan) Format in the file is such that the data can be then plotted with cplot. If the full filename is given as input parameter, then it is used, otherwise the filename is composed from TDC_DATA_DIR, TDC_FILE_PREFIX and TDC_RUN_NUMBER. NB: Note that the format limits the values to 16-bit dynamic range (like used in MCA!!!), although arrays tdc_data0-3 are unsigned long. Usage: tdcsave_old <filename>

    _tdcctscan
    Usage: _tdcctscan
    Activate or not TDC acquisition during the counting and scanning. When in scan and when DATAFILE is not /dev/null, the 1D TDC spectrum is saved in a standard SPEC scan file as MCA spectrum.

    tdcon
    Usage: tdcon
    Switch on TDC acq. during ct + scan By modifying user_prepcount + user_getcount rather than measure0 and measure1 the code below is good both for counting AND scanning. If would modify measure0/1 than tdcon would swich on TDC acq. only during scan and not during normal counting.

    tdcoff
    Usage: tdcoff
    Switch off TDC acq. during ct + scan

    tdcroishow
    Usage: tdcroishow
    Macro to Show the ROI definitions.

    tdcroi
    Usage: tdcroi
    Macro to Add/Remove/Modify ROIs used to get integral count for each of them. ROI index goes from 1 to 8.

    tdcroimenu
    Usage: tdcroimenu
    Macro to Interactively Add/Remove/Modify ROI(s) to get integral of counts for channels within ROI.

    tdcroioff
    Usage: tdcroioff
    Macro to Cancel the use of ROI counters.

    tdcroion
    Usage: tdcroion
    Macro to Activate the use of ROI counters.

    tdcplot
    Usage: tdcplot
    Macro that wraps _tdcsplotlin and which is to be used without parameters i.e. it creates a plot covering channels between TDC_PLOTMIN and TDC_PLOTMAX. It is defined to make a plot with linear Y-scale. (need this definition before doing tdctolog where the macro is redefined).

    tdcplot0
    Usage: tdcplot0
    Macro that wraps _tdcsplotlin1 for each one of 4 TDC input channels. It creates a plot for selected TDC input channel covering digitized channels between TDC_PLOTMIN and TDC_PLOTMAX. It is defined to make a plot with linear Y-scale. (need this definition before doing tdctolog where the macros are redefined).

    tdctolin
    Usage: tdctolin
    Macro to redefine tdcplot (all 4 channels) and tdcplot1 (1 ch.) to plot in linear Y-scale.

    tdctolog
    Usage: tdctolog
    Macro to redefine tdcplot (all 4 channels) and tdcplot1 (1 ch.) to plot in logarithmic Y-scale.

    tdcsplotrange
    Usage: tdcsplotrange
    Macro that allows to change limit channels for plotting if new limits are passed as input parameters. tdcsplotrange <xmin> <xmax> If no parameters passed then TDC_PLOTMIN = 0 and TDC_PLOTMAX = TDC_NBCOLS-1

Internal Macros:
    _tdcvarinit
    Usage: _tdcvarinit()
    Internal macro to declare global variables and initialise some.

    _tdccleanup
    Usage: _tdccleanup
    Macro executed at cleanup(CTRL-C)

    tdcstate
    Usage: tdcstate
    Get and show the state of TDC device For brevity did not name this macro tdcgetstate but tdcstate

    _tdcgetconfig
    Usage: _tdcgetconfig
    Get TDC configuration parameters (less than full status)

    _tdcreconfig
    Usage: _tdcreconfig
    ReConfigure C111 TDC with values FROM the DATABASE.

    _tdcsetconfig
    Usage: _tdcsetconfig
    ReConfigure C111 with values entered interactively

    _tdcstatistics
    Usage: _tdcstatistics
    Gives statistics information for C111

    tdcregs
    Usage: tdcregs
    Read value of some C111 registers (usefull for debugging)

    _tdcsavemultiprivate
    Usage: _tdcsavemultiprivate(chn)
    Writes a header and data into channel specific file. Inside the same macros (_tdc_savemultichnheader and _tdc_savemultichndata) are used as in tdc_user_scan_loop

    tdcsave_jadi
    Usage: tdcsave_jadi


    tdc_prepcount
    Usage: tdc_prepcount
    Done at each scan point before counting

    tdc_pollcounts
    Usage: tdc_pollcounts
    Done during counting when polling for end of counting with polling interval COUNTERSPOLLTIME (0.01sec) We DO NOT USE it!!!!!!!!

    tdc_getcounts
    Usage: tdc_getcounts
    Done at each scan point, after counting and in scan also during counting if selected by setscans. TDC is stopped only when the counting is over (i.e. when chk_count = 0).

    tdc_user_scan_loop
    Usage: tdc_user_scan_loop
    Adds TDC data to scan file This macro adds TDC data to scan file for all 4 TDC input channels. For simplicity assume that will always record all 4 channel data. So this macro is somewhat similar to mcasavescandata. TODO: refine so to choose which channel(s) to record. REMARK: test on TDC_SAVEONLYROI is done in case macro tdc_user_scan_loop is still hooked to user_scan_loop.

    _tdc_savemultichndata
    Usage: _tdc_savemultichndata (file, chn)
    Save TDC spectrum data for TDC input channel <chn>
    Return 0 on sucess, -1 otherwise, to be consitent with logic in saveload.mac. Inside scan do nothing if only integral of ROI cnts required Outside scan write complete spectrum.

    tdc_user_scan_loop_old
    Usage: tdc_user_scan_loop_old
    Adds TDC data to scan file

    tdc_savehead
    Usage: tdc_savehead
    For all 4 TDC input channels this macro adds info on nb of channels read and elapsed time in scan header Since in C111 server(driver) do not measure the acq. time take the scan time per scan point. For simplicity assume that will always record all 4 channel data. So this macro is somewhat similar to mcasavescanheader. TODO: refine so to choose which channel(s) to record.

    _tdc_savemultichnheader
    Usage: _tdc_savemultichnheader(file,chn,withtime)
    Saves channel specfic header info TODO: see if it works like it is or need to change COUNT_TIME to _ctime

    tdc_savehead_old
    Usage: tdc_savehead_old
    Adds info on nb of channels read and elapsed time in scan header Since in C111 server(driver) do not measure the acq. time take the scan time per scan point. For simplicity assume that will alwys record all 4 channel data. So this macro is somewhat similar to mcaisavescanheader (which calls in turn savemultimcaheader). TODO: refine so to choose which channel(s) to record.

    _tdcroiset
    Usage: _tdcroiset(cmne,tdcchan,cmin,cmax)
    Internal macro function to Setup(= Add or Modify) an ROI. cmne = pseudo-counter mnemonic, tdcchan = TDC input channel (0->3) cmin/max = min/max digital channel

    _tdcroishow
    Usage: _tdcroishow ()
    Internal macro function to show ROI(s) definitions.

    _tdcsplotlin
    Usage: _tdcsplotlin
    Internal macro to create plot and display 1D TDC spectrum using standard SPEC plotting with linear Y scale. - abscissa array = coloumns array = tdc_xdata - ordinate array = TDC data for all 4 channels = tdc_data0-3 The range of TDC channels to be plotted is between minimum and maximum digitized TDC channel which are passed as parameters along with macro name: _tdcsplotlin <xmin> <xmax>

    _tdcsplotlin1
    Usage: _tdcsplotlin1
    Internal macro to create plot and display 1D TDC spectrum using standard SPEC plotting with linear Y scale. - abscissa array = coloumns array = tdc_xdata - ordinate array = TDC data for ONE channel (0->3) which is passed as first parameter. The range of TDC channels to be plotted is between minimum and maximum digitized TDC channel which are passed as parameters along with macro name: _tdcsplotlin1 <inch> <xmin> <xmax>

    _tdcsplotlog
    Usage: _tdcsplotlog
    Internal macro to create plot and display 1D TDC spectrum using standard SPEC plotting with logarithmic Y scale. - abscissa array = coloumns array = tdc_xdata - ordinate array = TDC data for all 4 channels = tdc_data0-3 The range of TDC channels to be plotted is between minimum and maximum digitized TDC channel which are passed as parameters along with macro name: _tdcsplotlog <xmin> <xmax>

    _tdcsplotlog1
    Usage: _tdcsplotlog1
    Internal macro to create plot and display 1D TDC spectrum using standard SPEC plotting with logarithmic Y scale. - abscissa array = coloumns array = tdc_xdata - ordinate array = TDC data for ONE channel (0->3) which is passed as first parameter. The range of TDC channels to be plotted is between minimum and maximum digitized TDC channel which are passed as parameters along with macro name: _tdcsplotlin1 <inch> <xmin> <xmax>

    tdcplot1
    Usage: tdcplot1


    tdcplot2
    Usage: tdcplot2


    tdcplot3
    Usage: tdcplot3


    tdcgetbank
    Usage: tdcgetbank


    tdcinvest
    Usage: tdcinvest


Filename: c111_mhip.mac
Author:
Last mod.: 26/06/2007 09:51 by rey