ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/multicrab.py
(Generate patch)

Comparing COMP/CRAB/python/multicrab.py (file contents):
Revision 1.6 by slacapra, Tue Dec 2 15:41:29 2008 UTC vs.
Revision 1.20 by slacapra, Fri Jan 8 13:35:31 2010 UTC

# Line 25 | Line 25 | class MultiCrab:
25          print self.prog_name + ' running on ' +  time.ctime(time.time())
26          print '  working directory   ' + self.continue_dir
27  
28        crabs=[]
28  
29      def processContinueOption_(self,opts):
30  
# Line 99 | Line 98 | class MultiCrab:
98              if ( opt == '-cfg' ):
99                  if self.flag_continue:
100                      raise CrabException('-continue and -cfg cannot coexist.')
101 <                if opts[opt] : self.cfg_fname = opts[opt]
101 >                if opts[opt] :
102 >                    self.cfg_fname = opts[opt]
103 >                    del opts[opt] # do not pass cfg further on
104                  else : processHelpOptions()
105                  pass
106              pass
# Line 116 | Line 117 | class MultiCrab:
117  
118          # Load cfg-file
119  
120 +        cfg_params = {}
121          if self.cfg_fname != None:
122              if os.path.exists(self.cfg_fname):
123 <                self.cfg_params = self.loadMultiConfig(self.cfg_fname)
123 >                cfg_params = self.loadMultiConfig(self.cfg_fname)
124                  pass
125              else:
126                  msg = 'cfg-file '+self.cfg_fname+' not found.'
# Line 129 | Line 131 | class MultiCrab:
131          # process the [CRAB] section
132  
133          lhp = len('MULTICRAB.')
134 <        for k in self.cfg_params.keys():
134 >        for k in cfg_params.keys():
135              if len(k) >= lhp and k[:lhp] == 'MULTICRAB.':
136                  opt = '-'+k[lhp:]
137                  if len(opt) >= 3 and opt[:3] == '-__': continue
138                  if opt not in opts.keys():
139 <                    opts[opt] = self.cfg_params[k]
139 >                    opts[opt] = cfg_params[k]
140                      pass
141                  pass
142              pass
# Line 142 | Line 144 | class MultiCrab:
144          self.cfg_params_dataset = {}
145          common_opts = {}
146          # first get common sections
147 <        for sec in self.cfg_params:
147 >        for sec in cfg_params:
148              if sec in ['MULTICRAB']:
149 <                cfg_common=self.cfg_params[sec]
149 >                if 'cfg' in cfg_params[sec]:
150 >                    common_opts['cfg']=cfg_params[sec]['cfg']
151                  continue
152              if sec in ['COMMON']:
153 <                common_opts=self.cfg_params[sec]
153 >                common_opts.update(cfg_params[sec])
154                  continue
155              pass
156  
157 +        crab_cfg='crab.cfg'
158 +        if common_opts.has_key('cfg') : crab_cfg=common_opts['cfg']
159 +
160          # then Dataset's specific
161 <        for sec in self.cfg_params:
161 >        for sec in cfg_params:
162              if sec in ['MULTICRAB', 'COMMON']: continue
163 <            self.cfg_params_dataset[sec]=self.cfg_params[sec]
163 >            self.cfg_params_dataset[sec]=cfg_params[sec]
164              # add common to all dataset
165              for key in common_opts:
166                  self.cfg_params_dataset[sec][key]=common_opts[key]
167              pass
168  
163        self.cfg=cfg_common['cfg']
164
169          # read crab.cfg file and search for storage_path
170 <        cfg_params = loadConfig(self.cfg,{})
171 <        if self.cfg_params.has_key("COMMON"):
172 <            self.user_remote_dir = self.cfg_params["COMMON"].get("user.user_remote_dir", cfg_params.get("USER.user_remote_dir",None))
170 >        crab_cfg_params = loadConfig(crab_cfg,{})
171 >        # also USER.ui_working_dir USER.outputdir and USER.logdir need special treatment
172 >        if cfg_params.has_key("COMMON"):
173 >            self.user_remote_dir = cfg_params["COMMON"].get("user.user_remote_dir", crab_cfg_params.get("USER.user_remote_dir",None))
174 >            self.outputdir = cfg_params["COMMON"].get("user.outputdir", crab_cfg_params.get("USER.outputdir",None))
175 >            self.logdir = cfg_params["COMMON"].get("user.logdir", crab_cfg_params.get("USER.logdir",None))
176 >            self.ui_working_dir = cfg_params["COMMON"].get("user.ui_working_dir", crab_cfg_params.get("USER.ui_working_dir",None))
177          else:
178 <            self.user_remote_dir = cfg_params.get("USER.user_remote_dir",None)
178 >            self.user_remote_dir = crab_cfg_params.get("USER.user_remote_dir",None)
179 >            self.outputdir = crab_cfg_params.get("USER.outputdir",None)
180 >            self.logdir = crab_cfg_params.get("USER.logdir",None)
181 >            self.ui_working_dir = crab_cfg_params.get("USER.ui_working_dir",None)
182 >
183          return
184  
185      def loadMultiConfig(self, file):
# Line 188 | Line 200 | class MultiCrab:
200  
201      def run(self):
202          #run crabs
203 +        runFileName = 'multicrab.exe'
204 +        runFile = open(runFileName,"w")
205          for sec in self.cfg_params_dataset:
206              options={}
207              if self.flag_continue:
# Line 196 | Line 210 | class MultiCrab:
210              options['-USER.ui_working_dir']=sec
211              # options from multicrab.cfg
212              for opt in self.cfg_params_dataset[sec]:
213 <                tmp="-"+string.upper(opt.split(".")[0])+"."+opt.split(".")[1]
213 >                tmp = "-"+str(opt)
214 >                if len(opt.split("."))==2:
215 >                    tmp="-"+string.upper(opt.split(".")[0])+"."+opt.split(".")[1]
216 >                
217                  options[tmp]=self.cfg_params_dataset[sec][opt]
218 +
219              # add section to storage_path if exist in crab.cfg
220              if not self.cfg_params_dataset.has_key("USER.user_remote_dir") and self.user_remote_dir:
221                  options["-USER.user_remote_dir"]=self.user_remote_dir+"/"+sec
222 +            # also for ui_working_dir
223 +            if not self.cfg_params_dataset.has_key("USER.ui_working_dir") and self.ui_working_dir:
224 +                options["-USER.ui_working_dir"]=self.ui_working_dir+"/"+sec
225 +            # also for logDir
226 +            if not self.cfg_params_dataset.has_key("USER.logdir") and self.logdir:
227 +                options["-USER.logdir"]=self.logdir+"/"+sec
228 +            # also for outputdir
229 +            if not self.cfg_params_dataset.has_key("USER.outputdir") and self.outputdir:
230 +                options["-USER.outputdir"]=self.outputdir+"/"+sec
231 +
232              # Input options (command)
233              for opt in self.opts:
234                  options[opt]=self.opts[opt]
235 <            try:
236 <                #print options
209 <                crab = Crab(options)
210 <                crab.run()
211 <                common.apmon.free()
212 <                del crab
213 <            except CrabException, e:
214 <                print '\n' + common.prog_name + ': ' + str(e) + '\n'
215 <                if common.logger:
216 <                    common.logger.write('ERROR: '+str(e)+'\n')
217 <                    pass
235 >                if self.flag_continue and options.has_key("-cfg"):
236 >                    del options['-cfg']
237                  pass
238 <            pass
238 > <<<<<<< multicrab.py
239 >
240 >            # write crab command to be executed later...
241 >            cmd='crab '
242 >            for o in options:
243 >                if options[o]==None:
244 >                    cmd+=str(o)+' '
245 >                else:
246 >                    options[o] = ''.join(options[o].split())
247 >                    cmd+=str(o)+'='+str(options[o])+' '
248 >                pass
249 >            cmd+="\n"
250 >            #print cmd
251 >
252 >            runFile.write(cmd)
253 >
254 >            # SL this does not work for complex, multi include pset.py
255 >
256 >            # crab = Crab()
257 >            # try:
258 >            #     crab.initialize_(options)
259 >            #     crab.run()
260 >            #     del crab
261 >            #     print 'Log file is %s%s.log'%(common.work_space.logDir(),common.prog_name)  
262 >            #     print '\n##############################  E N D  ####################################\n'
263 >            # except CrabException, e:
264 >            #     del crab
265 >            #     print '\n' + common.prog_name + ': ' + str(e) + '\n'
266 >            #     pass
267 >            # pass
268 >            # if (common.logger): common.logger.delete()
269 > =======
270 >
271 >            # write crab command to be executed later...
272 >            cmd='crab '
273 >            for o in options:
274 >                if options[o]==None: options[o]=""
275 >                cmd+=str(o)+'='+str(options[o])+' '
276 >            cmd+="\n"
277 >            # print cmd
278 >
279 >            runFile.write(cmd)
280 >
281 >            # SL this does not work for complex, multi include pset.py
282 >
283 >            # crab = Crab()
284 >            # try:
285 >            #     crab.initialize_(options)
286 >            #     crab.run()
287 >            #     del crab
288 >            #     print 'Log file is %s%s.log'%(common.work_space.logDir(),common.prog_name)  
289 >            #     print '\n##############################  E N D  ####################################\n'
290 >            # except CrabException, e:
291 >            #     del crab
292 >            #     print '\n' + common.prog_name + ': ' + str(e) + '\n'
293 >            #     pass
294 >            # pass
295 >            # if (common.logger): common.logger.delete()
296 > >>>>>>> 1.19
297          pass
298          
222        #common.apmon.free()
299  
300   ###########################################################################
301   if __name__ == '__main__':

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines