diff --git a/python/ModelTools.py b/python/ModelTools.py index 6728d430156..61ac006ad3d 100644 --- a/python/ModelTools.py +++ b/python/ModelTools.py @@ -38,6 +38,20 @@ def __call__(self, *args): self.imp(*args) +def goodpath(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") + + 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 +84,8 @@ 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 +247,7 @@ def doExtArgs(self): self.out._import(wstmp.arg(rp), *importargs) else: fitmp = ROOT.TFile.Open(fin) + goodpath(fin, self.options.absPath) if not fitmp: raise RuntimeError("No File '%s' found for extArg" % fin) wstmp = fitmp.Get(wsn) @@ -289,6 +306,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..d868d4ad31c 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,7 @@ 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 +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] + goodpath(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 +78,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: