-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhiggs_hacker_std.py
executable file
·228 lines (158 loc) · 7.49 KB
/
higgs_hacker_std.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env python
#############################################################################
# Author : Jerome ODIER
# Email : [email protected]
#
# Version : 1.0 (2011)
#
#
# This file is part of HIGGS_HACKER.
#
#############################################################################
import higgs_hacker_core
import higgs_hacker_conf
import sys, time, commands, threading
#############################################################################
# THiggsHacker #
#############################################################################
class THiggsHacker(higgs_hacker_core.THiggsHackerAbstract):
#####################################################################
# SQL #
#####################################################################
def create(self):
self.execute('''
CREATE TABLE "DataSet" (
"in_type" VARCHAR(64) NOT NULL,
"in_ds" VARCHAR(256) NOT NULL PRIMARY KEY,
"out_ds" VARCHAR(256) NOT NULL,
"state" VARCHAR(16) NOT NULL,
"get" INT2 NOT NULL,
"jobID" INT NOT NULL,
"date" INT NOT NULL,
"run" INT NOT NULL
);
''')
#####################################################################
# CRON 1 #
#####################################################################
def cron1(self, in_type, in_pattern, out_pattern):
print('#############################################################################')
print('%s - %s' % (in_type, time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())))
print('#############################################################################')
datasets = self.dq2_ls(in_pattern)
# if len(datasets) > 0:
# datasets = [datasets[0]]
for in_ds in datasets:
if self.dq2_complete(in_ds) != False:
values = self.execute('SELECT * FROM DataSet WHERE in_ds = "%s"' % in_ds)
date = self.dq2_date(in_ds)
run = self.dq2_run(in_ds)
if run >= 178044 and run <= 186755 and len(values) == 0:
out_ds = out_pattern % (higgs_hacker_conf.GRID_USER, run, int(time.time()))
print('\033[32min_ds\033[0m: %s' % in_ds)
print('\033[36mout_ds\033[0m: %s' % out_ds)
#####################################
# TIMESTAMP #
#####################################
timestamp = int(time.time())
#####################################
# PANDA 1 #
#####################################
status, output = commands.getstatusoutput('./tools/higgs_analysis_std.sh %s %s %s %s' % (in_ds, out_ds, higgs_hacker_conf.PATH_HIGGS_ANALYSIS, higgs_hacker_conf.OPTION_HIGGS_ANALYSIS))
if status != 0:
self.error('Could not launch \'higgs_analysis.sh\' !\n%d' % output)
continue
print(output)
#####################################
# PANDA 2 #
#####################################
jobIDs = self.getJobIDs(timestamp)
if len(jobIDs) > 0:
jobID = int(jobIDs[-1])
self.execute('INSERT INTO DataSet (in_type, in_ds, out_ds, state, get, jobID, date, run) VALUES ("%s", "%s", "%s", "??????", "0", "%d", "%d", "%d");' % (in_type, in_ds, out_ds, jobID, date, run))
else:
jobID = int(0x00000000)
self.execute('INSERT INTO DataSet (in_type, in_ds, out_ds, state, get, jobID, date, run) VALUES ("%s", "%s", "%s", "FAILED", "0", "%d", "%d", "%d");' % (in_type, in_ds, out_ds, jobID, date, run))
self.error('Could not start \'pathena\' job !\n%s' % output)
#####################################
higgsHacker.commit()
#####################################################################
# CRON 2 #
#####################################################################
def cron2(self):
values = self.execute('SELECT * FROM DataSet WHERE state = "??????"')
for value in values:
jobID = value['jobID']
if self.jobIsFinished(jobID) != False:
#############################################
# SQL #
#############################################
self.execute('UPDATE DataSet SET state = "SUCCESS" WHERE jobID = "%d";' % jobID)
#############################################
# LOG #
#############################################
self.success('New run available: %08d :-)\nJob \'%d\' is \'success\' !\nhttp://panda.cern.ch/server/pandamon/query?job=*&jobsetID=%d&user=Jerome%%20Odier\n' % (value['run'], jobID, jobID))
#############################################
else:
if self.jobIsFailed(jobID) != False:
self.execute('UPDATE DataSet SET state = "FAILED" WHERE jobID = "%d";' % jobID)
self.error('New run available: %08d :-(\nJob \'%d\' is \'failed \' !\nhttp://panda.cern.ch/server/pandamon/query?job=*&jobsetID=%d&user=Jerome%%20Odier\n' % (value['run'], jobID, jobID))
continue
if self.jobIsCancelled(jobID) != False:
self.execute('UPDATE DataSet SET state = "FAILED" WHERE jobID = "%d";' % jobID)
self.error('New run available: %08d :-(\nJob \'%d\' is \'cancelled\' !\nhttp://panda.cern.ch/server/pandamon/query?job=*&jobsetID=%d&user=Jerome%%20Odier\n' % (value['run'], jobID, jobID))
continue
higgsHacker.commit()
#############################################################################
# HIGGS HACKER #
#############################################################################
dbHost = 'sqlite://test_std.db'
dbPort = 3306
dbName = 'HiggsHunter'
#############################################################################
from optparse import OptionParser
#############################################################################
if __name__ == '__main__':
parser = OptionParser('usage: %prog [options] dbhost dbport dbname')
parser.add_option('-a', '--authors',
action='store_true', dest='authors', help='show the authors of this application')
parser.add_option('-v', '--version',
action='store_true', dest='version', help='show the version of this application')
(options, args) = parser.parse_args()
if options.authors:
print 'Jerome ODIER'
sys.exit()
if options.version:
print 'higgs_hacker-1.0'
sys.exit()
#####################################################################
higgsHacker = THiggsHacker()
#####################################################################
if len(args) == 0:
higgsHacker.open(dbHost, dbPort, dbName)
elif len(args) == 1:
higgsHacker.open(args[0], dbPort, dbName)
elif len(args) == 2:
higgsHacker.open(args[0], int(args[1]), dbName)
elif len(args) == 3:
higgsHacker.open(args[0], int(args[1]), args[2])
higgsHacker.create()
#####################################################################
try:
i = 0
while True:
if i % 40 == 0:
higgsHacker.checkGridProxy()
higgsHacker.cron1('egamma_4L', 'data11_7TeV.*.physics_Egamma.merge.NTUP_HSG2.f*_m*_p600/', 'user.%s.data11_7TeV.%08d.physics_Egamma.merge.higgs-analysis-%d_std.p600/')
# higgsHacker.cron1('egamma_2L', 'data11_7TeV.*.physics_Egamma.merge.NTUP_2LHSG2.f*_m*_p600/', 'user.%s.data11_7TeV.%08d.physics_Egamma.merge.2Lhiggs-analysis_std-%d.p600/')
higgsHacker.cron1('muon_4L', 'data11_7TeV.*.physics_Muons.merge.NTUP_HSG2.f*_m*_p600/', 'user.%s.data11_7TeV.%08d.physics_Muons.merge.higgs-analysis-%d_std.p600/')
# higgsHacker.cron1('muon_2L', 'data11_7TeV.*.physics_Muons.merge.NTUP_2LHSG2.f*_m*_p600/', 'user.%s.data11_7TeV.%08d.physics_Muons.merge.2Lhiggs-analysis-%d_std.p600/')
time.sleep(30)
higgsHacker.cron2()
time.sleep(30)
i += 1
except KeyboardInterrupt:
higgsHacker.commit()
higgsHacker.close()
print('Bye')
#####################################################################