Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Removing abs path #774

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions python/ModelTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion python/ShapeTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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 ----------
Expand Down
7 changes: 7 additions & 0 deletions scripts/text2workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down