14 dat_source =
'/fff/ramdisk/playback_files/run224380'
15 pb_source =
'/fff/ramdisk/playback_files/run225044_pb'
16 destination =
'/fff/ramdisk'
20 files_copied_buffer_len = 20
29 files = os.listdir(dat_source)
30 dat_jsn_pattern = re.compile(
r'run([0-9]+)_ls([0-9]+)_streamDQM_StorageManager.jsn')
31 dat_jsn_files = sorted(
filter(
lambda x: dat_jsn_pattern.match(x), files))
32 if len(dat_jsn_files) < 1:
33 print(
'No dat json files are found in "{0}"'.
format(dat_source))
34 return False, dat_jsn_files, dat_files, dat_run_number
37 jsn_files_tobe_removed = []
38 for jsn_file
in dat_jsn_files:
39 dat_file = jsn_file.replace(
'.jsn',
'.dat')
40 if not os.path.exists(dat_source +
'/' + dat_file):
41 print(
'The dat file {0} does NOT exist! Removing the corresponding json file.'.
format(dat_file))
42 jsn_files_tobe_removed.append(jsn_file)
45 dat_jsn_files = [x
for x
in dat_jsn_files
if x
not in jsn_files_tobe_removed]
48 dat_files =
map(
lambda x: x.replace(
'.jsn',
'.dat'), dat_jsn_files)
51 dat_run_number = int(dat_jsn_pattern.match(dat_jsn_files[0]).
group(1))
53 for i
in range(1,len(dat_jsn_files)):
54 run_number_current = int(dat_jsn_pattern.match(dat_jsn_files[i]).
group(1))
55 if run_number_current != dat_run_number:
56 print(
'Non consistent run numbers: "{0}" - expected, "{1}" - found'.
format(run_nummber, run_nummber_current))
57 print(
'\t "{0}" - will be used as a run number'.
format(run_nummber))
59 return True, dat_jsn_files, dat_files, dat_run_number
68 files = os.listdir(pb_source)
69 pb_jsn_pattern = re.compile(
r'run([0-9]+)_ls([0-9]+)_streamDQMHistograms_StorageManager.jsn')
70 pb_jsn_files = sorted(
filter(
lambda x: pb_jsn_pattern.match(x), files))
73 jsn_files_tobe_removed = []
74 for jsn_file
in pb_jsn_files:
75 pb_file = jsn_file.replace(
'.jsn',
'.pb')
76 if not os.path.exists(pb_source +
'/' + pb_file):
77 print(
'The pb file {0} does NOT exist! Removing the corresponding json file.'.
format(pb_file))
78 jsn_files_tobe_removed.append(jsn_file)
81 pb_jsn_files = [x
for x
in pb_jsn_files
if x
not in jsn_files_tobe_removed]
83 if len(pb_jsn_files) < 1:
84 print(
'No pb json files are found in "{0}"'.
format(pb_source))
85 return False, pb_jsn_files, pb_files, pb_run_number
88 pb_files =
map(
lambda x: x.replace(
'.jsn',
'.pb'), pb_jsn_files)
90 pb_run_number = int(pb_jsn_pattern.match(pb_jsn_files[0]).
group(1))
92 for i
in range(1,len(pb_jsn_files)):
93 run_number_current = int(pb_jsn_pattern.match(pb_jsn_files[i]).
group(1))
94 if run_number_current != pb_run_number:
95 print(
'Non consistent run numbers: "{0}" - expected, "{1}" - found'.
format(run_nummber, run_nummber_current))
96 print(
'\t "{0}" - will be used as a run number'.
format(run_nummber))
98 return True, pb_jsn_files, pb_files, pb_run_number
101 def copy_next_lumi(jsn_files, files, run_number, current_lumi, source, destination):
102 assert(len(jsn_files) == len(files))
104 index = current_lumi % len(jsn_files)
107 input_fn = source +
'/' + files[index]
108 output_fn = files[index]
109 run_start = output_fn.find(
'run') + 3
110 output_fn = output_fn[:run_start] + str(run_number).zfill(run_padding) + output_fn[run_start + run_padding:]
111 lumi_start = output_fn.find(
'ls') + 2
112 output_fn = destination +
'/' + output_fn[:lumi_start] + str(current_lumi).zfill(lumi_padding) + output_fn[lumi_start + lumi_padding:]
113 os.link(input_fn, output_fn)
114 print(input_fn +
' -> ' + output_fn)
117 input_jsn_fn = source +
'/' + jsn_files[index]
118 input_jsn = open(input_jsn_fn,
'r')
119 jsn_data = json.load(input_jsn)
123 output_jsn_fn = jsn_files[index]
124 run_start = output_jsn_fn.find(
'run') + 3
125 output_jsn_fn = output_jsn_fn[:run_start] + str(run_number).zfill(run_padding) + output_jsn_fn[run_start + run_padding:]
126 lumi_start = output_jsn_fn.find(
'ls') + 2
127 output_jsn_fn = destination +
'/' + output_jsn_fn[:lumi_start] + str(current_lumi).zfill(lumi_padding) + output_jsn_fn[lumi_start + lumi_padding:]
130 jsn_data[
'data'][3] = output_fn[output_fn.rfind(
'/')+1:]
133 output_jsn = open(output_jsn_fn,
'w')
134 output_jsn.write(json.dumps(jsn_data, indent=4))
137 print(input_jsn_fn +
' -> ' + output_jsn_fn)
139 return output_jsn_fn, output_fn
143 if __name__ ==
'__main__':
144 dat_dir_ok, dat_jsn_files, dat_files, dat_run_number =
dat_sanity_check(dat_source)
145 pb_dir_ok, pb_jsn_files, pb_files, pb_run_number =
pb_sanity_check(pb_source)
147 if dat_dir_ok
and pb_dir_ok:
148 run_number = int(dat_run_number)
149 if run_number != int(pb_run_number):
150 print(
'The dat run number "{0}" differs from the PB run number "{1}".'.
format(run_number, pb_run_number))
151 print(
'"{0}" is going to be used as a run number.'.
format(run_number))
154 output_dir = destination +
'/' +
'run' + str(dat_run_number).zfill(run_padding)
155 if not os.path.exists(output_dir): os.mkdir(output_dir)
162 files_copied +=
copy_next_lumi(dat_jsn_files, dat_files, run_number, current_lumi, dat_source, output_dir)
164 files_copied +=
copy_next_lumi(pb_jsn_files, pb_files, run_number, current_lumi, pb_source, output_dir)
166 print(
'******************************************************************************************')
168 while files_copied_buffer_len < len(files_copied):
169 os.remove(files_copied.pop(0))
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.