CMS 3D CMS Logo

MVAConfigBuilder.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 """
4 MVAConfigBuilder.py
5 
6 Author: Evan K. Friis, UC Davis friis@physics.ucdavis.edu
7 
8 Usage: Any objects with file type [name].mvac will be turned into [name].xml with the correct format
9 
10 A configuration script to automate changes in available MVA input variables (for the PhysicsTools/MVAComputer framework)
11 across numerous MVA configurations.
12 
13 This is total kludge and will be deprecated when
14  a. I figure out how you use <xi:include... success full (xml sucks)
15  b. Proposed changes to the MVA objects allow classification steering in a single xml file
16 """
17 from __future__ import print_function
18 
19 import os
20 import glob
21 import string
22 
23 filesToConvert = glob.glob("./*.mvac")
24 
25 RemoveNumEventsSpecifiers = True
26 
27 for aFile in filesToConvert:
28  xmlFileName = string.replace(aFile, "mvac", "xml")
29  if os.path.exists(xmlFileName):
30  os.system("cp %s %s.bak" % (xmlFileName, xmlFileName))
31  os.remove(xmlFileName)
32 
33  print("Building %s..." % xmlFileName)
34  os.system("cat Preamble.xml.fragment > %s" % xmlFileName)
35  os.system("cat Inputs.xml.fragment >> %s" % xmlFileName)
36  os.system("cat Helpers.xml.fragment >> %s" % xmlFileName)
37  if RemoveNumEventsSpecifiers:
38  os.system("cat %s | sed 's|NSigTest=[0-9]*|NSigTest=0|' | sed 's|NBkgTest=[0-9]*|NBkgTest=0|' | sed 's|NSigTrain=[0-9]*|NSigTrain=0|' | sed 's|NBkgTrain=[0-9]*|NBkgTrain=0|' >> %s" % (aFile, xmlFileName))
39  else:
40  os.system("cat %s >> %s" % (aFile, xmlFileName))
41  os.system("cat Finale.xml.fragment >> %s" % xmlFileName)
42 
43 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65