3 from __future__
import print_function
4 import os,time,sys,shutil,glob
6 from datetime
import datetime
8 from email.MIMEText
import MIMEText
13 s=smtplib.SMTP(
"localhost")
15 body=
"File merge failed by unknown reason for run"+run
17 msg[
'Subject'] =
"File merge failed."
18 msg[
'From'] = ServerMail
19 msg[
'To'] = EmailAddress
20 s.sendmail(ServerMail,tolist,msg.as_string())
30 hist = f.FindObjectAny(
"reportSummaryContents")
32 if (hist ==
None and rootfile.rfind(
'HcalTiming') == -1):
43 TempTag = TimeTag +
'-tmp'
44 if not os.path.exists(TimeTag):
45 os.system(
'touch -t 01010000 '+ TimeTag)
51 TAG = os.stat(TimeTag).st_mtime
52 for dir, subdirs, files
in os.walk(DIR):
53 paths = [
"%s/%s" % (dir, x)
for x
in files]
54 for f
in [x
for x
in paths
if re.search(
r'/DQM_.*_R[0-9]{9}\.root$', x)]:
55 if os.stat(f).st_mtime > TAG
and f.index(
"DQM_Reference") < 0:
56 NEW.get(f[-14:-5], []).
append(f)
60 print(
'Have not found new files...')
63 os.system(
"ls -l %s" % TimeTag)
64 os.system(
'touch '+ TempTag)
66 print(
'Found %d new file(s).' % NFOUND)
71 for (run, files)
in six.iteritems(NEW):
72 runnr =
"%09d" % long(run)
73 destdir =
"%s/%s/%s/%s" % (FILEDIR, runnr[0:3], runnr[3:6], runnr[6:9])
77 destfile =
"%s/DQM_V%04d_R%s.root" % (destdir, version, runnr)
78 if not os.path.exists(destfile):
break
79 oldfiles.append(destfile)
82 if not os.path.exists(destdir):
85 logfile =
"%s.log" % destfile[:-4]
86 tmpdestfile =
"%s.tmp" % destfile
88 print(
'Run %s is being merged...' % run)
90 if os.path.exists(tmpdestfile):
91 os.remove(tmpdestfile)
95 LOGFILE =
file(logfile,
'a')
96 LOGFILE.write(os.popen(
'DQMMergeFile %s %s' % (tmpdestfile,
" ".
join(files))).
read())
97 if not os.path.exists(tmpdestfile):
98 print(
'Failed merging files for run %s. Try again after two minutes' % run)
104 os.rename(tmpdestfile, destfile)
106 allOldFiles.extend(oldfiles)
107 newFiles.append(destfile)
110 if os.path.exists(TMPDB):
113 if os.path.exists(DB):
116 logfile.write(
'*** INITIALISE DATABASE ***\n')
117 logfile.write(os.popen(
'visDQMRegisterFile %s "/Global/Online/ALL" "Global run"' % TMPDB).
read())
119 logfile.write(
'*** UNREGISTER %d OLD FILES ***\n' % len(allOldFiles))
120 while len(allOldFiles) > 0:
121 (slice, rest) = (allOldFiles[0:50], allOldFiles[50:])
122 logfile.write(os.popen(
'visDQMUnregisterFile %s %s' % (tmpdb,
" ".
join(slice))).
read())
127 for file
in newFiles:
128 print(
'Registering %s' % file)
129 logfile.write(
'*** REGISTER FILE %s ***\n' % file)
130 logfile.write(os.popen(
'visDQMRegisterFile %s "/Global/Online/ALL" "Global run" %s' % (TMPDB, file)).
read())
131 print(
'%s registered' % file)
135 os.rename(TempTag, TimeTag)