Skip to content

Automate beam energy configurations #886

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

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
20 changes: 12 additions & 8 deletions .github/workflows/linux-eic-shell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ jobs:
- uses: actions/checkout@v4
- id: list-detector-configs
run: |
CONFIGS_CSV=$(
ls -1 configurations | sed 's/^/epic_/g' | xargs | sed 's/\.yml//g;s/ /,/g'
)
CONFIGS_JSON=$((
echo '['
ls -1 configurations | sed 's/^/epic_/g' | xargs | sed 's/\.yml//g;s/ /, /g' | xargs -n 1 echo | sed -r 's/^([^,]*)(,?)$/"\1"\2/'
echo ']'
) | jq -c .)
# Collect all config names from all YAMLs, one per line
CONFIGS="$(
for config in configurations/*.yml; do
./bin/make_detector_configuration -d templates -t epic.xml.jinja2 -c "$config" -o "epic_$(basename "$config" .yml).xml" -p
done | sort -u
)"

# CSV
CONFIGS_CSV="$(echo "$CONFIGS" | paste -sd, -)"
# JSON
CONFIGS_JSON="$(echo "$CONFIGS" | jq -R -s -c 'split("\n")[:-1]')"

echo "configs_csv=${CONFIGS_CSV}" | tee -a $GITHUB_OUTPUT
echo "configs_json=${CONFIGS_JSON}" | tee -a $GITHUB_OUTPUT

Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ foreach(config_yml ${CONFIG_YMLS})
--output ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_${config}.xml
COMMENT "Creating configuration ${config} for ${PROJECT_NAME}"
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_${config}.xml
file(GLOB GENERATED_XMLS "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_${config}*.xml")
install(FILES ${GENERATED_XMLS}
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/
)
endforeach()
Expand Down
47 changes: 45 additions & 2 deletions bin/make_detector_configuration
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ parser.add_argument('-d', '--dir', type=str, default='templates', help='Template
parser.add_argument('-t', '--template', type=str, help='Template to render.')
parser.add_argument('-o', '--output', type=str, help='Output file to write.')
parser.add_argument('-c', '--config', type=str, help='Config file to load.')
parser.add_argument('-p', '--print', action='store_true', help='Print the list of configurations to be created without creating them.')
args = parser.parse_args()

outputs = [args.output]

# template
env = jinja2.Environment(
loader = jinja2.FileSystemLoader(args.dir),
Expand All @@ -27,5 +30,45 @@ if args.config is not None:
config = yaml.safe_load(f)

# render the template
with open(args.output, 'w') as output:
output.write(template.render(**config))
if not args.print:
with open(args.output, 'w') as output:
output.write(template.render(**config))

# If the config contains far_forward or far_backward create new xml files with ebeam and pbeam set
if 'features' in config and ('far_forward' in config['features'] or 'far_backward' in config['features']):

# Dictonary of potential ebeam and pbeam values
ebeam_pbeam_values = [
{'ebeam': '5', 'pbeam': '41'},
{'ebeam': '5', 'pbeam': '100'},
{'ebeam': '10', 'pbeam': '100'},
{'ebeam': '10', 'pbeam': '100_Au197'},
{'ebeam': '10', 'pbeam': '115_Cu63'},
{'ebeam': '10', 'pbeam': '115_Ru96'},
{'ebeam': '10', 'pbeam': '130'},
{'ebeam': '10', 'pbeam': '130_H2'},
{'ebeam': '10', 'pbeam': '166_He3'},
{'ebeam': '10', 'pbeam': '250'},
{'ebeam': '10', 'pbeam': '275'},
{'ebeam': '18', 'pbeam': '110_Au'},
{'ebeam': '18', 'pbeam': '110_He3'},
{'ebeam': '18', 'pbeam': '275'},
]

for values in ebeam_pbeam_values:
# Create a new output filename based on the ebeam and pbeam values
new_output = args.output.replace('.xml', f"_{values['ebeam']}x{values['pbeam']}.xml")
outputs.append(new_output)

# Create a new config dictionary with the current ebeam and pbeam values
new_config = config.copy()
new_config.update(values)

if not args.print:
with open(new_output, 'w') as output:
output.write(template.render(**new_config))

if args.print:
for output in outputs:
# Print the output configuration name without the xml extension
print(os.path.basename(output).replace('.xml', ''))
38 changes: 0 additions & 38 deletions configurations/craterlake_10x100.yml

This file was deleted.

38 changes: 0 additions & 38 deletions configurations/craterlake_10x100_Au197.yml

This file was deleted.

38 changes: 0 additions & 38 deletions configurations/craterlake_10x115_Cu63.yml

This file was deleted.

38 changes: 0 additions & 38 deletions configurations/craterlake_10x115_Ru96.yml

This file was deleted.

38 changes: 0 additions & 38 deletions configurations/craterlake_10x130.yml

This file was deleted.

38 changes: 0 additions & 38 deletions configurations/craterlake_10x130_H2.yml

This file was deleted.

38 changes: 0 additions & 38 deletions configurations/craterlake_10x166_He3.yml

This file was deleted.

Loading
Loading