CMS 3D CMS Logo

mps_alisetup.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #############################################################################
4 ## Builds the config-templates from the universal config-template for each
5 ## dataset specified in .ini-file that is passed to this script as argument.
6 ## Then calls mps_setup.pl for all datasets.
7 
11 
12 import argparse
13 import os
14 import re
15 import subprocess
16 import ConfigParser
17 import sys
18 import itertools
19 import collections
20 import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass as mpslib
21 import Alignment.MillePedeAlignmentAlgorithm.mpslib.tools as mps_tools
22 from Alignment.MillePedeAlignmentAlgorithm.alignmentsetup.helper import checked_out_MPS
23 from functools import reduce
24 
25 
26 def get_weight_configs(config):
27  """Extracts different weight configurations from `config`.
28 
29  Arguments:
30  - `config`: ConfigParser object containing the alignment configuration
31  """
32 
33  weight_dict = collections.OrderedDict()
34  common_weights = {}
35 
36  # loop over datasets to reassign weights
37  for section in config.sections():
38  if 'general' in section:
39  continue
40  elif section == "weights":
41  for option in config.options(section):
42  common_weights[option] = [x.strip() for x in
43  config.get(section, option).split(",")]
44  elif section.startswith("dataset:"):
45  name = section[8:] # get name of dataset by stripping of "dataset:"
46  if config.has_option(section,'weight'):
47  weight_dict[name] = [x.strip() for x in
48  config.get(section, "weight").split(",")]
49  else:
50  weight_dict[name] = ['1.0']
51 
52  weights_list = [[(name, weight) for weight in weight_dict[name]]
53  for name in weight_dict]
54 
55  common_weights_list = [[(name, weight) for weight in common_weights[name]]
56  for name in common_weights]
57  common_weights_dicts = []
58  for item in itertools.product(*common_weights_list):
59  d = {}
60  for name,weight in item:
61  d[name] = weight
62  common_weights_dicts.append(d)
63 
64  configs = []
65  for weight_conf in itertools.product(*weights_list):
66  if len(common_weights) > 0:
67  for common_weight in common_weights_dicts:
68  configs.append([(dataset[0],
69  reduce(lambda x,y: x.replace(y, common_weight[y]),
70  common_weight, dataset[1]))
71  for dataset in weight_conf])
72  else:
73  configs.append(weight_conf)
74 
75  return configs
76 
77 
78 def create_input_db(cms_process, run_number):
79  """
80  Create sqlite file with single-IOV tags and use it to override the GT. If
81  the GT is already customized by the user, the customization has higher
82  priority. Returns a snippet to be appended to the configuration file
83 
84  Arguments:
85  - `cms_process`: cms.Process object
86  - `run_number`: run from which to extract the alignment payloads
87  """
88 
89  run_number = int(run_number)
90  if not run_number > 0:
91  print "'FirstRunForStartGeometry' must be positive, but is", run_number
92  sys.exit(1)
93 
94  input_db_name = os.path.abspath("alignment_input.db")
95  tags = mps_tools.create_single_iov_db(
96  check_iov_definition(cms_process, run_number),
97  run_number, input_db_name)
98 
99  result = ""
100  for record,tag in tags.iteritems():
101  if result == "":
102  result += ("\nimport "
103  "Alignment.MillePedeAlignmentAlgorithm.alignmentsetup."
104  "SetCondition as tagwriter\n")
105  result += ("\ntagwriter.setCondition(process,\n"
106  " connect = \""+tag["connect"]+"\",\n"
107  " record = \""+record+"\",\n"
108  " tag = \""+tag["tag"]+"\")\n")
109 
110  return result
111 
112 
113 def check_iov_definition(cms_process, first_run):
114  """
115  Check consistency of input alignment payloads and IOV definition.
116  Returns a dictionary with the information needed to override possibly
117  problematic input taken from the global tag.
118 
119  Arguments:
120  - `cms_process`: cms.Process object containing the CMSSW configuration
121  - `first_run`: first run for start geometry
122  """
123 
124  print "Checking consistency of IOV definition..."
125  iovs = mps_tools.make_unique_runranges(cms_process.AlignmentProducer)
126 
127  if first_run != iovs[0]: # simple consistency check
128  print "Value of 'FirstRunForStartGeometry' has to match first defined",
129  print "output IOV:",
130  print first_run, "!=", iovs[0]
131  sys.exit(1)
132 
133 
134  inputs = {
135  "TrackerAlignmentRcd": None,
136  "TrackerSurfaceDeformationRcd": None,
137  "TrackerAlignmentErrorExtendedRcd": None,
138  }
139 
140  for condition in cms_process.GlobalTag.toGet.value():
141  if condition.record.value() in inputs:
142  inputs[condition.record.value()] = {
143  "tag": condition.tag.value(),
144  "connect": ("pro"
145  if not condition.hasParameter("connect")
146  else condition.connect.value())
147  }
148 
149  inputs_from_gt = [record for record in inputs if inputs[record] is None]
150  inputs.update(mps_tools.get_tags(cms_process.GlobalTag.globaltag.value(),
151  inputs_from_gt))
152 
153  for inp in inputs.itervalues():
154  inp["iovs"] = mps_tools.get_iovs(inp["connect"], inp["tag"])
155 
156  # check consistency of input with output
157  problematic_gt_inputs = {}
158  input_indices = {key: len(value["iovs"]) -1
159  for key,value in inputs.iteritems()}
160  for iov in reversed(iovs):
161  for inp in inputs:
162  if inp in problematic_gt_inputs: continue
163  if input_indices[inp] < 0:
164  print "First output IOV boundary at run", iov,
165  print "is before the first input IOV boundary at",
166  print inputs[inp]["iovs"][0], "for '"+inp+"'."
167  print "Please check your run range selection."
168  sys.exit(1)
169  input_iov = inputs[inp]["iovs"][input_indices[inp]]
170  if iov < input_iov:
171  if inp in inputs_from_gt:
172  problematic_gt_inputs[inp] = inputs[inp]
173  print "Found problematic input taken from global tag."
174  print "Input IOV boundary at run",input_iov,
175  print "for '"+inp+"' is within output IOV starting with",
176  print "run", str(iov)+"."
177  print "Deriving an alignment with coarse IOV granularity",
178  print "starting from finer granularity leads to wrong",
179  print "results."
180  print "A single IOV input using the IOV of",
181  print "'FirstRunForStartGeometry' ("+str(first_run)+") is",
182  print "automatically created and used."
183  continue
184  print "Found input IOV boundary at run",input_iov,
185  print "for '"+inp+"' which is within output IOV starting with",
186  print "run", str(iov)+"."
187  print "Deriving an alignment with coarse IOV granularity",
188  print "starting from finer granularity leads to wrong results."
189  print "Please check your run range selection."
190  sys.exit(1)
191  elif iov == input_iov:
192  input_indices[inp] -= 1
193 
194  # check consistency of 'TrackerAlignmentRcd' with other inputs
195  input_indices = {key: len(value["iovs"]) -1
196  for key,value in inputs.iteritems()
197  if (key != "TrackerAlignmentRcd")
198  and (inp not in problematic_gt_inputs)}
199  for iov in reversed(inputs["TrackerAlignmentRcd"]["iovs"]):
200  for inp in input_indices:
201  input_iov = inputs[inp]["iovs"][input_indices[inp]]
202  if iov < input_iov:
203  print "Found input IOV boundary at run",input_iov,
204  print "for '"+inp+"' which is within 'TrackerAlignmentRcd'",
205  print "IOV starting with run", str(iov)+"."
206  print "Deriving an alignment with inconsistent IOV boundaries",
207  print "leads to wrong results."
208  print "Please check your input IOVs."
209  sys.exit(1)
210  elif iov == input_iov:
211  input_indices[inp] -= 1
212 
213  print "IOV consistency check successful."
214  print "-"*60
215 
216  return problematic_gt_inputs
217 
218 
219 # ------------------------------------------------------------------------------
220 # set up argument parser and config parser
221 
222 helpEpilog ='''Builds the config-templates from a universal config-template for each
223 dataset specified in .ini-file that is passed to this script.
224 Then calls mps_setup.pl for all datasets.'''
226  description='Setup the alignment as configured in the alignment_config file.',
227  epilog=helpEpilog)
228 # optional argmuent: verbose (toggles output of mps_setup)
229 parser.add_argument('-v', '--verbose', action='store_true',
230  help='display detailed output of mps_setup')
231 # optional argmuent: weight (new weights for additional merge job)
232 parser.add_argument('-w', '--weight', action='store_true',
233  help='create an additional mergejob with (possibly new) weights from .ini-config')
234 # positional argument: config file
235 parser.add_argument('alignmentConfig', action='store',
236  help='name of the .ini config file that specifies the datasets to be used')
237 # parse argument
238 args = parser.parse_args()
239 aligmentConfig = args.alignmentConfig
240 
241 # parse config file
242 config = ConfigParser.ConfigParser()
243 config.optionxform = str # default would give lowercase options -> not wanted
244 config.read(aligmentConfig)
245 
246 
247 
248 #------------------------------------------------------------------------------
249 # construct directories
250 
251 # set variables that are not too specific (millescript, pedescript, etc.)
252 mpsTemplates = os.path.join("src", "Alignment", "MillePedeAlignmentAlgorithm", "templates")
253 if checked_out_MPS()[0]:
254  mpsTemplates = os.path.join(os.environ["CMSSW_BASE"], mpsTemplates)
255 else:
256  mpsTemplates = os.path.join(os.environ["CMSSW_RELEASE_BASE"], mpsTemplates)
257 milleScript = os.path.join(mpsTemplates, "mps_runMille_template.sh")
258 pedeScript = os.path.join(mpsTemplates, "mps_runPede_rfcp_template.sh")
259 
260 # get working directory name
261 currentDir = os.getcwd()
262 mpsdirname = ''
263 match = re.search(re.compile('mpproduction\/mp(.+?)$', re.M|re.I),currentDir)
264 if match:
265  mpsdirname = 'mp'+match.group(1)
266 else:
267  print "Current location does not seem to be a MillePede campaign directory:",
268  print currentDir
269  sys.exit(1)
270 
271 # set directory on eos
272 mssDir = '/store/caf/user/'+os.environ['USER']+'/MPproduction/'+mpsdirname
273 
274 # create directory on eos if it doesn't exist already
275 eos = '/afs/cern.ch/project/eos/installation/cms/bin/eos.select'
276 os.system(eos+' mkdir -p '+mssDir)
277 
278 
279 
280 #------------------------------------------------------------------------------
281 # read general-section
282 generalOptions = {}
283 
284 # essential variables
285 for var in ["classInf","pedeMem","jobname", "FirstRunForStartGeometry"]:
286  try:
287  generalOptions[var] = config.get('general',var)
288  except ConfigParser.NoOptionError:
289  print "No", var, "found in [general] section. Please check ini-file."
290  raise SystemExit
291 
292 # check if datasetdir is given
293 generalOptions['datasetdir'] = ''
294 if config.has_option('general','datasetdir'):
295  generalOptions['datasetdir'] = config.get('general','datasetdir')
296  # add it to environment for later variable expansion:
297  os.environ["datasetdir"] = generalOptions['datasetdir']
298 else:
299  print "No datasetdir given in [general] section.",
300  print "Be sure to give a full path in inputFileList."
301 
302 # check for default options
303 for var in ['globaltag','configTemplate','json']:
304  try:
305  generalOptions[var] = config.get('general',var)
306  except ConfigParser.NoOptionError:
307  print 'No default', var, 'given in [general] section.'
308 
309 
310 
311 pedesettings = ([x.strip() for x in config.get("general", "pedesettings").split(",")]
312  if config.has_option("general", "pedesettings") else [None])
313 
314 weight_confs = get_weight_configs(config)
315 
316 
317 #------------------------------------------------------------------------------
318 # -w option: Get new weights from .ini and create additional mergejob with these
319 if args.weight:
320 
321  # do some basic checks
322  if not os.path.isdir("jobData"):
323  print "No jobData-folder found. Properly set up the alignment before using the -w option."
324  raise SystemExit
325  if not os.path.exists("mps.db"):
326  print "No mps.db found. Properly set up the alignment before using the -w option."
327  raise SystemExit
328 
329  # check if default configTemplate is given
330  try:
331  configTemplate = config.get('general','configTemplate')
332  except ConfigParser.NoOptionError:
333  print 'No default configTemplate given in [general] section.'
334  print 'When using -w, a default configTemplate is needed to build a merge-config.'
335  raise SystemExit
336 
337  # check if default globaltag is given
338  try:
339  globalTag = config.get('general','globaltag')
340  except ConfigParser.NoOptionError:
341  print "No default 'globaltag' given in [general] section."
342  print "When using -w, a default configTemplate is needed to build a merge-config."
343  raise SystemExit
344 
345  try:
346  first_run = config.get("general", "FirstRunForStartGeometry")
347  except ConfigParser.NoOptionError:
348  print "Missing mandatory option 'FirstRunForStartGeometry' in [general] section."
349  raise SystemExit
350 
351  for section in config.sections():
352  if section.startswith("dataset:"):
353  try:
354  collection = config.get(section, "collection")
355  break
356  except ConfigParser.NoOptionError:
357  print "Missing mandatory option 'collection' in section ["+section+"]."
358  raise SystemExit
359 
360  try:
361  with open(configTemplate,"r") as f:
362  tmpFile = f.read()
363  except IOError:
364  print "The config-template '"+configTemplate+"' cannot be found."
365  raise SystemExit
366 
367  tmpFile = re.sub('setupGlobaltag\s*\=\s*[\"\'](.*?)[\"\']',
368  'setupGlobaltag = \"'+globalTag+'\"',
369  tmpFile)
370  tmpFile = re.sub('setupCollection\s*\=\s*[\"\'](.*?)[\"\']',
371  'setupCollection = \"'+collection+'\"',
372  tmpFile)
373  tmpFile = re.sub(re.compile("setupRunStartGeometry\s*\=\s*.*$", re.M),
374  "setupRunStartGeometry = "+first_run,
375  tmpFile)
376 
377  thisCfgTemplate = "tmp.py"
378  with open(thisCfgTemplate, "w") as f: f.write(tmpFile)
379 
380  cms_process = mps_tools.get_process_object(thisCfgTemplate)
381 
382  overrideGT = create_input_db(cms_process, first_run)
383  with open(thisCfgTemplate, "a") as f: f.write(overrideGT)
384 
385  for setting in pedesettings:
386  print
387  print "="*60
388  if setting is None:
389  print "Creating pede job."
390  else:
391  print "Creating pede jobs using settings from '{0}'.".format(setting)
392  for weight_conf in weight_confs:
393  print "-"*60
394  # blank weights
395  os.system("mps_weight.pl -c > /dev/null")
396 
397  for name,weight in weight_conf:
398  os.system("mps_weight.pl -N "+name+" "+weight)
399 
400  # create new mergejob
401  os.system("mps_setupm.pl")
402 
403  # read mps.db to find directory of new mergejob
404  lib = mpslib.jobdatabase()
405  lib.read_db()
406 
407  # delete old merge-config
408  command = "rm -f jobData/"+lib.JOBDIR[-1]+"/alignment_merge.py"
409  print command
410  os.system(command)
411 
412  # create new merge-config
413  command = ("mps_merge.py -w "+thisCfgTemplate+" jobData/"+
414  lib.JOBDIR[-1]+"/alignment_merge.py jobData/"+
415  lib.JOBDIR[-1]+" "+str(lib.nJobs))
416  if setting is not None: command += " -a "+setting
417  print command
418  if args.verbose:
419  subprocess.call(command, stderr=subprocess.STDOUT, shell=True)
420  else:
421  with open(os.devnull, 'w') as FNULL:
422  subprocess.call(command, stdout=FNULL,
423  stderr=subprocess.STDOUT, shell=True)
424 
425  # remove temporary file
426  os.system("rm "+thisCfgTemplate)
427 
428  if overrideGT.strip() != "":
429  print "="*60
430  msg = ("Overriding global tag with single-IOV tags extracted from '{}' "
431  "for run number '{}'.".format(generalOptions["globaltag"],
432  first_run))
433  print msg
434  print "-"*60
435  print overrideGT
436 
437  sys.exit()
438 
439 
440 #------------------------------------------------------------------------------
441 # loop over dataset-sections
442 firstDataset = True
443 overrideGT = ""
444 for section in config.sections():
445  if 'general' in section:
446  continue
447  elif section.startswith("dataset:"):
448  datasetOptions={}
449  print "-"*60
450 
451  # set name from section-name
452  datasetOptions['name'] = section[8:]
453 
454  # extract essential variables
455  for var in ['inputFileList','collection']:
456  try:
457  datasetOptions[var] = config.get(section,var)
458  except ConfigParser.NoOptionError:
459  print 'No', var, 'found in', section+'. Please check ini-file.'
460  raise SystemExit
461 
462  # get globaltag and configTemplate. If none in section, try to get default from [general] section.
463  for var in ['configTemplate','globaltag']:
464  if config.has_option(section,var):
465  datasetOptions[var] = config.get(section,var)
466  else:
467  try:
468  datasetOptions[var] = generalOptions[var]
469  except KeyError:
470  print "No",var,"found in ["+section+"]",
471  print "and no default in [general] section."
472  raise SystemExit
473 
474  # extract non-essential options
475  datasetOptions['cosmicsZeroTesla'] = False
476  if config.has_option(section,'cosmicsZeroTesla'):
477  datasetOptions['cosmicsZeroTesla'] = config.getboolean(section,'cosmicsZeroTesla')
478 
479  datasetOptions['cosmicsDecoMode'] = False
480  if config.has_option(section,'cosmicsDecoMode'):
481  datasetOptions['cosmicsDecoMode'] = config.getboolean(section,'cosmicsDecoMode')
482 
483  datasetOptions['primaryWidth'] = -1.0
484  if config.has_option(section,'primaryWidth'):
485  datasetOptions['primaryWidth'] = config.getfloat(section,'primaryWidth')
486 
487  datasetOptions['json'] = ''
488  if config.has_option(section, 'json'):
489  datasetOptions['json'] = config.get(section,'json')
490  else:
491  try:
492  datasetOptions['json'] = generalOptions['json']
493  except KeyError:
494  print "No json given in either [general] or ["+section+"] sections.",
495  print "Proceeding without json-file."
496 
497 
498  # replace '${datasetdir}' and other variables in inputFileList-path
499  datasetOptions['inputFileList'] = os.path.expandvars(datasetOptions['inputFileList'])
500 
501  # replace variables in configTemplate-path, e.g. $CMSSW_BASE
502  datasetOptions['configTemplate'] = os.path.expandvars(datasetOptions['configTemplate'])
503 
504 
505  # Get number of jobs from lines in inputfilelist
506  datasetOptions['njobs'] = 0
507  try:
508  with open(datasetOptions['inputFileList'],'r') as filelist:
509  for line in filelist:
510  if 'CastorPool' in line:
511  continue
512  # ignore empty lines
513  if not line.strip()=='':
514  datasetOptions['njobs'] += 1
515  except IOError:
516  print 'Inputfilelist', datasetOptions['inputFileList'], 'does not exist.'
517  raise SystemExit
518  if datasetOptions['njobs'] == 0:
519  print 'Number of jobs is 0. There may be a problem with the inputfilelist:'
520  print datasetOptions['inputFileList']
521  raise SystemExit
522 
523  # Check if njobs gets overwritten in .ini-file
524  if config.has_option(section,'njobs'):
525  if config.getint(section,'njobs')<=datasetOptions['njobs']:
526  datasetOptions['njobs'] = config.getint(section,'njobs')
527  else:
528  print 'njobs is bigger than the default',datasetOptions['njobs'],'. Using default.'
529  else:
530  print 'No number of jobs specified. Using number of files in inputfilelist as the number of jobs.'
531 
532 
533  # Build config from template/Fill in variables
534  try:
535  with open(datasetOptions['configTemplate'],'r') as INFILE:
536  tmpFile = INFILE.read()
537  except IOError:
538  print 'The config-template called',datasetOptions['configTemplate'],'cannot be found.'
539  raise SystemExit
540 
541  tmpFile = re.sub('setupGlobaltag\s*\=\s*[\"\'](.*?)[\"\']',
542  'setupGlobaltag = \"'+datasetOptions['globaltag']+'\"',
543  tmpFile)
544  tmpFile = re.sub(re.compile("setupRunStartGeometry\s*\=\s*.*$", re.M),
545  "setupRunStartGeometry = "+
546  generalOptions["FirstRunForStartGeometry"], tmpFile)
547  tmpFile = re.sub('setupCollection\s*\=\s*[\"\'](.*?)[\"\']',
548  'setupCollection = \"'+datasetOptions['collection']+'\"',
549  tmpFile)
550  if datasetOptions['cosmicsZeroTesla']:
551  tmpFile = re.sub(re.compile('setupCosmicsZeroTesla\s*\=\s*.*$', re.M),
552  'setupCosmicsZeroTesla = True',
553  tmpFile)
554  if datasetOptions['cosmicsDecoMode']:
555  tmpFile = re.sub(re.compile('setupCosmicsDecoMode\s*\=\s*.*$', re.M),
556  'setupCosmicsDecoMode = True',
557  tmpFile)
558  if datasetOptions['primaryWidth'] > 0.0:
559  tmpFile = re.sub(re.compile('setupPrimaryWidth\s*\=\s*.*$', re.M),
560  'setupPrimaryWidth = '+str(datasetOptions['primaryWidth']),
561  tmpFile)
562  if datasetOptions['json'] != '':
563  tmpFile = re.sub(re.compile('setupJson\s*\=\s*.*$', re.M),
564  'setupJson = \"'+datasetOptions['json']+'\"',
565  tmpFile)
566 
567  thisCfgTemplate = 'tmp.py'
568  with open(thisCfgTemplate, 'w') as OUTFILE:
569  OUTFILE.write(tmpFile)
570 
571 
572  # Set mps_setup append option for datasets following the first one
573  append = ' -a'
574  if firstDataset:
575  append = ''
576  firstDataset = False
577  configTemplate = tmpFile
578  cms_process = mps_tools.get_process_object(thisCfgTemplate)
579  overrideGT = create_input_db(cms_process,
580  generalOptions["FirstRunForStartGeometry"])
581 
582  with open(thisCfgTemplate, "a") as f: f.write(overrideGT)
583 
584 
585  # create mps_setup command
586  command = 'mps_setup.pl -m%s -M %s -N %s %s %s %s %d %s %s %s cmscafuser:%s' % (
587  append,
588  generalOptions['pedeMem'],
589  datasetOptions['name'],
590  milleScript,
591  thisCfgTemplate,
592  datasetOptions['inputFileList'],
593  datasetOptions['njobs'],
594  generalOptions['classInf'],
595  generalOptions['jobname'],
596  pedeScript,
597  mssDir)
598  # Some output:
599  print 'Submitting dataset:', datasetOptions['name']
600  print 'Baseconfig: ', datasetOptions['configTemplate']
601  print 'Collection: ', datasetOptions['collection']
602  if datasetOptions["collection"] in ("ALCARECOTkAlCosmicsCTF0T",
603  "ALCARECOTkAlCosmicsInCollisions"):
604  print 'cosmicsDecoMode: ', datasetOptions['cosmicsDecoMode']
605  print 'cosmicsZeroTesla: ', datasetOptions['cosmicsZeroTesla']
606  print 'Globaltag: ', datasetOptions['globaltag']
607  print 'Number of jobs: ', datasetOptions['njobs']
608  print 'Inputfilelist: ', datasetOptions['inputFileList']
609  if datasetOptions['json'] != '':
610  print 'Jsonfile: ', datasetOptions['json']
611  print 'Pass to mps_setup: ', command
612 
613  # call the command and toggle verbose output
614  if args.verbose:
615  subprocess.call(command, stderr=subprocess.STDOUT, shell=True)
616  else:
617  with open(os.devnull, 'w') as FNULL:
618  subprocess.call(command, stdout=FNULL,
619  stderr=subprocess.STDOUT, shell=True)
620 
621  # remove temporary file
622  os.system("rm "+thisCfgTemplate)
623 
624 if firstDataset:
625  print "No dataset section defined in '{0}'".format(aligmentConfig)
626  print "At least one section '[dataset:<name>]' is required."
627  sys.exit(1)
628 
629 firstPedeConfig = True
630 for setting in pedesettings:
631  print
632  print "="*60
633  if setting is None:
634  print "Creating pede job."
635  else:
636  print "Creating pede jobs using settings from '{0}'.".format(setting)
637  for weight_conf in weight_confs:
638  print "-"*60
639  # blank weights
640  os.system("mps_weight.pl -c > /dev/null")
641 
642  for name,weight in weight_conf:
643  os.system("mps_weight.pl -N "+name+" "+weight)
644 
645  if firstPedeConfig:
646  firstPedeConfig = False
647  else:
648  # create new mergejob
649  os.system("mps_setupm.pl")
650 
651  # read mps.db to find directory of new mergejob
652  lib = mpslib.jobdatabase()
653  lib.read_db()
654 
655  # delete old merge-config
656  command = "rm -f jobData/"+lib.JOBDIR[-1]+"/alignment_merge.py"
657  print command
658  os.system(command)
659 
660  thisCfgTemplate = "tmp.py"
661  with open(thisCfgTemplate, "w") as f:
662  f.write(configTemplate+overrideGT)
663 
664  # create new merge-config
665  command = ("mps_merge.py -w "+thisCfgTemplate+" jobData/"+lib.JOBDIR[-1]+
666  "/alignment_merge.py jobData/"+lib.JOBDIR[-1]+" "+
667  str(lib.nJobs))
668  if setting is not None: command += " -a "+setting
669  print command
670  if args.verbose:
671  subprocess.call(command, stderr=subprocess.STDOUT, shell=True)
672  else:
673  with open(os.devnull, 'w') as FNULL:
674  subprocess.call(command, stdout=FNULL,
675  stderr=subprocess.STDOUT, shell=True)
676 
677  # remove temporary file
678  os.system("rm "+thisCfgTemplate)
679 
680 if overrideGT.strip() != "":
681  print "="*60
682  msg = ("Overriding global tag with single-IOV tags extracted from '{}' for "
683  "run number '{}'.".format(generalOptions["globaltag"],
684  generalOptions["FirstRunForStartGeometry"]))
685  print msg
686  print "-"*60
687  print overrideGT
def check_iov_definition(cms_process, first_run)
def checked_out_MPS()
Definition: helper.py:3
def create_input_db(cms_process, run_number)
Definition: mps_alisetup.py:78
def get_weight_configs(config)
Definition: mps_alisetup.py:26
double split
Definition: MVATrainer.cc:139