ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_orca.py
Revision: 1.42
Committed: Wed Mar 29 14:48:42 2006 UTC (19 years, 1 month ago) by fanzago
Content type: text/x-python
Branch: MAIN
Changes since 1.41: +2 -2 lines
Log Message:
changed ../ with  in untar of tgz code

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 nsmirnov 1.3 import PubDB
7 nsmirnov 1.1 import orcarcBuilder
8 slacapra 1.9 import orcarcBuilderOld
9     import Scram
10 slacapra 1.41 import TarBall
11 nsmirnov 1.1
12     import os, string, re
13    
14     class Orca(JobType):
15     def __init__(self, cfg_params):
16     JobType.__init__(self, 'ORCA')
17 slacapra 1.6 common.logger.debug(3,'ORCA::__init__')
18 nsmirnov 1.1
19     self.analisys_common_info = {}
20 corvo 1.36 # Marco.
21     self._params = {}
22     self.cfg_params = cfg_params
23 nsmirnov 1.1
24     log = common.logger
25    
26 slacapra 1.9 self.scram = Scram.Scram(cfg_params)
27 nsmirnov 1.1 scramArea = ''
28 corvo 1.20 self.additional_inbox_files = []
29     self.scriptExe = ''
30 slacapra 1.6
31 slacapra 1.9 self.version = self.scram.getSWVersion()
32 corvo 1.36 self.setParam_('application', self.version)
33 slacapra 1.9 common.analisys_common_info['sw_version'] = self.version
34 fanzago 1.35 ### FEDE
35 fanzago 1.33 common.analisys_common_info['copy_input_data'] = 0
36 fanzago 1.35 common.analisys_common_info['events_management'] = 1
37 nsmirnov 1.1
38 slacapra 1.9 ### collect Data cards
39 nsmirnov 1.1 try:
40 fanzago 1.32 self.owner = cfg_params['ORCA.owner']
41 corvo 1.36 self.setParam_('owner', self.owner)
42 nsmirnov 1.3 log.debug(6, "Orca::Orca(): owner = "+self.owner)
43 fanzago 1.32 self.dataset = cfg_params['ORCA.dataset']
44 corvo 1.36 self.setParam_('dataset', self.dataset)
45 nsmirnov 1.3 log.debug(6, "Orca::Orca(): dataset = "+self.dataset)
46 slacapra 1.9 except KeyError:
47     msg = "Error: owner and/or dataset not defined "
48     raise CrabException(msg)
49    
50     self.dataTiers = []
51     try:
52 fanzago 1.32 tmpDataTiers = string.split(cfg_params['ORCA.data_tier'],',')
53 slacapra 1.9 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 fanzago 1.32 self.executable = cfg_params['ORCA.executable']
65 nsmirnov 1.3 log.debug(6, "Orca::Orca(): executable = "+self.executable)
66 corvo 1.36 self.setParam_('exe', self.executable)
67 slacapra 1.23 except KeyError:
68 slacapra 1.9 msg = "Error: executable not defined "
69     raise CrabException(msg)
70    
71     try:
72 fanzago 1.32 self.orcarc_file = cfg_params['ORCA.orcarc_file']
73 nsmirnov 1.3 log.debug(6, "Orca::Orca(): orcarc file = "+self.orcarc_file)
74 slacapra 1.23 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 slacapra 1.9 log.message("Using empty orcarc file")
78     self.orcarc_file = ''
79 nsmirnov 1.1
80 slacapra 1.9 # output files
81     try:
82 nsmirnov 1.1 self.output_file = []
83    
84 fanzago 1.32 tmp = cfg_params['ORCA.output_file']
85 nsmirnov 1.1 if tmp != '':
86 fanzago 1.32 tmpOutFiles = string.split(cfg_params['ORCA.output_file'],',')
87 nsmirnov 1.3 log.debug(7, 'Orca::Orca(): output files '+str(tmpOutFiles))
88 nsmirnov 1.1 for tmp in tmpOutFiles:
89     tmp=string.strip(tmp)
90     self.output_file.append(tmp)
91     pass
92    
93 slacapra 1.9 else:
94     log.message("No output file defined: only stdout/err will be available")
95 nsmirnov 1.1 pass
96     pass
97     except KeyError:
98 slacapra 1.9 log.message("No output file defined: only stdout/err will be available")
99 nsmirnov 1.1 pass
100    
101 corvo 1.20 # script_exe file as additional file in inputSandbox
102     try:
103 fanzago 1.32 self.scriptExe = cfg_params['ORCA.script_exe']
104 corvo 1.20 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 slacapra 1.9 ## additional input files
115 nsmirnov 1.1 try:
116     tmpAddFiles = string.split(cfg_params['USER.additional_input_files'],',')
117     for tmp in tmpAddFiles:
118     tmp=string.strip(tmp)
119 slacapra 1.7 self.additional_inbox_files.append(tmp)
120 nsmirnov 1.1 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 nsmirnov 1.3 log.debug(6, "Orca::Orca(): total number of events = "+`self.total_number_of_events`)
137 slacapra 1.6 #log.debug(6, "Orca::Orca(): events per job = "+`self.job_number_of_events`)
138 nsmirnov 1.3 log.debug(6, "Orca::Orca(): first event = "+`self.first`)
139 nsmirnov 1.1
140     self.maxEvents=0 # max events available in any PubDB
141 slacapra 1.7 self.connectPubDB(cfg_params)
142 nsmirnov 1.1
143 slacapra 1.9 # [-- self.checkNevJobs() --]
144 nsmirnov 1.1
145 slacapra 1.41 self.TarBaller = TarBall.TarBall(self.executable, self.scram)
146     self.tgzNameWithPath = self.TarBaller.prepareTarBall()
147 nsmirnov 1.1
148 slacapra 1.10 try:
149     self.ML = int(cfg_params['USER.activate_monalisa'])
150     except KeyError:
151     self.ML = 0
152     pass
153 corvo 1.36
154     self.setTaskid_()
155    
156 nsmirnov 1.1 return
157    
158 nsmirnov 1.4 def wsSetupEnvironment(self, nj):
159     """
160     Returns part of a job script which prepares
161     the execution environment for the job 'nj'.
162     """
163    
164     # Prepare JobType-independent part
165     txt = self.wsSetupCMSEnvironment_()
166    
167 fanzago 1.16 # Prepare JobType-specific part
168     scram = self.scram.commandName()
169     txt += '\n\n'
170     txt += 'echo "### SPECIFIC JOB SETUP ENVIRONMENT ###"\n'
171     txt += scram+' project ORCA '+self.version+'\n'
172     txt += 'status=$?\n'
173     txt += 'if [ $status != 0 ] ; then\n'
174     txt += ' echo "SET_EXE_ENV 1 ==>ERROR ORCA '+self.version+' not found on `hostname`" \n'
175 corvo 1.38 txt += ' echo "JOB_EXIT_STATUS = 10034"\n'
176     txt += ' echo "JobExitCode=10034" | tee -a $RUNTIME_AREA/$repo\n'
177 corvo 1.28 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
178 corvo 1.38 txt += ' exit 10034 \n'
179 fanzago 1.16 txt += 'fi \n'
180     txt += 'echo "ORCA_VERSION = '+self.version+'"\n'
181     txt += 'cd '+self.version+'\n'
182 fanzago 1.29 ### needed grep for bug in scramv1 ###
183 fanzago 1.35 #txt += 'eval `'+scram+' runtime -sh | grep -v SCRAMRT_LSB_JOBNAME`\n'
184 fanzago 1.16
185 slacapra 1.9 # Handle the arguments:
186     txt += "\n"
187 slacapra 1.41 txt += "## ARGUMENTS: $1 Job Number\n"
188     txt += "## ARGUMENTS: $2 First Event for this job\n"
189     txt += "## ARGUMENTS: $3 Max Event for this job\n"
190 slacapra 1.9 txt += "\n"
191     txt += "narg=$#\n"
192     txt += "if [ $narg -lt 3 ]\n"
193     txt += "then\n"
194 fanzago 1.16 txt += " echo 'SET_EXE_ENV 1 ==> ERROR Too few arguments' +$narg+ \n"
195 corvo 1.38 txt += ' echo "JOB_EXIT_STATUS = 50113"\n'
196     txt += ' echo "JobExitCode=50113" | tee -a $RUNTIME_AREA/$repo\n'
197 corvo 1.28 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
198 slacapra 1.9 txt += " exit 1\n"
199     txt += "fi\n"
200 fanzago 1.16 txt += "\n"
201 slacapra 1.10 txt += "NJob=$1\n"
202     txt += "FirstEvent=$2\n"
203 afanfani 1.24 txt += "MaxEvents=$3\n"
204 corvo 1.38 txt += 'echo "MonitorID=`echo ' + self._taskId + '`" | tee -a $RUNTIME_AREA/$repo\n'
205     txt += 'echo "MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
206     txt += 'echo "SyncGridJobId=`echo $EDG_WL_JOBID`" | tee -a $RUNTIME_AREA/$repo\n'
207     txt += 'echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo\n'
208 corvo 1.36 txt += 'dumpStatus $RUNTIME_AREA/$repo\n'
209 nsmirnov 1.4
210     # Prepare job-specific part
211     job = common.job_list[nj]
212     orcarc = os.path.basename(job.configFilename())
213     txt += '\n'
214     txt += 'cp $RUNTIME_AREA/'+orcarc+' .orcarc\n'
215 slacapra 1.22 txt += 'if [ -e $RUNTIME_AREA/orcarc_$CE ] ; then\n'
216 fanzago 1.34 txt += ' cat $RUNTIME_AREA/orcarc_$CE .orcarc >> .orcarc_tmp\n'
217     txt += ' mv .orcarc_tmp .orcarc\n'
218 slacapra 1.22 txt += 'fi\n'
219     txt += 'if [ -e $RUNTIME_AREA/init_$CE.sh ] ; then\n'
220 fanzago 1.34 txt += ' cp $RUNTIME_AREA/init_$CE.sh init.sh\n'
221 nsmirnov 1.4 txt += 'fi\n'
222 fanzago 1.26
223     if len(self.additional_inbox_files) > 0:
224     for file in self.additional_inbox_files:
225 fanzago 1.34 file = os.path.basename(file)
226 fanzago 1.26 txt += 'if [ -e $RUNTIME_AREA/'+file+' ] ; then\n'
227 fanzago 1.34 txt += ' cp $RUNTIME_AREA/'+file+' .\n'
228     txt += ' chmod +x '+file+'\n'
229 fanzago 1.26 txt += 'fi\n'
230 fanzago 1.39 pass
231 fanzago 1.26
232 nsmirnov 1.4 txt += '\n'
233     txt += 'chmod +x ./init.sh\n'
234     txt += './init.sh\n'
235     txt += 'exitStatus=$?\n'
236     txt += 'if [ $exitStatus != 0 ] ; then\n'
237 fanzago 1.34 txt += ' echo "SET_EXE_ENV 1 ==> ERROR StageIn init script failed"\n'
238     txt += ' echo "JOB_EXIT_STATUS = $exitStatus" \n'
239 corvo 1.38 txt += ' echo "JobExitCode=20001" | tee -a $RUNTIME_AREA/$repo\n'
240 fanzago 1.34 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
241     txt += ' exit $exitStatus\n'
242 nsmirnov 1.4 txt += 'fi\n'
243 fanzago 1.16 txt += "echo 'SET_EXE_ENV 0 ==> job setup ok'\n"
244     txt += 'echo "### END JOB SETUP ENVIRONMENT ###"\n\n'
245 slacapra 1.9
246 slacapra 1.10 txt += 'echo "FirstEvent=$FirstEvent" >> .orcarc\n'
247 afanfani 1.24 txt += 'echo "MaxEvents=$MaxEvents" >> .orcarc\n'
248 slacapra 1.10 if self.ML:
249     txt += 'echo "MonalisaJobId=$NJob" >> .orcarc\n'
250    
251     txt += '\n'
252     txt += 'echo "***** cat .orcarc *********"\n'
253     txt += 'cat .orcarc\n'
254     txt += 'echo "****** end .orcarc ********"\n'
255 nsmirnov 1.4 return txt
256    
257     def wsBuildExe(self, nj):
258     """
259     Put in the script the commands to build an executable
260     or a library.
261     """
262    
263     txt = ""
264    
265 fanzago 1.12 if os.path.isfile(self.tgzNameWithPath):
266 fanzago 1.42 txt += 'echo "tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'"\n'
267     txt += 'tar xzvf $RUNTIME_AREA/'+os.path.basename(self.tgzNameWithPath)+'\n'
268 nsmirnov 1.4 txt += 'untar_status=$? \n'
269     txt += 'if [ $untar_status -ne 0 ]; then \n'
270 fanzago 1.34 txt += ' echo "SET_EXE 1 ==> ERROR Untarring .tgz file failed"\n'
271     txt += ' echo "JOB_EXIT_STATUS = $untar_status" \n'
272 corvo 1.38 txt += ' echo "SanityCheckCode=$untar_status" | tee -a $repo\n'
273 fanzago 1.34 txt += ' exit $untar_status \n'
274 nsmirnov 1.4 txt += 'else \n'
275 fanzago 1.34 txt += ' echo "Successful untar" \n'
276 nsmirnov 1.4 txt += 'fi \n'
277     # TODO: what does this code do here ?
278     # SL check that lib/Linux__... is present
279 slacapra 1.9 txt += 'mkdir -p lib/${SCRAM_ARCH} \n'
280 nsmirnov 1.4 pass
281 fanzago 1.37 txt += 'eval `'+self.scram.commandName()+' runtime -sh |grep -v SCRAMRT_LSB_JOBNAME`'+'\n'
282 nsmirnov 1.4
283     return txt
284    
285     def wsRenameOutput(self, nj):
286     """
287     Returns part of a job script which renames the produced files.
288     """
289 slacapra 1.9
290 nsmirnov 1.4 txt = '\n'
291 fanzago 1.15 file_list = ''
292 slacapra 1.9 for fileWithSuffix in self.output_file:
293     output_file_num = self.numberFile_(fileWithSuffix, '$NJob')
294 fanzago 1.15 file_list=file_list+output_file_num+','
295 fanzago 1.26 txt += '\n'
296     txt += 'ls \n'
297     txt += '\n'
298 spiga 1.17 txt += 'ls '+fileWithSuffix+'\n'
299 fanzago 1.18 txt += 'exe_result=$?\n'
300     txt += 'if [ $exe_result -ne 0 ] ; then\n'
301 fanzago 1.34 txt += ' echo "ERROR: No output file to manage"\n'
302     txt += ' echo "JOB_EXIT_STATUS = $exe_result"\n'
303 corvo 1.38 txt += ' echo "JobExitCode=60302" | tee -a $RUNTIME_AREA/$repo\n'
304 fanzago 1.34 txt += ' dumpStatus $RUNTIME_AREA/$repo\n'
305     txt += ' exit $exe_result \n'
306 spiga 1.17 txt += 'else\n'
307 fanzago 1.34 txt += ' cp '+fileWithSuffix+' $RUNTIME_AREA/'+output_file_num+'\n'
308 fanzago 1.25 txt += 'fi\n'
309 fanzago 1.40 pass
310 fanzago 1.37
311 fanzago 1.40 txt += 'cd $RUNTIME_AREA\n'
312 fanzago 1.15 file_list=file_list[:-1]
313     txt += 'file_list='+file_list+'\n'
314 nsmirnov 1.4 return txt
315    
316 nsmirnov 1.1 def executableName(self):
317 corvo 1.20 if self.scriptExe != '':
318     return "./" + os.path.basename(self.scriptExe)
319     else:
320     return self.executable
321 nsmirnov 1.1
322 slacapra 1.7 def connectPubDB(self, cfg_params):
323 nsmirnov 1.1
324 nsmirnov 1.3 fun = "Orca::connectPubDB()"
325    
326 nsmirnov 1.1 self.allOrcarcs = []
327     # first check if the info from PubDB have been already processed
328     if os.path.exists(common.work_space.shareDir()+'PubDBSummaryFile') :
329 nsmirnov 1.3 common.logger.debug(6, fun+": info from PubDB has been already processed -- use it")
330 nsmirnov 1.1 f = open( common.work_space.shareDir()+'PubDBSummaryFile', 'r' )
331     for i in f.readlines():
332     a=string.split(i,' ')
333 slacapra 1.9 self.allOrcarcs.append(orcarcBuilderOld.constructFromFile(a[0:-1]))
334 nsmirnov 1.1 pass
335     for o in self.allOrcarcs:
336     # o.dump()
337     if o.Nevents >= self.maxEvents:
338     self.maxEvents= o.Nevents
339     pass
340     pass
341     pass
342    
343     else: # PubDB never queried
344 nsmirnov 1.3 common.logger.debug(6, fun+": PubDB was never queried -- do it")
345 nsmirnov 1.1 # New PubDB class by SL
346     try:
347 nsmirnov 1.3 self.pubdb = PubDB.PubDB(self.owner,
348 nsmirnov 1.1 self.dataset,
349 slacapra 1.7 self.dataTiers,
350     cfg_params)
351 slacapra 1.9 except PubDB.RefDBmapError:
352 nsmirnov 1.1 msg = 'ERROR ***: accessing PubDB'
353     raise CrabException(msg)
354    
355 slacapra 1.9 ## extract info from pubDB (grouped by PubDB version :
356     ## pubDBData contains a list of info for the new-style PubDBs,
357     ## and a list of info for the old-style PubDBs )
358     self.pubDBData = self.pubdb.getAllPubDBData()
359    
360     ## check and exit if no data are published in any PubDB
361     nodata=1
362     for PubDBversion in self.pubDBData.keys():
363     if len(self.pubDBData[PubDBversion])>0:
364     nodata=0
365     if (nodata):
366     msg = 'Owner '+self.owner+' Dataset '+ self.dataset+ ' not published in any PubDB with asked dataTiers '+string.join(self.dataTiers,'-')+' ! '
367 nsmirnov 1.1 raise CrabException(msg)
368 nsmirnov 1.3
369 slacapra 1.9 ## logging PubDB content for debugging
370     for PubDBversion in self.pubDBData.keys():
371     common.logger.debug(6, fun+": PubDB "+PubDBversion+" info ("+`len(self.pubDBData[PubDBversion])`+"):\/")
372     for aa in self.pubDBData[PubDBversion]:
373     common.logger.debug(6, "---------- start of a PubDB")
374     for bb in aa:
375     if common.logger.debugLevel() >= 6 :
376     common.logger.debug(6, str(bb.dump()))
377     pass
378     pass
379     common.logger.debug(6, "----------- end of a PubDB")
380     common.logger.debug(6, fun+": End of PubDB "+PubDBversion+" info\n")
381 nsmirnov 1.1
382    
383 slacapra 1.9 ## building orcarc : switch between info from old and new-style PubDB
384 nsmirnov 1.1 currDir = os.getcwd()
385     os.chdir(common.work_space.jobDir())
386 slacapra 1.9
387     tmpOrcarcList=[]
388     for PubDBversion in self.pubDBData.keys():
389     if len(self.pubDBData[PubDBversion])>0 :
390     #print (" PubDB-style : %s"%(PubDBversion))
391     if PubDBversion=='newPubDB' :
392 slacapra 1.19 self.builder = orcarcBuilder.orcarcBuilder(cfg_params)
393 slacapra 1.9 else :
394     self.builder = orcarcBuilderOld.orcarcBuilderOld()
395     tmpAllOrcarcs = self.builder.createOrcarcAndInit(self.pubDBData[PubDBversion])
396     tmpOrcarcList.append(tmpAllOrcarcs)
397     #print 'version ',PubDBversion,' tmpAllOrcarcs ', tmpAllOrcarcs
398    
399     #print tmpOrcarcList
400 nsmirnov 1.1 os.chdir(currDir)
401    
402     self.maxEvents=0
403 slacapra 1.9 for tmpAllOrcarcs in tmpOrcarcList:
404     for o in tmpAllOrcarcs:
405     numEvReq=self.total_number_of_events
406     if ((numEvReq == '-1') | (numEvReq <= o.Nevents)):
407     self.allOrcarcs.append(o)
408 slacapra 1.31 if (int(o.Nevents) >= self.maxEvents):
409     self.maxEvents= int(o.Nevents)
410 slacapra 1.9 pass
411 nsmirnov 1.1 pass
412     pass
413    
414     # set maximum number of event available
415    
416     # I save to a file self.allOrcarcs
417    
418     PubDBSummaryFile = open(common.work_space.shareDir()+'PubDBSummaryFile','w')
419     for o in self.allOrcarcs:
420     for d in o.content():
421     PubDBSummaryFile.write(d)
422     PubDBSummaryFile.write(' ')
423     pass
424     PubDBSummaryFile.write('\n')
425     pass
426     PubDBSummaryFile.close()
427 fanzago 1.29 ### fede
428 fanzago 1.40 #for o in self.allOrcarcs:
429     # o.dump()
430 nsmirnov 1.1 pass
431    
432     # build a list of sites
433     ces= []
434     for o in self.allOrcarcs:
435     ces.append(o.CE)
436     pass
437    
438     if len(ces)==0:
439 slacapra 1.9 msg = 'No PubDBs publish correct catalogs or enough events! '
440 nsmirnov 1.1 msg += `self.total_number_of_events`
441     raise CrabException(msg)
442    
443 nsmirnov 1.3 common.logger.debug(6, "List of CEs: "+str(ces))
444 slacapra 1.6 common.analisys_common_info['sites']=ces
445 nsmirnov 1.1
446     return
447    
448     def nJobs(self):
449     # TODO: should not be here !
450     # JobType should have no internal knowledge about submitted jobs
451     # One possibility is to use len(common.job_list).
452     """ return the number of job to be created """
453 slacapra 1.6 return len(common.job_list)
454 nsmirnov 1.5
455     def prepareSteeringCards(self):
456     """
457     modify the orcarc card provided by the user,
458     writing a new card into share dir
459     """
460     infile = ''
461     try:
462     infile = open(self.orcarc_file,'r')
463     except:
464     self.orcarc_file = 'empty.orcarc'
465     cmd='touch '+self.orcarc_file
466 slacapra 1.9 runCommand(cmd)
467 nsmirnov 1.5 infile = open(self.orcarc_file,'r')
468    
469 slacapra 1.9 outfile = open(common.work_space.jobDir()+self.name()+'.orcarc', 'w')
470 nsmirnov 1.5
471     inline=infile.readlines()
472     ### remove from user card these lines ###
473 slacapra 1.9 wordRemove=['InputFileCatalogURL', 'InputCollections', 'FirstEvent', 'MaxEvents', 'TFileAdaptor']
474     for line in inline:
475     word = string.strip(string.split(line,'=')[0])
476 slacapra 1.8
477 slacapra 1.9 if word not in wordRemove:
478     outfile.write(line)
479     else:
480     continue
481     pass
482    
483     outfile.write('\n\n##### The following cards have been created by CRAB: DO NOT TOUCH #####\n')
484     outfile.write('TFileAdaptor = true\n')
485    
486 slacapra 1.10 if (self.ML) :
487     outfile.write('MonalisaAddPid = false\n')
488     outfile.write('ExtraPackages=RecApplPlugins\n')
489     outfile.write('MonRecAlisaBuilder=true\n')
490     ## TaskId is username+crab_0_date_time : that should be unique
491 corvo 1.36 # TaskID = os.getlogin()+'_'+string.split(common.work_space.topDir(),'/')[-2]
492     outfile.write('MonalisaApplName='+self._taskId+'\n')
493 corvo 1.38 outfile.write('MonalisaNode=137.138.4.152\n')
494 slacapra 1.10 outfile.write('MonalisaPort=58884\n')
495     pass
496    
497 slacapra 1.9 outfile.write('InputCollections=/System/'+self.owner+'/'+self.dataset+'/'+self.dataset+'\n')
498 slacapra 1.8
499 nsmirnov 1.5 infile.close()
500     outfile.close()
501     return
502 nsmirnov 1.1
503     def modifySteeringCards(self, nj):
504     """
505     Creates steering cards file modifying a template file
506     """
507     return
508    
509     def cardsBaseName(self):
510     """
511     Returns name of user orcarc card-file
512     """
513     return os.path.split (self.orcarc_file)[1]
514    
515 fanzago 1.27 ### content of input_sanbdox ...
516 nsmirnov 1.1 def inputSandbox(self, nj):
517     """
518     Returns a list of filenames to be put in JDL input sandbox.
519     """
520     inp_box = []
521 corvo 1.13 # dict added to delete duplicate from input sandbox file list
522     seen = {}
523 slacapra 1.7 ## code
524 fanzago 1.12 if os.path.isfile(self.tgzNameWithPath):
525     inp_box.append(self.tgzNameWithPath)
526 slacapra 1.7 ## orcarc
527 nsmirnov 1.1 for o in self.allOrcarcs:
528     for f in o.fileList():
529 corvo 1.13 if (f not in seen.keys()):
530     inp_box.append(common.work_space.jobDir()+f)
531     seen[f] = 1
532 slacapra 1.9
533 slacapra 1.7 ## config
534 nsmirnov 1.1 inp_box.append(common.job_list[nj].configFilename())
535 slacapra 1.7 ## additional input files
536 fanzago 1.26 #inp_box = inp_box + self.additional_inbox_files
537 nsmirnov 1.1 return inp_box
538    
539 fanzago 1.15 ### and of output_sandbox
540 nsmirnov 1.1 def outputSandbox(self, nj):
541     """
542     Returns a list of filenames to be put in JDL output sandbox.
543     """
544     out_box = []
545    
546 slacapra 1.9 stdout=common.job_list[nj].stdout()
547     stderr=common.job_list[nj].stderr()
548 fanzago 1.15 #out_box.append(stdout)
549     #out_box.append(stderr)
550 slacapra 1.9
551 slacapra 1.7 ## User Declared output files
552 slacapra 1.9 for out in self.output_file:
553 fanzago 1.14 n_out = nj + 1
554 fanzago 1.25 #FEDE
555     #out_box.append(self.version+'/'+self.numberFile_(out,str(n_out)))
556     out_box.append(self.numberFile_(out,str(n_out)))
557 nsmirnov 1.1 return out_box
558 slacapra 1.7
559 fanzago 1.32 def getRequirements(self):
560     """
561     return job requirements to add to jdl files
562     """
563     req = ''
564     if common.analisys_common_info['sites']:
565     if common.analisys_common_info['sw_version']:
566     req='Member("VO-cms-' + \
567     common.analisys_common_info['sw_version'] + \
568     '", other.GlueHostApplicationSoftwareRunTimeEnvironment)'
569     if len(common.analisys_common_info['sites'])>0:
570     req = req + ' && ('
571     for i in range(len(common.analisys_common_info['sites'])):
572     req = req + 'other.GlueCEInfoHostName == "' \
573     + common.analisys_common_info['sites'][i] + '"'
574     if ( i < (int(len(common.analisys_common_info['sites']) - 1)) ):
575     req = req + ' || '
576     req = req + ')'
577     #print "req = ", req
578     return req
579    
580 slacapra 1.9 def numberFile_(self, file, txt):
581     """
582     append _'txt' before last extension of a file
583     """
584     p = string.split(file,".")
585     # take away last extension
586     name = p[0]
587     for x in p[1:-1]:
588     name=name+"."+x
589     # add "_txt"
590     if len(p)>1:
591     ext = p[len(p)-1]
592 fanzago 1.14 #result = name + '_' + str(txt) + "." + ext
593     result = name + '_' + txt + "." + ext
594 slacapra 1.9 else:
595 fanzago 1.14 #result = name + '_' + str(txt)
596     result = name + '_' + txt
597 slacapra 1.9
598     return result
599    
600    
601 slacapra 1.7 def stdOut(self):
602     return self.stdOut_
603    
604     def stdErr(self):
605     return self.stdErr_
606 corvo 1.36
607     # marco
608     def setParam_(self, param, value):
609     self._params[param] = value
610    
611     def getParams(self):
612     return self._params
613    
614     def setTaskid_(self):
615     self._taskId = self.cfg_params['user'] + '_' + string.split(common.work_space.topDir(),'/')[-2]
616    
617     def getTaskid(self):
618     return self._taskId
619     # marco