ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/cms_orca.py
Revision: 1.45
Committed: Thu Apr 6 08:03:51 2006 UTC (19 years ago) by corvo
Content type: text/x-python
Branch: MAIN
Changes since 1.44: +1 -10 lines
Log Message:
switched off ML reporting from Framework

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