#!/bin/bash
export PATH=$PATH:~/trbsoft/daqtools/users/gsi_dirc
-
-#trbcmd reset
-check_ping.pl --reboot
-rc=$?; if [[ $rc != 0 ]]; then echo "exit from startup as not all boards are up"; exit $rc; fi
-
export TRB3_SERVER=trb056:26000
export TRBNETDPID=$(pgrep trbnetd)
echo "- trbnetd pid: $TRBNETDPID"
-
if [[ -z "$TRBNETDPID" ]]
then
~/bin/trbnetd -i 56
fi
+trbcmd reset
+check_ping.pl --reboot
+rc=$?; if [[ $rc != 0 ]]; then echo "exit from startup as not all boards are up"; exit $rc; fi
+
+
export DAQOPSERVER=localhost:56
#export DAQOPSERVER=localhost
+#js just for a minute
+#??
./trbreset_loop.pl
##################################################
# AUX TDCs
trbcmd clearbit 0xfe4a 0xc800 0x2000 ## clear bit to reset the epoch and coarse counters
-trbcmd w 0xfe4a 0xc800 0x00002000 ## Triggered mode
-trbcmd w 0xfe4a 0xc801 0x801e0046 ## triggerwindow -350...+150ns ;5ns granularity
-#trbcmd w 0xfe4a 0xc801 0x80c600c6 ## triggerwindow +/-990ns ;5ns granularity
+trbcmd w 0xfe4a 0xc800 0x00002000 ## Triggerless mode, reset next trigger all coarse counters
+#trbcmd w 0xfe4a 0xc800 0x00000000 ## Triggerless mode, reset next trigger all coarse counters
+#trbcmd w 0xfe4a 0xc801 0x801e0046 ## triggerwindow -350...+150ns ;5ns granularity
+trbcmd w 0xfe4a 0xc801 0x80c600c6 ## triggerwindow +/-990ns ;5ns granularity
trbcmd w 0xfe4a 0xc802 0x00000000 ## channel 33-64 enable
-trbcmd w 0x202c 0xc802 0xffffffff ## channel 01-32 enable
-trbcmd w 0x202d 0xc802 0xffffffff ## channel 01-32 enable
+#trbcmd w 0x202c 0xc802 0xffffffff ## channel 01-32 enable
+#trbcmd w 0x202d 0xc802 0xffffffff ## channel 01-32 enable
trbcmd w 0xfe4a 0xc803 0x00000000 ## channel 33-64 enable
trbcmd w 0xfe4a 0xc804 0x0000007c ## data transfer limit
-
+echo -n "register_config_tdc"
~/trbsoft/daqtools/tools/loadregisterdb.pl register_config_tdc.db
# Reset trigger logic - only a workaround for a bug
#trbcmd w 0xffff 0x20 0x33
-#20150522 Jan comment
-~/trbsoft/daqtools/padiwa.pl 0xfe4c 0 time > /dev/null;~/trbsoft/daqtools/padiwa.pl 0xfe4c 1 time > /dev/null; ~/trbsoft/daqtools/padiwa.pl 0xfe4c 2 time > /dev/null
+
+
+#20150522 Jan comment, Merlin auskommentiert
+#~/trbsoft/daqtools/padiwa.pl 0xfe4c 0 time > /dev/null;~/trbsoft/daqtools/padiwa.pl 0xfe4c 1 time > /dev/null; ~/trbsoft/daqtools/padiwa.pl 0xfe4c 2 time > /dev/null
+
+
+
+
# Barrel DIRC
# enable stretch prepare_padiwas_invert_leds.pl --endpoints=0x2000-0x2013 --chains=0..2 --invert=0xffff --stretch=0xffff
-prepare_padiwas_invert_leds.pl --endpoints=0x2000..0x200b --chains=0..2 --invert=0xffff
+#prepare_padiwas_invert_leds.pl --endpoints=0x2000..0x200b --chains=0..2 --invert=0xffff
+#20170822 prepare_padiwas_invert_leds.pl --endpoints=0x2000..0x2003 --chains=0..2 --invert=0xffff
+
+
+prepare_padiwas_invert_leds.pl --endpoints=0x2000..0x200f --chains=0..2 --invert=0xffff
+
+#Invert erlangen
+prepare_padiwas_invert_leds.pl --endpoints=0x2014..0x201d --chains=0..1 --invert=0xffff
+
padiwa_led_off.pl
-# Beam
-#prepare_padiwas_invert_leds.pl --endpoints=0x2014-0x201f --chains=0..2 --invert=0xffff
+#invert Erlangen Padiwas
+#~/trbsoft/daqtools/users/gsi_dirc/setup_erlangen.sh
+
+
+# Beam (TOF/Hodo)
+#prepare_padiwas_invert_leds.pl --endpoints=0x2018-0x201f --chains=0..2 --invert=0xffff
+#~/trbsoft/daqtools/padiwa.pl 0x201c 0 invert f
# disable unused TDCs
# turn off two unused TDCs in HODO
-# turn off two unused TDCs in TOF1
-#switchport.pl 0x8005 3 off
+#------------------------------------------------
+# taken out by Carsten for debugging 26-July-2018
-# turn off two unused TDCs in TOF1
+#switchport.pl 0x8007 3 off
+#switchport.pl 0x8007 2 off
+
+#------------------------------------------------
+
+# turn off two unused TDCs in TOF2
+#switchport.pl 0x8006 2 off
#switchport.pl 0x8006 3 off
+# turn off two unused TDCs in TOF1
+#switchport.pl 0x8007 2 off
+#switchport.pl 0x8007 3 off
+
+# turn off two unused TDCs in HODO
+#switchport.pl 0x8005 2 off
+#switchport.pl 0x8005 3 off
# timeouts
trbcmd w 0xfffe 0xc5 0x800050ff
# ./write_thresholds.pl padiwa_threshold_results_05jul16.log -o 600
#./write_thresholds.pl padiwa_threshold_results_sequential_2016_08_30_offset_0.log -o 130
#./write_thresholds.pl padiwa_threshold_results_sequential_2016_09_06_offset_0.log -o 130
-./write_thresholds.pl padiwa_threshold_results_blockwise_2016_10_05.log -o 1200
-
-#sleep 2
+#./write_thresholds.pl padiwa_threshold_results_blockwise_2016_10_07a.log -o 800
+#evening 10/18./write_thresholds.pl padiwa_threshold_results_blockwise_2016_10_18.log -o 1000
+#evening 10/19./write_thresholds.pl padiwa_threshold_results_blockwise_2016_10_19.log -o 500
+#10/20 7pm ./write_thresholds.pl padiwa_threshold_results_blockwise_2016_10_22f.log -o 500
+#10/23 change to symlink
+
+# 10/24 disabled for a few special runs ./write_thresholds.pl padiwa_threshold_results_latest.log -o 1000
+# 10/31 test ./write_thresholds.pl padiwa_threshold_results_latest.log -o 500
+# 11/01 ./write_thresholds.pl padiwa_threshold_results_latest.log -o 250
+
+# 8/26./write_thresholds.pl padiwa_threshold_results.log -o 600
+#./write_thresholds.pl padiwa_threshold_results_blockwise_20170826_1745.log -o 600
+### ./write_thresholds.pl padiwa_threshold_results_blockwise_20170829_1101.log -o 600
+
+
+#
+#./write_thresholds.pl padiwa_threshold_results_blockwise_20170831_0835.log -o 600
+
+# ./split_thresholds.sh padiwa_threshold_results_blockwise_20170901_2119.log
+# ./split_thresholds.sh padiwa_threshold_results_blockwise_20170902_1718.log
+#./split_thresholds.sh padiwa_threshold_results_blockwise_20170905_1901.log
+#./split_thresholds.sh padiwa_threshold_results_blockwise_20170906_1825.log
+#./split_thresholds.sh padiwa_threshold_results_blockwise_20170910_1857.log
+#./split_thresholds.sh cern2017_beam/padiwa_threshold_results_blockwise_20170911_1330.log
+# ./write_thresholds.pl padiwa_threshold_results_blockwise_20180727.log -o 600
+#./write_thresholds.pl padiwa_threshold_results_blockwise_20180728_1132.log -o 600
+#./write_thresholds.pl padiwa_threshold_results_blockwise_20180729_1015.log -o 600
+#./split_thresholds.sh padiwa_threshold_results_blockwise_20180804_0945.log
+#./split_thresholds.sh padiwa_threshold_results_blockwise_20180809_1915.log
+#./split_thresholds.sh padiwa_threshold_results_blockwise_20180810_1130.log
+#./split_thresholds.sh padiwa_threshold_results_blockwise_20180811_2000.log
+#./split_thresholds.sh padiwa_threshold_results_blockwise_20180813_1100.log
+##################./split_thresholds.sh padiwa_threshold_results_blockwise_20180814_1115.log
+#./split_thresholds.sh padiwa_threshold_results_31jan2018.log
+## ./split_thresholds.sh padiwa_threshold_results.log
+
+echo "padiwa_threshold_results loading"
+
+#./write_thresholds.pl mcp00.log -o 600
+#./write_thresholds.pl mcp01.log -o 600
+#./write_thresholds.pl mcp02.log -o 600
+#./write_thresholds.pl mcp03.log -o 600
+#./write_thresholds.pl mcp04.log -o 600
+#./write_thresholds.pl mcp05.log -o 600
+#./write_thresholds.pl mcp06.log -o 600
+#./write_thresholds.pl mcp07.log -o 600
+#./write_thresholds.pl mcp08.log -o 700 #20170911
+#./write_thresholds.pl mcp09.log -o 700 #20170912
+#./write_thresholds.pl mcp10.log -o 600
+#./write_thresholds.pl mcp11.log -o 600
+
+#./write_thresholds.pl mcp00.log -o 600
+#./write_thresholds.pl mcp01.log -o 1200 # 1200 30.7.2018
+#./write_thresholds.pl mcp02.log -o 600
+#./write_thresholds.pl mcp03.log -o 600
+#./write_thresholds.pl mcp04.log -o 600
+#./write_thresholds.pl mcp05.log -o 600
+#./write_thresholds.pl mcp06.log -o 600
+./write_thresholds.pl padiwa_threshold_results.log -o 600
+
+#./write_thresholds.pl mcp08.log -o 900 #20170911
+#./write_thresholds.pl mcp09.log -o 600 #20170912
+#./write_thresholds.pl mcp10.log -o 600
+#./write_thresholds.pl mcp11.log -o 600
+
+
+# 10/26 quick fix to set special threshold for 0x2006/0 = +1mV
+#grep '0x2006' padiwa_threshold_results_latest.log | grep 'chain: 00' >! padiwa_thresholds_current_0x2006-0.txt
+#./write_thresholds.pl padiwa_thresholds_current_0x2006-0.txt -o 1000
+
+
+#./write_erlangen.sh
-#echo "write mcp and scitil thresholds"
-#MCP-TOF, SciTils
-#./write_thresholds.pl mcptof_mcpout_zero.log -o 0 >> /dev/null # =10 mV before amp
-#./write_thresholds.pl mcptof_pixels_zero.log -o 0 >> /dev/null # =10 mV before amp
-#./write_thresholds.pl mcptof_scitil_noatt_zero.log -o 0 >> /dev/null # =10 mV before amp
-#./write_thresholds.pl mcptof_hodo_zero.log -o 0 >> /dev/null # =7 mV before amp
-#./write_thresholds.pl mcptof_chanmerge_mcpnoamp_zero.log -o 0 >> /dev/null # =7 mV before amp
-#sleep 2
-#./write_thresholds.pl mcptof_mcpout_zero.log -o 400 >> /dev/null # =10 mV before amp
-#./write_thresholds.pl mcptof_pixels_zero.log -o 1500 >> /dev/null # =10 mV before amp
-#./write_thresholds.pl mcptof_scitil_noatt_zero.log -o 400 >> /dev/null # =10 mV before amp
-#./write_thresholds.pl mcptof_hodo_zero.log -o 1000 >> /dev/null # =7 mV before amp
-#./write_thresholds.pl mcptof_chanmerge_mcpnoamp_zero.log -o 400 >> /dev/null # =7 mV before amp
#echo "led off"
#echo "- setting trigger rate register in TDC";
# trigger rate 1500Hz
-trbcmd w 0xc000 0xa150 0x0001869f
+trbcmd w 0xc000 0xa154 0x0001869f
# pulser enable
#trbcmd setbit 0xc000 0xa101 0x2
# enable multiplexer 0
-trbcmd setbit 0xc000 0xa101 0x30
+# js 20170909 trbcmd setbit 0xc000 0xa101 0x30
+trbcmd setbit 0xc000 0xa101 0x18
+
+
+# js 20170909 trbcmd w 0xc000 0xa154 0x270f #10kHz pulser
+trbcmd w 0xc000 0xa154 0x0001869f #1kHz pulser for TRB calib
+trbcmd w 0xc000 0xa155 0x05f5e100 #1Hz pulser
-trbcmd w 0xc000 0xa150 0x270f #1kHz pulser
-trbcmd w 0xc000 0xa151 0x05f5e100 #1Hz pulser
-trbcmd loadbit 0xc000 0xa158 0x00000f00 0x00000d00 #Pulser 1 is calibration
+##trbcmd w 0xc000 0xa159 0x11111d1d # type0=0xd_tdc_calibration_trigger
+# js 20170909 ttrbcmd loadbit 0xc000 0xa159 0x00000f00 0x00000d00 #Pulser 1 is calibration
# disable all triggers