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

Used to be MergedMigrated.py

parent 0bde1322
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 MergedMigrated(castorfile, castorenv, verbose = False):
"""
Input file: /some_path/data09_cos.00122050.physics_IDCosmic.daq.RAW._lb0123._SFO-1._0001.data
Check fo migration of:
/<basedir>/<projecttag>/<streamtype_streamname>/<runnr-7digit>/<dataset>/<dataset>._lb<lbnr-4digit>._0001.<y>
basedir = /castor/cern.ch/grid/atlas/tzero/prod1/perm/
projecttag = data09_cos
dataset = data09_cos.00122050.physics_IDCosmic.merge.RAW
"""
parsed = SFOFileNameParser(os.path.basename(castorfile))
dataset = '%s.%s.%s_%s.merge.RAW' \
% (parsed.ProjectTag(), parsed.RunNr(), \
parsed.StreamType(), parsed.StreamName())
### List the content of the path
path = os.path.join(BASEDIR, parsed.ProjectTag(), \
'%s_%s' % (parsed.StreamType(), parsed.StreamName()), \
'%07d' % int(parsed.RunNr()), \
'%s' % dataset)
if verbose:
print path
### Look for files into the dataset dir
success, all_files = nsls(path, castorenv)
## If fails, return false
if not success: return False
files = []
target_lb = int(parsed.LBNr())
for f in all_files.split('\n'):
if not f: continue
lbstring = f.split('.',6)[5].partition('_lb')[2]
if '-' in lbstring:
#Multi LB file
minlb,maxlb = [int(lb) for lb in lbstring.split('-')]
if minlb <= target_lb and \
maxlb >= target_lb: files.append(f)
else:
#Single LB file
if target_lb == int(lbstring): files.append(f)
if not files: return False
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], '', verbose=True)
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