Skip to content

[PWGUD] Fix casts - #18392

Open
vkucera wants to merge 1 commit into
AliceO2Group:masterfrom
vkucera:cast-PWGUD
Open

vkucera wants to merge 1 commit into
AliceO2Group:masterfrom
vkucera:cast-PWGUD

Conversation

@vkucera

@vkucera vkucera commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Fixes C-style, redundant, wrong, and dangerous casts (found by Clang-Tidy and cpplint).

  • Remove redundant casts. (readability-redundant-casting)
  • Remove const_cast. (cppcoreguidelines-pro-type-const-cast)
  • Replace C-style casts with static_cast. (google-readability-casting, cpplint: readability/casting)
  • Replace unsafe C-style casts with dynamic_cast. (cppcoreguidelines-pro-type-cstyle-cast)
  • Replace static_cast in downcasts with dynamic_cast. (cppcoreguidelines-pro-type-static-cast-downcast)
  • Replace reinterpret_cast with static_cast or dynamic_cast. (cppcoreguidelines-pro-type-reinterpret-cast)
  • Replace two-step casting through void* with reinterpret_cast. (bugprone-casting-through-void)

@github-actions github-actions Bot added the pwgud label Oct 21, 2026
@github-actions

Copy link
Copy Markdown

O2 linter results: ❌ 0 errors, ⚠️ 402 warnings, 🔕 0 disabled

@github-actions github-actions Bot changed the title Fix casts [PWGUD] Fix casts Oct 21, 2026
@vkucera
vkucera marked this pull request as ready for review October 21, 2026 16:52
@alibuild

alibuild commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Error while checking build/O2Physics/code-check for f969d1d at 2026-10-22 01:14:

## sw/BUILD/O2Physics-code-check-latest/log
--
========== List of issues found ==========
++ echo 'To reproduce the results below locally, run: '\''aliBuild build O2Physics-code-check -e ALIBUILD_BASE_HASH=upstream/master'\''.'
To reproduce the results below locally, run: 'aliBuild build O2Physics-code-check -e ALIBUILD_BASE_HASH=upstream/master'.
++ echo 'To apply all automatic fixes, add the '\''-e O2PHYSICS_CHECKER_FIX=1'\'' option.'
To apply all automatic fixes, add the '-e O2PHYSICS_CHECKER_FIX=1' option.
++ echo 'See the documentation for more details at: <https://aliceo2group.github.io/analysis-framework/docs/tools/#running-with-o2physics-code-check>.'
See the documentation for more details at: <https://aliceo2group.github.io/analysis-framework/docs/tools/#running-with-o2physics-code-check>.
++ echo 'Found 3 errors and 878 warnings.'
Found 3 errors and 878 warnings.
++ [[ 3 -gt 0 ]]
++ cat /sw/BUILD/499fdd2f7836a465e14589b357efc3b5d37984d8/O2Physics-code-check/errors.txt
PWGUD/TableProducer/UPCCandidateProducer.cxx:879:9: error: Value stored to 'curbc' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
PWGUD/Tasks/diffQA.cxx:953:7: error: Value stored to 'bc3' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
PWGUD/Tasks/upcQuarkoniaCentralBarrel.cxx:52:1: error: included header TObject.h is not used directly [misc-include-cleaner,-warnings-as-errors]
++ [[ 878 -gt 0 ]]
++ cat /sw/BUILD/499fdd2f7836a465e14589b357efc3b5d37984d8/O2Physics-code-check/warnings.txt
PWGUD/AQC/udQCmidRap.cxx:47:8: warning: constructor does not initialize these fields: maxdEdxTPC, maxdEdxTOF [cppcoreguidelines-pro-type-member-init]
PWGUD/AQC/udQCmidRap.cxx:58:29: warning: initializer for member 'diffCuts' is redundant [readability-redundant-member-init]
PWGUD/AQC/udQCmidRap.cxx:162:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:239:30: warning: statement should be inside braces [readability-braces-around-statements]
PWGUD/AQC/udQCmidRap.cxx:321:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:355:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:369:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:388:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:407:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:428:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:449:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:463:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:54:8: warning: constructor does not initialize these fields: maxdEdxTPC, maxdEdxTOF [cppcoreguidelines-pro-type-member-init]
PWGUD/AQC/udQC.cxx:60:20: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGUD/AQC/udQC.cxx:61:20: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGUD/AQC/udQC.cxx:62:20: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGUD/AQC/udQC.cxx:69:29: warning: initializer for member 'diffCuts' is redundant [readability-redundant-member-init]
PWGUD/AQC/udQC.cxx:221:10: warning: implicit conversion 'int64_t' (aka 'long') -> 'bool' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:221:24: warning: statement should be inside braces [readability-braces-around-statements]
PWGUD/AQC/udQC.cxx:223:36: warning: statement should be inside braces [readability-braces-around-statements]
PWGUD/AQC/udQC.cxx:227:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:257:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:258:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:259:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:260:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:261:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:262:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:263:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:267:81: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:268:81: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:269:81: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
[0 more errors; see full log]

Full log here.

@amatyja

amatyja commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Dear @nburmaso and @rolavick,
Could you have a look at Vit changes in your parts of code, please? I think they are very reasonable, but want to know your opinion.
Best regards
Adam

@vkucera
vkucera marked this pull request as draft October 21, 2026 23:27
Comment thread PWGUD/Tasks/upcVmRof.cxx
auto alppar = ccdb->getForTimeStamp<o2::itsmft::DPLAlpideParam<0>>("ITS/Config/AlpideParam", sor);
rofShift = alppar->roFrameBiasInBC;
rofLength = alppar->roFrameLengthInBC;
rofPerOrbit = static_cast<int>(o2::constants::lhc::LHCMaxBunches / rofLength);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

imo the static_cast is not indeed needed here, but it is ill-coded anyway, because the result is not rounded, but truncated. We do not know the intentions of the author, maybe it is on purpose like that, so I would judge this as ok fix.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just to add, in principle the truncation should not matter as one expects the LHCMaxBunches to be an integral multiple of ROF length. However, the ROF lenght is taken from a configuration file and hence it depends on human who writes the value there. A guard is missing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

What do you mean? rofLength is int regardless of what alppar->roFrameLengthInBC returns.

@rolavick rolavick Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, rofLength is always int, but the value is taken from a calibration file and can be, in principle, any integer. You have LHCMaxBunches = 3564 bunches and for PbPb we always had ROF of length 594. Then, your rofPerOrbit is exactly 6, which is what you want to learn here. But if someone makes a typo in the calibration file and write for example 595, then this code would return rofPerOrbit is 5. That does not look suspicious. The mistake would then propagate further, while not being easily trackable.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ah OK, you meant that the task should have a sanity check verifying that LHCMaxBunches is divisible by rofLength. Thanks for the clarification.

@rolavick

Copy link
Copy Markdown
Collaborator

Well, I think it is ok, but I recommend to make one test run of SGProducer to see what effect has the change of cast there. If I understand it correctly, the previous was potentially dangerous (but it does not necessarily mean mistake happened)

Roman

@vkucera
vkucera marked this pull request as ready for review October 22, 2026 12:49
@alibuild

Copy link
Copy Markdown
Collaborator

Error while checking build/O2Physics/o2 for d9140f4 at 2026-10-22 17:42:

No log files found

Full log here.

@alibuild

Copy link
Copy Markdown
Collaborator

Error while checking build/O2Physics/staging for d9140f4 at 2026-10-22 17:42:

No log files found

Full log here.

@alibuild

Copy link
Copy Markdown
Collaborator

Error while checking build/O2Physics/code-check for d9140f4 at 2026-10-22 17:43:

No log files found

Full log here.

Fixes C-style, redundant, wrong, and dangerous casts (found by Clang-Tidy and cpplint).

- Remove redundant casts. (`readability-redundant-casting`)
- Remove `const_cast`. (`cppcoreguidelines-pro-type-const-cast`)
- Replace C-style casts with `static_cast`. (`google-readability-casting`, cpplint: `readability/casting`)
- Replace unsafe C-style casts with `dynamic_cast`. (`cppcoreguidelines-pro-type-cstyle-cast`)
- Replace `static_cast` in downcasts with `dynamic_cast`. (`cppcoreguidelines-pro-type-static-cast-downcast`)
- Replace `reinterpret_cast` with `static_cast` or `dynamic_cast`. (`cppcoreguidelines-pro-type-reinterpret-cast`)
- Replace two-step casting through `void*` with `reinterpret_cast`. (`bugprone-casting-through-void`)
@alibuild

Copy link
Copy Markdown
Collaborator

Error while checking build/O2Physics/code-check for e95cbf6 at 2026-10-22 19:17:

## sw/BUILD/O2Physics-code-check-latest/log
--
========== List of issues found ==========
++ echo 'To reproduce the results below locally, run: '\''aliBuild build O2Physics-code-check -e ALIBUILD_BASE_HASH=upstream/master'\''.'
To reproduce the results below locally, run: 'aliBuild build O2Physics-code-check -e ALIBUILD_BASE_HASH=upstream/master'.
++ echo 'To apply all automatic fixes, add the '\''-e O2PHYSICS_CHECKER_FIX=1'\'' option.'
To apply all automatic fixes, add the '-e O2PHYSICS_CHECKER_FIX=1' option.
++ echo 'See the documentation for more details at: <https://aliceo2group.github.io/analysis-framework/docs/tools/#running-with-o2physics-code-check>.'
See the documentation for more details at: <https://aliceo2group.github.io/analysis-framework/docs/tools/#running-with-o2physics-code-check>.
++ echo 'Found 3 errors and 878 warnings.'
Found 3 errors and 878 warnings.
++ [[ 3 -gt 0 ]]
++ cat /sw/BUILD/896e72859abb40583be3e7f8dfe231cbeb2e1134/O2Physics-code-check/errors.txt
PWGUD/TableProducer/UPCCandidateProducer.cxx:879:9: error: Value stored to 'curbc' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
PWGUD/Tasks/diffQA.cxx:953:7: error: Value stored to 'bc3' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
PWGUD/Tasks/upcQuarkoniaCentralBarrel.cxx:52:1: error: included header TObject.h is not used directly [misc-include-cleaner,-warnings-as-errors]
++ [[ 878 -gt 0 ]]
++ cat /sw/BUILD/896e72859abb40583be3e7f8dfe231cbeb2e1134/O2Physics-code-check/warnings.txt
PWGUD/AQC/udQCmidRap.cxx:47:8: warning: constructor does not initialize these fields: maxdEdxTPC, maxdEdxTOF [cppcoreguidelines-pro-type-member-init]
PWGUD/AQC/udQCmidRap.cxx:58:29: warning: initializer for member 'diffCuts' is redundant [readability-redundant-member-init]
PWGUD/AQC/udQCmidRap.cxx:162:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:239:30: warning: statement should be inside braces [readability-braces-around-statements]
PWGUD/AQC/udQCmidRap.cxx:321:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:355:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:369:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:388:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:407:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:428:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:449:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQCmidRap.cxx:463:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:54:8: warning: constructor does not initialize these fields: maxdEdxTPC, maxdEdxTOF [cppcoreguidelines-pro-type-member-init]
PWGUD/AQC/udQC.cxx:60:20: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGUD/AQC/udQC.cxx:61:20: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGUD/AQC/udQC.cxx:62:20: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGUD/AQC/udQC.cxx:69:29: warning: initializer for member 'diffCuts' is redundant [readability-redundant-member-init]
PWGUD/AQC/udQC.cxx:221:10: warning: implicit conversion 'int64_t' (aka 'long') -> 'bool' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:221:24: warning: statement should be inside braces [readability-braces-around-statements]
PWGUD/AQC/udQC.cxx:223:36: warning: statement should be inside braces [readability-braces-around-statements]
PWGUD/AQC/udQC.cxx:227:58: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:257:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:258:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:259:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:260:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:261:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:262:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:263:70: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:267:81: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:268:81: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
PWGUD/AQC/udQC.cxx:269:81: warning: implicit conversion 'bool' -> 'double' [readability-implicit-bool-conversion]
[0 more errors; see full log]

Full log here.

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

Labels

Development

Successfully merging this pull request may close these issues.

4 participants