2 '''Script that runs SiStrip DCS O2O. 12 from functools
import partial
13 import CondTools.SiStrip.o2o_helper
as helper
16 cfg_file =
'CondTools/SiStrip/python/SiStripDCS_popcon.py' 20 logging.debug(
str(args))
23 for basedir
in os.environ[
'CMSSW_SEARCH_PATH'].
split(
':'):
24 cfg = os.path.join(basedir, cfg_file)
25 if os.path.exists(cfg):
26 logging.info(
'Use config file %s' % cfg)
29 output_db =
'SiStripDetVOff_{delay}.db'.
format(delay=args.delay)
30 if os.path.exists(output_db):
31 logging.info(
'Output sqlite file %s already exists! Deleting...' % output_db)
35 command =
'cmsRun {cfg} delay={delay} destinationConnection={destFile} conddbConnection={conddb} tag={tag}'.
format(
36 cfg=cfg, delay=args.delay, destFile=
'sqlite:///%s' % output_db, conddb=args.condDbRead, tag=args.inputTag)
37 pipe = subprocess.Popen(command, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
38 atexit.register(partial(helper.kill_subproc_noexcept, pipe))
39 out = pipe.communicate()[0]
40 logging.info(
'\n%s\n' % out)
41 logging.info(
'@@@CMSSW job return code = %d@@@' % pipe.returncode)
42 if pipe.returncode != 0:
43 raise RuntimeError(
'O2O job FAILED!')
47 logging.info(
'Will not run uploading as requested!')
50 if not helper.exists_iov(output_db, args.inputTag):
51 logging.info(
'No IOV exists in the SQLite file. Will skip upload!')
55 f = helper.upload_payload
57 f = helper.copy_payload
58 f(dbFile=output_db, inputTag=args.inputTag, destTags=args.destTags, destDb=args.destDb, since=
None,
59 userText=
'SiStripDCS {delay} hour delay'.
format(delay=args.delay))
64 os.remove(output_db.replace(
'.db',
'.txt'))
69 parser =
argparse.ArgumentParser(description=
'Run a single O2O job for SiStrip DCS and upload the payloads to condition database.')
70 parser.add_argument(
'--delay', required=
True, help=
'Time delay (in hours) for the O2O. The O2O then queries the PVSS DB from last IOV until (current hour - delay), ignoring minutes and seconds.')
71 parser.add_argument(
'--destTags', required=
True, help=
'Destination tag name(s) for upload. Use comma to separate multiple values.')
72 parser.add_argument(
'--destDb', required=
True, help=
'Destination DB to upload.')
73 parser.add_argument(
'--inputTag', required=
True, help=
'Tag name to be used in the sqlite file.')
74 parser.add_argument(
'--condDbRead', default=
'oracle://cms_orcon_adg/CMS_CONDITIONS', help=
'Connection string for the DB from which the fast O2O retrives payloads.')
76 parser.add_argument(
'--no-upload', action=
"store_true", default=
False, help=
'Do not upload payload. Default: %(default)s.')
77 parser.add_argument(
'--use-uploader', action=
"store_true", default=
False, help=
'Use conditionUploader instead of conddb copy. Default: %(default)s.')
78 parser.add_argument(
'--debug', action=
"store_true", default=
False, help=
'Switch on debug mode. Default: %(default)s.')
79 args = parser.parse_args()
81 loglevel = logging.INFO
83 loglevel = logging.DEBUG
84 logging.basicConfig(level=loglevel, format=
'[%(asctime)s] %(levelname)s: %(message)s')
86 args.destTags = args.destTags.strip().
split(
',')
88 logging.info(
'Running DCS O2O with %s hour(s) delay on machine [%s]' % (
str(args.delay), socket.gethostname()))
91 jobdirbase = os.environ[jobDirVar]
94 logging.warning(
'%s not set in env, will use %s' % (jobDirVar, jobdirbase))
98 jobdir = os.path.join(jobdirbase,
'{delay}hourDelay'.
format(delay=args.delay))
99 if not os.path.exists(jobdir):
102 logging.info(
'Running O2O in %s' % jobdir)
107 logging.info(
'Done!')
111 if __name__ ==
'__main__':