CMS 3D CMS Logo

DTVdriftWorkflow.py
Go to the documentation of this file.
1 import os
2 import logging
3 
4 import tools
5 import FWCore.ParameterSet.Config as cms
6 from DTWorkflow import DTWorkflow
7 
8 log = logging.getLogger(__name__)
9 
11  """ This class creates and performce / submits vdrift workflow jobs"""
12  def __init__(self, options):
13  # call parent constructor
14  super( DTvdriftWorkflow, self ).__init__( options )
15 
16  self.outpath_command_tag = "VdriftCalibration"
17  output_file_dict ={ "segment" : "DTVDriftHistos.root",
18  }
19  self.outpath_workflow_mode_dict = { "segment" : "Segments"
20  }
21  self.output_file = output_file_dict[self.options.workflow_mode]
22  self.output_files = [self.output_file]
23 
24  def prepare_workflow(self):
25  """ Generalized function to prepare workflow dependent on workflow mode"""
26  function_name = "prepare_" + self.options.workflow_mode + "_" + self.options.command
27 
28  try:
29  fill_function = getattr(self, function_name)
30  except AttributeError:
31  errmsg = "Class `{}` does not implement `{}`"
32  raise NotImplementedError( errmsg.format(my_cls.__class__.__name__,
33  method_name))
34  log.debug("Preparing workflow with function %s" % function_name)
35  # call chosen function
36  fill_function()
37 
39  self.pset_name = 'dtVDriftSegmentCalibration_cfg.py'
40  self.pset_template = 'CalibMuon.DTCalibration.dtVDriftSegmentCalibration_cfg'
41  if self.options.datasettype == "Cosmics":
42  self.pset_template = 'CalibMuon.DTCalibration.dtVDriftSegmentCalibration_cosmics_cfg'
43 
45  self.process.GlobalTag.globaltag = self.options.globaltag
46  self.process.dtVDriftSegmentCalibration.rootFileName = self.output_file
47 
48  if self.options.inputCalibDB:
49  err = "Option inputCalibDB not available for segment."
50  err += "Maybe you want to use option inputTtrigDB"
51  raise ValueError(err)
53  if self.options.inputTtrigDB:
54  label = ''
55  if self.options.datasettype == "Cosmics":
56  label = 'cosmics'
57  connect = os.path.basename(self.options.inputTtrigDB)
58  self.addPoolDBESSource( process = self.process,
59  moduleName = 'tTrigDB',
60  record = 'DTTtrigRcd',
61  tag = 'ttrig',
62  connect = str("sqlite_file:%s" % connect),
63  label = label
64  )
65  self.input_files.append( os.path.abspath(self.options.inputTtrigDB) )
66  self.write_pset_file()
67 
69  self.load_options_command("submit")
70 
72  self.pset_name = 'dtVDriftSegmentWriter_cfg.py'
73  self.pset_template = 'CalibMuon.DTCalibration.dtVDriftSegmentWriter_cfg'
74  tag = self.prepare_common_write()
75  merged_file = os.path.join(self.result_path, self.output_file)
77 
78  if self.options.inputVDriftDB:
79  self.add_local_vdrift_db(self)
80  vdrift_db = "vDrift_segment"+ tag + ".db"
81  vdrift_db = os.path.join(self.result_path, vdrift_db)
82  self.process.dtVDriftSegmentWriter.vDriftAlgoConfig.rootFileName = "file:///" + merged_file
83  self.process.PoolDBOutputService.connect = 'sqlite_file:%s' % vdrift_db
84  self.process.source.firstRun = cms.untracked.uint32(self.options.run)
85  self.process.GlobalTag.globaltag = cms.string(str(self.options.globaltag))
86  self.write_pset_file()
87 
89  self.pset_name = 'dumpDBToFile_vdrift_cfg.py'
90  self.pset_template = 'CalibMuon.DTCalibration.dumpDBToFile_vdrift_cfg'
91  if self.options.input_dumpDB:
92  try:
93  test = self.result_path
94  self.load_options_command("write")
95  except:
96  pass
97  dbpath = os.path.abspath(self.options.input_dumpDB)
98  else:
99  crabtask = self.crabFunctions.CrabTask(crab_config = self.crab_config_filepath,
100  initUpdate = False)
101  tag = crabtask.crabConfig.Data.outputDatasetTag
102  dbpath = os.path.abspath( os.path.join(self.result_path,
103  "vDrift_segment"+ tag + ".db"))
104  self.prepare_common_dump(dbpath)
105  self.write_pset_file()
106 
108  # individual prepare functions for all tasks will be called in
109  # main implementation of all
110  self.all_commands=["submit", "check", "write", "dump"]
111 
112  ####################################################################
113  # CLI creation #
114  ####################################################################
115  @classmethod
116  def add_parser_options(cls, subparser_container):
117  vdrift_parser = subparser_container.add_parser( "vdrift",
118  #parents=[mutual_parent_parser, common_parent_parser],
119  help = "" ) # What does ttrig
120 
121  ################################################################
122  # Sub parser options for workflow modes #
123  ################################################################
124  vdrift_subparsers = vdrift_parser.add_subparsers( dest="workflow_mode",
125  help="Possible workflow modes",)
126  ## Add all workflow modes for ttrig
127  vdrift_segment_subparser = vdrift_subparsers.add_parser( "segment",
128  #parents=[mutual_parent_parser, common_parent_parser],
129  help = "" )
130  ################################################################
131  # Sub parser options for workflow mode segment #
132  ################################################################
133  vdrift_segment_subparsers = vdrift_segment_subparser.add_subparsers( dest="command",
134  help="Possible commands for segments")
135  vdrift_segment_submit_parser = vdrift_segment_subparsers.add_parser(
136  "submit",
137  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
138  super(DTvdriftWorkflow,cls).get_submission_options_parser(),
139  super(DTvdriftWorkflow,cls).get_local_input_db_options_parser(),
140  super(DTvdriftWorkflow,cls).get_input_db_options_parser()],
141  help = "Submit job to the GRID via crab3")
142  vdrift_segment_submit_parser.add_argument("--inputTtrigDB",
143  help="Local alternative calib ttrig db")
144 
145  vdrift_segment_check_parser = vdrift_segment_subparsers.add_parser(
146  "check",
147  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
148  super(DTvdriftWorkflow,cls).get_check_options_parser()],
149  help = "Check status of submitted jobs")
150 
151  vdrift_segment_write_parser = vdrift_segment_subparsers.add_parser(
152  "write",
153  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
154  super(DTvdriftWorkflow,cls).get_write_options_parser()
155  ],
156  help = "Write result from root output to text file")
157 
158  vdrift_segment_dump_parser = vdrift_segment_subparsers.add_parser(
159  "dump",
160  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
161  super(DTvdriftWorkflow,cls).get_dump_options_parser()],
162  help = "Dump database to text file")
163 
164  vdrift_segment_all_parser = vdrift_segment_subparsers.add_parser(
165  "all",
166  parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
167  super(DTvdriftWorkflow,cls).get_submission_options_parser(),
168  super(DTvdriftWorkflow,cls).get_check_options_parser(),
169  super(DTvdriftWorkflow,cls).get_input_db_options_parser(),
170  super(DTvdriftWorkflow,cls).get_local_input_db_options_parser(),
171  super(DTvdriftWorkflow,cls).get_write_options_parser(),
172  super(DTvdriftWorkflow,cls).get_dump_options_parser()
173  ],
174  help = "Perform all steps: submit, check, write, dump in this order")
175  vdrift_segment_all_parser.add_argument("--inputTtrigDB",
176  help="Local alternative calib ttrig db")
def add_local_vdrift_db(self, local=False)
Definition: DTWorkflow.py:146
def addPoolDBESSource(process, moduleName, record, tag, connect='sqlite_file:', label='')
Definition: DTWorkflow.py:246
def load_options_command(self, command)
Definition: DTWorkflow.py:402
def get_common_options_parser(cls)
Definition: CLIHelper.py:5
def get_dump_options_parser(cls)
Definition: CLIHelper.py:133
def prepare_common_write(self, do_hadd=True)
Definition: DTWorkflow.py:210
def get_input_db_options_parser(cls)
Definition: CLIHelper.py:50
def crab_config_filepath(self)
Definition: CrabHelper.py:224
def get_local_input_db_options_parser(cls)
Definition: CLIHelper.py:65
def loadCmsProcess(psetPath)
Definition: tools.py:55
def add_parser_options(cls, subparser_container)
CLI creation #.
def prepare_common_submit(self)
Definition: DTWorkflow.py:192
def prepare_common_dump(self, db_path)
Definition: DTWorkflow.py:227
def write_pset_file(self)
Definition: DTWorkflow.py:375
def get_submission_options_parser(cls)
Definition: CLIHelper.py:79
def get_write_options_parser(cls)
Definition: CLIHelper.py:123
def get_check_options_parser(cls)
Definition: CLIHelper.py:111