VERITAS-Observatory / V2DL3

VERITAS (VEGAS and Eventdisplay) to DL3 Converter
BSD 3-Clause "New" or "Revised" License
8 stars 1 forks source link

KeyError due to setting a dictionary with a cppyy string instead of a python string. #212

Open matthew-w-lundy opened 1 month ago

matthew-w-lundy commented 1 month ago

When running the vegas branch the following error appears:

8 Traceback (most recent call last): File "/global/home/hpc5308/.local/ENV/bin/v2dl3-vegas", line 8, in sys.exit(cli()) File "/global/home/hpc5308/.local/ENV/lib/python3.8/site-packages/click/core.py", line 1157, in call return self.main(args, kwargs) File "/global/home/hpc5308/.local/ENV/lib/python3.8/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) File "/global/home/hpc5308/.local/ENV/lib/python3.8/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, ctx.params) File "/global/home/hpc5308/.local/ENV/lib/python3.8/site-packages/click/core.py", line 783, in invoke return __callback(args, *kwargs) File "/global/home/hpc5308/.local/ENV/lib/python3.8/site-packages/pyV2DL3/script/v2dl3_for_vegas.py", line 261, in cli ea_file = EffectiveAreaFile(ea_file) File "/global/home/hpc5308/.local/ENV/lib/python3.8/site-packages/pyV2DL3/vegas/EffectiveAreaFile.py", line 58, in init self.axis_dict, self.index_dict = self.build_index() File "/global/home/hpc5308/.local/ENV/lib/python3.8/site-packages/pyV2DL3/vegas/EffectiveAreaFile.py", line 96, in build_index check_num = len(np.unique(index_dict[k])) KeyError: 'Azimuth'

In index_dict the keys are set to <class cppyy.gbl.std.string at 0x22b4ac90> instead of a <class 'str'>. These should be equivalent but they throw a key error in some configurations. If you add the line "name=str(name)" above this section of the code https://github.com/VERITAS-Observatory/V2DL3/blob/ee2a5fc6a06cfe1a826db9073fb09536357033b9/pyV2DL3/vegas/EffectiveAreaFile.py#L79C1-L79C42 it will work. This might be good as a small commit to the main branch

matthew-w-lundy commented 1 month ago

Located first by @BryanOwens55

wlav commented 1 month ago

In index_dict the keys are set to <class cppyy.gbl.std.string at 0x22b4ac90> instead of a <class 'str'>. These should be equivalent but they throw a key error in some configurations.

Do you have a reproducer? They really should be the same in all cases since the strings hash to the same values. Example:

import cppyy

s1 = "Hello, World!"
s2 = cppyy.gbl.std.string(s1)

d = {s1: True}
assert s1 in d
assert s2 in d
assert d[s2]

d[s2] = False
assert len(d) == 1
assert s1 in d
assert s2 in d
assert not d[s1]

The only reason I could see it would fail, if is there is some decoding mishap, but then str(name) would fail as well.