Newer
Older
TB_Chris / Kepler / GangaPlugin / Lib / .svn / text-base / TbDataset.py.svn-base
  1. from Ganga.GPIDev.Adapters.ISplitter import ISplitter
  2. from Ganga.GPIDev.Schema import *
  3. from TbQuery import TbQuery
  4. from collections import defaultdict
  5. from Ganga.GPIDev.Base.Proxy import addProxy, stripProxy
  6.  
  7. class TbDataset(ISplitter):
  8. _name = "TbDataset"
  9. _schema = Schema(Version(1,0), {
  10. 'filesPerJob' : SimpleItem(defvalue=1),
  11. 'maxFiles' : SimpleItem(defvalue=1),
  12. 'ignoremissing': SimpleItem(defvalue=False),
  13. 'Files' : SimpleItem(defvalue={}),
  14. 'AlignmentFiles' : SimpleItem(defvalue={}),
  15. 'PixelConfigFiles' : SimpleItem(defvalue={}),
  16. 'TimingConfigFiles' : SimpleItem(defvalue={}),
  17. 'Month' : SimpleItem(defvalue=""),
  18. 'run' : SimpleItem(defvalue=0),
  19. 'prefix' : SimpleItem(defvalue=""),
  20. 'AutoConfig' : SimpleItem(defvalue=True) })
  21. _exportmethods = [ 'split','optionsString' ]
  22. def split(self,job):
  23. from Ganga.GPIDev.Lib.Job import Job
  24. subjobs = []
  25. for run in self.Files.keys():
  26. j = addProxy(self.createSubjob(job))
  27. # j.splitter = None
  28. # j.merger = None
  29. jp = stripProxy(j)
  30. jp._splitter_data = self.optionsString(run)
  31. subjobs.append(jp)
  32. print "Submitting jobs for %d runs" %( len(subjobs))
  33. return subjobs
  34. def __construct__(self,args):
  35. if len( args ) == 0 : return
  36. self.Month = args[0]
  37. for r in args[1]:
  38. query = TbQuery()
  39. query.Month = self.Month
  40. query.Run = r
  41. print "Looking for %s/Run%d" %(self.Month, r )
  42. files = query.getFiles()
  43. if len(files) != 0 : self.Files[r] = []
  44. for f in files:
  45. self.Files[r].append(f)
  46. if self.AutoConfig:
  47. config_files = query.getConfiguration()
  48. alignment_file = ""
  49. for f in config_files:
  50. if f.find("Alignment") != -1:
  51. if alignment_file != "": alignment_file = f
  52. elif f.find("mille") != -1: alignment_file = f
  53. # elif f.find(self.prefix) != -1 : alignment_file = f
  54. elif f.find("PixelConfig") != -1:
  55. if r not in self.PixelConfigFiles.keys():
  56. self.PixelConfigFiles[r] = []
  57. self.PixelConfigFiles[r].append(f)
  58. elif f.find("TimingConfig") != -1: self.TimingConfigFiles[r] = f
  59. if alignment_file != "" : self.AlignmentFiles[r] = alignment_file
  60. def optionsString(self, run):
  61. files_for_this_run = self.Files[run]
  62. if len( files_for_this_run ) == 0 :
  63. return ""
  64. output = "from Configurables import TbDataSvc \n"
  65. output += "TbDataSvc().Input = ['" + files_for_this_run[0] +"'"
  66. for f in range(1, len(files_for_this_run)):
  67. output += ",'"+files_for_this_run[f]+"'"
  68. output += "]"
  69. # now add the configuration files ...
  70. if self.AutoConfig:
  71. pixel_config = []
  72. if run in self.PixelConfigFiles.keys() :
  73. pixel_config = self.PixelConfigFiles[run]
  74. output+= " \nTbDataSvc().PixelConfigFile += ['" + pixel_config[0] +"'"
  75. for f in range(1,len(pixel_config)):
  76. output += ",'"+pixel_config[f]+"'"
  77. output += "]"
  78. timing_config = ""
  79. if run in self.TimingConfigFiles.keys() :
  80. timing_config = self.TimingConfigFiles[run]
  81. output += " \nTbDataSvc().TimingConfigFile = '%s'" %(timing_config)
  82. alignment = ""
  83. if run in self.AlignmentFiles.keys() :
  84. alignment = self.AlignmentFiles[run]
  85. output += " \nTbDataSvc().AlignmentFile = '%s'" %(alignment)
  86. return output