# Move Telescope to Wobble Position 1
.! echo `date -u`  "data taking script for Wobble 1 starting up... " >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
.! echo `date -u`  "----------------------------------------------------" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
.! echo
.! echo `date -u`  "Operator: make sure that telescope is tracking wobble position 1 of source" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
.! echo `date -u`  "... This script will wait 10sec for you" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
.w 10000
FEEDBACK/ENABLE_OUTPUT 1

# Making sure bias is off
BIAS_CONTROL/SET_ZERO_VOLTAGE
.s BIAS_CONTROL 7
FAD_CONTROL/START_DRS_CALIBRATION
.! echo `date -u`  "bias voltage is switched off" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.! echo `date -u`  "taking DRS:Pedestal 1000 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
.s FAD_CONTROL 4
MCP/START -1 1000 drs-pedestal
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.! echo `date -u`  "taking DRS:Gain 1000 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
MCP/START -1 1000 drs-gain
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.! echo `date -u`  "taking DRS:Pedestal 1000 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
MCP/START -1 1000 drs-pedestal
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.! echo `date -u`  "taking crosscheck DRS:Pedestal 1000 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
FAD_CONTROL/SET_FILE_FORMAT 2
MCP/START -1 1000 drs-pedestal
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.! echo `date -u`  "taking DRS:Time 1000 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
MCP/START -1 1000 drs-time
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.! echo `date -u`  "taking DRS:Time upshifted 1000 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
MCP/START -1 1000 drs-time-upshifted
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.! echo `date -u`  "taking Pedestal 1000 for secondary baseline..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
FAD_CONTROL/RESET_SECONDARY_DRS_BASELINE
MCP/START -1 1000 pedestal
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.! echo `date -u`  "taking crosscheck Pedestal 1000 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
FAD_CONTROL/SET_FILE_FORMAT 2
MCP/START -1 1000 pedestal
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
.! echo `date -u`  "Operator: Measure Sky Brightness" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.! echo `date -u`  "switching on bias ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
BIAS_CONTROL/SET_GLOBAL_DAC 1
.s BIAS_CONTROL 9
.s BIAS_CONTROL 5
.s BIAS_CONTROL 9
# here one should wait 30..45sec according to TB
.! echo `date -u`  "bias is on, and feedback-program is working, but we wait 45sec for the current readings..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
.w 45000
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.x ScriptsForDimCtrl/IsReadyForDataTaking
.! echo `date -u`  "taking Pedestal with BIAS on 1000 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
MCP/START -1 1000 pedestal
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.x ScriptsForDimCtrl/IsReadyForDataTaking
.! echo `date -u`  "taking External Light Pulser with BIAS on 1000 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
MCP/START -1 1000 light-pulser-ext
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

#Data Taking with Full Trigger Area (4x5min)
.x ScriptsForDimCtrl/IsReadyForDataTaking
.! echo `date -u`  "taking Data:FullTriggerArea 5min Run 1 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
MCP/START 300 -1 data
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.x ScriptsForDimCtrl/IsReadyForDataTaking
.! echo `date -u`  "taking Data:FullTriggerArea 5min Run 2 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
MCP/START 300 -1 data
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.x ScriptsForDimCtrl/IsReadyForDataTaking
.! echo `date -u`  "taking Data:FullTriggerArea 5min Run 3 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
MCP/START 300 -1 data
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.x ScriptsForDimCtrl/IsReadyForDataTaking
.! echo `date -u`  "taking Data:FullTriggerArea 5min Run 4 ..." >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
MCP/START 300 -1 data
.s FAD_CONTROL 8
.s FAD_CONTROL 4
.! echo `date -u`  "... done" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

.! echo `date -u` "----------------------------------------------------" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log
.! echo `date -u` "This is the end of data taking of Wobble 1" >> ~/FACT++/ScriptsForDimCtrl/DataTaking.log

