ext_trigger_readout.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/bin/bash
  2. usage="
  3. $(basename "$0") [-h] [-f NNNNN] [-d AAAA] [-a n] [-s n]
  4. -- script to acquire with KALYPSO with external trigger
  5. ------------------------------------------------
  6. where:
  7. -h show this help text
  8. -f set the fill number (default: 12345)
  9. -d set the detector name (default: Si01)
  10. -a set the number of triggers to acquire (default: 8)
  11. -s set the skip value (default: 0)
  12. Note: to stop acquisition, create a 'stop_aq' file in the running directory
  13. ------------------------------------------------"
  14. # A POSIX variable
  15. OPTIND=1 # Reset in case getopts has been used previously in the shell.
  16. # Initialize our own variables:
  17. # fill_num="12345"
  18. # det_name="Si01"
  19. extension=".bin"
  20. acquisitions=1000
  21. skip=0
  22. div="_"
  23. fill_prefix="f"
  24. fill_numFlag=false
  25. det_nameFlag=false
  26. bg_delay=20
  27. sig_delay=49
  28. bum="m"
  29. while getopts 'hd:f:as' opt; do
  30. case "$opt" in
  31. h) echo "$usage"
  32. exit
  33. ;;
  34. a) acquisitions=$OPTARG
  35. ;;
  36. s) skip=$OPTARG
  37. ;;
  38. f) fill_num=$OPTARG
  39. fill_numFlag=true
  40. ;;
  41. d) det_name=$OPTARG
  42. det_nameFlag=true
  43. ;;
  44. esac
  45. done
  46. shift $((OPTIND-1))
  47. [ "$1" = "--" ] && shift
  48. if ! $fill_numFlag; then
  49. echo "Error: please specify the fill number with -f option (e.g. -f 12345)" >&2
  50. echo "Use $(basename "$0") -h for help" >&2
  51. exit
  52. fi
  53. if ! $det_nameFlag; then
  54. echo "Error: please specify the detector name with -d option (e.g. -d Si01)" >&2
  55. echo "Use $(basename "$0") -h for help" >&2
  56. exit
  57. fi
  58. if [ -e "stop_aq" ]; then
  59. rm "stop_aq"
  60. fi
  61. echo "Data Reset ... "
  62. pci -w 0x9040 0x000fff01
  63. echo "Writing Acquisitions ($acquisitions) and Skip ($skip)"
  64. pci -w 9024 $acquisitions
  65. sleep 0.1
  66. pci -w 902C $skip
  67. sleep 0.1
  68. echo "System is ON, now waiting for External trigger..."
  69. pci -w 0x9040 000fff00
  70. sleep 1
  71. for (( i=1; i<=$acquisitions; i++ ))
  72. do
  73. tmpfname=$output_file$i$extension
  74. echo "Acquiring dataset $i of $acquisitions in $tmpfname..."
  75. ## Wait until a new acquisition is acquired...
  76. ACQ_NUM="$(pci -r 9034 | sed 's/.*[0-9]: //';)"
  77. ACQ_NUM="$((16#$ACQ_NUM))"
  78. ACQ_NUM_TEMP="$(pci -r 9034 | sed 's/.*[0-9]: //';)"
  79. ACQ_NUM_TEMP="$((16#$ACQ_NUM_TEMP))"
  80. while [ "$ACQ_NUM_TEMP" -eq "$ACQ_NUM" ]
  81. do
  82. ACQ_NUM_TEMP="$(pci -r 9034 | sed 's/.*[0-9]: //';)"
  83. ACQ_NUM_TEMP="$((16#$ACQ_NUM_TEMP))"
  84. sleep 0.01
  85. now=$(date +"%T")
  86. echo -ne "$now : Waiting for new trigger..."\\r
  87. done
  88. pci -r dma0 --multipacket -o $tmpfname --timeout $(($(($skip+1))*15000000))
  89. #echo "Acquired at: $now"
  90. creationtime="$(date +"%Y-%m-%dT%Hh%Mm%Ss" -r $tmpfname)"
  91. pci -w 0x9040 0x000fff01
  92. sleep 0.01
  93. pci -w 0x9040 0x000fff00
  94. mv $tmpfname $fill_prefix${fill_num}_${creationtime}_${det_name}_$bum$extension
  95. echo "Acquired at $now: $fill_prefix${fill_num}_${creationtime}_${det_name}_$bum$extension"
  96. python write_csv.py -f $fill_prefix${fill_num}_${creationtime}_${det_name}_$bum$extension
  97. sleep 0.1
  98. MODUL="$(($i%12))"
  99. if ((MODUL == 0)); then
  100. echo "Moving to Background"
  101. pci -w 9004 $(printf %x $bg_delay)
  102. bum="bg"
  103. pci -r 9004
  104. else
  105. echo "Moving to Signal"
  106. pci -w 9004 $(printf %x $sig_delay)
  107. bum="m"
  108. pci -r 9004
  109. fi
  110. if [ -e "stop_aq" ]; then
  111. echo "Found 'stop_aq' file, data taking will now stop."
  112. break
  113. fi
  114. done
  115. #
  116. #
  117. #
  118. #
  119. # for (( i=1; i<=$acquisitions; i++ ))
  120. # do
  121. # echo "Acquiring dataset $i of $acquisitions..."
  122. # pci -r dma0 --multipacket -o $i$extension --timeout $(($(($skip+1))*10000000))
  123. # now=$(date +"%T")
  124. # echo "Acquired at: $now"
  125. # creationtime="$(date +"%Y-%m-%dT%Hh%Mm%Ss" -r $i$extension)"
  126. # # creationtimeunix="$(date +"%s" -r $i$extension)"
  127. # mv $i$extension $fill_prefix${fill_num}_${creationtime}_${det_name}$extension
  128. # echo "Saved in $fill_prefix${fill_num}_${creationtime}_${det_name}$extension"
  129. # sleep 0.1
  130. # done
  131. echo "Acquisition done!"
  132. pci -w 0x9040 400000ff
  133. sleep 0.1
  134. pci -w 9024 0
  135. sleep 0.1
  136. pci -w 902C 0
  137. sleep 0.1