Skip to content

Commit 33b109f

Browse files
committed
new options -digitization_variation in gdynamicdigitization overwrites gsystem variation if present. passed to digitization routines
1 parent 008afe8 commit 33b109f

8 files changed

Lines changed: 71 additions & 12 deletions

File tree

.github/workflows/binary_tarballs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
if: >-
2525
${{
2626
github.event.workflow_run.conclusion == 'success' &&
27-
github.event.workflow_run.event == 'push'
27+
github.event.workflow_run.head_repository.full_name == github.repository
2828
}}
2929
name: Attach GEMC tarballs to dev release
3030
runs-on: ubuntu-latest
@@ -66,7 +66,7 @@ jobs:
6666
if: >-
6767
${{
6868
github.event.workflow_run.conclusion == 'success' &&
69-
github.event.workflow_run.event == 'push'
69+
github.event.workflow_run.head_repository.full_name == github.repository
7070
}}
7171
name: Create Job Matrix
7272
runs-on: ubuntu-latest

.github/workflows/trigger_clas12_systems_tests.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ on:
2424
jobs:
2525
dispatch:
2626
name: Dispatch clas12-systems Test
27-
# Security: only dispatch for a successful push to the base repo. workflow_run
28-
# runs privileged (here it consumes CLAS12_SYSTEMS_PAT), so guard against
29-
# fork-PR events the same way deploy.yml and binary_tarballs.yml do.
27+
# Security: only dispatch when the upstream chain originated in the base repo
28+
# (not a fork). This is a 2nd-hop workflow_run (Deploy is itself workflow_run-
29+
# triggered), so workflow_run.event is always 'workflow_run' here, not 'push' --
30+
# head_repository is what carries the original source through the chain. This
31+
# workflow_run runs privileged (it consumes CLAS12_SYSTEMS_PAT), so the guard
32+
# keeps fork PRs from reaching the dispatch step.
3033
if: >-
3134
${{
3235
github.event.workflow_run.conclusion == 'success' &&
33-
github.event.workflow_run.event == 'push'
36+
github.event.workflow_run.head_repository.full_name == github.repository
3437
}}
3538
runs-on: ubuntu-latest
3639
steps:

gemc/eventDispenser/eventDispenser.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ int EventDispenser::processEvents() {
157157
// Iterate the (plugin name -> digitization routine) map.
158158
// digiRoutine is a std::shared_ptr<GDynamicDigitization>.
159159
for (const auto& [plugin, digiRoutine] : *gDigitizationMap) {
160-
log->debug(NORMAL, FUNCTION_NAME, "Calling ", plugin, " loadConstants for run ", runNumber);
160+
// The variation is resolved per routine at geometry load (gsystem variation,
161+
// or the digitization_variation option override when set).
162+
const std::string& variation = digiRoutine->getDigitizationVariation();
163+
164+
log->debug(NORMAL, FUNCTION_NAME, "Calling ", plugin, " loadConstants for run ", runNumber,
165+
" with variation ", variation);
161166
if (digiRoutine->loadConstants(runNumber, variation) == false) {
162167
log->error(ERR_LOADCONSTANTFAIL,
163168
"Failed to load constants for ", plugin, " for run ", runNumber, " with variation ",

gemc/eventDispenser/eventDispenser.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <map>
77
#include <memory>
88
#include <vector>
9-
#include <string>
109

1110
/**
1211
* \file eventDispenser.h
@@ -67,9 +66,6 @@ class EventDispenser : public GBase<EventDispenser>
6766
/// Most recently processed run number. Used to detect run changes and reload run-dependent data.
6867
int currentRunno = -1;
6968

70-
/// Variation string passed to digitization routines when loading constants/translation tables.
71-
std::string variation;
72-
7369
/** @} */
7470

7571
/**

gemc/gdetector/gdetectorConstruction.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,23 @@ void GDetectorConstruction::loadDigitizationPlugins() {
257257
// when the geometry is reloaded with the same SD names.
258258
digitization_routines_map->clear();
259259

260+
// Resolve the variation each routine uses to load constants / translation tables.
261+
// By default a routine follows the variation of the gsystem it belongs to; the
262+
// digitization_variation option, when set, overrides that for every routine.
263+
const std::string digiVariationOverride = gopt->getScalarString("digitization_variation");
264+
const bool overrideVariation = (digiVariationOverride != UNINITIALIZEDSTRINGQUANTITY);
265+
266+
// Map each digitization (sensitive-detector) name to its system's variation.
267+
std::map<std::string, std::string> systemVariationFor;
268+
for (const auto& [systemName, gsystemPtr] : *gworld->getSystemsMap()) {
269+
for (const auto& [volumeName, gvolumePtr] : gsystemPtr->getGVolumesMap()) {
270+
const auto& digiName = gvolumePtr->getDigitization();
271+
if (digiName != "" && digiName != UNINITIALIZEDSTRINGQUANTITY) {
272+
systemVariationFor.emplace(digiName, gsystemPtr->getVariation());
273+
}
274+
}
275+
}
276+
260277
const auto sdetectors = gworld->getSensitiveDetectorsList();
261278

262279
for (auto &sdname: sdetectors) {
@@ -281,6 +298,15 @@ void GDetectorConstruction::loadDigitizationPlugins() {
281298
// Ensure each routine uses the correct logger and is configured for readout.
282299
digitization_routines_map->at(sdname)->set_loggers(gopt);
283300

301+
// Resolve and store the variation used when loading this routine's constants/TT:
302+
// the digitization_variation option when set, otherwise the routine's gsystem variation.
303+
std::string variation = "default";
304+
if (const auto it = systemVariationFor.find(sdname); it != systemVariationFor.end()) {
305+
variation = it->second;
306+
}
307+
if (overrideVariation) { variation = digiVariationOverride; }
308+
digitization_routines_map->at(sdname)->setDigitizationVariation(variation);
309+
284310
if (digitization_routines_map->at(sdname)->defineReadoutSpecs()) {
285311
log->info(1, "Digitization routine <" + sdname + "> has been successfully defined.");
286312
} else { log->error(ERR_DEFINESPECFAIL, "defineReadoutSpecs failure for <" + sdname + ">"); }

gemc/gdynamicDigitization/gdynamicdigitization.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,31 @@ class GDynamicDigitization : public GBase<GDynamicDigitization> {
498498
// TODO: REMOVE THIS EVERYWHERE also remove check_if_log_defined
499499
void set_loggers(const std::shared_ptr<GOptions> &g) { gopts = g; }
500500

501+
/**
502+
* \brief Sets the variation used when this routine loads constants / translation tables.
503+
*
504+
* Resolved once per geometry load: defaults to the variation of the gsystem the routine
505+
* belongs to, and is overridden by the \c digitization_variation option when that is set.
506+
*
507+
* \param v Variation string to use.
508+
*/
509+
void setDigitizationVariation(const std::string &v) { digitization_variation = v; }
510+
511+
/**
512+
* \brief Returns the variation passed to loadConstants() / loadTT().
513+
*
514+
* \return The effective digitization variation for this routine.
515+
*/
516+
[[nodiscard]] std::string getDigitizationVariation() const { return digitization_variation; }
517+
501518
private:
502519
/// When false, hits with exactly zero deposited energy may be skipped.
503520
bool recordZeroEdep = false;
504521

522+
/// Variation used to load constants / translation tables. Defaults to the routine's
523+
/// gsystem variation; overridden by the digitization_variation option when set.
524+
std::string digitization_variation = "default";
525+
505526
protected:
506527
/// Options used by the digitization plugin instance.
507528
std::shared_ptr<GOptions> gopts;

gemc/gdynamicDigitization/gdynamicdigitization_options.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ GOptions defineOptions() {
2121
// When enabled, hits with exactly zero deposited energy are still recorded.
2222
goptions.defineSwitch("recordZeroEdep", "Record particle even if they do not deposit energy in the sensitive volumes");
2323

24+
// When set, overrides the per-system geometry variation used to load digitization
25+
// constants and translation tables. The sentinel default means "not set": each routine
26+
// then follows the variation of the gsystem it belongs to.
27+
goptions.defineOption(
28+
GVariable("digitization_variation", UNINITIALIZEDSTRINGQUANTITY, "digitization variation"),
29+
"If set, overrides the gsystem variation when the digitization routines load their\n"
30+
"constants and translation tables. Default: not set (each routine uses its system's\n"
31+
"variation).\n \nExample: -digitization_variation=rga_fall2018");
32+
2433
// Aggregate options required by downstream types used in the digitization workflow.
2534
goptions += gevent_data::defineOptions();
2635
goptions += grun_data::defineOptions();

gemc_options.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ namespace gemc {
4040
goptions.defineOption(GVariable("nthreads", 0, "sets number of threads."), "Default: 0 (use one thread for each available cores)");
4141
// goptions.defineOption(GVariable("event_module_log", 0, "Event Modulo log"), "Logs every <value> events. Default: 0 (log all events)");
4242
//
43-
// goptions.defineOption(GVariable("digitization_variation", "default", "digitization variation"), "Default: default");
4443
// goptions.defineOption(GVariable("eventTimeSize", "0*ns", "event duration with unit"), "Default: 0*ns");
4544

4645
// random engine name

0 commit comments

Comments
 (0)