Skip to content
Snippets Groups Projects
Commit 980b1c75 authored by Stewart Martin-Haugh's avatar Stewart Martin-Haugh
Browse files

Move pickle->JSON entirely into its own method, use in confTool.py

parent 9dfa13ef
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,7 @@ def parse_args(): ...@@ -31,7 +31,7 @@ def parse_args():
parser.add_argument( parser.add_argument(
"--diff", dest="diff", action="store_true", help="Diffs two files" "--diff", dest="diff", action="store_true", help="Diffs two files"
) )
parser.add_argument("--toJSON", help="Convert to JSON file") parser.add_argument("--toJSON", action="store_true", help="Convert to JSON file")
parser.add_argument("--toPickle", help="Convert to pickle file") parser.add_argument("--toPickle", help="Convert to pickle file")
parser.add_argument("file", nargs="+", help="Files to work with") parser.add_argument("file", nargs="+", help="Files to work with")
...@@ -106,9 +106,9 @@ def main(args): ...@@ -106,9 +106,9 @@ def main(args):
sys.exit( sys.exit(
"ERROR, can convert single file at a time, got: %s" % args.file "ERROR, can convert single file at a time, got: %s" % args.file
) )
conf = _loadSingleFile(args.file[0], args) from TrigConfIO.JsonUtils import create_joboptions_json
with open(args.toJSON, "w") as oFile: create_joboptions_json(args.file[0], args.file[0].replace("pkl","json"))
json.dump(conf, oFile, indent=2, ensure_ascii=True)
if args.toPickle: if args.toPickle:
if len(args.file) != 1: if len(args.file) != 1:
......
...@@ -179,15 +179,9 @@ else: ...@@ -179,15 +179,9 @@ else:
if PscConfig.dumpJobProperties: if PscConfig.dumpJobProperties:
from AthenaCommon import ConfigurationShelve from AthenaCommon import ConfigurationShelve
from TrigConfIO.JsonUtils import create_joboptions_json from TrigConfIO.JsonUtils import create_joboptions_json
ConfigurationShelve.storeJobOptionsCatalogue('HLTJobOptions.pkl')
fname = 'HLTJobOptions' fname = 'HLTJobOptions'
with open(fname+'.pkl', "rb") as f: ConfigurationShelve.storeJobOptionsCatalogue(fname+".pkl")
import pickle create_joboptions_json(fname+".pkl",fname+".json")
jocat = pickle.load(f) # basic job properties
jocfg = pickle.load(f) # some specialized services
jocat.update(jocfg) # merge the two dictionaries
psclog.info('Dumping joboptions to "%s.json"', fname)
create_joboptions_json(jocat, fname+".json")
if PscConfig.exitAfterDump: if PscConfig.exitAfterDump:
theApp.exit(0) theApp.exit(0)
......
...@@ -3,48 +3,59 @@ ...@@ -3,48 +3,59 @@
# #
# Module to collect JSON specific trigger configuration helpers # Module to collect JSON specific trigger configuration helpers
# #
import pickle
import json import json
def create_joboptions_json(properties, filename="HLTJobOptions.json"): def create_joboptions_json(pkl_file, json_file):
"""Create the configuration JSON file from the `properties` dictionary """Create the configuration JSON file from the properties in `pkl_file`
and save it into `filename`. and save it into `json_file`.
""" """
hlt_json = {'filetype' : 'joboptions'}
with open(filename,'w') as f: with open(pkl_file, "rb") as f:
hlt_json['properties'] = properties jocat = pickle.load(f) # basic job properties
json.dump(hlt_json, f, sort_keys=True, indent=4) jocfg = pickle.load(f) # some specialized services
jocat.update(jocfg) # merge the two dictionaries
hlt_json = {'filetype' : 'joboptions'}
hlt_json['properties'] = jocat
with open(json_file, "w") as f:
json.dump(hlt_json, f, indent=4, sort_keys=True, ensure_ascii=True)
""" also create a configuration JSON file that can be uploaded """ also create a configuration JSON file that can be uploaded
to the triggerdb for running at P1 to the triggerdb for running at P1
""" """
base, ending = (filename.rsplit('.',1) + ["json"])[:2] base, ending = (json_file.rsplit('.',1) + ["json"])[:2]
filenameUpload = base + ".db." + ending db_file = base + ".db." + ending
modifyConfigForP1(properties) modifyConfigForP1(json_file, db_file)
with open(filenameUpload,'w') as f:
hlt_json['properties'] = properties
json.dump(hlt_json, f, sort_keys=True, indent=4)
def modifyConfigForP1(properties): def modifyConfigForP1(json_file, db_file):
""" modifies (in place) a number of job properties to run from the TriggerDB """ modifies a number of job properties to run from the TriggerDB and writes out modified JSON
modification in place is OK, as the original properties are temporary
""" """
def mod(props, alg, prop, fnc): with open(json_file, 'r') as f:
if alg in props and prop in props[alg]: jocat = json.load(f)
origVal = props[alg][prop] properties = jocat['properties']
else:
origVal = "" def mod(props, alg, prop, fnc):
props[alg][prop] = fnc(origVal) if alg in props and prop in props[alg]:
origVal = props[alg][prop]
else:
origVal = ""
props[alg][prop] = fnc(origVal)
# L1 and HLT Config Svc must read from db
mod( properties, "LVL1ConfigSvc", "InputType", lambda x : "db" )
mod( properties, "HLTConfigSvc", "InputType", lambda x : "db" )
mod( properties, "HLTPrescaleCondAlg", "Source", lambda x : "COOL" ) # prescales will be read from COOL online
mod( properties, "HLTPrescaleCondAlg", "TriggerDB", lambda x : "JOSVC" ) # configuration will be taken from the JOSvc at P1
# L1 and HLT Config Svc must read from db with open(db_file,'w') as f:
mod( properties, "LVL1ConfigSvc", "InputType", lambda x : "db" ) json.dump(jocat, f, indent=4, sort_keys=True, ensure_ascii=True)
mod( properties, "HLTConfigSvc", "InputType", lambda x : "db" )
mod( properties, "HLTPrescaleCondAlg", "Source", lambda x : "COOL" ) # prescales will be read from COOL online
mod( properties, "HLTPrescaleCondAlg", "TriggerDB", lambda x : "JOSVC" ) # configuration will be taken from the JOSvc at P1
if __name__ == "__main__": if __name__ == "__main__":
...@@ -57,10 +68,10 @@ if __name__ == "__main__": ...@@ -57,10 +68,10 @@ if __name__ == "__main__":
hlt_json = json.load( fh ) hlt_json = json.load( fh )
properties = hlt_json["properties"] properties = hlt_json["properties"]
modifyConfigForP1(properties) modifyConfigForP1(sys.argv[1], sys.argv[1].replace("json", "db.json"))
outfn = sys.argv[1].replace(".json",".test.json") outfn = sys.argv[1].replace(".json",".test.json")
with open(outfn,'w') as f: with open(outfn,'w') as f:
hlt_json['properties'] = properties hlt_json['properties'] = properties
json.dump(hlt_json, f, sort_keys=True, indent=4) json.dump(hlt_json, f, indent=2, sort_keys=True, ensure_ascii=True)
print("Wrote %s" % outfn) print("Wrote %s" % outfn)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment