CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DTVdriftWorkflow.py
Go to the documentation of this file.
1 from __future__ import absolute_import
2 import os
3 import logging
4 
5 from . import tools
6 import FWCore.ParameterSet.Config as cms
7 from .DTWorkflow import DTWorkflow
8 
9 log = logging.getLogger(__name__)
10 
12  """ This class creates and performce / submits vdrift workflow jobs"""
13  def __init__(self, options):
14  # call parent constructor
15  super( DTvdriftWorkflow, self ).__init__( options )
16 
17  self.outpath_command_tag = "VdriftCalibration"
18  output_file_dict = { "segment" : "DTVDriftHistos.root",
19  "meantimer" : "DTTMaxHistos.root",
20  }
21  self.outpath_workflow_mode_dict = { "segment" : "Segments",
22  "meantimer" : "MeanTimer",
23  }
24  self.output_file = output_file_dict[self.options.workflow_mode]
25  self.output_files = [self.output_file]
26 
27  def prepare_workflow(self):
28  """ Generalized function to prepare workflow dependent on workflow mode"""
29  function_name = "prepare_" + self.options.workflow_mode + "_" + self.options.command
30 
31  try:
32  fill_function = getattr(self, function_name)
33  except AttributeError:
34  errmsg = "Class `{}` does not implement `{}`"
35  raise NotImplementedError( errmsg.format(self.__class__.__name__,
36  function_name))
37  log.debug("Preparing workflow with function %s" % function_name)
38  # call chosen function
39  fill_function()
40 
42  self.pset_name = 'dtVDriftSegmentCalibration_cfg.py'
43  self.pset_template = 'CalibMuon.DTCalibration.dtVDriftSegmentCalibration_cfg'
44  if self.options.datasettype == "Cosmics":
45  self.pset_template = 'CalibMuon.DTCalibration.dtVDriftSegmentCalibration_cosmics_cfg'
46 
48  self.process.GlobalTag.globaltag = self.options.globaltag
49  self.process.dtVDriftSegmentCalibration.rootFileName = self.output_file
50 
51  if self.options.inputCalibDB:
52  err = "Option inputCalibDB not available for segment."
53  err += "Maybe you want to use option inputTtrigDB"
54  raise ValueError(err)
55  self.prepare_common_submit()
56  if self.options.inputTtrigDB:
57  label = ''
58  if self.options.datasettype == "Cosmics":
59  label = 'cosmics'
60  connect = os.path.basename(self.options.inputTtrigDB)
61  self.addPoolDBESSource( process = self.process,
62  moduleName = 'tTrigDB',
63  record = 'DTTtrigRcd',
64  tag = 'ttrig',
65  connect = str("sqlite_file:%s" % connect),
66  label = label
67  )
68  self.input_files.append( os.path.abspath(self.options.inputTtrigDB) )
69  self.write_pset_file()
70 
72  self.load_options_command("submit")
73 
75  self.pset_name = 'dtVDriftSegmentWriter_cfg.py'
76  self.pset_template = 'CalibMuon.DTCalibration.dtVDriftSegmentWriter_cfg'
77  tag = self.prepare_common_write()
78  merged_file = os.path.join(self.result_path, self.output_file)
80 
81  if self.options.inputVDriftDB:
82  self.add_local_vdrift_db(self)
83  vdrift_db = "vDrift_segment"+ tag + ".db"
84  vdrift_db = os.path.join(self.result_path, vdrift_db)
85  self.process.dtVDriftSegmentWriter.vDriftAlgoConfig.rootFileName = "file:///" + merged_file
86  self.process.PoolDBOutputService.connect = 'sqlite_file:%s' % vdrift_db
87  self.process.source.firstRun = cms.untracked.uint32(self.options.run)
88  self.process.GlobalTag.globaltag = cms.string(str(self.options.globaltag))
89  self.write_pset_file()
90 
92  self.pset_name = 'dumpDBToFile_vdrift_cfg.py'
93  self.pset_template = 'CalibMuon.DTCalibration.dumpDBToFile_vdrift_cfg'
94  if self.options.input_dumpDB:
95  try:
96  test = self.result_path
97  self.load_options_command("write")
98  except:
99  pass
100  dbpath = os.path.abspath(self.options.input_dumpDB)
101  else:
102  crabtask = self.crabFunctions.CrabTask(crab_config = self.crab_config_filepath,
103  initUpdate = False)
104  tag = crabtask.crabConfig.Data.outputDatasetTag
105  dbpath = os.path.abspath( os.path.join(self.result_path,
106  "vDrift_segment"+ tag + ".db"))
107  self.prepare_common_dump(dbpath)
108  self.write_pset_file()
109 
111  # individual prepare functions for all tasks will be called in
112  # main implementation of all
113  self.all_commands=["submit", "check", "write", "dump"]
114 
115  ####################################################################
116  # Mean Timer #
117  ####################################################################
119  self.pset_name = 'dtVDriftMeanTimerCalibration_cfg.py'
120  self.pset_template = 'CalibMuon.DTCalibration.dtVDriftMeanTimerCalibration_cfg'
121  if self.options.datasettype == "Cosmics":
122  self.pset_template = 'CalibMuon.DTCalibration.dtVDriftMeanTimerCalibration_cosmics_cfg'
123 
125  self.process.GlobalTag.globaltag = self.options.globaltag
126  self.process.dtVDriftMeanTimerCalibration.rootFileName = self.output_file
127 
128  if self.options.inputCalibDB:
129  err = "Option inputCalibDB not available for meantimer."
130  err += "Maybe you want to use option inputTtrigDB"
131  raise ValueError(err)
132  self.prepare_common_submit()
133  if self.options.inputTtrigDB:
134  label = ''
135  if self.options.datasettype == "Cosmics":
136  label = 'cosmics'
137  connect = os.path.basename(self.options.inputTtrigDB)
138  self.addPoolDBESSource( process = self.process,
139  moduleName = 'tTrigDB',
140  record = 'DTTtrigRcd',
141  tag = 'ttrig',
142  connect = str("sqlite_file:%s" % connect),
143  label = label
144  )
145  self.input_files.append( os.path.abspath(self.options.inputTtrigDB) )
146  self.write_pset_file()
147 
149  self.load_options_command("submit")
150 
152  self.pset_name = 'dtVDriftMeanTimerWriter_cfg.py'
153  self.pset_template = 'CalibMuon.DTCalibration.dtVDriftMeanTimerWriter_cfg'
154  tag = self.prepare_common_write()
155  merged_file = os.path.join(self.result_path, self.output_file)
157 
158  if self.options.inputVDriftDB:
159  self.add_local_vdrift_db(self)
160  vdrift_db = "vDrift_meantimer" + tag + ".db"
161  vdrift_db = os.path.join(self.result_path, vdrift_db)
162  self.process.dtVDriftMeanTimerWriter.vDriftAlgoConfig.rootFileName = "file:///" + merged_file
163  self.process.PoolDBOutputService.connect = 'sqlite_file:%s' % vdrift_db
164  self.process.source.firstRun = cms.untracked.uint32(self.options.run)
165  self.process.GlobalTag.globaltag = cms.string(str(self.options.globaltag))
166  self.write_pset_file()
167 
169  self.pset_name = 'dumpDBToFile_vdrift_cfg.py'
170  self.pset_template = 'CalibMuon.DTCalibration.dumpDBToFile_vdrift_cfg'
171  if self.options.input_dumpDB:
172  try:
173  test = self.result_path
174  self.load_options_command("write")
175  except:
176  pass
177  dbpath = os.path.abspath(self.options.input_dumpDB)
178  else:
179  crabtask = self.crabFunctions.CrabTask(crab_config = self.crab_config_filepath,
180  initUpdate = False)
181  tag = crabtask.crabConfig.Data.outputDatasetTag
182  dbpath = os.path.abspath( os.path.join(self.result_path,
183  "vDrift_meantimer" + tag + ".db"))
184  self.prepare_common_dump(dbpath)
185  self.write_pset_file()
186 
188  # individual prepare functions for all tasks will be called in
189  # main implementation of all
190  self.all_commands=["submit", "check", "write", "dump"]
191 
192  ####################################################################
193  # CLI creation #
194  ####################################################################
195  @classmethod
196  def add_parser_options(cls, subparser_container):
197  vdrift_parser = subparser_container.add_parser( "vdrift",
198  #parents=[mutual_parent_parser, common_parent_parser],
199  help = "" ) # What does ttrig
200 
201  ################################################################
202  # Sub parser options for workflow modes #
203  ################################################################
204  vdrift_subparsers = vdrift_parser.add_subparsers( dest="workflow_mode",
205  help="Possible workflow modes",)
206  ## Add all workflow modes for ttrig
207  vdrift_segment_subparser = vdrift_subparsers.add_parser( "segment",
208  #parents=[mutual_parent_parser, common_parent_parser],
209  help = "" )
210  vdrift_meantimer_subparser = vdrift_subparsers.add_parser( "meantimer",
211  #parents=[mutual_parent_parser, common_parent_parser],
212  help = "" )
213  ################################################################
214  # Sub parser options for workflow mode segment #
215  ################################################################
216  vdrift_segment_subparsers = vdrift_segment_subparser.add_subparsers( dest="command",
217  help="Possible commands for segments")
218  vdrift_segment_submit_parser = vdrift_segment_subparsers.add_parser(
219  "submit",
220  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
221  super(DTvdriftWorkflow,cls).get_submission_options_parser(),
222  super(DTvdriftWorkflow,cls).get_local_input_db_options_parser(),
223  super(DTvdriftWorkflow,cls).get_input_db_options_parser()],
224  help = "Submit job to the GRID via crab3")
225  vdrift_segment_submit_parser.add_argument("--inputTtrigDB",
226  help="Local alternative calib ttrig db")
227 
228  vdrift_segment_check_parser = vdrift_segment_subparsers.add_parser(
229  "check",
230  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
231  super(DTvdriftWorkflow,cls).get_check_options_parser()],
232  help = "Check status of submitted jobs")
233 
234  vdrift_segment_write_parser = vdrift_segment_subparsers.add_parser(
235  "write",
236  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
237  super(DTvdriftWorkflow,cls).get_write_options_parser()
238  ],
239  help = "Write result from root output to text file")
240 
241  vdrift_segment_dump_parser = vdrift_segment_subparsers.add_parser(
242  "dump",
243  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
244  super(DTvdriftWorkflow,cls).get_dump_options_parser()],
245  help = "Dump database to text file")
246 
247  vdrift_segment_all_parser = vdrift_segment_subparsers.add_parser(
248  "all",
249  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
250  super(DTvdriftWorkflow,cls).get_submission_options_parser(),
251  super(DTvdriftWorkflow,cls).get_check_options_parser(),
252  super(DTvdriftWorkflow,cls).get_input_db_options_parser(),
253  super(DTvdriftWorkflow,cls).get_local_input_db_options_parser(),
254  super(DTvdriftWorkflow,cls).get_write_options_parser(),
255  super(DTvdriftWorkflow,cls).get_dump_options_parser()
256  ],
257  help = "Perform all steps: submit, check, write, dump in this order")
258  vdrift_segment_all_parser.add_argument("--inputTtrigDB",
259  help="Local alternative calib ttrig db")
260  ################################################################
261  # Sub parser options for workflow mode meantimer #
262  ################################################################
263  vdrift_meantimer_subparsers = vdrift_meantimer_subparser.add_subparsers( dest="command",
264  help="Possible commands for meantimers")
265  vdrift_meantimer_submit_parser = vdrift_meantimer_subparsers.add_parser(
266  "submit",
267  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
268  super(DTvdriftWorkflow,cls).get_submission_options_parser(),
269  super(DTvdriftWorkflow,cls).get_local_input_db_options_parser(),
270  super(DTvdriftWorkflow,cls).get_input_db_options_parser()],
271  help = "Submit job to the GRID via crab3")
272  vdrift_meantimer_submit_parser.add_argument("--inputTtrigDB",
273  help="Local alternative calib ttrig db")
274 
275  vdrift_meantimer_check_parser = vdrift_meantimer_subparsers.add_parser(
276  "check",
277  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
278  super(DTvdriftWorkflow,cls).get_check_options_parser()],
279  help = "Check status of submitted jobs")
280 
281  vdrift_meantimer_write_parser = vdrift_meantimer_subparsers.add_parser(
282  "write",
283  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
284  super(DTvdriftWorkflow,cls).get_write_options_parser()
285  ],
286  help = "Write result from root output to text file")
287 
288  vdrift_meantimer_dump_parser = vdrift_meantimer_subparsers.add_parser(
289  "dump",
290  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
291  super(DTvdriftWorkflow,cls).get_dump_options_parser()],
292  help = "Dump database to text file")
293 
294  vdrift_meantimer_all_parser = vdrift_meantimer_subparsers.add_parser(
295  "all",
296  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
297  super(DTvdriftWorkflow,cls).get_submission_options_parser(),
298  super(DTvdriftWorkflow,cls).get_check_options_parser(),
299  super(DTvdriftWorkflow,cls).get_input_db_options_parser(),
300  super(DTvdriftWorkflow,cls).get_local_input_db_options_parser(),
301  super(DTvdriftWorkflow,cls).get_write_options_parser(),
302  super(DTvdriftWorkflow,cls).get_dump_options_parser()
303  ],
304  help = "Perform all steps: submit, check, write, dump in this order")
305  vdrift_meantimer_all_parser.add_argument("--inputTtrigDB",
306  help="Local alternative calib ttrig db")
def prepare_meantimer_submit
Mean Timer #.
def loadCmsProcess
Definition: tools.py:56
def add_parser_options
CLI creation #.
#define str(s)