From 18d2e745bf7f7209c58a22d2f6e144ca6a918171 Mon Sep 17 00:00:00 2001 From: Andrea Carlo Marini Date: Fri, 29 Jul 2022 12:52:19 +0200 Subject: [PATCH 1/5] Removing abs path --- python/ModelTools.py | 11 +++++++++++ python/ShapeTools.py | 6 +++++- scripts/text2workspace.py | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/python/ModelTools.py b/python/ModelTools.py index 6728d430156..13fc76c9128 100644 --- a/python/ModelTools.py +++ b/python/ModelTools.py @@ -37,6 +37,14 @@ def __call__(self, *args): else: self.imp(*args) +def goodpath(self,s,permissive=False): + ''' Need to be used in FileCache for shapes and here for rateParameters''' + if not s.startswith('/'): return True + if 'CMSSW_BASE' in os.environ and s.startswith(os.environ['CMSSW_BASE']+'/src/HiggsAnalysis/CombinedLimit/data'): return True + if 'HiggsAnalysis' in s.split('/') and 'CombinedLimit' in s.split('/') and 'data' in s.split('/'): return True ## standalone? + if permissive: print("Warning: you have an absolute path in your datacard: ",s) + raise RuntimeError("No!No!No! You can't use absolute paths anymore") + class ModelBuilderBase: """This class defines the basic stuff for a model builder, and it's an interface on top of RooWorkspace::factory or HLF files""" @@ -70,6 +78,7 @@ def __init__(self, options): if options.cexpr: global ROOFIT_EXPR ROOFIT_EXPR = "cexpr" + if not hasattr(options, 'absPath'): options.absPath=False def addObj(self, classtype, name, *args): if name not in self.objstore: @@ -231,6 +240,7 @@ def doExtArgs(self): self.out._import(wstmp.arg(rp), *importargs) else: fitmp = ROOT.TFile.Open(fin) + goodpath(fin,options.absPath) if not fitmp: raise RuntimeError("No File '%s' found for extArg" % fin) wstmp = fitmp.Get(wsn) @@ -289,6 +299,7 @@ def doRateParams(self): self.out._import(wstmp.arg(argu), ROOT.RooFit.RecycleConflictNodes()) else: fitmp = ROOT.TFile.Open(fin) + goodpath(fin) if not fitmp: raise RuntimeError("No File '%s' found for rateParam" % fin) wstmp = fitmp.Get(wsn) diff --git a/python/ShapeTools.py b/python/ShapeTools.py index 8f9921082b0..1aa03aaa383 100644 --- a/python/ShapeTools.py +++ b/python/ShapeTools.py @@ -10,7 +10,7 @@ from six.moves import range import ROOT -from HiggsAnalysis.CombinedLimit.ModelTools import ModelBuilder +from HiggsAnalysis.CombinedLimit.ModelTools import ModelBuilder, goodpath from .DataFrameWrapper import DataFrameWrapper @@ -34,6 +34,8 @@ def __init__(self, basedir, maxsize=250): self._files = {} self._hits = defaultdict(int) self._total = 0 + self._absPath=False + def __getitem__(self, fname): self._total += 1 @@ -50,6 +52,7 @@ def __getitem__(self, fname): trueFName = self._basedir + "/" + trueFName # interpret file from extension - csv, json, html, pkl, xlsx, h5, parquet filepath = trueFName.split(":")[0] + goodfile(trueFName,self._absPath) filename, ext = os.path.splitext(filepath) if ext in [".csv", ".json", ".html", ".pkl", ".xlsx", ".h5", ".parquet"]: filehandle = DataFrameWrapper(trueFName, ext) @@ -76,6 +79,7 @@ def __init__(self, datacard, options): self.extraImports = [] self.norm_rename_map = {} self._fileCache = FileCache(self.options.baseDir) + self._fileCache._absPath=options.absPath ## ------------------------------------------ ## -------- ModelBuilder interface ---------- diff --git a/scripts/text2workspace.py b/scripts/text2workspace.py index db78d816339..b486507bd04 100755 --- a/scripts/text2workspace.py +++ b/scripts/text2workspace.py @@ -60,6 +60,13 @@ action="store_true", help="Swap multipdf pdfs with their current index pdf", ) +parser.add_option( + "--X-allow-abs-path", + dest="absPath", + default=False, + action="store_true", + help="Swap multipdf pdfs with their current index pdf", +) (options, args) = parser.parse_args() if len(args) == 0: From 96c8b7b72cef914deb5cb5f62ef1e9783e769358 Mon Sep 17 00:00:00 2001 From: Andrea Carlo Marini Date: Tue, 2 Aug 2022 11:31:57 +0200 Subject: [PATCH 2/5] running black --- python/ModelTools.py | 23 +++++++++++++++-------- python/ShapeTools.py | 7 +++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/python/ModelTools.py b/python/ModelTools.py index 13fc76c9128..7cdb7a2e400 100644 --- a/python/ModelTools.py +++ b/python/ModelTools.py @@ -37,12 +37,18 @@ def __call__(self, *args): else: self.imp(*args) -def goodpath(self,s,permissive=False): - ''' Need to be used in FileCache for shapes and here for rateParameters''' - if not s.startswith('/'): return True - if 'CMSSW_BASE' in os.environ and s.startswith(os.environ['CMSSW_BASE']+'/src/HiggsAnalysis/CombinedLimit/data'): return True - if 'HiggsAnalysis' in s.split('/') and 'CombinedLimit' in s.split('/') and 'data' in s.split('/'): return True ## standalone? - if permissive: print("Warning: you have an absolute path in your datacard: ",s) + +def goodpath(self, s, permissive=False): + """Need to be used in FileCache for shapes and here for rateParameters""" + if not s.startswith("/"): + return True + if "CMSSW_BASE" in os.environ and s.startswith(os.environ["CMSSW_BASE"] + "/src/HiggsAnalysis/CombinedLimit/data"): + return True + if "HiggsAnalysis" in s.split("/") and "CombinedLimit" in s.split("/") and "data" in s.split("/"): + return True ## standalone? + if permissive: + print("Warning: you have an absolute path in your datacard: ", s) + return True raise RuntimeError("No!No!No! You can't use absolute paths anymore") @@ -78,7 +84,8 @@ def __init__(self, options): if options.cexpr: global ROOFIT_EXPR ROOFIT_EXPR = "cexpr" - if not hasattr(options, 'absPath'): options.absPath=False + if not hasattr(options, "absPath"): + options.absPath = False def addObj(self, classtype, name, *args): if name not in self.objstore: @@ -240,7 +247,7 @@ def doExtArgs(self): self.out._import(wstmp.arg(rp), *importargs) else: fitmp = ROOT.TFile.Open(fin) - goodpath(fin,options.absPath) + goodpath(fin, options.absPath) if not fitmp: raise RuntimeError("No File '%s' found for extArg" % fin) wstmp = fitmp.Get(wsn) diff --git a/python/ShapeTools.py b/python/ShapeTools.py index 1aa03aaa383..92ba0936f4a 100644 --- a/python/ShapeTools.py +++ b/python/ShapeTools.py @@ -34,8 +34,7 @@ def __init__(self, basedir, maxsize=250): self._files = {} self._hits = defaultdict(int) self._total = 0 - self._absPath=False - + self._absPath = False def __getitem__(self, fname): self._total += 1 @@ -52,7 +51,7 @@ def __getitem__(self, fname): trueFName = self._basedir + "/" + trueFName # interpret file from extension - csv, json, html, pkl, xlsx, h5, parquet filepath = trueFName.split(":")[0] - goodfile(trueFName,self._absPath) + goodfile(trueFName, self._absPath) filename, ext = os.path.splitext(filepath) if ext in [".csv", ".json", ".html", ".pkl", ".xlsx", ".h5", ".parquet"]: filehandle = DataFrameWrapper(trueFName, ext) @@ -79,7 +78,7 @@ def __init__(self, datacard, options): self.extraImports = [] self.norm_rename_map = {} self._fileCache = FileCache(self.options.baseDir) - self._fileCache._absPath=options.absPath + self._fileCache._absPath = options.absPath ## ------------------------------------------ ## -------- ModelBuilder interface ---------- From 781ee38e0d17445a22fe0d7434a830ac4ea04e52 Mon Sep 17 00:00:00 2001 From: Andrea Carlo Marini Date: Wed, 3 Aug 2022 12:17:42 +0200 Subject: [PATCH 3/5] fix --- python/ShapeTools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ShapeTools.py b/python/ShapeTools.py index 92ba0936f4a..d868d4ad31c 100644 --- a/python/ShapeTools.py +++ b/python/ShapeTools.py @@ -51,7 +51,7 @@ def __getitem__(self, fname): trueFName = self._basedir + "/" + trueFName # interpret file from extension - csv, json, html, pkl, xlsx, h5, parquet filepath = trueFName.split(":")[0] - goodfile(trueFName, self._absPath) + goodpath(trueFName, self._absPath) filename, ext = os.path.splitext(filepath) if ext in [".csv", ".json", ".html", ".pkl", ".xlsx", ".h5", ".parquet"]: filehandle = DataFrameWrapper(trueFName, ext) From 8789a96effc2e53d594a1cd1d839488ae04a39c7 Mon Sep 17 00:00:00 2001 From: Andrea Carlo Marini Date: Wed, 3 Aug 2022 12:44:20 +0200 Subject: [PATCH 4/5] removing self as goodpath is a global function --- python/ModelTools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ModelTools.py b/python/ModelTools.py index 7cdb7a2e400..204a01f3626 100644 --- a/python/ModelTools.py +++ b/python/ModelTools.py @@ -38,7 +38,7 @@ def __call__(self, *args): self.imp(*args) -def goodpath(self, s, permissive=False): +def goodpath(s, permissive=False): """Need to be used in FileCache for shapes and here for rateParameters""" if not s.startswith("/"): return True From d938b174449b80311e94e9e94ad393a047991c19 Mon Sep 17 00:00:00 2001 From: Andrea Carlo Marini Date: Wed, 3 Aug 2022 13:04:06 +0200 Subject: [PATCH 5/5] options are self member --- python/ModelTools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ModelTools.py b/python/ModelTools.py index 204a01f3626..61ac006ad3d 100644 --- a/python/ModelTools.py +++ b/python/ModelTools.py @@ -247,7 +247,7 @@ def doExtArgs(self): self.out._import(wstmp.arg(rp), *importargs) else: fitmp = ROOT.TFile.Open(fin) - goodpath(fin, options.absPath) + goodpath(fin, self.options.absPath) if not fitmp: raise RuntimeError("No File '%s' found for extArg" % fin) wstmp = fitmp.Get(wsn)