Repository navigation
Refactor/shared lookuptable #15667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
spulawsk
wants to merge
3
commits into
AliceO2Group:dev
Choose a base branch
from
spulawsk:refactor/shared-lookuptable
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor/shared lookuptable #15667
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
DataFormats/Detectors/FIT/FT0/include/DataFormatsFT0/PMLookupTable.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
| // See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
| // All rights not expressly granted are reserved. | ||
| // | ||
| // This software is distributed under the terms of the GNU General Public | ||
| // License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
| // | ||
| // In applying this license CERN does not waive the privileges and immunities | ||
| // granted to it by virtue of its status as an Intergovernmental Organization | ||
| // or submit itself to any jurisdiction. | ||
|
|
||
| #ifndef O2_FT0_PMLOOKUPTABLE_H_ | ||
| #define O2_FT0_PMLOOKUPTABLE_H_ | ||
|
|
||
| #include <array> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <map> | ||
|
|
||
| #include "FT0Base/Constants.h" | ||
|
|
||
| namespace o2::ft0 | ||
| { | ||
|
|
||
| /// Cached mapping between FT0 channels and PM modules. | ||
| /// | ||
| /// The mapping is constructed once from SingleLUT and can then be reused by | ||
| /// digitization, reconstruction, trigger and QA code without reparsing the LUT. | ||
| class PMLookupTable | ||
| { | ||
| public: | ||
| using ChannelID = uint16_t; | ||
| using PMHash = uint8_t; | ||
| using PMMap = std::map<PMHash, bool>; // PM hash -> true for A side, false for C side | ||
|
|
||
| /// Return the process-wide immutable lookup table. | ||
| static const PMLookupTable& Instance(); | ||
|
|
||
| /// Return the PM hash assigned to a detector channel. | ||
| PMHash getPMHash(ChannelID channelID) const; | ||
|
|
||
| /// Return true for an A-side PM and false for a C-side PM. | ||
| bool isASide(PMHash pmHash) const; | ||
|
|
||
| /// Return all PM hashes and their sides. TCM entries are not included. | ||
| const PMMap& getPMs() const noexcept { return mPMHash2IsASide; } | ||
|
|
||
| private: | ||
| PMLookupTable(); | ||
|
|
||
| std::array<PMHash, Constants::sNCHANNELS_PM> mChannelID2PMHash{}; | ||
| std::array<bool, Constants::sNCHANNELS_PM> mChannelIsMapped{}; | ||
| PMMap mPMHash2IsASide; | ||
| }; | ||
|
|
||
| } // namespace o2::ft0 | ||
|
|
||
| #endif // O2_FT0_PMLOOKUPTABLE_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
| // See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
| // All rights not expressly granted are reserved. | ||
| // | ||
| // This software is distributed under the terms of the GNU General Public | ||
| // License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
| // | ||
| // In applying this license CERN does not waive the privileges and immunities | ||
| // granted to it by virtue of its status as an Intergovernmental Organization | ||
| // or submit itself to any jurisdiction. | ||
|
|
||
| #include "DataFormatsFT0/PMLookupTable.h" | ||
|
|
||
| #include "DataFormatsFT0/LookUpTable.h" | ||
| #include "Framework/Logger.h" | ||
|
|
||
| #include <algorithm> | ||
| #include <charconv> | ||
| #include <map> | ||
| #include <limits> | ||
| #include <string> | ||
| #include <system_error> | ||
|
|
||
| namespace o2::ft0 | ||
| { | ||
|
|
||
| const PMLookupTable& PMLookupTable::Instance() | ||
| { | ||
| static const PMLookupTable table; | ||
| return table; | ||
| } | ||
|
|
||
| PMLookupTable::PMLookupTable() | ||
| { | ||
| std::map<std::string, PMHash> moduleName2Hash; | ||
|
|
||
| auto lut = SingleLUT::Instance().getVecMetadataFEE(); | ||
| std::sort(lut.begin(), lut.end(), [](const auto& lhs, const auto& rhs) { | ||
| return lhs.mModuleName < rhs.mModuleName; | ||
| }); | ||
|
|
||
| unsigned int nextHash = 0; | ||
|
|
||
| for (const auto& entry : lut) { | ||
| const auto& moduleName = entry.mModuleName; | ||
| const auto& moduleType = entry.mModuleType; | ||
| const auto& channelString = entry.mChannelID; | ||
|
|
||
| if (nextHash > static_cast<unsigned int>(std::numeric_limits<PMHash>::max())) { | ||
| LOG(fatal) << "Too many FT0 FEE modules to represent with PMHash"; | ||
| } | ||
|
|
||
| auto [moduleIt, inserted] = moduleName2Hash.emplace(moduleName, static_cast<PMHash>(nextHash)); | ||
|
|
||
| if (inserted) { | ||
| const auto moduleHash = moduleIt->second; | ||
| if (moduleName.find("PMA") != std::string::npos) { | ||
| mPMHash2IsASide.emplace(moduleHash, true); | ||
| } else if (moduleName.find("PMC") != std::string::npos) { | ||
| mPMHash2IsASide.emplace(moduleHash, false); | ||
| } else if (moduleType != "TCM") { | ||
| LOG(fatal) << "Unknown FT0 module in LUT: " << moduleName | ||
| << " (type " << moduleType << ")"; | ||
| } | ||
| ++nextHash; | ||
| } | ||
|
|
||
| int channelID = -1; | ||
| const char* begin = channelString.data(); | ||
| const char* end = begin + channelString.size(); | ||
| const auto [ptr, error] = std::from_chars(begin, end, channelID); | ||
| const bool isNumericChannel = error == std::errc{} && ptr == end; | ||
|
|
||
| if (isNumericChannel) { | ||
| if (channelID < 0 || channelID >= Constants::sNCHANNELS_PM) { | ||
| LOG(fatal) << "Incorrect FT0 LUT entry: channel " << channelString | ||
| << " | module " << moduleName; | ||
| } | ||
|
|
||
| mChannelID2PMHash[channelID] = moduleIt->second; | ||
| mChannelIsMapped[channelID] = true; | ||
| } else if (moduleType != "TCM") { | ||
| LOG(fatal) << "Non-TCM FT0 module without numerical channel ID: channel " | ||
| << channelString << " | module " << moduleName; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| PMLookupTable::PMHash PMLookupTable::getPMHash(ChannelID channelID) const | ||
| { | ||
| if (channelID >= Constants::sNCHANNELS_PM) { | ||
| LOG(fatal) << "FT0 channel ID outside valid range: " << channelID; | ||
| } | ||
| if (!mChannelIsMapped[channelID]) { | ||
| LOG(fatal) << "FT0 channel is not mapped to a PM: " << channelID; | ||
| } | ||
| return mChannelID2PMHash[channelID]; | ||
| } | ||
|
|
||
| bool PMLookupTable::isASide(PMHash pmHash) const | ||
| { | ||
| const auto it = mPMHash2IsASide.find(pmHash); | ||
| if (it == mPMHash2IsASide.end()) { | ||
| LOG(fatal) << "Unknown FT0 PM hash: " << static_cast<unsigned int>(pmHash); | ||
| } | ||
| return it->second; | ||
| } | ||
|
|
||
| } // namespace o2::ft0 | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.