Ejemplo n.º 1
0
def skim(inQueue):
    running = True
    while running:
        try:
            inFileName = inQueue.get(True,2)
            print "About to process " + inFileName
            inFile  = ROOT.TFile(inDir + "/" + inFileName)
            if not os.path.isfile(outDir + "/" + inFileName):
                outFile = ROOT.TFile(outDir + "/" + inFileName,"RECREATE")
                goodRunFilter = goodlumi.makeGoodLumiFilter(GoodRunsFile)
                tempInTree = inFile.events
                inTree = tempInTree.CloneTree(0)
                for entry in range(tempInTree.GetEntriesFast()):
                    tempInTree.GetEntry(entry)
                    if goodRunFilter.isGoodLumi(tempInTree.runNum,tempInTree.lumiNum):
                        inTree.Fill()
                outFile.WriteTObject(inTree,"events")
                outFile.WriteTObject(inFile.htotal.Clone())
                outFile.Close()
                inFile.Close()
                print "Finished " + inFileName
            ##
            else:
                print inFileName + " already processed!"
        except:
            print "Worker finished..."
            running = False
Ejemplo n.º 2
0
    def executeSkim(self):
        """
        Execute the skim.
        """

        skimmer = ROOT.Skimmer()

        skimmer.setPrintEvery(SkimSlimWeight.config['printEvery'])
        skimmer.setPrintLevel(SkimSlimWeight.config['printLevel'])
        skimmer.setSkipMissingFiles(SkimSlimWeight.config['skipMissing'])

        if SkimSlimWeight.config['openTimeout'] is not None:
            ROOT.TIMEOUT = SkimSlimWeight.config['openTimeout']

        # temporary - backward compatibility issue 004 -> 005/006/007
        if self.sample.book != 'pandaf/004':
            skimmer.setCompatibilityMode(True)

        # can eventually think of submitting jobs separately for different preskims
        bypreskim = collections.defaultdict(list)
        for rname, selgen in self.selectors.items():
            if type(selgen) is tuple:  # has modifiers
                selector = selgen[0](self.sample, rname)
                for mod in selgen[1:]:
                    mod(self.sample, selector)
            else:
                selector = selgen(self.sample, rname)

            selector.setUseTimers(SkimSlimWeight.config['timer'])
            skimmer.addSelector(selector)

            bypreskim[selector.getPreskim()].append(selector)

        if len(bypreskim) > 1:
            print 'Selectors with different preskims mixed. Aborting.'
            for preskim, selectors in bypreskim.iteritems():
                print preskim
                print ' ' + ' '.join(str(s.name()) for s in selectors)

            raise RuntimeError('invalid configuration')

        if self.sample.data and SkimSlimWeight.config['json']:
            logger.info('Good lumi filter: %s', SkimSlimWeight.config['json'])
            skimmer.setGoodLumiFilter(
                makeGoodLumiFilter(SkimSlimWeight.config['json']))

        paths = {}  # {filset: list of paths}

        if self.manual:
            paths['manual'] = []
            for path in self.files:
                paths['manual'].append(path)

        else:
            for fileset in self.filesets:
                paths[fileset] = []
                for path in self.sample.files([fileset]):
                    if SkimSlimWeight.config['readRemote']:
                        if not os.path.exists(path) or os.stat(
                                path).st_size == 0:
                            path = path.replace(
                                '/mnt/hadoop/cms',
                                'root://xrootd.cmsaf.mit.edu/')

                    logger.debug('Add input: %s %s', fileset, path)
                    paths[fileset].append(path)

        tmpOutDir = self.tmpDir + '/' + self.sample.name

        for fileset, fnames in paths.items():
            print 'Fileset', fileset

            skimmer.clearPaths()
            for fname in fnames:
                skimmer.addPath(fname)

            outNameBase = self.getOutNameBase(fileset)
            nentries = SkimSlimWeight.config['nentries']
            firstEntry = SkimSlimWeight.config['firstEntry']

            logger.debug('Skimmer.run(%s, %s, %s, %d, %d)', tmpOutDir,
                         outNameBase, self.sample.data, nentries, firstEntry)
            skimmer.run(tmpOutDir, outNameBase, self.sample.data, nentries,
                        firstEntry)

            for rname in self.selectors:
                outName = outNameBase + '_' + rname + '.root'

                if SkimSlimWeight.config['testRun']:
                    logger.info('Output at %s/%s', tmpOutDir, outName)
                else:
                    logger.info('Copying output to %s/%s', self.outDir,
                                outName)
                    shutil.copy(tmpOutDir + '/' + outName, self.outDir)
                    logger.info('Removing %s/%s', tmpOutDir, outName)
                    os.remove(tmpOutDir + '/' + outName)
Ejemplo n.º 3
0
sys.path.append(monoxdir + '/common')
from datasets import allsamples
import config
from goodlumi import makeGoodLumiFilter

ROOT.gSystem.Load(config.libsimpletree)
ROOT.gSystem.AddIncludePath('-I' + config.dataformats + '/interface')
ROOT.gSystem.AddIncludePath('-I' + monoxdir + '/common')

ROOT.gROOT.LoadMacro(thisdir + '/PhotonSkim.cc+')

sname = sys.argv[1]
goodlumi = None
try:
    json = sys.argv[2]
    goodlumi = makeGoodLumiFilter(json)
except:
    pass

sample = allsamples[sname]

if goodlumi:
    ROOT.PhotonSkim(config.ntuplesDir + '/' + sample.book + '/' + sample.fullname, '/tmp/' + sname + '.root', NENTRIES, goodlumi)
else:
    ROOT.PhotonSkim(config.ntuplesDir + '/' + sample.book + '/' + sample.fullname, '/tmp/' + sname + '.root', NENTRIES)

try:
    os.makedirs(config.photonSkimDir)
except OSError:
    pass