Belle II Software  release-08-01-10
batchToTxt.py
1 # @cond
2 import json
3 skimfiles = json.loads(open(snakemake.input.skim_dirs, "r").read())
4 outputfiles = snakemake.output
5 BatchesPerSkim = snakemake.params.BatchesPerSkim
6 
7 binwidth = int(len(skimfiles)/BatchesPerSkim)
8 if(binwidth < 1.):
9  raise ValueError("Attempting to batching with binwidth smaller 1. Decrease the number of batches!")
10 
11 batches = {}
12 for batch in range(BatchesPerSkim):
13  if(batch == BatchesPerSkim - 1):
14  batches.update({outputfiles[batch]: list(skimfiles[binwidth*batch:])})
15  else:
16  batches.update({outputfiles[batch]: list(skimfiles[binwidth*batch:binwidth*(batch+1)])})
17 
18 for key, file_list in batches.items():
19  with open(key, "w") as f:
20  f.write(json.dumps(file_list))
21 # @endcond