From 8357275bf20119dab564819b41d2beb3c29bbf50 Mon Sep 17 00:00:00 2001 From: shahoian Date: Mon, 23 Jun 2025 15:27:53 +0200 Subject: [PATCH] Move bulk of the code to cxx to not expose extra headers --- .../Detectors/ITSMFT/common/CMakeLists.txt | 9 +- .../include/DataFormatsITSMFT/TimeDeadMap.h | 95 ++--------------- .../ITSMFT/common/src/TimeDeadMap.cxx | 100 ++++++++++++++++++ 3 files changed, 113 insertions(+), 91 deletions(-) create mode 100644 DataFormats/Detectors/ITSMFT/common/src/TimeDeadMap.cxx diff --git a/DataFormats/Detectors/ITSMFT/common/CMakeLists.txt b/DataFormats/Detectors/ITSMFT/common/CMakeLists.txt index 62fc09ffcad00..96d376526a1a4 100644 --- a/DataFormats/Detectors/ITSMFT/common/CMakeLists.txt +++ b/DataFormats/Detectors/ITSMFT/common/CMakeLists.txt @@ -18,6 +18,7 @@ o2_add_library(DataFormatsITSMFT src/ClusterPattern.cxx src/ClusterTopology.cxx src/TopologyDictionary.cxx + src/TimeDeadMap.cxx src/CTF.cxx PUBLIC_LINK_LIBRARIES O2::ITSMFTBase O2::ReconstructionDataFormats @@ -25,10 +26,10 @@ o2_add_library(DataFormatsITSMFT o2_target_root_dictionary(DataFormatsITSMFT HEADERS include/DataFormatsITSMFT/ROFRecord.h - include/DataFormatsITSMFT/Digit.h - include/DataFormatsITSMFT/GBTCalibData.h - include/DataFormatsITSMFT/NoiseMap.h - include/DataFormatsITSMFT/TimeDeadMap.h + include/DataFormatsITSMFT/Digit.h + include/DataFormatsITSMFT/GBTCalibData.h + include/DataFormatsITSMFT/NoiseMap.h + include/DataFormatsITSMFT/TimeDeadMap.h include/DataFormatsITSMFT/Cluster.h include/DataFormatsITSMFT/CompCluster.h include/DataFormatsITSMFT/ClusterPattern.h diff --git a/DataFormats/Detectors/ITSMFT/common/include/DataFormatsITSMFT/TimeDeadMap.h b/DataFormats/Detectors/ITSMFT/common/include/DataFormatsITSMFT/TimeDeadMap.h index a0b214f705d7c..5a93cbb712931 100644 --- a/DataFormats/Detectors/ITSMFT/common/include/DataFormatsITSMFT/TimeDeadMap.h +++ b/DataFormats/Detectors/ITSMFT/common/include/DataFormatsITSMFT/TimeDeadMap.h @@ -15,8 +15,6 @@ #define ALICEO2_ITSMFT_TIMEDEADMAP_H #include "Rtypes.h" -#include "DetectorsCommonDataFormats/DetID.h" -#include #include #include @@ -26,6 +24,8 @@ namespace o2 namespace itsmft { +class NoiseMap; + class TimeDeadMap { public: @@ -56,96 +56,17 @@ class TimeDeadMap mStaticDeadMap.clear(); } - void decodeMap(o2::itsmft::NoiseMap& noisemap) - { // for static part only - if (mMAP_VERSION == "3") { - LOG(error) << "Trying to decode static part of deadmap version " << mMAP_VERSION << ". Not implemented, doing nothing."; - return; - } - for (int iel = 0; iel < mStaticDeadMap.size(); iel++) { - uint16_t w = mStaticDeadMap[iel]; - noisemap.maskFullChip(w & 0x7FFF); - if (w & 0x8000) { - for (int w2 = (w & 0x7FFF) + 1; w2 < mStaticDeadMap.at(iel + 1); w2++) { - noisemap.maskFullChip(w2); - } - } - } - } - - void decodeMap(unsigned long orbit, o2::itsmft::NoiseMap& noisemap, bool includeStaticMap = true, long orbitGapAllowed = 330000) - { // for time-dependent and (optionally) static part. Use orbitGapAllowed = -1 to ignore check on orbit difference - - if (mMAP_VERSION != "3" && mMAP_VERSION != "4") { - LOG(error) << "Trying to decode time-dependent deadmap version " << mMAP_VERSION << ". Not implemented, doing nothing."; - return; - } - - if (mEvolvingDeadMap.empty()) { - LOG(warning) << "Time-dependent dead map is empty. Doing nothing."; - return; - } - - std::vector closestVec; - long dT = getMapAtOrbit(orbit, closestVec); - - if (orbitGapAllowed >= 0 && std::abs(dT) > orbitGapAllowed) { - LOG(warning) << "Requested orbit " << orbit << ", found " << orbit - dT << ". Orbit gap is too high, skipping time-dependent map."; - closestVec.clear(); - } - - // add static part if requested. something may be masked twice - if (includeStaticMap && mMAP_VERSION != "3") { - closestVec.insert(closestVec.end(), mStaticDeadMap.begin(), mStaticDeadMap.end()); - } - - // vector encoding: if 1<<15 = 0x8000 is set, the word encodes the first element of a range, with mask (1<<15)-1 = 0x7FFF. The last element of the range is the next in the vector. - - for (int iel = 0; iel < closestVec.size(); iel++) { - uint16_t w = closestVec.at(iel); - noisemap.maskFullChip(w & 0x7FFF); - if (w & 0x8000) { - for (int w2 = (w & 0x7FFF) + 1; w2 < closestVec.at(iel + 1); w2++) { - noisemap.maskFullChip(w2); - } - } - } - }; - + void decodeMap(NoiseMap& noisemap) const; + void decodeMap(unsigned long orbit, o2::itsmft::NoiseMap& noisemap, bool includeStaticMap = true, long orbitGapAllowed = 330000) const; std::string getMapVersion() const { return mMAP_VERSION; }; unsigned long getEvolvingMapSize() const { return mEvolvingDeadMap.size(); }; - - std::vector getEvolvingMapKeys() - { - std::vector keys; - std::transform(mEvolvingDeadMap.begin(), mEvolvingDeadMap.end(), std::back_inserter(keys), - [](const auto& O) { return O.first; }); - return keys; - } - - void getStaticMap(std::vector& mmap) { mmap = mStaticDeadMap; }; - - long getMapAtOrbit(unsigned long orbit, std::vector& mmap) - { // fills mmap and returns requested_orbit - found_orbit. Found orbit is the highest key lower or equal to the requested one - if (mEvolvingDeadMap.empty()) { - LOG(warning) << "Requested orbit " << orbit << "from an empty time-dependent map. Doing nothing"; - return (long)orbit; - } - auto closest = mEvolvingDeadMap.upper_bound(orbit); - if (closest != mEvolvingDeadMap.begin()) { - --closest; - mmap = closest->second; - return (long)orbit - closest->first; - } else { - mmap = mEvolvingDeadMap.begin()->second; - return (long)(orbit)-mEvolvingDeadMap.begin()->first; - } - } - + std::vector getEvolvingMapKeys() const; + void getStaticMap(std::vector& mmap) const { mmap = mStaticDeadMap; }; + long getMapAtOrbit(unsigned long orbit, std::vector& mmap) const; void setMapVersion(std::string version) { mMAP_VERSION = version; }; - bool isDefault() { return mIsDefaultObject; }; + bool isDefault() const { return mIsDefaultObject; }; void setAsDefault(bool isdef = true) { mIsDefaultObject = isdef; }; private: diff --git a/DataFormats/Detectors/ITSMFT/common/src/TimeDeadMap.cxx b/DataFormats/Detectors/ITSMFT/common/src/TimeDeadMap.cxx new file mode 100644 index 0000000000000..e3df8e7f91f86 --- /dev/null +++ b/DataFormats/Detectors/ITSMFT/common/src/TimeDeadMap.cxx @@ -0,0 +1,100 @@ +// 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. + +/// \file TimeDeadMap.cxx +/// \brief Implementation of the time-dependent map + +#include "DataFormatsITSMFT/TimeDeadMap.h" +#include "DataFormatsITSMFT/NoiseMap.h" +#include "Framework/Logger.h" + +using namespace o2::itsmft; + +void TimeDeadMap::decodeMap(o2::itsmft::NoiseMap& noisemap) const +{ // for static part only + if (mMAP_VERSION == "3") { + LOG(error) << "Trying to decode static part of deadmap version " << mMAP_VERSION << ". Not implemented, doing nothing."; + return; + } + for (int iel = 0; iel < mStaticDeadMap.size(); iel++) { + uint16_t w = mStaticDeadMap[iel]; + noisemap.maskFullChip(w & 0x7FFF); + if (w & 0x8000) { + for (int w2 = (w & 0x7FFF) + 1; w2 < mStaticDeadMap.at(iel + 1); w2++) { + noisemap.maskFullChip(w2); + } + } + } +} + +void TimeDeadMap::decodeMap(unsigned long orbit, o2::itsmft::NoiseMap& noisemap, bool includeStaticMap, long orbitGapAllowed) const +{ // for time-dependent and (optionally) static part. Use orbitGapAllowed = -1 to ignore check on orbit difference + + if (mMAP_VERSION != "3" && mMAP_VERSION != "4") { + LOG(error) << "Trying to decode time-dependent deadmap version " << mMAP_VERSION << ". Not implemented, doing nothing."; + return; + } + + if (mEvolvingDeadMap.empty()) { + LOG(warning) << "Time-dependent dead map is empty. Doing nothing."; + return; + } + + std::vector closestVec; + long dT = getMapAtOrbit(orbit, closestVec); + + if (orbitGapAllowed >= 0 && std::abs(dT) > orbitGapAllowed) { + LOG(warning) << "Requested orbit " << orbit << ", found " << orbit - dT << ". Orbit gap is too high, skipping time-dependent map."; + closestVec.clear(); + } + + // add static part if requested. something may be masked twice + if (includeStaticMap && mMAP_VERSION != "3") { + closestVec.insert(closestVec.end(), mStaticDeadMap.begin(), mStaticDeadMap.end()); + } + + // vector encoding: if 1<<15 = 0x8000 is set, the word encodes the first element of a range, with mask (1<<15)-1 = 0x7FFF. The last element of the range is the next in the vector. + + for (int iel = 0; iel < closestVec.size(); iel++) { + uint16_t w = closestVec.at(iel); + noisemap.maskFullChip(w & 0x7FFF); + if (w & 0x8000) { + for (int w2 = (w & 0x7FFF) + 1; w2 < closestVec.at(iel + 1); w2++) { + noisemap.maskFullChip(w2); + } + } + } +} + +std::vector TimeDeadMap::getEvolvingMapKeys() const +{ + std::vector keys; + std::transform(mEvolvingDeadMap.begin(), mEvolvingDeadMap.end(), std::back_inserter(keys), + [](const auto& O) { return O.first; }); + return keys; +} + +long TimeDeadMap::getMapAtOrbit(unsigned long orbit, std::vector& mmap) const +{ // fills mmap and returns requested_orbit - found_orbit. Found orbit is the highest key lower or equal to the requested one + if (mEvolvingDeadMap.empty()) { + LOG(warning) << "Requested orbit " << orbit << "from an empty time-dependent map. Doing nothing"; + return (long)orbit; + } + auto closest = mEvolvingDeadMap.upper_bound(orbit); + if (closest != mEvolvingDeadMap.begin()) { + --closest; + mmap = closest->second; + return (long)orbit - closest->first; + } else { + mmap = mEvolvingDeadMap.begin()->second; + return (long)(orbit)-mEvolvingDeadMap.begin()->first; + } +}