CMS 3D CMS Logo

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