test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
iniparser.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 ##########################################################################
4 
5 # Read the ini data which is passed to the function and return the
6 # data as a configData object. If a parameter is given the function
7 # parseParameter will override the config values.
8 ##
9 
10 import ConfigParser
11 import logging
12 import os
13 
14 
15 class ConfigData:
16  """ stores the config data of the ini files or the console parameters
17  """
18 
19  def __init__(self):
20  # get path to modules, defaut ini and templates
21  self.mpspath = os.path.join(os.path.dirname(__file__))
22 
23  # General
24  # jobmX dir
25  self.jobNumber = -1
26  # MillePedeUser_X time
27  self.jobTime = -1
28  # ./jobData/jobmX path
29  self.jobDataPath = ""
30  # base outputpath
31  self.outputPath = ""
32  # latex file name
33  self.latexfile = ""
34  # identification in every plot (e.g. mp1885)
35  self.message = ""
36  # limits for warning dict with keys xyz, rot, dist
37  # arguments must be given in this order
38  self.limit = {}
39  # statboxsize
40  self.statboxsize = -1
41 
42  # what should be created
43  self.showmonitor = -1
44  self.showadditional = -1
45  self.showdump = -1
46  self.showtime = -1
47  self.showhighlevel = -1
48  self.showmodule = -1
49  self.showsubmodule = -1
50  self.showtex = -1
51  self.showbeamer = -1
52  self.showhtml = -1
53 
54  # MODULEPLOTS
55  # number of bins after shrinking
56  self.numberofbins = -1
57  # definition of sharp peak; max_outlier / StdDev > X
58  self.defpeak = -1
59  # new histogram width in units of StdDev
60  self.widthstddev = -1
61  # every parameter (e.g. xyz) with same range
62  self.samerange = -1
63  # rangemode "stddev" = multiple of StdDev, "all" = show all, "given" =
64  # use given ranges
65  self.rangemode = -1
66  # ranges
67  self.rangexyzM = []
68  self.rangerotM = []
69  self.rangedistM = []
70 
71  # HIGHLEVELPLOTS
72  # given ranges
73  self.rangexyzHL = []
74  self.rangerotHL = []
75  # every parameter (e.g. xyz) with same range
76  self.samerangeHL = -1
77  # rangemode "all" = show all, "given" = use given ranges
78  self.rangemodeHL = -1
79 
80  # Time dependent
81  self.firsttree = -1
82 
83  # list with the plots for the output
84  self.outputList = []
85 
86  def parseConfig(self, path):
87  logger = logging.getLogger("mpsvalidate")
88 
89  # create ConfigParser object
90  parser = ConfigParser.ConfigParser()
91 
92  # read ini file
93  if (parser.read(path) == []):
94  logger.error("Could not open ini-file: {0}".format(path))
95 
96  # buffer object
97  configBuffer = ConfigData()
98 
99  # collect data and process it
100  try:
101  configBuffer.jobNumber = int(parser.get("GENERAL", "job"))
102  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
103  pass
104 
105  try:
106  configBuffer.jobDataPath = parser.get("GENERAL", "jobdatapath")
107  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
108  pass
109 
110  # set jobDataPath if job number is given and if path is not given
111  if (configBuffer.jobNumber != -1 and configBuffer.jobDataPath == ""):
112  self.jobNumber = configBuffer.jobNumber
113  if (self.jobNumber == 0):
114  self.jobDataPath = "jobData/jobm"
115  else:
116  self.jobDataPath = "jobData/jobm{0}".format(self.jobNumber)
117  self.outputPath = os.path.join(self.jobDataPath, "validation_output")
118 
119  # if jobData path is given
120  if (configBuffer.jobDataPath != ""):
121  self.jobDataPath = configBuffer.jobDataPath
122  self.outputPath = "validation_output"
123 
124  # set outputpath
125  try:
126  if (parser.get("GENERAL", "outputpath")):
127  self.outputPath = parser.get("GENERAL", "outputpath")
128  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
129  pass
130 
131 
132  # data which could be stored directly
133  try:
134  self.jobTime = int(parser.get("GENERAL", "time"))
135  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
136  pass
137 
138  try:
139  self.latexfile = parser.get("GENERAL", "latexfile")
140  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
141  pass
142 
143  try:
144  self.limit = parser.get("GENERAL", "limit")
145  self.limit = map(float, self.limit.replace(" ", "").split(","))
146  # make a dict to lookup by mode
147  self.limit = dict(zip(["xyz", "rot", "dist"], self.limit))
148  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
149  pass
150 
151  try:
152  self.statboxsize = float(parser.get("GENERAL", "statboxsize"))
153  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
154  pass
155 
156  # MODULEPLOTS
157 
158  try:
159  self.numberofbins = int(parser.get("MODULEPLOTS", "numberofbins"))
160  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
161  pass
162 
163  try:
164  self.defpeak = int(parser.get("MODULEPLOTS", "defpeak"))
165  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
166  pass
167 
168  try:
169  self.widthstddev = int(parser.get("MODULEPLOTS", "widthstddev"))
170  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
171  pass
172 
173  try:
174  self.samerange = int(parser.get("MODULEPLOTS", "samerange"))
175  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
176  pass
177 
178  try:
179  self.rangemode = parser.get("MODULEPLOTS", "rangemode")
180  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
181  pass
182 
183  try:
184  self.rangexyzM = parser.get("MODULEPLOTS", "rangexyz")
185  self.rangexyzM = sorted(
186  map(float, self.rangexyzM.replace(" ", "").split(",")))
187  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
188  pass
189 
190  try:
191  self.rangerotM = parser.get("MODULEPLOTS", "rangerot")
192  self.rangerotM = sorted(
193  map(float, self.rangerotM.replace(" ", "").split(",")))
194  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
195  pass
196 
197  try:
198  self.rangedistM = parser.get("MODULEPLOTS", "rangedist")
199  self.rangedistM = sorted(
200  map(float, self.rangedistM.replace(" ", "").split(",")))
201  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
202  pass
203 
204  # HIGHLEVELPLOTS
205 
206  try:
207  self.rangexyzHL = parser.get("HIGHLEVELPLOTS", "rangexyz")
208  self.rangexyzHL = sorted(
209  map(float, self.rangexyzHL.replace(" ", "").split(",")))
210  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
211  pass
212 
213  try:
214  self.rangerotHL = parser.get("HIGHLEVELPLOTS", "rangerot")
215  self.rangerotHL = sorted(
216  map(float, self.rangerotHL.replace(" ", "").split(",")))
217  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
218  pass
219 
220  try:
221  self.samerangeHL = int(parser.get("HIGHLEVELPLOTS", "samerange"))
222  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
223  pass
224 
225  try:
226  self.rangemodeHL = parser.get("HIGHLEVELPLOTS", "rangemode")
227  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
228  pass
229 
230  # TIMEPLOTS
231 
232  try:
233  self.firsttree = int(parser.get("TIMEPLOTS", "firsttree"))
234  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
235  pass
236 
237  # SHOW
238 
239  try:
240  self.showmonitor = int(parser.get("SHOW", "showmonitor"))
241  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
242  pass
243 
244  try:
245  self.showadditional = int(parser.get("SHOW", "showadditional"))
246  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
247  pass
248 
249  try:
250  self.showdump = int(parser.get("SHOW", "showdump"))
251  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
252  pass
253 
254  try:
255  self.showtime = int(parser.get("SHOW", "showtime"))
256  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
257  pass
258 
259  try:
260  self.showhighlevel = int(parser.get("SHOW", "showhighlevel"))
261  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
262  pass
263 
264  try:
265  self.showmodule = int(parser.get("SHOW", "showmodule"))
266  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
267  pass
268 
269  try:
270  self.showsubmodule = int(parser.get("SHOW", "showsubmodule"))
271  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
272  pass
273 
274  try:
275  self.showtex = int(parser.get("SHOW", "showtex"))
276  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
277  pass
278 
279  try:
280  self.showbeamer = int(parser.get("SHOW", "showbeamer"))
281  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
282  pass
283 
284  try:
285  self.showhtml = int(parser.get("SHOW", "showhtml"))
286  except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
287  pass
288 
289  def parseParameter(self, args):
290  logger = logging.getLogger("mpsvalidate")
291 
292  # check if parameter is given and override the config data
293  if (args.time != -1):
294  self.jobTime = args.time
295 
296  if (args.job != -1):
297  self.jobNumber = args.job
298 
299  # set jobDataPath
300  if (self.jobNumber == 0):
301  self.jobDataPath = "jobData/jobm"
302  else:
303  self.jobDataPath = "jobData/jobm{0}".format(self.jobNumber)
304  self.outputPath = os.path.join(self.jobDataPath, "validation_output")
305 
306  if (args.jobdatapath != ""):
307  self.jobDataPath = args.jobdatapath
308 
309  if (args.message != ""):
310  self.message = args.message
311 
312  # if path is given put the output in the current directory
313  if (args.jobdatapath):
314  self.outputPath = "validation_output"
315 
316  if (args.outputpath):
317  self.outputPath = args.outputpath
318 
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
double split
Definition: MVATrainer.cc:139