ATLAS Offline Software
Loading...
Searching...
No Matches
MergeEBWeightsFiles Namespace Reference

Functions

 mergeEBWeightsFiles (input_files)
 createWeightsNode (xmlDoc, xmlRoot, weights_list)
 createEventsNode (xmlDoc, xmlRoot, events_list)
 checkRunNumber (runNumber, input_files)

Variables

 log = logging.getLogger('MergeEBWeigtsFiles.py')
 parser = ArgumentParser()
 nargs
 help
 default
 type
 int
 args = parser.parse_args()
 input_files = args.inputfiles
 runNumber = re.compile(r'\d+')
dict parsed_files = {}
 weights_list
 events_list
 doc = minidom.parseString("<run/>")
 root = doc.documentElement
 output_filename = args.outputfile
 xml_str = root.toprettyxml(indent = " ")

Function Documentation

◆ checkRunNumber()

MergeEBWeightsFiles.checkRunNumber ( runNumber,
input_files )

Definition at line 73 of file MergeEBWeightsFiles.py.

73def checkRunNumber(runNumber, input_files):
74 for fin in input_files[1:]:
75 rn = re.compile(r'\d+')
76 rn = rn.findall(fin)
77 if rn[-1] != runNumber[-1]:
78 sys.exit("ERROR: run number should be the same for all input files. Exiting.")
79

◆ createEventsNode()

MergeEBWeightsFiles.createEventsNode ( xmlDoc,
xmlRoot,
events_list )

Definition at line 63 of file MergeEBWeightsFiles.py.

63def createEventsNode(xmlDoc, xmlRoot, events_list):
64 events_element = xmlDoc.createElement("events")
65 xmlRoot.appendChild(events_element)
66 for event in events_list:
67 e=doc.createElement("e")
68 e.setAttribute("n", event["n"])
69 e.setAttribute("w", event["w"])
70 events_element.appendChild(e)
71
72# Check that all the input files have the same run number

◆ createWeightsNode()

MergeEBWeightsFiles.createWeightsNode ( xmlDoc,
xmlRoot,
weights_list )

Definition at line 52 of file MergeEBWeightsFiles.py.

52def createWeightsNode(xmlDoc, xmlRoot, weights_list):
53 weights_element = xmlDoc.createElement("weights")
54 xmlRoot.appendChild(weights_element)
55 for weight in weights_list:
56 w=doc.createElement("weight")
57 w.setAttribute("id", weight["id"])
58 w.setAttribute("value", weight["value"])
59 w.setAttribute("unbiased", weight["unbiased"])
60 weights_element.appendChild(w)
61
62# Create events node

◆ mergeEBWeightsFiles()

MergeEBWeightsFiles.mergeEBWeightsFiles ( input_files)

Definition at line 13 of file MergeEBWeightsFiles.py.

13def mergeEBWeightsFiles(input_files):
14 check_weight = []
15 weightsList = []
16 eventsList = []
17
18 new_id=0
19 log.debug("Processing file {0}".format(list(input_files.keys())[0]))
20 weights = list(input_files.values())[0].getElementsByTagName("weight")
21 for weight in weights:
22 weightsList.append({"value":weight.getAttribute("value"), "unbiased":weight.getAttribute("unbiased"), "id":str(new_id)})
23 check_weight.append({"value": weight.getAttribute("value"), "unbiased":weight.getAttribute("unbiased")})
24 new_id+=1
25 events = list(input_files.values())[0].getElementsByTagName("e")
26 for event in events:
27 eventsList.append({"n":event.getAttribute("n"), "w":event.getAttribute("w")})
28
29 for fin_name, fin in list(input_files.items())[1:]:
30 log.debug("Processing file {0}".format(fin_name))
31 id_map = {} # mapping between old and new ids
32 weights = fin.getElementsByTagName("weight")
33 for weight in weights:
34 element = {"value": weight.getAttribute("value"), "unbiased":weight.getAttribute("unbiased")}
35 # If the weight is not already in the list, add it to the list, update the id and associate the new id to the old one through id_map
36 # If the weight is already in the list, only associate the new id to the old one through id_map
37 if element not in check_weight:
38 check_weight.append(element.copy())
39 element["id"] = str(new_id)
40 weightsList.append(element)
41 id_map[weight.getAttribute("id")]=element["id"]
42 new_id+=1
43 else:
44 id_map[weight.getAttribute("id")]=weightsList[check_weight.index(element)]["id"]
45 events = fin.getElementsByTagName("e")
46 # Loop on events to update the weights ids
47 for event in events:
48 eventsList.append({"n":event.getAttribute("n"), "w":id_map[event.getAttribute("w")]})
49 return weightsList, eventsList
50
51# Create weights node

Variable Documentation

◆ args

MergeEBWeightsFiles.args = parser.parse_args()

Definition at line 87 of file MergeEBWeightsFiles.py.

◆ default

MergeEBWeightsFiles.default

Definition at line 85 of file MergeEBWeightsFiles.py.

◆ doc

MergeEBWeightsFiles.doc = minidom.parseString("<run/>")

Definition at line 111 of file MergeEBWeightsFiles.py.

◆ events_list

MergeEBWeightsFiles.events_list

Definition at line 108 of file MergeEBWeightsFiles.py.

◆ help

MergeEBWeightsFiles.help

Definition at line 84 of file MergeEBWeightsFiles.py.

◆ input_files

MergeEBWeightsFiles.input_files = args.inputfiles

Definition at line 91 of file MergeEBWeightsFiles.py.

◆ int

MergeEBWeightsFiles.int

Definition at line 86 of file MergeEBWeightsFiles.py.

◆ log

MergeEBWeightsFiles.log = logging.getLogger('MergeEBWeigtsFiles.py')

Definition at line 10 of file MergeEBWeightsFiles.py.

◆ nargs

MergeEBWeightsFiles.nargs

Definition at line 84 of file MergeEBWeightsFiles.py.

◆ output_filename

MergeEBWeightsFiles.output_filename = args.outputfile

Definition at line 119 of file MergeEBWeightsFiles.py.

◆ parsed_files

dict MergeEBWeightsFiles.parsed_files = {}

Definition at line 103 of file MergeEBWeightsFiles.py.

◆ parser

MergeEBWeightsFiles.parser = ArgumentParser()

Definition at line 83 of file MergeEBWeightsFiles.py.

◆ root

MergeEBWeightsFiles.root = doc.documentElement

Definition at line 112 of file MergeEBWeightsFiles.py.

◆ runNumber

MergeEBWeightsFiles.runNumber = re.compile(r'\d+')

Definition at line 99 of file MergeEBWeightsFiles.py.

◆ type

MergeEBWeightsFiles.type

Definition at line 86 of file MergeEBWeightsFiles.py.

◆ weights_list

MergeEBWeightsFiles.weights_list

Definition at line 108 of file MergeEBWeightsFiles.py.

◆ xml_str

MergeEBWeightsFiles.xml_str = root.toprettyxml(indent = " ")

Definition at line 124 of file MergeEBWeightsFiles.py.