ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_orca_pubdb.py
Revision: 1.12
Committed: Fri Sep 22 15:03:24 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.11: +2 -4 lines
Log Message:
working dir creation on OSG moved to mktemp

File Contents

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