Skip to content

Set the EWT to be the event number in sims#1807

Open
michaelmackenzie wants to merge 2 commits intoMu2e:mainfrom
michaelmackenzie:EventHeaderEWTSim
Open

Set the EWT to be the event number in sims#1807
michaelmackenzie wants to merge 2 commits intoMu2e:mainfrom
michaelmackenzie:EventHeaderEWTSim

Conversation

@michaelmackenzie
Copy link
Copy Markdown
Contributor

This will at least allow for changing EWT values in simulations. The run/subrun/event values can't be packed into the 64 bit EWT, so this cannot all be encoded. The linearly increasing EWT values within a subrun will be useful for lumi stream tests, where the subrun number can be taken from the art event but the event number is lost in the buffering of objects.

@FNALbuild
Copy link
Copy Markdown
Collaborator

Hi @michaelmackenzie,
You have proposed changes to files in these packages:

  • DAQ

which require these tests: build.

@Mu2e/fnalbuild-users, @Mu2e/write have access to CI actions on main.

⌛ The following tests have been triggered for 32aa705: build (Build queue - API unavailable)

About FNALbuild. Code review on Mu2e/Offline.

@oksuzian
Copy link
Copy Markdown
Collaborator

PR #1807 Review — Set the EWT to be the event number in sims

Summary

Author: @michaelmackenzie
Base: Mu2e:mainHead: michaelmackenzie:EventHeaderEWTSim
State: Open, draft: false, mergeable: true, mergeable_state: unstable (CI build still in queue)
Scope: 1 file, +2 / −0, 1 commit, 1 comment (FNALbuild CI bot)
Reviews: None yet
Labels: build running
Risk: Low — 2-line scoped change in a single DAQ producer module, gated by a branch that only fires when no CFO fragment handle is present (i.e., in simulation).

Intent (from PR body): Allow the EWT to vary in simulations so that lumi-stream tests see a linearly increasing EWT inside a subrun. The full (run/subrun/event) tuple can't be packed into the 64-bit EWT, so the event number alone is used as a best-effort proxy.


Core Change

File: DAQ/src/EventHeaderFromCFOFragment_module.cc

   if(!event.getByLabel(cfoFragmentTag_, cfoFragmentHandle)) {
+    // Set the EWT to be the art event number for now, useful for simulations
+    evtHdr->ewt = static_cast<long unsigned int>(event.event());
     event.put(std::move(evtHdr));
     if(ewm_) event.put(std::move(ewm));
     TLOG(TLVL_DEBUG + 1) << "No CFO fragments found";
     return;
   }

Previously, when there was no CFO fragment collection in the event (the sim path), evtHdr->ewt was left at whatever the default-constructed mu2e::EventHeader initializes it to. Now it is set to event.event() so downstream lumi-stream / EWT-based code sees monotonically increasing values within a subrun.


🔎 Issue found — inconsistent handling of the "no CFO fragments" case

There are actually two places in produce() that represent "no usable CFO fragment" but this PR only patches one of them:

  if(!event.getByLabel(cfoFragmentTag_, cfoFragmentHandle)) {
    // Set the EWT to be the art event number for now, useful for simulations
    evtHdr->ewt = static_cast<long unsigned int>(event.event());   // ← patched
    event.put(std::move(evtHdr));
    if(ewm_) event.put(std::move(ewm));
    TLOG(TLVL_DEBUG + 1) << "No CFO fragments found";
    return;
  }

  const auto *fragments = cfoFragmentHandle.product();
  if (fragments->size()>0){
    ...
    evtHdr->ewt = static_cast<long unsigned int>(cfo.GetEventWindowTag()...);
    ...
  } else {
    TLOG(TLVL_DEBUG + 3) << "No CFO fragments found in the event";   // ← NOT patched, ewt stays default
  }

If the handle is present but the fragment vector is empty (fragments->size() == 0), evtHdr->ewt is never assigned and the event is still put() at line 127. So the new simulation-friendly behavior only kicks in if getByLabel fails outright; any job where the CFO collection exists but is empty will still emit an EventHeader with a stale/default EWT. For the lumi-stream test use case this will look like many consecutive events with the same EWT and likely defeat the purpose of the PR.

Suggested fix — set the fallback EWT for both "no fragment" branches, e.g.:

  // default EWT for the sim / no-fragment case
  evtHdr->ewt = static_cast<long unsigned int>(event.event());

  if(!event.getByLabel(cfoFragmentTag_, cfoFragmentHandle)) {
    event.put(std::move(evtHdr));
    if(ewm_) event.put(std::move(ewm));
    TLOG(TLVL_DEBUG + 1) << "No CFO fragments found";
    return;
  }

  const auto *fragments = cfoFragmentHandle.product();
  if (fragments->size() > 0) {
    ...
    evtHdr->ewt = static_cast<long unsigned int>(cfo.GetEventWindowTag()...); // overwrite with real value
    ...
  } else {
    TLOG(TLVL_DEBUG + 3) << "No CFO fragments found in the event";
    // evtHdr->ewt already seeded from event.event()
  }

This keeps the single-line-of-intent semantics and ensures both "simish" code paths produce a useful EWT.


Other observations / possible improvements

  1. EWM not populated on the early-return path (pre-existing). On the !getByLabel branch, when ewm_ is true, the EventWindowMarker is put() without _spillType or _eventLength ever being assigned (compare to lines 121–125 on the main path). Not introduced by this PR, but worth considering a follow-up since this is the sim path you are now leaning on.
  2. Cast type. event.event() returns art::EventNumber_t (32-bit unsigned). static_cast<long unsigned int> works but is platform-dependent. Since EventHeader::ewt is a uint64_t, using static_cast<uint64_t>(event.event()) (or the exact type of ewt) would be clearer and match the cast used on line 112.
  3. Comment wording. "for now" usually becomes "forever" — consider referencing a ticket or TODO so future readers know this is an intentional sim-only fallback.
  4. Run/subrun in EWT. The PR body notes that run/subrun can't be packed in. If it ever becomes desirable, the subrun could be stashed in the high bits of the 64-bit EWT with the event number in the low bits; worth an inline comment documenting that this was considered and rejected.

Merge readiness

  • ✅ Change is minimal, localized, and the intent matches the diff.
  • build CI check is still queued — wait for that to pass.
  • ⚠️ The fragments->size() == 0 inconsistency above is the one substantive issue I'd flag before approving; everything else is polish.
  • No reviewers have been requested yet.

Want me to…

  1. Draft an inline review comment on the PR pointing out the fragments->size() == 0 inconsistency.
  2. Propose a concrete patch (commit-ready diff) that also hoists the default-EWT assignment above the getByLabel check.
  3. Check the mu2e::EventHeader default-construction to confirm what ewt currently defaults to when unset.
  4. Look for downstream consumers of EventHeader::ewt in Offline to verify the sim-proxy value won't trip any validity checks.
  5. Poll CI and report back when the build check finishes.

@michaelmackenzie
Copy link
Copy Markdown
Contributor Author

If there is a CFO fragment collection in the event, but no usable CFO fragment, I don't think this should be handled like simulation and set to a non-zero value. I think it's better to leave this alone and perhaps later we'll throw an error or filter out this event due to missing CFO or corrupted information.

@FNALbuild
Copy link
Copy Markdown
Collaborator

☀️ The build tests passed at 32aa705.

Test Result Details
test with Command did not list any other PRs to include
merge Merged 32aa705 at 314d115
build (prof) Log file. Build time: 04 min 09 sec
ceSimReco Log file.
g4test_03MT Log file.
transportOnly Log file.
POT Log file.
g4study Log file.
cosmicSimReco Log file.
cosmicOffSpill Log file.
ceSteps Log file.
ceDigi Log file.
muDauSteps Log file.
ceMix Log file.
rootOverlaps Log file.
g4surfaceCheck Log file.
trigger Log file.
check_cmake Log file.
FIXME, TODO TODO (0) FIXME (0) in 1 files
clang-tidy ➡️ 2 errors 10 warnings
whitespace check no whitespace errors found

N.B. These results were obtained from a build of this Pull Request at 32aa705 after being merged into the base branch at 314d115.

For more information, please check the job page here.
Build artifacts are deleted after 5 days. If this is not desired, select Keep this build forever on the job page.

@michaelmackenzie
Copy link
Copy Markdown
Contributor Author

@FNALbuild run build test

@FNALbuild
Copy link
Copy Markdown
Collaborator

⌛ The following tests have been triggered for 5a0d718: build (Build queue - API unavailable)

@FNALbuild
Copy link
Copy Markdown
Collaborator

☀️ The build tests passed at 5a0d718.

Test Result Details
test with Command did not list any other PRs to include
merge Merged 5a0d718 at 314d115
build (prof) Log file. Build time: 04 min 08 sec
ceSimReco Log file.
g4test_03MT Log file.
transportOnly Log file.
POT Log file.
g4study Log file.
cosmicSimReco Log file.
cosmicOffSpill Log file.
ceSteps Log file.
ceDigi Log file.
muDauSteps Log file.
ceMix Log file.
rootOverlaps Log file.
g4surfaceCheck Log file.
trigger Log file.
check_cmake Log file.
FIXME, TODO TODO (0) FIXME (0) in 1 files
clang-tidy ➡️ 2 errors 12 warnings
whitespace check no whitespace errors found

N.B. These results were obtained from a build of this Pull Request at 5a0d718 after being merged into the base branch at 314d115.

For more information, please check the job page here.
Build artifacts are deleted after 5 days. If this is not desired, select Keep this build forever on the job page.

@FNALbuild
Copy link
Copy Markdown
Collaborator

📝 The HEAD of main has changed to 839521c. Tests are now out of date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants