-
Notifications
You must be signed in to change notification settings - Fork 2
/
cafe_setup.sh
executable file
·390 lines (303 loc) · 11.3 KB
/
cafe_setup.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#!/bin/bash
# user input
fsys=$1
display_help()
{
# Display Help
echo "-------------------------------------------------------"
echo "This shell script automatically sets up the necessary symbolic"
echo "links (or dir.) for the CaFe experiment raw data and output based on which "
echo "machine (ifarm, cdaq, local) the user is at."
echo ""
echo "Syntax: ./cafe_setup.sh "
echo ""
echo "options:"
echo ""
echo "For users on IFARM ONLY: "
echo " The optional arguments are: volatile, work, group"
echo ""
echo " volatile (/volatile/hallc/c-cafe-2022/ 4 TB high quota; 2 TB guarantee): "
echo " Files are NOT backed-up. Use for all large file output from analysis or simulation jobs. "
echo " When guarantee threshold is exceeded it is possible to have files auto-cleaned up (removed). "
echo ""
echo " work (/work/hallc/c-cafe-2022/ 1 TB quota): "
echo " Files are NOT backed up. Good place for analysis software, database files, etc. "
echo " These files should be in GitHub or have similar backups."
echo ""
echo " group (/group/c-cafe-2022/ 100 GB quota): "
echo " Backed up regularly. Best place for analysis/replay scripts; software that is "
echo " being actively developed, etc. (But, still use GitHub!)"
echo ""
echo " See https://hallcweb.jlab.org/wiki/index.php/CaFe_Disk_Space "
echo " for detailed information on each of these filesystems."
echo " "
echo "examples: ./cafe_setup.sh volatile"
echo " ./cafe_setup.sh work"
echo " ./cafe_setup.sh group"
echo ""
echo "For LOCAL users: "
echo "./cafe_setup.sh local"
echo "-------------------------------------------------------"
}
# set environment var within this code (I don't yet know how to export variables using bash)
# the export command seems not to work
# these assume that this script is on cafe_offline_replay
# and that hcana dir is one directory back
HCREPLAY="$PWD"
HCANALYZER=$PWD"/../hcana"
echo "HCREPLAY -> $HCREPLAY"
echo "HCANALYZER -> $HCANALYZER"
if [ "$#" -eq 0 ]; then
display_help
exit 1
fi
#--- most recent online raw data is stored here (and then copied to tape shortly after)---
coda_raw="/net/cdaq/cdaql1data/coda/data/raw"
coda_raw_copiedtotape="/net/cdaq/cdaql1data/coda/data/raw.copiedtotape"
# where CaFe raw data output to be replayed will be stored (.dat files)
# but these are NOT directly accessible, one would have to look for them in cache.
# tape_raw_dir="/mss/hallc/c-cafe-2022/raw"
tape_raw_dir="/mss/hallc/c-pionlt/raw"
# tape volume for analysis output (simulation or replay output you want to keep long-term)
tape_analysis_out="/mss/hallc/c-cafe-2022/analysis"
#--- define cache allocations (ONLY for raw and analyzed online data storage) ---
# cafe Sep data
cache_raw_dir_cafe="/cache/hallc/c-cafe-2022/raw/"
# cafe Aug data (optics, heep elastics, was written in pion lt raw dir)
cache_raw_dir_pionlt="/cache/hallc/c-pionlt/raw"
# cafe online analysis output would have been written here
cache_analysis_out="/cache/hallc/c-cafe-2022/analysis/"
bourne_shell_flg=0 # sh, bash, zsh, ksh
shell_flg=0 #c-shell (csh), t-shell(tcsh)
#determine user shell
if echo $SHELL | grep -q "/sh"; then
echo "SHELL: $SHELL"
bourne_shell_flg=1
elif echo $SHELL | grep -q "/bash"; then
echo "SHELL: $SHELL"
bourne_shell_flg=1
elif echo $SHELL | grep -q "/zsh"; then
echo "SHELL: $SHELL"
bourne_shell_flg=1
elif echo $SHELL | grep -q "/ksh"; then
echo "SHELL: $SHELL"
bourne_shell_flg=1
elif echo $SHELL | grep -q "/csh"; then
echo "SHELL: $SHELL"
shell_flg=1
elif echo $SHELL | grep -q "/tcsh"; then
echo "SHELL: $SHELL"
shell_flg=1
fi
echo "bourne_shell_flg: $bourne_shell_flg"
echo "shell_flg: $shell_flg"
set_hcana_link()
{
if [[ -z $HCANALYZER ]]; then
echo ""
echo "Environment variable: $HCANALYZER does NOT exist. "
echo "Will try to source setup.sh(csh) in hcana first. "
echo "Trying to source environment:"
echo "cd ../hcana"
cd ../hcana/
if [[ shell_flg -eq 1 ]]; then
echo "source setup.csh "
source setup.csh
elif [[ bourne_shell_flg -eq 1 ]]; then
echo "source setup.sh "
source setup.sh
fi
echo "cd $HCREPLAY"
cd $HCREPLAY
else
echo ""
cd $HCREPLAY
unlink hcana
echo "Creating hcana symbolic link now . . ."
echo "ln -sf $HCANALYZER/hcana"
ln -sf $HCANALYZER"/hcana"
echo "ln -sf $HCANALYZER/libHallC.so"
ln -sf $HCANALYZER"/libHallC.so"
echo "ln -sf $HCANALYZER/libHallC.so.0.90.0"
ln -sf $HCANALYZER"/libHallC.so.0.90.0"
echo ""
fi
}
# set link to cache cafe raw data
set_raw_link()
{
echo ""
echo "Setting Up symlinks to raw (.dat) files . . ."
mkdir $HCREPLAY"/CACHE_LINKS"
cd $HCREPLAY"/CACHE_LINKS"
unlink cache_cafe
echo "Creating symlink to /cache/hallc/c-cafe-2022/raw/"
ln -sf $cache_raw_dir_cafe cache_cafe
unlink cache_pionlt
echo "Creating symlink to /cache/hallc/c-pionlt/raw/"
ln -sf $cache_raw_dir_pionlt cache_pionlt
echo "cd $HCREPLAY"
cd $HCREPLAY
echo ""
}
set_hcana_link
set_raw_link
# initialize machine flags to 0
# (depending on where this script gets called, it will turn ON one of these)
ifarm_flg=0
cdaq_flg=0
# determine user hostname
if echo $HOSTNAME | grep -q "ifarm"; then
ifarm_flg=1
elif echo $HOSTNAME | grep -q "cdaq"; then
cdaq_flg=1
fi
#if [[ ifarm_flg==0 && cdaq_flg==0 ]]; then
# echo "***************************************"
# echo " Did not recognize remote machine. "
# echo " Please run: ./cafe_setup.sh -help "
# echo " for help in running this script."
# echo "***************************************"
#fi
#=================================
# ifarm
# (off-line experiment analysis)
#
# =================================
if [[ ifarm_flg -eq 1 ]]; then
echo ""
echo "Checking if necessary directories or symlinks exist in remote machine: " ${USER}"@"${HOSTNAME}". . ."
echo ""
if [[ $fsys == "volatile" ]]; then
echo ""
echo 'Setting up symbolic links to volatile filesystem on ifarm . . .'
base_dir_voli="/volatile/hallc/c-cafe-2022/"
echo "Creating dir $base_dir_voli$USER . . ."
mkdir $base_dir_voli$USER
unlink REPORT_OUTPUT
echo "Creating dir and symlink to $base_dir_voli$USER/REPORT_OUTPUT . . ."
mkdir $base_dir_voli$USER"/REPORT_OUTPUT"
ln -sf $base_dir_voli$USER"/REPORT_OUTPUT"
unlink CAFE_OUTPUT
echo "Creating dir and symlink to $base_dir_voli$USER/CAFE_OUTPUT . . ."
mkdir $base_dir_voli$USER"/CAFE_OUTPUT"
ln -sf $base_dir_voli$USER"/CAFE_OUTPUT"
mkdir -p "CAFE_OUTPUT/ROOT"
mkdir -p "CAFE_OUTPUT/REPORT"
mkdir -p "CAFE_OUTPUT/PDF"
unlink ROOTfiles
echo "Creating dir and symlink to $base_dir_voli$USER/ROOTfiles . . ."
mkdir $base_dir_voli$USER"/ROOTfiles"
ln -sf $base_dir_voli$USER"/ROOTfiles"
echo ""
elif [[ $fsys == "work" ]]; then
echo ""
echo 'Setting up symbolic links to work filesystem on ifarm . . .'
base_dir_work="/work/hallc/c-cafe-2022/"
echo "Creating dir $base_dir_work$USER . . ."
mkdir $base_dir_work$USER
unlink REPORT_OUTPUT
echo "Creating dir and symlink to $base_dir_work$USER/REPORT_OUTPUT . . ."
mkdir $base_dir_work$USER"/REPORT_OUTPUT"
ln -sf $base_dir_work$USER"/REPORT_OUTPUT"
unlink CAFE_OUTPUT
echo "Creating dir and symlink to $base_dir_work$USER/CAFE_OUTPUT . . ."
mkdir $base_dir_work$USER"/CAFE_OUTPUT"
ln -sf $base_dir_work$USER"/CAFE_OUTPUT"
mkdir -p "CAFE_OUTPUT/ROOT"
mkdir -p "CAFE_OUTPUT/REPORT"
mkdir -p "CAFE_OUTPUT/PDF"
unlink ROOTfiles
echo "Creating dir and symlink to $base_dir_work$USER/ROOTfiles . . ."
mkdir $base_dir_work$USER"/ROOTfiles"
ln -sf $base_dir_work$USER"/ROOTfiles"
elif [[ $fsys == "group" ]]; then
echo 'Setting up symbolic links to group filesystem on ifarm . . .'
base_dir_group="/group/c-cafe-2022/"
echo "Creating dir $base_dir_group$USER . . ."
mkdir $base_dir_group$USER
unlink REPORT_OUTPUT
echo "Creating dir and symlink to $base_dir_group$USER/REPORT_OUTPUT . . ."
mkdir $base_dir_group$USER"/REPORT_OUTPUT"
ln -sf $base_dir_group$USER"/REPORT_OUTPUT"
unlink CAFE_OUTPUT
echo "Creating dir and symlink to $base_dir_group$USER/CAFE_OUTPUT . . ."
mkdir $base_dir_group$USER"/CAFE_OUTPUT"
ln -sf $base_dir_group$USER"/CAFE_OUTPUT"
mkdir -p "CAFE_OUTPUT/ROOT"
mkdir -p "CAFE_OUTPUT/REPORT"
mkdir -p "CAFE_OUTPUT/PDF"
unlink ROOTfiles
echo "Creating dir and symlink to $base_dir_group$USER/ROOTfiles . . ."
mkdir $base_dir_group$USER"/ROOTfiles"
ln -sf $base_dir_group$USER"/ROOTfiles"
echo ""
fi
fi
#===============================
# cdaq cluster
# (online experiment analysis)
#===============================
if [[ cdaq_flg -eq 1 ]]; then
echo ""
echo "Checking if necessary directories or symlinks exist in remote machine: " ${USER}"@"${HOSTNAME}". . ."
echo ""
# source cafe_online_replay
source setup.csh
base_dir_cdaq="/net/cdaq/cdaql1data/cdaq/hallc-online-cafe2022"
echo "Creating symlink to ${coda_raw}"
ln -sf $coda_raw
echo "Creating symlink to ${coda_raw_copiedtotape}"
ln -sf $coda_raw_copiedtotape
echo "Creating symlink to $cache_raw_dir_cafe"
ln -sf $cache_raw_dir_cafe cache_cafe
echo "Creating symlink to $cache_raw_dir_pionlt"
ln -sf $cache_raw_dir_cafe cache_pionlt
echo "Creating dir and symlink to $base_dir_cdaq/REPORT_OUTPUT . . ."
mkdir $base_dir_cdaq"/REPORT_OUTPUT"
ln -sf $base_dir_cdaq"/REPORT_OUTPUT"
echo "Creating dir and symlink to $base_dir_cdaq/ROOTfiles . . ."
mkdir $base_dir_cdaq"/ROOTfiles"
ln -sf $base_dir_cdaq"/ROOTfiles"
echo "Creating dir and symlink to $base_dir_cdaq/HISTOGRAMS . . ."
mkdir $base_dir_cdaq"/HISTOGRAMS"
ln -sf $base_dir_cdaq"/HISTOGRAMS"
echo "Creating dir and symlink to $base_dir_cdaq/CAFE_OUTPUT . . ."
mkdir $base_dir_cdaq"/CAFE_OUTPUT"
ln -sf $base_dir_cdaq"/CAFE_OUTPUT"
mkdir -p "CAFE_OUTPUT/ROOT"
mkdir -p "CAFE_OUTPUT/REPORT"
mkdir -p "CAFE_OUTPUT/PDF"
fi
#=============================
# local
# (the user local computer)
#=============================
# assume user is local if NOT on cdaq or ifarm
if [[ ifarm_flg==0 && cdaq_flg==0 && $fsys=="local" ]]; then
# source cafe_online_replay (usually shell script on local machine)
source setup.sh
# This function checks if necessary dir. exists, else it creates them
dir_arr=("raw" "ROOTfiles" "REPORT_OUTPUT" "HISTOGRAMS" "CAFE_OUTPUT" "CACHE_LINKS")
echo ""
echo "Checking if necessary directories or symlinks exist in local machine: " ${USER}"@"${HOSTNAME}". . ."
echo ""
for i in "${dir_arr[@]}"
do
if [[ -L "$i" && -d "$i" ]]; then
cmd="ls -l $i"
echo "$i is a symlink to a directory and it exists:"
eval $cmd
elif [[ -d "$i" ]]; then
echo "/$i directory exists"
else
echo "$i symlink is broken or /$i dir does not exist. Unlinking + Creating $i directory now . . ."
echo "unlink $i"
unlink $i
cmd="mkdir $i"
echo $cmd
eval $cmd
echo "done!"
fi
done
fi