Skip to content
Snippets Groups Projects
Commit cf60b934 authored by Wouter Deconinck's avatar Wouter Deconinck Committed by MarkusFrankATcernch
Browse files

fix: action=append for argparse; deduplicate; recursive makeListOfDictFromJSON

parent fe3a98ff
No related branches found
No related tags found
No related merge requests found
...@@ -67,10 +67,15 @@ or ...@@ -67,10 +67,15 @@ or
self._trackerSDTypes = ['tracker'] self._trackerSDTypes = ['tracker']
self._calorimeterSDTypes = ['calorimeter'] self._calorimeterSDTypes = ['calorimeter']
self._run = [] self._run = []
self._run_EXTRA = {"action": "append"}
self._event = [] self._event = []
self._event_EXTRA = {"action": "append"}
self._track = [] self._track = []
self._track_EXTRA = {"action": "append"}
self._step = [] self._step = []
self._step_EXTRA = {"action": "append"}
self._stack = [] self._stack = []
self._stack_EXTRA = {"action": "append"}
self._closeProperties() self._closeProperties()
@property @property
...@@ -148,27 +153,23 @@ or ...@@ -148,27 +153,23 @@ or
import json import json
try: try:
val = json.loads(val) val = json.loads(val)
# interpret json structure
return Action.makeListOfDictFromJSON(val)
except ValueError: except ValueError:
val = [dict(name=v) for v in val.split(",")] # returns: [ { "name": "Geant4TestEventAction" } ]
return [dict(name=v) for v in val.split(",")]
if isinstance(val, tuple): if isinstance(val, tuple):
# assumes: ( "Geant4TestEventAction", {"Property_int": 10} ) # assumes: ( "Geant4TestEventAction", {"Property_int": 10} )
# creates: { "name": "Geant4TestEventAction", "parameter": {"Property_int": 10} } # returns: [ { "name": "Geant4TestEventAction", "parameter": {"Property_int": 10} } ]
# note: not able to be specified as json which only allows a list # note: not able to be specified as json which only allows a list
val = dict(name=val[0], parameter=val[1]) return [dict(name=val[0], parameter=val[1])]
if isinstance(val, dict): if isinstance(val, dict):
# assumes: { "name": "Geant4TestEventAction", "parameter": {"Property_int": 10} } # assumes: { "name": "Geant4TestEventAction", "parameter": {"Property_int": 10} }
# creates: [ { "name": "Geant4TestEventAction", "parameter": {"Property_int": 10} } ] # returns: [ { "name": "Geant4TestEventAction", "parameter": {"Property_int": 10} } ]
val = [val] return [val]
if isinstance(val, list): if isinstance(val, list):
if not val: # interpret each list entry into a list and concatenate
# empty list return [i for v in val for i in Action.makeListOfDictFromJSON(v)]
return []
if isinstance(val[0], str):
# assumes: [ "Geant4TestEventAction", "Geant4TestEventAction" ]
return [dict(name=v) for v in val]
if isinstance(val[0], dict):
# assumes: [ { "name": "Geant4TestEventAction", "parameter": {"Property_int": 10} } ]
return val
raise RuntimeError("Commandline setting of action is not successful for: %s " % val) raise RuntimeError("Commandline setting of action is not successful for: %s " % val)
@property @property
...@@ -178,7 +179,9 @@ or ...@@ -178,7 +179,9 @@ or
@run.setter @run.setter
def run(self, val): def run(self, val):
self._run.extend(Action.makeListOfDictFromJSON(val)) for action in Action.makeListOfDictFromJSON(val):
if action not in self._run:
self._run.append(action)
@property @property
def event(self): def event(self):
...@@ -187,7 +190,9 @@ or ...@@ -187,7 +190,9 @@ or
@event.setter @event.setter
def event(self, val): def event(self, val):
self._event.extend(Action.makeListOfDictFromJSON(val)) for action in Action.makeListOfDictFromJSON(val):
if action not in self._event:
self._event.append(action)
@property @property
def track(self): def track(self):
...@@ -196,7 +201,9 @@ or ...@@ -196,7 +201,9 @@ or
@track.setter @track.setter
def track(self, val): def track(self, val):
self._track.extend(Action.makeListOfDictFromJSON(val)) for action in Action.makeListOfDictFromJSON(val):
if action not in self._track:
self._track.append(action)
@property @property
def step(self): def step(self):
...@@ -205,7 +212,9 @@ or ...@@ -205,7 +212,9 @@ or
@step.setter @step.setter
def step(self, val): def step(self, val):
self._step.extend(Action.makeListOfDictFromJSON(val)) for action in Action.makeListOfDictFromJSON(val):
if action not in self._step:
self._step.append(action)
@property @property
def stack(self): def stack(self):
...@@ -214,4 +223,6 @@ or ...@@ -214,4 +223,6 @@ or
@stack.setter @stack.setter
def stack(self, val): def stack(self, val):
self._stack.extend(Action.makeListOfDictFromJSON(val)) for action in Action.makeListOfDictFromJSON(val):
if action not in self._stack:
self._stack.append(action)
...@@ -154,6 +154,10 @@ if (DD4HEP_USE_GEANT4) ...@@ -154,6 +154,10 @@ if (DD4HEP_USE_GEANT4)
--action.step '\[ \"Geant4TestStepAction/StepActionCLI3\" , \"Geant4TestStepAction/StepActionCLI4\" \]' --action.step '\[ \"Geant4TestStepAction/StepActionCLI3\" , \"Geant4TestStepAction/StepActionCLI4\" \]'
--action.stack '\{ \"name\" : \"Geant4TestStackAction/StackActionCLI1\" , \"parameter\" : \{ \"Property_int\" : 10 \} \}' --action.stack '\{ \"name\" : \"Geant4TestStackAction/StackActionCLI1\" , \"parameter\" : \{ \"Property_int\" : 10 \} \}'
--action.stack '\[ \{ \"name\" : \"Geant4TestStackAction/StackActionCLI2\" , \"parameter\" : { \"Property_int\" : 10 \} \} \]' --action.stack '\[ \{ \"name\" : \"Geant4TestStackAction/StackActionCLI2\" , \"parameter\" : { \"Property_int\" : 10 \} \} \]'
--printLevel VERBOSE
)
set_tests_properties( t_ddsimUserActions PROPERTIES
PASS_REGULAR_EXPRESSION "Deleting object StepActionCLI1"
) )
endif() endif()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment