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