-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonutor.mk
More file actions
330 lines (256 loc) · 9.02 KB
/
monutor.mk
File metadata and controls
330 lines (256 loc) · 9.02 KB
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
###############################################
# monutor
#
# That's right, monutor is largely implemented in make. Sorry, it seemed like it'd be a
# good idea, but it's probably an illegible mess.
#
# Cosmin Deaconu <cozzyd@kicp.uchicago.edu>
#
#
## Define what you need for your site in site.cfg
.PHONY: all sync clean extract-status extract-header extract-hk extract-event rootify-event rootify-hk rootify-header rootify-status filtered-header decimated-status
all: deploy
include site.cfg
### Pretty error message if you don't have site
site.cfg:
$(error "You must copy (or symlink) a site.cfg into this directory!")
clean:
rm -f sync *.d extract rootify
startdir=$(shell pwd)
### Copy over new files
sync: | $(LOCAL_DEST)
ifdef REMOTE_HOST
echo "---" >> sync
date >> sync
mkdir -p $(LOCAL_DEST)/$(EVENT_DIR)
mkdir -p $(LOCAL_DEST)/$(STATUS_DIR)
mkdir -p $(LOCAL_DEST)/$(HK_DIR)
mkdir -p $(LOCAL_DEST)/$(HEADER_DIR)
ifdef PROXY_HOST
-ssh -x -T $(PROXY_HOST) "cd $(startdir); rsync -av $(REMOTE_HOST):$(REMOTE_PATH_BASE)/$(STATUS_DIR) $(LOCAL_DEST)/ >> $@"
-ssh -x -T $(PROXY_HOST) "cd $(startdir); rsync -av $(REMOTE_HOST):$(REMOTE_PATH_BASE)/$(HK_DIR) $(LOCAL_DEST)/ >> $@"
-ssh -x -T $(PROXY_HOST) "cd $(startdir); rsync -av $(REMOTE_HOST):$(REMOTE_PATH_BASE)/$(EVENT_DIR) $(LOCAL_DEST)/ >> $@"
-ssh -x -T $(PROXY_HOST) "cd $(startdir); rsync -av $(REMOTE_HOST):$(REMOTE_PATH_BASE)/$(HEADER_DIR) $(LOCAL_DEST)/ >> $@"
else
rsync -av $(REMOTE_HOST):$(REMOTE_PATH_BASE)/$(STATUS_DIR) $(LOCAL_DEST)/ >> $@
rsync -av $(REMOTE_HOST):$(REMOTE_PATH_BASE)/$(HK_DIR) $(LOCAL_DEST)/ >> $@
rsync -av $(REMOTE_HOST):$(REMOTE_PATH_BASE)/$(EVENT_DIR) $(LOCAL_DEST)/ >> $@
rsync -av $(REMOTE_HOST):$(REMOTE_PATH_BASE)/$(HEADER_DIR) $(LOCAL_DEST)/ >> $@
endif
else
echo "No need to sync"
endif
ifdef REMOTE_HOST # only need to the the weird tarring thing if from a remote host
### These are responsible for generating the list of files to extract and rootify
### Since sync is phony (and must be), these will infinitely loop (because they are included)
### without MAKE_RESTARTS
ifndef MAKE_RESTARTS
extract.d: sync | $(RAW_DIR) $(RAW_DIR)/hk
echo "# Automatically generated file. Dont' touch. " > $@
echo -n "extract-event: " >> $@
find $(LOCAL_DEST)/$(EVENT_DIR) -type f -name *.flat.tar | sed 's/.flat.tar/.extracted \\/'>> $@
echo >> $@
echo -n "extract-status: " >> $@
find $(LOCAL_DEST)/$(STATUS_DIR) -type f -name *.flat.tar | sed 's/.flat.tar/.extracted \\/'>> $@
echo >> $@
echo -n "extract-header: " >> $@
find $(LOCAL_DEST)/$(HEADER_DIR) -type f -name *.flat.tar | sed 's/.flat.tar/.extracted \\/'>> $@
echo >> $@
echo -n "extract-hk: " >> $@
find $(LOCAL_DEST)/$(HK_DIR) -type f -name *.flat.tar | sed 's/.flat.tar/.hkextracted \\/'>> $@
echo >> $@
rootify.d:
touch $@
filtered.d:
touch $@
endif
endif
## Use slightly different rules for remote host vs. not. Assume not tarred if not using remote host
ifdef RAW_DIR
ifndef REMOTE_HOST
ifndef MAKE_RESTARTS
# This enumerates the necessary ROOT files
rootify.d: sync | $(ROOT_DIR)
echo "# Automatically generated file. Dont' touch. " > $@
echo -n "rootify-event: " >> $@
find $(RAW_DIR) -type d -name event -printf '$(ROOT_DIR)/%P.root ' >> $@
echo >> $@
echo -n "rootify-status: " >> $@
find $(RAW_DIR) -type d -name status -printf '$(ROOT_DIR)/%P.root ' >> $@
find $(RAW_DIR) -type d -name status -printf '$(ROOT_DIR)/%P.decimated.root ' >> $@
echo >> $@
echo -n "rootify-header: " >> $@
find $(RAW_DIR) -type d -name header -printf '$(ROOT_DIR)/%P.root ' >> $@
echo >> $@
echo -n "rootify-hk: " >> $@
find $(RAW_DIR)/hk -mindepth 3 -type d -printf '$(ROOT_DIR)/hk/%P.root ' >> $@
echo >> $@
filtered.d:
touch $@
endif
else #with remote host
ifeq (1,${MAKE_RESTARTS})
# This enumerates the necessary ROOT files
rootify.d: extract | $(ROOT_DIR)
echo "# Automatically generated file. Dont' touch. " > $@
echo -n "rootify-event: " >> $@
find $(RAW_DIR) -type d -name event -printf '$(ROOT_DIR)/%P.root ' >> $@
find $(RAW_DIR) -type f -name event.tar -printf '$(ROOT_DIR)/%P ' | sed 's/.tar/.root/g' >> $@
echo >> $@
echo -n "rootify-status: " >> $@
find $(RAW_DIR) -type d -name status -printf '$(ROOT_DIR)/%P.root ' >> $@
find $(RAW_DIR) -type f -name status.tar -printf '$(ROOT_DIR)/%P ' | sed 's/.tar/.root/g' >> $@
echo >> $@
echo -n "rootify-header: " >> $@
find $(RAW_DIR) -type d -name header -printf '$(ROOT_DIR)/%P.root ' >> $@
find $(RAW_DIR) -type f -name header.tar -printf '$(ROOT_DIR)/%P ' | sed 's/.tar/.root/g' >> $@
echo >> $@
echo -n "rootify-hk: " >> $@
find $(RAW_DIR)/hk -mindepth 3 -type d -printf '$(ROOT_DIR)/hk/%P.root ' >> $@
find $(RAW_DIR) -type f -name *.tar -printf '$(ROOT_DIR)/%P ' | sed 's/.tar/.root/g' >> $@
echo >> $@
endif
endif #end remote host
ifdef REMOTE_HOST
MAKE_RESTARTS_FOR_FILTERED=2
else
MAKE_RESTARTS_FOR_FILTERED=1
endif
###NO RAW_DIR
else
MAKE_RESTARTS_FOR_FILTERED=1
ifndef MAKE_RESTARTS
rootify.d:
touch $@
filtered.d:
touch $@
endif
endif
ifeq (${MAKE_RESTARTS_FOR_FILTERED},${MAKE_RESTARTS})
filtered.d: rootify | $(ROOT_DIR)
echo "# Automatically generated file. Dont' touch. " > $@
echo -n "decimated-status: " >> $@
find $(ROOT_DIR) -type f -name status.root -printf '%h/status.decimated.root ' >> $@
echo >> $@
echo -n "filtered-header: " >> $@
find $(ROOT_DIR) -type d -name run* -exec test -e {}/event.root -a -e {}/header.root \; -printf '%p/header.filtered.root ' >>$@
echo >> $@
endif
## Directories
$(LOCAL_DEST):
mkdir -p $@
$(RAW_DIR):
mkdir -p $@
$(RAW_DIR)/hk:
mkdir -p $@
$(ROOT_DIR):
mkdir -p $@
$(HTML_DIR):
mkdir -p $@
## Extraction!
extract: extract.d extract-status extract-event extract-hk extract-header
touch $@
## Extraction of hk
%.hkextracted: %.tar | $(RAW_DIR)/hk
tar -C $(RAW_DIR)/hk -x -f $^
touch $@
## Extraction of non-hk
%.extracted: %.tar | $(RAW_DIR)
tar -C $(RAW_DIR) -x -f $^
touch $@
## Unflatten
$(LOCAL_DEST)/%.tar: $(LOCAL_DEST)/%.flat.tar | $(LOCAL_DEST)
tar -C $(@D) -xf $^ *.tar || tar -cvf $@ --files-from /dev/null
# Put all files in tar files so we don't have so many of them
$(RAW_DIR)/%.tar: $(RAW_DIR)/%
rm -f $@.tmp
if [ -f $@ ]; then cp $@ $@.tmp ; fi
cd $(@D); tar --update -f $(*F).tar.tmp $(*F)/*
mv $@.tmp $@
rm -f $</*
rmdir $<
# Do NOT delete tar files!
.PRECIOUS: $(RAW_DIR)/%.tar
#special case hk
#special case hk
$(ROOT_DIR)/hk/%.root: $(RAW_DIR)/hk/%.tar
mkdir -p $(@D)
tar -C $(@D) --extract -f $<
nuphaseroot-convert hk $(@D)/$(*F) $@.tmp
mv $@.tmp $@
rm -rf $(@D)/$(*F)
touch new_hk;
$(ROOT_DIR)/hk/%.root: $(RAW_DIR)/hk/%
mkdir -p $(@D)
nuphaseroot-convert hk $< $@.tmp
mv $@.tmp $@
touch new_hk
# Crazy rule to rootify root file from raw event tar
$(ROOT_DIR)/%.root: $(RAW_DIR)/%.tar
mkdir -p $(@D)
tar -C $(@D) --extract -f $<
nuphaseroot-convert $(*F) $(@D)/$(*F) $@.tmp
mv $@.tmp $@
rm -rf $(@D)/$(*F)
$(ROOT_DIR)/%.root: $(RAW_DIR)/%
mkdir -p $(@D)
nuphaseroot-convert $(*F) $< $@.tmp
mv $@.tmp $@
# Rule to make decimated file
$(ROOT_DIR)/%.decimated.root: $(ROOT_DIR)/%.root
ln $< $<.tmp
nuphaseroot-decimate $(*F) 25 $(@D)/$(*F).root.tmp
unlink $<.tmp
mv $@.tmp $@
$(ROOT_DIR)/%/header.filtered.root: $(ROOT_DIR)/%/event.root $(ROOT_DIR)/%/header.root
nuphaseroot-convert filtered_header $^ $@
rootify: rootify.d rootify-event rootify-status rootify-header rootify-hk
touch $@
filtered: rootify filtered.d filtered-header decimated-status
touch $@
html/runs: rootify filtered
find $(ROOT_DIR) -type d -name run* -printf ' %f\n' | sed 's/run//' | sort -n | paste -s -d ',' > $@
html/runlist.js: html/runs
echo "var runs = [ " > $@
cat $< >> $@
echo "];" >> $@
echo "var last_updated = \"`date -u`\";" >> $@
html/runlist.json: html/runs
echo "{ \"runs\" : [" > $@
sed -e 's/,^//g' $< >> $@
echo "]," >> $@
echo "\"last_updated\" : \"`date -u`\"" >> $@
echo "}" >> $@
$(HTML_DIR)/% : html/%
cp $< $@
new_hk:
touch $@
# Merge all housekeeping into a single root file since it's small
$(HTML_DIR)/all_hk.root: new_hk | $(HTML_DIR) rootify
-hadd -f $@.tmp $(ROOT_DIR)/hk/*/*/*.root && mv $@.tmp $@
$(HTML_DIR)/rootdata: | $(HTML_DIR)
ln -sf $(ROOT_DIR) $(HTML_DIR)/rootdata
$(HTML_DIR)/jsroot: jsroot/scripts jsroot/style
mkdir -p $@
cp -r $^ $@
$(HTML_DIR)/rfjs: rfjs/rf.js rfjs/FFT.js rfjs/KissFFT.js
mkdir -p $@
cp -r $^ $@
RUNLOG_LINK?=javascript:alert("Not configured. Set RUNLOG_LINK appropriately.")
$(HTML_DIR)/index.html: html/index.html.in site.cfg
cp $< $@
sed -i 's^|||RUNLOG_LINK|||^$(RUNLOG_LINK)^g' $@
DEPLOY_TARGETS= rootify filtered $(HTML_DIR)/rootdata $(HTML_DIR)/index.html $(HTML_DIR)/monutor.js $(HTML_DIR)/runlist.js $(HTML_DIR)/runlist.json \
$(HTML_DIR)/all_hk.root $(HTML_DIR)/jsroot $(HTML_DIR)/monutor.ico $(HTML_DIR)/monutor.png $(HTML_DIR)/rfjs
ifdef REMOTE_HOST
ALL_DEPLOY_TARGETS = extract $(DEPLOY_TARGETS)
else
ALL_DEPLOY_TARGETS = $(DEPLOY_TARGETS)
endif
deploy: $(ALL_DEPLOY_TARGETS) | $(HTML_DIR)
touch $@
ifdef REMOTE_HOST
include extract.d
endif
include rootify.d
include filtered.d