Newer
Older
TB_Chris / Kepler / python / Kepler / .svn / text-base / Configuration.py.svn-base
  1.  
  2. """
  3. High level configuration tools for Kepler
  4. """
  5. __version__ = ""
  6. __author__ = ""
  7.  
  8. from Gaudi.Configuration import *
  9. import GaudiKernel.ProcessJobOptions
  10. from Configurables import LHCbConfigurableUser, LHCbApp
  11.  
  12. class Kepler(LHCbConfigurableUser):
  13.  
  14. __slots__ = {
  15. # Input
  16. "AlignmentFile" : "", # Name of input alignment file
  17. "PixelConfigFile" : [], # Names of pixel configuration files
  18. "TimingConfigFile" : "", # Name of file that configures time offsets
  19. "EtaConfigFiles" : [], # Names of files with eta correction parameters
  20. "InputFiles" : [], # Names of input files or directories
  21. "EvtMax" : -1, # Max. number of events to process
  22. # Output
  23. "HistogramFile" : "", # Name of output histogram file
  24. "TupleFile" : "", # Name of output tuple file
  25. "WriteTuples" : False, # Flag to write out tuple file or not
  26. # Options
  27. "Tracking" : True, # Flag to run tracking or not
  28. "UseSimpleTracking" : True, # Flag to use Heinrich's Track finding method
  29. "Alignment" : False, # Flag to run alignment or not
  30. "Monitoring" : True, # Flag to run the monitoring sequence
  31. "Sim" : False,
  32. "UT" : False, # Flag to run the UT reconstruction sequence
  33. "UserAlgorithms" : [] # List of user algorithms not typically run
  34. }
  35.  
  36. _propertyDocDct = {
  37. 'AlignmentFile' : """ Name of input alignment file """,
  38. 'PixelConfigFile' : """ Names of input pixel configuration files """,
  39. 'TimingConfigFile': """ Name of input timing configuration file """,
  40. 'EtaConfigFiles' : """ Names of files with eta correction parameters """,
  41. 'InputFiles' : """ Names of input raw data files or directories """,
  42. 'EvtMax' : """ Maximum number of events to process """,
  43. 'HistogramFile' : """ Name of output histogram file """,
  44. 'TupleFile' : """ Name of output tuple file """,
  45. 'WriteTuples' : """ Flag to write out tuple files or not """,
  46. 'Tracking' : """ Flag to run tracking or not """,
  47. 'Alignment' : """ Flag to activate alignment or not """,
  48. 'Monitoring' : """ Flag to run the monitoring sequence or not """,
  49. 'Sim' : """ Flag to simulate tracks rather than read in """,
  50. 'UT' : """ Flag to run the UT sequence or not """,
  51. 'UserAlgorithms' : """ List of user algorithms """
  52. }
  53.  
  54. __used_configurables__ = [LHCbApp,LHCbConfigurableUser]
  55.  
  56. def configureServices(self):
  57. # Pass the input file names to the data service.
  58. from Configurables import TbDataSvc
  59. TbDataSvc().Input = self.getProp("InputFiles")
  60. TbDataSvc().AlignmentFile = self.getProp("AlignmentFile")
  61. TbDataSvc().PixelConfigFile = self.getProp("PixelConfigFile")
  62. TbDataSvc().TimingConfigFile = self.getProp("TimingConfigFile")
  63. TbDataSvc().EtaConfigFiles = self.getProp("EtaConfigFiles")
  64. ApplicationMgr().ExtSvc += [TbDataSvc()]
  65.  
  66. # Add the geometry service which keeps track of alignment,
  67. # the timing service, which tracks event boundaries,
  68. # and the pixel service, which stores masked pixels,
  69. # clock phases and per column timing offsets.
  70. from Configurables import TbGeometrySvc, TbTimingSvc, TbPixelSvc
  71. ApplicationMgr().ExtSvc += [TbGeometrySvc(), TbTimingSvc(), TbPixelSvc()]
  72. # Use TimingAuditor for timing, suppress printout from SequencerTimerTool
  73. from Configurables import AuditorSvc, SequencerTimerTool
  74. ApplicationMgr().ExtSvc += ['ToolSvc', 'AuditorSvc']
  75. ApplicationMgr().AuditAlgorithms = True
  76. AuditorSvc().Auditors += ['TimingAuditor']
  77. if not SequencerTimerTool().isPropertySet("OutputLevel"):
  78. SequencerTimerTool().OutputLevel = 4
  79.  
  80. def configureSequence(self):
  81. """
  82. Set up the top level sequence and its phases
  83. """
  84. keplerSeq = GaudiSequencer("KeplerSequencer")
  85. ApplicationMgr().TopAlg = [keplerSeq]
  86. telescopeSeq = GaudiSequencer("Telescope")
  87. self.configureTelescope(telescopeSeq)
  88. keplerSeq.Members = [telescopeSeq]
  89. if self.getProp("UT") == True:
  90. utSeq = GaudiSequencer("UT")
  91. self.configureUT(utSeq)
  92. keplerSeq.Members += [utSeq]
  93. if self.getProp("Monitoring") == True:
  94. monitoringSeq = GaudiSequencer("Monitoring")
  95. self.configureMonitoring(monitoringSeq)
  96. keplerSeq.Members += [monitoringSeq]
  97. outputSeq = GaudiSequencer("Output")
  98. self.configureOutput(outputSeq)
  99. keplerSeq.Members += [outputSeq]
  100. UserAlgorithms = self.getProp("UserAlgorithms")
  101. if (len(UserAlgorithms) != 0):
  102. userSeq = GaudiSequencer("UserSequence")
  103. userSeq.Members = UserAlgorithms
  104. keplerSeq.Members += [userSeq]
  105. def configureTelescope(self, seq):
  106. if self.getProp("Sim") == False:
  107. from Configurables import TbEventBuilder
  108. seq.Members += [TbEventBuilder()]
  109. else :
  110. from Configurables import TbTestMC
  111. seq.Members += [TbTestMC()]
  112. from Configurables import TbClustering
  113. seq.Members += [TbClustering()]
  114. if self.getProp("Tracking") == True:
  115. from Configurables import TbSimpleTracking, TbTracking
  116. trackingSeq = GaudiSequencer("Tracking")
  117. if self.getProp("UseSimpleTracking") == True :
  118. trackingSeq.Members = [TbSimpleTracking()]
  119. else :
  120. trackingSeq.Members = [TbTracking()]
  121. seq.Members += [trackingSeq]
  122. from Configurables import TbTriggerAssociator
  123. seq.Members += [TbTriggerAssociator()]
  124. from Configurables import TbClusterAssociator
  125. seq.Members += [TbClusterAssociator()]
  126. if self.getProp("Alignment") == True:
  127. from Configurables import TbAlignment
  128. seq.Members += [TbAlignment()]
  129.  
  130. def configureMonitoring(self, seq):
  131. from Configurables import TbHitMonitor, TbClusterPlots, TbTrackPlots
  132. if self.getProp("Tracking") == True :
  133. seq.Members += [TbHitMonitor(), TbClusterPlots(), TbTrackPlots()]
  134. from Configurables import TbTriggerMonitor
  135. seq.Members += [TbTriggerMonitor()]
  136. from Configurables import TbDUTMonitor
  137. seq.Members += [TbDUTMonitor()]
  138. else :
  139. seq.Members += [TbHitMonitor(), TbClusterPlots()]
  140.  
  141. def configureUT(self, seq):
  142. # UT algorithms
  143. seq.Members = []
  144.  
  145. def configureInput(self):
  146. # No events are read as input
  147. ApplicationMgr().EvtSel = 'NONE'
  148. # Delegate handling of max. number of events to ApplicationMgr
  149. self.setOtherProps(ApplicationMgr(), ["EvtMax"])
  150. # Transient store setup
  151. EventDataSvc().ForceLeaves = True
  152. EventDataSvc().RootCLID = 1
  153. # Suppress warning message from EventLoopMgr
  154. from Configurables import MessageSvc
  155. MessageSvc().setError += ['EventLoopMgr']
  156.  
  157. def configureOutput(self, seq):
  158. # ROOT persistency for histograms
  159. ApplicationMgr().HistogramPersistency = "ROOT"
  160. # Set histogram file name.
  161. histoFile = "Kepler-histos.root"
  162. if (self.isPropertySet("HistogramFile") and self.getProp("HistogramFile") != ""):
  163. histoFile = self.getProp("HistogramFile")
  164. HistogramPersistencySvc().OutputFile = histoFile
  165. # Set tuple file name.
  166. tupleFile = "Kepler-tuple.root"
  167. if (self.isPropertySet('TupleFile') and self.getProp("TupleFile") != ""):
  168. tupleFile = self.getProp("TupleFile")
  169. ApplicationMgr().ExtSvc += [NTupleSvc()]
  170. tupleStr = "FILE1 DATAFILE='%s' TYP='ROOT' OPT='NEW'" % tupleFile
  171. NTupleSvc().Output += [tupleStr]
  172. from Configurables import MessageSvc
  173. MessageSvc().setWarning += ['RFileCnv', 'RCWNTupleCnv']
  174. # If requested add TbTupleWriter to the output sequence
  175. if self.getProp("WriteTuples") == True:
  176. from Configurables import TbTupleWriter
  177. seq.Members += [TbTupleWriter()]
  178.  
  179. def evtMax(self):
  180. return LHCbApp().evtMax()
  181.  
  182. def __apply_configuration__(self):
  183. GaudiKernel.ProcessJobOptions.PrintOn()
  184. self.configureServices()
  185. self.configureSequence()
  186. self.configureInput()
  187. GaudiKernel.ProcessJobOptions.PrintOn()
  188. log.info(self)
  189. GaudiKernel.ProcessJobOptions.PrintOff()
  190.  
  191. def addAlignment(self, a):
  192. from Configurables import TbAlignment
  193. counter = len(TbAlignment().AlignmentTechniques)
  194. name = "s%d" % (counter)
  195. algname = type(a).__name__
  196. print "Added tool: %s (%d)" % (algname, counter)
  197. TbAlignment().addTool(a, name = name)
  198. TbAlignment().AlignmentTechniques.append(algname)
  199.  
  200.  
  201.