58 title = f
"File size, {unit}. Mean = {np.mean(arr):.3f} {unit}. Overall {len(arr)} files."
61 print(
"Obtained characteristics:")
62 print(f
" File statistics: min = {np.min(arr):.3f} {unit}, avg = {np.mean(arr):.3f} {unit}, " \
63 f
"max={np.max(arr):.3f} {unit}, summary={np.sum(arr):.3f} {unit}")
66 title_per_event = f
"File size per event, {unit_per_event}. Mean = {np.mean(arr_per_event):.3f} {unit_per_event}. " \
67 f
"Overall {len(arr_per_event)} files."
69 if len(arr_per_event) == 0:
70 print(
"There is no additional statistics on individual events")
72 print(f
" File statistics per event: min = {np.min(arr_per_event):.3f} {unit_per_event}, " +
73 f
"avg = {np.mean(arr_per_event):.3f} {unit_per_event}, max={np.max(arr_per_event):.3f} {unit_per_event}")
75 return (arr, unit, title, arr_per_event, unit_per_event, title_per_event)
80 filesize_per_event = []
83 files_to_walk = os.walk(_dir)
85 files_to_walk = [next(os.walk(_dir))]
87 files_parsed_successful = 0
88 files_parsed_overall = 0
89 unsuccessful_list = []
90 for root, dirs, files
in files_to_walk:
93 files_parsed_overall += 1
94 file_path = os.path.join(root, file)
95 filesize_bytes = os.stat(file_path).st_size
99 print(f
"\nFile {file_path} is {filesize_conv:.1f} {filesize_units} "\
100 f
"which does not meet file size limit - skipping.")
101 unsuccessful_list.append(file_path)
120 if event_count
is None:
121 print(f
"\nNo event count found in the database for file {file_path}")
122 unsuccessful_list.append(file_path)
125 file_ext = os.path.splitext(file_path)[1]
126 if file_ext ==
".root":
129 if uproot_count !=
None and event_count !=
None and uproot_count != event_count:
130 print(f
"\nFile {file_path} has {uproot_count} events but the database reports {event_count} events - skipping...")
131 unsuccessful_list.append(file_path)
134 if (event_count
is not None)
and (event_count != 0):
135 filesize_bytes_per_event = filesize_bytes / event_count
139 print(f
"\nFile {file_path} has {eventsize_conv:.1f} {eventsize_units} per event "\
140 f
"which does not meet event size limit - skipping.")
141 unsuccessful_list.append(file_path)
143 filesize_per_event.append(filesize_bytes_per_event)
144 files_parsed_successful += 1
145 print(
"+", end=
"", flush=
True)
146 filesize_arr.append(filesize_bytes)
149 print(f
"Total files parsed: {files_parsed_successful}")
150 if filesize_arr == []:
151 raise NoDataException
152 unsuccessful_list.sort()
153 if len(unsuccessful_list) == 0:
154 print(
"\nAll files processed successfully.\n")
156 print(
"\nUnsuccessfully processed files:")
157 for elem
in unsuccessful_list:
159 if config.UNSUCCESSFUL_LOG_FILE
is not None:
161 with open(config.UNSUCCESSFUL_LOG_FILE,
"wt")
as f:
162 for elem
in unsuccessful_list:
164 print(f
"Unsuccessfully processed files list ({len(unsuccessful_list)}/{files_parsed_overall}, {(100*len(unsuccessful_list)/files_parsed_overall):.1f}%)"\
165 f
" was saved to {config.UNSUCCESSFUL_LOG_FILE}\n")
166 return np.array(filesize_arr), np.array(filesize_per_event)