Beispiel #1
0
def main():
 #######################################################
 ### Start the execution
 verbose = False; pretend = False; force = False; rm = False
 sampleName = ''
 inFolder = ''
 outFolder = ''

 # Parsing options
 pr = argparse.ArgumentParser()
 pr.add_argument('folder', help='Input folder')
 pr.add_argument('--sample', type = str, default = '')
 pr.add_argument('--outdir', type = str, default = '')
 pr.add_argument('-v','--verbose', action='store_true', help='Activate verbosing')
 pr.add_argument('-f','--force', action='store_true', help='If out saple exists, moves to .bck and executes the merging')
 pr.add_argument('-p','--pretend', action='store_true', help='Returns the hadd commands')
 pr.add_argument('-r','--rm', action='store_true', help='Returns the hadd commands')

 args = pr.parse_args()
 inFolder = args.folder
 if args.verbose: verbose = True
 if args.force:   force   = True
 if args.pretend: pretend = True
 if args.rm:      rm = True
 if args.sample:  sampleName = args.sample
 if args.outdir:  outFolder = args.outdir
 
 if outFolder == '': outFolder = inFolder 
 if not inFolder[-1] == '/': inFolder+= '/'
 if not outFolder[-1] == '/': outFolder += '/'
 # Check input folder...
 if not os.path.isdir(inFolder):
   print 'ERROR: Directory "' + inFolder + '"  does not exist!!'
   exit()

 if sampleName == '':  ### Automatic option
   print 'INFO: Automatic merge of files in folder: ' + inFolder
   listOfFiles = getDicFiles(inFolder)
   if len(listOfFiles) == 0:
     print 'WARNING: no files to merge in "' + inFolder + '"'
     exit()
   for L in listOfFiles: hadd(listOfFiles[L], L, inFolder, outFolder, verbose, pretend, force, rm)
 
 else:    ### hadd only one sample
   listOfFiles = findValidRootfiles(inFolder, sampleName)
   hadd(listOfFiles, sampleName, inFolder, outFolder, verbose, pretend, force, rm)
Beispiel #2
0
def GetSampleList(path, sample):
    dic = getDicFiles(path)
    nfileInPath = len(dic)
    if verbose: print 'Found %i files in path %s' % (nfileInPath, path)
    samples = []
    for s in sample:
        s, indices = GetSampleAndIndex(s)
        dk = dic.keys()
        if not s in dk: s = prefix + '_' + s
        if not s in dk:
            print 'WARNING: file %s not in path %s' % (s, path)
        else:
            allsamples = dic[s]
            if len(indices) > 0:
                for si in allsamples:
                    i = int(si[len(s) + 1:si.index('.root')])
                    if i in indices: samples += [si]
            else:
                samples += allsamples
    return samples
Beispiel #3
0
def main():
 #######################################################
 ### Start the execution
 verbose = False; pretend = False; force = False; rm = False
 sampleName = ''
 inFolder = ''
 outFolder = ''

 # Parsing options
 pr = argparse.ArgumentParser()
 pr.add_argument('folder', help='Input folder')
 pr.add_argument('--sample', type = str, default = '')
 pr.add_argument('--outdir', type = str, default = '')
 pr.add_argument('-v','--verbose', action='store_true', help='Activate verbosing')
 pr.add_argument('-f','--force', action='store_true', help='If out saple exists, moves to .bck and executes the merging')
 pr.add_argument('-p','--pretend', action='store_true', help='Returns the hadd commands')
 pr.add_argument('-r','--rm', action='store_true', help='Returns the hadd commands')
 pr.add_argument('--rmZero', action='store_true', help='Moves single name_0.root file to name.root')
 pr.add_argument('--recursive', '--subfolders', action='store_true', help='Execute for all subfolders')

 args = pr.parse_args()
 inFolder = args.folder
 rmZero = args.rmZero
 recur  = args.recursive
 if args.verbose: verbose = True
 if args.force:   force   = True
 if args.pretend: pretend = True
 if args.rm:      rm = True
 if args.sample:  sampleName = args.sample
 if args.outdir:  outFolder = args.outdir
 
 if outFolder == '': outFolder = inFolder 
 if not inFolder[-1] == '/': inFolder+= '/'
 if not outFolder[-1] == '/': outFolder += '/'
 # Check input folder...
 if not os.path.isdir(inFolder):
   print 'ERROR: Directory "' + inFolder + '"  does not exist!!'
   exit()

 if sampleName == '':  ### Automatic option
   print 'INFO: Automatic merge of files in folder: ' + inFolder
   if recur:
     paths = [] 
     for root, subdirs, files in os.walk(inFolder):
       if root in paths: continue
       paths.append(root)
       print("Exploring ", root)
       if len(files) > 0:
         listOfFiles = getDicFiles(root)
         inFolder = root
         outFolder = root
         if len(listOfFiles) == 0: continue
         for L in listOfFiles:
           if rmZero and len(listOfFiles[L]) == 1:
             if listOfFiles[L][0] == L+'_0.root': os.system('mv %s/%s %s/%s.root'%(inFolder, listOfFiles[L][0], outFolder, L))
           hadd(listOfFiles[L], L, inFolder, outFolder, verbose, pretend, force, rm)
     exit() 
   listOfFiles = getDicFiles(inFolder)
   if len(listOfFiles) == 0:
     print 'WARNING: no files to merge in "' + inFolder + '"'
     exit()
   for L in listOfFiles: 
     if rmZero and len(listOfFiles[L]) == 1:
       if listOfFiles[L][0] == L+'_0.root': os.system('mv %s/%s %s/%s.root'%(inFolder, listOfFiles[L][0], outFolder, L))
     hadd(listOfFiles[L], L, inFolder, outFolder, verbose, pretend, force, rm)
 
 else:    ### hadd only one sample
   listOfFiles = findValidRootfiles(inFolder, sampleName)
   hadd(listOfFiles, sampleName, inFolder, outFolder, verbose, pretend, force, rm)