-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·271 lines (226 loc) · 10.1 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/env bash
set -x
# BINDIR should point to the psrdada installation
if [ x$BINDIR == x ]; then
echo "Please set BINDIR"
exit
fi
# FITS_TEMPLATES should be set to the directory containing the templates
if [ x$FITS_TEMPLATES == x ]; then
echo "Please set FITS_TEMPLATES"
exit
fi
######################################################################
echo "Observation configuration"
######################################################################
# Set the science case:
# 3: 12500 sampels/1.024 seconds
# 4: 25000 samples/1.024 seconds
SCIENCE_CASE=3
# Set beam type (note, science_mode is derived from this for the I and IQUV data flows)
# TAB: mode 0 (I+TAB) for Stokes I, and mode 1 (IQUV+TAB) for Stokes IQUV
# IAB: mode 2 (I+IAB) for Stokes I, and mode 3 (IQUV+IAB) for Stokes IQUV
BEAM_TYPE=IAB
# Start time of observation
START_STAMP=`date +%s`
UTC_START=`date -u +%Y-%m-%d-%H:%M:%S --date "@${START_STAMP}"`
# Start packet: TODO how was this again?
START_PACKET=10
# Duration of observation in seconds
DURATION=30
# NOTE: output directories should exist, files are not overwritten
OUTPUT_FULL_IQUV=./output/ # directory
OUTPUT_FULL_I=./output/fulli # directory plus prefix of filename: /full/path/file -> /full/path/file_01.fil
OUTPUT_REDUCED_I=./output # directory
# NOTE: full paths to logfiles, directories should exist
LOG_WRITER_FULL_I=./output/log_full_i.txt
LOG_WRITER_FULL_IQVU=./output/log_full_iquv.txt
LOG_WRITER_REDUCED_I=./output/log_reduced_i.txt
LOG_TRIGGER=./output/log_trigger.txt
LOG_NETWORK_I=./output/log_fill_i.txt
LOG_NETWORK_IQUV=./output/log_fill_iquv.txt
######################################################################
# Static config (does not depend on specific observation)
######################################################################
# AMBER uses padding to optimize memory layout. Specifiy padding sizes here:
# note: this should be at least 12500 for science case 3, and 25000 for science case 4
if [ x${SCIENCE_CASE} = x3 ]
then
SAMPLES_PER_BATCH=12500
FULL_I_PADDED_SIZE=12588
elif [ x${SCIENCE_CASE} = x4 ]
then
SAMPLES_PER_BATCH=25000
FULL_I_PADDED_SIZE=25088
else
echo "Illegal science case: $SCIENCE_CASE"
exit -1
fi
if [ x${BEAM_TYPE} = xTAB ]
then
NTABS=12;
SCIENCE_MODE_I=0
SCIENCE_MODE_IQUV=1
elif [ x${BEAM_TYPE} = xIAB ]
then
NTABS=1;
SCIENCE_MODE_I=2
SCIENCE_MODE_IQUV=3
else
echo "Illegal beam type, cannot derive science mode: $BEAM_TYPE"
fi
# When AMBER indicates there is a possible FRB, full StokesIQUV data in a window around the event
# must be written to disk. Therfore, we need to hold on to old data until it is outside of a possible window
TRIGGER_HISTORY=5 # maximum delay (s) to retain data for
# Network ports for incomming data streams
PORT_I=8001
PORT_IQUV=8002
# main buffer I
# NTABS x NCHANNELS x PADDING bytes
MAINI_KEY=dada
let "MAINI_SIZE = ${NTABS} * 1536 * ${FULL_I_PADDED_SIZE}"
MAINI_COUNT=3
# main buffer IQUV
# NTABS x NCHANNELS x NPOLS x NTIMES bytes
MAINIQUV_KEY=dadc
let "MAINIQUV_SIZE = ${NTABS} * 1536 * 4 * ${SAMPLES_PER_BATCH}"
let "MAINIQUV_COUNT= 3 + ${TRIGGER_HISTORY}"
# disk buffer IQUV
# should hold exaclty one page of the main iquv buffer
DISKIQUV_KEY=dade
DISKIQUV_SIZE=${MAINIQUV_SIZE}
DISKIQUV_COUNT=3
######################################################################
echo "Start the dada_db ring buffers"
######################################################################
# delete ringbuffers TODO: do we really want that? it could accidentally kill another observation
${BINDIR}/dada_db -d -k ${MAINI_KEY} 2>&1 > /dev/null
${BINDIR}/dada_db -d -k ${MAINIQUV_KEY} 2>&1 > /dev/null
${BINDIR}/dada_db -d -k ${DISKIQUV_KEY} 2>&1 > /dev/null
# start buffers
${BINDIR}/dada_db -p -k ${MAINI_KEY} -n ${MAINI_COUNT} -b ${MAINI_SIZE} -r 2
${BINDIR}/dada_db -p -k ${MAINIQUV_KEY} -n ${MAINIQUV_COUNT} -b ${MAINIQUV_SIZE} -r 1
${BINDIR}/dada_db -p -k ${DISKIQUV_KEY} -n ${DISKIQUV_COUNT} -b ${DISKIQUV_SIZE} -r 1
######################################################################
echo "Start the dada_dbevent for FRB triggers"
######################################################################
# TASK: Respond to FRB triggers
# dada_dbevent [options] inkey outkey
# inkey input hexadecimal shared memory key
# outkey input hexadecimal shared memory key
# -b percent delay procesing of the input buffer up to this amount [default 80 %]
# -t delay maximum delay (s) to retain data for [default 60s]
# -h print this help text
# -p port port to listen for event commands [default 30000]
# -v be verbose
${BINDIR}/dada_dbevent ${MAINIQUV_KEY} ${DISKIQUV_KEY} -v -t ${TRIGGER_HISTORY} 2> ${LOG_TRIGGER} &
# NOTE: multilog writes to stderr here
######################################################################
echo "Start AMBER"
######################################################################
# TASK: build example trigger
let "EVENT_START_STAMP = ${START_STAMP} + 20"
let "EVENT_END_STAMP = ${START_STAMP} + 22"
EVENTSTART=`date -u +%Y-%m-%d-%H:%M:%S --date "@${EVENT_START_STAMP}"`
EVENTEND=`date -u +%Y-%m-%d-%H:%M:%S --date "@${EVENT_END_STAMP}"`
# A trigger contains:
# N_EVENTS %i
# YYYY-MM-DD-HH:MM:SS (start of observation, here UTC_START)
# QUIT | YYYY-MM-DD-HH:MM:SS fraction YYYY-MM-DD-HH:MM:SS fraction DM SNR (start and end of event)
#
# UPDATE: newer versions require 2 more data points in the trigger
# QUIT | YYYY-MM-DD-HH:MM:SS fraction YYYY-MM-DD-HH:MM:SS fraction DM SNR WIDTH BEAM (start and end of event)
# note that start time is:
# * converted to a byte index using BYTES_PER_SECOND and observation UTC_START
# * rounded down to RESOLUTION
# and end time is:
# * converted to a byte index using BYTES_PER_SECOND and observation UTC_START
# * rounded up to RESOLUTION
echo "N_EVENTS 1" > trigger
echo "${UTC_START}" >> trigger
echo "${EVENTSTART} 0 ${EVENTEND} 0 2.0 1.0 3.0 3" >> trigger
# TASK: connect AMBER to the ringbuffer
######################################################################
echo "Start the data writers"
######################################################################
# TASK: Write full I to disk in filterbank format
# dadafilterbank [options]
# -c <science case>
# -m <science mode>
# -k <hexadecimal key>
# -l <logfile>
# -b <padded_size>
# -n <filename prefix for dumps>
${BINDIR}/dadafilterbank -k ${MAINI_KEY} -l ${LOG_WRITER_FULL_I} -n ${OUTPUT_FULL_I} &
# TASK: Write reduced (1-bit, downsampled) I to disk in FITS format
# dadafits [options]
# -k <hexadecimal key>
# -l <logfile>
# -t <template>
# -d <output_directory>
# -S <synthesized beam table>
# -s <synthesize these beams>
${BINDIR}/dadafits -k ${MAINI_KEY} -l ${LOG_WRITER_REDUCED_I} -t ${FITS_TEMPLATES} -d ${OUTPUT_REDUCED_I} &
# TASK: Write full IQUV data to disk on triggers
# dada_dbdisk [options]
# -b <core> bind process to CPU core TODO
# -k hexadecimal shared memory key [default: dada]
# -D <path> add a disk to which data will be written
# -o use O_DIRECT flag to bypass kernel buffering
# -W over-write exisiting files
# -s single transfer only TODO
# -t bytes set optimal bytes TODO
# -z use zero copy transfers TODO
# -d run as daemon
${BINDIR}/dada_dbdisk -k ${DISKIQUV_KEY} -D ${OUTPUT_FULL_IQUV} 2> ${LOG_WRITER_FULL_IQVU} &
# NOTE: multilog writes to stderr here
# TASK: 8 bits tracking beams per pulsar TODO
######################################################################
echo "Connect dada_db ringbuffers to the network"
######################################################################
# TASK: create dada header file for the Stokes I buffer
# * set the UTC_START in the header
# * set bytes per second in the header correctly 462422016 / 1.024 = 451584000
# * set the observation RESOLUTION to the page size 462422016
let "BPS = ${MAINI_SIZE} * 1000 / 1024"
cp header ./header_i_with_utc
echo "SAMPLES_PER_BATCH ${SAMPLES_PER_BATCH}" >> ./header_i_with_utc
echo "UTC_START ${UTC_START}" >> ./header_i_with_utc
echo "RESOLUTION ${MAINI_SIZE}" >> ./header_i_with_utc
echo "BYTES_PER_SECOND ${BPS}" >> ./header_i_with_utc
# TASK: create dada header file for the Stokes IQUV buffer
# * set the UTC_START in the header
# * set bytes per second in the header correctly 462422016 / 1.024 = 451584000
# * set the observation RESOLUTION to the page size 462422016
let "BPS = ${MAINIQUV_SIZE} * 1000 / 1024"
cp header ./header_iquv_with_utc
echo "SAMPLES_PER_BATCH ${SAMPLES_PER_BATCH}" >> ./header_iquv_with_utc
echo "UTC_START ${UTC_START}" >> ./header_iquv_with_utc
echo "RESOLUTION ${MAINIQUV_SIZE}" >> ./header_iquv_with_utc
echo "BYTES_PER_SECOND ${BPS}" >> ./header_iquv_with_utc
# TASK: listen to a network port, and copy incomming UDP packets to the Stokes I ringbuffer
# fill_ringbuffer [options]
# -h <header file>
# -k <hexadecimal key>
# -c <science case>
# -m <science mode>
# -s <start packet number>
# -d <duration (s)>
# -p <port>
# -l <logfile>
#${BINDIR}/fill_ringbuffer -h ./header_i_with_utc -k ${MAINI_KEY} -c ${SCIENCE_CASE} -m ${SCIENCE_MODE_I} -d ${DURATION} -b ${FULL_I_PADDED_SIZE} -l ${LOG_NETWORK_I} -s ${START_PACKET} -p ${PORT_I} &
${BINDIR}/fill_fake -h ./header_i_with_utc -k ${MAINI_KEY} -c ${SCIENCE_CASE} -m ${SCIENCE_MODE_I} -d ${DURATION} -b ${FULL_I_PADDED_SIZE} -l ${LOG_NETWORK_I} &
# TASK: listen to a network port, and copy incomming UDP packets to the Stokes IQUV ringbuffer
# fill_ringbuffer [options]
# -h <header file>
# -k <hexadecimal key>
# -c <science case>
# -m <science mode>
# -s <start packet number>
# -d <duration (s)>
# -p <port>
# -l <logfile>
#${BINDIR}/fill_ringbuffer -h ./header_iquv_with_utc -k ${MAINIQUV_KEY} -c ${SCIENCE_CASE} -m ${SCIENCE_MODE_IQUV} -d ${DURATION} -b ${FULL_I_PADDED_SIZE} -l ${LOG_NETWORK_IQUV} -s ${START_PACKET} -p ${PORT_IQUV} &
${BINDIR}/fill_fake -h ./header_iquv_with_utc -k ${MAINIQUV_KEY} -c ${SCIENCE_CASE} -m ${SCIENCE_MODE_IQUV} -d ${DURATION} -b ${FULL_I_PADDED_SIZE} -l ${LOG_NETWORK_IQUV} &
## pull a trigger
cat trigger | ncat localhost 30000