Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:40

0001 #!/usr/bin/env python3
0002 from __future__ import print_function
0003 import json , sys
0004 input_range = []
0005 output_files_list = []
0006 lumi_ranges  = sys.argv[1].split(':')
0007 for lumi_range in lumi_ranges:
0008   input_range.append(tuple(lumi_range.split(',')))
0009 
0010 jdata = sys.stdin.read()
0011 try:
0012   lumi_data = json.loads(jdata) 
0013 except:
0014   print(jdata)
0015   exit (1)
0016 lumi_data = lumi_data['data']
0017 
0018 def match_in(sub_list,lumi_list):
0019   for i in range(int(sub_list[0]),int(sub_list[1])+1):
0020     if len(lumi_list) == 1:
0021       if i == int(lumi_list[0]): return True
0022     else:
0023       if i >= int(lumi_list[0]) and i <= int(lumi_list[1]): return True
0024   return False
0025 
0026 def check_lumi_ranges(given_lumi_list , sub_range):
0027   for lumi_r in given_lumi_list:
0028     if match_in(sub_range, lumi_r):
0029       return True 
0030   return False
0031 
0032 def process_lumi(data):
0033   for lumi_info in data:
0034     if isinstance(lumi_info['lumi'], list):
0035       lumi_nums = lumi_info['lumi'][0]['number']
0036       lumi_file = lumi_info['file'][0]['name']
0037     else:
0038       lumi_nums = lumi_info['lumi']['number']
0039       lumi_file = lumi_info['file']['name']
0040     if not isinstance(lumi_nums[0], list): lumi_rang = [ [n,n] for n in lumi_nums ]
0041     else: lumi_rang = lumi_nums
0042     for sub_list in lumi_rang:
0043       if check_lumi_ranges(input_range,tuple(sub_list)):
0044         output_files_list.append(lumi_file)
0045         break
0046   for out_file_name in output_files_list:
0047     print(out_file_name)
0048 
0049 #Get file names for desired lumi ranges
0050 process_lumi(lumi_data)
0051