87 if infilepath !=
'stdin':
88 fin = open(infilepath,
'rb')
90 fin = sys.stdin.buffer
113 if infilepath !=
'stdin':
114 fin = open(infilepath,
'rb')
116 fin = sys.stdin.buffer
123 h = frd_file_header_v2()
124 h.event_count = orbitcount
125 h.run_number = rn_override
126 h.lumisection = last_ls
127 h.file_size = fout.tell()
129 fout.write(frd_file_header_v2.ver_id)
130 fout.write(struct.pack(
'H',h.header_size))
131 fout.write(struct.pack(
'H',h.data_type))
132 fout.write(struct.pack(
'I',h.event_count))
133 fout.write(struct.pack(
'I',h.run_number))
134 fout.write(struct.pack(
'I',h.lumisection))
135 fout.write(struct.pack(
'Q',h.file_size))
138 print(h.ver_id, h.header_size, h.data_type, h.event_count, h.lumisection, h.file_size)
149 fout.write(struct.pack(
'H',version))
150 fout.write(struct.pack(
'H',flags))
151 fout.write(struct.pack(
'I',rn_override))
153 fout.write(struct.pack(
'I',last_ls))
154 fout.write(struct.pack(
'I',orbit_nr))
155 fout.write(struct.pack(
'I',orbit_size))
156 fout.write(struct.pack(
'I',c_crc32c))
157 fout.write(orbit_data)
162 def writeout_close():
172 if orbitcount_total > maxorbits:
173 print(f
"finish: {orbitcount_total-1}/{maxorbits} orbits")
176 if infilepath !=
'stdin':
182 bxmatch = struct.unpack(
'B', h_raw[3:4])[0]
183 mAcount = struct.unpack(
'B', h_raw[2:3])[0]
184 orbitmatch = struct.unpack(
'B', h_raw[1:2])[0]
185 mBcount = struct.unpack(
'B', h_raw[0:1])[0]
190 bx = struct.unpack(
'i', bx_raw)[0]
192 orbit_raw = fin.read(4)
193 orbit = struct.unpack(
'i', orbit_raw)[0]
206 fout = open(os.path.join(outdir, f
'run{rn_override}_ls{str(new_ls).zfill(4)}_index000000.raw') ,
'wb')
208 fout.write(frd_file_header_v2.ver_id)
210 fout.write(bytes(24))
212 read_len = 8*(mAcount+mBcount)
213 mu_blk = fin.read(8*(mAcount+mBcount))
214 if len(mu_blk) != read_len:
215 print(
'incomplete read')
218 if not orbit_nr
or orbit != orbit_nr:
226 print(
"got smaller orbit than earlier!")
229 print(
"new orbit", orbit)
235 orbitcount_total += 1
238 orbit_size += 12 + read_len
239 orbit_data += (h_raw + bx_raw + orbit_raw) + mu_blk
241 except Exception
as ex:
243 print(f
"exception: {ex}")
def parseMuonScoutingRawFile(infilepath, outdir, rn_override, maxorbits)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)