-
Notifications
You must be signed in to change notification settings - Fork 180
Script for hybrid JSON template generation #1802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
572b9a9
Create clean-ci.yml
jackal1-66 9e3d886
Merge pull request #2 from jackal1-66/cleanpr
jackal1-66 f71a6b9
Merge branch 'AliceO2Group:master' into master
jackal1-66 1ce8e05
Script for hybrid JSON template generation
jackal1-66 913ab51
Removed comment
jackal1-66 a6fe17c
Added description and example
jackal1-66 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # This script creates a template JSON file for the configuration of the hybrid generator | ||
| # The generators to be used are passed as a list of strings via the --gen flag, while the | ||
| # output filename is set using --output. All the generators available in O2sim are supported. | ||
| # Example: | ||
| # $O2DPG_ROOT/MC/bin/o2_hybrid_gen.py --gen pythia8 boxgen external extkinO2 hepmc pythia8hf \ | ||
| # --output config.json | ||
|
|
||
| import argparse | ||
| import json | ||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description='Create a JSON file from command line flags.') | ||
| parser.add_argument('--gen', type=str, nargs='+', required=True, help='List of generators to be used') | ||
| parser.add_argument('--output', type=str, required=True, help='Output JSON file path') | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| # put in a list all the elementes in the gen flag | ||
| noConfGen = ["pythia8pp", "pythia8hf", "pythia8hi", "pythia8powheg"] | ||
| gens = [] | ||
| for gen in args.gen: | ||
| if gen == "pythia8": | ||
| gens.append({ | ||
| 'name': 'pythia8', | ||
| 'config': { | ||
| "config": "$O2_ROOT/share/Generators/egconfig/pythia8_inel.cfg", | ||
| "hooksFileName": "", | ||
| "hooksFuncName": "", | ||
| "includePartonEvent": False, | ||
| "particleFilter": "", | ||
| "verbose": 0 | ||
| } | ||
| }) | ||
| elif gen == "external": | ||
| gens.append({ | ||
| 'name': 'external', | ||
| 'config': { | ||
| "fileName": "${O2DPG_ROOT}/MC/config/PWGDQ/external/generator/GeneratorParamPromptJpsiToElectronEvtGen_pp13TeV.C", | ||
| "funcName": "GeneratorParamPromptJpsiToElectronEvtGen_pp13TeV()" | ||
| } | ||
| }) | ||
| elif gen == "extkinO2": | ||
| gens.append({ | ||
| 'name': 'extkinO2', | ||
| 'config': { | ||
| "skipNonTrackable": True, | ||
| "continueMode": False, | ||
| "roundRobin": False, | ||
| "randomize": False, | ||
| "rngseed": 0, | ||
| "randomphi": False, | ||
| "fileName": "/path/to/filename.root" | ||
| } | ||
| }) | ||
| elif gen == "hepmc": | ||
| gens.append({ | ||
| "name": "hepmc", | ||
| "config": { | ||
| "configcmd": { | ||
| "fileNames": "", | ||
| "cmd": "" | ||
| }, | ||
| "confighepmc": { | ||
| "version": 2, | ||
| "eventsToSkip": 0, | ||
| "fileName": "/path/to/filename.hepmc", | ||
| "prune": False | ||
| } | ||
| } | ||
| }) | ||
| elif gen == "boxgen": | ||
| gens.append({ | ||
| "name": "boxgen", | ||
| "config": { | ||
| "pdg": 13, | ||
| "number": 1, | ||
| "eta": [ | ||
| -4, | ||
| -2.5 | ||
| ], | ||
| "prange": [ | ||
| 0.1, | ||
| 5 | ||
| ], | ||
| "phirange": [ | ||
| 0, | ||
| 360 | ||
| ] | ||
| } | ||
| }) | ||
| elif gen in noConfGen: | ||
| gens.append({ | ||
| "name": gen, | ||
| "config": "" | ||
| }) | ||
| else: | ||
| print(f"Generator {gen} not found in the list of available generators") | ||
| exit(1) | ||
|
|
||
| # fill fractions with 1 for each generator | ||
| fractions = [1] * len(gens) | ||
|
|
||
| # Put gens and fractions in the data dictionary | ||
| data = { | ||
| "generators": gens, | ||
| "fractions": fractions | ||
| } | ||
|
|
||
| # Write the data dictionary to a JSON file | ||
| with open(args.output, 'w') as f: | ||
| json.dump(data, f, indent=2) | ||
|
|
||
| print(f"JSON file created at {args.output}") | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.