From 067ce248e1539d441a992f9740e08d02c1827a75 Mon Sep 17 00:00:00 2001 From: schoef Date: Mon, 17 Jun 2019 12:11:28 +0200 Subject: [PATCH 1/3] Raise EmptySampleError if chain ends up with zero files --- core/python/Sample.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/python/Sample.py b/core/python/Sample.py index ec0d347..25b6f9a 100644 --- a/core/python/Sample.py +++ b/core/python/Sample.py @@ -710,7 +710,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 From 876eea724602a19ea4ef2a1623043ffbe81ee8d6 Mon Sep 17 00:00:00 2001 From: Robert Schoefbeck Date: Tue, 25 Jun 2019 12:36:59 +0200 Subject: [PATCH 2/3] treeMaker example --- examples/example_treeMaker.py | 5 ++++- fwlite/python/Database.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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() From 5ce9553a7e0c7f95287e152044bca1190a58afb7 Mon Sep 17 00:00:00 2001 From: Robert Schoefbeck Date: Mon, 1 Jul 2019 09:59:24 +0200 Subject: [PATCH 3/3] EmptySampleError in fromDPMDirectory --- core/python/Sample.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/python/Sample.py b/core/python/Sample.py index 25b6f9a..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)