CMS 3D CMS Logo

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

Functions

def main
 
def run
 
def summary
 

Variables

string logDirVar = 'O2O_LOG_FOLDER'
 

Function Documentation

def o2oRun_SiStripDAQ.main ( )

Definition at line 96 of file o2oRun_SiStripDAQ.py.

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

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

Definition at line 21 of file o2oRun_SiStripDAQ.py.

References edm.decode().

Referenced by main().

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

Definition at line 74 of file o2oRun_SiStripDAQ.py.

Referenced by main().

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

Variable Documentation

string o2oRun_SiStripDAQ.logDirVar = 'O2O_LOG_FOLDER'

Definition at line 19 of file o2oRun_SiStripDAQ.py.