3 import os, time, sys, shutil, glob, smtplib, re
4 from datetime
import datetime
5 from email.MIMEText
import MIMEText
7 sys.stdout = os.fdopen(sys.stdout.fileno(),
'w', 0)
9 DIR =
'/data/dqm/dropbox'
10 DB =
'/home/dqm/dqm.db'
11 TMPDB =
'/home/dqm/dqm.db.tmp'
12 FILEDIR =
'/data/dqm/merged'
13 DONEDIR =
'/data/dqm/done'
18 YourMail =
"lilopera@cern.ch"
19 ServerMail =
"dqm@srv-C2D05-19.cms"
22 s=smtplib.SMTP(
"localhost")
23 tolist=[EmailAddress,
"lat@cern.ch"]
24 body=
"File merge failed by unknown reason for run"+run
26 msg[
'Subject'] =
"File merge failed."
27 msg[
'From'] = ServerMail
28 msg[
'To'] = EmailAddress
29 s.sendmail(ServerMail,tolist,msg.as_string())
39 hist = f.FindObjectAny(
"reportSummaryContents")
41 if (hist ==
None and rootfile.rfind(
'HcalTiming') == -1):
55 for dir, subdirs, files
in os.walk(DIR):
57 if not f.startswith(
"DQM_Reference")
and re.match(
r'^DQM_.*_R[0-9]{9}\.root$', f):
59 donefile =
"%s/%s/%s/%s" % (DONEDIR, runnr[0:3], runnr[3:6], f)
60 f =
"%s/%s" % (dir, f)
61 if os.path.exists(donefile)
and os.stat(donefile).st_size == os.stat(f).st_size:
62 print "WARNING: %s was already processed but re-appeared" % f
65 NEW.setdefault(runnr, []).
append(f)
69 print '%s: found %d new files in %d runs.' % (datetime.now(), NFOUND, len(NEW))
73 for run
in sorted(NEW.keys())[::-1]:
79 runnr =
"%09d" % long(run)
80 destdir =
"%s/%s/%s" % (FILEDIR, runnr[0:3], runnr[3:6])
81 donedir =
"%s/%s/%s" % (DONEDIR, runnr[0:3], runnr[3:6])
82 oldfiles = sorted(glob.glob(
"%s/DQM_V????_R%s.root" % (destdir, runnr)))[::-1]
84 version = int(oldfiles[0][-20:-16]) + 1
85 files.append(oldfiles[0])
89 if not os.path.exists(destdir):
91 if not os.path.exists(donedir):
94 destfile =
"%s/DQM_V%04d_R%s.root" % (destdir, version, runnr)
95 logfile =
"%s.log" % destfile[:-5]
96 tmpdestfile =
"%s.tmp" % destfile
98 print 'Merging run %s to %s (adding %s to %s)' % (run, destfile, files, oldfiles)
99 LOGFILE = open(logfile,
'a')
100 LOGFILE.write(os.popen(
'DQMMergeFile %s %s' % (tmpdestfile,
" ".
join(files))).
read())
102 if not os.path.exists(tmpdestfile):
103 print 'Failed merging files for run %s. Will try again later.' % run
107 os.rename(tmpdestfile, destfile)
109 os.rename(f,
"%s/%s" % (donedir, f.rsplit(
'/', 1)[1]))
111 allOldFiles.extend(oldfiles)
112 newFiles.append((long(run), destfile))
114 if os.path.exists(TMPDB):
117 if os.path.exists(DB):
120 os.system(
'set -x; visDQMRegisterFile %s "/Global/Online/ALL" "Global run"' % TMPDB)
122 if len(allOldFiles) > 0:
123 os.system(
'set -x; visDQMUnregisterFile %s %s' % (TMPDB,
" ".
join(allOldFiles)))
125 existing = [long(x)
for x
in os.popen(
"sqlite3 %s 'select distinct runnr from t_data'" % TMPDB).
read().
split()]
126 for runnr, file
in newFiles:
127 print 'Registering %s for run %d' % (file, runnr)
128 older = sorted([x
for x
in existing
if x < runnr])
129 newer = sorted([x
for x
in existing
if x > runnr])
130 if len(newer) > MAX_TOTAL_RUNS:
131 print "Too many newer runs (%d), not registering %s for run %d" % (len(newer), file, runnr)
134 if len(older) > MAX_TOTAL_RUNS:
135 print "Too many older runs (%d), pruning data for oldest run %d" % (len(older), older[0])
136 os.system(
r"set -x; sqlite3 %s 'delete from t_data where runnr = %d'" % (TMPDB, older[0]))
137 os.system(
r"set -x; sqlite3 %s 'delete from t_files where name like '\''%%R%09d.root'\'" % (TMPDB, older[0]))
138 os.system(
r"set -x; sqlite3 %s 'vacuum'" % TMPDB)
139 existing.remove(older[0])
141 os.system(
'set -x; visDQMRegisterFile %s "/Global/Online/ALL" "Global run" %s' % (TMPDB, file))
142 existing.append(runnr)
146 if NRUNS <= MAX_RUNS:
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
static std::string join(char **cmd)