CMS 3D CMS Logo

das-selected-lumis.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 from __future__ import print_function
3 import json , sys
4 input_range = []
5 output_files_list = []
6 lumi_ranges = sys.argv[1].split(':')
7 for lumi_range in lumi_ranges:
8  input_range.append(tuple(lumi_range.split(',')))
9 
10 jdata = sys.stdin.read()
11 try:
12  lumi_data = json.loads(jdata)
13 except:
14  print(jdata)
15  exit (1)
16 lumi_data = lumi_data['data']
17 
18 def match_in(sub_list,lumi_list):
19  for i in range(int(sub_list[0]),int(sub_list[1])+1):
20  if len(lumi_list) == 1:
21  if i == int(lumi_list[0]): return True
22  else:
23  if i >= int(lumi_list[0]) and i <= int(lumi_list[1]): return True
24  return False
25 
26 def check_lumi_ranges(given_lumi_list , sub_range):
27  for lumi_r in given_lumi_list:
28  if match_in(sub_range, lumi_r):
29  return True
30  return False
31 
32 def process_lumi(data):
33  for lumi_info in data:
34  if isinstance(lumi_info['lumi'], list):
35  lumi_nums = lumi_info['lumi'][0]['number']
36  lumi_file = lumi_info['file'][0]['name']
37  else:
38  lumi_nums = lumi_info['lumi']['number']
39  lumi_file = lumi_info['file']['name']
40  if not isinstance(lumi_nums[0], list): lumi_rang = [ [n,n] for n in lumi_nums ]
41  else: lumi_rang = lumi_nums
42  for sub_list in lumi_rang:
43  if check_lumi_ranges(input_range,tuple(sub_list)):
44  output_files_list.append(lumi_file)
45  break
46  for out_file_name in output_files_list:
47  print(out_file_name)
48 
49 #Get file names for desired lumi ranges
50 process_lumi(lumi_data)
51 
def check_lumi_ranges(given_lumi_list, sub_range)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def match_in(sub_list, lumi_list)