-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_jsons.py
44 lines (32 loc) · 1.67 KB
/
create_jsons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import yaml
import argparse
import subprocess
import json
def create_jsons(args):
with open(f'samples/{args.year}.yaml') as f:
samples = yaml.load(f, Loader=yaml.FullLoader)
subprocess.run(['gfal-mkdir', f'{args.destination_path}/{args.year}'])
for sample in samples:
subprocess.run(['gfal-mkdir', f'{args.destination_path}/{args.year}/{sample}'])
for sample in samples:
source_sample_path = f'{args.source_path}/{args.year}/{sample}'
result = subprocess.run(['gfal-ls', source_sample_path], capture_output=True, text=True, check=True)
files = result.stdout.splitlines()
data = {
"files": []
}
for file in files:
file_entry = {
"sources": [f'{source_sample_path}/{file}'],
"destinations": [f'{args.destination_path}/{args.year}/{sample}/{file}']
}
data["files"].append(file_entry)
with open(f'jsons/{args.year}/{sample}.json', 'w') as f:
json.dump(data, f, indent=4)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Create JSONs from YAMLs')
parser.add_argument('--year', required=True, help='Year to process')
parser.add_argument('--destination_path', required=False, help='Path to create directories on dcache', default='davs://gfe02.grid.hep.ph.ic.ac.uk:2880/pnfs/hep.ph.ic.ac.uk/data/cms/store/user/ksavva/HLepRare/skim_2024_v2')
parser.add_argument('--source_path', required=False, help='Path to sample root files', default='davs://eoscms.cern.ch/eos/cms/store/group/phys_higgs/HLepRare/skim_2024_v2')
args = parser.parse_args()
create_jsons(args)