Skip to content

Conversation

@mrtineide
Copy link
Contributor

@mrtineide mrtineide commented Jul 18, 2025

Namespace cleanup - Change in other libraries will affect O2

Story of what happened

I was contacted by @costing, who relayed a report from @vkucera regarding problematic headers. It was discovered while running clang-tidy on O2Physics. The issue was that while running cland-tidy it would include the header TJAlienCredentials.h from the JAlien-ROOT or libjalienO2 libraries instead of #include <string>.

Specifically, the header contained the following lines:

using std::map;
using std::string;

These using declarations in a header file pollute the global namespace for every file that uses them. A common place where this was spread was through CCDBApi.h, which includes TJAlienCredentials.h, thereby spreading the using std::string declaration across many parts that uses CCDB API.

I am new to C++ so I had to find some sources that confirmed why the change should be considered:

The proposed change in the other repo's:

In external repos: Removed using std::string and using std::map from TJAlienCredentials.h

What this PR does

I updated all affected files in O2 to explicitly use std:: where needed for compilation to complete.
That is, this compilation command completed:

aliBuild build O2 --defaults o2

Some smaller potential issues

  • Some comments may be slightly misaligned due to code edits.
  • I may have added std:: in places where it wasn’t strictly necessary due to using std::string; declarations in the same .cxx files.
  • Other, unknown to me, repositories might still rely on the polluted namespace and could break when the updated headers are published.

A bit about me 🧑‍💻

  • Background in Software Engineering
  • First experience working with C++ in a large codebase

Please let me know if anything is not how it should be and I'll fix it. (I do not know if I got the o2codechecker to run properly)

@github-actions
Copy link
Contributor

REQUEST FOR PRODUCTION RELEASES:
To request your PR to be included in production software, please add the corresponding labels called "async-" to your PR. Add the labels directly (if you have the permissions) or add a comment of the form (note that labels are separated by a ",")

+async-label <label1>, <label2>, !<label3> ...

This will add <label1> and <label2> and removes <label3>.

The following labels are available
async-2023-pbpb-apass4
async-2023-pp-apass4
async-2024-pp-apass1
async-2022-pp-apass7
async-2024-pp-cpass0
async-2024-PbPb-apass1
async-2024-ppRef-apass1
async-2024-PbPb-apass2
async-2023-PbPb-apass5

davidrohr
davidrohr previously approved these changes Jul 18, 2025
Copy link
Collaborator

@davidrohr davidrohr left a comment

Choose a reason for hiding this comment

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

This looks correct to me, and indeed one should not have using statements in headers in the global namespace.

Please ignore the CI failure about code formatting, this is just because you touched files that are not formatted correctly. We can just force-merge it ignorning the CI errors.

Why did you mark the PR draft? In principle we should start the CI on it and check if it suceeds.

@mrtineide
Copy link
Contributor Author

Why did you mark the PR draft? In principle we should start the CI on it and check if it suceeds.

Oh, that was just to play it safe. And also to maybe avoid the mass ping if there was something wrong with formatting and other smaller things.

I'll mark it as ready.

@davidrohr
Copy link
Collaborator

@mrtineide : CI looks good, could you please fix the merge conflict and update the PR. Then we can merge it.

davidrohr
davidrohr previously approved these changes Jul 18, 2025
@mrtineide mrtineide force-pushed the change-namespace-in-headers branch from 284d96c to a39666f Compare July 18, 2025 15:08
The header TJAlienCredentials.h polluted the global namespace, included usually with CCDB
or something related.

Many source files in O2 took advantage of this.
This commit prepares for the removal of the polluted namespace.
The libraries/repo with TJAlienCredentials is JAliEn-ROOT and libjalieno2.
The problem was first noticed by @vkucera.
@mrtineide mrtineide force-pushed the change-namespace-in-headers branch from a39666f to c025018 Compare July 18, 2025 15:59
@ktf ktf merged commit 51d4f86 into AliceO2Group:dev Jul 18, 2025
11 of 12 checks passed
@ktf
Copy link
Member

ktf commented Jul 18, 2025

Thank you!

@vkucera
Copy link
Collaborator

vkucera commented Jul 19, 2025

Thanks a lot, @mrtineide !

@mrtineide mrtineide deleted the change-namespace-in-headers branch July 21, 2025 06:53
mrtineide added a commit to mrtineide/O2Physics that referenced this pull request Aug 1, 2025
The header TJAlienCredentials.h polluted the global namespace, included usually with CCDB
or something related.

See AliceO2Group/AliceO2#14524
This commit prepares for the removal of the polluted namespace.
The libraries/repo with TJAlienCredentials is JAliEn-ROOT and libjalieno2.
The problem was first noticed by @vkucera.
mrtineide added a commit to mrtineide/QualityControl that referenced this pull request Aug 1, 2025
The header TJAlienCredentials.h polluted the global namespace, included usually with CCDB
or something related.

See AliceO2Group/AliceO2#14524 for more background.
This commit prepares for the removal of the polluted namespace.
The libraries/repo with TJAlienCredentials is JAliEn-ROOT and libjalieno2.
The problem was first noticed by @vkucera.
knopers8 added a commit to AliceO2Group/QualityControl that referenced this pull request Aug 6, 2025
* Add fully qualified names for std::string and std::map

The header TJAlienCredentials.h polluted the global namespace, included usually with CCDB
or something related.

See AliceO2Group/AliceO2#14524 for more background.
This commit prepares for the removal of the polluted namespace.
The libraries/repo with TJAlienCredentials is JAliEn-ROOT and libjalieno2.
The problem was first noticed by @vkucera.

* fix clang-format

---------

Co-authored-by: Piotr Konopka <piotr.jan.konopka@cern.ch>
mrtineide added a commit to mrtineide/alidist that referenced this pull request Aug 11, 2025
mrtineide added a commit to mrtineide/alidist that referenced this pull request Aug 12, 2025
mrtineide added a commit to mrtineide/AliceO2 that referenced this pull request Aug 13, 2025
When working on AliceO2Group#14524 the code
that needed to be changed came most likely from the
README.md and its code example. So with this change
now any future copy-paste will also have std::.
sawenzel pushed a commit that referenced this pull request Aug 13, 2025
When working on #14524 the code
that needed to be changed came most likely from the
README.md and its code example. So with this change
now any future copy-paste will also have std::.
ktf pushed a commit to alisw/alidist that referenced this pull request Aug 27, 2025
* Bump JAliEn-ROOT to tag 0.7.15

For more details about the change look at:
GitHub: AliceO2Group/AliceO2#14524
GitLab: https://gitlab.cern.ch/jalien/jalien-root/-/merge_requests/88

* Bump libjalienO2 to tag 0.1.5

For more details about the change look at:
GitHub: AliceO2Group/AliceO2#14524
GitLab: https://gitlab.cern.ch/jalien/libjalieno2/-/merge_requests/3
mhemmer-cern pushed a commit to mhemmer-cern/AliceO2 that referenced this pull request Sep 9, 2025
When working on AliceO2Group#14524 the code
that needed to be changed came most likely from the
README.md and its code example. So with this change
now any future copy-paste will also have std::.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants