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 },
17 "output_dir": "output",
18 "force": true,
19 "compression": 6,
20 "validate": true
21}
22"""
23
24from hpsmc.tools import MergeROOT
25
26# The 'job' object is provided by the framework when this script is executed
27# via exec() in the Job.run() method
28
29# Set job description
30job.description = "Merge ROOT files using hadd"
31
32# Get list of input files from the job parameters
33# The keys of input_files dict are the local file names
34input_list = list(job.input_files.keys())
35
36# Get the output file name
37# The key of output_files dict is the source (local name)
38output_file = list(job.output_files.keys())[0]
39
40# Set up optional parameters with defaults
41force_overwrite = job.params.get('force', True)
42compression_level = job.params.get('compression', None)
43validate_merge = job.params.get('validate', True)
44
45# Create the MergeROOT component
46merge = MergeROOT(
47 name="merge_root",
48 inputs=input_list,
49 outputs=[output_file],
50 force=force_overwrite,
51 compression=compression_level,
52 validate=validate_merge
53)
54
55# Add component to the job
56job.add(merge)
Tools that can be used in HPSMC jobs.
Definition tools.py:1