def pickTag(inputdir, options) :
    tag = options.tag if options.tag else guessLatestTagFromLatestRootFiles(inputdir, options.debug)
    tag = tag if tag else guessMonthDayTagFromLastRootFile(inputdir, options.debug) # can get it wrong if from single file
    tag = tag.strip('_') # leading/trailing separators are not part of the tag
    if not isMonthDayTag(tag) : print "warning, non-standard tag might lead to bugs '%s'"%tag
    if options.verbose : print "using tag %s"%tag
    return tag
Пример #2
0
debug         = options.debug
dryrun        = options.dryrun
onedata       = options.onedata
overwrite     = options.overwrite
outdir        = options.output if options.output else inputdir+'/merged/'
tag           = (options.tag if options.tag
                 else guessLatestTagFromLatestRootFiles(inputdir, debug))
tag           = tag if tag else guessMonthDayTagFromLastRootFile(inputdir, debug)
tag           = tag.strip('_') # leading/trailing separators are not part of the tag
if verbose :
    print "Options:"
    print '\n'.join(["%s : %s" % (o, eval(o))
                     for o in ['inputdir', 'outdir', 'group_regexp', 'tag', 'overwrite',
                               'allBkg', 'allBkgButHf', 'onedata',
                               'verbose', 'debug',]])
if not isMonthDayTag(tag) : print "warning, non-standard tag might lead to bugs '%s'"%tag
if not os.path.isdir(outdir) :
    os.mkdir(outdir)
    if verbose : print "created directory '%s'"%outdir
allDatasets = [d for d in datasets if alsoph or not d.placeholder]
if onedata : allDatasets = setSameGroupForAllData(allDatasets)
filenamesByGroup = collections.defaultdict(list)
rootfiles = filter(os.path.isfile, glob.glob(inputdir + "*.root"))
rootfiles = [rf for rf in rootfiles if tag in rf]
for rf in rootfiles :
    dsname = os.path.basename(rf).replace('.root','').replace(tag,'')
    dsname = dsname.rstrip('_') # depending on the specified tag there might be a leftover '_'
    if debug : print "'%s' -> dataset '%s'"%(rf, dsname)
    dataset = next((d for d in allDatasets if d.name==dsname), None)
    if not dataset :
        print "warning, cannot identify dataset for '%s'"%rf