From 382b83797a10725f97ac45b75fc93931ae7ad28b Mon Sep 17 00:00:00 2001 From: Chiara Zampolli Date: Wed, 12 Jan 2022 18:45:09 +0100 Subject: [PATCH 1/2] GRP DCS DP processing --- .../include/DetectorsCalibration/Utils.h | 24 + Detectors/GRP/calibration/CMakeLists.txt | 12 +- .../GRPCalibration/GRPDCSDPsProcessor.h | 268 +++++++++++ .../calibration/src/GRPCalibrationLinkDef.h | 4 + .../calibration/src/GRPDCSDPsProcessor.cxx | 451 ++++++++++++++++++ Detectors/GRP/workflows/CMakeLists.txt | 15 + .../include/GRPWorkflows/GRPDCSDPsSpec.h | 56 +++ Detectors/GRP/workflows/src/GRPDCSDPsSpec.cxx | 247 ++++++++++ .../src/grp-dcs-dps-sim-workflow.cxx | 55 +++ .../workflows/src/grp-dcs-dps-workflow.cxx | 33 ++ .../include/TOFCalibration/TOFDCSProcessor.h | 28 +- .../TOF/calibration/src/TOFDCSProcessor.cxx | 7 +- 12 files changed, 1180 insertions(+), 20 deletions(-) create mode 100644 Detectors/GRP/calibration/include/GRPCalibration/GRPDCSDPsProcessor.h create mode 100644 Detectors/GRP/calibration/src/GRPDCSDPsProcessor.cxx create mode 100644 Detectors/GRP/workflows/include/GRPWorkflows/GRPDCSDPsSpec.h create mode 100644 Detectors/GRP/workflows/src/GRPDCSDPsSpec.cxx create mode 100644 Detectors/GRP/workflows/src/grp-dcs-dps-sim-workflow.cxx create mode 100644 Detectors/GRP/workflows/src/grp-dcs-dps-workflow.cxx diff --git a/Detectors/Calibration/include/DetectorsCalibration/Utils.h b/Detectors/Calibration/include/DetectorsCalibration/Utils.h index 5093d5feda1f6..b9f4793e9ddd3 100644 --- a/Detectors/Calibration/include/DetectorsCalibration/Utils.h +++ b/Detectors/Calibration/include/DetectorsCalibration/Utils.h @@ -22,17 +22,41 @@ #include "Headers/DataHeader.h" #include "CommonUtils/StringUtils.h" #include "CCDB/CCDBTimeStampUtils.h" +#include "CCDB/CcdbObjectInfo.h" +#include "CommonUtils/MemFileHelper.h" +#include "CCDB/CcdbApi.h" namespace o2 { namespace calibration { +using TFType = uint64_t; + struct Utils { static constexpr o2::header::DataOrigin gDataOriginCDBPayload{"CLP"}; // generic DataOrigin for calibrations payload static constexpr o2::header::DataOrigin gDataOriginCDBWrapper{"CLW"}; // generic DataOrigin for calibrations wrapper + template + static void prepareCCDBobjectInfo(T& obj, o2::ccdb::CcdbObjectInfo& info, const std::string& path, TFType tf, + const std::map& md); }; +template +void Utils::prepareCCDBobjectInfo(T& obj, o2::ccdb::CcdbObjectInfo& info, const std::string& path, TFType tf, + const std::map& md) +{ + + // prepare all info to be sent to CCDB for object obj + auto clName = o2::utils::MemFileHelper::getClassName(obj); + auto flName = o2::ccdb::CcdbApi::generateFileName(clName); + info.setPath(path); + info.setObjectType(clName); + info.setFileName(flName); + info.setStartValidityTimestamp(tf); + info.setEndValidityTimestamp(99999999999999); + info.setMetaData(md); +} + } // namespace calibration } // namespace o2 diff --git a/Detectors/GRP/calibration/CMakeLists.txt b/Detectors/GRP/calibration/CMakeLists.txt index db86caabf7273..db87677b61162 100644 --- a/Detectors/GRP/calibration/CMakeLists.txt +++ b/Detectors/GRP/calibration/CMakeLists.txt @@ -12,8 +12,14 @@ o2_add_library(GRPCalibration TARGETVARNAME targetName SOURCES src/LHCIFfileReader.cxx - PUBLIC_LINK_LIBRARIES Microsoft.GSL::GSL - O2::Framework) + src/GRPDCSDPsProcessor.cxx + PUBLIC_LINK_LIBRARIES Microsoft.GSL::GSL + O2::Framework + O2::DetectorsDCS + O2::DetectorsCalibration + O2::CCDB + O2::DataFormatsParameters) o2_target_root_dictionary(GRPCalibration - HEADERS include/GRPCalibration/LHCIFfileReader.h) + HEADERS include/GRPCalibration/LHCIFfileReader.h + include/GRPCalibration/GRPDCSDPsProcessor.h) diff --git a/Detectors/GRP/calibration/include/GRPCalibration/GRPDCSDPsProcessor.h b/Detectors/GRP/calibration/include/GRPCalibration/GRPDCSDPsProcessor.h new file mode 100644 index 0000000000000..2605306dff9b3 --- /dev/null +++ b/Detectors/GRP/calibration/include/GRPCalibration/GRPDCSDPsProcessor.h @@ -0,0 +1,268 @@ +// 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 DETECTOR_GRPDCSDPSPROCESSOR_H_ +#define DETECTOR_GRPDCSDPSPROCESSOR_H_ + +#include +#include +#include +#include "Framework/Logger.h" +#include "DetectorsDCS/DataPointCompositeObject.h" +#include "DetectorsDCS/DataPointIdentifier.h" +#include "DetectorsDCS/DataPointValue.h" +#include "DetectorsDCS/DeliveryType.h" +#include "CCDB/CcdbObjectInfo.h" +#include "CommonUtils/MemFileHelper.h" +#include "CCDB/CcdbApi.h" +#include "DataFormatsParameters/GRPMagField.h" +#include + +/// @brief Class to process GRP DCS data points (B field, environment variables, LHCIF Data Points) + +namespace o2 +{ +namespace grp +{ + +using DPID = o2::dcs::DataPointIdentifier; +using DPVAL = o2::dcs::DataPointValue; +using DPCOM = o2::dcs::DataPointCompositeObject; + +struct GRPEnvVariables { + + std::pair mCavernTemperature; + std::pair mCavernAtmosPressure; + std::pair mSurfaceAtmosPressure; + std::pair mCavernAtmosPressure2; + + GRPEnvVariables() + { + mCavernTemperature = std::make_pair(0, -999999999); + mCavernAtmosPressure = std::make_pair(0, -999999999); + mSurfaceAtmosPressure = std::make_pair(0, -999999999); + mCavernAtmosPressure2 = std::make_pair(0, -999999999); + } + + void print() + { + std::printf("%-30s : timestamp %llu val %.3f\n", "Cavern Temperature", mCavernTemperature.first, mCavernTemperature.second); + std::printf("%-30s : timestamp %llu val %.3f\n", "Cavern Atm Pressure", mCavernAtmosPressure.first, mCavernAtmosPressure.second); + std::printf("%-30s : timestamp %llu val %.3f\n", "Surf Atm Pressure", mSurfaceAtmosPressure.first, mSurfaceAtmosPressure.second); + std::printf("%-30s : timestamp %llu val %.3f\n", "Cavern Atm Pressure 2", mCavernAtmosPressure2.first, mCavernAtmosPressure2.second); + } + + ClassDefNV(GRPEnvVariables, 1); +}; + +struct GRPCollimators { + + std::pair mgap_downstream; + std::pair mgap_upstream; + std::pair mleft_downstream; + std::pair mleft_upstream; + std::pair mright_downstream; + std::pair mright_upstream; + + GRPCollimators() + { + mgap_downstream = std::make_pair(0, -999999999); + mgap_upstream = std::make_pair(0, -999999999); + mleft_downstream = std::make_pair(0, -999999999); + mleft_upstream = std::make_pair(0, -999999999); + mright_downstream = std::make_pair(0, -999999999); + mright_upstream = std::make_pair(0, -999999999); + } + + void print() + { + std::printf("%-60s : timestamp %llu val %.3e\n", "LHC_CollimatorPos_TCLIA_4R2_lvdt_gap_downstream", mgap_downstream.first, mgap_downstream.second); + std::printf("%-60s : timestamp %llu val %.3e\n", "LHC_CollimatorPos_TCLIA_4R2_lvdt_gap_upstream", mgap_upstream.first, mgap_upstream.second); + std::printf("%-60s : timestamp %llu val %.3e\n", "LHC_CollimatorPos_TCLIA_4R2_lvdt_left_downstream", mleft_downstream.first, mleft_downstream.second); + std::printf("%-60s : timestamp %llu val %.3e\n", "LHC_CollimatorPos_TCLIA_4R2_lvdt_left_upstream", mleft_upstream.first, mleft_upstream.second); + std::printf("%-60s : timestamp %llu val %.3e\n", "LHC_CollimatorPos_TCLIA_4R2_lvdt_right_downstream", mright_downstream.first, mright_downstream.second); + std::printf("%-60s : timestamp %llu val %.3e\n", "LHC_CollimatorPos_TCLIA_4R2_lvdt_right_upstream", mright_upstream.first, mright_upstream.second); + } + + ClassDefNV(GRPCollimators, 1); +}; + +struct GRPLHCInfo { + + 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 reset() + { + for (int i = 0; i < 2; ++i) { + mIntensityBeam[i].clear(); + mBPTXPhase[i].clear(); + mBPTXPhaseRMS[i].clear(); + mBPTXPhaseShift[i].clear(); + } + for (int i = 0; i < 3; ++i) { + mBackground[i].clear(); + } + mInstLumi.clear(); + mBPTXdeltaT.clear(); + mBPTXdeltaTRMS.clear(); + } + + void print() + { + char alias[60]; + for (int i = 0; i < 2; ++i) { + std::sprintf(alias, "LHC_IntensityBeam%d_totalIntensity", i + 1); + std::printf("%-30s : n elements %ld\n", alias, mIntensityBeam[i].size()); + for (int iel = 0; iel < mIntensityBeam[i].size(); ++iel) { + std::printf("timestamp %llu val %.3e\n", mIntensityBeam[i].at(iel).first, mIntensityBeam[i].at(iel).second); + } + } + for (int i = 0; i < 3; ++i) { + std::sprintf(alias, "ALI_Background%d", i + 1); + std::printf("%-30s : n elements %ld\n", alias, mBackground[i].size()); + for (int iel = 0; iel < mBackground[i].size(); ++iel) { + std::printf("timestamp %llu val %.3e\n", mBackground[i].at(iel).first, mBackground[i].at(iel).second); + } + } + std::printf("%-30s : n elements %ld\n", "ALI_Lumi_Total_Inst", mInstLumi.size()); + for (int iel = 0; iel < mInstLumi.size(); ++iel) { + std::printf("timestamp %llu val %.3e\n", mInstLumi.at(iel).first, mInstLumi.at(iel).second); + } + std::printf("%-30s : n elements %ld\n", "BPTX_deltaT_B1_B2", mBPTXdeltaT.size()); + for (int iel = 0; iel < mBPTXdeltaT.size(); ++iel) { + std::printf("timestamp %llu val %.3e\n", mBPTXdeltaT.at(iel).first, mBPTXdeltaT.at(iel).second); + } + std::printf("%-30s : n elements %ld\n", "BPTX_deltaTRMS_B1_B2", mBPTXdeltaTRMS.size()); + for (int iel = 0; iel < mBPTXdeltaTRMS.size(); ++iel) { + std::printf("timestamp %llu val %.3e\n", mBPTXdeltaTRMS.at(iel).first, mBPTXdeltaTRMS.at(iel).second); + } + for (int i = 0; i < 2; ++i) { + std::sprintf(alias, "BPTX_Phase_B%d", i + 1); + std::printf("%-30s : n elements %ld\n", alias, mBPTXPhase[i].size()); + for (int iel = 0; iel < mBPTXPhase[i].size(); ++iel) { + std::printf("timestamp %llu val %.3e\n", mBPTXPhase[i].at(iel).first, mBPTXPhase[i].at(iel).second); + } + } + for (int i = 0; i < 2; ++i) { + std::sprintf(alias, "BPTX_PhaseRMS_B%d", i + 1); + std::printf("%-30s : n elements %ld\n", alias, mBPTXPhaseRMS[i].size()); + for (int iel = 0; iel < mBPTXPhaseRMS[i].size(); ++iel) { + std::printf("timestamp %llu val %.3e\n", mBPTXPhaseRMS[i].at(iel).first, mBPTXPhaseRMS[i].at(iel).second); + } + } + for (int i = 0; i < 2; ++i) { + std::sprintf(alias, "BPTX_Phase_Shift_B%d", i + 1); + std::printf("%-30s : n elements %ld\n", alias, mBPTXPhaseShift[i].size()); + for (int iel = 0; iel < mBPTXPhaseShift[i].size(); ++iel) { + std::printf("timestamp %llu val %.3e\n", mBPTXPhaseShift[i].at(iel).first, mBPTXPhaseShift[i].at(iel).second); + } + } + std::printf("%-30s :\n", "ALI_Lumi_Source_Name"); + std::printf("timestamp %llu val %s\n", mLumiSource.first, mLumiSource.second.c_str()); + std::printf("%-30s :\n", "BEAM_MODE"); + std::printf("timestamp %llu val %s\n", mBeamMode.first, mBeamMode.second.c_str()); + std::printf("%-30s :\n", "MACHINE_MODE"); + std::printf("timestamp %llu val %s\n", mMachineMode.first, mMachineMode.second.c_str()); + } + + ClassDefNV(GRPLHCInfo, 1); +}; + +class GRPDCSDPsProcessor +{ + public: + using TFType = uint64_t; + // using CcdbObjectInfo = o2::ccdb::CcdbObjectInfo; + + GRPDCSDPsProcessor() = default; + ~GRPDCSDPsProcessor() = default; + + 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 + void processCollimators(const DPCOM& dpcom); + void processEnvVar(const DPCOM& dpcom); + void processPair(const DPCOM& dpcom, const std::string& alias, std::pair& p, bool& flag); + bool compareAndUpdate(std::pair& p, const DPCOM& dpcom); + bool processLHCIFDPs(const DPCOM& dpcom); + + void resetLHCIFDPs() { mLHCInfo.reset(); } + + const o2::parameters::GRPMagField& getMagFieldObj() const { return mMagField; } + const o2::ccdb::CcdbObjectInfo& getccdbMagFieldInfo() const { return mccdbMagFieldInfo; } + o2::ccdb::CcdbObjectInfo& getccdbMagFieldInfo() { return mccdbMagFieldInfo; } + void updateMagFieldCCDB(); + bool isMagFieldUpdated() const { return mUpdateMagField; } + + const GRPLHCInfo& getLHCIFObj() const { return mLHCInfo; } + const o2::ccdb::CcdbObjectInfo& getccdbLHCIFInfo() const { return mccdbLHCIFInfo; } + o2::ccdb::CcdbObjectInfo& getccdbLHCIFInfo() { return mccdbLHCIFInfo; } + void updateLHCIFInfoCCDB(); + bool isLHCIFInfoUpdated() const { return mUpdateLHCIFInfo; } + + const GRPEnvVariables& getEnvVarsObj() const { return mEnvVars; } + const o2::ccdb::CcdbObjectInfo& getccdbEnvVarsInfo() const { return mccdbEnvVarsInfo; } + o2::ccdb::CcdbObjectInfo& getccdbEnvVarsInfo() { return mccdbEnvVarsInfo; } + void updateEnvVarsCCDB(); + bool isEnvVarsUpdated() const { return mUpdateEnvVars; } + + const GRPCollimators& getCollimatorsObj() const { return mCollimators; } + const o2::ccdb::CcdbObjectInfo& getccdbCollimatorsInfo() const { return mccdbCollimatorsInfo; } + o2::ccdb::CcdbObjectInfo& getccdbCollimatorsInfo() { return mccdbCollimatorsInfo; } + void updateCollimatorsCCDB(); + bool isCollimatorsUpdated() const { return mUpdateCollimators; } + + void setTF(TFType tf) { mTF = tf; } + void useVerboseMode() { mVerbose = true; } + + private: + std::unordered_map mPids; // contains all PIDs for the processor, the bool + // will be true if the DP was processed at least once + + TFType mStartTF; // TF index for processing of first processed TF, used to store CCDB object + TFType mTF = 0; // TF index for processing, used to store CCDB object + bool mStartTFset = false; + + bool mVerbose = false; + + o2::parameters::GRPMagField mMagField; + o2::ccdb::CcdbObjectInfo mccdbMagFieldInfo; + bool mUpdateMagField = false; + + GRPEnvVariables mEnvVars; + o2::ccdb::CcdbObjectInfo mccdbEnvVarsInfo; + bool mUpdateEnvVars = false; + + GRPCollimators mCollimators; + o2::ccdb::CcdbObjectInfo mccdbCollimatorsInfo; + bool mUpdateCollimators = false; + + GRPLHCInfo mLHCInfo; + o2::ccdb::CcdbObjectInfo mccdbLHCIFInfo; + bool mUpdateLHCIFInfo = false; + + ClassDefNV(GRPDCSDPsProcessor, 0); +}; +} // namespace grp +} // namespace o2 + +#endif diff --git a/Detectors/GRP/calibration/src/GRPCalibrationLinkDef.h b/Detectors/GRP/calibration/src/GRPCalibrationLinkDef.h index 438c14b7dd8a0..f916970a0c333 100644 --- a/Detectors/GRP/calibration/src/GRPCalibrationLinkDef.h +++ b/Detectors/GRP/calibration/src/GRPCalibrationLinkDef.h @@ -16,5 +16,9 @@ #pragma link off all functions; #pragma link C++ class o2::grp::LHCIFfileReader + ; +//#pragma link C++ class std::unordered_map < o2::dcs::DataPointIdentifier, std::vector < std::pair < uint64_t, float > > > +; +#pragma link C++ struct o2::grp::GRPEnvVariables + ; +#pragma link C++ struct o2::grp::GRPCollimators + ; +#pragma link C++ struct o2::grp::GRPLHCInfo + ; #endif diff --git a/Detectors/GRP/calibration/src/GRPDCSDPsProcessor.cxx b/Detectors/GRP/calibration/src/GRPDCSDPsProcessor.cxx new file mode 100644 index 0000000000000..f7b9bf8151525 --- /dev/null +++ b/Detectors/GRP/calibration/src/GRPDCSDPsProcessor.cxx @@ -0,0 +1,451 @@ +// 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 +#include "DetectorsCalibration/Utils.h" +#include "Rtypes.h" +#include + +using namespace o2::grp; +using namespace o2::dcs; + +using DeliveryType = o2::dcs::DeliveryType; +using DPID = o2::dcs::DataPointIdentifier; +using DPVAL = o2::dcs::DataPointValue; + +//__________________________________________________________________ + +void GRPDCSDPsProcessor::init(const std::vector& pids) +{ + // fill the array of the DPIDs that will be used by GRP + // pids should be provided by CCDB + + for (const auto& it : pids) { + mPids[it] = false; + } +} +//__________________________________________________________________ + +int GRPDCSDPsProcessor::process(const gsl::span dps) +{ + + // first we check which DPs are missing - if some are, it means that + // the delta map was sent + if (mVerbose) { + LOG(info) << "\n\n\nProcessing new TF\n-----------------"; + } + if (!mStartTFset) { + mStartTF = mTF; + mStartTFset = true; + } + std::unordered_map mapin; + for (auto& it : dps) { + mapin[it.id] = it.data; + } + for (auto& it : mPids) { + const auto& el = mapin.find(it.first); + if (el == mapin.end()) { + LOG(debug) << "DP " << it.first << " not found in list of DPs expected for GRP"; + } else { + LOG(debug) << "DP " << it.first << " found in list of DPs expected for GRP"; + } + } + + mUpdateMagField = false; // by default, we do not foresee a new entry in the CCDB for the B field + mUpdateEnvVars = false; // by default, we do not foresee a new entry in the CCDB for the Env Var + mUpdateCollimators = false; // by default, we do not foresee a new entry in the CCDB for the Collimators + mUpdateLHCIFInfo = false; // by default, we do not foresee a new entry in the CCDB for the LHCIF DPs + + // now we process all DPs, one by one + for (const auto& it : dps) { + // we process only the DPs defined in the configuration + const auto& el = mPids.find(it.id); + if (el == mPids.end()) { + LOG(info) << "DP " << it.id << " not found in GRPDCSProcessor, we will not process it"; + continue; + } + processDP(it); + mPids[it.id] = true; + } + + if (mUpdateMagField) { + updateMagFieldCCDB(); + } + if (mUpdateEnvVars) { + updateEnvVarsCCDB(); + } + if (mUpdateCollimators) { + updateCollimatorsCCDB(); + } + if (mUpdateLHCIFInfo) { + updateLHCIFInfoCCDB(); + } + + return 0; +} + +//__________________________________________________________________ + +int GRPDCSDPsProcessor::processDP(const DPCOM& dpcom) +{ + + // processing single DP + + auto& dpid = dpcom.id; + const auto& type = dpid.get_type(); + auto& val = dpcom.data; + if (mVerbose) { + if (type == RAW_DOUBLE) { + LOG(info); + LOG(info) << "Processing DP = " << dpcom << ", with double value = " << o2::dcs::getValue(dpcom); + } else if (type == RAW_BOOL) { + LOG(info); + LOG(info) << "Processing DP = " << dpcom << ", with bool value = " << o2::dcs::getValue(dpcom); + } else if (type == RAW_STRING) { + LOG(info); + LOG(info) << "Processing DP = " << dpcom << ", with string value = " << o2::dcs::getValue(dpcom); + } + } + auto flags = val.get_flags(); + if (processFlags(flags, dpid.get_alias()) == 0) { + + // now I need to access the correct element + std::string aliasStr(dpid.get_alias()); + // LOG(info) << "alias 0 = " << aliasStr; + // B-field DPs + if (aliasStr.find("Current") != string::npos || aliasStr.find("Polarity") != string::npos) { // B-field DPs + mUpdateMagField = true; + if (aliasStr == "L3Current") { + mMagField.setL3Current(std::signbit(mMagField.getL3Current()) ? -static_cast(o2::dcs::getValue(dpcom)) : static_cast(o2::dcs::getValue(dpcom))); // true is negative field + if (mVerbose) { + LOG(info) << "Updating L3 current with value " << mMagField.getL3Current(); + } + } else if (aliasStr == "L3Polarity") { + mMagField.setL3Current(o2::dcs::getValue(dpcom) ? -mMagField.getL3Current() : mMagField.getL3Current()); // true is negative field + if (mVerbose) { + LOG(info) << "Updating L3 polarity with value " << std::signbit(mMagField.getL3Current()); // poisitive is false, negative is true + } + } else if (aliasStr == "DipoleCurrent") { + mMagField.setDipoleCurrent(std::signbit(mMagField.getDipoleCurrent()) ? -static_cast(o2::dcs::getValue(dpcom)) : static_cast(o2::dcs::getValue(dpcom))); // true is negative field + if (mVerbose) { + LOG(info) << "Updating Dipole current with value " << mMagField.getDipoleCurrent(); + } + } else if (aliasStr == "DipolePolarity") { + mMagField.setDipoleCurrent(o2::dcs::getValue(dpcom) ? -mMagField.getDipoleCurrent() : mMagField.getDipoleCurrent()); // true is negative field + if (mVerbose) { + LOG(info) << "Updating Dipole polarity with value " << std::signbit(mMagField.getDipoleCurrent()); // poisitive is false, negative is true + } + } else { + if (mVerbose) { + LOG(info) << "Alias " << aliasStr << " seemd from B field, but it is not recognized"; + } + mUpdateMagField = false; + } + } else { + // environment variables + if (aliasStr.find("Cavern") != string::npos || aliasStr.find("Surface") != string::npos) { + if (mVerbose) { + LOG(info) << "Alias " << aliasStr << " seems from Env Variables"; + } + processEnvVar(dpcom); + } + + else { + // Collimators + if (aliasStr.find("Collimator") != string::npos) { + // this is a collimator + if (mVerbose) { + LOG(info) << "Alias " << aliasStr << " seems from Collimators"; + } + processCollimators(dpcom); + } + + else { + // the rest should all be LHCIF DPs + if (mVerbose) { + LOG(info) << "Alias " << aliasStr << " should be related to LHCIF"; + } + processLHCIFDPs(dpcom); + } + } + } + } + return 0; +} + +//______________________________________________________________________ + +void GRPDCSDPsProcessor::processCollimators(const DPCOM& dpcom) +{ + + // function to process Data Points that are related to the collimators + + processPair(dpcom, "LHC_CollimatorPos_TCLIA_4R2_lvdt_gap_downstream", mCollimators.mgap_downstream, mUpdateCollimators); + processPair(dpcom, "LHC_CollimatorPos_TCLIA_4R2_lvdt_gap_upstream", mCollimators.mgap_upstream, mUpdateCollimators); + processPair(dpcom, "LHC_CollimatorPos_TCLIA_4R2_lvdt_left_downstream", mCollimators.mleft_downstream, mUpdateCollimators); + processPair(dpcom, "LHC_CollimatorPos_TCLIA_4R2_lvdt_left_upstream", mCollimators.mleft_upstream, mUpdateCollimators); + processPair(dpcom, "LHC_CollimatorPos_TCLIA_4R2_lvdt_right_downstream", mCollimators.mright_downstream, mUpdateCollimators); + processPair(dpcom, "LHC_CollimatorPos_TCLIA_4R2_lvdt_right_upstream", mCollimators.mright_upstream, mUpdateCollimators); + LOG(info) << "update collimators = " << mUpdateCollimators; + return; +} + +//______________________________________________________________________ + +void GRPDCSDPsProcessor::processEnvVar(const DPCOM& dpcom) +{ + + // function to process Data Points that are related to env variables + + processPair(dpcom, "CavernTemperature", mEnvVars.mCavernTemperature, mUpdateEnvVars); + processPair(dpcom, "CavernAtmosPressure", mEnvVars.mCavernAtmosPressure, mUpdateEnvVars); + processPair(dpcom, "SurfaceAtmosPressure", mEnvVars.mSurfaceAtmosPressure, mUpdateEnvVars); + processPair(dpcom, "CavernAtmosPressure2", mEnvVars.mCavernAtmosPressure2, mUpdateEnvVars); + LOG(info) << "update env vars = " << mUpdateEnvVars; + return; +} + +//______________________________________________________________________ + +void GRPDCSDPsProcessor::processPair(const DPCOM& dpcom, const std::string& alias, std::pair& p, bool& flag) +{ + + // function to process Data Points that is stored in a pair + + auto& dpcomdata = dpcom.data; + auto& dpid = dpcom.id; + std::string aliasStr(dpid.get_alias()); + + if (mVerbose) { + LOG(info) << "Processing alias " << aliasStr; + } + + if (aliasStr == alias) { + if (mVerbose) { + LOG(info) << "It matches the requested string " << alias << ", let's check if the value needs to be updated"; + } + flag = compareAndUpdate(p, dpcom); + } + return; +} + +//______________________________________________________________________ + +bool GRPDCSDPsProcessor::compareAndUpdate(std::pair& p, const DPCOM& dpcom) +{ + + // check if the content of the pair should be updated + + double val = o2::dcs::getValue(dpcom); + auto& dpcomdata = dpcom.data; + if (mVerbose) { + LOG(info) << "old value = " << p.second << ", new value = " << val << ", absolute difference = " << std::abs(p.second - val); + } + if (std::abs(p.second - val) > 0.5e-7 * (std::abs(p.second) + std::abs(val))) { + p.first = dpcomdata.get_epoch_time(); + p.second = val; + if (mVerbose) { + LOG(info) << "value will be updated"; + } + return true; + } + if (mVerbose) { + LOG(info) << "value will not be updated"; + } + return false; +} + +//______________________________________________________________________ + +bool GRPDCSDPsProcessor::processLHCIFDPs(const DPCOM& dpcom) +{ + + // function to process the remaining LHCIF DPs + + auto& dpcomdata = dpcom.data; + auto& dpid = dpcom.id; + std::string aliasStr(dpid.get_alias()); + if (mVerbose) { + LOG(info) << "Processing LHCIF DP " << aliasStr; + } + for (int ibeam = 1; ibeam <= 2; ++ibeam) { + if (aliasStr.find(fmt::format("{}{}", "LHC_IntensityBeam", ibeam)) != string::npos) { + double val = o2::dcs::getValue(dpcom); + mLHCInfo.mIntensityBeam[ibeam - 1].emplace_back(dpcomdata.get_epoch_time(), val); + if (mVerbose) { + LOG(info) << "Adding value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " to mIntensityBeam[" << ibeam - 1 << "]"; + } + return true; + } + } + + if (aliasStr.find("BPTX") != string::npos) { + double val = o2::dcs::getValue(dpcom); + if (aliasStr == "BPTX_deltaT_B1_B2") { + mLHCInfo.mBPTXdeltaT.emplace_back(dpcomdata.get_epoch_time(), val); + if (mVerbose) { + LOG(info) << "Adding value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " to BPTX_deltaT_B1_B2"; + } + return true; + } + if (aliasStr == "BPTX_deltaTRMS_B1_B2") { + mLHCInfo.mBPTXdeltaTRMS.emplace_back(dpcomdata.get_epoch_time(), val); + if (mVerbose) { + LOG(info) << "Adding value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " to BPTX_deltaTRMS_B1_B2"; + } + return true; + } + for (int ibeam = 1; ibeam <= 2; ++ibeam) { + if (aliasStr == fmt::format("{}{}", "BPTX_Phase_B", ibeam)) { + mLHCInfo.mBPTXPhase[ibeam - 1].emplace_back(dpcomdata.get_epoch_time(), val); + if (mVerbose) { + LOG(info) << "Adding value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " to mBPTXPhase[" << ibeam - 1 << "]"; + } + return true; + } else if (aliasStr == fmt::format("{}{}", "BPTX_PhaseRMS_B", ibeam)) { + mLHCInfo.mBPTXPhaseRMS[ibeam - 1].emplace_back(dpcomdata.get_epoch_time(), val); + if (mVerbose) { + LOG(info) << "Adding value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " to mBPTXPhaseRMS[" << ibeam - 1 << "]"; + } + return true; + } else if (aliasStr == fmt::format("{}{}", "BPTX_Phase_Shift_B", ibeam)) { + mLHCInfo.mBPTXPhaseShift[ibeam - 1].emplace_back(dpcomdata.get_epoch_time(), val); + if (mVerbose) { + LOG(info) << "Adding value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " to mBPTXPhaseShift[" << ibeam - 1 << "]"; + } + return true; + } + } + return true; + } + if (aliasStr == "ALI_Lumi_Total_Inst") { + double val = o2::dcs::getValue(dpcom); + mLHCInfo.mInstLumi.emplace_back(dpcomdata.get_epoch_time(), val); + if (mVerbose) { + LOG(info) << "Adding value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " to mInstLumi"; + } + return true; + } + + for (int ibkg = 1; ibkg <= 3; ++ibkg) { + if (aliasStr.find(fmt::format("{}{}", "ALI_Background", ibkg)) != string::npos) { + double val = o2::dcs::getValue(dpcom); + mLHCInfo.mBackground[ibkg - 1].emplace_back(dpcomdata.get_epoch_time(), val); + LOG(info) << "Adding value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " to mBackground[" << ibkg - 1 << "]"; + if (mVerbose) { + LOG(info) << "Adding value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " to mBackground[" << ibkg - 1 << "]"; + } + return true; + } + } + if (aliasStr == "ALI_Lumi_Source_Name") { + std::string val = o2::dcs::getValue(dpcom); + mLHCInfo.mLumiSource.first = dpcomdata.get_epoch_time(); + mLHCInfo.mLumiSource.second = val; + LOG(info) << "Updating value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " for mLumiSource"; + if (mVerbose) { + LOG(info) << "Updating value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " for mLumiSource"; + } + mUpdateLHCIFInfo = true; // we force the update of the LHCIF if the lumi source changes + return true; + } + + if (aliasStr == "MACHINE_MODE") { + std::string val = o2::dcs::getValue(dpcom); + mLHCInfo.mMachineMode.first = dpcomdata.get_epoch_time(); + mLHCInfo.mMachineMode.second = val; + LOG(info) << "Updating value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " for mMachineMode"; + if (mVerbose) { + LOG(info) << "Updating value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " for mMachineMode"; + } + mUpdateLHCIFInfo = true; // we force the update of the LHCIF if the machine mode (ION PHYSICS, PROTON PHYSICS..., see https://lhc-commissioning.web.cern.ch/systems/data-exchange/doc/LHC-OP-ES-0005-10-00.pdf) changes + return true; + } + if (aliasStr == "BEAM_MODE") { + std::string val = o2::dcs::getValue(dpcom); + LOG(info) << "Updating value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " for mBeamMode"; + mLHCInfo.mBeamMode.first = dpcomdata.get_epoch_time(); + mLHCInfo.mBeamMode.second = val; + if (mVerbose) { + LOG(info) << "Updating value " << val << " with timestamp " << dpcomdata.get_epoch_time() << " for mBeamMode"; + } + + mUpdateLHCIFInfo = true; // we force the update of the LHCIF if the beam mode (SETUP, RAMP, STABLE BEAMS..., see https://lhc-commissioning.web.cern.ch/systems/data-exchange/doc/LHC-OP-ES-0005-10-00.pdf) changes + return true; + } + + // LOG(error) << "DP " << aliasStr << " not known for GRP, please check"; + return false; +} + +//______________________________________________________________________ + +void GRPDCSDPsProcessor::updateMagFieldCCDB() +{ + + // we need to update a CCDB for the B field --> let's prepare the CCDBInfo + + if (mVerbose) { + LOG(info) << "At least one DP related to B field changed --> we will update CCDB with startTime " << mTF; + } + std::map md; + md["responsible"] = "Chiara Zampolli"; + o2::calibration::Utils::prepareCCDBobjectInfo(mMagField, mccdbMagFieldInfo, "GLO/Config/GRPMagField", mTF, md); + return; +} + +//______________________________________________________________________ + +void GRPDCSDPsProcessor::updateLHCIFInfoCCDB() +{ + + // we need to update a CCDB for the LHCIF DPs --> let's prepare the CCDBInfo + + if (mVerbose) { + LOG(info) << "Entry related to LHCIF needs to be updated with startTime " << mTF; + } + std::map md; + md["responsible"] = "Chiara Zampolli"; + o2::calibration::Utils::prepareCCDBobjectInfo(mLHCInfo, mccdbLHCIFInfo, "GLO/Config/LHCIF", mTF, md); + return; +} + +//______________________________________________________________________ + +void GRPDCSDPsProcessor::updateEnvVarsCCDB() +{ + + // we need to update a CCDB for the Env Variables DPs --> let's prepare the CCDBInfo + + if (mVerbose) { + LOG(info) << "Entry related to Env Vars needs to be updated with startTime " << mTF; + } + std::map md; + md["responsible"] = "Chiara Zampolli"; + o2::calibration::Utils::prepareCCDBobjectInfo(mEnvVars, mccdbEnvVarsInfo, "GLO/Config/EnvVars", mTF, md); + return; +} + +//______________________________________________________________________ + +void GRPDCSDPsProcessor::updateCollimatorsCCDB() +{ + + // we need to update a CCDB for the Env Variables DPs --> let's prepare the CCDBInfo + + if (mVerbose) { + LOG(info) << "Entry related to Env Vars needs to be updated with startTime " << mTF; + } + std::map md; + md["responsible"] = "Chiara Zampolli"; + o2::calibration::Utils::prepareCCDBobjectInfo(mEnvVars, mccdbCollimatorsInfo, "GLO/Config/Collimators", mTF, md); + return; +} diff --git a/Detectors/GRP/workflows/CMakeLists.txt b/Detectors/GRP/workflows/CMakeLists.txt index 51fe16342141f..4b44c7817697d 100644 --- a/Detectors/GRP/workflows/CMakeLists.txt +++ b/Detectors/GRP/workflows/CMakeLists.txt @@ -12,6 +12,7 @@ o2_add_library(GRPCalibrationWorkflow TARGETVARNAME targetName SOURCES src/GRPLHCIFfileSpec.cxx + src/GRPDCSDPsSpec.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2::Headers O2::CCDB @@ -38,3 +39,17 @@ o2_add_executable(grp-create O2::CommonUtils O2::CCDB Boost::program_options) + +o2_add_executable(grp-dcs-dps-sim-workflow + COMPONENT_NAME calibration + SOURCES src/grp-dcs-dps-sim-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::DCStestWorkflow) + +o2_add_executable(grp-dcs-dps-workflow + COMPONENT_NAME calibration + SOURCES src/grp-dcs-dps-workflow.cxx + PUBLIC_LINK_LIBRARIES O2::Framework + O2::CCDB + O2::GRPCalibrationWorkflow + O2::GRPCalibration + O2::DetectorsCalibration) diff --git a/Detectors/GRP/workflows/include/GRPWorkflows/GRPDCSDPsSpec.h b/Detectors/GRP/workflows/include/GRPWorkflows/GRPDCSDPsSpec.h new file mode 100644 index 0000000000000..fb8b669fc5372 --- /dev/null +++ b/Detectors/GRP/workflows/include/GRPWorkflows/GRPDCSDPsSpec.h @@ -0,0 +1,56 @@ +// 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 GRPDCSDPsSpec.h + +#ifndef O2_GRP_DCS_DPs_SPEC +#define O2_GRP_DCS_DPs_SPEC + +#include +#include "GRPCalibration/GRPDCSDPsProcessor.h" +#include "Framework/DataProcessorSpec.h" +#include "Framework/Task.h" + +using namespace o2::framework; +using HighResClock = std::chrono::high_resolution_clock; + +namespace o2 +{ +namespace grp +{ +class GRPDCSDPsDataProcessor : public Task +{ + public: + void init(o2::framework::InitContext& ic) final; + void run(o2::framework::ProcessingContext& pc) final; + void endOfStream(o2::framework::EndOfStreamContext& ec) final; + + private: + void sendLHCIFDPsoutput(DataAllocator& output); + void sendMagFieldDPsoutput(DataAllocator& output); + void sendCollimatorsDPsoutput(DataAllocator& output); + void sendEnvVarsDPsoutput(DataAllocator& output); + + bool mVerbose = false; // to enable verbose mode + std::unique_ptr mProcessor; + HighResClock::time_point mTimer; + int64_t mDPsUpdateInterval; +}; +} // namespace grp + +namespace framework +{ +DataProcessorSpec getGRPDCSDPsDataProcessorSpec(); + +} // namespace framework +} // namespace o2 + +#endif diff --git a/Detectors/GRP/workflows/src/GRPDCSDPsSpec.cxx b/Detectors/GRP/workflows/src/GRPDCSDPsSpec.cxx new file mode 100644 index 0000000000000..d9617263890e9 --- /dev/null +++ b/Detectors/GRP/workflows/src/GRPDCSDPsSpec.cxx @@ -0,0 +1,247 @@ +// 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 GRPDCSDPsSpec.cxx + +#include "Framework/ControlService.h" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/Logger.h" +#include "GRPWorkflows/GRPDCSDPsSpec.h" +#include "GRPCalibration/GRPDCSDPsProcessor.h" +#include "CCDB/CcdbApi.h" +#include "CCDB/CcdbObjectInfo.h" +#include "CCDB/BasicCCDBManager.h" +#include "CCDB/CcdbApi.h" +#include "CommonUtils/MemFileHelper.h" +#include "DetectorsCalibration/Utils.h" +#include "CommonTypes/Units.h" +#include "DetectorsDCS/AliasExpander.h" +#include "DetectorsDCS/DataPointIdentifier.h" +#include "DetectorsDCS/DataPointValue.h" +#include "DetectorsDCS/DataPointCompositeObject.h" + +namespace o2 +{ +namespace grp +{ + +using CcdbManager = o2::ccdb::BasicCCDBManager; +using namespace o2::ccdb; +using DPID = o2::dcs::DataPointIdentifier; +using DPVAL = o2::dcs::DataPointValue; +using DPCOM = o2::dcs::DataPointCompositeObject; +using Duration = std::chrono::duration>; + +void GRPDCSDPsDataProcessor::init(o2::framework::InitContext& ic) +{ + + std::vector vect; + mDPsUpdateInterval = ic.options().get("DPs-update-interval"); + if (mDPsUpdateInterval == 0) { + LOG(error) << "GRP DPs update interval set to zero seconds --> changed to 60"; + mDPsUpdateInterval = 60; + } + bool useCCDBtoConfigure = ic.options().get("use-ccdb-to-configure"); + if (useCCDBtoConfigure) { + LOG(info) << "Configuring via CCDB"; + std::string ccdbpath = ic.options().get("ccdb-path"); + auto& mgr = CcdbManager::instance(); + mgr.setURL(ccdbpath); + CcdbApi api; + api.init(mgr.getURL()); + long ts = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + std::unordered_map* dpid2DataDesc = mgr.getForTimeStamp>("GRP/Config/DCSDPconfig", ts); + for (auto& i : *dpid2DataDesc) { + vect.push_back(i.first); + } + } else { + LOG(info) << "Configuring via hardcoded strings"; + std::vector aliasesBFieldDouble = {"L3Current", "DipoleCurrent"}; + std::vector aliasesBFieldBool = {"L3Polarity", "DipolePolarity"}; + std::vector aliasesEnvVar = {"CavernTemperature", "CavernAtmosPressure", "SurfaceAtmosPressure", "CavernAtmosPressure2"}; + std::vector compactAliasesLHCIFDouble = {"LHC_IntensityBeam[1..2]_totalIntensity", "ALI_Background[1..3]", + "ALI_Lumi_Total_Inst", + "BPTX_deltaT_B1_B2", "BPTX_deltaTRMS_B1_B2", + "BPTX_Phase_B[1..2]", "BPTX_PhaseRMS_B[1..2]", "BPTX_Phase_Shift_B[1..2]"}; + std::vector aliasesLHCIFDouble = o2::dcs::expandAliases(compactAliasesLHCIFDouble); + std::vector aliasesLHCIFString = {"ALI_Lumi_Source_Name", "MACHINE_MODE", "BEAM_MODE"}; + std::vector aliasesLHCIFCollimators = {"LHC_CollimatorPos_TCLIA_4R2_lvdt_gap_downstream", "LHC_CollimatorPos_TCLIA_4R2_lvdt_gap_upstream", + "LHC_CollimatorPos_TCLIA_4R2_lvdt_left_downstream", "LHC_CollimatorPos_TCLIA_4R2_lvdt_left_upstream", + "LHC_CollimatorPos_TCLIA_4R2_lvdt_right_downstream", "LHC_CollimatorPos_TCLIA_4R2_lvdt_right_upstream"}; + + for (const auto& i : aliasesBFieldDouble) { + vect.emplace_back(i, o2::dcs::RAW_DOUBLE); + } + for (const auto& i : aliasesBFieldBool) { + vect.emplace_back(i, o2::dcs::RAW_BOOL); + } + for (const auto& i : aliasesEnvVar) { + vect.emplace_back(i, o2::dcs::RAW_DOUBLE); + } + for (const auto& i : aliasesLHCIFDouble) { + vect.emplace_back(i, o2::dcs::RAW_DOUBLE); + } + for (const auto& i : aliasesLHCIFCollimators) { + vect.emplace_back(i, o2::dcs::RAW_DOUBLE); + } + for (const auto& i : aliasesLHCIFString) { + vect.emplace_back(i, o2::dcs::RAW_STRING); + } + } + + LOG(info) << "Listing Data Points for GRP:"; + for (auto& i : vect) { + LOG(info) << i; + } + + mProcessor = std::make_unique(); + bool useVerboseMode = ic.options().get("use-verbose-mode"); + LOG(info) << " ************************* Verbose?" << useVerboseMode; + if (useVerboseMode) { + mProcessor->useVerboseMode(); + } + mProcessor->init(vect); + mTimer = HighResClock::now(); +} +//__________________________________________________________________ + +void GRPDCSDPsDataProcessor::run(o2::framework::ProcessingContext& pc) +{ + auto tfid = o2::header::get(pc.inputs().get("input").header)->startTime; + auto dps = pc.inputs().get>("input"); + mProcessor->setTF(tfid); + mProcessor->process(dps); + auto timeNow = HighResClock::now(); + Duration elapsedTime = timeNow - mTimer; // in seconds + if (elapsedTime.count() >= mDPsUpdateInterval || mProcessor->isLHCIFInfoUpdated()) { + sendLHCIFDPsoutput(pc.outputs()); + mProcessor->resetLHCIFDPs(); + mTimer = timeNow; + } + if (mProcessor->isMagFieldUpdated()) { + sendMagFieldDPsoutput(pc.outputs()); + } + if (mProcessor->isCollimatorsUpdated()) { + sendCollimatorsDPsoutput(pc.outputs()); + } + if (mProcessor->isEnvVarsUpdated()) { + sendEnvVarsDPsoutput(pc.outputs()); + } +} +//________________________________________________________________ + +void GRPDCSDPsDataProcessor::endOfStream(o2::framework::EndOfStreamContext& ec) +{ + + LOG(info) << " ********** End of Stream **********"; + mProcessor->updateLHCIFInfoCCDB(); + sendLHCIFDPsoutput(ec.outputs()); + /* + sendMagFieldDPsoutput(ec.outputs()); + sendCollimatorsDPsoutput(ec.outputs()); + sendEnvVarsDPsoutput(ec.outputs()); + */ +} + +//________________________________________________________________ + +void GRPDCSDPsDataProcessor::sendLHCIFDPsoutput(DataAllocator& output) +{ + // filling CCDB with LHCIF DPs object + + const auto& payload = mProcessor->getLHCIFObj(); + auto& info = mProcessor->getccdbLHCIFInfo(); + auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info); + LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size() + << " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp(); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "GRP_LHCIF_DPs", 0}, *image.get()); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "GRP_LHCIF_DPs", 0}, info); +} +//________________________________________________________________ + +void GRPDCSDPsDataProcessor::sendMagFieldDPsoutput(DataAllocator& output) +{ + // filling CCDB with B field object + + const auto& payload = mProcessor->getMagFieldObj(); + auto& info = mProcessor->getccdbMagFieldInfo(); + auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info); + LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size() + << " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp(); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "GRP_Bfield", 0}, *image.get()); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "GRP_Bfield", 0}, info); +} + +//________________________________________________________________ + +void GRPDCSDPsDataProcessor::sendCollimatorsDPsoutput(DataAllocator& output) +{ + // filling CCDB with Collimators object + + const auto& payload = mProcessor->getCollimatorsObj(); + auto& info = mProcessor->getccdbCollimatorsInfo(); + auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info); + LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size() + << " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp(); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "GRP_COLLIM_DPs", 0}, *image.get()); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "GRP_COLLIM_DPs", 0}, info); +} + +//________________________________________________________________ + +void GRPDCSDPsDataProcessor::sendEnvVarsDPsoutput(DataAllocator& output) +{ + // filling CCDB with EnvVars object + + const auto& payload = mProcessor->getEnvVarsObj(); + auto& info = mProcessor->getccdbEnvVarsInfo(); + auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info); + LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size() + << " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp(); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "GRP_EVARS_DPs", 0}, *image.get()); + output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "GRP_EVARS_DPs", 0}, info); +} + +} // namespace grp + +namespace framework +{ + +DataProcessorSpec getGRPDCSDPsDataProcessorSpec() +{ + using clbUtils = o2::calibration::Utils; + + std::vector outputs; + outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "GRP_Bfield"}, Lifetime::Sporadic); + outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "GRP_Bfield"}, Lifetime::Sporadic); + + outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "GRP_LHCIF_DPs"}, Lifetime::Sporadic); + outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "GRP_LHCIF_DPs"}, Lifetime::Sporadic); + + outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "GRP_COLLIM_DPs"}, Lifetime::Sporadic); + outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "GRP_COLLIM_DPs"}, Lifetime::Sporadic); + + outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "GRP_EVARS_DPs"}, Lifetime::Sporadic); + outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "GRP_EVARS_DPs"}, Lifetime::Sporadic); + + return DataProcessorSpec{ + "grp-dcs-data-processor", + Inputs{{"input", "DCS", "GRPDATAPOINTS"}}, + outputs, + AlgorithmSpec{adaptFromTask()}, + Options{{"ccdb-path", VariantType::String, "http://localhost:8080", {"Path to CCDB"}}, + {"use-ccdb-to-configure", VariantType::Bool, false, {"Use CCDB to configure"}}, + {"use-verbose-mode", VariantType::Bool, false, {"Use verbose mode"}}, + {"DPs-update-interval", VariantType::Int64, 600ll, {"Interval (in s) after which to update the DPs CCDB entry"}}}}; +} + +} // namespace framework +} // namespace o2 diff --git a/Detectors/GRP/workflows/src/grp-dcs-dps-sim-workflow.cxx b/Detectors/GRP/workflows/src/grp-dcs-dps-sim-workflow.cxx new file mode 100644 index 0000000000000..ca758391c854b --- /dev/null +++ b/Detectors/GRP/workflows/src/grp-dcs-dps-sim-workflow.cxx @@ -0,0 +1,55 @@ +// 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. + +// // we need to add workflow options before including Framework/runDataProcessing +// void customize(std::vector& workflowOptions) +// { +// // option allowing to set parameters +// } + +// ------------------------------------------------------------------ + +#include "DCStestWorkflow/DCSRandomDataGeneratorSpec.h" +#include "Framework/runDataProcessing.h" + +o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& configcontext) +{ + std::vector dphints; + // for GRP + dphints.emplace_back(o2::dcs::test::DataPointHint{"L3Current", 29.9, 30.1}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"DipoleCurrent", 11.9, 12.1}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"L3Polarity", 0, 1}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"DipolePolarity", 0, 1}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"CavernTemperature", 16, 28}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"CavernAtmosPressure", 0.95, 1.05}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"SurfaceAtmosPressure", 0.95, 1.05}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"CavernAtmosPressure2", 0.95, 1.05}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"LHC_IntensityBeam[1..2]_totalIntensity", +1.811e+14, +1.906e+14}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"ALI_Background[1..3]", +1.839e+14, +1.909e+14}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"ALI_Lumi_Total_Inst", +2.589e+00, +2.618e+00}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"BPTX_deltaT_B1_B2", +4.096e-02, +5.006e-02}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"BPTX_deltaTRMS_B1_B2", +2.800e-02, +2.800e-02}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"BPTX_Phase_B[1..2]", +1.142e+00, +1.181e+00}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"BPTX_PhaseRMS_B[1..2]", +2.271e-03, +3.942e-03}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"BPTX_Phase_Shift_B[1..2]", +1.835e-02, -2.068e-02}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"LHC_CollimatorPos_TCLIA_4R2_lvdt_gap_downstream", +5.592e+01, +5.592e+01}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"LHC_CollimatorPos_TCLIA_4R2_lvdt_gap_upstream", +5.588e+01, +5.588e+01}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"LHC_CollimatorPos_TCLIA_4R2_lvdt_left_downstream", +2.797e+01, +2.797e+01}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"LHC_CollimatorPos_TCLIA_4R2_lvdt_left_upstream", +2.799e+01, +2.799e+01}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"LHC_CollimatorPos_TCLIA_4R2_lvdt_right_downstream", -2.797e+01, -2.797e+01}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"LHC_CollimatorPos_TCLIA_4R2_lvdt_right_upstream", -2.799e+01, -2.799e+01}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"ALI_Lumi_Source_Name", "FT0ORA", "FT0ORC"}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"BEAM_MODE", "RAMP", "STABLE BEAMS"}); + dphints.emplace_back(o2::dcs::test::DataPointHint{"MACHINE_MODE", "PP PHYSICS", "ION PHYSICS"}); + o2::framework::WorkflowSpec specs; + specs.emplace_back(o2::dcs::test::getDCSRandomDataGeneratorSpec(dphints, "GRP")); + return specs; +} diff --git a/Detectors/GRP/workflows/src/grp-dcs-dps-workflow.cxx b/Detectors/GRP/workflows/src/grp-dcs-dps-workflow.cxx new file mode 100644 index 0000000000000..9d2d2710ba0df --- /dev/null +++ b/Detectors/GRP/workflows/src/grp-dcs-dps-workflow.cxx @@ -0,0 +1,33 @@ +// 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/TypeTraits.h" +#include "Framework/DataProcessorSpec.h" +#include "GRPWorkflows/GRPDCSDPsSpec.h" + +using namespace o2::framework; + +// we need to add workflow options before including Framework/runDataProcessing +void customize(std::vector& workflowOptions) +{ + // option allowing to set parameters +} + +// ------------------------------------------------------------------ + +#include "Framework/runDataProcessing.h" + +WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) +{ + WorkflowSpec specs; + specs.emplace_back(getGRPDCSDPsDataProcessorSpec()); + return specs; +} diff --git a/Detectors/TOF/calibration/include/TOFCalibration/TOFDCSProcessor.h b/Detectors/TOF/calibration/include/TOFCalibration/TOFDCSProcessor.h index 193dcd71c19f9..6d57f4852c3b6 100644 --- a/Detectors/TOF/calibration/include/TOFCalibration/TOFDCSProcessor.h +++ b/Detectors/TOF/calibration/include/TOFCalibration/TOFDCSProcessor.h @@ -107,10 +107,10 @@ class TOFDCSProcessor const std::bitset& getHVStatus() const { return mHV; } bool isHVUpdated() const { return mUpdateHVStatus; } - template + /*template void prepareCCDBobjectInfo(T& obj, CcdbObjectInfo& info, const std::string& path, TFType tf, const std::map& md); - + */ void setTF(TFType tf) { mTF = tf; } void useVerboseMode() { mVerbose = true; } @@ -145,23 +145,23 @@ class TOFDCSProcessor ClassDefNV(TOFDCSProcessor, 0); }; - +/* template void TOFDCSProcessor::prepareCCDBobjectInfo(T& obj, CcdbObjectInfo& info, const std::string& path, TFType tf, - const std::map& md) + const std::map& md) { - // prepare all info to be sent to CCDB for object obj - auto clName = o2::utils::MemFileHelper::getClassName(obj); - auto flName = o2::ccdb::CcdbApi::generateFileName(clName); - info.setPath(path); - info.setObjectType(clName); - info.setFileName(flName); - info.setStartValidityTimestamp(tf); - info.setEndValidityTimestamp(99999999999999); - info.setMetaData(md); +// prepare all info to be sent to CCDB for object obj +auto clName = o2::utils::MemFileHelper::getClassName(obj); +auto flName = o2::ccdb::CcdbApi::generateFileName(clName); +info.setPath(path); +info.setObjectType(clName); +info.setFileName(flName); +info.setStartValidityTimestamp(tf); +info.setEndValidityTimestamp(99999999999999); +info.setMetaData(md); } - +*/ } // namespace tof } // namespace o2 diff --git a/Detectors/TOF/calibration/src/TOFDCSProcessor.cxx b/Detectors/TOF/calibration/src/TOFDCSProcessor.cxx index f87d5ef416718..90d9d7a5db73f 100644 --- a/Detectors/TOF/calibration/src/TOFDCSProcessor.cxx +++ b/Detectors/TOF/calibration/src/TOFDCSProcessor.cxx @@ -10,6 +10,7 @@ // or submit itself to any jurisdiction. #include +#include "DetectorsCalibration/Utils.h" #include "Rtypes.h" #include #include @@ -392,7 +393,7 @@ void TOFDCSProcessor::updateDPsCCDB() } std::map md; md["responsible"] = "Chiara Zampolli"; - prepareCCDBobjectInfo(mTOFDCS, mccdbDPsInfo, "TOF/Calib/DCSDPs", mTF, md); + o2::calibration::Utils::prepareCCDBobjectInfo(mTOFDCS, mccdbDPsInfo, "TOF/Calib/DCSDPs", mTF, md); return; } @@ -409,7 +410,7 @@ void TOFDCSProcessor::updateFEACCCDB() } std::map md; md["responsible"] = "Chiara Zampolli"; - prepareCCDBobjectInfo(mFeac, mccdbLVInfo, "TOF/Calib/LVStatus", mTF, md); + o2::calibration::Utils::prepareCCDBobjectInfo(mFeac, mccdbLVInfo, "TOF/Calib/LVStatus", mTF, md); return; } @@ -425,7 +426,7 @@ void TOFDCSProcessor::updateHVCCDB() } std::map md; md["responsible"] = "Chiara Zampolli"; - prepareCCDBobjectInfo(mHV, mccdbHVInfo, "TOF/Calib/HVStatus", mTF, md); + o2::calibration::Utils::prepareCCDBobjectInfo(mHV, mccdbHVInfo, "TOF/Calib/HVStatus", mTF, md); return; } From 2db02c274aebcb3e1659f2a0d24bfd7a6320e9a4 Mon Sep 17 00:00:00 2001 From: Chiara Zampolli Date: Fri, 28 Jan 2022 17:43:33 +0100 Subject: [PATCH 2/2] Fix startTime and endTime --- .../include/DetectorsCalibration/Utils.h | 15 +++++----- .../GRPCalibration/GRPDCSDPsProcessor.h | 11 +++---- .../calibration/src/GRPDCSDPsProcessor.cxx | 22 +++++++------- Detectors/GRP/workflows/src/GRPDCSDPsSpec.cxx | 9 ++++-- .../GRP/workflows/src/GRPLHCIFfileSpec.cxx | 6 ++-- .../include/TOFCalibration/TOFDCSProcessor.h | 30 +++---------------- .../TOF/calibration/src/TOFDCSProcessor.cxx | 14 ++++----- .../testWorkflow/TOFDCSDataProcessorSpec.h | 9 ++++-- 8 files changed, 47 insertions(+), 69 deletions(-) diff --git a/Detectors/Calibration/include/DetectorsCalibration/Utils.h b/Detectors/Calibration/include/DetectorsCalibration/Utils.h index b9f4793e9ddd3..4a55274a3b357 100644 --- a/Detectors/Calibration/include/DetectorsCalibration/Utils.h +++ b/Detectors/Calibration/include/DetectorsCalibration/Utils.h @@ -31,19 +31,18 @@ namespace o2 namespace calibration { -using TFType = uint64_t; - struct Utils { static constexpr o2::header::DataOrigin gDataOriginCDBPayload{"CLP"}; // generic DataOrigin for calibrations payload static constexpr o2::header::DataOrigin gDataOriginCDBWrapper{"CLW"}; // generic DataOrigin for calibrations wrapper + static constexpr long INFINITE_TIME = 99999999999999; template - static void prepareCCDBobjectInfo(T& obj, o2::ccdb::CcdbObjectInfo& info, const std::string& path, TFType tf, - const std::map& md); + static void prepareCCDBobjectInfo(T& obj, o2::ccdb::CcdbObjectInfo& info, const std::string& path, + const std::map& md, long start, long end = -1); }; template -void Utils::prepareCCDBobjectInfo(T& obj, o2::ccdb::CcdbObjectInfo& info, const std::string& path, TFType tf, - const std::map& md) +void Utils::prepareCCDBobjectInfo(T& obj, o2::ccdb::CcdbObjectInfo& info, const std::string& path, + const std::map& md, long start, long end) { // prepare all info to be sent to CCDB for object obj @@ -52,8 +51,8 @@ void Utils::prepareCCDBobjectInfo(T& obj, o2::ccdb::CcdbObjectInfo& info, const info.setPath(path); info.setObjectType(clName); info.setFileName(flName); - info.setStartValidityTimestamp(tf); - info.setEndValidityTimestamp(99999999999999); + info.setStartValidityTimestamp(start); + info.setEndValidityTimestamp(end); info.setMetaData(md); } diff --git a/Detectors/GRP/calibration/include/GRPCalibration/GRPDCSDPsProcessor.h b/Detectors/GRP/calibration/include/GRPCalibration/GRPDCSDPsProcessor.h index 2605306dff9b3..60059ce7b42a9 100644 --- a/Detectors/GRP/calibration/include/GRPCalibration/GRPDCSDPsProcessor.h +++ b/Detectors/GRP/calibration/include/GRPCalibration/GRPDCSDPsProcessor.h @@ -189,9 +189,6 @@ struct GRPLHCInfo { class GRPDCSDPsProcessor { public: - using TFType = uint64_t; - // using CcdbObjectInfo = o2::ccdb::CcdbObjectInfo; - GRPDCSDPsProcessor() = default; ~GRPDCSDPsProcessor() = default; @@ -231,16 +228,16 @@ class GRPDCSDPsProcessor void updateCollimatorsCCDB(); bool isCollimatorsUpdated() const { return mUpdateCollimators; } - void setTF(TFType tf) { mTF = tf; } + void setStartValidity(long t) { mStartValidity = t; } void useVerboseMode() { mVerbose = true; } private: std::unordered_map mPids; // contains all PIDs for the processor, the bool // will be true if the DP was processed at least once - TFType mStartTF; // TF index for processing of first processed TF, used to store CCDB object - TFType mTF = 0; // TF index for processing, used to store CCDB object - bool mStartTFset = false; + long mFirstTime; // time when a CCDB object was stored first + long mStartValidity = 0; // TF index for processing, used to store CCDB object + bool mFirstTimeSet = false; bool mVerbose = false; diff --git a/Detectors/GRP/calibration/src/GRPDCSDPsProcessor.cxx b/Detectors/GRP/calibration/src/GRPDCSDPsProcessor.cxx index f7b9bf8151525..e3bc21ad8cb32 100644 --- a/Detectors/GRP/calibration/src/GRPDCSDPsProcessor.cxx +++ b/Detectors/GRP/calibration/src/GRPDCSDPsProcessor.cxx @@ -42,9 +42,9 @@ int GRPDCSDPsProcessor::process(const gsl::span dps) if (mVerbose) { LOG(info) << "\n\n\nProcessing new TF\n-----------------"; } - if (!mStartTFset) { - mStartTF = mTF; - mStartTFset = true; + if (!mFirstTimeSet) { + mFirstTime = mStartValidity; + mFirstTimeSet = true; } std::unordered_map mapin; for (auto& it : dps) { @@ -394,11 +394,11 @@ void GRPDCSDPsProcessor::updateMagFieldCCDB() // we need to update a CCDB for the B field --> let's prepare the CCDBInfo if (mVerbose) { - LOG(info) << "At least one DP related to B field changed --> we will update CCDB with startTime " << mTF; + LOG(info) << "At least one DP related to B field changed --> we will update CCDB with startTime " << mStartValidity; } std::map md; md["responsible"] = "Chiara Zampolli"; - o2::calibration::Utils::prepareCCDBobjectInfo(mMagField, mccdbMagFieldInfo, "GLO/Config/GRPMagField", mTF, md); + o2::calibration::Utils::prepareCCDBobjectInfo(mMagField, mccdbMagFieldInfo, "GLO/Config/GRPMagField", md, mStartValidity, o2::calibration::Utils::INFINITE_TIME); return; } @@ -410,11 +410,11 @@ void GRPDCSDPsProcessor::updateLHCIFInfoCCDB() // we need to update a CCDB for the LHCIF DPs --> let's prepare the CCDBInfo if (mVerbose) { - LOG(info) << "Entry related to LHCIF needs to be updated with startTime " << mTF; + LOG(info) << "Entry related to LHCIF needs to be updated with startTime " << mStartValidity; } std::map md; md["responsible"] = "Chiara Zampolli"; - o2::calibration::Utils::prepareCCDBobjectInfo(mLHCInfo, mccdbLHCIFInfo, "GLO/Config/LHCIF", mTF, md); + o2::calibration::Utils::prepareCCDBobjectInfo(mLHCInfo, mccdbLHCIFInfo, "GLO/Config/LHCIF", md, mStartValidity, o2::calibration::Utils::INFINITE_TIME); return; } @@ -426,11 +426,11 @@ void GRPDCSDPsProcessor::updateEnvVarsCCDB() // we need to update a CCDB for the Env Variables DPs --> let's prepare the CCDBInfo if (mVerbose) { - LOG(info) << "Entry related to Env Vars needs to be updated with startTime " << mTF; + LOG(info) << "Entry related to Env Vars needs to be updated with startTime " << mStartValidity; } std::map md; md["responsible"] = "Chiara Zampolli"; - o2::calibration::Utils::prepareCCDBobjectInfo(mEnvVars, mccdbEnvVarsInfo, "GLO/Config/EnvVars", mTF, md); + o2::calibration::Utils::prepareCCDBobjectInfo(mEnvVars, mccdbEnvVarsInfo, "GLO/Config/EnvVars", md, mStartValidity, o2::calibration::Utils::INFINITE_TIME); return; } @@ -442,10 +442,10 @@ void GRPDCSDPsProcessor::updateCollimatorsCCDB() // we need to update a CCDB for the Env Variables DPs --> let's prepare the CCDBInfo if (mVerbose) { - LOG(info) << "Entry related to Env Vars needs to be updated with startTime " << mTF; + LOG(info) << "Entry related to Env Vars needs to be updated with startTime " << mStartValidity; } std::map md; md["responsible"] = "Chiara Zampolli"; - o2::calibration::Utils::prepareCCDBobjectInfo(mEnvVars, mccdbCollimatorsInfo, "GLO/Config/Collimators", mTF, md); + o2::calibration::Utils::prepareCCDBobjectInfo(mEnvVars, mccdbCollimatorsInfo, "GLO/Config/Collimators", md, mStartValidity, o2::calibration::Utils::INFINITE_TIME); return; } diff --git a/Detectors/GRP/workflows/src/GRPDCSDPsSpec.cxx b/Detectors/GRP/workflows/src/GRPDCSDPsSpec.cxx index d9617263890e9..80a29ab3ae8cb 100644 --- a/Detectors/GRP/workflows/src/GRPDCSDPsSpec.cxx +++ b/Detectors/GRP/workflows/src/GRPDCSDPsSpec.cxx @@ -115,11 +115,14 @@ void GRPDCSDPsDataProcessor::init(o2::framework::InitContext& ic) void GRPDCSDPsDataProcessor::run(o2::framework::ProcessingContext& pc) { - auto tfid = o2::header::get(pc.inputs().get("input").header)->startTime; + auto startValidity = DataRefUtils::getHeader(pc.inputs().getFirstValid(true))->creation; auto dps = pc.inputs().get>("input"); - mProcessor->setTF(tfid); - mProcessor->process(dps); auto timeNow = HighResClock::now(); + if (startValidity == 0xffffffffffffffff) { // it means it is not set + startValidity = std::chrono::duration_cast(timeNow.time_since_epoch()).count(); // in ms + } + mProcessor->setStartValidity(startValidity); + mProcessor->process(dps); Duration elapsedTime = timeNow - mTimer; // in seconds if (elapsedTime.count() >= mDPsUpdateInterval || mProcessor->isLHCIFInfoUpdated()) { sendLHCIFDPsoutput(pc.outputs()); diff --git a/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx b/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx index 260a75d6e1406..4b0b3268b338e 100644 --- a/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx +++ b/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx @@ -216,18 +216,16 @@ void GRPLHCIFfileProcessor::endOfStream(o2::framework::EndOfStreamContext& ec) //__________________________________________________________________ -void GRPLHCIFfileProcessor::sendOutput(DataAllocator& output, long tf, const GRPLHCIFData& lhcifdata) +void GRPLHCIFfileProcessor::sendOutput(DataAllocator& output, long start, const GRPLHCIFData& lhcifdata) { // sending output to CCDB - constexpr uint64_t INFINITE_TF = 0xffffffffffffffff; - using clbUtils = o2::calibration::Utils; auto clName = o2::utils::MemFileHelper::getClassName(lhcifdata); auto flName = o2::ccdb::CcdbApi::generateFileName(clName); std::map md; md.emplace("created by", "dpl"); - o2::ccdb::CcdbObjectInfo info("GLO/Config/GRPLHCIFData", clName, flName, md, tf, INFINITE_TF); + o2::ccdb::CcdbObjectInfo info("GLO/Config/GRPLHCIFData", clName, flName, md, start, o2::calibration::Utils::INFINITE_TIME); auto image = o2::ccdb::CcdbApi::createObjectImage(&lhcifdata, &info); LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size() << " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp(); diff --git a/Detectors/TOF/calibration/include/TOFCalibration/TOFDCSProcessor.h b/Detectors/TOF/calibration/include/TOFCalibration/TOFDCSProcessor.h index 6d57f4852c3b6..ebf919ffd9ffe 100644 --- a/Detectors/TOF/calibration/include/TOFCalibration/TOFDCSProcessor.h +++ b/Detectors/TOF/calibration/include/TOFCalibration/TOFDCSProcessor.h @@ -71,7 +71,6 @@ class TOFDCSProcessor { public: - using TFType = uint64_t; using CcdbObjectInfo = o2::ccdb::CcdbObjectInfo; using DQDoubles = std::deque; @@ -107,11 +106,7 @@ class TOFDCSProcessor const std::bitset& getHVStatus() const { return mHV; } bool isHVUpdated() const { return mUpdateHVStatus; } - /*template - void prepareCCDBobjectInfo(T& obj, CcdbObjectInfo& info, const std::string& path, TFType tf, - const std::map& md); - */ - void setTF(TFType tf) { mTF = tf; } + void setStartValidity(long t) { mStartValidity = t; } void useVerboseMode() { mVerbose = true; } void clearDPsinfo() @@ -137,31 +132,14 @@ class TOFDCSProcessor CcdbObjectInfo mccdbDPsInfo; CcdbObjectInfo mccdbLVInfo; CcdbObjectInfo mccdbHVInfo; - TFType mStartTF; // TF index for processing of first processed TF, used to store CCDB object - TFType mTF = 0; // TF index for processing, used to store CCDB object - bool mStartTFset = false; + long mFirstTime; // time when a CCDB object was stored first + long mStartValidity = 0; // TF index for processing, used to store CCDB object + bool mFirstTimeSet = false; bool mVerbose = false; ClassDefNV(TOFDCSProcessor, 0); }; -/* -template -void TOFDCSProcessor::prepareCCDBobjectInfo(T& obj, CcdbObjectInfo& info, const std::string& path, TFType tf, - const std::map& md) -{ - -// prepare all info to be sent to CCDB for object obj -auto clName = o2::utils::MemFileHelper::getClassName(obj); -auto flName = o2::ccdb::CcdbApi::generateFileName(clName); -info.setPath(path); -info.setObjectType(clName); -info.setFileName(flName); -info.setStartValidityTimestamp(tf); -info.setEndValidityTimestamp(99999999999999); -info.setMetaData(md); -} -*/ } // namespace tof } // namespace o2 diff --git a/Detectors/TOF/calibration/src/TOFDCSProcessor.cxx b/Detectors/TOF/calibration/src/TOFDCSProcessor.cxx index 90d9d7a5db73f..3625ecf8f2c6c 100644 --- a/Detectors/TOF/calibration/src/TOFDCSProcessor.cxx +++ b/Detectors/TOF/calibration/src/TOFDCSProcessor.cxx @@ -63,11 +63,11 @@ int TOFDCSProcessor::process(const gsl::span dps) // first we check which DPs are missing - if some are, it means that // the delta map was sent if (mVerbose) { - LOG(info) << "\n\n\nProcessing new TF\n-----------------"; + LOG(info) << "\n\n\nProcessing new DCS DP map\n-----------------"; } - if (!mStartTFset) { - mStartTF = mTF; - mStartTFset = true; + if (!mFirstTimeSet) { + mFirstTime = mStartValidity; + mFirstTimeSet = true; } std::unordered_map mapin; @@ -393,7 +393,7 @@ void TOFDCSProcessor::updateDPsCCDB() } std::map md; md["responsible"] = "Chiara Zampolli"; - o2::calibration::Utils::prepareCCDBobjectInfo(mTOFDCS, mccdbDPsInfo, "TOF/Calib/DCSDPs", mTF, md); + o2::calibration::Utils::prepareCCDBobjectInfo(mTOFDCS, mccdbDPsInfo, "TOF/Calib/DCSDPs", md, mStartValidity, o2::calibration::Utils::INFINITE_TIME); return; } @@ -410,7 +410,7 @@ void TOFDCSProcessor::updateFEACCCDB() } std::map md; md["responsible"] = "Chiara Zampolli"; - o2::calibration::Utils::prepareCCDBobjectInfo(mFeac, mccdbLVInfo, "TOF/Calib/LVStatus", mTF, md); + o2::calibration::Utils::prepareCCDBobjectInfo(mFeac, mccdbLVInfo, "TOF/Calib/LVStatus", md, mStartValidity, o2::calibration::Utils::INFINITE_TIME); return; } @@ -426,7 +426,7 @@ void TOFDCSProcessor::updateHVCCDB() } std::map md; md["responsible"] = "Chiara Zampolli"; - o2::calibration::Utils::prepareCCDBobjectInfo(mHV, mccdbHVInfo, "TOF/Calib/HVStatus", mTF, md); + o2::calibration::Utils::prepareCCDBobjectInfo(mHV, mccdbHVInfo, "TOF/Calib/HVStatus", md, mStartValidity, o2::calibration::Utils::INFINITE_TIME); return; } diff --git a/Detectors/TOF/calibration/testWorkflow/TOFDCSDataProcessorSpec.h b/Detectors/TOF/calibration/testWorkflow/TOFDCSDataProcessorSpec.h index a9292b56286b1..751380b83d925 100644 --- a/Detectors/TOF/calibration/testWorkflow/TOFDCSDataProcessorSpec.h +++ b/Detectors/TOF/calibration/testWorkflow/TOFDCSDataProcessorSpec.h @@ -106,11 +106,14 @@ class TOFDCSDataProcessor : public o2::framework::Task void run(o2::framework::ProcessingContext& pc) final { - auto tfid = o2::header::get(pc.inputs().get("input").header)->startTime; + auto startValidity = DataRefUtils::getHeader(pc.inputs().getFirstValid(true))->creation; auto dps = pc.inputs().get>("input"); - mProcessor->setTF(tfid); - mProcessor->process(dps); auto timeNow = HighResClock::now(); + if (startValidity == 0xffffffffffffffff) { // it means it is not set + startValidity = std::chrono::duration_cast(timeNow.time_since_epoch()).count(); // in ms + } + mProcessor->setStartValidity(startValidity); + mProcessor->process(dps); Duration elapsedTime = timeNow - mTimer; // in seconds if (elapsedTime.count() >= mDPsUpdateInterval) { sendDPsoutput(pc.outputs());