Warning, /acts/Python/Examples/python/tgeo_aux.py.in is written in an unsupported language. File is not indexed.
0001 # This is deprecated code for Gen-1
0002
0003 import inspect
0004 from acts._adapter import _patchKwargsConstructor
0005 from .ActsExamplesPythonBindingsTGeo import TGeoDetector
0006
0007 def _makeLayerTriplet(*args, **kwargs):
0008 if len(args) == 1:
0009 _type = type(args[0])
0010 negative = central = positive = args[0]
0011 else:
0012 negative = kwargs.get("negative")
0013 central = kwargs.get("central")
0014 positive = kwargs.get("positive")
0015 types = []
0016 if negative is not None:
0017 types.append(type(negative))
0018 if central is not None:
0019 types.append(type(central))
0020 if positive is not None:
0021 types.append(type(positive))
0022
0023 assert all(types[0] == t for t in types), "Inconsistent types"
0024
0025 _type = types[0]
0026
0027 def fill(obj):
0028 if negative is not None:
0029 obj.negative = negative
0030 if central is not None:
0031 obj.central = central
0032 if positive is not None:
0033 obj.positive = positive
0034 return obj
0035
0036 if _type == bool:
0037 return fill(TGeoDetector.Config.LayerTripletBool())
0038 elif _type == list:
0039 if all(
0040 all(isinstance(v, str) for v in vv)
0041 for vv in (negative, central, positive)
0042 if vv is not None
0043 ):
0044 return fill(TGeoDetector.Config.LayerTripletVectorString())
0045 elif all(
0046 all(
0047 (isinstance(v, tuple) or isinstance(v, list))
0048 and isinstance(v[0], int)
0049 and isinstance(v[1], inspect.unwrap(TGeoDetector.Config.BinningType))
0050 for v in vv
0051 )
0052 for vv in (negative, central, positive)
0053 if vv is not None
0054 ):
0055 return fill(TGeoDetector.Config.LayerTripletVectorBinning())
0056 else:
0057 raise TypeError("Invalid types for list input")
0058 elif _type == tuple:
0059 if all(
0060 all(isinstance(v, float) for v in vv)
0061 for vv in (negative, central, positive)
0062 if vv is not None
0063 ):
0064 negative = Interval(*negative) if negative is not None else None
0065 central = Interval(*central) if central is not None else None
0066 positive = Interval(*positive) if positive is not None else None
0067 return fill(TGeoDetector.Config.LayerTripletInterval())
0068 else:
0069 raise TypeError("Invalid types for tuple input")
0070 elif _type == Interval:
0071 return fill(TGeoDetector.Config.LayerTripletInterval())
0072 elif _type == str:
0073 return fill(TGeoDetector.Config.LayerTripletString())
0074 elif _type == float:
0075 return fill(TGeoDetector.Config.LayerTripletDouble())
0076 else:
0077 raise TypeError("Unknown type given")
0078
0079
0080 TGeoDetector.Config.LayerTriplet = _makeLayerTriplet
0081
0082
0083 def _process_volume_intervals(kwargs):
0084 if len(kwargs) == 0:
0085 return kwargs # prevent infinite recursion
0086 _kwargs = kwargs.copy()
0087
0088 v = TGeoDetector.Config.Volume()
0089 for name, value in inspect.getmembers(inspect.unwrap(TGeoDetector.Config.Volume)):
0090 if not isinstance(getattr(v, name), inspect.unwrap(Interval)):
0091 continue
0092 if not name in _kwargs:
0093 continue
0094 if not isinstance(_kwargs[name], tuple):
0095 continue
0096 _kwargs[name] = Interval(*_kwargs[name])
0097
0098 return _kwargs
0099
0100
0101 _patchKwargsConstructor(TGeoDetector.Config.Volume, proc=_process_volume_intervals)