-
Notifications
You must be signed in to change notification settings - Fork 1
/
eviocat
executable file
·78 lines (69 loc) · 1.93 KB
/
eviocat
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
#!/bin/bash
#
# eviocat - shell wrapper around the evioCat utility.
#
# author: richard.t.jones at uconn.edu
# version: december 9, 2020
[ -r .eviocat ] || cp $0 .eviocat
if [ ! -d /group/halld ]; then
exec osg-container ./.eviocat $*
fi
cat <<EOI >.eviocat.py
#!/usr/bin/env python3
import sys
import struct
def usage():
print("Usage: eviocat [options] <input_file> [<input_file2> ... ]")
print(" where options include any of the following:")
print(" -o <output_file> : overrides default output to stdout")
sys.exit(1)
if len(sys.argv) < 2:
usage()
argc = 1
fout = sys.stdout.buffer
while argc < len(sys.argv):
if sys.argv[argc] == "-o":
fout = open(sys.argv[argc + 1], "wb")
argc += 1
elif sys.argv[argc][0] == "-":
usage()
else:
break
argc += 1
head = []
blockno = 0
for infile in sys.argv[argc:]:
with open(infile, "rb") as fin:
while True:
buf = fin.read(32)
if len(buf) != 32:
sys.stderr.write("Error - evio file {0} is truncated at block {1}\n"
.format(infile,blockno))
sys.exit(7)
head = struct.unpack(">IIIIIIII", buf)
if head[7] != 0xc0da0100:
sys.stderr.write("Error - corrupted block in {0} at block {1}\n"
.format(infile, blockno))
for c in buf:
sys.stderr.write(hex(c))
sys.stderr.write("\n")
sys.exit(8)
length = head[0] - head[2]
if length > 0:
blockno += 1
rehead = [h for h in head]
rehead[1] = blockno
buf = struct.pack(">IIIIIIII", *rehead)
fout.write(buf)
fout.write(fin.read(length * 4))
else:
break
if len(head) > 0:
blockno += 1
rehead = [h for h in head]
rehead[1] = blockno
buf = struct.pack(">IIIIIIII", *rehead)
fout.write(buf)
EOI
chmod +x .eviocat.py
./.eviocat.py $*