HPS-MC
 
Loading...
Searching...
No Matches
root_merge_job.py
Go to the documentation of this file.
1"""
2Merge ROOT files job script for hps-mc
3
4This job merges multiple ROOT files into a single output file using hadd.
5
6Example JSON parameters:
7{
8 "job_id": 1,
9 "input_files": {
10 "input1.root": "/path/to/input1.root",
11 "input2.root": "/path/to/input2.root",
12 "input3.root": "/path/to/input3.root"
13 },
14 "output_files": {
15 "merged.root": "merged_output.root",
16 "merged_stats.json": "merged_stats.json"
17 },
18 "output_dir": "output",
19 "force": true,
20 "compression": 6,
21 "validate": true,
22 "write_stats": true
23}
24"""
25
26from hpsmc.tools import MergeROOT
27
28# The 'job' object is provided by the framework when this script is executed
29# via exec() in the Job.run() method
30
31# Set job description
32job.description = "Merge ROOT files using hadd"
33
34# Get list of input files from the job parameters
35# The keys of input_files dict are the local file names
36input_list = list(job.input_files.keys())
37
38# Get the output file name (first .root file in output_files)
39output_file = None
40for key in job.output_files.keys():
41 if key.endswith('.root'):
42 output_file = key
43 break
44if output_file is None:
45 output_file = list(job.output_files.keys())[0]
46
47# Set up optional parameters with defaults
48force_overwrite = job.params.get('force', True)
49compression_level = job.params.get('compression', None)
50validate_merge = job.params.get('validate', True)
51write_stats = job.params.get('write_stats', True)
52job_id = job.params.get('job_id', None)
53
54# Create the MergeROOT component
55merge = MergeROOT(
56 name="merge_root",
57 inputs=input_list,
58 outputs=[output_file],
59 force=force_overwrite,
60 compression=compression_level,
61 validate=validate_merge,
62 write_stats=write_stats,
63 job_id=job_id
64)
65
66# Add component to the job
67job.add(merge)
Tools that can be used in HPSMC jobs.
Definition tools.py:1