Skip to content

CaloTowerStatus: Prioritize Direct URL Overrides#4266

Merged
pinkenburg merged 3 commits into
sPHENIX-Collaboration:masterfrom
Steepspace:CaloTowerStatus
May 12, 2026
Merged

CaloTowerStatus: Prioritize Direct URL Overrides#4266
pinkenburg merged 3 commits into
sPHENIX-Collaboration:masterfrom
Steepspace:CaloTowerStatus

Conversation

@Steepspace
Copy link
Copy Markdown
Contributor

@Steepspace Steepspace commented May 12, 2026

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work for users)
  • Requiring change in macros repository (Please provide links to the macros pull request in the last section)
  • I am a member of GitHub organization of sPHENIX Collaboration, EIC, or ECCE (contact Chris Pinkenburg to join)

What kind of change does this PR introduce? (Bug fix, feature, ...)

Updated the logic in InitRun to ensure that URLs provided via set_directURL_hotMap and set_directURL_chi2 take precedence over the default CDBInterface lookups. Previously, the code checked the CDB first, which caused user-specified URLs to act only as fallbacks rather than overrides.

The logic now:

  1. Checks for a user-specified direct URL.
  2. Falls back to the CDBInterface if no direct URL is provided.
  3. Aborts or disables the masking if neither is found.

TODOs (if applicable)

Links to other PRs in macros and calibration repositories (if applicable)

CaloTowerStatus: Prioritize Direct URL Overrides

Motivation

CaloTowerStatus previously queried the CDB first and treated user-provided direct URLs as fallbacks. That made it awkward to run with local calibration files when a CDB entry existed. This PR fixes the lookup order so explicit direct URLs reliably override CDB entries, enabling straightforward local testing and intended override behavior.

Key Changes

  • Direct-URL precedence: InitRun now checks the direct URL string members (m_directURL_chi2, m_directURL_hotMap) first; non-empty strings are used directly.
  • Removed boolean flags: Eliminated use_directURL_chi2 and use_directURL_hotMap; presence of a non-empty direct URL string is now the single signal to use an override.
  • CDB fallback: If no direct URL is provided, the code queries CDBInterface for the appropriate entry and constructs CDBTTree only when a URL is returned.
  • Abort/disable behavior preserved: If neither a direct URL nor a CDB entry is found, behavior remains — abort if m_doAbortNoChi2 / m_doAbortNoHotMap are set; otherwise disable the corresponding masking and log the outcome.
  • Logging improved: Clearer messages distinguish direct-URL usage, CDB lookups, and the fallback/abort paths.

Potential Risk Areas

  • IO/data formats: None — no changes to calibration file formats or downstream reconstruction objects; only the lookup source selection changed.
  • Reconstruction behavior: Low risk — the same CDBTTree objects are produced when a source is available; behavior differs only in which source is chosen.
  • Thread-safety: No new shared mutable state introduced; risk is unchanged.
  • Performance: Negligible — simple string emptiness checks replace the previous boolean-flag logic.
  • Configuration pitfalls: Users who previously relied on the boolean flags must ensure they provide non-empty direct URL strings; otherwise CDB will be consulted.

Possible Future Improvements

  • Validate direct-URL/file existence at InitRun and emit actionable errors (instead of only logging) to avoid silent misconfiguration.
  • Add unit/integration tests covering direct-URL overrides, CDB fallbacks, and abort vs disable behavior.
  • Consolidate and simplify related configuration handling to a single helper that returns the resolved URL (direct or CDB) to reduce duplication.

Notes

  • Reviewer feedback favored removing boolean flags (to avoid a true flag with no filename); this PR implements that suggestion.
  • AI-generated summaries can be imperfect — please review the diff to confirm behavior and messaging details.

Review Change Stack

Updated the logic in InitRun to ensure that URLs provided via set_directURL_hotMap and set_directURL_chi2 take precedence over the default CDBInterface lookups. Previously, the code checked the CDB first, which caused user-specified URLs to act only as fallbacks rather than overrides. This made it difficult to test local calibration files when a CDB map already existed for the current run.

The logic now:
1. Checks for a user-specified direct URL.
2. Falls back to the CDBInterface if no direct URL is provided.
3. Aborts or disables the masking if neither is found.
Copilot AI review requested due to automatic review settings May 12, 2026 02:12
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 974eb163-3c3a-418d-b83e-36572da928db

📥 Commits

Reviewing files that changed from the base of the PR and between ecb6971 and ad25fc2.

📒 Files selected for processing (2)
  • offline/packages/CaloReco/CaloTowerStatus.cc
  • offline/packages/CaloReco/CaloTowerStatus.h
💤 Files with no reviewable changes (1)
  • offline/packages/CaloReco/CaloTowerStatus.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • offline/packages/CaloReco/CaloTowerStatus.cc

📝 Walkthrough

Walkthrough

InitRun now prioritizes non-empty direct URL string overrides for chi2 and hot-map; if absent it queries CDBInterface and constructs trees only when a URL is returned, preserving existing exit-or-disable behavior. Setters no longer toggle boolean flags.

Changes

Calibration initialization refactor

Layer / File(s) Summary
Header: remove boolean flags; update setters
offline/packages/CaloReco/CaloTowerStatus.h
Removes use_directURL_hotMap/use_directURL_chi2 booleans and makes set_directURL_* assign only the m_directURL_* strings without side effects.
InitRun: prefer direct URL strings then CDB
offline/packages/CaloReco/CaloTowerStatus.cc
InitRun checks m_directURL_chi2/m_directURL_hotMap first (log + build m_cdbttree_* from direct URL). If empty, it calls CDBInterface::instance()->getUrl(...), builds m_cdbttree_* only if that URL is non-empty, and otherwise preserves gSystem->Exit(1) when abort flags are set or disables hot-tree usage and logs.

Possibly related PRs

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
offline/packages/CaloReco/CaloTowerStatus.cc (2)

84-152: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Memory leak on repeated InitRun calls.

Lines 89, 96, 126, and 133 allocate new CDBTTree objects and assign to m_cdbttree_chi2 and m_cdbttree_hotMap without first deleting any existing allocation. If InitRun is called multiple times (e.g., processing multiple runs in a single job), the old pointers are overwritten and the previously allocated memory is leaked until the CaloTowerStatus object is destroyed.

🔧 Proposed fix

Delete existing pointers before allocating new ones:

 std::string calibdir_chi2;
 if (use_directURL_chi2)
 {
   calibdir_chi2 = m_directURL_chi2;
   std::cout << "CaloTowerStatus::InitRun: Using direct URL override for chi2: " << calibdir_chi2 << std::endl;
+  delete m_cdbttree_chi2;
+  m_cdbttree_chi2 = nullptr;
   m_cdbttree_chi2 = new CDBTTree(calibdir_chi2);
 }
 else
 {
   calibdir_chi2 = CDBInterface::instance()->getUrl(m_calibName_chi2);
   if (!calibdir_chi2.empty())
   {
+    delete m_cdbttree_chi2;
+    m_cdbttree_chi2 = nullptr;
     m_cdbttree_chi2 = new CDBTTree(calibdir_chi2);

Apply the same fix for m_cdbttree_hotMap at lines 126 and 133.


84-152: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

CDBTTree construction not protected by exception handling.

The CDBTTree constructor at lines 89, 96, 126, and 133 can throw exceptions (e.g., file not found, invalid path, access denied), but these allocations occur before the try-catch block at lines 170-179. If construction fails—particularly when a user provides a malformed direct URL—the exception propagates uncaught, potentially crashing the framework ungracefully.

🛡️ Proposed fix

Wrap the CDBTTree constructions in the existing try-catch block or add local error handling:

+  try
+  {
   std::string calibdir_chi2;
   if (use_directURL_chi2)
   {
     calibdir_chi2 = m_directURL_chi2;
     std::cout << "CaloTowerStatus::InitRun: Using direct URL override for chi2: " << calibdir_chi2 << std::endl;
     m_cdbttree_chi2 = new CDBTTree(calibdir_chi2);
   }
   // ... rest of chi2 and hotMap setup ...
+  }
+  catch (std::exception &e)
+  {
+    std::cout << "CaloTowerStatus::InitRun: Failed to load calibration: " << e.what() << std::endl;
+    return Fun4AllReturnCodes::ABORTRUN;
+  }

Alternatively, move all calibration setup into the existing try-catch block starting at line 170.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1a4b2489-986b-41f0-bd4a-86e5bb99fc79

📥 Commits

Reviewing files that changed from the base of the PR and between 3c0f433 and ecb6971.

📒 Files selected for processing (1)
  • offline/packages/CaloReco/CaloTowerStatus.cc

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates CaloTowerStatus::InitRun so that user-specified calibration URLs (via set_directURL_hotMap / set_directURL_chi2) are treated as true overrides, with CDB lookups used only as a fallback.

Changes:

  • Reordered chi2 calibration loading to use m_directURL_chi2 first when provided, otherwise query CDBInterface.
  • Reordered hot map calibration loading to use m_directURL_hotMap first when provided, otherwise query CDBInterface.
  • Kept existing abort/disable behavior when no calibration source is available.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread offline/packages/CaloReco/CaloTowerStatus.cc
Comment on lines +122 to +126
if (use_directURL_hotMap)
{
m_cdbttree_hotMap = new CDBTTree(calibdir);
if (Verbosity() > 1)
{
std::cout << "CaloTowerStatus::Init " << m_detector << " hot map found " << m_calibName_hotMap << " Ddoing isHot" << std::endl;
}
calibdir_hotMap = m_directURL_hotMap;
std::cout << "CaloTowerStatus::InitRun: Using direct URL override for hot map: " << calibdir_hotMap << std::endl;
m_cdbttree_hotMap = new CDBTTree(calibdir_hotMap);
Comment thread offline/packages/CaloReco/CaloTowerStatus.cc Outdated
"Ddoing" - > "Doing"

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sphenix-jenkins-ci
Copy link
Copy Markdown

Build & test report

Report for commit ecb697166f7676109c18a5efacd163e015409ed2:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@sphenix-jenkins-ci
Copy link
Copy Markdown

Build & test report

Report for commit b3467b76fb6610d0a571711955b2c56be083b27d:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@pinkenburg
Copy link
Copy Markdown
Contributor

The proliferation of flags is really concerning. Here an approach of setting the filename and only call the cdb if that filename is empty is more appropriate. That will simplify the code a lot and prevent bad usages where the flag is set to true but the filename is not set.

@pinkenburg pinkenburg marked this pull request as draft May 12, 2026 13:59
- Removed 'use_directURL_hotMap' and 'use_directURL_chi2' boolean flags.
- Updated InitRun to check if URL strings are non-empty to determine if a direct override should be used.
- Ensured that a non-empty direct URL string takes precedence over the default CDBInterface lookup.

This change prevents potential bugs where a flag could be set to true without a valid filename, and streamlines the code by relying on the string's presence as the single source of truth for the override.
@sphenix-jenkins-ci
Copy link
Copy Markdown

Build & test report

Report for commit ad25fc22e314edbeb0dbdaf01d7d2b9f0b6ee135:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@Steepspace Steepspace marked this pull request as ready for review May 12, 2026 19:44
@Steepspace
Copy link
Copy Markdown
Contributor Author

The proliferation of flags is really concerning. Here an approach of setting the filename and only call the cdb if that filename is empty is more appropriate. That will simplify the code a lot and prevent bad usages where the flag is set to true but the filename is not set.

@pinkenburg , thank you for the feedback. I have simplified the module by removing the additional boolean flags. If you could confirm it looks good on your end that would be great.

@pinkenburg pinkenburg merged commit 48aea72 into sPHENIX-Collaboration:master May 12, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants