ATLAS Offline Software
sim_reg_test_fastchain.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
4 
5 import os,sys
6 import time,datetime
7 
8 __author__ = 'FFF'
9 __doc__ = 'FFF'
10 
11 
12 dryrun=False
13 
14 
15 def checkStatus(path,days=1):
16  if not os.path.exists(path+"/jobExitCode.txt"):
17  print path+"/jobExitCode.txt","missing - skipping this nightly"
18  return False,999
19  f = open(path+"/jobExitCode.txt")
20  print "Checking job status..."
21  print "Found "+path+"/jobExitCode.txt"
22  file_status=False
23  for line in f:
24  if line.strip()=='0':
25  file_status=True
26  #print line,
27  if "<jobSuccess>True</jobSuccess>" in line:
28  file_status=True
29  #print line,
30  elif "<jobSuccess>False</jobSuccess>" in line:
31  file_status=False
32  #print line,
33  if file_status: print "Job succeeded in this nightly."
34  else:
35  print "Job failed in this nightly."
36  return False,999
37  #check date
38  #<timeStamp>1352062929</timeStamp>
39  if os.path.exists(path+"/rttjobinfo.xml"):
40  import re
41  f = open(path+"/rttjobinfo.xml")
42  for l in f:
43  #<timeStamp>1352062929</timeStamp>#
44  m=re.search('<timeStamp>([0-9]*)</timeStamp>',l)
45  if m is not None:
46  #print m.groups()
47  ts=int(m.groups()[0])
48  import datetime as dt
49  yes=dt.date.fromtimestamp(ts)
50  now=dt.date.today()
51  days=(now-yes).days
52  if days>6:
53  # to old, ignore
54  print 'WARNING results found in '+path+' are more than a week old'
55 # file_status=False
56  return file_status,days
57 
58 
59 def get_recent(path,pathsplit):
60  print "---------------------------------------------------------------------------------------"
61  pathlist=path.split('/')
62  pos_index=0
63  release_list=[]
64  for i,a in enumerate(pathsplit):
65  if a.find("rel_")>=0:
66  pos_index=i
67  release_list=a.split('_')
68  todays_release=pathlist[pos_index]
69  recent_days=999;
70  recent_index=0;
71  for i in xrange(7):
72  release_tag=release_list[0]+"_"+str(i)
73 # print release_tag
74  pathlist[pos_index]=release_tag
75  path_refill="/".join(pathlist)
76 # print path_refill
77  print "Checking for results for "+release_tag+"..."
78  status_tmp,days_tmp=checkStatus(path_refill)
79  if status_tmp:
80  print "==> Nightly: "+release_tag+" Age: "+str(days_tmp)+" days"
81  if days_tmp>=0 and days_tmp<recent_days:
82  recent_days=days_tmp
83  recent_index=i
84  else:
85  print "==> Nightly: "+release_tag+" Age: N/A"
86  print "---------------------------------------------------------------------------------------"
87  if recent_days>998:
88  print "=====> Could not find another release to compare to. Returning today's nightly ("+todays_release+") as the reference."
89  return todays_release
90  good_rel_refease="rel_"+str(recent_index)
91  print "=====> "+good_rel_refease+" is the most recent nightly to use as reference."
92  return good_rel_refease
93 
94 
95 def eoscp(package,filename,jobname,nightly,tag,store_tag,release):
96 
97  current=os.getcwd()
98  if os.environ.has_key('LS_SUBCWD'):
99  current=os.environ['LS_SUBCWD']
100  #current='/afs/cern.ch/atlas/project/RTT/prod/Results/rtt/rel_2/19.2.X.Y-VAL/build/x86_64-slc6-gcc47-opt/offline/ISF_Validation/ttbar_ISF_G4_sim_Reg'
101  argv=current.split('/')
102  argv.pop()
103 
114 
115  postfix="x86_64-slc6-gcc62-opt/Athena/"+package
116  #middle='/'.join(argv[-6:-5])
117  #middle=argv[-5]
118  middle=nightly
119  pathlist=["prod","batch"]#This 2nd option should make the script work on the RTT test instance.
120 # status=0
121  for path in pathlist:
122  prefix="root://eosatlas.cern.ch//eos/atlas/atlascerngroupdisk/proj-sit/rtt/"+path+"/rtt"
123  #print "postfix: "+postfix
124  #print "middle: "+middle
125  #print "prefix: "+prefix
126  #print "jobname: "+jobname
127  #print "filename: "+filename
128  path=prefix+'/'+release+'/'+middle+'/'+postfix+'/'+jobname+'/'+filename
129  print "Path to check on eos: "+path
130  if store_tag!='':
131  command_cp="xrdcp %s %s.%s.root"%(path,tag,store_tag)
132  else:
133  command_cp="xrdcp %s %s.%s"%(path,tag,filename)
134  print command_cp
135  status=os.system(command_cp)
136  if status==0: return status
137  return status
138 
139 
140 if __name__ == "__main__":
141  print '------------------usage-----------------'
142  print 'sim_reg_test_fastchain.py [ref package] [ref rel] [ref job name] [ref filename] [mon package] [mon rel] [mon job name] [mon filename]'
143  print 'packages supported are ISF_Validation and FastChainPileup'
144  print 'to use current release, put "current" as a release argument'
145  print 'if job fails for today`s ref/mon, the latest succeeded job will be taken'
146  print '----------------------------------------'
147 
148  print 'Got input arguments:'
149  print 'reference:'
150  print 'package: ', sys.argv[1]
151  print 'release: ', sys.argv[2]
152  print 'job: ', sys.argv[3]
153  print 'filename: ', sys.argv[4]
154  print 'monitored:'
155  print 'package: ', sys.argv[5]
156  print 'release: ', sys.argv[6]
157  print 'job: ', sys.argv[7]
158  print 'filename: ', sys.argv[8]
159  if sys.argv[1]!='ISF_Validation' and sys.argv[1]!='FastChainPileup' :
160  print 'ERROR: unsupported reference package.'
161  if sys.argv[5]!='ISF_Validation' and sys.argv[5]!='FastChainPileup' :
162  print 'ERROR: unsupported monitored package.'
163  #establish path to monitored release, rel num is just dummy at this stage
164  pwdmon=''
165  prepath='/afs/cern.ch/atlas/project/RTT/prod/Results/rtt/rel_0/'
166  #TODO: make postpath configurable
167  postpath='/build/x86_64-slc6-gcc62-opt/Athena/'
168  currel='NOREL'
169  if sys.argv[6] == 'current' or sys.argv[2] == 'current' :
170  curdir=os.getcwd()
171  if os.environ.has_key('LS_SUBCWD'):
172  curdir= os.environ['LS_SUBCWD']
173  #!TEST
174  #curdir='/afs/cern.ch/atlas/project/RTT/prod/Results/rtt/rel_2/mig13/build/x86_64-slc6-gcc49-opt/offline/FastChainPileup/'
175  #!END TEST
176  folders=curdir.split('/')
177  print folders
178  for idx, folder in enumerate(folders):
179  if 'rel_' in folder :
180  try:
181  currel = folders[idx+1]
182  except IndexError:
183  print 'ERROR: Could not find current release in the path after /rel_*/'
184  if currel == 'NOREL' :
185  print 'ERROR: Could not find current release in the path. Setting release to "NOREL" and going to crash.'
186 
187  relmon=sys.argv[6]
188  if sys.argv[6] == 'current' :
189  relmon = currel
190  pwdmon=prepath + relmon + postpath
191  #establish path to reference release, rel num is just dummy at this stage
192  pwdref=''
193  prepath='/afs/cern.ch/atlas/project/RTT/prod/Results/rtt/rel_0/'
194  postpath='/build/x86_64-slc6-gcc62-opt/Athena/'
195  relref=sys.argv[2]
196  if sys.argv[2] == 'current' :
197  relref=currel
198  pwdref=prepath + relref + postpath
199 
200  argvref=pwdref.split('/')
201  argvref.pop()
202  argvref.append(sys.argv[1])
203  argvref.append(sys.argv[3])
204  print 'argvref ',argvref
205  corr_path_ref='/'.join(argvref)
206  print 'reference path:', corr_path_ref
207 
208  print '###### Get the most recent successful reference job ######'
209  good_rel_ref=get_recent(corr_path_ref,argvref)
210 
211  print ''
212  print ''
213  print ''
214  print ''
215 
216  argvmon=pwdmon.split('/')
217  argvmon.pop()
218  argvmon.append(sys.argv[5])
219  argvmon.append(sys.argv[7])
220  print 'argvmon ',argvmon
221  corr_path_mon='/'.join(argvmon)
222  print 'monitored path:', corr_path_mon
223  print '###### Get the most recent successful monitored job ######'
224  good_rel_mon=get_recent(corr_path_mon,argvmon)
225 
226  posref=9
227  for i,a in enumerate(argvref):
228  if a.find("rel_")>=0 :
229  posref = i
230 
231  posmon=9
232  for i,a in enumerate(argvmon):
233  if a.find("rel_")>=0 :
234  posmon = i
235 
236  argvmon[posmon]=good_rel_mon
237  monPath='/'.join(argvmon)
238 
239  argvref[posref]=good_rel_ref
240  refPath='/'.join(argvref)
241 
242  print "Releases to compare: "+good_rel_ref+", "+good_rel_mon
243  print refPath
244  print monPath
245 
246  # look for suffix
247  file_name='.root'
248  store_tag=''
249 
250  # make sure ISFBroker.root is not confused with truth*.root
251  compfilesref=['ISFBroker.root']
252  compfilesmon=['ISFBroker.root']
253  #if len(sys.argv)>3:
254 
262 
263  compfilesref.append(sys.argv[4])
264  compfilesmon.append(sys.argv[8])
265  print 'compfilesref:',compfilesref
266  print 'compfilesref:',compfilesmon
267  file_list_ref=compfilesref[:]
268  print file_list_ref
269  file_list_val=compfilesmon[:]
270  try:
271  print "Confirming monitored job status..."
272  file_status_val,days=checkStatus(monPath)
273 
274  if file_status_val==True:
275  #print "Success"
276  file_root=False
277  for f in os.listdir(monPath):
278  if f.endswith(file_name) and f != 'yesterday.root' and f!= 'today.root':
279  print f
280  name,suffix=f.split('.',1)
281  if f in compfilesmon:
282  suffix=f
283  print 'f1'
284  elif len(compfilesmon)>=2:
285  continue
286  if store_tag!='':
287  cmd = 'cp'+' '+monPath+'/'+f+' '+'today.'+store_tag+".root"
288  else:
289  cmd = 'cp'+' '+monPath+'/'+f+' '+'today.'+suffix
290  print cmd
291  if not dryrun:
292  os.system(cmd)
293  file_root=True
294  if f in file_list_val:
295  file_list_val.remove(f)
296  print file_list_val
297  if 'ISFBroker.root' in file_list_val:
298  file_list_val.remove('ISFBroker.root')
299  if len(file_list_val)!=0:
300  print "The following files were not found in the output directory of today's job: "+str(file_list_val)+", will try to copy them from EOS instead."
301  for val_f in file_list_val:
302  if eoscp(sys.argv[5],val_f,sys.argv[7],sys.argv[6],"today",store_tag,good_rel_mon)!=0 :
303  print "File does not exist in EOS."
304  else:
305  file_list_val.remove(val_f)
306 
307 
308  file_status_ref=False
309  file_list_ref_orig = file_list_ref
310  for i in range(1,5):
311  print "Confirming reference job status..."
312  file_status_ref,days_ref=checkStatus(refPath)
313  if file_status_ref==True:
314  #print("Looking for .root files to compare...")
315  file_root=False
316  for f in os.listdir(refPath):
317  if f.endswith(file_name) and f != 'yesterday.root' and f!= 'today.root':
318  print f
319  print compfilesref
320  name,suffix=f.split('.',1)
321  #if name in compfiles:
322  if f in compfilesref:
323  suffix=f
324  print 'f2'
325  elif len(compfilesref)>=2:
326  continue
327  if store_tag!='':
328  cmd = 'cp'+' '+refPath+'/'+f+' '+'yesterday.'+store_tag+'.root'
329  else:
330  cmd = 'cp'+' '+refPath+'/'+f+' '+'yesterday.'+suffix
331  print cmd
332  if not dryrun:
333  os.system(cmd)
334  file_root=True
335  if f in file_list_ref:
336  file_list_ref.remove(f)
337  print file_list_ref
338  if 'ISFBroker.root' in file_list_ref:
339  file_list_ref.remove('ISFBroker.root')
340  if len(file_list_ref)!=0:
341  print "The following files were not found in the output directory of "+good_rel_ref+"'s job: "+str(file_list_ref)+", will try to copy them from EOS instead."
342  for ref_f in file_list_ref :
343  if eoscp(sys.argv[1],ref_f,sys.argv[3],sys.argv[2],"yesterday",store_tag,good_rel_ref)!=0:
344  print "File does not exist in EOS."
345  else:
346  file_list_ref.remove(ref_f)
347 
348  if len(file_list_ref)==0:
349  break
350  else:
351 
352  print "Could not find a full set of files for "+good_rel_ref+", so removing any we did find."
353  if(len(file_list_ref)+1) < len(file_list_ref_orig): os.system('rm yesterday.*')
354  file_list_ref = file_list_ref_orig
355  file_status_ref=False
356  previous_rel = good_rel_ref
357  if good_rel_ref == 'rel_0':
358  good_rel_ref = 'rel_6'
359  else:
360  good_rel_ref = 'rel_%d' % (int(good_rel_ref.split('_')[1])-1)
361 
362  argvref[pos]=good_rel_ref
363  refPath='/'.join(argvref)
364  print "As we failed to find all required files in "+previous_rel+", trying again with "+good_rel_ref
365  print monPath
366  print refPath
367 
368  if not file_status_ref==True:
369  print("Failed to find a usable reference nightly!")
370  else:
371  # make fileGrepper happy
372  print "leaving with code 0"
373 
374  elif file_status_val==False:
375  print "Failed to find expected files in the path for today's nightly!"
376 
377  except (OSError,IOError):
378  print "No running in this release!"
xrange
void xrange(TH1 *h, bool symmetric)
Definition: computils.cxx:515
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
sim_reg_test_fastchain.checkStatus
def checkStatus(path, days=1)
Definition: sim_reg_test_fastchain.py:15
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
sim_reg_test_fastchain.eoscp
def eoscp(package, filename, jobname, nightly, tag, store_tag, release)
Add EOS prefix###.
Definition: sim_reg_test_fastchain.py:95
Trk::open
@ open
Definition: BinningType.h:40
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:569
str
Definition: BTagTrackIpAccessor.cxx:11
sim_reg_test_fastchain.get_recent
def get_recent(path, pathsplit)
get the recent tag###
Definition: sim_reg_test_fastchain.py:59