DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
raw_file_check.py
Go to the documentation of this file.
1import os.path
2
3def compare_raw_name(file1, file2):
4 """Compare the name of two files from their path"""
5 return os.path.basename(file1) == os.path.basename(file2)
6
7def compare_raw_size(file1, file2):
8 """Compare the size of two files from their path"""
9 return os.path.getsize(file1) == os.path.getsize(file2)
10
11def compare_raw_content(file1, file2, buffer_size=1024):
12 """Compare the content of two files from their path"""
13 buffer_count = 0
14 with open(file1, 'rb') as f1, open(file2, 'rb') as f2:
15 while True:
16 data1 = f1.read(buffer_size)
17 data2 = f2.read(buffer_size)
18
19 if not data1 and not data2:
20 return True
21 if not data1 or not data2:
22 return False
23 if data1 != data2:
24 print("Files are differents at bytes " + str(buffer_size * buffer_count) + " to " + str(buffer_size * (buffer_count + 1)))
25 print(data1)
26 print(data2)
27 return False
28 buffer_count += 1
compare_raw_content(file1, file2, buffer_size=1024)
compare_raw_name(file1, file2)
compare_raw_size(file1, file2)