CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
SiStripDCSPopCon Namespace Reference

Functions

def main
 
def runjob
 

Variables

string cfg_file = 'CondTools/SiStrip/python/SiStripDCS_popcon.py'
 
string jobDirVar = 'JOBDIR'
 

Function Documentation

def SiStripDCSPopCon.main ( )

Definition at line 68 of file SiStripDCSPopCon.py.

References runjob(), submitPVValidationJobs.split(), and str.

68 
69 def main():
70  parser = argparse.ArgumentParser(description='Run a single O2O job for SiStrip DCS and upload the payloads to condition database.')
71  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.')
72  parser.add_argument('--destTags', required=True, help='Destination tag name(s) for upload. Use comma to separate multiple values.')
73  parser.add_argument('--sourceDb', required=True, help='Connection string for the source database.')
74  parser.add_argument('--destDb', required=True, help='Destination DB to upload.')
75  parser.add_argument('--inputTag', required=True, help='Tag name to be used in the sqlite file.')
76  parser.add_argument('--condDbRead', default='oracle://cms_orcon_adg/CMS_CONDITIONS', help='Connection string for the DB from which the fast O2O retrives payloads.')
77 
78  parser.add_argument('--no-upload', action="store_true", default=False, help='Do not upload payload. Default: %(default)s.')
79  parser.add_argument('--use-uploader', action="store_true", default=False, help='Use conditionUploader instead of conddb copy. Default: %(default)s.')
80  parser.add_argument('--debug', action="store_true", default=False, help='Switch on debug mode. Default: %(default)s.')
81  args = parser.parse_args()
82 
83  loglevel = logging.INFO
84  if args.debug:
85  loglevel = logging.DEBUG
86  logging.basicConfig(level=loglevel, format='[%(asctime)s] %(levelname)s: %(message)s')
87 
88  args.destTags = args.destTags.strip().split(',')
89 
90  logging.info('Running DCS O2O with %s hour(s) delay on machine [%s]' % (str(args.delay), socket.gethostname()))
91 
92  try:
93  jobdirbase = os.environ[jobDirVar]
94  except KeyError:
95  jobdirbase = '/tmp'
96  logging.warning('%s not set in env, will use %s' % (jobDirVar, jobdirbase))
97 
98 
99  # change to O2O working directory
100  jobdir = os.path.join(jobdirbase, '{delay}hourDelay'.format(delay=args.delay))
101  if not os.path.exists(jobdir):
102  os.makedirs(jobdir)
103  os.chdir(jobdir)
104  logging.info('Running O2O in %s' % jobdir)
105 
106  # run job and upload
107  runjob(args)
108 
109  logging.info('Done!')
110 
111 
#define str(s)
def SiStripDCSPopCon.runjob (   args)

Definition at line 18 of file SiStripDCSPopCon.py.

References validate-o2o-wbm.f, submitPVValidationJobs.split(), and str.

Referenced by main().

18 
19 def runjob(args):
20  if args.debug:
21  logging.debug(str(args))
22 
23  # find cfg file
24  for basedir in os.environ['CMSSW_SEARCH_PATH'].split(':'):
25  cfg = os.path.join(basedir, cfg_file)
26  if os.path.exists(cfg):
27  logging.info('Use config file %s' % cfg)
28  break
29 
30  output_db = 'SiStripDetVOff_{delay}.db'.format(delay=args.delay)
31  if os.path.exists(output_db):
32  logging.info('Output sqlite file %s already exists! Deleting...' % output_db)
33  os.remove(output_db)
34 
35  # run cmssw job: raise error if failed
36  command = 'cmsRun {cfg} delay={delay} destinationConnection={destFile} sourceConnection={sourceDb} conddbConnection={conddb} tag={tag}'.format(
37  cfg=cfg, delay=args.delay, destFile='sqlite:///%s' % output_db, sourceDb=args.sourceDb, conddb=args.condDbRead, tag=args.inputTag)
38  pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
39  atexit.register(partial(helper.kill_subproc_noexcept, pipe))
40  out = pipe.communicate()[0]
41  logging.info('\n%s\n' % out)
42  logging.info('@@@CMSSW job return code = %d@@@' % pipe.returncode)
43  if pipe.returncode != 0:
44  raise RuntimeError('O2O job FAILED!')
45 
46  # upload: raise error if failed
47  if args.no_upload:
48  logging.info('Will not run uploading as requested!')
49  return
50 
51  if not helper.exists_iov(output_db, args.inputTag):
52  logging.info('No IOV exists in the SQLite file. Will skip upload!')
53  return
54 
55  if args.use_uploader:
56  f = helper.upload_payload
57  else:
58  f = helper.copy_payload
59  f(dbFile=output_db, inputTag=args.inputTag, destTags=args.destTags, destDb=args.destDb, since=None,
60  userText='SiStripDCS {delay} hour delay'.format(delay=args.delay))
61 
62  # clean up
63  try:
64  os.remove(output_db)
65  os.remove(output_db.replace('.db', '.txt'))
66  except OSError:
67  pass
#define str(s)

Variable Documentation

string SiStripDCSPopCon.cfg_file = 'CondTools/SiStrip/python/SiStripDCS_popcon.py'

Definition at line 16 of file SiStripDCSPopCon.py.

string SiStripDCSPopCon.jobDirVar = 'JOBDIR'

Definition at line 15 of file SiStripDCSPopCon.py.