ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_orca_common.py
Revision: 1.6
Committed: Fri Mar 31 17:15:54 2006 UTC (19 years, 1 month ago) by spiga
Content type: text/x-python
Branch: MAIN
Changes since 1.5: +130 -120 lines
Log Message:
checked if alligned and some minor fixes, spaces comment....

File Contents

# User Rev Content
1 gutsche 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 gutsche 1.3 import TarBall
11 gutsche 1.1
12     import os, string, re
13    
14     class Orca_common(JobType):
15     def __init__(self, cfg_params):
16     JobType.__init__(self, 'ORCA_COMMON')
17     common.logger.debug(3,'ORCA_COMMON::__init__')
18    
19     self.analisys_common_info = {}
20     # Marco.
21     self._params = {}
22     self.cfg_params = cfg_params
23    
24     log = common.logger
25    
26     self.scram = Scram.Scram(cfg_params)
27     scramArea = ''
28     self.additional_inbox_files = []
29     self.scriptExe = ''
30    
31     self.version = self.scram.getSWVersion()
32     self.setParam_('application', self.version)
33     common.analisys_common_info['sw_version'] = self.version
34     ### FEDE
35     common.analisys_common_info['copy_input_data'] = 0
36     common.analisys_common_info['events_management'] = 1
37    
38     ### collect Data cards
39     try:
40     self.owner = cfg_params['ORCA.owner']
41     self.setParam_('owner', self.owner)
42     log.debug(6, "Orca::Orca(): owner = "+self.owner)
43     self.dataset = cfg_params['ORCA.dataset']
44     self.setParam_('dataset', self.dataset)
45     log.debug(6, "Orca::Orca(): dataset = "+self.dataset)
46     except KeyError:
47     msg = "Error: owner and/or dataset not defined "
48     raise CrabException(msg)
49    
50     self.dataTiers = []
51     try:
52     tmpDataTiers = string.split(cfg_params['ORCA.data_tier'],',')
53     for tmp in tmpDataTiers:
54     tmp=string.strip(tmp)
55     self.dataTiers.append(tmp)
56     pass
57     pass
58     except KeyError:
59     pass
60     log.debug(6, "Orca::Orca(): dataTiers = "+str(self.dataTiers))
61    
62     ## now the application
63     try:
64     self.executable = cfg_params['ORCA.executable']
65     log.debug(6, "Orca::Orca(): executable = "+self.executable)
66     self.setParam_('exe', self.executable)
67     except KeyError:
68     msg = "Error: executable not defined "
69     raise CrabException(msg)
70    
71     try:
72     self.orcarc_file = cfg_params['ORCA.orcarc_file']
73     log.debug(6, "Orca::Orca(): orcarc file = "+self.orcarc_file)
74     if (not os.path.exists(self.orcarc_file)):
75     raise CrabException("User defined .orcarc file "+self.orcarc_file+" does not exist")
76     except KeyError:
77     log.message("Using empty orcarc file")
78     self.orcarc_file = ''
79    
80     # output files
81     try:
82     self.output_file = []
83    
84     tmp = cfg_params['ORCA.output_file']
85     if tmp != '':
86     tmpOutFiles = string.split(cfg_params['ORCA.output_file'],',')
87     log.debug(7, 'Orca::Orca(): output files '+str(tmpOutFiles))
88     for tmp in tmpOutFiles:
89     tmp=string.strip(tmp)
90     self.output_file.append(tmp)
91     pass
92    
93     else:
94     log.message("No output file defined: only stdout/err will be available")
95     pass
96     pass
97     except KeyError:
98     log.message("No output file defined: only stdout/err will be available")
99     pass
100    
101     # script_exe file as additional file in inputSandbox
102     try:
103     self.scriptExe = cfg_params['ORCA.script_exe']
104     self.additional_inbox_files.append(self.scriptExe)
105     except KeyError:
106     pass
107     if self.scriptExe != '':
108     if os.path.isfile(self.scriptExe):
109     pass
110     else:
111     log.message("WARNING. file "+self.scriptExe+" not found")
112     sys.exit()
113    
114     ## additional input files
115     try:
116     tmpAddFiles = string.split(cfg_params['USER.additional_input_files'],',')
117     for tmp in tmpAddFiles:
118     tmp=string.strip(tmp)
119     self.additional_inbox_files.append(tmp)
120     pass
121     pass
122     except KeyError:
123     pass
124    
125     try:
126     self.total_number_of_events = int(cfg_params['USER.total_number_of_events'])
127     except KeyError:
128     msg = 'Must define total_number_of_events and job_number_of_events'
129     raise CrabException(msg)
130    
131     try:
132     self.first = int(cfg_params['USER.first_event'])
133     except KeyError:
134     self.first = 0
135     pass
136     log.debug(6, "Orca::Orca(): total number of events = "+`self.total_number_of_events`)
137     #log.debug(6, "Orca::Orca(): events per job = "+`self.job_number_of_events`)
138     log.debug(6, "Orca::Orca(): first event = "+`self.first`)
139    
140     self.maxEvents=0 # max events available in any PubDB
141     self.connectPubDB(cfg_params)
142    
143     # [-- self.checkNevJobs() --]
144    
145 gutsche 1.3 self.TarBaller = TarBall.TarBall(self.executable, self.scram)
146     self.tgzNameWithPath = self.TarBaller.prepareTarBall()
147 gutsche 1.1
148     try:
149     self.ML = int(cfg_params['USER.activate_monalisa'])
150     except KeyError:
151     self.ML = 0
152     pass
153    
154     self.setTaskid_()
155 corvo 1.4 self.setParam_('taskId', self.cfg_params['user'] + '_' + string.split(common.work_space.topDir(),'/')[-2])
156 gutsche 1.1
157     return
158    
159     def wsSetupEnvironment(self, nj):
160     """
161     Returns part of a job script which prepares
162     the execution environment for the job 'nj'.
163     """
164    
165     # Prepare JobType-independent part
166     txt = ''
167    
168 spiga 1.6 ## OLI_Daniele at this level middleware already known
169    
170 gutsche 1.1 txt += 'if [ $middleware == LCG ]; then \n'
171     txt += self.wsSetupCMSLCGEnvironment_()
172     txt += 'elif [ $middleware == OSG ]; then\n'
173 spiga 1.6 txt += ' time=`date -u +"%s"`\n'
174     txt += ' WORKING_DIR=$OSG_WN_TMP/cms_$time\n'
175     txt += ' echo "Creating working directory: $WORKING_DIR"\n'
176     txt += ' /bin/mkdir -p $WORKING_DIR\n'
177     txt += ' if [ ! -d $WORKING_DIR ] ;then\n'
178     txt += ' echo "OSG WORKING DIR ==> $WORKING_DIR could not be created on on WN `hostname`"\n'
179    
180     txt += ' echo "JOB_EXIT_STATUS = 1"\n'
181     txt += ' exit 1\n'
182     txt += ' fi\n'
183 gutsche 1.1 txt += '\n'
184 spiga 1.6 txt += ' echo "Change to working directory: $WORKING_DIR"\n'
185     txt += ' cd $WORKING_DIR\n'
186 gutsche 1.1 txt += self.wsSetupCMSOSGEnvironment_()
187     txt += 'fi\n'
188 spiga 1.6
189 gutsche 1.1 # Prepare JobType-specific part
190     scram = self.scram.commandName()
191     txt += '\n\n'
192 fanzago 1.5 txt += 'echo "### SPECIFIC JOB SETUP ENVIRONMENT ###"\n'
193 gutsche 1.1 txt += scram+' project ORCA '+self.version+'\n'
194     txt += 'status=$?\n'
195     txt += 'if [ $status != 0 ] ; then\n'
196 spiga 1.6 txt += ' echo "SET_EXE_ENV 1 ==>ERROR ORCA '+self.version+' not found on `hostname`" \n'
197     txt += ' echo "JOB_EXIT_STATUS = 10034"\n'
198     txt += ' echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
199     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
200    
201 gutsche 1.1 ## OLI_Daniele
202 spiga 1.6 txt += ' if [ $middleware == OSG ]; then \n'
203     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
204     txt += ' cd $RUNTIME_AREA\n'
205     txt += ' /bin/rm -f $WORKING_DIR\n'
206     txt += ' if [ -d $WORKING_DIR ] ;then\n'
207     txt += ' echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
208     txt += ' fi\n'
209     txt += ' fi \n'
210     txt += ' exit \n'
211 gutsche 1.1 txt += 'fi \n'
212     txt += 'echo "ORCA_VERSION = '+self.version+'"\n'
213     txt += 'cd '+self.version+'\n'
214     ### needed grep for bug in scramv1 ###
215 spiga 1.6
216 gutsche 1.1 #txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
217    
218     # Handle the arguments:
219     txt += "\n"
220     txt += "## ARGUMNETS: $1 Job Number\n"
221     txt += "## ARGUMNETS: $2 First Event for this job\n"
222     txt += "## ARGUMNETS: $3 Max Event for this job\n"
223     txt += "\n"
224     txt += "narg=$#\n"
225     txt += "if [ $narg -lt 3 ]\n"
226     txt += "then\n"
227     txt += " echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$narg+ \n"
228     txt += ' echo "JOB_EXIT_STATUS = 50113"\n'
229 spiga 1.6 txt += ' echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
230 gutsche 1.1 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
231 spiga 1.6
232 gutsche 1.1 ## OLI_Daniele
233 fanzago 1.5 txt += ' if [ $middleware == OSG ]; then \n'
234     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
235     txt += ' cd $RUNTIME_AREA\n'
236     txt += ' /bin/rm -f $WORKING_DIR\n'
237     txt += ' if [ -d $WORKING_DIR ] ;then\n'
238     txt += ' echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
239     txt += ' fi\n'
240     txt += ' fi \n'
241 spiga 1.6 txt += " exit\n"
242 gutsche 1.1 txt += "fi\n"
243     txt += "\n"
244     txt += "NJob=$1\n"
245     txt += "FirstEvent=$2\n"
246     txt += "MaxEvents=$3\n"
247     txt += 'echo "MonitorID=`echo ' + self._taskId + '`" | tee -a $RUNTIME_AREA/$repo\n'
248     ### OLI_DANIELE
249     txt += 'if [ $middleware == LCG ]; then \n'
250 spiga 1.6 txt += ' echo "MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
251     txt += ' echo "SyncGridJobId=`echo $EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
252     txt += ' echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo\n'
253 gutsche 1.1 txt += 'elif [ $middleware == OSG ]; then\n'
254 spiga 1.6 txt += ' echo "Additional info from OSG WN to be implemented"\n'
255 gutsche 1.1 txt += 'fi\n'
256     txt += 'dumpStatus $RUNTIME_AREA/$repo\n'
257    
258    
259     # Prepare job-specific part
260     job = common.job_list[nj]
261     orcarc = os.path.basename(job.configFilename())
262     txt += '\n'
263     txt += 'cp $RUNTIME_AREA/'+orcarc+' .orcarc\n'
264     txt += 'if [ -e $RUNTIME_AREA/orcarc_$CE ] ; then\n'
265 spiga 1.6 txt += ' cat $RUNTIME_AREA/orcarc_$CE .orcarc >> .orcarc_tmp\n'
266     txt += ' mv .orcarc_tmp .orcarc\n'
267 gutsche 1.1 txt += 'fi\n'
268     txt += 'if [ -e $RUNTIME_AREA/init_$CE.sh ] ; then\n'
269 spiga 1.6 txt += ' cp $RUNTIME_AREA/init_$CE.sh init.sh\n'
270 gutsche 1.1 txt += 'fi\n'
271    
272     if len(self.additional_inbox_files) > 0:
273     for file in self.additional_inbox_files:
274 spiga 1.6 file = os.path.basename(file)
275 gutsche 1.1 txt += 'if [ -e $RUNTIME_AREA/'+file+' ] ; then\n'
276 spiga 1.6 txt += ' cp $RUNTIME_AREA/'+file+' .\n'
277     txt += ' chmod +x '+file+'\n'
278 gutsche 1.1 txt += 'fi\n'
279     pass
280    
281     txt += '\n'
282     txt += 'chmod +x ./init.sh\n'
283     txt += './init.sh\n'
284     txt += 'exitStatus=$?\n'
285     txt += 'if [ $exitStatus != 0 ] ; then\n'
286     txt += ' echo "SET_EXE_ENV 1 ==> ERROR StageIn init script failed"\n'
287     txt += ' echo "JOB_EXIT_STATUS = $exitStatus" \n'
288     txt += ' echo "JobExitCode=20001" | tee -a $RUNTIME_AREA/$repo\n'
289     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
290 spiga 1.6
291 gutsche 1.1 ### OLI_DANIELE
292 fanzago 1.5 txt += ' if [ $middleware == OSG ]; then \n'
293 spiga 1.6 txt += ' echo "Remove working directory: $WORKING_DIR"\n'
294     txt += ' cd $RUNTIME_AREA\n'
295     txt += ' /bin/rm -f $WORKING_DIR\n'
296     txt += ' if [ -d $WORKING_DIR ] ;then\n'
297     txt += ' echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
298     txt += ' fi\n'
299 fanzago 1.5 txt += ' fi \n'
300     txt += ' exit $exitStatus\n'
301 gutsche 1.1 txt += 'fi\n'
302     txt += "echo 'SET_EXE_ENV 0 ==> job setup ok'\n"
303     txt += 'echo "### END JOB SETUP ENVIRONMENT ###"\n\n'
304    
305     txt += 'echo "FirstEvent=$FirstEvent" >> .orcarc\n'
306     txt += 'echo "MaxEvents=$MaxEvents" >> .orcarc\n'
307     if self.ML:
308     txt += 'echo "MonalisaJobId=$NJob" >> .orcarc\n'
309    
310     txt += '\n'
311     txt += 'echo "***** cat .orcarc *********"\n'
312     txt += 'cat .orcarc\n'
313     txt += 'echo "****** end .orcarc ********"\n'
314     return txt
315    
316     def wsBuildExe(self, nj):
317     """
318     Put in the script the commands to build an executable
319     or a library.
320     """
321    
322     txt = ""
323    
324     if os.path.isfile(self.tgzNameWithPath):
325 fanzago 1.2 txt += 'echo "tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'"\n'
326     txt += 'tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
327 gutsche 1.1 txt += 'untar_status=$? \n'
328     txt += 'if [ $untar_status -ne 0 ]; then \n'
329     txt += ' echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
330     txt += ' echo "JOB_EXIT_STATUS = $untar_status" \n'
331     txt += ' echo "SanityCheckCode=$untar_status" | tee -a $repo\n'
332 spiga 1.6
333 gutsche 1.1 ### OLI_DANIELE
334     txt += ' if [ $middleware == OSG ]; then \n'
335 spiga 1.6 txt += ' echo "Remove working directory: $WORKING_DIR"\n'
336     txt += ' cd $RUNTIME_AREA\n'
337     txt += ' /bin/rm -f $WORKING_DIR\n'
338     txt += ' if [ -d $WORKING_DIR ] ;then\n'
339     txt += ' echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
340     txt += ' fi\n'
341 gutsche 1.1 txt += ' fi \n'
342     txt += ' \n'
343     txt += ' exit $untar_status \n'
344     txt += 'else \n'
345 spiga 1.6 txt += ' echo "Successful untar" \n'
346 gutsche 1.1 txt += 'fi \n'
347     # TODO: what does this code do here ?
348     # SL check that lib/Linux__... is present
349     txt += 'mkdir -p lib/${SCRAM_ARCH} \n'
350     pass
351     txt += 'eval `'+self.scram.commandName()+' runtime -sh |grep -v SCRAMRT_LSB_JOBNAME`'+'\n'
352    
353     return txt
354    
355     def wsRenameOutput(self, nj):
356     """
357     Returns part of a job script which renames the produced files.
358     """
359    
360     txt = '\n'
361     file_list = ''
362     for fileWithSuffix in self.output_file:
363     output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
364     file_list=file_list+output_file_num+','
365     txt += '\n'
366     txt += 'ls \n'
367     txt += '\n'
368     txt += 'ls '+fileWithSuffix+'\n'
369     txt += 'exe_result=$?\n'
370     txt += 'if [ $exe_result -ne 0 ] ; then\n'
371     txt += ' echo "ERROR: No output file to manage"\n'
372     txt += ' echo "JOB_EXIT_STATUS = $exe_result"\n'
373     txt += ' echo "JobExitCode=60302" | tee -a $RUNTIME_AREA/$repo\n'
374     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
375 spiga 1.6
376 gutsche 1.1 ### OLI_DANIELE
377 spiga 1.6 txt += ' if [ $middleware == OSG ]; then \n'
378     txt += ' cd $RUNTIME_AREA\n'
379     txt += ' echo "prepare dummy output file"\n'
380     txt += ' echo "Processing of job output failed" > $RUNTIME_AREA/'+output_file_num+'\n'
381     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
382     txt += ' /bin/rm -f $WORKING_DIR\n'
383     txt += ' if [ -d $WORKING_DIR ] ;then\n'
384     txt += ' echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
385     txt += ' fi\n'
386     txt += ' fi \n'
387     txt += ' \n'
388     txt += ' exit $exe_result \n'
389 gutsche 1.1 txt += 'else\n'
390 spiga 1.6 txt += ' cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
391 gutsche 1.1 txt += 'fi\n'
392    
393     pass
394    
395    
396     txt += 'cd $RUNTIME_AREA\n'
397     file_list=file_list[:-1]
398     txt += 'file_list='+file_list+'\n'
399     ### OLI_DANIELE
400     txt += 'if [ $middleware == OSG ]; then\n'
401 spiga 1.6 txt += ' cd $RUNTIME_AREA\n'
402     txt += ' echo "Remove working directory: $WORKING_DIR"\n'
403     txt += ' /bin/rm -rf $WORKING_DIR\n'
404     txt += ' if [ -d $WORKING_DIR ] ;then\n'
405     txt += ' echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
406     txt += ' fi\n'
407 gutsche 1.1 txt += 'fi\n'
408     txt += '\n'
409    
410     return txt
411    
412     def executableName(self):
413     if self.scriptExe != '':
414     return "./" + os.path.basename(self.scriptExe)
415     else:
416     return self.executable
417    
418     def connectPubDB(self, cfg_params):
419    
420     fun = "Orca::connectPubDB()"
421    
422     self.allOrcarcs = []
423     # first check if the info from PubDB have been already processed
424     if os.path.exists(common.work_space.shareDir()+'PubDBSummaryFile') :
425     common.logger.debug(6, fun+": info from PubDB has been already processed -- use it")
426     f = open( common.work_space.shareDir()+'PubDBSummaryFile', 'r' )
427     for i in f.readlines():
428     a=string.split(i,' ')
429     self.allOrcarcs.append(orcarcBuilderOld.constructFromFile(a[0:-1]))
430     pass
431     for o in self.allOrcarcs:
432     # o.dump()
433     if o.Nevents >= self.maxEvents:
434     self.maxEvents= o.Nevents
435     pass
436     pass
437     pass
438    
439     else: # PubDB never queried
440     common.logger.debug(6, fun+": PubDB was never queried -- do it")
441     # New PubDB class by SL
442     try:
443     self.pubdb = PubDB.PubDB(self.owner,
444     self.dataset,
445     self.dataTiers,
446     cfg_params)
447     except PubDB.RefDBmapError:
448     msg = 'ERROR ***: accessing PubDB'
449     raise CrabException(msg)
450    
451     ## extract info from pubDB (grouped by PubDB version :
452     ## pubDBData contains a list of info for the new-style PubDBs,
453     ## and a list of info for the old-style PubDBs )
454     self.pubDBData = self.pubdb.getAllPubDBData()
455    
456     ## check and exit if no data are published in any PubDB
457     nodata=1
458     for PubDBversion in self.pubDBData.keys():
459     if len(self.pubDBData[PubDBversion])>0:
460     nodata=0
461     if (nodata):
462     msg = 'Owner '+self.owner+' Dataset '+ self.dataset+ ' not published in any PubDB with asked dataTiers '+string.join(self.dataTiers,'-')+' ! '
463     raise CrabException(msg)
464    
465     ## logging PubDB content for debugging
466     for PubDBversion in self.pubDBData.keys():
467     common.logger.debug(6, fun+": PubDB "+PubDBversion+" info ("+`len(self.pubDBData[PubDBversion])`+"):\/")
468     for aa in self.pubDBData[PubDBversion]:
469     common.logger.debug(6, "---------- start of a PubDB")
470     for bb in aa:
471     if common.logger.debugLevel() >= 6 :
472     common.logger.debug(6, str(bb.dump()))
473     pass
474     pass
475     common.logger.debug(6, "----------- end of a PubDB")
476     common.logger.debug(6, fun+": End of PubDB "+PubDBversion+" info\n")
477    
478    
479     ## building orcarc : switch between info from old and new-style PubDB
480     currDir = os.getcwd()
481     os.chdir(common.work_space.jobDir())
482    
483     tmpOrcarcList=[]
484     for PubDBversion in self.pubDBData.keys():
485     if len(self.pubDBData[PubDBversion])>0 :
486     #print (" PubDB-style : %s"%(PubDBversion))
487     if PubDBversion=='newPubDB' :
488     self.builder = orcarcBuilder.orcarcBuilder(cfg_params)
489     else :
490     self.builder = orcarcBuilderOld.orcarcBuilderOld()
491     tmpAllOrcarcs = self.builder.createOrcarcAndInit(self.pubDBData[PubDBversion])
492     tmpOrcarcList.append(tmpAllOrcarcs)
493     #print 'version ',PubDBversion,' tmpAllOrcarcs ', tmpAllOrcarcs
494    
495     #print tmpOrcarcList
496     os.chdir(currDir)
497    
498     self.maxEvents=0
499     for tmpAllOrcarcs in tmpOrcarcList:
500     for o in tmpAllOrcarcs:
501     numEvReq=self.total_number_of_events
502     if ((numEvReq == '-1') | (numEvReq <= o.Nevents)):
503     self.allOrcarcs.append(o)
504     if (int(o.Nevents) >= self.maxEvents):
505     self.maxEvents= int(o.Nevents)
506     pass
507     pass
508     pass
509    
510     # set maximum number of event available
511    
512     # I save to a file self.allOrcarcs
513    
514     PubDBSummaryFile = open(common.work_space.shareDir()+'PubDBSummaryFile','w')
515     for o in self.allOrcarcs:
516     for d in o.content():
517     PubDBSummaryFile.write(d)
518     PubDBSummaryFile.write(' ')
519     pass
520     PubDBSummaryFile.write('\n')
521     pass
522     PubDBSummaryFile.close()
523     ### fede
524 spiga 1.6 #for o in self.allOrcarcs:
525     # o.dump()
526 gutsche 1.1 pass
527    
528     # build a list of sites
529     ces= []
530     for o in self.allOrcarcs:
531     ces.append(o.CE)
532     pass
533    
534     if len(ces)==0:
535     msg = 'No PubDBs publish correct catalogs or enough events! '
536     msg += `self.total_number_of_events`
537     raise CrabException(msg)
538    
539     common.logger.debug(6, "List of CEs: "+str(ces))
540 spiga 1.6 common.analisys_common_info['sites'] = ces
541 corvo 1.4 self.setParam_('TargetCE', ','.join(ces))
542 gutsche 1.1
543     return
544    
545     def nJobs(self):
546     # TODO: should not be here !
547     # JobType should have no internal knowledge about submitted jobs
548     # One possibility is to use len(common.job_list).
549     """ return the number of job to be created """
550     return len(common.job_list)
551    
552     def prepareSteeringCards(self):
553     """
554     modify the orcarc card provided by the user,
555     writing a new card into share dir
556     """
557     infile = ''
558     try:
559     infile = open(self.orcarc_file,'r')
560     except:
561     self.orcarc_file = 'empty.orcarc'
562     cmd='touch '+self.orcarc_file
563     runCommand(cmd)
564     infile = open(self.orcarc_file,'r')
565    
566     outfile = open(common.work_space.jobDir()+self.name()+'.orcarc', 'w')
567    
568     inline=infile.readlines()
569     ### remove from user card these lines ###
570     wordRemove=['InputFileCatalogURL', 'InputCollections', 'FirstEvent', 'MaxEvents', 'TFileAdaptor']
571     for line in inline:
572     word = string.strip(string.split(line,'=')[0])
573    
574     if word not in wordRemove:
575     outfile.write(line)
576     else:
577     continue
578     pass
579    
580     outfile.write('\n\n##### The following cards have been created by CRAB: DO NOT TOUCH #####\n')
581     outfile.write('TFileAdaptor = true\n')
582    
583     if (self.ML) :
584     outfile.write('MonalisaAddPid = false\n')
585     outfile.write('ExtraPackages=RecApplPlugins\n')
586     outfile.write('MonRecAlisaBuilder=true\n')
587     ## TaskId is username+crab_0_date_time : that should be unique
588     # TaskID = os.getlogin()+'_'+string.split(common.work_space.topDir(),'/')[-2]
589     outfile.write('MonalisaApplName='+self._taskId+'\n')
590     outfile.write('MonalisaNode=137.138.4.152\n')
591     outfile.write('MonalisaPort=58884\n')
592     pass
593    
594     outfile.write('InputCollections=/System/'+self.owner+'/'+self.dataset+'/'+self.dataset+'\n')
595    
596     infile.close()
597     outfile.close()
598     return
599    
600     def modifySteeringCards(self, nj):
601     """
602     Creates steering cards file modifying a template file
603     """
604     return
605    
606     def cardsBaseName(self):
607     """
608     Returns name of user orcarc card-file
609     """
610     return os.path.split (self.orcarc_file)[1]
611    
612     ### content of input_sanbdox ...
613     def inputSandbox(self, nj):
614     """
615     Returns a list of filenames to be put in JDL input sandbox.
616     """
617     inp_box = []
618     # dict added to delete duplicate from input sandbox file list
619     seen = {}
620     ## code
621     if os.path.isfile(self.tgzNameWithPath):
622     inp_box.append(self.tgzNameWithPath)
623     ## orcarc
624     for o in self.allOrcarcs:
625     for f in o.fileList():
626     if (f not in seen.keys()):
627     inp_box.append(common.work_space.jobDir()+f)
628     seen[f] = 1
629    
630     ## config
631     inp_box.append(common.job_list[nj].configFilename())
632     ## additional input files
633     #inp_box = inp_box + self.additional_inbox_files
634     return inp_box
635    
636     ### and of output_sandbox
637     def outputSandbox(self, nj):
638     """
639     Returns a list of filenames to be put in JDL output sandbox.
640     """
641     out_box = []
642    
643     stdout=common.job_list[nj].stdout()
644     stderr=common.job_list[nj].stderr()
645     #out_box.append(stdout)
646     #out_box.append(stderr)
647    
648     ## User Declared output files
649     for out in self.output_file:
650     n_out = nj + 1
651     #FEDE
652     #out_box.append(self.version+'/'+self.numberFile_(out,str(n_out)))
653     out_box.append(self.numberFile_(out,str(n_out)))
654     return out_box
655    
656     def getRequirements(self):
657     """
658     return job requirements to add to jdl files
659     """
660     req = ''
661     if common.analisys_common_info['sites']:
662     if common.analisys_common_info['sw_version']:
663     req='Member("VO-cms-' + \
664     common.analisys_common_info['sw_version'] + \
665     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
666     if len(common.analisys_common_info['sites'])>0:
667     req = req + ' && ('
668     for i in range(len(common.analisys_common_info['sites'])):
669     req = req + 'other.GlueCEInfoHostName == "' \
670     + common.analisys_common_info['sites'][i] + '"'
671     if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
672     req = req + ' || '
673     req = req + ')'
674     #print "req = ", req
675     return req
676    
677     def numberFile_(self, file, txt):
678     """
679     append _'txt' before last extension of a file
680     """
681     p = string.split(file,".")
682     # take away last extension
683     name = p[0]
684     for x in p[1:-1]:
685     name=name+"."+x
686     # add "_txt"
687     if len(p)>1:
688     ext = p[len(p)-1]
689     #result = name + '_' + str(txt) + "." + ext
690     result = name + '_' + txt + "." + ext
691     else:
692     #result = name + '_' + str(txt)
693     result = name + '_' + txt
694    
695     return result
696    
697    
698     def stdOut(self):
699     return self.stdOut_
700    
701     def stdErr(self):
702     return self.stdErr_
703    
704     # marco
705     def setParam_(self, param, value):
706     self._params[param] = value
707    
708     def getParams(self):
709     return self._params
710    
711     def setTaskid_(self):
712     self._taskId = self.cfg_params['user'] + '_' + string.split(common.work_space.topDir(),'/')[-2]
713    
714     def getTaskid(self):
715     return self._taskId
716     # marco
717    
718     ### OLI_DANIELE
719     def wsSetupCMSOSGEnvironment_(self):
720     """
721     Returns part of a job script which is prepares
722     the execution environment and which is common for all CMS jobs.
723     """
724     txt = '\n'
725 spiga 1.6 txt += ' echo "### SETUP CMS OSG ENVIRONMENT ###"\n'
726 gutsche 1.1 txt += ' if [ -f $GRID3_APP_DIR/cmssoft/cmsset_default.sh ] ;then\n'
727     txt += ' # Use $GRID3_APP_DIR/cmssoft/cmsset_default.sh to setup cms software\n'
728 spiga 1.6 txt += ' source $GRID3_APP_DIR/cmssoft/cmsset_default.sh '+self.version+'\n'
729 gutsche 1.1 txt += ' elif [ -f $OSG_APP/cmssoft/cmsset_default.sh ] ;then\n'
730     txt += ' # Use $OSG_APP/cmssoft/cmsset_default.sh to setup cms software\n'
731 spiga 1.6 txt += ' source $OSG_APP/cmssoft/cmsset_default.sh '+self.version+'\n'
732 gutsche 1.1 txt += ' else\n'
733 spiga 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'
734     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
735     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
736     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
737     txt += ' exit 10020 \n'
738 gutsche 1.1 txt += '\n'
739 spiga 1.6 txt += ' echo "Remove working directory: $WORKING_DIR"\n'
740     txt += ' cd $RUNTIME_AREA\n'
741     txt += ' /bin/rm -f $WORKING_DIR\n'
742     txt += ' if [ -d $WORKING_DIR ] ;then\n'
743     txt += ' echo "OSG WORKING DIR ==> $WORKING_DIR could not be deleted on on WN `hostname`"\n'
744     txt += ' fi\n'
745 gutsche 1.1 txt += '\n'
746 spiga 1.6 txt += ' exit 1\n'
747 gutsche 1.1 txt += ' fi\n'
748     txt += '\n'
749     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
750 spiga 1.6 txt += ' echo " END SETUP CMS OSG ENVIRONMENT "\n'
751 gutsche 1.1
752     return txt
753    
754     ### OLI_DANIELE
755     def wsSetupCMSLCGEnvironment_(self):
756     """
757     Returns part of a job script which is prepares
758     the execution environment and which is common for all CMS jobs.
759     """
760     txt = ' \n'
761 spiga 1.6 txt += ' echo " ### SETUP CMS LCG ENVIRONMENT ### "\n'
762 gutsche 1.1 txt += ' echo "JOB_EXIT_STATUS = 0"\n'
763     txt += ' if [ ! $VO_CMS_SW_DIR ] ;then\n'
764 spiga 1.6 txt += ' echo "SET_CMS_ENV 10031 ==> ERROR CMS software dir not found on WN `hostname`"\n'
765     txt += ' echo "JOB_EXIT_STATUS = 10031" \n'
766     txt += ' echo "JobExitCode=10031" | tee -a $RUNTIME_AREA/$repo\n'
767     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
768     txt += ' exit 10031 \n'
769 gutsche 1.1 txt += ' else\n'
770 spiga 1.6 txt += ' echo "Sourcing environment... "\n'
771     txt += ' if [ ! -s $VO_CMS_SW_DIR/cmsset_default.sh ] ;then\n'
772     txt += ' echo "SET_CMS_ENV 10020 ==> ERROR cmsset_default.sh file not found into dir $VO_CMS_SW_DIR"\n'
773     txt += ' echo "JOB_EXIT_STATUS = 10020"\n'
774     txt += ' echo "JobExitCode=10020" | tee -a $RUNTIME_AREA/$repo\n'
775     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
776     txt += ' exit 10020 \n'
777     txt += ' fi\n'
778     txt += ' echo "sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
779     txt += ' source $VO_CMS_SW_DIR/cmsset_default.sh\n'
780     txt += ' result=$?\n'
781     txt += ' if [ $result -ne 0 ]; then\n'
782     txt += ' echo "SET_CMS_ENV 10032 ==> ERROR problem sourcing $VO_CMS_SW_DIR/cmsset_default.sh"\n'
783     txt += ' echo "JOB_EXIT_STATUS = 10032"\n'
784     txt += ' echo "JobExitCode=10032" | tee -a $RUNTIME_AREA/$repo\n'
785     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
786     txt += ' exit 10032 \n'
787     txt += ' fi\n'
788 gutsche 1.1 txt += ' fi\n'
789     txt += ' \n'
790     txt += ' string=`cat /etc/redhat-release`\n'
791     txt += ' echo $string\n'
792     txt += ' if [[ $string = *alhalla* ]]; then\n'
793 spiga 1.6 txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
794 gutsche 1.1 txt += ' elif [[ $string = *Enterprise* ]] || [[ $string = *cientific* ]]; then\n'
795 spiga 1.6 txt += ' export SCRAM_ARCH=slc3_ia32_gcc323\n'
796     txt += ' echo "SCRAM_ARCH= $SCRAM_ARCH"\n'
797 gutsche 1.1 txt += ' else\n'
798 spiga 1.6 txt += ' echo "SET_CMS_ENV 1 ==> ERROR OS unknown, LCG environment not initialized"\n'
799     txt += ' echo "JOB_EXIT_STATUS = 10033"\n'
800     txt += ' echo "JobExitCode=10033" | tee -a $RUNTIME_AREA/$repo\n'
801     txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
802     txt += ' exit 5 \n'
803 gutsche 1.1 txt += ' fi\n'
804     txt += ' echo "SET_CMS_ENV 0 ==> setup cms environment ok"\n'
805 spiga 1.6 txt += ' echo "### END SETUP CMS LCG ENVIRONMENT ###"\n'
806 gutsche 1.1 return txt
807