-
Notifications
You must be signed in to change notification settings - Fork 5
WIP: Add merger #8
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
Open
mesmith75
wants to merge
11
commits into
ShipSoft:pythonise
Choose a base branch
from
mesmith75:add_merger
base: pythonise
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3a8252d
add merger script
9840305
add namespace function
5c0cdd9
feat: pythonise (#7)
mesmith75 f0795af
fixes
841316c
only parse known args
ce04f1a
Remove hardcoded X509_USER_PROXY path
mesmith75 17d4b98
update
8117fd1
Merge branch 'add_merger' of github.com-mesmith75:mesmith75/htcondor_…
9d83369
temp
6923207
conflict resolution
fe01394
tidy
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,58 @@ | ||
| # ----------------------------------------------------- | ||
| # Put the functions defined here into your ~/.ganga.py | ||
| # and it will be available in the Ganga namespace. | ||
| # Then you can just do mergeOutput(jobNo) and it will | ||
| # submit the job. | ||
| # ----------------------------------------------------- | ||
|
|
||
| def args_list_to_dict(args_list): | ||
| result = {} | ||
| i = 0 | ||
| while i < len(args_list): | ||
| key = str(args_list[i]).lstrip("-") | ||
| # Check if next item exists and is not another flag | ||
| if i + 1 < len(args_list) and isinstance(args_list[i + 1], str) and not args_list[i + 1].startswith("-"): | ||
| result[key] = args_list[i + 1] | ||
| i += 2 | ||
| else: | ||
| # Flag without value → set to True | ||
| result[key] = True | ||
| i += 1 | ||
| return result | ||
|
|
||
| def mergeOutput(jNo): | ||
|
|
||
| script_path = "/vols/lhcb/masmith/SHiP/htcondor_submission_scripts/fixedTarget/batch/" # set this to wherever you checked out the scripts package | ||
|
|
||
| j = Job(name = f"Merge output of production job {jNo}") | ||
| j.virtualization = Apptainer(image="/cvmfs/unpacked.cern.ch/registry.cern.ch/ship/gha-runner:latest/") | ||
| j.virtualization.mounts = {'/cvmfs':'/cvmfs', '/home/hep':'/home/hep'} # Adjust for your own setup | ||
| j.application = Executable(exe = File(script_path + 'wn_script.py')) | ||
| j.inputfiles = [LocalFile(script_path + "merger.py")] | ||
|
|
||
| # Copy over the args but change the run file from run_fixedTarget.py to merger | ||
| j_arg_dict = args_list_to_dict(jobs(jNo).application.args) | ||
| this_site = j_arg_dict["site"] | ||
| myargs = ['merger.py' if _a=='run_fixedTarget.py' else _a for _a in jobs(jNo).application.args] | ||
| myargs.insert(0,"--useLocalFile") | ||
| myargs.extend(['-j', jNo, '--prodSite', this_site]) | ||
| myargs.append('-i') | ||
|
|
||
| # Now grab the files | ||
| if this_site == "GRIDPP": # Do something different for GRIDPP where the files are on Dirac | ||
| inputfiles = jobs(jNo).backend.getOutputDataAccessURLs(protocol='"root"') | ||
| config["DIRAC"]["userVO"] = 'gridpp' | ||
| config["DIRAC"]["allDiracSE"] = ["UKI-LT2-IC-HEP-disk"] | ||
| else: | ||
| inputfiles = [] | ||
| for sj in jobs(jNo).subjobs.select(status="completed"): | ||
| for _f in sj.outputfiles: | ||
| if isinstance(_f, MassStorageFile): | ||
| inputfiles.append(_f.locations[0]) | ||
| myargs.extend(inputfiles) | ||
| j.application.args = myargs | ||
|
|
||
| j.outputfiles = [DiracFile('pythia8_*.root')] | ||
| j.backend = Condor() | ||
| j.backend.cdf_options["+MaxRuntime"] = '3000' # Set this to something reasonable | ||
| j.submit() | ||
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
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,19 @@ | ||
| jNo = 61 | ||
|
|
||
|
mesmith75 marked this conversation as resolved.
|
||
| j = Job(name = f"Merge output of production job {jNo}") | ||
| j.virtualization = Apptainer(image="/cvmfs/unpacked.cern.ch/registry.cern.ch/ship/gha-runner:latest/") | ||
| j.virtualization.mounts = {'/cvmfs':'/cvmfs', '/home/hep/mesmith':'/home/hep/mesmith' } | ||
| j.application = Executable(exe = File('wn_script.py')) | ||
| j.inputfiles = [LocalFile("merger.py")] | ||
| myargs = ['merger.py' if _a=='run_fixedTarget.py' else _a for _a in jobs(jNo).application.args] | ||
| myargs.extend(['-j', jNo, '--prodSite', 'GRIDPP']) | ||
| myargs.append('-i') | ||
| inputfiles = jobs(jNo).backend.getOutputDataAccessURLs(protocol='"root"') | ||
| myargs.extend(inputfiles) | ||
| j.application.args = myargs | ||
| j.outputfiles = [LocalFile('pythia_*.root')] | ||
|
|
||
| j.backend = Condor() | ||
| j.backend.cdf_options["+MaxRuntime"] = '3000' | ||
|
|
||
| j.submit() | ||
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,85 @@ | ||
| #!/usr/bin/env python | ||
| import os | ||
| import argparse | ||
| import ROOT | ||
| import uproot | ||
| import json | ||
| from datetime import datetime | ||
|
|
||
| def mergeFiles(myfiles, tmpFile): | ||
| myChain = ROOT.TChain("cbmsim") | ||
| for _f in myfiles: | ||
| myChain.Add(_f) | ||
| myChain.Merge(tmpFile) | ||
|
|
||
|
|
||
| parser = argparse.ArgumentParser( | ||
| description="Run FairShip file merger" | ||
| ) | ||
|
|
||
| parser.add_argument("-i", "--inFiles", nargs="*", | ||
| help="input files to merge") | ||
|
|
||
| parser.add_argument("-n", "--genEvents", | ||
| default=500000, | ||
| type=int, | ||
| help="How many events were generated to make this file" | ||
| ) | ||
|
|
||
| parser.add_argument("-e", "--eCut", | ||
| default=30, | ||
| type=float, | ||
| help="What was the energy cut to produce the file" | ||
| ) | ||
|
|
||
| parser.add_argument("-j", "--gangaJob", | ||
| type=int, | ||
| help="Which ganga job produced these files", | ||
| ) | ||
| parser.add_argument("-s", "--site", | ||
| default="CERN", | ||
| help="Which site was this run at" | ||
| ) | ||
|
|
||
| parser.add_argument("-o", "--outputPath", | ||
| help="A placeholder") | ||
|
|
||
| parser.add_argument("--prodSite", | ||
| default="CERN", | ||
| help="Which site was this run at" | ||
| ) | ||
|
|
||
| args, _ = parser.parse_known_args() | ||
|
|
||
|
|
||
| if args.prodSite == "GRIDPP": | ||
| os.environ["X509_VOMSES"]="/cvmfs/grid.cern.ch/etc/grid-security/vomses" | ||
| os.environ["X509_VOMS_DIR"]="/cvmfs/grid.cern.ch/etc/grid-security/vomsdir" | ||
| os.environ["X509_CERT_DIR"]="/cvmfs/grid.cern.ch/etc/grid-security/certificates" | ||
|
|
||
| files_to_merge = args.inFiles | ||
| if not len(files_to_merge)>0: | ||
| print("ERROR: no files to merge! Doing nothing") | ||
| sys.exit() | ||
| print("INFO: Merging %s files from job %s" % (len(files_to_merge), args.gangaJob)) | ||
|
|
||
| total_pot = len(files_to_merge) * args.genEvents | ||
| outName = f"pythia8_Geant4_eCut_{args.eCut}_PoT_{total_pot}_{args.prodSite}_j{args.gangaJob}.root" | ||
|
|
||
| mergeFiles(files_to_merge, outName) | ||
|
|
||
| fsr = { | ||
| "PoT" : total_pot, | ||
| "EnergyCut": args.eCut, | ||
| "PoTperFile": args.genEvents, | ||
| "nFilesMerged": len(files_to_merge), | ||
| "filesMerged": args.inFiles, | ||
| "prodSite": args.prodSite, | ||
| "mergeDate": datetime.today().strftime('%Y-%m-%d') | ||
| } | ||
|
|
||
| print("INFO: Adding the file summary") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @THanae This is the file summary I suggested. Not FairRoot specific and easy to structure, merge, add to |
||
| with uproot.update(outName) as _f: | ||
| _f["FileSummary"] = json.dumps(fsr) | ||
|
|
||
| print("INFO: All done") | ||
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
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.