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