22 logging.debug(
str(args))
25 with open(args.cfgfile)
as cfgfile:
26 cfglines = cfgfile.read()
27 logging.debug(cfglines)
30 job_file =
'cfg_{type}_{run}.py'.
format(type=args.analyzer, run=args.since)
31 output_db =
'{type}_{run}.db'.
format(type=args.analyzer, run=args.since)
32 if os.path.exists(output_db):
33 logging.info(
'Output sqlite file %s already exists! Deleting...' % output_db)
35 hashmap_db =
'hashmap_{type}_{run}.db'.
format(type=args.analyzer, run=args.since)
36 if os.path.exists(hashmap_db):
37 logging.info(
'Hashmap sqlite file %s already exists! Deleting...' % hashmap_db)
39 replace_dict = {
'_CFGLINES_' : cfglines.replace(
'\\',
''),
40 '_ANALYZER_' : args.analyzer,
41 '_USEANALYSIS_':
'False',
42 '_CONDDB_' : args.condDbRead,
43 '_DBFILE_' :
'sqlite:///%s' % output_db,
44 '_TARGETTAG_': args.inputTag,
45 '_RUNNUMBER_': args.since,
46 '_HASHMAPDB_': args.hashmapDb,
47 '_MAPDBFILE_':
'sqlite:///%s' % hashmap_db,
51 if args.analyzer ==
'SiStripO2OApvGain':
55 with open(args.skiplistFile)
as skipfile:
56 skipped = skipfile.read()
58 logging.warning(
'Skipped module list not provided! No module will be skipped...')
60 if args.whitelistFile:
61 with open(args.whitelistFile)
as wfile:
62 whitelisted = wfile.read()
64 logging.warning(
'Module whitelist not provided!')
65 replace_dict[
'_USEANALYSIS_'] =
'True' 66 replace_dict[
'_SKIPPED_'] = skipped
67 replace_dict[
'_WHITELISTED_'] = whitelisted
68 replace_dict[
'_HASHMAPDB_'] =
'' 69 replace_dict[
'_MAPDBFILE_'] =
'' 72 for basedir
in os.environ[
'CMSSW_SEARCH_PATH'].
split(
':'):
73 templatefile = os.path.join(basedir, cfg_template)
74 if os.path.exists(templatefile):
75 logging.info(
'Use template config file %s' % templatefile)
77 config = helper.insert_to_file(templatefile, job_file, replace_dict)
78 logging.info(
'Start running O2O...')
79 logging.debug(
' ... config:\n%s\n' % config)
82 command =
'cmsRun %s' % job_file
83 pipe = subprocess.Popen(command, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
84 atexit.register(partial(helper.kill_subproc_noexcept, pipe))
85 out = pipe.communicate()[0]
86 logging.info(
'\n%s\n' % out)
87 logging.info(
'@@@CMSSW job return code = %d@@@' % pipe.returncode)
88 if pipe.returncode != 0:
89 raise RuntimeError(
'O2O job FAILED!')
93 logging.info(
'Will not run uploading as requested!')
96 f = helper.upload_payload
98 f = helper.copy_payload
99 f(dbFile=output_db, inputTag=args.inputTag, destTags=args.destTags, destDb=args.destDb, since=args.since,
100 userText=
'{type}, run: {run}'.
format(type=args.analyzer, run=args.since))
103 if args.analyzer ==
'SiStripO2OApvGain':
104 logging.info(
'Writting bookkeeping info to database.')
105 dbmgr = DbManagerGain(args.bookkeeping_db)
106 dbmgr.update_gain_logs(args.since, job_file)
108 logging.info(
'Updating config-to-payload hash map to database.')
109 dbmgr = DbManagerDAQ(args.bookkeeping_db)
110 dbmgr.update_hashmap(hashmap_db)
115 os.remove(output_db.replace(
'.db',
'.txt'))
116 os.remove(hashmap_db)