From 057ee10f7f65a9714607be880e8b8023be8d1a75 Mon Sep 17 00:00:00 2001
From: Wainer Vandelli <Wainer.Vandelli@cern.ch>
Date: Thu, 15 Dec 2011 12:54:29 +0000
Subject: [PATCH] Used to be MergedMigrated.py

---
 Script/MergedMigratedOld.py | 98 +++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)
 create mode 100644 Script/MergedMigratedOld.py

diff --git a/Script/MergedMigratedOld.py b/Script/MergedMigratedOld.py
new file mode 100644
index 0000000..fa599df
--- /dev/null
+++ b/Script/MergedMigratedOld.py
@@ -0,0 +1,98 @@
+#!/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)
+     
+
+    
+
+
+    
-- 
GitLab