예제 #1
0
    def __init__(self, mainTree=None, otherTreesToKeepWhenSkimming=None,
                 leavesToBlackList=None, moveOutputFiles=None, localStem=None,
                 globalStem=None, subDir=None, steps=None, calculables=None,
                 inputFiles=None, name=None, nEventsMax=None, quietMode=None,
                 skip=None, nSlicesFixed=None, nEventsPerSlice=None, byEvents=None):

        for arg in ["mainTree", "otherTreesToKeepWhenSkimming",
                    "leavesToBlackList", "moveOutputFiles", "localStem",
                    "globalStem", "subDir", "steps", "calculables",
                    "inputFiles", "name", "nEventsMax", "quietMode",
                    "skip", "byEvents"]:
            setattr(self, arg, eval(arg))

        if nSlicesFixed is not None:
            assert nEventsPerSlice is None
            self.nSlices = nSlicesFixed
        if nEventsPerSlice is not None:
            assert nSlicesFixed is None
            self.byEvents = True  # until "by chunks" is implemented
            assert 1 <= nEventsPerSlice
            assert configuration.computeEntriesAtMakeFileList()
            num = self.nExpect + 0.0
            self.nSlices = int(math.ceil(num / nEventsPerSlice)) if num else 1
        assert hasattr(self, "nSlices")
        assert 1 <= self.nSlices

        self.trace = configuration.trace() and not any([step.requiresNoTrace() for step in self.steps])
        self.outputDir = self.globalDir #the value will be modified in self.prepareOutputDirectory()
        self.inputDir = self.globalDir 
        self.divisor = None
        self.remainder = None
        self.checkSteps()
예제 #2
0
 def writeFromSteps() :
     while "/" not in r.gDirectory.GetName() : r.gDirectory.GetMotherDir().cd()
     for step in self.steps :
         r.gDirectory.mkdir(step.name, step.moreNames).cd()
         for hist in [step.book[name] for name in step.book.fillOrder] : hist.Write()
         if configuration.trace() and step.isSelector :
             r.gDirectory.mkdir("Calculables").cd()
             for key in step.tracer.tracedKeys : r.gDirectory.mkdir(key)
             r.gDirectory.GetMother().cd()
예제 #3
0
    def __init__(self, mainTree = None, otherTreesToKeepWhenSkimming = None, leavesToBlackList = None,
                 localStem = None, globalStem = None, subDir = None, steps = None, calculables = None, inputFiles = None, name = None,
                 nEventsMax = None, quietMode = None) :

        for arg in ["mainTree", "otherTreesToKeepWhenSkimming", "leavesToBlackList", "steps", "calculables",
                    "localStem", "globalStem", "subDir", "inputFiles", "name", "nEventsMax", "quietMode"] :
            setattr(self, arg, eval(arg))

        self.trace = configuration.trace() and not any([step.requiresNoTrace() for step in self.steps])
        self.outputDir = self.globalDir #the value will be modified in self.prepareOutputDirectory()
        self.inputDir = self.globalDir 
        self.checkSteps()
예제 #4
0
    def loop(self) :
        if self.nEventsMax!=0 :
            chainWrapper = wrappedChain.wrappedChain( self.chains[self.mainTree],
                                                      calculables = self.calculables,
                                                      useSetBranchAddress = not any([step.requiresNoSetBranchAddress() for step in self.steps]),
                                                      leavesToBlackList = self.leavesToBlackList,
                                                      maxArrayLength = configuration.maxArrayLength(),
                                                      trace = configuration.trace(),
                                                      cacheSizeMB = configuration.ttreecacheMB(),
                                                      )
            for step in filter(lambda s: (issubclass(type(s),wrappedChain.wrappedChain.calculable) and
                                          hasattr(s,"source") and
                                          hasattr(s.source,"tracedKeys")), self.steps) :
                step.tracer = step.source
                step.source.tracedKeys |= step.priorFilters

            [ all(step(eventVars) for step in self.steps) for eventVars in chainWrapper.entries(self.nEventsMax) ]

            for step in filter(lambda s: s.tracer and s.name in s.tracer.tracedKeys, self.steps) : step.tracer.tracedKeys.remove(step.name)
            self.recordLeavesAndCalcsUsed( chainWrapper.activeKeys(), chainWrapper.calcDependencies() )
        else : self.recordLeavesAndCalcsUsed([], {})
예제 #5
0
    def setupSteps(self, minimal = False) :
        r.gROOT.cd()
        current = r.gDirectory
        priorFilters = []
        self.steps[0].books = []

        for step in self.steps :
            step.setOutputFileStem(self.outputFileStem)
            step.setInputFileStem(self.inputFileStem)
            current = current.mkdir(step.name)
            step.book = autoBook(current)
            step.tracer = wrappedChain.keyTracer(None) if configuration.trace() and (step.isSelector or issubclass(type(step),wrappedChain.wrappedChain.calculable)) else None
            step.priorFilters = set(priorFilters)

            self.steps[0].books.append(step.book)
            if step.isSelector and step!=self.steps[0] : priorFilters.append((step.name,step.moreNames))

            if minimal : continue
            if self.quietMode : step.makeQuiet()
            assert step.isSelector ^ hasattr(step,"uponAcceptance"), "Step %s must implement 1 and only 1 of {select,uponAcceptance}"%step.name
            step.setup(self.chains[self.mainTree], self.mainTree[0])