CMS 3D CMS Logo

Functions
o2oRun_SiStripDAQ Namespace Reference

Functions

def main ()
 
def run (args)
 
def summary (args, is_ok, status, logfile)
 

Detailed Description

Main Script to run all SiStrip DAQ O2Os at the same time.
@author: Huilin Qu

Function Documentation

def o2oRun_SiStripDAQ.main ( )

Definition at line 94 of file o2oRun_SiStripDAQ.py.

References run(), split, harvestTrackValidationPlots.str, and summary().

94 def main():
95  parser = argparse.ArgumentParser(description='Run all SiStrip DAQ O2Os at the same time.')
96  parser.add_argument('since', metavar='SINCE', type=str, help='Run number.')
97  parser.add_argument('cfgfile', metavar='CFGLINES', help='File containing configuration lines.')
98  parser.add_argument('--skiplistFile', default='', help='File containing the devices to be skipped in G1 O2O.')
99 
100  parser.add_argument('--analyzers',
101  default='SiStripO2OBadStrip,SiStripO2OFedCabling,SiStripO2OLatency,SiStripO2ONoises,SiStripO2OPedestals,SiStripO2OThreshold',
102  help='Which EDAnalyzers to run.')
103  parser.add_argument('--mail-from', default='trk.o2o@cern.ch', help='Account to send email notification.')
104  parser.add_argument('--mail-to', default='cms-tracker-o2o-notification@cern.ch', help='List of O2O notification recipients.')
105  parser.add_argument('--mail-log-to', default='trk.o2o@cern.ch', help='List of O2O log recipients.')
106  parser.add_argument('--db', default='pro', help='The database for o2o job management: pro ( for prod ) or dev ( for prep ). Default: %(default)s.')
107  parser.add_argument('--debug', action="store_true", default=False, help='Switch on debug mode. Default: %(default)s.')
108 
109  args = parser.parse_args()
110  if args.debug:
111  args.mail_to = args.mail_log_to
112 
113  args.analyzers = args.analyzers.strip().split(',')
114  args.mail_to = args.mail_to.strip().split(',')
115  args.mail_log_to = args.mail_log_to.strip().split(',')
116 
117  # Should NOT use logging before it's set up
118  try:
119  logdir = os.environ[logDirVar] if logDirVar in os.environ else '/tmp'
120  if not os.path.exists(logdir):
121  os.makedirs(logdir)
122  logfile = os.path.join(logdir, 'SiStripsO2O_Run%s.log' % str(args.since))
123  loglevel = logging.DEBUG if args.debug else logging.INFO
124  helper.configLogger(logfile, loglevel)
125  except Exception:
126  # in case we failed before logging is set up
127  # print the error, send an email, and exit
128  helper.send_mail('O2O Failure, IOV: %s' % args.since, traceback.format_exc(), args.mail_to, args.mail_from)
129  raise
130 
131  try:
132  is_ok, status = run(args)
133  summary(args, is_ok, status, logfile)
134  except Exception:
135  # in case we failed before logging is set up
136  # print the error, send an email, and exit
137  helper.send_mail('O2O Failure, IOV: %s' % args.since, traceback.format_exc(), args.mail_to, args.mail_from)
138  raise
139 
140  if not is_ok:
141  return ' --- O2O FAILED! ---'
142 
def summary(args, is_ok, status, logfile)
double split
Definition: MVATrainer.cc:139
def o2oRun_SiStripDAQ.run (   args)

Definition at line 21 of file o2oRun_SiStripDAQ.py.

Referenced by main().

21 def run(args):
22  logging.debug(args)
23 
24  is_ok = True
25  status = {}
26  processes = {}
27 
28  for analyzer in args.analyzers:
29  o2ocmd = 'SiStripDAQPopCon.py {analyzer} {since} {cfgfile}'.format(
30  analyzer=analyzer, since=args.since, cfgfile=args.cfgfile)
31  o2ocmd += ' --destTags {destTags}'
32  o2ocmd += ' --destDb {destDb}'
33  o2ocmd += ' --inputTag {inputTag}'
34  o2ocmd += ' --condDbRead {condDbRead}'
35  o2ocmd += ' --hashmapDb {hashmapDb}'
36  if args.skiplistFile:
37  o2ocmd += ' --skiplistFile %s' % args.skiplistFile
38  if args.debug:
39  o2ocmd += ' --debug'
40 
41  jobname = analyzer.replace('O2O', '')
42  cmd = 'o2o --db {db} -v run -n {jobname} "{o2ocmd}"'.format(db=args.db, jobname=jobname, o2ocmd=o2ocmd)
43  logging.info('Start running command:\n %s' % cmd)
44 
45  processes[jobname] = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
46  atexit.register(partial(helper.kill_subproc_noexcept, processes[jobname]))
47 
48  for jobname in processes:
49  status[jobname] = {'job':None, 'upload':None, 'fast':None, 'changed':None}
50  p = processes[jobname]
51  log = p.communicate()[0]
52  logging.debug('=== log from o2o run ===\n%s' % log)
53  if p.returncode == 0:
54  logging.info('Job for %s finished successfully!' % jobname)
55  status[jobname]['job'] = True
56  status[jobname]['upload'] = True
57  for line in log.split('\n'):
58  if '@@@' not in line:
59  continue
60  if 'FastO2O' in line:
61  status[jobname]['fast'] = ('true' in line)
62  if 'PayloadChange' in line:
63  status[jobname]['changed'] = ('true' in line)
64  else:
65  logging.error('Job %s FAILED!' % jobname)
66  status[jobname]['job'] = '@@@CMSSW job return code = 0@@@' in log
67  status[jobname]['upload'] = '@@@Upload return code = 0@@@' in log
68  is_ok = False
69 
70  return is_ok, status
71 
def o2oRun_SiStripDAQ.summary (   args,
  is_ok,
  status,
  logfile 
)

Definition at line 72 of file o2oRun_SiStripDAQ.py.

Referenced by main().

72 def summary(args, is_ok, status, logfile):
73  summary = json.dumps(status, sort_keys=True, indent=2)
74  if is_ok:
75  logging.info('O2O finished successfully! Summary: %s' % summary)
76  else:
77  logging.error('O2O FAILED! Summary: %s' % summary)
78 
79  debugLabel = '[TEST] ' if args.debug else ''
80 
81  # send the summary email
82  helper.send_mail(subject='%sNew O2O, IOV: %s' % (debugLabel, args.since),
83  message=summary,
84  send_to=args.mail_to,
85  send_from=args.mail_from)
86  # send the detailed log
87  with open(logfile, 'rb') as log:
88  helper.send_mail(subject='%sNew O2O Log, IOV: %s' % (debugLabel, args.since),
89  message=log.read(),
90  send_to=args.mail_log_to,
91  send_from=args.mail_from)
92 
93 
def summary(args, is_ok, status, logfile)