import ROOT,glob,os pandapath=os.environ.get('PANDAPATH') from makeRunlist import make_runlist class PyChainMaker: def __init__(self): self.path="outfiles_e12/Data/Cosmics/" self.runList=[] self.pattern="" self.chain=ROOT.TChain("cbmsim") self.chainDone=False self.isMC=False self.fileList=[] self.manualFiles=False self.debug=False def setPath(self,pa): self.path=pa if self.debug: print "PyChainMaker: setPath:",pa def setPattern(self,pat): self.pattern=pat if self.debug: print "PyChainMaker: setPattern:",pat def setRuns(self,theruns='3883-3901'): self.runList=make_runlist(theruns) if self.debug: print "PyChainMaker: setRuns:",theruns print self.runList def setRedoChain(self): self.chainDone=False def setMC(self): self.isMC=True def setFiles(self,list): self.fileList=list self.manualFiles=True def setDebug(self): self.debug=True def setFileList(self): if self.isMC: self.fileList=glob.glob('{0}/*{1}*.reco.root'.format(self.path,self.pattern)) else: for run in self.runList: files=glob.glob('{0}/run_{1}/*{2}*.reco.root'.format(self.path,run,self.pattern)) for f in files: print 'adding',f,'to fileList' self.fileList.append(f) if self.debug: print "PyChainMaker: fileList=" print self.fileList def makeChain(self): if len(self.runList)==0 and not self.isMC: print 'runList is empty!' return False if self.chainDone: print 'chain is alsready done!' return True if len(self.fileList)==0: self.setFileList() for f in self.fileList: self.chain.AddFile(f) self.chainDone=True return True def getChain(self): if self.makeChain(): return self.chain else: return False