ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_orca.py
Revision: 1.64
Committed: Fri Sep 22 15:03:06 2006 UTC (18 years, 7 months ago) by gutsche
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_3_0_pre5, CRAB_1_3_0_pre4
Changes since 1.63: +2 -4 lines
Log Message:
working dir creation on OSG moved to mktemp

File Contents

# User Rev Content
1 nsmirnov 1.1 from JobType import JobType
2     from crab_logger import Logger
3     from crab_exceptions import *
4     from crab_util import *
5     import common
6 slacapra 1.53 import DataDiscovery
7     import DataLocation
8 slacapra 1.9 import Scram
9 slacapra 1.41 import TarBall
10 nsmirnov 1.1
11     import os, string, re
12 slacapra 1.53
13     ###Fabio
14 gutsche 1.50 import math
15 nsmirnov 1.1
16     class Orca(JobType):
17 gutsche 1.63 def __init__(self, cfg_params, ncjobs):
18 nsmirnov 1.1 JobType.__init__(self, 'ORCA')
19 slacapra 1.6 common.logger.debug(3,'ORCA::__init__')
20 nsmirnov 1.1
21     self.analisys_common_info = {}
22 corvo 1.36 # Marco.
23     self._params = {}
24     self.cfg_params = cfg_params
25 nsmirnov 1.1
26 gutsche 1.63 # number of jobs requested to be created, limit ojb splitting
27     self.ncjobs = ncjobs
28    
29 nsmirnov 1.1 log = common.logger
30    
31 slacapra 1.9 self.scram = Scram.Scram(cfg_params)
32 nsmirnov 1.1 scramArea = ''
33 corvo 1.20 self.additional_inbox_files = []
34     self.scriptExe = ''
35 slacapra 1.6
36 slacapra 1.9 self.version = self.scram.getSWVersion()
37 corvo 1.36 self.setParam_('application', self.version)
38 slacapra 1.9 common.analisys_common_info['sw_version'] = self.version
39 fanzago 1.33 common.analisys_common_info['copy_input_data'] = 0
40 gutsche 1.50
41     self.total_number_of_jobs = 0
42     self.job_number_of_events = 0
43 nsmirnov 1.1
44 slacapra 1.9 ### collect Data cards
45 nsmirnov 1.1 try:
46 fanzago 1.32 self.owner = cfg_params['ORCA.owner']
47 corvo 1.36 self.setParam_('owner', self.owner)
48 nsmirnov 1.3 log.debug(6, "Orca::Orca(): owner = "+self.owner)
49 fanzago 1.32 self.dataset = cfg_params['ORCA.dataset']
50 corvo 1.36 self.setParam_('dataset', self.dataset)
51 nsmirnov 1.3 log.debug(6, "Orca::Orca(): dataset = "+self.dataset)
52 slacapra 1.9 except KeyError:
53     msg = "Error: owner and/or dataset not defined "
54     raise CrabException(msg)
55    
56     self.dataTiers = []
57     try:
58 fanzago 1.32 tmpDataTiers = string.split(cfg_params['ORCA.data_tier'],',')
59 slacapra 1.9 for tmp in tmpDataTiers:
60     tmp=string.strip(tmp)
61     self.dataTiers.append(tmp)
62     pass
63     pass
64     except KeyError:
65     pass
66     log.debug(6, "Orca::Orca(): dataTiers = "+str(self.dataTiers))
67    
68     ## now the application
69     try:
70 fanzago 1.32 self.executable = cfg_params['ORCA.executable']
71 nsmirnov 1.3 log.debug(6, "Orca::Orca(): executable = "+self.executable)
72 corvo 1.36 self.setParam_('exe', self.executable)
73 slacapra 1.23 except KeyError:
74 slacapra 1.9 msg = "Error: executable not defined "
75     raise CrabException(msg)
76    
77     try:
78 fanzago 1.32 self.orcarc_file = cfg_params['ORCA.orcarc_file']
79 nsmirnov 1.3 log.debug(6, "Orca::Orca(): orcarc file = "+self.orcarc_file)
80 slacapra 1.23 if (not os.path.exists(self.orcarc_file)):
81     raise CrabException("User defined .orcarc file "+self.orcarc_file+" does not exist")
82     except KeyError:
83 slacapra 1.9 log.message("Using empty orcarc file")
84     self.orcarc_file = ''
85 nsmirnov 1.1
86 slacapra 1.9 # output files
87     try:
88 nsmirnov 1.1 self.output_file = []
89    
90 fanzago 1.32 tmp = cfg_params['ORCA.output_file']
91 nsmirnov 1.1 if tmp != '':
92 fanzago 1.32 tmpOutFiles = string.split(cfg_params['ORCA.output_file'],',')
93 nsmirnov 1.3 log.debug(7, 'Orca::Orca(): output files '+str(tmpOutFiles))
94 nsmirnov 1.1 for tmp in tmpOutFiles:
95     tmp=string.strip(tmp)
96     self.output_file.append(tmp)
97     pass
98    
99 slacapra 1.9 else:
100     log.message("No output file defined: only stdout/err will be available")
101 nsmirnov 1.1 pass
102     pass
103     except KeyError:
104 slacapra 1.9 log.message("No output file defined: only stdout/err will be available")
105 nsmirnov 1.1 pass
106    
107 corvo 1.20 # script_exe file as additional file in inputSandbox
108     try:
109 fanzago 1.32 self.scriptExe = cfg_params['ORCA.script_exe']
110 corvo 1.20 self.additional_inbox_files.append(self.scriptExe)
111     except KeyError:
112     pass
113     if self.scriptExe != '':
114     if os.path.isfile(self.scriptExe):
115     pass
116     else:
117     log.message("WARNING. file "+self.scriptExe+" not found")
118     sys.exit()
119    
120 slacapra 1.9 ## additional input files
121 nsmirnov 1.1 try:
122     tmpAddFiles = string.split(cfg_params['USER.additional_input_files'],',')
123     for tmp in tmpAddFiles:
124     tmp=string.strip(tmp)
125 slacapra 1.7 self.additional_inbox_files.append(tmp)
126 nsmirnov 1.1 pass
127     pass
128     except KeyError:
129     pass
130    
131     try:
132 slacapra 1.54 self.total_number_of_events = int(cfg_params['ORCA.total_number_of_events'])
133 nsmirnov 1.1 except KeyError:
134     msg = 'Must define total_number_of_events and job_number_of_events'
135     raise CrabException(msg)
136    
137     try:
138 slacapra 1.54 self.first_event = int(cfg_params['ORCA.first_event'])
139 nsmirnov 1.1 except KeyError:
140 gutsche 1.50 self.first_event = 0
141 nsmirnov 1.1 pass
142 nsmirnov 1.3 log.debug(6, "Orca::Orca(): total number of events = "+`self.total_number_of_events`)
143 slacapra 1.6 #log.debug(6, "Orca::Orca(): events per job = "+`self.job_number_of_events`)
144 gutsche 1.50 log.debug(6, "Orca::Orca(): first event = "+`self.first_event`)
145 slacapra 1.53
146     #DBSDLS-start
147     ## Initialize the variables that are extracted from DBS/DLS and needed in other places of the code
148     self.maxEvents=0 # max events available ( --> check the requested nb. of evts in Creator.py)
149     self.DBSPaths={} # all dbs paths requested ( --> input to the site local discovery script)
150     ## Perform the data location and discovery (based on DBS/DLS)
151     self.DataDiscoveryAndLocation(cfg_params)
152     #DBSDLS-end
153 nsmirnov 1.1
154 slacapra 1.41 self.TarBaller = TarBall.TarBall(self.executable, self.scram)
155     self.tgzNameWithPath = self.TarBaller.prepareTarBall()
156 nsmirnov 1.1
157 slacapra 1.10 try:
158     self.ML = int(cfg_params['USER.activate_monalisa'])
159     except KeyError:
160     self.ML = 0
161     pass
162 corvo 1.36
163     self.setTaskid_()
164 corvo 1.44 self.setParam_('taskId', self.cfg_params['taskId'])
165 corvo 1.36
166 nsmirnov 1.1 return
167    
168 gutsche 1.50 def split(self, jobParams):
169     """
170 slacapra 1.53 This method returns the list of orca specific job type items
171 gutsche 1.50 needed to run the jobs
172     """
173     common.jobDB.load()
174     njobs = self.total_number_of_jobs
175     # create the empty structure
176     for i in range(njobs):
177     jobParams.append("")
178    
179     # fill the both the list and the DB (part of the code taken from jobsToDB)
180     firstEvent = self.first_event
181 slacapra 1.58 lastJobsNumberOfEvents = str(self.job_number_of_events)
182 gutsche 1.50 # last jobs is different...
183     for job in range(njobs-1):
184 slacapra 1.58 jobParams[job] = [str(firstEvent), str(lastJobsNumberOfEvents)]
185 gutsche 1.50 common.jobDB.setArguments(job, jobParams[job])
186 gutsche 1.61 common.jobDB.setDestination(job, self.sites)
187 gutsche 1.50 firstEvent += self.job_number_of_events
188    
189     # this is the last job
190     lastJobsNumberOfEvents = (self.total_number_of_events + self.first_event) - firstEvent
191     status = common.jobDB.status(njobs - 1)
192 slacapra 1.58 jobParams[njobs - 1] = [str(firstEvent), str(lastJobsNumberOfEvents)]
193 gutsche 1.50 common.jobDB.setArguments(njobs - 1, jobParams[njobs - 1])
194    
195     if (lastJobsNumberOfEvents!=self.job_number_of_events):
196     common.logger.message(str(self.total_number_of_jobs-1)+' jobs will be created for '+str(self.job_number_of_events)+' events each plus 1 for '+str(lastJobsNumberOfEvents)+' events for a total of '+str(self.job_number_of_events*(self.total_number_of_jobs-1)+lastJobsNumberOfEvents)+' events')
197     else:
198     common.logger.message(str(self.total_number_of_jobs)+' jobs will be created for '+str(self.job_number_of_events)+' events each for a total of '+str(self.job_number_of_events*(self.total_number_of_jobs-1)+lastJobsNumberOfEvents)+' events')
199    
200     common.jobDB.save()
201     return
202    
203     def getJobTypeArguments(self, nj, sched):
204     params = common.jobDB.arguments(nj)
205    
206 slacapra 1.53 if sched=="EDG" or sched=="CONDOR" or sched=="GRID":
207 gutsche 1.50 parString = "" + str(params[0])+' '+str(params[1])
208     elif sched=="BOSS":
209     parString = "" + str(params[0])+' '+str(params[1])
210     else:
211     return ""
212     return parString
213    
214     def numberOfJobs(self):
215     first_event = self.first_event
216     maxAvailableEvents = int(self.maxEvents)
217     common.logger.debug(1,"Available events: "+str(maxAvailableEvents))
218     if first_event>=maxAvailableEvents:
219     raise CrabException('First event is bigger than maximum number of available events!')
220    
221     try:
222     n = self.total_number_of_events
223     if n == 'all': n = '-1'
224     if n == '-1':
225     tot_num_events = (maxAvailableEvents - first_event)
226     common.logger.debug(1,"Analysing all available events "+str(tot_num_events))
227     else:
228     if maxAvailableEvents<(int(n)+ first_event): # + self.first_event):
229     raise CrabException('(First event + total events)='+str(int(n)+first_event)+' is bigger than maximum number of available events '+str(maxAvailableEvents)+' !! Use "total_number_of_events=-1" to analyze to whole dataset')
230     tot_num_events = int(n)
231     except KeyError:
232     common.logger.message("total_number_of_events not defined, set it to maximum available")
233     tot_num_events = (maxAvailableEvents - first_event)
234     pass
235     common.logger.message("Total number of events to be analyzed: "+str(self.total_number_of_events))
236    
237    
238     # read user directives
239     eventPerJob=0
240     try:
241 slacapra 1.54 eventPerJob = self.cfg_params['ORCA.job_number_of_events']
242 gutsche 1.50 except KeyError:
243     pass
244    
245     jobsPerTask=0
246     try:
247 slacapra 1.54 jobsPerTask = int(self.cfg_params['ORCA.total_number_of_jobs'])
248 gutsche 1.50 except KeyError:
249     pass
250    
251     # If both the above set, complain and use event per jobs
252     if eventPerJob>0 and jobsPerTask>0:
253     msg = 'Warning. '
254     msg += 'job_number_of_events and total_number_of_jobs are both defined '
255     msg += 'Using job_number_of_events.'
256     common.logger.message(msg)
257     jobsPerTask = 0
258     if eventPerJob==0 and jobsPerTask==0:
259     msg = 'Warning. '
260     msg += 'job_number_of_events and total_number_of_jobs are not defined '
261     msg += 'Creating just one job for all events.'
262     common.logger.message(msg)
263     jobsPerTask = 1
264    
265     # first case: events per job defined
266     if eventPerJob>0:
267     n=eventPerJob
268     #if n == 'all' or n == '-1' or (int(n)>self.total_number_of_events and self.total_number_of_events>0):
269     if n == 'all' or n == '-1' or (int(n)>tot_num_events and tot_num_events>0):
270     common.logger.message("Asking more events than available: set it to maximum available")
271     job_num_events = tot_num_events
272     tot_num_jobs = 1
273     else:
274     job_num_events = int(n)
275     tot_num_jobs = int((tot_num_events-1)/job_num_events)+1
276    
277     elif jobsPerTask>0:
278     common.logger.debug(2,"total number of events: "+str(tot_num_events)+" JobPerTask "+str(jobsPerTask))
279     job_num_events = int(math.floor((tot_num_events)/jobsPerTask))
280     tot_num_jobs = jobsPerTask
281    
282     # should not happen...
283     else:
284     raise CrabException('Something wrong with splitting')
285    
286     common.logger.debug(2,"total number of events: "+str(tot_num_events)+" events per job: "+str(job_num_events))
287    
288     #used by jobsToDB for logs
289     self.job_number_of_events = job_num_events
290     self.total_number_of_jobs = tot_num_jobs
291     return tot_num_jobs
292    
293    
294     def jobsToDB(self, nJobs):
295     """
296 slacapra 1.53 Fill the DB with proper entries for ORCA
297 gutsche 1.50 """
298    
299     firstEvent = self.first_event
300     lastJobsNumberOfEvents = self.job_number_of_events
301    
302     # last jobs is different...
303     for job in range(nJobs-1):
304     common.jobDB.setFirstEvent(job, firstEvent)
305     common.jobDB.setMaxEvents(job, self.job_number_of_events)
306     firstEvent=firstEvent+self.job_number_of_events
307    
308     # this is the last job
309     common.jobDB.setFirstEvent(nJobs-1, firstEvent)
310     lastJobsNumberOfEvents= (self.total_number_of_events+self.first_event)-firstEvent
311     common.jobDB.setMaxEvents(nJobs-1, lastJobsNumberOfEvents)
312    
313     if (lastJobsNumberOfEvents!=self.job_number_of_events):
314     common.logger.message(str(self.total_number_of_jobs-1)+' jobs will be created for '+str(self.job_number_of_events)+' events each plus 1 for '+str(lastJobsNumberOfEvents)+' events for a total of '+str(self.job_number_of_events*(self.total_number_of_jobs-1)+lastJobsNumberOfEvents)+' events')
315     else:
316     common.logger.message(str(self.total_number_of_jobs)+' jobs will be created for '+str(self.job_number_of_events)+' events each for a total of '+str(self.job_number_of_events*(self.total_number_of_jobs-1)+lastJobsNumberOfEvents)+' events')
317    
318     return
319    
320    
321 nsmirnov 1.4 def wsSetupEnvironment(self, nj):
322     """
323     Returns part of a job script which prepares
324     the execution environment for the job 'nj'.
325     """
326    
327     # Prepare JobType-independent part
328 spiga 1.46 txt = ''
329    
330     ## OLI_Daniele at this level middleware already known
331    
332     txt += 'if [ $middleware == LCG ]; then \n'
333     txt += self.wsSetupCMSLCGEnvironment_()
334     txt += 'elif [ $middleware == OSG ]; then\n'
335 gutsche 1.64 txt += ' WORKING_DIR=`/bin/mktemp -d $OSG_WN_TMP/cms_XXXXXXXXXXXX`\n'
336     txt += ' echo "Created working directory: $WORKING_DIR"\n'
337 slacapra 1.53 txt += ' if [ ! -d $WORKING_DIR ] ;then\n'
338 gutsche 1.52 txt += ' echo "SET_CMS_ENV 10016 ==> OSG $WORKING_DIR could not be created on WN `hostname`"\n'
339     txt += ' echo "JOB_EXIT_STATUS = 10016"\n'
340     txt += ' echo "JobExitCode=10016" | tee -a $RUNTIME_AREA/$repo\n'
341     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
342 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
343     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
344     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
345 slacapra 1.53 txt += ' exit 1\n'
346     txt += ' fi\n'
347 spiga 1.46 txt += '\n'
348     txt += ' echo "Change to working directory: $WORKING_DIR"\n'
349     txt += ' cd $WORKING_DIR\n'
350     txt += self.wsSetupCMSOSGEnvironment_()
351     txt += 'fi\n'
352 nsmirnov 1.4
353 fanzago 1.16 # Prepare JobType-specific part
354     scram = self.scram.commandName()
355     txt += '\n\n'
356     txt += 'echo "### SPECIFIC JOB SETUP ENVIRONMENT ###"\n'
357     txt += scram+' project ORCA '+self.version+'\n'
358     txt += 'status=$?\n'
359     txt += 'if [ $status != 0 ] ; then\n'
360 gutsche 1.52 txt += ' echo "SET_EXE_ENV 10034 ==>ERROR ORCA '+self.version+' not found on `hostname`" \n'
361 spiga 1.46 txt += ' echo "JOB_EXIT_STATUS = 10034"\n'
362     txt += ' echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
363     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
364 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
365     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
366     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
367 spiga 1.46 ## OLI_Daniele
368 slacapra 1.53 txt += ' if [ $middleware == OSG ]; then \n'
369     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
370     txt += ' cd $RUNTIME_AREA\n'
371     txt += ' /bin/rm -rf $WORKING_DIR\n'
372     txt += ' if [ -d $WORKING_DIR ] ;then\n'
373 gutsche 1.55 txt += ' echo "SET_CMS_ENV 10018 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after ORCA not found on `hostname`"\n'
374 gutsche 1.52 txt += ' echo "JOB_EXIT_STATUS = 10018"\n'
375     txt += ' echo "JobExitCode=10018" | tee -a $RUNTIME_AREA/$repo\n'
376     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
377 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
378     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
379     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
380 slacapra 1.53 txt += ' fi\n'
381     txt += ' fi \n'
382     txt += ' exit 1\n'
383 fanzago 1.16 txt += 'fi \n'
384     txt += 'echo "ORCA_VERSION = '+self.version+'"\n'
385     txt += 'cd '+self.version+'\n'
386 fanzago 1.29 ### needed grep for bug in scramv1 ###
387 spiga 1.46
388 fanzago 1.35 #txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
389 fanzago 1.16
390 slacapra 1.9 # Handle the arguments:
391     txt += "\n"
392 mkirn 1.60 # txt += "## ARGUMNETS: $1 Job Number\n"
393     # txt += "## ARGUMNETS: $2 First Event for this job\n"
394     # txt += "## ARGUMNETS: $3 Max Event for this job\n"
395     txt += "## ARGUMENTS: ${args[0]} Job Number\n"
396     txt += "## ARGUMENTS: ${args[1]} First Event for this job\n"
397     txt += "## ARGUMENTS: ${args[2]} Max Event for this job\n"
398 slacapra 1.9 txt += "\n"
399 mkirn 1.60 # txt += "narg=$#\n"
400     # txt += "NJob=$1\n"
401     # txt += "FirstEvent=$2\n"
402     # txt += "MaxEvents=$3\n"
403     txt += "NJob=${args[0]}\n"
404     txt += "FirstEvent=${args[1]}\n"
405     txt += "MaxEvents=${args[2]}\n"
406     txt += "if [ $nargs -lt 3 ]\n"
407 slacapra 1.9 txt += "then\n"
408 mkirn 1.60 txt += " echo 'SET_EXE_ENV 50113 ==> ERROR Too few arguments' +$nargs+ \n"
409 corvo 1.38 txt += ' echo "JOB_EXIT_STATUS = 50113"\n'
410     txt += ' echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
411 corvo 1.28 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
412 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
413     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
414     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
415 spiga 1.46
416     ## OLI_Daniele
417 slacapra 1.53 txt += ' if [ $middleware == OSG ]; then \n'
418     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
419     txt += ' cd $RUNTIME_AREA\n'
420     txt += ' /bin/rm -rf $WORKING_DIR\n'
421     txt += ' if [ -d $WORKING_DIR ] ;then\n'
422 gutsche 1.52 txt += ' echo "SET_EXE_ENV 50114 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Too few arguments for CRAB job wrapper"\n'
423     txt += ' echo "JOB_EXIT_STATUS = 50114"\n'
424     txt += ' echo "JobExitCode=50114" | tee -a $RUNTIME_AREA/$repo\n'
425     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
426 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
427     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
428     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
429 slacapra 1.53 txt += ' fi\n'
430     txt += ' fi \n'
431 gutsche 1.52 txt += " exit 1\n"
432 slacapra 1.9 txt += "fi\n"
433 fanzago 1.16 txt += "\n"
434 spiga 1.46
435 nsmirnov 1.4 # Prepare job-specific part
436     job = common.job_list[nj]
437     orcarc = os.path.basename(job.configFilename())
438     txt += '\n'
439 slacapra 1.53 #DBSDLS-start
440     #### site-local catalogue discovery mechanism:
441     ## check that the site configuration file exists
442     txt += 'echo "### Site Local Catalogue Discovery ### "\n'
443     txt += 'if [ $middleware == LCG ]; then \n'
444     txt += ' if [ -f $VO_CMS_SW_DIR/cms_site_config ]; then \n'
445     txt += ' dbsdls_cms_site_config=$VO_CMS_SW_DIR/cms_site_config\n'
446     txt += ' else\n'
447     txt += ' echo "Site Local Catalogue Discovery Failed: No site configuration file $VO_CMS_SW_DIR/cms_site_config !" \n'
448     txt += ' echo "JOB_EXIT_STATUS = 10037"\n'
449     txt += ' echo "JobExitCode=10037" | tee -a $RUNTIME_AREA/$repo\n'
450     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
451 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
452     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
453     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
454 slacapra 1.53 txt += ' exit 1\n'
455     txt += ' fi \n'
456     txt += 'elif [ $middleware == OSG ]; then\n'
457     txt += ' if [ -f $GRID3_APP_DIR/cmssoft/cms_site_config ]; then \n'
458     txt += ' dbsdls_cms_site_config=$GRID3_APP_DIR/cmssoft/cms_site_config\n'
459     txt += ' elif [ -f $OSG_APP/cmssoft/cms_site_config ]; then \n'
460     txt += ' dbsdls_cms_site_config=$OSG_APP/cmssoft/cms_site_config\n'
461     txt += ' else\n'
462     txt += ' echo "Site Local Catalogue Discovery Failed: No site configuration file $GRID3_APP_DIR/cmssoft/cms_site_config or $OSG_APP/cmssoft/cms_site_config !" \n'
463     txt += ' echo "JOB_EXIT_STATUS = 10037"\n'
464     txt += ' echo "JobExitCode=10037" | tee -a $RUNTIME_AREA/$repo\n'
465     txt += ' if [ $middleware == OSG ]; then \n'
466     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
467     txt += ' cd $RUNTIME_AREA\n'
468     txt += ' /bin/rm -rf $WORKING_DIR\n'
469     txt += ' if [ -d $WORKING_DIR ] ;then\n'
470     txt += ' echo "SET_EXE_ENV 10019 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after No site configuration file $GRID3_APP_DIR/cmssoft/cms_site_config or $OSG_APP/cmssoft/cms_site_config"\n'
471     txt += ' echo "JOB_EXIT_STATUS = 10019"\n'
472     txt += ' echo "JobExitCode=10019" | tee -a $RUNTIME_AREA/$repo\n'
473     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
474 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
475     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
476     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
477 slacapra 1.53 txt += ' fi\n'
478     txt += ' fi \n'
479     txt += ' exit 1\n'
480     txt += ' fi \n'
481 slacapra 1.22 txt += 'fi\n'
482 slacapra 1.53 txt += 'echo "Site Local Catalog Discovery, selected site configuration: $dbsdls_cms_site_config"\n'
483     ## look for a site local script sent as inputsandbox otherwise use the default one under $VO_CMS_SW_DIR for LCG or $GRID3_APP_DIR/cmssoft or $OSG_APP/cmssoft for OSG
484     txt += 'if [ -f $RUNTIME_AREA/cms_site_catalogue.sh ]; then \n'
485     txt += ' sitelocalscript=$RUNTIME_AREA/cms_site_catalogue.sh \n'
486     txt += 'elif [ $middleware == LCG ]; then \n'
487     txt += ' if [ -f $VO_CMS_SW_DIR/cms_site_catalogue.sh ]; then \n'
488     txt += ' sitelocalscript=$VO_CMS_SW_DIR/cms_site_catalogue.sh \n'
489     txt += ' else \n'
490     txt += ' echo "Site Local Catalogue Discovery Failed: No site local script cms_site_catalogue.sh !"\n'
491     txt += ' echo "JOB_EXIT_STATUS = 10038"\n'
492     txt += ' echo "JobExitCode=10038" | tee -a $RUNTIME_AREA/$repo\n'
493     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
494 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
495     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
496     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
497 slacapra 1.53 txt += ' exit 1\n'
498     txt += ' fi \n'
499     txt += 'elif [ $middleware == OSG ]; then\n'
500     txt += ' if [ -f $GRID3_APP_DIR/cmssoft/cms_site_catalogue.sh ]; then \n'
501     txt += ' sitelocalscript=$GRID3_APP_DIR/cmssoft/cms_site_catalogue.sh\n'
502     txt += ' elif [ -f $OSG_APP/cmssoft/cms_site_catalogue.sh ]; then \n'
503     txt += ' sitelocalscript=$OSG_APP/cmssoft/cms_site_catalogue.sh\n'
504     txt += ' else\n'
505     txt += ' echo "Site Local Catalogue Discovery Failed: No site local script cms_site_catalogue.sh !"\n'
506     txt += ' echo "JOB_EXIT_STATUS = 10038"\n'
507     txt += ' echo "JobExitCode=10038" | tee -a $RUNTIME_AREA/$repo\n'
508     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
509 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
510     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
511     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
512 slacapra 1.53 txt += ' if [ $middleware == OSG ]; then \n'
513     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
514     txt += ' cd $RUNTIME_AREA\n'
515     txt += ' /bin/rm -rf $WORKING_DIR\n'
516     txt += ' if [ -d $WORKING_DIR ] ;then\n'
517     txt += ' echo "SET_EXE_ENV 10014 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after No site local script cms_site_catalogue.sh"\n'
518     txt += ' echo "JOB_EXIT_STATUS = 10014"\n'
519     txt += ' echo "JobExitCode=10014" | tee -a $RUNTIME_AREA/$repo\n'
520     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
521 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
522     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
523     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
524 slacapra 1.53 txt += ' fi\n'
525     txt += ' fi \n'
526     txt += ' exit 1\n'
527     txt += ' fi \n'
528 nsmirnov 1.4 txt += 'fi\n'
529 slacapra 1.53 txt += 'echo "Site Local Catalog Discovery, selected local script: $sitelocalscript"\n'
530     ## execute the site local configuration script with the user requied data as input
531     inputdata=string.join(self.DBSPaths,' ')
532     sitecatalog_cmd='$sitelocalscript -c $dbsdls_cms_site_config '+inputdata
533     txt += sitecatalog_cmd+'\n'
534     txt += 'sitestatus=$?\n'
535     txt += 'if [ ! -f inputurl_orcarc ] || [ $sitestatus -ne 0 ]; then\n'
536     txt += ' echo "Site Local Catalogue Discovery Failed: exiting with $sitestatus"\n'
537     txt += ' echo "JOB_EXIT_STATUS = 1"\n'
538     txt += ' echo "JobExitCode=10039" | tee -a $RUNTIME_AREA/$repo\n'
539     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
540 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
541     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
542     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
543 slacapra 1.53 txt += ' if [ $middleware == OSG ]; then \n'
544     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
545     txt += ' cd $RUNTIME_AREA\n'
546     txt += ' /bin/rm -rf $WORKING_DIR\n'
547     txt += ' if [ -d $WORKING_DIR ] ;then\n'
548     txt += ' echo "SET_EXE_ENV 10013 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Site Local Catalogue Discovery Failed: exiting with $sitestatus"\n'
549     txt += ' echo "JOB_EXIT_STATUS = 10013"\n'
550     txt += ' echo "JobExitCode=10013" | tee -a $RUNTIME_AREA/$repo\n'
551     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
552 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
553     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
554     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
555 slacapra 1.53 txt += ' fi\n'
556     txt += ' fi \n'
557     txt += ' exit 1\n'
558     txt += 'fi \n'
559     ## append the orcarc fragment about the Input catalogues to the .orcarc
560     txt += 'cp $RUNTIME_AREA/'+orcarc+' .orcarc\n'
561     txt +=' cat inputurl_orcarc >> .orcarc\n'
562     #DBSDLS-end
563 fanzago 1.26
564     if len(self.additional_inbox_files) > 0:
565     for file in self.additional_inbox_files:
566 fanzago 1.34 file = os.path.basename(file)
567 fanzago 1.26 txt += 'if [ -e $RUNTIME_AREA/'+file+' ] ; then\n'
568 fanzago 1.34 txt += ' cp $RUNTIME_AREA/'+file+' .\n'
569     txt += ' chmod +x '+file+'\n'
570 fanzago 1.26 txt += 'fi\n'
571 spiga 1.46 pass
572 fanzago 1.26
573 spiga 1.46 ### OLI_DANIELE
574 fanzago 1.16 txt += "echo 'SET_EXE_ENV 0 ==> job setup ok'\n"
575     txt += 'echo "### END JOB SETUP ENVIRONMENT ###"\n\n'
576 slacapra 1.9
577 slacapra 1.10 txt += 'echo "FirstEvent=$FirstEvent" >> .orcarc\n'
578 afanfani 1.24 txt += 'echo "MaxEvents=$MaxEvents" >> .orcarc\n'
579 slacapra 1.10 if self.ML:
580     txt += 'echo "MonalisaJobId=$NJob" >> .orcarc\n'
581    
582     txt += '\n'
583     txt += 'echo "***** cat .orcarc *********"\n'
584     txt += 'cat .orcarc\n'
585     txt += 'echo "****** end .orcarc ********"\n'
586 nsmirnov 1.4 return txt
587    
588     def wsBuildExe(self, nj):
589     """
590     Put in the script the commands to build an executable
591     or a library.
592     """
593    
594     txt = ""
595    
596 fanzago 1.12 if os.path.isfile(self.tgzNameWithPath):
597 fanzago 1.42 txt += 'echo "tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'"\n'
598     txt += 'tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
599 nsmirnov 1.4 txt += 'untar_status=$? \n'
600     txt += 'if [ $untar_status -ne 0 ]; then \n'
601 fanzago 1.34 txt += ' echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
602     txt += ' echo "JOB_EXIT_STATUS = $untar_status" \n'
603 gutsche 1.52 txt += ' echo "JobExitCode=$untar_status" | tee -a $repo\n'
604 spiga 1.46
605     ### OLI_DANIELE
606     txt += ' if [ $middleware == OSG ]; then \n'
607     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
608     txt += ' cd $RUNTIME_AREA\n'
609     txt += ' /bin/rm -rf $WORKING_DIR\n'
610     txt += ' if [ -d $WORKING_DIR ] ;then\n'
611 gutsche 1.52 txt += ' echo "SET_EXE 50999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after Untarring .tgz file failed"\n'
612     txt += ' echo "JOB_EXIT_STATUS = 50999"\n'
613     txt += ' echo "JobExitCode=50999" | tee -a $RUNTIME_AREA/$repo\n'
614     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
615 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
616     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
617     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
618 spiga 1.46 txt += ' fi\n'
619     txt += ' fi \n'
620     txt += ' \n'
621 gutsche 1.52 txt += ' exit 1 \n'
622 nsmirnov 1.4 txt += 'else \n'
623 fanzago 1.34 txt += ' echo "Successful untar" \n'
624 nsmirnov 1.4 txt += 'fi \n'
625     # TODO: what does this code do here ?
626     # SL check that lib/Linux__... is present
627 slacapra 1.9 txt += 'mkdir -p lib/${SCRAM_ARCH} \n'
628 nsmirnov 1.4 pass
629 fanzago 1.37 txt += 'eval `'+self.scram.commandName()+' runtime -sh |grep -v SCRAMRT_LSB_JOBNAME`'+'\n'
630 nsmirnov 1.4
631     return txt
632    
633     def wsRenameOutput(self, nj):
634     """
635     Returns part of a job script which renames the produced files.
636     """
637 slacapra 1.9
638 nsmirnov 1.4 txt = '\n'
639 gutsche 1.52 txt += '# directory content\n'
640     txt += 'ls \n'
641 fanzago 1.15 file_list = ''
642 slacapra 1.9 for fileWithSuffix in self.output_file:
643     output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
644 slacapra 1.48 file_list=file_list+output_file_num+' '
645 fanzago 1.26 txt += '\n'
646 spiga 1.17 txt += 'ls '+fileWithSuffix+'\n'
647 fanzago 1.57 #txt += 'exe_result=$?\n'
648     txt += 'ls_result=$?\n'
649     #txt += 'if [ $exe_result -ne 0 ] ; then\n'
650     txt += 'if [ $ls_result -ne 0 ] ; then\n'
651     txt += ' echo "ERROR: Problem with output file"\n'
652     #txt += ' echo "ERROR: No output file to manage"\n'
653     #txt += ' echo "JOB_EXIT_STATUS = $exe_result"\n'
654     #txt += ' echo "JobExitCode=60302" | tee -a $RUNTIME_AREA/$repo\n'
655     #txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
656     # txt += 'exe_result=$?\n'
657     # txt += 'if [ $exe_result -ne 0 ] ; then\n'
658     # txt += ' echo "ERROR: No output file to manage"\n'
659     # txt += ' echo "JOB_EXIT_STATUS = $exe_result"\n'
660     # txt += ' echo "JobExitCode=60302" | tee -a $RUNTIME_AREA/$repo\n'
661     # txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
662     # txt += ' rm -f $RUNTIME_AREA/$repo \n'
663     # txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
664     # txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
665 gutsche 1.55
666 spiga 1.46 ### OLI_DANIELE
667 gutsche 1.52 if common.scheduler.boss_scheduler_name == 'condor_g':
668     txt += ' if [ $middleware == OSG ]; then \n'
669     txt += ' echo "prepare dummy output file"\n'
670     txt += ' echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
671     txt += ' fi \n'
672 spiga 1.17 txt += 'else\n'
673 fanzago 1.34 txt += ' cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
674 fanzago 1.25 txt += 'fi\n'
675 spiga 1.46
676    
677 fanzago 1.40 txt += 'cd $RUNTIME_AREA\n'
678 fanzago 1.15 file_list=file_list[:-1]
679 slacapra 1.48 txt += 'file_list="'+file_list+'"\n'
680 spiga 1.46 ### OLI_DANIELE
681     txt += 'if [ $middleware == OSG ]; then\n'
682     txt += ' cd $RUNTIME_AREA\n'
683     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
684     txt += ' /bin/rm -rf $WORKING_DIR\n'
685     txt += ' if [ -d $WORKING_DIR ] ;then\n'
686 gutsche 1.52 txt += ' echo "SET_EXE 60999 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after cleanup of WN"\n'
687     txt += ' echo "JOB_EXIT_STATUS = 60999"\n'
688     txt += ' echo "JobExitCode=60999" | tee -a $RUNTIME_AREA/$repo\n'
689     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
690 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
691     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
692     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
693 spiga 1.46 txt += ' fi\n'
694     txt += 'fi\n'
695     txt += '\n'
696    
697 nsmirnov 1.4 return txt
698    
699 nsmirnov 1.1 def executableName(self):
700 corvo 1.20 if self.scriptExe != '':
701     return "./" + os.path.basename(self.scriptExe)
702     else:
703     return self.executable
704 nsmirnov 1.1
705 slacapra 1.53 #DBSDLS-start
706     def DataDiscoveryAndLocation(self, cfg_params):
707    
708     fun = "Orca::DataDiscoveryAndLocation()"
709 nsmirnov 1.1
710 slacapra 1.53 ## Contact the DBS
711     try:
712     self.pubdata=DataDiscovery.DataDiscovery(self.owner,
713     self.dataset,
714     self.dataTiers,
715     cfg_params)
716     self.pubdata.fetchDBSInfo()
717 nsmirnov 1.1
718 slacapra 1.53 except DataDiscovery.NotExistingDatasetError, ex :
719 slacapra 1.62 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
720     raise CrabException(msg)
721 nsmirnov 1.1
722 slacapra 1.53 except DataDiscovery.NoDataTierinProvenanceError, ex :
723 slacapra 1.62 msg = 'ERROR ***: failed Data Discovery in DBS : %s'%ex.getErrorMessage()
724     raise CrabException(msg)
725 slacapra 1.53 except DataDiscovery.DataDiscoveryError, ex:
726 slacapra 1.62 msg = 'ERROR ***: failed Data Discovery in DBS %s'%ex.getErrorMessage()
727     raise CrabException(msg)
728 nsmirnov 1.3
729 slacapra 1.53 ## get list of all required data in the form of dbs paths (dbs path = /dataset/datatier/owner)
730     self.DBSPaths=self.pubdata.getDBSPaths()
731     common.logger.message("Required data are : ")
732     for path in self.DBSPaths:
733 slacapra 1.62 common.logger.message(" --> "+path )
734 slacapra 1.53
735     ## get max number of events
736     #common.logger.debug(10,"number of events for primary fileblocks %i"%self.pubdata.getMaxEvents())
737     self.maxEvents=self.pubdata.getMaxEvents() ## self.maxEvents used in Creator.py
738     common.logger.message("\nThe number of available events is %s"%self.maxEvents)
739    
740     ## get fileblocks corresponding to the required data
741     fb=self.pubdata.getFileBlocks()
742    
743    
744     ## Contact the DLS and build a list of sites hosting the fileblocks
745     try:
746 slacapra 1.62 dataloc=DataLocation.DataLocation(self.pubdata.getFileBlocks(),cfg_params)
747     dataloc.fetchDLSInfo()
748 slacapra 1.53 except DataLocation.DataLocationError , ex:
749 slacapra 1.62 msg = 'ERROR ***: failes Data Location in DLS \n %s '%ex.getErrorMessage()
750     raise CrabException(msg)
751 nsmirnov 1.1
752    
753 gutsche 1.61 self.sites=dataloc.getSites()
754 nsmirnov 1.1
755 gutsche 1.61 if len(self.sites)==0:
756 slacapra 1.53 msg = 'No sites hosting all the needed data! Exiting... '
757 nsmirnov 1.1 raise CrabException(msg)
758 gutsche 1.61 common.logger.message("List of Sites ("+str(len(self.sites))+") hosting the data : "+str(self.sites))
759     common.logger.debug(6, "List of Sites: "+str(self.sites))
760 slacapra 1.53
761     return
762 nsmirnov 1.1
763 slacapra 1.53 #DBDDLS-stop
764 nsmirnov 1.1
765    
766     def nJobs(self):
767     # TODO: should not be here !
768     # JobType should have no internal knowledge about submitted jobs
769     # One possibility is to use len(common.job_list).
770     """ return the number of job to be created """
771 slacapra 1.6 return len(common.job_list)
772 nsmirnov 1.5
773     def prepareSteeringCards(self):
774     """
775     modify the orcarc card provided by the user,
776     writing a new card into share dir
777     """
778     infile = ''
779     try:
780     infile = open(self.orcarc_file,'r')
781     except:
782     self.orcarc_file = 'empty.orcarc'
783     cmd='touch '+self.orcarc_file
784 slacapra 1.9 runCommand(cmd)
785 nsmirnov 1.5 infile = open(self.orcarc_file,'r')
786    
787 slacapra 1.9 outfile = open(common.work_space.jobDir()+self.name()+'.orcarc', 'w')
788 nsmirnov 1.5
789     inline=infile.readlines()
790     ### remove from user card these lines ###
791 slacapra 1.53 wordRemove=['InputFileCatalogURL', 'InputCollections', 'FirstEvent', 'MaxEvents', 'TFileAdaptor']
792 slacapra 1.9 for line in inline:
793     word = string.strip(string.split(line,'=')[0])
794 slacapra 1.8
795 slacapra 1.9 if word not in wordRemove:
796     outfile.write(line)
797     else:
798     continue
799     pass
800    
801     outfile.write('\n\n##### The following cards have been created by CRAB: DO NOT TOUCH #####\n')
802     outfile.write('TFileAdaptor = true\n')
803    
804 corvo 1.45 outfile.write('MonRecAlisaBuilder=false\n')
805 slacapra 1.10
806 slacapra 1.9 outfile.write('InputCollections=/System/'+self.owner+'/'+self.dataset+'/'+self.dataset+'\n')
807 slacapra 1.8
808 nsmirnov 1.5 infile.close()
809     outfile.close()
810     return
811 nsmirnov 1.1
812     def modifySteeringCards(self, nj):
813     """
814     Creates steering cards file modifying a template file
815     """
816     return
817    
818     def cardsBaseName(self):
819     """
820     Returns name of user orcarc card-file
821     """
822     return os.path.split (self.orcarc_file)[1]
823    
824 fanzago 1.27 ### content of input_sanbdox ...
825 nsmirnov 1.1 def inputSandbox(self, nj):
826     """
827     Returns a list of filenames to be put in JDL input sandbox.
828     """
829     inp_box = []
830 corvo 1.13 # dict added to delete duplicate from input sandbox file list
831     seen = {}
832 slacapra 1.7 ## code
833 fanzago 1.12 if os.path.isfile(self.tgzNameWithPath):
834     inp_box.append(self.tgzNameWithPath)
835 slacapra 1.53
836     ##DBSDLS: no orcarc_CE and init_CE.sh produced on UI , thus not inserting them in inputSandbox
837     # ## orcarc
838     # for o in self.allOrcarcs:
839     # for f in o.fileList():
840     # if (f not in seen.keys()):
841     # inp_box.append(common.work_space.jobDir()+f)
842     # seen[f] = 1
843 slacapra 1.9
844 slacapra 1.7 ## config
845 nsmirnov 1.1 inp_box.append(common.job_list[nj].configFilename())
846 slacapra 1.7 ## additional input files
847 fanzago 1.26 #inp_box = inp_box + self.additional_inbox_files
848 nsmirnov 1.1 return inp_box
849    
850 fanzago 1.15 ### and of output_sandbox
851 nsmirnov 1.1 def outputSandbox(self, nj):
852     """
853     Returns a list of filenames to be put in JDL output sandbox.
854     """
855     out_box = []
856    
857 slacapra 1.9 stdout=common.job_list[nj].stdout()
858     stderr=common.job_list[nj].stderr()
859 fanzago 1.15 #out_box.append(stdout)
860     #out_box.append(stderr)
861 slacapra 1.9
862 slacapra 1.7 ## User Declared output files
863 slacapra 1.9 for out in self.output_file:
864 fanzago 1.14 n_out = nj + 1
865 fanzago 1.25 #FEDE
866     #out_box.append(self.version+'/'+self.numberFile_(out,str(n_out)))
867     out_box.append(self.numberFile_(out,str(n_out)))
868 nsmirnov 1.1 return out_box
869 slacapra 1.7
870 gutsche 1.61 def getRequirements(self, nj):
871 fanzago 1.32 """
872 slacapra 1.53 return job requirements to add to jdl files
873 fanzago 1.32 """
874     req = ''
875 gutsche 1.61 #if common.analisys_common_info['sites']:
876     if common.analisys_common_info['sw_version']:
877     req='Member("VO-cms-' + \
878     common.analisys_common_info['sw_version'] + \
879     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
880    
881     sites = common.jobDB.destination(nj)
882    
883     if len(sites)>0:
884     req = req + ' && ('
885     for site in sites:
886     req = req + 'other.GlueCEInfoHostName == "' + site + '" || '
887     pass
888     # remove last ||
889     req = req[0:-4]
890     req = req + ')'
891 fanzago 1.32 #print "req = ", req
892 gutsche 1.61
893 fanzago 1.32 return req
894    
895 slacapra 1.9 def numberFile_(self, file, txt):
896     """
897     append _'txt' before last extension of a file
898     """
899     p = string.split(file,".")
900     # take away last extension
901     name = p[0]
902     for x in p[1:-1]:
903     name=name+"."+x
904     # add "_txt"
905     if len(p)>1:
906     ext = p[len(p)-1]
907 fanzago 1.14 #result = name + '_' + str(txt) + "." + ext
908     result = name + '_' + txt + "." + ext
909 slacapra 1.9 else:
910 fanzago 1.14 #result = name + '_' + str(txt)
911     result = name + '_' + txt
912 slacapra 1.9
913     return result
914    
915    
916 slacapra 1.7 def stdOut(self):
917     return self.stdOut_
918    
919     def stdErr(self):
920     return self.stdErr_
921 spiga 1.46
922 corvo 1.36 # marco
923     def setParam_(self, param, value):
924     self._params[param] = value
925    
926     def getParams(self):
927     return self._params
928    
929     def setTaskid_(self):
930 corvo 1.44 self._taskId = self.cfg_params['taskId']
931 corvo 1.36
932     def getTaskid(self):
933     return self._taskId
934     # marco
935 spiga 1.46
936 gutsche 1.50 def configFilename(self):
937     """ return the config filename """
938     return self.name()+'.orcarc'
939    
940 spiga 1.46 ### OLI_DANIELE
941     def wsSetupCMSOSGEnvironment_(self):
942     """
943     Returns part of a job script which is prepares
944     the execution environment and which is common for all CMS jobs.
945     """
946     txt = '\n'
947     txt += ' echo "### SETUP CMS OSG ENVIRONMENT ###"\n'
948     txt += ' if [ -f $GRID3_APP_DIR/cmssoft/cmsset_default.sh ] ;then\n'
949     txt += ' # Use $GRID3_APP_DIR/cmssoft/cmsset_default.sh to setup cms software\n'
950     txt += ' source $GRID3_APP_DIR/cmssoft/cmsset_default.sh '+self.version+'\n'
951     txt += ' elif [ -f $OSG_APP/cmssoft/cmsset_default.sh ] ;then\n'
952     txt += ' # Use $OSG_APP/cmssoft/cmsset_default.sh to setup cms software\n'
953     txt += ' source $OSG_APP/cmssoft/cmsset_default.sh '+self.version+'\n'
954     txt += ' else\n'
955 slacapra 1.53 txt += ' echo "SET_CMS_ENV 10020 ==> ERROR $GRID3_APP_DIR/cmssoft/cmsset_default.sh and $OSG_APP/cmssoft/cmsset_default.sh file not found"\n'
956     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
957     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
958     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
959 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
960     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
961     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
962 slacapra 1.53 txt += ' exit 1\n'
963 spiga 1.46 txt += '\n'
964     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
965     txt += ' cd $RUNTIME_AREA\n'
966     txt += ' /bin/rm -rf $WORKING_DIR\n'
967     txt += ' if [ -d $WORKING_DIR ] ;then\n'
968 gutsche 1.52 txt += ' echo "SET_CMS_ENV 10017 ==> OSG $WORKING_DIR could not be deleted on WN `hostname` after $GRID3_APP_DIR/cmssoft/cmsset_default.sh and $OSG_APP/cmssoft/cmsset_default.sh file not found"\n'
969     txt += ' echo "JOB_EXIT_STATUS = 10017"\n'
970     txt += ' echo "JobExitCode=10017" | tee -a $RUNTIME_AREA/$repo\n'
971     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
972 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
973     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
974     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
975 spiga 1.46 txt += ' fi\n'
976     txt += '\n'
977 slacapra 1.53 txt += ' exit 1\n'
978 spiga 1.46 txt += ' fi\n'
979     txt += '\n'
980     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
981     txt += ' echo " END SETUP CMS OSG ENVIRONMENT "\n'
982    
983     return txt
984    
985     ### OLI_DANIELE
986     def wsSetupCMSLCGEnvironment_(self):
987     """
988     Returns part of a job script which is prepares
989     the execution environment and which is common for all CMS jobs.
990     """
991     txt = ' \n'
992     txt += ' echo " ### SETUP CMS LCG ENVIRONMENT ### "\n'
993     txt += ' if [ ! $VO_CMS_SW_DIR ] ;then\n'
994 slacapra 1.53 txt += ' echo "SET_CMS_ENV 10031 ==> ERROR CMS software dir not found on WN `hostname`"\n'
995     txt += ' echo "JOB_EXIT_STATUS = 10031" \n'
996     txt += ' echo "JobExitCode=10031" | tee -a $RUNTIME_AREA/$repo\n'
997     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
998 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
999     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1000     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1001 slacapra 1.53 txt += ' exit 1\n'
1002 spiga 1.46 txt += ' else\n'
1003 slacapra 1.53 txt += ' echo "Sourcing environment... "\n'
1004     txt += ' if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
1005     txt += ' echo "SET_CMS_ENV 10020 ==> ERROR cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
1006     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
1007     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
1008     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1009 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1010     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1011     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1012 slacapra 1.53 txt += ' exit 1\n'
1013     txt += ' fi\n'
1014     txt += ' echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1015     txt += ' source $VO_CMS_SW_DIR/cmsset_default.sh\n'
1016     txt += ' result=$?\n'
1017     txt += ' if [ $result -ne 0 ]; then\n'
1018     txt += ' echo "SET_CMS_ENV 10032 ==> ERROR problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
1019     txt += ' echo "JOB_EXIT_STATUS = 10032"\n'
1020     txt += ' echo "JobExitCode=10032" | tee -a $RUNTIME_AREA/$repo\n'
1021     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1022 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1023     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1024     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1025 slacapra 1.53 txt += ' exit 1\n'
1026     txt += ' fi\n'
1027 spiga 1.46 txt += ' fi\n'
1028     txt += ' \n'
1029     txt += ' string=`cat /etc/redhat-release`\n'
1030     txt += ' echo $string\n'
1031     txt += ' if [[ $string = *alhalla* ]]; then\n'
1032     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1033     txt += ' elif [[ $string = *Enterprise* ]] || [[ $string = *cientific* ]]; then\n'
1034     txt += ' export SCRAM_ARCH=slc3_ia32_gcc323\n'
1035     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
1036     txt += ' else\n'
1037 slacapra 1.53 txt += ' echo "SET_CMS_ENV 10033 ==> ERROR OS unknown, LCG environment not initialized"\n'
1038     txt += ' echo "JOB_EXIT_STATUS = 10033"\n'
1039     txt += ' echo "JobExitCode=10033" | tee -a $RUNTIME_AREA/$repo\n'
1040     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
1041 gutsche 1.55 txt += ' rm -f $RUNTIME_AREA/$repo \n'
1042     txt += ' echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
1043     txt += ' echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
1044 slacapra 1.53 txt += ' exit 1\n'
1045 spiga 1.46 txt += ' fi\n'
1046     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
1047     txt += ' echo "### END SETUP CMS LCG ENVIRONMENT ###"\n'
1048     return txt
1049