From 2a92e5e191b8db5feb74d87e0fd9711cd2c48b04 Mon Sep 17 00:00:00 2001 From: shahoian Date: Fri, 13 Dec 2024 16:24:35 +0100 Subject: [PATCH] Use O2LongInt aliased to long int instead of int64_t in persistent objects with pair<...> This is to make readable on the MacOS the CCDB objects with pair (stored as pair). A static_assert is added to ensure that the long int is at least 8 bytes long. --- .../include/DataFormatsFIT/DCSDPValues.h | 9 ++-- .../GRPCalibration/GRPDCSDPsProcessor.h | 51 ++++++++++--------- .../calibration/src/GRPDCSDPsProcessor.cxx | 10 ++-- .../include/MFTCondition/MFTDCSProcessor.h | 15 +++--- .../include/TOFCalibration/TOFDCSProcessor.h | 15 +++--- .../calib/include/ZDCCalib/ZDCDCSProcessor.h | 9 ++-- Framework/Foundation/CMakeLists.txt | 1 + .../Foundation/include/Framework/O2LongInt.h | 32 ++++++++++++ Framework/Foundation/src/O2LongInt.cxx | 12 +++++ 9 files changed, 102 insertions(+), 52 deletions(-) create mode 100644 Framework/Foundation/include/Framework/O2LongInt.h create mode 100644 Framework/Foundation/src/O2LongInt.cxx diff --git a/DataFormats/Detectors/FIT/common/include/DataFormatsFIT/DCSDPValues.h b/DataFormats/Detectors/FIT/common/include/DataFormatsFIT/DCSDPValues.h index 26e1969fca968..97bbe982e6aac 100644 --- a/DataFormats/Detectors/FIT/common/include/DataFormatsFIT/DCSDPValues.h +++ b/DataFormats/Detectors/FIT/common/include/DataFormatsFIT/DCSDPValues.h @@ -14,22 +14,23 @@ #include #include "Framework/Logger.h" +#include "Framework/O2LongInt.h" namespace o2 { namespace fit { struct DCSDPValues { - std::vector> values; + std::vector> values; DCSDPValues() { - values = std::vector>(); + values = std::vector>(); } void add(uint64_t timestamp, int64_t value) { - values.push_back(std::pair(timestamp, value)); + values.push_back(std::pair(timestamp, value)); } bool empty() @@ -63,4 +64,4 @@ struct DCSDPValues { } // namespace fit } // namespace o2 -#endif \ No newline at end of file +#endif diff --git a/Detectors/GRP/calibration/include/GRPCalibration/GRPDCSDPsProcessor.h b/Detectors/GRP/calibration/include/GRPCalibration/GRPDCSDPsProcessor.h index 98075051356e7..5043f36ef1433 100644 --- a/Detectors/GRP/calibration/include/GRPCalibration/GRPDCSDPsProcessor.h +++ b/Detectors/GRP/calibration/include/GRPCalibration/GRPDCSDPsProcessor.h @@ -16,6 +16,7 @@ #include #include #include "Framework/Logger.h" +#include "Framework/O2LongInt.h" #include "DetectorsDCS/DataPointCompositeObject.h" #include "DetectorsDCS/DataPointIdentifier.h" #include "DetectorsDCS/DataPointValue.h" @@ -37,11 +38,11 @@ using DPID = o2::dcs::DataPointIdentifier; using DPVAL = o2::dcs::DataPointValue; using DPCOM = o2::dcs::DataPointCompositeObject; -inline unsigned long llu2lu(std::uint64_t v) { return (unsigned long)v; } +inline O2LongUInt llu2lu(std::uint64_t v) { return (O2LongUInt)v; } struct GRPEnvVariables { - std::unordered_map>> mEnvVars; + std::unordered_map>> mEnvVars; size_t totalEntries() const { size_t s = 0; @@ -60,7 +61,7 @@ struct GRPEnvVariables { } } - ClassDefNV(GRPEnvVariables, 1); + ClassDefNV(GRPEnvVariables, 2); }; struct MagFieldHelper { @@ -122,7 +123,7 @@ struct MagFieldHelper { struct GRPCollimators { - std::unordered_map>> mCollimators; + std::unordered_map>> mCollimators; size_t totalEntries() const { size_t s = 0; @@ -141,7 +142,7 @@ struct GRPCollimators { } } - ClassDefNV(GRPCollimators, 1); + ClassDefNV(GRPCollimators, 2); }; struct GRPLHCInfo { @@ -191,19 +192,19 @@ struct GRPLHCInfo { static constexpr std::string_view lhcStringAliases[NLHCStringAliases] = {"ALI_Lumi_Source_Name", "BEAM_MODE", "MACHINE_MODE"}; static constexpr int nAliasesLHC = (int)NCollimatorAliases + (int)NBeamAliases + (int)NBkgAliases + (int)NBPTXAliases + (int)NBPTXPhaseAliases + (int)NBPTXPhaseRMSAliases + (int)NBPTXPhaseShiftAliases + (int)NLumiAliases + (int)NLHCStringAliases; - std::array>, 2> mIntensityBeam; - std::array>, 3> mBackground; - std::vector> mInstLumi; - std::vector> mBPTXdeltaT; - std::vector> mBPTXdeltaTRMS; - std::array>, 2> mBPTXPhase; - std::array>, 2> mBPTXPhaseRMS; - std::array>, 2> mBPTXPhaseShift; - std::pair mLumiSource; // only one value per object: when there is a change, a new object is stored - std::pair mMachineMode; // only one value per object: when there is a change, a new object is stored - std::pair mBeamMode; // only one value per object: when there is a change, a new object is stored - - void resetAndKeepLastVector(std::vector>& vect) + std::array>, 2> mIntensityBeam; + std::array>, 3> mBackground; + std::vector> mInstLumi; + std::vector> mBPTXdeltaT; + std::vector> mBPTXdeltaTRMS; + std::array>, 2> mBPTXPhase; + std::array>, 2> mBPTXPhaseRMS; + std::array>, 2> mBPTXPhaseShift; + std::pair mLumiSource; // only one value per object: when there is a change, a new object is stored + std::pair mMachineMode; // only one value per object: when there is a change, a new object is stored + std::pair mBeamMode; // only one value per object: when there is a change, a new object is stored + + void resetAndKeepLastVector(std::vector>& vect) { // always check that the size is > 0 (--> begin != end) for all vectors if (vect.begin() != vect.end()) { @@ -291,16 +292,16 @@ class GRPDCSDPsProcessor void init(const std::vector& pids); int process(const gsl::span dps); int processDP(const DPCOM& dpcom); - uint64_t processFlags(uint64_t flag, const char* pid) { return 0; } // for now it is not really implemented + O2LongUInt processFlags(O2LongUInt flag, const char* pid) { return 0; } // for now it is not really implemented bool processCollimators(const DPCOM& dpcom); bool processEnvVar(const DPCOM& dpcom); - bool processPairD(const DPCOM& dpcom, const std::string& alias, std::unordered_map>>& mapToUpdate); - bool processPairS(const DPCOM& dpcom, const std::string& alias, std::pair& p, bool& flag); - bool compareToLatest(std::pair& p, double val); + bool processPairD(const DPCOM& dpcom, const std::string& alias, std::unordered_map>>& mapToUpdate); + bool processPairS(const DPCOM& dpcom, const std::string& alias, std::pair& p, bool& flag); + bool compareToLatest(std::pair& p, double val); bool processLHCIFDPs(const DPCOM& dpcom); void resetAndKeepLastLHCIFDPs() { mLHCInfo.resetAndKeepLast(); } - void resetAndKeepLast(std::unordered_map>>& mapToReset) + void resetAndKeepLast(std::unordered_map>>& mapToReset) { // keep only the latest measurement for (auto& el : mapToReset) { @@ -366,8 +367,8 @@ class GRPDCSDPsProcessor void useVerboseMode() { mVerbose = true; } void clearVectors() { mClearVectors = true; } - void printVectorInfo(const std::vector>& vect, bool afterUpdate); - void updateVector(const DPID& dpid, std::vector>& vect, std::string alias, uint64_t timestamp, double val); + void printVectorInfo(const std::vector>& vect, bool afterUpdate); + void updateVector(const DPID& dpid, std::vector>& vect, std::string alias, O2LongUInt timestamp, double val); private: std::unordered_map mPids; // contains all PIDs for the processor, the bool diff --git a/Detectors/GRP/calibration/src/GRPDCSDPsProcessor.cxx b/Detectors/GRP/calibration/src/GRPDCSDPsProcessor.cxx index f3f96794095d7..c8fa7c2bff38b 100644 --- a/Detectors/GRP/calibration/src/GRPDCSDPsProcessor.cxx +++ b/Detectors/GRP/calibration/src/GRPDCSDPsProcessor.cxx @@ -185,7 +185,7 @@ bool GRPDCSDPsProcessor::processEnvVar(const DPCOM& dpcom) } //______________________________________________________________________ -bool GRPDCSDPsProcessor::processPairD(const DPCOM& dpcom, const std::string& alias, std::unordered_map>>& mapToUpdate) +bool GRPDCSDPsProcessor::processPairD(const DPCOM& dpcom, const std::string& alias, std::unordered_map>>& mapToUpdate) { // function to process Data Points that is stored in a pair @@ -207,7 +207,7 @@ bool GRPDCSDPsProcessor::processPairD(const DPCOM& dpcom, const std::string& ali } //______________________________________________________________________ -bool GRPDCSDPsProcessor::processPairS(const DPCOM& dpcom, const std::string& alias, std::pair& p, bool& flag) +bool GRPDCSDPsProcessor::processPairS(const DPCOM& dpcom, const std::string& alias, std::pair& p, bool& flag) { // function to process string Data Points that is stored in a pair @@ -237,7 +237,7 @@ bool GRPDCSDPsProcessor::processPairS(const DPCOM& dpcom, const std::string& ali //______________________________________________________________________ -bool GRPDCSDPsProcessor::compareToLatest(std::pair& p, double val) +bool GRPDCSDPsProcessor::compareToLatest(std::pair& p, double val) { // check if the content of the pair should be updated @@ -408,7 +408,7 @@ void GRPDCSDPsProcessor::updateCollimatorsCCDB() //______________________________________________________________________ -void GRPDCSDPsProcessor::printVectorInfo(const std::vector>& vect, bool afterUpdate) +void GRPDCSDPsProcessor::printVectorInfo(const std::vector>& vect, bool afterUpdate) { std::string stage = afterUpdate ? "after update" : "before update"; @@ -422,7 +422,7 @@ void GRPDCSDPsProcessor::printVectorInfo(const std::vector>& vect, std::string alias, uint64_t timestamp, double val) +void GRPDCSDPsProcessor::updateVector(const DPID& dpid, std::vector>& vect, std::string alias, O2LongUInt timestamp, double val) { printVectorInfo(vect, 0); bool updateFlag = false; diff --git a/Detectors/ITSMFT/MFT/condition/include/MFTCondition/MFTDCSProcessor.h b/Detectors/ITSMFT/MFT/condition/include/MFTCondition/MFTDCSProcessor.h index 4fb411c0b73b5..e5bcf07ee083e 100644 --- a/Detectors/ITSMFT/MFT/condition/include/MFTCondition/MFTDCSProcessor.h +++ b/Detectors/ITSMFT/MFT/condition/include/MFTCondition/MFTDCSProcessor.h @@ -22,6 +22,7 @@ #include "DetectorsDCS/DataPointIdentifier.h" #include "DetectorsDCS/DataPointValue.h" #include "DetectorsDCS/DeliveryType.h" +#include "Framework/O2LongInt.h" #include "CCDB/CcdbObjectInfo.h" #include "CommonUtils/MemFileHelper.h" #include "CCDB/CcdbApi.h" @@ -40,13 +41,13 @@ using DPCOM = o2::dcs::DataPointCompositeObject; struct MFTDCSinfo { - std::pair firstValue; // first value seen by the MFT DCS processor - std::pair lastValue; // last value seen by the MFT DCS processor - std::pair meanValue; // mean value seen by the MFT DCS processor - std::pair stddevValue; // standard deviation value seen by the MFT DCS processor - std::pair midValue; // mid value seen by the MFT DCS processor - std::pair maxChange; // maximum variation seen by the MFT DCS processor - std::pair summary; // number of entries by the MFT DCS processor + std::pair firstValue; // first value seen by the MFT DCS processor + std::pair lastValue; // last value seen by the MFT DCS processor + std::pair meanValue; // mean value seen by the MFT DCS processor + std::pair stddevValue; // standard deviation value seen by the MFT DCS processor + std::pair midValue; // mid value seen by the MFT DCS processor + std::pair maxChange; // maximum variation seen by the MFT DCS processor + std::pair summary; // number of entries by the MFT DCS processor MFTDCSinfo() { diff --git a/Detectors/TOF/calibration/include/TOFCalibration/TOFDCSProcessor.h b/Detectors/TOF/calibration/include/TOFCalibration/TOFDCSProcessor.h index 6279565f4ef63..bb7e1fc7f5971 100644 --- a/Detectors/TOF/calibration/include/TOFCalibration/TOFDCSProcessor.h +++ b/Detectors/TOF/calibration/include/TOFCalibration/TOFDCSProcessor.h @@ -18,6 +18,7 @@ #include #include #include "Framework/Logger.h" +#include "Framework/O2LongInt.h" #include "DetectorsDCS/DataPointCompositeObject.h" #include "DetectorsDCS/DataPointIdentifier.h" #include "DetectorsDCS/DataPointValue.h" @@ -40,19 +41,19 @@ using DPVAL = o2::dcs::DataPointValue; using DPCOM = o2::dcs::DataPointCompositeObject; struct TOFDCSinfo { - std::pair firstValue; // first value seen by the TOF DCS processor - std::pair lastValue; // last value seen by the TOF DCS processor - std::pair midValue; // mid value seen by the TOF DCS processor - std::pair, double> maxChange; // maximum variation seen by the TOF DCS processor (previous - subsequent value) - std::pair minValue; // smallest measurement seen by the TOF DCS processor - std::pair maxValue; // largest measurement seen by the TOF DCS processor + std::pair firstValue; // first value seen by the TOF DCS processor + std::pair lastValue; // last value seen by the TOF DCS processor + std::pair midValue; // mid value seen by the TOF DCS processor + std::pair, double> maxChange; // maximum variation seen by the TOF DCS processor (previous - subsequent value) + std::pair minValue; // smallest measurement seen by the TOF DCS processor + std::pair maxValue; // largest measurement seen by the TOF DCS processor bool updated = false; TOFDCSinfo() { firstValue = std::make_pair(0, -999999999); lastValue = std::make_pair(0, -999999999); midValue = std::make_pair(0, -999999999); - std::array atmp = {0, 0}; + std::array atmp = {0, 0}; maxChange = std::make_pair(atmp, 0); minValue = std::make_pair(0, 99999999999); maxValue = std::make_pair(0, -99999999999); diff --git a/Detectors/ZDC/calib/include/ZDCCalib/ZDCDCSProcessor.h b/Detectors/ZDC/calib/include/ZDCCalib/ZDCDCSProcessor.h index 7f7bb40414781..ee5367376356f 100644 --- a/Detectors/ZDC/calib/include/ZDCCalib/ZDCDCSProcessor.h +++ b/Detectors/ZDC/calib/include/ZDCCalib/ZDCDCSProcessor.h @@ -15,6 +15,7 @@ #include #include #include "Framework/Logger.h" +#include "Framework/O2LongInt.h" #include "DetectorsDCS/DataPointCompositeObject.h" #include "DetectorsDCS/DataPointIdentifier.h" #include "DetectorsDCS/DataPointValue.h" @@ -39,10 +40,10 @@ using DPVAL = o2::dcs::DataPointValue; using DPCOM = o2::dcs::DataPointCompositeObject; struct ZDCDCSinfo { - std::pair firstValue; // first value seen by the ZDC DCS processor - std::pair lastValue; // last value seen by the ZDC DCS processor - std::pair midValue; // mid value seen by the ZDC DCS processor - std::pair maxChange; // maximum variation seen by the ZDC DCS processor + std::pair firstValue; // first value seen by the ZDC DCS processor + std::pair lastValue; // last value seen by the ZDC DCS processor + std::pair midValue; // mid value seen by the ZDC DCS processor + std::pair maxChange; // maximum variation seen by the ZDC DCS processor ZDCDCSinfo() { diff --git a/Framework/Foundation/CMakeLists.txt b/Framework/Foundation/CMakeLists.txt index 1cffe7f0487ff..65a43073ef9d8 100644 --- a/Framework/Foundation/CMakeLists.txt +++ b/Framework/Foundation/CMakeLists.txt @@ -17,6 +17,7 @@ o2_add_library(FrameworkFoundation SOURCES src/RuntimeError.cxx src/Signpost.cxx src/BacktraceHelpers.cxx + src/O2LongInt.cxx TARGETVARNAME targetName PUBLIC_LINK_LIBRARIES O2::FrameworkFoundation3rdparty ) diff --git a/Framework/Foundation/include/Framework/O2LongInt.h b/Framework/Foundation/include/Framework/O2LongInt.h new file mode 100644 index 0000000000000..29b5c50b29ad5 --- /dev/null +++ b/Framework/Foundation/include/Framework/O2LongInt.h @@ -0,0 +1,32 @@ +// 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. + +/* + Due to the root bug https://github.com/root-project/root/issues/17216 + we cannot safely use std::pair since it is saved in the + root file as long int, on the MacOS considered to be different from int64_t or + UInt64_t. Thererefor, we define out own O2LongInt and make sure that it is at + least 8 bytes long. +*/ + +#ifndef O2_FRAMEWORK_O2LONGINT_H_ +#define O2_FRAMEWORK_O2LONGINT_H_ + +namespace o2 +{ + +static_assert(sizeof(long int) >= 8, "long int on this machine is < 8 bytes."); + +using O2LongInt = long int; +using O2LongUInt = unsigned long int; + +} // namespace o2 +#endif // O2_FRAMEWORK_O2LONGINT_H_ diff --git a/Framework/Foundation/src/O2LongInt.cxx b/Framework/Foundation/src/O2LongInt.cxx new file mode 100644 index 0000000000000..2b5906180b3ef --- /dev/null +++ b/Framework/Foundation/src/O2LongInt.cxx @@ -0,0 +1,12 @@ +// 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 "Framework/O2LongInt.h"