ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/joshmt/onlyLast.py
(Generate patch)

Comparing UserCode/joshmt/onlyLast.py (file contents):
Revision 1.1 by joshmt, Fri Apr 23 16:42:45 2010 UTC vs.
Revision 1.2 by joshmt, Wed Aug 25 10:15:46 2010 UTC

# Line 1 | Line 1
1   import os, sys, re
2  
3 + ###############################################################
4 +
5 + #Usage:
6 + # python onlyLast.py <path to input directory on CASTOR>
7 +
8 + #now updated to handle output from the latest CRAB with
9 + #file names like this:
10 + #                      myfilename_1_1_aBC.root
11 +
12 + ###############################################################
13 +
14   #handle input arguments
15   #this includes the name of the script
16   ##for arg in sys.argv:
# Line 28 | Line 39 | cmd += tmpfile
39   #print cmd
40   os.system(cmd)
41  
42 < print mkdircommand
43 < #this will give a harmless error if the dir already exists
33 < os.system(mkdircommand)
42 > #keep track of whether we made the directory or not
43 > alreadymadedir = 0
44  
45   f = open(tmpfile,'r')
46  
47 + #to deal with the arbitrary extension to the filename that crab
48 + #now adds, I will add a second associative array to keep track of the
49 + #whole file name. (completefilenames)
50 + #The only subtle part is where the file names are sorted.
51 + #Hopefully this does not create any bugs
52   indexdict = {}
53 + completefilenames = {}
54  
55   stub = 'stub'
56  
57 + #do some accounting
58 + nmoved = 0
59 +
60   for line in f:
61      mypair = line.split()
62   #file size
63      size = int(mypair[0])
64   #parse filename
65 <    result = re.match('(.*)_([0-9]*)_([0-9]*).root',mypair[1])
65 >    result = re.match('(.*)_([0-9]*)_([0-9]*)_(.*).root',mypair[1])
66      if size > 0:
67          if stub=='stub':
68              stub = result.group(1)
69          elif stub!=result.group(1):
70 <            print "oh no!"
70 >            print "WARNING -- there is more than one group of filenames here!"
71          
72          if result.group(2) in indexdict:
73              #so the key already exists
74              indexdict[result.group(2)].append(result.group(3))
75 +            completefilenames[result.group(2)].append(mypair[1])
76          else:
77              indexdict[result.group(2)] = [result.group(3)]
78 +            completefilenames[result.group(2)] = [mypair[1]]
79   #        print result.group(0)
80   #        print result.group(1)
81   #        print result.group(2)
# Line 67 | Line 88 | for ii in indexdict:
88          print "nothing to do for ",ii
89      else:
90          indexdict[ii].sort()
91 +        #will this work? in my one test case, yes
92 +        completefilenames[ii].sort()
93          goodindex = indexdict[ii].pop()
94 +        goodfilename = completefilenames[ii].pop()
95          print ii, ": keeping index ",goodindex
96 <        for jj in indexdict[ii]:
96 >        print ii, ": corresponds to file ",goodfilename
97 >        for jj in completefilenames[ii]:
98 >            if alreadymadedir == 0:
99 >                print mkdircommand
100 >                #this will give a harmless error if the dir already exists
101 >                os.system(mkdircommand)
102 >
103              s=inputdir
74            s+=stub
75            s+='_'
76            s+=ii
77            s+='_'
104              s+=jj
105 <            s+='.root'
80 < #            print "moving ", s
105 >            print "moving ", s
106              cpcmd = 'rfcp '
107              cpcmd += s
108              cpcmd += ' '
# Line 88 | Line 113 | for ii in indexdict:
113              rmcmd += s
114              print rmcmd
115              os.system(rmcmd)
116 <
116 >            nmoved = nmoved+1
117  
118   f.close()
119   os.remove(tmpfile)
120  
121 <
121 > print "----------------------------"
122 > print "I moved this many files: ",nmoved
123 > print "----------------------------"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines