1 from __future__
import print_function
2 from __future__
import absolute_import
6 from importlib
import import_module
12 log = logging.getLogger(__name__)
18 self.
crabFunctions = import_module(
'CalibMuon.DTCalibration.Workflow.Crabtools.crabFunctions')
25 log.info(
"Creating crab config")
29 if self.options.no_exec:
30 log.info(
"Runing with option no-exec exiting")
33 log.info(
"Submitting crab job")
35 log.info(
"crab job submitted. Waiting 120 seconds before first status call")
38 task = self.
crabFunctions.CrabTask(crab_config = full_crab_config_filename)
40 if task.state ==
"UNKNOWN":
43 success_states = (
'QUEUED',
'SUBMITTED',
"COMPLETED",
"FINISHED")
44 if task.state
in success_states:
45 log.info(
"Job in state %s" % task.state )
48 log.error(
"Job submission not successful, crab state:%s" % task.state)
49 raise RuntimeError(
"Job submission not successful, crab state:%s" % task.state)
56 if self.options.no_exec:
57 log.info(
"Nothing to check in no-exec mode")
59 for n_check
in range(self.options.max_checks):
61 if task.state
in (
"COMPLETED"):
62 print(
"Crab task complete. Getting output locally")
63 output_path = os.path.join( self.local_path,
"unmerged_results" )
64 self.get_output_files(task, output_path)
66 if task.state
in (
"SUBMITFAILED",
"FAILED"):
67 print(
"Crab task failed")
69 possible_job_states = [
"nUnsubmitted",
79 for jobstate
in possible_job_states:
80 njobs_in_state = getattr(task, jobstate)
81 if njobs_in_state > 0:
82 jobinfos+=
"%s: %d " % (jobstate[1:], njobs_in_state)
85 sys.stdout.write(
"\r")
87 sys.stdout.write(
"\r")
88 prompt_text =
"Check (%d/%d). Task state: %s (%s). Press q and enter to stop checks: " % (n_check,
89 self.options.max_checks, task.state, jobinfos)
90 user_input =
tools.stdinWait(prompt_text,
"", self.options.check_interval)
91 if user_input
in (
"q",
"Q"):
93 print(
"Task not completed after %d checks (%d minutes)" % ( self.options.max_checks,
94 int( self.options.check_interval / 60. )))
98 process = subprocess.Popen([
'voms-proxy-info',
'-timeleft'],
99 stdout=subprocess.PIPE)
100 stdout = process.communicate()[0]
101 if process.returncode != 0:
109 p = subprocess.Popen([shutil.which(
'voms-proxy-init'),
'--voms', voms,
'--valid',
'192:00'],
110 executable =
'/bin/bash',
111 stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
112 stdout = p.communicate(input=passphrase+
'\n')[0]
113 retcode = p.returncode
115 raise ProxyError(
'Proxy initialization command failed: %s'%stdout)
117 retcode = subprocess.call([shutil.which(
'voms-proxy-init'),
'--voms', voms,
'--valid',
'192:00'])
119 raise ProxyError(
'Proxy initialization command failed.')
123 """ Create a crab config object dependent on the chosen command option""" 124 from CalibMuon.DTCalibration.Workflow.Crabtools.crabConfigParser
import CrabConfigParser
126 """ Fill common options in crab config """ 130 raise ValueError(
'Sample contains "/" which is not allowed' )
132 self.
crab_config.set(
'General',
'workArea', self.local_path)
133 if self.options.no_log:
134 self.
crab_config.set(
'General',
'transferLogs',
'False' )
136 self.
crab_config.set(
'General',
'transferLogs',
'True' )
139 self.
crab_config.set(
'JobType',
'pluginName',
'Analysis' )
140 self.
crab_config.set(
'JobType',
'psetName', self.pset_path )
141 self.
crab_config.set(
'JobType',
'outputFiles', self.output_files)
143 self.
crab_config.set(
'JobType',
'inputFiles', self.input_files)
146 self.
crab_config.set(
'Data',
'inputDataset', self.options.datasetpath)
148 if self.options.datasettype ==
"MC":
149 self.
crab_config.set(
'Data',
'splitting',
'FileBased')
150 self.
crab_config.set(
'Data',
'unitsPerJob',
str(self.options.filesPerJob) )
152 self.
crab_config.set(
'Data',
'splitting',
'LumiBased')
153 self.
crab_config.set(
'Data',
'unitsPerJob',
str(self.options.lumisPerJob) )
154 if self.options.runselection:
157 ",".
join( self.options.runselection )
161 self.
crab_config.set(
'Data',
'outputDatasetTag', self.remote_out_path[
"outputDatasetTag"])
162 self.
crab_config.set(
'Data',
'outLFNDirBase', self.remote_out_path[
"outLFNDirBase"] )
166 self.
crab_config.set(
'Site',
'storageSite', self.options.output_site)
167 self.
crab_config.set(
'Site',
'whitelist', self.options.ce_white_list)
168 self.
crab_config.set(
'Site',
'blacklist', self.options.ce_black_list)
180 """ Write crab config file in working dir with label option as name """ 181 base_path = os.path.join( self.options.working_dir,self.local_path)
183 if not os.path.exists(base_path):
184 os.makedirs(base_path)
185 if os.path.exists(filename):
186 raise IOError(
"file %s alrady exits"%(filename))
188 log.info(
'created crab config file %s'%filename )
193 splitinfo = crabtask.crabConfig.Data.outputDatasetTag.split(
"_")
194 run, trial = splitinfo[0].
split(
"Run")[-1], splitinfo[1].
split(
"v")[-1]
195 if not self.options.run:
196 self.options.run =
int(run)
197 self.options.trail =
int(trial)
198 if not hasattr(self.options,
"datasetpath"):
199 self.options.datasetpath = crabtask.crabConfig.Data.inputDataset
200 if not hasattr(self.options,
"label"):
201 self.options.label = crabtask.crabConfig.General.requestName.split(
"_")[0]
205 """ Retuns a CrabController instance from cache or creates new 207 if self.
_crab is None:
218 warn_msg =
"No valid proxy, a default proxy without a specific" 219 warn_msg =
"VOGroup will be used" 221 log.warning(warn_msg)
227 if hasattr(self.options,
"crab_config_path"):
228 return self.options.crab_config_path
233 base_path = os.path.join( self.options.working_dir,self.local_path)
238 taskname = self.options.label +
"_" + self.options.workflow +
"_" 239 if hasattr( self.options,
"workflow_mode"):
240 taskname+= self.options.workflow_mode +
"_" 241 taskname +=
"run_" +
str(self.options.run) +
"_v" +
str(self.options.trial)
def fill_options_from_crab_config(self)
def create_crab_config(self)
This module extends the python configparser to create crab3 config files.
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def crab_config_filepath(self)
def split(sequence, size)
def voms_proxy_create(self, passphrase=None)
def submit_crab_task(self)
static std::string join(char **cmd)
def voms_proxy_time_left(self)
def write_crabConfig(self)
Exception for the VOMS proxy.
def crab_config_filename(self)