test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
additionalparser.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 ##########################################################################
4 # Parse the alignment_merge.py file for additional information
5 #
6 
7 import logging
8 
9 
11  """ stores the additional information of the alignment_merge.py file
12  """
13 
14  def __init__(self):
18 
19  # safe the selector information Rigid, Bowed, TwoBowed
20  self.selector = [[] for x in range(3)]
21  self.selectorTag = [[] for x in range(3)]
22  self.selectorThird = [[] for x in range(3)]
23 
24  # string to find the information and variables where to safe the
25  # information (searchstring: [selector list, seletor tag, third element,
26  # name])
27  self.pattern = {
28  "process.AlignmentProducer.ParameterBuilder.SelectorRigid = cms.PSet(": [self.selector[0], self.selectorTag[0], self.selectorThird[0], "SelectorRigid"],
29  "process.AlignmentProducer.ParameterBuilder.SelectorBowed = cms.PSet(": [self.selector[1], self.selectorTag[1], self.selectorThird[1], "SelectorBowed"],
30  "process.AlignmentProducer.ParameterBuilder.SelectorTwoBowed = cms.PSet(": [self.selector[2], self.selectorTag[2], self.selectorThird[2], "SelectorTwoBowed"]
31  }
32 
33  def parse(self, config, path):
34  logger = logging.getLogger("mpsvalidate")
35 
36  # open aligment_merge.py file
37  try:
38  with open(path) as inputFile:
39  mergeFile = inputFile.readlines()
40  except IOError:
41  logger.error("AdditionalData: {0} does not exist".format(path))
42  return
43 
44  # search pattern
45 
46  # loop over lines
47  for index, line in enumerate(mergeFile):
48  try:
49  # search for SelectorRigid, SelectorBowed and SelectorTwoBowed
50  for string in self.pattern:
51  if (string in line):
52  # extract data
53  for lineNumber in range(index + 2, index + 8):
54  mergeFile[lineNumber] = mergeFile[lineNumber].split("#", 1)[0]
55  # break at the end of the SelectorRigid
56  if (")" in mergeFile[lineNumber]):
57  break
58  self.pattern[string][0].append(
59  mergeFile[lineNumber].replace("\"", "'").strip("', \n").split(","))
60  # check if third argument
61  if (len(self.pattern[string][0][-1]) > 2):
62  self.pattern[string][1].append(
63  self.pattern[string][0][-1][2])
64  # check for third arguments
65  if ("'" not in line.replace("\"", "'")):
66  for tag in self.pattern[string][1]:
67  if tag in line:
68  self.pattern[string][2].append(line.strip("\n").replace("#", ""))
69  # add following lines
70  for lineNumber in range(index + 1, index + 5):
71  # new process or blank line
72  if ("process" in mergeFile[lineNumber] or "\n" == mergeFile[lineNumber]):
73  break
74  # different tag
75  if (any(x in mergeFile[lineNumber] for x in self.pattern[string][1])):
76  break
77  self.pattern[string][2].append(mergeFile[lineNumber].strip("\n").replace("#", ""))
78  except Exception as e:
79  logging.error("Selector Parsing error")
80 
81  # search for pedeSteererMethod
82  if ("process.AlignmentProducer.algoConfig.pedeSteerer.method" in line and "#" not in line):
83  try:
84  self.pedeSteererMethod = line.replace("\"", "'").split("'")[1]
85  except Exception as e:
86  logger.error("AdditionalParser: pedeSteererMethod not found - {0}".format(e))
87 
88  # search for pedeSteererOptions
89  if ("process.AlignmentProducer.algoConfig.pedeSteerer.options" in line and "#" not in line):
90  for lineNumber in range(index + 1, index + 15):
91  if (lineNumber<len(mergeFile)):
92  if ("]" in mergeFile[lineNumber]):
93  break
94  self.pedeSteererOptions.append(
95  mergeFile[lineNumber].replace("\"", "'").strip("', \n"))
96 
97  # search for pedeSteererCommand
98  if ("process.AlignmentProducer.algoConfig.pedeSteerer.pedeCommand" in line and "#" not in line):
99  try:
100  self.pedeSteererCommand = line.replace("\"", "'").split("'")[1]
101  except Exception as e:
102  logger.error("AdditionalParser: pedeSteererCommand not found - {0}".format(e))
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:34
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
double split
Definition: MVATrainer.cc:139