Skip to content

Commit

Permalink
Merge pull request cms-sw#178 from clelange/continueEosDownload
Browse files Browse the repository at this point in the history
add flag to allow downloadTreesFromEOS to continue download if indivi…
  • Loading branch information
clelange authored Feb 27, 2017
2 parents 951af57 + fecc3e8 commit ea05dcc
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Production/scripts/downloadTreesFromEOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
parser = OptionParser(usage=usage)
parser.add_option("-t", dest="treeproducername", type='string', default="myTreeProducer", help='Name of the tree producer module')
parser.add_option("-T", dest="treename", type='string', default="tree.root", help='Name of the tree file')
parser.add_option("-c", "--continue", dest="continueCopy", action="store_true", default=False, help='Continue downloading if a chunk failed and print a summary at the end')
(options, args) = parser.parse_args()

locdir = args[0]
chunks = eostools.ls(locdir)

Expand All @@ -28,17 +29,28 @@
print 'Will operate on the following chunks:',chunks

tocopy = []
failedDict = {}
for d in chunks:
f = '%s/%s/%s'%(d,options.treeproducername,options.treename)
furl = '%s.url'%f
if os.path.exists(f):
print 'Chunk %s already contains tree root file %s, skipping'%(d,f)
continue
if not os.path.exists(furl):
raise RuntimeError,'Chunk %s does not contain url file %s'%(d,furl)
if (options.continueCopy):
print 'Chunk %s does not contain url file %s' % (d, furl)
failedDict[d] = furl
continue
else:
raise RuntimeError,'Chunk %s does not contain url file %s'%(d,furl)
with open(furl,'r') as _furl:
rem = _furl.readline().replace('root://eoscms.cern.ch/','').replace('\n','')
if not eostools.isFile(rem):
raise RuntimeError,'Remote file %s not found'%rem
eostools.xrdcp(rem,f)

if (options.continueCopy and (len(failedDict.keys()) > 0)):
print "="*100
print "Summary of failed download attempts (%d in total):" % len(failedDict.keys())
for d, furl in failedDict.iteritems():
print 'Chunk %s does not contain url file %s' % (d, furl)

0 comments on commit ea05dcc

Please sign in to comment.