1 from __future__
import print_function
5 from importlib
import import_module
10 log = logging.getLogger(__name__)
16 self.
crabFunctions = import_module(
'CalibMuon.DTCalibration.Workflow.Crabtools.crabFunctions')
23 log.info(
"Creating crab config")
27 if self.options.no_exec:
28 log.info(
"Runing with option no-exec exiting")
31 log.info(
"Submitting crab job")
32 self.crab.submit(full_crab_config_filename)
33 log.info(
"crab job submitted. Waiting 30 seconds before first status call")
35 task = self.crabFunctions.CrabTask(crab_config = full_crab_config_filename)
37 success_states = (
'QUEUED',
'SUBMITTED',
"COMPLETED",
"FINISHED")
38 if task.state
in success_states:
39 log.info(
"Job in state %s" % task.state )
42 log.error(
"Job submission not successful, crab state:%s" % task.state)
43 raise RuntimeError(
"Job submission not successful, crab state:%s" % task.state)
49 if self.options.no_exec:
50 log.info(
"Nothing to check in no-exec mode")
52 for n_check
in range(self.options.max_checks):
54 if task.state
in (
"COMPLETED"):
55 print(
"Crab task complete. Getting output locally")
56 output_path = os.path.join( self.local_path,
"unmerged_results" )
57 self.get_output_files(task, output_path)
59 if task.state
in (
"SUBMITFAILED",
"FAILED"):
60 print(
"Crab task failed")
62 possible_job_states = [
"nUnsubmitted",
72 for jobstate
in possible_job_states:
73 njobs_in_state = getattr(task, jobstate)
74 if njobs_in_state > 0:
75 jobinfos+=
"%s: %d " % (jobstate[1:], njobs_in_state)
78 sys.stdout.write(
"\r")
80 sys.stdout.write(
"\r")
81 prompt_text =
"Check (%d/%d). Task state: %s (%s). Press q and enter to stop checks: " % (n_check,
82 self.options.max_checks, task.state, jobinfos)
83 user_input =
tools.stdinWait(prompt_text,
"", self.options.check_interval)
84 if user_input
in (
"q",
"Q"):
86 print(
"Task not completed after %d checks (%d minutes)" % ( self.options.max_checks,
87 int( self.options.check_interval / 60. )))
91 process = subprocess.Popen([
'voms-proxy-info',
'-timeleft'],
92 stdout=subprocess.PIPE,
93 stderr=subprocess.STDOUT)
94 stdout = process.communicate()[0]
95 if process.returncode != 0:
103 p = subprocess.Popen([
'voms-proxy-init',
'--voms', voms,
'--valid',
'192:00'],
104 stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
105 stdout = p.communicate(input=passphrase+
'\n')[0]
106 retcode = p.returncode
108 raise ProxyError(
'Proxy initialization command failed: %s'%stdout)
110 retcode = subprocess.call([
'voms-proxy-init',
'--voms', voms,
'--valid',
'192:00'])
112 raise ProxyError(
'Proxy initialization command failed.')
116 """ Create a crab config object dependent on the chosen command option""" 117 from CalibMuon.DTCalibration.Workflow.Crabtools.crabConfigParser
import CrabConfigParser
119 """ Fill common options in crab config """ 121 self.crab_config.add_section(
'General')
123 raise ValueError(
'Sample contains "/" which is not allowed' )
124 self.crab_config.set(
'General',
'requestName', self.
crab_taskname )
125 self.crab_config.set(
'General',
'workArea', self.local_path)
126 if self.options.no_log:
127 self.crab_config.set(
'General',
'transferLogs',
'False' )
129 self.crab_config.set(
'General',
'transferLogs',
'True' )
131 self.crab_config.add_section(
'JobType')
132 self.crab_config.set(
'JobType',
'pluginName',
'Analysis' )
133 self.crab_config.set(
'JobType',
'psetName', self.pset_path )
134 self.crab_config.set(
'JobType',
'outputFiles', self.output_files)
136 self.crab_config.set(
'JobType',
'inputFiles', self.input_files)
138 self.crab_config.add_section(
'Data')
139 self.crab_config.set(
'Data',
'inputDataset', self.options.datasetpath)
141 if self.options.datasettype ==
"MC":
142 self.crab_config.set(
'Data',
'splitting',
'FileBased')
143 self.crab_config.set(
'Data',
'unitsPerJob',
str(self.options.filesPerJob) )
145 self.crab_config.set(
'Data',
'splitting',
'LumiBased')
146 self.crab_config.set(
'Data',
'unitsPerJob',
str(self.options.lumisPerJob) )
147 if self.options.runselection:
148 self.crab_config.set(
"Data",
150 ",".
join( self.options.runselection )
153 self.crab_config.set(
'Data',
'publication',
False)
154 self.crab_config.set(
'Data',
'outputDatasetTag', self.remote_out_path[
"outputDatasetTag"])
155 self.crab_config.set(
'Data',
'outLFNDirBase', self.remote_out_path[
"outLFNDirBase"] )
158 self.crab_config.add_section(
'Site')
159 self.crab_config.set(
'Site',
'storageSite', self.options.output_site)
160 self.crab_config.set(
'Site',
'whitelist', self.options.ce_white_list)
161 self.crab_config.set(
'Site',
'blacklist', self.options.ce_black_list)
173 """ Write crab config file in working dir with label option as name """ 174 base_path = os.path.join( self.options.working_dir,self.local_path)
176 if not os.path.exists(base_path):
177 os.makedirs(base_path)
178 if os.path.exists(filename):
179 raise IOError(
"file %s alrady exits"%(filename))
180 self.crab_config.writeCrabConfig(filename)
181 log.info(
'created crab config file %s'%filename )
186 splitinfo = crabtask.crabConfig.Data.outputDatasetTag.split(
"_")
187 run, trial = splitinfo[0].
split(
"Run")[-1], splitinfo[1].
split(
"v")[-1]
188 if not self.options.run:
189 self.options.run =
int(run)
190 self.options.trail =
int(trial)
191 if not hasattr(self.options,
"datasetpath"):
192 self.options.datasetpath = crabtask.crabConfig.Data.inputDataset
193 if not hasattr(self.options,
"label"):
194 self.options.label = crabtask.crabConfig.General.requestName.split(
"_")[0]
198 """ Retuns a CrabController instance from cache or creates new 200 if self.
_crab is None:
201 if self.cert_info.voGroup:
202 self.
_crab = self.crabFunctions.CrabController(voGroup = self.cert_info.voGroup)
204 self.
_crab = self.crabFunctions.CrabController()
211 warn_msg =
"No valid proxy, a default proxy without a specific" 212 warn_msg =
"VOGroup will be used" 214 log.warning(warn_msg)
215 self.
_cert_info = self.crabFunctions.CertInfo()
220 if hasattr(self.options,
"crab_config_path"):
221 return self.options.crab_config_path
226 base_path = os.path.join( self.options.working_dir,self.local_path)
231 taskname = self.options.label +
"_" + self.options.workflow +
"_" 232 if hasattr( self.options,
"workflow_mode"):
233 taskname+= self.options.workflow_mode +
"_" 234 taskname +=
"run_" +
str(self.options.run) +
"_v" +
str(self.options.trial)
S & print(S &os, JobReport::InputFile const &f)
def fill_options_from_crab_config(self)
def create_crab_config(self)
This module extends the python configparser to create crab3 config files.
def crab_config_filepath(self)
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)
def crab_config_filename(self)