1 |
rovere |
1.1 |
import re, os, popen2, stat, uuid
|
2 |
|
|
|
3 |
|
|
class IOV_Wrapper:
|
4 |
|
|
""" A simple ad-hoc interface to cmscond_list_iov command line tool"""
|
5 |
|
|
main_db = "cms_orcoff_prep"
|
6 |
rovere |
1.2 |
table_name = 'CMS_COND_34X_DQM'
|
7 |
rovere |
1.1 |
verbose = False
|
8 |
|
|
release = "/home/apache_CMSSW/CMSSW_3_2_7/src/"
|
9 |
|
|
tags = []
|
10 |
|
|
iovs = {}
|
11 |
|
|
if os.getenv('USER') :
|
12 |
|
|
user = os.getenv('USER')
|
13 |
|
|
else :
|
14 |
|
|
user = 'apache'
|
15 |
|
|
filename = '/tmp/tmp' + uuid.uuid4().hex + '.sh'
|
16 |
|
|
passwdfile = '/home/apache_CMSSW/conddb/'
|
17 |
|
|
|
18 |
|
|
def __init__(self, databaseName, table_name, verbose=False):
|
19 |
|
|
self.main_db = databaseName
|
20 |
|
|
self.table_name = table_name
|
21 |
|
|
self.verbose = verbose
|
22 |
|
|
self.tags = []
|
23 |
|
|
self.iovs = {}
|
24 |
|
|
|
25 |
|
|
def clean(self):
|
26 |
|
|
if os.path.exists(self.filename):
|
27 |
|
|
os.remove(self.filename)
|
28 |
|
|
|
29 |
|
|
def loadTags(self):
|
30 |
|
|
f = open(self.filename, 'w')
|
31 |
|
|
command = "export PATH=/afs/cern.ch/cms/sw/common/:$PATH \ncd " + self.release + " \neval `/afs/cern.ch/cms/sw/common/scramv1 runtime -sh` \ncmscond_list_iov -c oracle://" + self.main_db + "/" + self.table_name + " -P " + self.passwdfile
|
32 |
|
|
f.write("#!/bin/sh\n")
|
33 |
|
|
f.write(command)
|
34 |
|
|
f.close()
|
35 |
|
|
os.chmod(self.filename, stat.S_IRWXU|stat.S_IRWXG|stat.S_IRWXO)
|
36 |
|
|
if self.verbose :
|
37 |
|
|
print command
|
38 |
|
|
r, w, e = popen2.popen3(self.filename)
|
39 |
|
|
for line in r:
|
40 |
|
|
self.tags.append(re.sub('\n', '', line))
|
41 |
|
|
if self.verbose:
|
42 |
|
|
print re.sub('\n', '', line)
|
43 |
|
|
for line in e:
|
44 |
|
|
if self.verbose:
|
45 |
|
|
print re.sub('\n', '', line)
|
46 |
|
|
r.close()
|
47 |
|
|
e.close()
|
48 |
|
|
w.close()
|
49 |
|
|
|
50 |
|
|
def getTags(self):
|
51 |
|
|
self.loadTags()
|
52 |
|
|
return self.tags
|
53 |
|
|
|
54 |
|
|
def loadIOVs(self, tag):
|
55 |
|
|
if not tag in self.tags :
|
56 |
|
|
if self.verbose:
|
57 |
|
|
print "No tag found in Database, skipping."
|
58 |
|
|
return
|
59 |
|
|
f = open(self.filename, 'w')
|
60 |
|
|
command = "export PATH=/afs/cern.ch/cms/sw/common/:$PATH \ncd " + self.release + " \neval `/afs/cern.ch/cms/sw/common/scramv1 runtime -sh` \ncmscond_list_iov -c oracle://" + self.main_db + "/" + self.table_name + " -P " + self.passwdfile + " -t " + tag
|
61 |
|
|
f.write("#!/bin/sh\n")
|
62 |
|
|
f.write(command)
|
63 |
|
|
f.close()
|
64 |
|
|
os.chmod(self.filename, stat.S_IRWXU|stat.S_IRWXG|stat.S_IRWXO)
|
65 |
|
|
if self.verbose :
|
66 |
|
|
print command
|
67 |
|
|
r, w, e = popen2.popen3(self.filename)
|
68 |
|
|
for line in r:
|
69 |
|
|
m = re.search('(\d+)\s+(\d+)\s+\[.*\]\[.*\]\[.*\]', line)
|
70 |
|
|
if m:
|
71 |
|
|
if tag in self.iovs :
|
72 |
|
|
if(self.verbose):
|
73 |
|
|
print 'Extending tag ', tag, ' with run ', m.group(1), ' was ', self.iovs[tags]
|
74 |
|
|
self.iovs[tag].append(m.group(1))
|
75 |
|
|
else :
|
76 |
|
|
if(self.verbose):
|
77 |
|
|
print 'Adding tag ', tag, ' with run ', m.group(1)
|
78 |
|
|
self.iovs[tag] = []
|
79 |
|
|
self.iovs[tag].append(m.group(1))
|
80 |
|
|
# print m.group(0), m.group(1), m.group(2)
|
81 |
|
|
# print re.sub('\n', '', line)
|
82 |
|
|
r.close()
|
83 |
|
|
e.close()
|
84 |
|
|
w.close()
|
85 |
|
|
if self.verbose:
|
86 |
|
|
print self.iovs
|
87 |
|
|
|
88 |
|
|
def checkAvailability(self, tag, run):
|
89 |
|
|
if not tag in self.tags:
|
90 |
|
|
if self.verbose:
|
91 |
|
|
print "No tag found in Database, returning True"
|
92 |
|
|
return True
|
93 |
|
|
if tag in self.iovs :
|
94 |
|
|
if self.verbose:
|
95 |
|
|
print 'Comparing ' ,self.iovs[tag][-1], ' with against Run ', run
|
96 |
|
|
if int(self.iovs[tag][-1]) >= int(run) :
|
97 |
|
|
if self.verbose :
|
98 |
|
|
print 'Comparison is good: run is NOT valid'
|
99 |
|
|
return False
|
100 |
|
|
else :
|
101 |
|
|
if self.verbose :
|
102 |
|
|
print 'Comparison is NOT good: run is valid'
|
103 |
|
|
return True
|
104 |
|
|
else :
|
105 |
|
|
return True
|
106 |
|
|
|
107 |
|
|
def checkPresence(self, tag, run):
|
108 |
|
|
if not tag in self.tags:
|
109 |
|
|
if self.verbose:
|
110 |
|
|
print "No tag found in Database, returning True"
|
111 |
|
|
return False
|
112 |
|
|
if tag in self.iovs :
|
113 |
|
|
if str(run) in self.iovs[tag]:
|
114 |
|
|
if self.verbose :
|
115 |
|
|
print 'Comparison is good: run is present'
|
116 |
|
|
return True
|
117 |
|
|
else:
|
118 |
|
|
if self.verbose :
|
119 |
|
|
print 'Comparison is NOT good: run is NOT present'
|
120 |
|
|
return False
|
121 |
|
|
else :
|
122 |
|
|
return False
|
123 |
|
|
|