def main(): parser = optparse.OptionParser(version='1.0.3') parser.add_option('', '--phast',dest='phast',default='phast', help='Path to PHAST program', metavar='PATH') parser.add_option('', '--phast-opts',dest='phast_opts',default='-D7 -m -f', help='PHAST options', type='string', metavar='OPTS') parser.usage = '%prog [options] <mDST dir> [<mDST dir2> ...]\n' \ 'Merge PHAST mDST files.\n' \ 'Author: [email protected]' parser.description = 'Output file will be named (assuming it was a run 55555) mDST-55555.root' (options, args) = parser.parse_args() if len(args)<1: parser.print_help() return 1 for d in args: files = [] print BLUE+BOLD+('Working in %s'%d)+RESET print RED+BOLD+'Removing previous PHAST merged files.'+RESET for f in castor.castor_files(d,'^mDST-\d+\.root(\.\d\d){0,1}$'): os.system('rfrm %s' % f) print 'Geting the list of files...' run = None for f in castor.castor_files(d,'mDST.*\.root'): if not files: # Get run number from file name r=re.search('.*cdr\d+-(?P<run>\d+).*',f) if not r: print 'Bad file name:',f return 1 run = int(r.group('run')) files.append(f) if len(files)==0: print RED+BOLD+'No files are found!'+RESET return 1 assert (run!=None) command = options.phast + ' ' + options.phast_opts command += ' -o %s/mDST-%d.root -h %s/hist-%d.root ' % (d,run,d,run) command += ' '.join(files) if os.system(command): print RED+BOLD+'Error!'+RESET return 1 return 0
def get_period_files_cern(period,dir_name='mDST',print_files=False): from CS.castor import castor_files compass_data = '/castor/cern.ch/compass/data/' d = compass_data+str(period.year())+'/oracle_dst/'+period.name()+'/'+dir_name files=[] for f in castor_files(d): name = os.path.split(f)[1] try: run,cdr,slot,phast,n = decode_mDST_name(name) except: print 'Bad name:',name continue if slot!=period.slot(): continue files.append(f) if print_files: print f return files
def main(): parser = optparse.OptionParser(version='1.0.2') parser.add_option('', '--noterm',dest='noterm',default=False,action='store_true', help='Do not use fancy output (terminal properties).') parser.add_option('', '--print-good-logs',dest='print_good_logs',default=False,action='store_true', help='Print good log file names.') parser.usage = 'cs %prog <options> [dir-with-logs]\n'\ 'Author: [email protected]' parser.description = 'Analyze CORAL log files.' (options, args) = parser.parse_args() if len(args)!=1: parser.print_help() return 1 try: if options.noterm: raise '' import term terminal = term.TerminalController() except: terminal = None #no_colors() files = [] run = 0 for f in castor.castor_files(args[0],'cdr.*\.log'): if not files: # Get run number from file name r=re.search('.*cdr\d+-(?P<run>\d+).*',f) if not r: print 'Bad file name:',f return 1 run = int(r.group('run')) files.append(f) if terminal: progress = term.ProgressBar(terminal, 'Analysing %d CORAL log files of the run %d' % (len(files),run)) else: print 'There are %d CORAL log files to analyze.' % len(files) logs_ok = [] logs_bad = [] i=0 n_files = 0.001+len(files) for i in range(len(files)): f = files[i] if terminal: progress.update(i/n_files, 'Analysing file %s' % f) else: if i%10==0: print ' %d%%' % int((i*100)/n_files), sys.stdout.flush() status = coral_log_analyze(f) if status.ok(): logs_ok.append(f) else: logs_bad.append(f) if terminal: progress.update((i+1)/n_files, 'FINISHED') else: print if options.print_good_logs: print 'List of good log files:' for f in logs_ok: print f ok = len(logs_ok) bad = len(logs_bad) print 'Out of %d jobs %d(%d%%) finished successfully' % (ok+bad,ok,(ok*100)/(ok+bad+0.001))