diff --git a/core/python/Sample.py b/core/python/Sample.py index ec0d347..9a60d1f 100644 --- a/core/python/Sample.py +++ b/core/python/Sample.py @@ -211,17 +211,23 @@ def fromDPMDirectory(cls, name, directory, redirector='root://hephyse.oeaw.ac.at files = [] for d in directories: cmd = [ "xrdfs", redirector, "ls", d ] + fileList = [] for i in range(10): try: fileList = [ file for file in subprocess.check_output( cmd ).split("\n")[:-1] ] break except: if i<9: pass + counter = 0 for filename in fileList: if filename.endswith(".root"): files.append( redirector + os.path.join( d, filename ) ) + counter += 1 if maxN is not None and maxN>0 and len(files)>=maxN: break + if counter==0: + raise helpers.EmptySampleError( "No root files found in directory %s." %d ) + sample = cls(name = name, treeName = treeName, files = files, normalization = normalization, xSection = xSection,\ selectionString = selectionString, weightString = weightString, isData = isData, color=color, texName = texName) @@ -710,7 +716,8 @@ def __loadChain(self): except IOError as e: logger.error( "Could not load file %s", f ) #raise e - + if counter==0: + raise helpers.EmptySampleError( "No root files for sample %s." %self.name ) logger.debug( "Loaded %i files for sample '%s'.", counter, self.name ) # Add friends diff --git a/examples/example_treeMaker.py b/examples/example_treeMaker.py index e32200b..0978702 100644 --- a/examples/example_treeMaker.py +++ b/examples/example_treeMaker.py @@ -5,6 +5,7 @@ import sys import logging import ROOT +import os #RootTools from RootTools.core.standard import * @@ -25,7 +26,7 @@ # from files -s0 = Sample.fromFiles("s0", files = ["example_data/file_0.root"], treeName = "Events") +s0 = Sample.fromFiles("s0", files = [os.path.expandvars("$CMSSW_BASE/src/RootTools/examples/example_data/file_0.root")], treeName = "Events") read_variables = [ TreeVariable.fromString( "nJet/I"), TreeVariable.fromString('Jet[pt/F,eta/F,phi/F]' ) ] \ + [ TreeVariable.fromString(x) for x in [ 'met_pt/F', 'met_phi/F' ] ] @@ -51,3 +52,5 @@ def filler(event): maker.start() while reader.run(): maker.run() + +logger.info("Success!") diff --git a/fwlite/python/Database.py b/fwlite/python/Database.py index 3363d3a..7c2b50f 100644 --- a/fwlite/python/Database.py +++ b/fwlite/python/Database.py @@ -68,7 +68,7 @@ def getObjects(self, key): return objs except sqlite3.DatabaseError as e: - logger.error( "There seems to be an issue with the database, trying to read again." ) + logger.error( "There seems to be an issue with the database, trying to read again from %s.", self.database_file ) logger.info( "Attempt no %i", i ) self.close() self.connect()