3 from __future__
import print_function
4 import os,time,sys,shutil,glob
6 from datetime
import datetime
8 from email.MIMEText
import MIMEText
12 s=smtplib.SMTP(
"localhost")
14 body=
"File merge failed by unknown reason for run"+run
16 msg[
'Subject'] =
"File merge failed."
17 msg[
'From'] = ServerMail
18 msg[
'To'] = EmailAddress
19 s.sendmail(ServerMail,tolist,msg.as_string())
29 hist = f.FindObjectAny(
"reportSummaryContents")
31 if (hist ==
None and rootfile.rfind(
'HcalTiming') == -1):
42 TempTag = TimeTag +
'-tmp'
43 if not os.path.exists(TimeTag):
44 os.system(
'touch -t 01010000 '+ TimeTag)
50 TAG = os.stat(TimeTag).st_mtime
51 for dir, subdirs, files
in os.walk(DIR):
52 paths = [
"%s/%s" % (dir, x)
for x
in files]
53 for f
in [x
for x
in paths
if re.search(
r'/DQM_.*_R[0-9]{9}\.root$', x)]:
54 if os.stat(f).st_mtime > TAG
and f.index(
"DQM_Reference") < 0:
55 NEW.get(f[-14:-5], []).
append(f)
59 print(
'Have not found new files...')
62 os.system(
"ls -l %s" % TimeTag)
63 os.system(
'touch '+ TempTag)
65 print(
'Found %d new file(s).' % NFOUND)
70 for (run, files)
in NEW.items():
71 runnr =
"%09d" % long(run)
72 destdir =
"%s/%s/%s/%s" % (FILEDIR, runnr[0:3], runnr[3:6], runnr[6:9])
76 destfile =
"%s/DQM_V%04d_R%s.root" % (destdir, version, runnr)
77 if not os.path.exists(destfile):
break
78 oldfiles.append(destfile)
81 if not os.path.exists(destdir):
84 logfile =
"%s.log" % destfile[:-4]
85 tmpdestfile =
"%s.tmp" % destfile
87 print(
'Run %s is being merged...' % run)
89 if os.path.exists(tmpdestfile):
90 os.remove(tmpdestfile)
94 LOGFILE =
file(logfile,
'a')
95 LOGFILE.write(os.popen(
'DQMMergeFile %s %s' % (tmpdestfile,
" ".
join(files))).
read())
96 if not os.path.exists(tmpdestfile):
97 print(
'Failed merging files for run %s. Try again after two minutes' % run)
103 os.rename(tmpdestfile, destfile)
105 allOldFiles.extend(oldfiles)
106 newFiles.append(destfile)
109 if os.path.exists(TMPDB):
112 if os.path.exists(DB):
115 logfile.write(
'*** INITIALISE DATABASE ***\n')
116 logfile.write(os.popen(
'visDQMRegisterFile %s "/Global/Online/ALL" "Global run"' % TMPDB).
read())
118 logfile.write(
'*** UNREGISTER %d OLD FILES ***\n' % len(allOldFiles))
119 while len(allOldFiles) > 0:
120 (slice, rest) = (allOldFiles[0:50], allOldFiles[50:])
121 logfile.write(os.popen(
'visDQMUnregisterFile %s %s' % (tmpdb,
" ".
join(slice))).
read())
126 for file
in newFiles:
127 print(
'Registering %s' % file)
128 logfile.write(
'*** REGISTER FILE %s ***\n' % file)
129 logfile.write(os.popen(
'visDQMRegisterFile %s "/Global/Online/ALL" "Global run" %s' % (TMPDB, file)).
read())
130 print(
'%s registered' % file)
134 os.rename(TempTag, TimeTag)
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 ...
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
static std::string join(char **cmd)