Skip to content
Snippets Groups Projects
Commit 52350a60 authored by Wainer Vandelli's avatar Wainer Vandelli
Browse files

Merged file migration modules implementing the new naming convention

parent d3f278a5
No related branches found
No related tags found
No related merge requests found
#!/bin/env python
__version__='$Revision:$'
# $Source$
from SFOFileNameParser import SFOFileNameParser
import os.path
import sys
from subprocess import *
BASEDIR = '/castor/cern.ch/grid/atlas/tzero/prod1/perm/'
def nsls(target, castorenv, opts=[]):
command = ['nsls']
command.extend(opts)
command.append(target)
kwds = {}
if castorenv:
kwds['env'] = castorenv
nsls = Popen(command, stdout = PIPE,
stderr = STDOUT, **kwds)
nslsOut, _ = nsls.communicate()
ret = nsls.wait()
return ((ret == 0), nslsOut)
def MergedMigratedNew(castorfile, castorenv):
"""
Destination directory:
/<basedir>/<projecttag>/<streamtype_streamname>/<runnr-7digit>/<dataset>/
basedir = /castor/cern.ch/grid/atlas/tzero/prod1/perm/
projecttag = data09_cos
dataset = data09_cos.00122050.physics_IDCosmic.merge.RAW
Merged file name is:
1) if all SFO files of a LB fit into a single file
<project>.<runnr>.<stream>.daq.RAW._lbXXXX._SFO-N._<fileseqnr>.data, N=4,5,9,10
--> <project>.<runnr>.<stream>.merge.RAW._lbXXXX._SFO-ALL._0001.<attemptnr>
2) if all SFO files of a LB don't fit into a single file
<project>.<runnr>.<stream>.daq.RAW._lbXXXX._SFO-N._<fileseqnr>.data, N=4,5,9,10
--> <project>.<runnr>.<stream>.merge.RAW._lbXXXX._SFO-N._<fileseqnr>.<attemptnr>, N=4,5,9,10
"""
### Build the target directory name
parsed = SFOFileNameParser(os.path.basename(castorfile))
dataset = '%s.%s.%s_%s.merge.RAW' \
% (parsed.ProjectTag(), parsed.RunNr(), \
parsed.StreamType(), parsed.StreamName())
path = os.path.join(BASEDIR, parsed.ProjectTag(), \
'%s_%s' % (parsed.StreamType(), parsed.StreamName()), \
'%07d' % int(parsed.RunNr()), \
'%s' % dataset)
### Look for files into the dataset dir
success, all_files = nsls(path, castorenv)
### If fails, return false
if not success: return False
### Create the two type of name we expect (neglecting attempt number)
notmerged = os.path.basename(castorfile).splitext()[0]
merged = '.'.join(notmerged.split('.',6)[:-1]+['_SFO-ALL._0001'])
### Find all the files with the correct name
files = [f for f in all_files.split('\n')
if f and (notmerged in f or merged in f)]
if not files: return False
### Take the file with the highest attempt number
file = sorted([(int(f.rsplit('.',1)[1]),f) for f in files])[-1][1]
### Check the migration status for the file
success, out = nsls(os.path.join(path, file), \
castorenv, opts = ['-l'])
if success and 'm' in out.split(' ')[0]: return True
else: return False
if __name__ == '__main__':
print MergedMigrated(sys.argv[1], '')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment