Newer
Older
TB_Chris / Kepler / GangaPlugin / Lib / .svn / text-base / TbFileChecker.py.svn-base
  1. from Ganga.GPIDev.Base import GangaObject
  2. from Ganga.GPIDev.Adapters.IPostProcessor import PostProcessException, IPostProcessor
  3. from Ganga.GPIDev.Base.Proxy import GPIProxyObject
  4. from Ganga.GPIDev.Schema import ComponentItem, FileItem, Schema, SimpleItem, Version
  5. from Ganga.Utility.Config import makeConfig, ConfigError, getConfig
  6. from Ganga.Utility.Plugin import allPlugins
  7. from Ganga.Utility.logging import getLogger, log_user_exception
  8. import commands
  9. import copy
  10. import os
  11. import string
  12. import re
  13.  
  14. class TbFileChecker(IPostProcessor):
  15.  
  16. _schema = IPostProcessor._schema.inherit_copy()
  17. _schema.datadict["alignment"] = SimpleItem(False)
  18. _schema.datadict["resubmit"] = SimpleItem(False) #resubmit items with no output in the errorsummary
  19. _category = 'postprocessor'
  20. _name = 'TbFileChecker'
  21. _exportmethods = ['check','ErrorSummary']
  22.  
  23. def check(self,job):
  24.  
  25. job_objects = []
  26. if len( job.subjobs ) != 0:
  27. for j in job.subjobs:
  28. job_objects.append(j)
  29. else: job_objects.append( job )
  30. result = True
  31. for j in job_objects:
  32. job_success = False
  33. filepath = "%s/stdout" %(j.outputdir)
  34. #print "Checking %d subjobs " %( len(job_objects ) )
  35. if j.status != "completed": continue
  36. if self.alignment:
  37.  
  38. if not os.path.isfile( j.outputdir + "Alignment_out.dat" ):
  39. job_success = False
  40. j.force_status('failed')
  41. continue
  42.  
  43. if not os.path.isfile( filepath ): continue
  44. f = reversed( open(filepath,'r').readlines() )
  45. for line in f:
  46. if re.search("ApplicationMgr INFO Application Manager Finalized successfully",line):
  47. job_success = True
  48. break
  49. if job_success: j.force_status('completed')
  50. else : j.force_status('failed')
  51. result = result*job_success
  52. return result
  53. def ErrorSummary(self,job):
  54. job_objects = []
  55. minuit_exceptions = ["MATRIX","DERIVATIVE","VALUE"]
  56. millepede_exceptions = ["Initial","Negative","diagonal"]
  57. for j in job.subjobs:
  58. if j.status == 'failed': job_objects.append(j)
  59. for j in job_objects:
  60. filepath = "%s/stdout" %(j.outputdir)
  61. error = "Unknown"
  62. if os.path.isfile( filepath ):
  63. for line in open(filepath,'r').readlines():
  64. if re.search("ERROR",line):
  65. found = False
  66. for e in minuit_exceptions:
  67. if re.search(e,line):
  68. found = True
  69. break
  70. if found : continue
  71. error = line[:-1]
  72. break
  73. if re.search("error",line):
  74. found = False
  75. for e in millepede_exceptions:
  76. if re.search(e,line):
  77. found = True
  78. break
  79. if found : continue
  80.  
  81. error = line[:-1]
  82. break
  83. if re.search("Error",line):
  84. found = False
  85. for e in millepede_exceptions:
  86. if re.search(e,line):
  87. found = True
  88. break
  89. if found : continue
  90.  
  91. error = line[:-1]
  92. break
  93. else:
  94. error = "No output files"
  95. if self.resubmit: j.resubmit()
  96. print "%s (%d.%3d) : %s" %( j.name, job.id, j.id, error )