Created
October 20, 2016 11:16
-
-
Save lukasheinrich/791c1708e744299952eef8561d09703b to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
import ROOT | |
ROOT.gROOT.SetBatch(True) | |
import yaml | |
import click | |
import os | |
from xml.etree import ElementTree as etree | |
def get_path(basedir,relpath): | |
return '{}/{}'.format(basedir,relpath.split('./',1)[-1]) | |
def parse_histfactory_xml(toplvlxml): | |
dirname = os.path.abspath(os.path.dirname(toplvlxml)) | |
histfithome = dirname.split('/config')[0] | |
p = etree.parse(toplvlxml) | |
channels = [etree.parse(open(get_path(histfithome,inpt.text))).findall('.')[0] for inpt in p.findall('Input')] | |
parsed_data = { | |
'Combination':{ | |
'Prefix':p.findall('.')[0].attrib['OutputFilePrefix'].split('./',1)[-1], | |
'Measurements':[ {'name':x.attrib['Name'] for x in p.findall('Measurement')}] | |
} | |
} | |
channel_info = [] | |
for input_tag in p.findall('Input'): | |
channel_xml = etree.parse(open(get_path(histfithome,input_tag.text))) | |
channel_name = channel_xml.findall('.')[0].attrib['Name'] | |
sample_names = [x.attrib['Name'] for x in channel_xml.findall('Sample')] | |
channel_info += [{'name':channel_name,'samples':sample_names}] | |
parsed_data['Combination']['Inputs'] = channel_info | |
return parsed_data | |
@click.command() | |
@click.argument('toplvlxml') | |
@click.argument('output') | |
def dump_information(toplvlxml,output): | |
parsed_data = parse_histfactory_xml(toplvlxml) | |
with open(output,'w') as f: | |
f.write(yaml.safe_dump(parsed_data,default_flow_style = False)) | |
if __name__=='__main__': | |
dump_information() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment