Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DD4hep
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cepc
externals
mirroring
DD4hep
Commits
cf60b934
Commit
cf60b934
authored
1 year ago
by
Wouter Deconinck
Committed by
MarkusFrankATcernch
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: action=append for argparse; deduplicate; recursive makeListOfDictFromJSON
parent
fe3a98ff
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
DDG4/python/DDSim/Helper/Action.py
+30
-19
30 additions, 19 deletions
DDG4/python/DDSim/Helper/Action.py
DDTest/CMakeLists.txt
+4
-0
4 additions, 0 deletions
DDTest/CMakeLists.txt
with
34 additions
and
19 deletions
DDG4/python/DDSim/Helper/Action.py
+
30
−
19
View file @
cf60b934
...
@@ -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} )
#
c
re
ates:
{
"
name
"
:
"
Geant4TestEventAction
"
,
"
parameter
"
: {
"
Property_int
"
: 10} }
# re
turns: [
{
"
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} }
#
c
re
ate
s: [ {
"
name
"
:
"
Geant4TestEventAction
"
,
"
parameter
"
: {
"
Property_int
"
: 10} } ]
# re
turn
s: [ {
"
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)
This diff is collapsed.
Click to expand it.
DDTest/CMakeLists.txt
+
4
−
0
View file @
cf60b934
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment