From 4ffbb2890fb66c553c65d57df1df03db722814ea Mon Sep 17 00:00:00 2001 From: Chiara Zampolli Date: Tue, 12 Oct 2021 16:09:08 +0200 Subject: [PATCH 1/9] Adding GRPECSObject clang-format --- .../DetectorsCommonDataFormats/NameConf.h | 5 + DataFormats/Detectors/Common/src/NameConf.cxx | 6 + DataFormats/Parameters/CMakeLists.txt | 2 + .../DataFormatsParameters/GRPECSObject.h | 125 ++++++++++++++++++ DataFormats/Parameters/src/GRPECSObject.cxx | 98 ++++++++++++++ .../Parameters/src/ParametersDataLinkDef.h | 1 + macro/CMakeLists.txt | 8 +- macro/CreateGRPECSObject.C | 60 +++++++++ 8 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 DataFormats/Parameters/include/DataFormatsParameters/GRPECSObject.h create mode 100644 DataFormats/Parameters/src/GRPECSObject.cxx create mode 100644 macro/CreateGRPECSObject.C diff --git a/DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/NameConf.h b/DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/NameConf.h index ad998115ea3a5..4db785b77d6a1 100644 --- a/DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/NameConf.h +++ b/DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/NameConf.h @@ -49,6 +49,9 @@ class NameConf : public o2::conf::ConfigurableParamHelper // Filename of general run parameters (GRP) static std::string getGRPFileName(const std::string_view prefix = STANDARDSIMPREFIX); + // Filename of general run parameters from ECS (GRPECS) + static std::string getGRPECSFileName(const std::string_view prefix = STANDARDSIMPREFIX); + // Filename to store kinematics + TrackRefs static std::string getMCKinematicsFileName(const std::string_view prefix = STANDARDSIMPREFIX) { @@ -119,6 +122,7 @@ class NameConf : public o2::conf::ConfigurableParamHelper static constexpr std::string_view HITS_STRING = "Hits"; // hardcoded static constexpr std::string_view DIGITS_STRING = "Digits"; // hardcoded static constexpr std::string_view GRP_STRING = "grp"; // hardcoded + static constexpr std::string_view GRPECS_STRING = "grpecs"; // hardcoded static constexpr std::string_view KINE_STRING = "Kine"; // hardcoded static constexpr std::string_view MCHEADER_STRING = "MCHeader"; // hardcoded static constexpr std::string_view GEOM_FILE_STRING = "geometry"; @@ -134,6 +138,7 @@ class NameConf : public o2::conf::ConfigurableParamHelper // these are configurable paths for some commonly used files std::string mDirGRP = "none"; // directory for GRP file ("none" == "") + std::string mDirGRPECS = "none"; // directory for GRPECS file ("none" == "") std::string mDirGeom = "none"; // directory for geometry file std::string mDirMatLUT = "none"; // directory for material LUT std::string mDirCollContext = "none"; // directory for collision context diff --git a/DataFormats/Detectors/Common/src/NameConf.cxx b/DataFormats/Detectors/Common/src/NameConf.cxx index 6fc949b742cce..92da712347206 100644 --- a/DataFormats/Detectors/Common/src/NameConf.cxx +++ b/DataFormats/Detectors/Common/src/NameConf.cxx @@ -55,6 +55,12 @@ std::string NameConf::getGRPFileName(const std::string_view prefix) return buildFileName(prefix, "_", STANDARDSIMPREFIX, GRP_STRING, ROOT_EXT_STRING, Instance().mDirGRP); } +// Filename to store general run parameters from ECS (GRPECS) +std::string NameConf::getGRPECSFileName(const std::string_view prefix) +{ + return buildFileName(prefix, "_", STANDARDSIMPREFIX, GRPECS_STRING, ROOT_EXT_STRING, Instance().mDirGRPECS); +} + // Filename to store simulation cuts/process summary std::string NameConf::getCutProcFileName(std::string_view prefix) { diff --git a/DataFormats/Parameters/CMakeLists.txt b/DataFormats/Parameters/CMakeLists.txt index 49bf5f6099fdc..e91329bfb1fa7 100644 --- a/DataFormats/Parameters/CMakeLists.txt +++ b/DataFormats/Parameters/CMakeLists.txt @@ -12,6 +12,7 @@ o2_add_library(DataFormatsParameters SOURCES src/GRPObject.cxx src/LHCIFData.cxx + src/GRPECSObject.cxx PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CommonConstants O2::CommonTypes O2::DetectorsCommonDataFormats) @@ -19,6 +20,7 @@ o2_add_library(DataFormatsParameters o2_target_root_dictionary(DataFormatsParameters HEADERS include/DataFormatsParameters/GRPObject.h include/DataFormatsParameters/LHCIFData.h + include/DataFormatsParameters/GRPECSObject.h LINKDEF src/ParametersDataLinkDef.h) diff --git a/DataFormats/Parameters/include/DataFormatsParameters/GRPECSObject.h b/DataFormats/Parameters/include/DataFormatsParameters/GRPECSObject.h new file mode 100644 index 0000000000000..404dc00064bf0 --- /dev/null +++ b/DataFormats/Parameters/include/DataFormatsParameters/GRPECSObject.h @@ -0,0 +1,125 @@ +// 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 GRPECSObject.h +/// \brief Header of the General Run Parameters object +/// \author ruben.shahoyan@cern.ch + +#ifndef ALICEO2_DATA_GRPECSOBJECT_H_ +#define ALICEO2_DATA_GRPECSOBJECT_H_ + +#include +#include +#include +#include "DetectorsCommonDataFormats/DetID.h" + +namespace o2 +{ +namespace parameters +{ +/* + * Collects parameters describing the run that come from ECS only. + */ + +class GRPECSObject +{ + using DetID = o2::detectors::DetID; + + public: + using timePoint = std::time_t; + + enum ROMode : int { ABSENT = 0, + PRESENT = 0x1, + CONTINUOUS = PRESENT + (0x1 << 1), + TRIGGERING = PRESENT + (0x1 << 2) }; + + GRPECSObject() = default; + ~GRPECSObject() = default; + + /// getters/setters for Start and Stop times according to logbook + timePoint getTimeStart() const { return mTimeStart; } + void setTimeStart(timePoint t) { mTimeStart = t; } + + void setNHBFPerTF(uint32_t n) { mNHBFPerTF = n; } + uint32_t getNHBFPerTF() const { return mNHBFPerTF; } + + /// getter/setter for data taking period name + const std::string& getDataPeriod() const { return mDataPeriod; } + void setDataPeriod(const std::string v) { mDataPeriod = v; } + // getter/setter for run identifier + void setRun(int r) { mRun = r; } + int getRun() const { return mRun; } + /// getter/setter for masks of detectors in the readout + DetID::mask_t getDetsReadOut() const { return mDetsReadout; } + void setDetsReadOut(DetID::mask_t mask) { mDetsReadout = mask; } + /// getter/setter for masks of detectors with continuos readout + DetID::mask_t getDetsContinuousReadOut() const { return mDetsContinuousRO; } + void setDetsContinuousReadOut(DetID::mask_t mask) { mDetsContinuousRO = mask; } + /// getter/setter for masks of detectors providing the trigger + DetID::mask_t getDetsTrigger() const { return mDetsTrigger; } + void setDetsTrigger(DetID::mask_t mask) { mDetsTrigger = mask; } + /// add specific detector to the list of readout detectors + void addDetReadOut(DetID id) { mDetsReadout |= id.getMask(); } + /// remove specific detector from the list of readout detectors + void remDetReadOut(DetID id) + { + mDetsReadout &= ~id.getMask(); + remDetContinuousReadOut(id); + remDetTrigger(id); + } + /// add specific detector to the list of continuously readout detectors + void addDetContinuousReadOut(DetID id) { mDetsContinuousRO |= id.getMask(); } + /// remove specific detector from the list of continuouslt readout detectors + void remDetContinuousReadOut(DetID id) { mDetsContinuousRO &= ~id.getMask(); } + /// add specific detector to the list of triggering detectors + void addDetTrigger(DetID id) { mDetsTrigger |= id.getMask(); } + /// remove specific detector from the list of triggering detectors + void remDetTrigger(DetID id) { mDetsTrigger &= ~id.getMask(); } + /// test if detector is read out + bool isDetReadOut(DetID id) const { return (mDetsReadout & id.getMask()) != 0; } + /// test if detector is read out + bool isDetContinuousReadOut(DetID id) const { return (mDetsContinuousRO & id.getMask()) != 0; } + /// test if detector is triggering + bool isDetTriggers(DetID id) const { return (mDetsTrigger & id.getMask()) != 0; } + /// set detector readout mode status + void setDetROMode(DetID id, ROMode status); + ROMode getDetROMode(DetID id) const; + + /// extra selections + /// mask of readout detectors with addition selections. "only" overrides "skip" + DetID::mask_t getDetsReadOut(DetID::mask_t only, DetID::mask_t skip = 0) const { return only.any() ? (mDetsReadout & only) : (mDetsReadout ^ skip); } + /// same with comma-separate list of detector names + DetID::mask_t getDetsReadOut(const std::string& only, const std::string& skip = "") const { return getDetsReadOut(DetID::getMask(only), DetID::getMask(skip)); } + + /// print itself + void print() const; + + static GRPECSObject* loadFrom(const std::string& grpecsFileName = "", const std::string& grpecsName = "GRPECS"); + + private: + timePoint mTimeStart = 0; ///< DAQ_time_start entry from DAQ logbook + + uint32_t mNHBFPerTF = 256; /// Number of HBFrames per TF + + DetID::mask_t mDetsReadout; ///< mask of detectors which are read out + DetID::mask_t mDetsContinuousRO; ///< mask of detectors read out in continuos mode + DetID::mask_t mDetsTrigger; ///< mask of detectors which provide trigger + + int mRun = 0; ///< run identifier + std::string mDataPeriod = ""; ///< name of the period + + ClassDefNV(GRPECSObject, 1); +}; + +} // namespace parameters +} // namespace o2 + +#endif diff --git a/DataFormats/Parameters/src/GRPECSObject.cxx b/DataFormats/Parameters/src/GRPECSObject.cxx new file mode 100644 index 0000000000000..021a4d7ac8e02 --- /dev/null +++ b/DataFormats/Parameters/src/GRPECSObject.cxx @@ -0,0 +1,98 @@ +// 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 GRPECSObject.cxx +/// \brief Implementation of General Run Parameters object +/// \author ruben.shahoyan@cern.ch + +#include +#include +#include "DataFormatsParameters/GRPECSObject.h" +#include +#include "DetectorsCommonDataFormats/NameConf.h" + +using namespace o2::parameters; +using o2::detectors::DetID; + +//_______________________________________________ +void GRPECSObject::print() const +{ + // print itself + std::time_t t = mTimeStart; // system_clock::to_time_t(mTimeStart); + printf("Start: %s", std::ctime(&t)); + printf("Detectors: Cont.RO Triggers\n"); + for (auto i = DetID::First; i <= DetID::Last; i++) { + if (!isDetReadOut(DetID(i))) { + continue; + } + printf("%9s: ", DetID(i).getName()); + printf("%7s ", isDetContinuousReadOut(DetID(i)) ? " + " : " - "); + printf("%7s ", isDetTriggers(DetID(i)) ? " + " : " - "); + printf("\n"); + } +} + +//_______________________________________________ +void GRPECSObject::setDetROMode(o2::detectors::DetID id, ROMode status) +{ + /// set detector readout mode status + if (!(status & PRESENT)) { + remDetReadOut(id); + return; + } + addDetReadOut(id); + if ((status & CONTINUOUS) == CONTINUOUS) { + addDetContinuousReadOut(id); + } else { + remDetContinuousReadOut(id); + } + if ((status & TRIGGERING) == TRIGGERING) { + addDetTrigger(id); + } else { + remDetTrigger(id); + } +} + +//_______________________________________________ +GRPECSObject::ROMode GRPECSObject::getDetROMode(o2::detectors::DetID id) const +{ + GRPECSObject::ROMode status = ABSENT; + if (isDetReadOut(id)) { + status = PRESENT; + } else { + if (isDetContinuousReadOut(id)) { + status = GRPECSObject::ROMode(status | CONTINUOUS); + } + if (isDetTriggers(id)) { + status = GRPECSObject::ROMode(status | TRIGGERING); + } + } + return status; +} + +//_______________________________________________ +GRPECSObject* GRPECSObject::loadFrom(const std::string& grpecsFileName, const std::string& grpecsName) +{ + // load object from file + auto fname = o2::base::NameConf::getGRPECSFileName(grpecsFileName); + TFile flGRPECS(fname.c_str()); + if (flGRPECS.IsZombie()) { + LOG(ERROR) << "Failed to open " << fname; + throw std::runtime_error("Failed to open GRP ECS file"); + } + auto grpecs = reinterpret_cast( + flGRPECS.GetObjectChecked(grpecsName.data(), o2::parameters::GRPECSObject::Class())); + if (!grpecs) { + LOG(ERROR) << "Did not find GRP ECS object named " << grpecsName; + throw std::runtime_error("Failed to load GRP ECS object"); + } + return grpecs; +} diff --git a/DataFormats/Parameters/src/ParametersDataLinkDef.h b/DataFormats/Parameters/src/ParametersDataLinkDef.h index da7124658164a..fb39e49335bf1 100644 --- a/DataFormats/Parameters/src/ParametersDataLinkDef.h +++ b/DataFormats/Parameters/src/ParametersDataLinkDef.h @@ -26,5 +26,6 @@ #pragma link C++ class o2::parameters::GRPObject + ; #pragma link C++ class o2::parameters::LHCIFData + ; #pragma link C++ class std::pair < long, std::string> + ; +#pragma link C++ class o2::parameters::GRPECSObject + ; #endif diff --git a/macro/CMakeLists.txt b/macro/CMakeLists.txt index a81f3d529a2a7..8ba8e1924b8ff 100644 --- a/macro/CMakeLists.txt +++ b/macro/CMakeLists.txt @@ -53,7 +53,8 @@ install(FILES CheckDigits_mft.C run_trac_its.C CreateBCPattern.C UploadDummyAlignment.C - CreateCTPOrbitResetObject.C + CreateCTPOrbitResetObject.C + CreateGRPECSObject.C DESTINATION share/macro/) # FIXME: a lot of macros that are here should really be elsewhere. Those which @@ -345,6 +346,11 @@ o2_add_test_root_macro(run_trac_its.C O2::SimulationDataFormat LABELS its) +o2_add_test_root_macro(CreateGRPECSObject.C + PUBLIC_LINK_LIBRARIES O2::DataFormatsParameters + O2::DetectorsCommonDataFormats + O2::CCDB) + # # NOTE: commented out until unit testing reenabled FIXME : re-enable or delete ? # diff --git a/macro/CreateGRPECSObject.C b/macro/CreateGRPECSObject.C new file mode 100644 index 0000000000000..1eec113324765 --- /dev/null +++ b/macro/CreateGRPECSObject.C @@ -0,0 +1,60 @@ +// 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. + +#if !defined(__CLING__) || defined(__ROOTCLING__) + +#include +#include +#include "DataFormatsParameters/GRPECSObject.h" +#include "DetectorsCommonDataFormats/DetID.h" +#include "CCDB/CcdbApi.h" + +#endif + +using timePoint = std::time_t; +using DetID = o2::detectors::DetID; +using CcdbApi = o2::ccdb::CcdbApi; +using GRPECSObject = o2::parameters::GRPECSObject; + +// Simple macro to exemplify how to fill a GRPECS object (GRP object containing the information that come from ECS) + +// The list of detectors in the readout, read-out continuously, or in the trigger are passed as DetID::mask_it; this is a std::bitset<32>, with the following meaning per bit: +// {"ITS", "TPC", "TRD", "TOF", "PHS", "CPV", "EMC", "HMP", "MFT", "MCH", "MID", "ZDC", "FT0", "FV0", "FDD", "ACO", "CTP"} + +// e.g. +/* + .L CreateGRPECSObject.C+ + std::time_t t = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() + o2::detectors::DetID::mask_t detsRO = o2::detectors::DetID::getMask("ITS, TPC, TRD, TOF, CPV, PHS, EMC, MID, MFT, MCH, FT0, FV0, FDD, CTP"); + o2::detectors::DetID::mask_t detsContRO = o2::detectors::DetID::getMask("TOF, TPC, ITS") + o2::detectors::DetID::mask_t detsTrig = o2::detectors::DetID::getMask("FV0") + CreateGRPECSObject(t, 128, detsRO, detsContRO, detsTrig, 123456, "LHC21m") +*/ + +void CreateGRPECSObject(timePoint start, uint32_t nHBPerTF, DetID::mask_t detsReadout, DetID::mask_t detsContinuousRO, DetID::mask_t detsTrigger, int run, std::string dataPeriod, std::string ccdbPath = "http://ccdb-test.cern.ch:8080") +{ + + GRPECSObject grpecs; + grpecs.setTimeStart(start); + grpecs.setNHBFPerTF(nHBPerTF); + grpecs.setDetsReadOut(detsReadout); + grpecs.setDetsContinuousReadOut(detsContinuousRO); + grpecs.setDetsTrigger(detsTrigger); + grpecs.setRun(run); + grpecs.setDataPeriod(dataPeriod); + + CcdbApi api; + api.init(ccdbPath); + std::map metadata; + metadata["responsible"] = "ECS"; + long ts = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + api.storeAsTFileAny(&grpecs, "GRP/GRP/ECS", metadata, ts, ts + 60 * 60 * 24 * 365); // making it 1-year valid to be sure we have something +} From a7f27a73e7d4422137f108be3e168b8fae178253 Mon Sep 17 00:00:00 2001 From: Chiara Zampolli Date: Fri, 15 Oct 2021 22:54:20 +0200 Subject: [PATCH 2/9] Review --- .../include/DataFormatsParameters/GRPECSObject.h | 2 +- macro/CreateGRPECSObject.C | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/DataFormats/Parameters/include/DataFormatsParameters/GRPECSObject.h b/DataFormats/Parameters/include/DataFormatsParameters/GRPECSObject.h index 404dc00064bf0..77bb1c52cd897 100644 --- a/DataFormats/Parameters/include/DataFormatsParameters/GRPECSObject.h +++ b/DataFormats/Parameters/include/DataFormatsParameters/GRPECSObject.h @@ -107,7 +107,7 @@ class GRPECSObject private: timePoint mTimeStart = 0; ///< DAQ_time_start entry from DAQ logbook - uint32_t mNHBFPerTF = 256; /// Number of HBFrames per TF + uint32_t mNHBFPerTF = 128; /// Number of HBFrames per TF DetID::mask_t mDetsReadout; ///< mask of detectors which are read out DetID::mask_t mDetsContinuousRO; ///< mask of detectors read out in continuos mode diff --git a/macro/CreateGRPECSObject.C b/macro/CreateGRPECSObject.C index 1eec113324765..4bce6d682e071 100644 --- a/macro/CreateGRPECSObject.C +++ b/macro/CreateGRPECSObject.C @@ -32,14 +32,15 @@ using GRPECSObject = o2::parameters::GRPECSObject; // e.g. /* .L CreateGRPECSObject.C+ - std::time_t t = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() + std::time_t tStart = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() + std::time_t tEnd = (tStart + 60 * 60 * 24 * 365) * 1000; // 1 year validity, just an example o2::detectors::DetID::mask_t detsRO = o2::detectors::DetID::getMask("ITS, TPC, TRD, TOF, CPV, PHS, EMC, MID, MFT, MCH, FT0, FV0, FDD, CTP"); o2::detectors::DetID::mask_t detsContRO = o2::detectors::DetID::getMask("TOF, TPC, ITS") o2::detectors::DetID::mask_t detsTrig = o2::detectors::DetID::getMask("FV0") - CreateGRPECSObject(t, 128, detsRO, detsContRO, detsTrig, 123456, "LHC21m") + CreateGRPECSObject(tStart, 128, detsRO, detsContRO, detsTrig, 123456, "LHC21m", tEnd) */ -void CreateGRPECSObject(timePoint start, uint32_t nHBPerTF, DetID::mask_t detsReadout, DetID::mask_t detsContinuousRO, DetID::mask_t detsTrigger, int run, std::string dataPeriod, std::string ccdbPath = "http://ccdb-test.cern.ch:8080") +void CreateGRPECSObject(timePoint start, uint32_t nHBPerTF, DetID::mask_t detsReadout, DetID::mask_t detsContinuousRO, DetID::mask_t detsTrigger, int run, std::string dataPeriod, timePoint end = -1, std::string ccdbPath = "http://ccdb-test.cern.ch:8080") { GRPECSObject grpecs; @@ -55,6 +56,10 @@ void CreateGRPECSObject(timePoint start, uint32_t nHBPerTF, DetID::mask_t detsRe api.init(ccdbPath); std::map metadata; metadata["responsible"] = "ECS"; - long ts = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - api.storeAsTFileAny(&grpecs, "GRP/GRP/ECS", metadata, ts, ts + 60 * 60 * 24 * 365); // making it 1-year valid to be sure we have something + metadata["run_number"] = std::to_string(run); + //long ts = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + if (end < 0) { + end = (start + 60 * 60 * 10) * 1000; // start + 10h, in ms + } + api.storeAsTFileAny(&grpecs, "GLO/Config/GRPECS", metadata, start * 1000, end); // making it 1-year valid to be sure we have something } From df8ed9b8117eac058fd00995f3ebef07a5ab5bae Mon Sep 17 00:00:00 2001 From: Chiara Zampolli Date: Sat, 16 Oct 2021 00:10:37 +0200 Subject: [PATCH 3/9] MagField object added clang-format --- .../DetectorsCommonDataFormats/NameConf.h | 5 ++ DataFormats/Detectors/Common/src/NameConf.cxx | 6 ++ DataFormats/Parameters/CMakeLists.txt | 2 + .../DataFormatsParameters/GRPMagField.h | 61 +++++++++++++++++++ DataFormats/Parameters/src/GRPECSObject.cxx | 2 +- DataFormats/Parameters/src/GRPMagField.cxx | 39 ++++++++++++ .../Parameters/src/ParametersDataLinkDef.h | 1 + macro/CMakeLists.txt | 13 ++++ macro/CreateGRPMagFieldObject.C | 59 ++++++++++++++++++ 9 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 DataFormats/Parameters/include/DataFormatsParameters/GRPMagField.h create mode 100644 DataFormats/Parameters/src/GRPMagField.cxx create mode 100644 macro/CreateGRPMagFieldObject.C diff --git a/DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/NameConf.h b/DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/NameConf.h index 4db785b77d6a1..ff693897021de 100644 --- a/DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/NameConf.h +++ b/DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/NameConf.h @@ -52,6 +52,9 @@ class NameConf : public o2::conf::ConfigurableParamHelper // Filename of general run parameters from ECS (GRPECS) static std::string getGRPECSFileName(const std::string_view prefix = STANDARDSIMPREFIX); + // Filename of general run parameters fof B field (GRPMagField) + static std::string getGRPMagFieldFileName(const std::string_view prefix = STANDARDSIMPREFIX); + // Filename to store kinematics + TrackRefs static std::string getMCKinematicsFileName(const std::string_view prefix = STANDARDSIMPREFIX) { @@ -123,6 +126,7 @@ class NameConf : public o2::conf::ConfigurableParamHelper static constexpr std::string_view DIGITS_STRING = "Digits"; // hardcoded static constexpr std::string_view GRP_STRING = "grp"; // hardcoded static constexpr std::string_view GRPECS_STRING = "grpecs"; // hardcoded + static constexpr std::string_view GRPMAGFIELD_STRING = "grpMagField"; // hardcoded static constexpr std::string_view KINE_STRING = "Kine"; // hardcoded static constexpr std::string_view MCHEADER_STRING = "MCHeader"; // hardcoded static constexpr std::string_view GEOM_FILE_STRING = "geometry"; @@ -139,6 +143,7 @@ class NameConf : public o2::conf::ConfigurableParamHelper // these are configurable paths for some commonly used files std::string mDirGRP = "none"; // directory for GRP file ("none" == "") std::string mDirGRPECS = "none"; // directory for GRPECS file ("none" == "") + std::string mDirGRPMagField = "none"; // directory for GRPMagField file ("none" == "") std::string mDirGeom = "none"; // directory for geometry file std::string mDirMatLUT = "none"; // directory for material LUT std::string mDirCollContext = "none"; // directory for collision context diff --git a/DataFormats/Detectors/Common/src/NameConf.cxx b/DataFormats/Detectors/Common/src/NameConf.cxx index 92da712347206..e2eeea64d007f 100644 --- a/DataFormats/Detectors/Common/src/NameConf.cxx +++ b/DataFormats/Detectors/Common/src/NameConf.cxx @@ -61,6 +61,12 @@ std::string NameConf::getGRPECSFileName(const std::string_view prefix) return buildFileName(prefix, "_", STANDARDSIMPREFIX, GRPECS_STRING, ROOT_EXT_STRING, Instance().mDirGRPECS); } +// Filename to store general run parameters from ECS (GRPECS) +std::string NameConf::getGRPMagFieldFileName(const std::string_view prefix) +{ + return buildFileName(prefix, "_", STANDARDSIMPREFIX, GRPMAGFIELD_STRING, ROOT_EXT_STRING, Instance().mDirGRPMagField); +} + // Filename to store simulation cuts/process summary std::string NameConf::getCutProcFileName(std::string_view prefix) { diff --git a/DataFormats/Parameters/CMakeLists.txt b/DataFormats/Parameters/CMakeLists.txt index e91329bfb1fa7..2c3cca3f64594 100644 --- a/DataFormats/Parameters/CMakeLists.txt +++ b/DataFormats/Parameters/CMakeLists.txt @@ -13,6 +13,7 @@ o2_add_library(DataFormatsParameters SOURCES src/GRPObject.cxx src/LHCIFData.cxx src/GRPECSObject.cxx + src/GRPMagField.cxx PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CommonConstants O2::CommonTypes O2::DetectorsCommonDataFormats) @@ -21,6 +22,7 @@ o2_target_root_dictionary(DataFormatsParameters HEADERS include/DataFormatsParameters/GRPObject.h include/DataFormatsParameters/LHCIFData.h include/DataFormatsParameters/GRPECSObject.h + include/DataFormatsParameters/GRPMagField.h LINKDEF src/ParametersDataLinkDef.h) diff --git a/DataFormats/Parameters/include/DataFormatsParameters/GRPMagField.h b/DataFormats/Parameters/include/DataFormatsParameters/GRPMagField.h new file mode 100644 index 0000000000000..8f4f1185c9b5d --- /dev/null +++ b/DataFormats/Parameters/include/DataFormatsParameters/GRPMagField.h @@ -0,0 +1,61 @@ +// 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 GRPMagField.h +/// \brief Header of the General Run Parameters object for B field values +/// \author ruben.shahoyan@cern.ch + +#ifndef ALICEO2_DATA_GRPMAGFIELDOBJECT_H_ +#define ALICEO2_DATA_GRPMAGFIELDOBJECT_H_ + +#include +#include +#include "CommonTypes/Units.h" + +namespace o2 +{ +namespace parameters +{ +/* + * Collects parameters describing the run that are related to the B field only. +*/ + +class GRPMagField +{ + public: + GRPMagField() = default; + ~GRPMagField() = default; + + /// getters/setters for magnets currents + o2::units::Current_t getL3Current() const { return mL3Current; } + o2::units::Current_t getDipoleCurrent() const { return mDipoleCurrent; } + bool getFieldUniformity() const { return mUniformField; } + void setL3Current(o2::units::Current_t v) { mL3Current = v; } + void setDipoleCurrent(o2::units::Current_t v) { mDipoleCurrent = v; } + void setFieldUniformity(bool v) { mUniformField = v; } + + /// print itself + void print() const { printf("magnet currents (A) L3 = %.3f, Dipole = %.f; uniformity = %s\n", getL3Current(), getDipoleCurrent(), mUniformField ? "true" : "false"); } + + static GRPMagField* loadFrom(const std::string& grpMagFieldFileName = "", const std::string& grpMagFieldName = "GRPMAGFIELD"); + + private: + o2::units::Current_t mL3Current = 0.f; ///< signed current in L3 + o2::units::Current_t mDipoleCurrent = 0.f; ///< signed current in Dipole + bool mUniformField = false; ///< uniformity of magnetic field + + ClassDefNV(GRPMagField, 1); +}; + +} // namespace parameters +} // namespace o2 + +#endif diff --git a/DataFormats/Parameters/src/GRPECSObject.cxx b/DataFormats/Parameters/src/GRPECSObject.cxx index 021a4d7ac8e02..0121d94b5fe94 100644 --- a/DataFormats/Parameters/src/GRPECSObject.cxx +++ b/DataFormats/Parameters/src/GRPECSObject.cxx @@ -10,7 +10,7 @@ // or submit itself to any jurisdiction. /// \file GRPECSObject.cxx -/// \brief Implementation of General Run Parameters object +/// \brief Implementation of General Run Parameters object from ECS /// \author ruben.shahoyan@cern.ch #include diff --git a/DataFormats/Parameters/src/GRPMagField.cxx b/DataFormats/Parameters/src/GRPMagField.cxx new file mode 100644 index 0000000000000..1413e4c91c6dd --- /dev/null +++ b/DataFormats/Parameters/src/GRPMagField.cxx @@ -0,0 +1,39 @@ +// 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 GRPMagField.cxx +/// \brief Implementation of General Run Parameters object for MagField +/// \author ruben.shahoyan@cern.ch + +#include +#include "DataFormatsParameters/GRPMagField.h" +#include "DetectorsCommonDataFormats/NameConf.h" + +using namespace o2::parameters; + +//_______________________________________________ +GRPMagField* GRPMagField::loadFrom(const std::string& grpMagFieldFileName, const std::string& grpMagFieldName) +{ + // load object from file + auto fname = o2::base::NameConf::getGRPMagFieldFileName(grpMagFieldFileName); + TFile flGRPMagField(fname.c_str()); + if (flGRPMagField.IsZombie()) { + LOG(ERROR) << "Failed to open " << fname; + throw std::runtime_error("Failed to open GRP Mag Field file"); + } + auto grpMagField = reinterpret_cast( + flGRPMagField.GetObjectChecked(grpMagFieldName.data(), o2::parameters::GRPMagField::Class())); + if (!grpMagField) { + LOG(ERROR) << "Did not find GRP Mag Field object named " << grpMagFieldName; + throw std::runtime_error("Failed to load GRP Mag Field object"); + } + return grpMagField; +} diff --git a/DataFormats/Parameters/src/ParametersDataLinkDef.h b/DataFormats/Parameters/src/ParametersDataLinkDef.h index fb39e49335bf1..72be02b31d514 100644 --- a/DataFormats/Parameters/src/ParametersDataLinkDef.h +++ b/DataFormats/Parameters/src/ParametersDataLinkDef.h @@ -27,5 +27,6 @@ #pragma link C++ class o2::parameters::LHCIFData + ; #pragma link C++ class std::pair < long, std::string> + ; #pragma link C++ class o2::parameters::GRPECSObject + ; +#pragma link C++ class o2::parameters::GRPMagField + ; #endif diff --git a/macro/CMakeLists.txt b/macro/CMakeLists.txt index 8ba8e1924b8ff..2c0f6f75ea57d 100644 --- a/macro/CMakeLists.txt +++ b/macro/CMakeLists.txt @@ -55,6 +55,7 @@ install(FILES CheckDigits_mft.C UploadDummyAlignment.C CreateCTPOrbitResetObject.C CreateGRPECSObject.C + CreateGRPMagFieldObject.C DESTINATION share/macro/) # FIXME: a lot of macros that are here should really be elsewhere. Those which @@ -351,6 +352,18 @@ o2_add_test_root_macro(CreateGRPECSObject.C O2::DetectorsCommonDataFormats O2::CCDB) +o2_add_test_root_macro(CreateGRPMagFieldObject.C + PUBLIC_LINK_LIBRARIES O2::DataFormatsParameters + O2::CommonTypes + O2::CCDB) + +o2_add_test_root_macro(UploadMatBudLUT.C + PUBLIC_LINK_LIBRARIES O2::DetectorsCommonDataFormats + O2::CCDB + O2::DataFormatsParameters + O2::DetectorsBase + O2::CommonUtils) + # # NOTE: commented out until unit testing reenabled FIXME : re-enable or delete ? # diff --git a/macro/CreateGRPMagFieldObject.C b/macro/CreateGRPMagFieldObject.C new file mode 100644 index 0000000000000..e868365135cde --- /dev/null +++ b/macro/CreateGRPMagFieldObject.C @@ -0,0 +1,59 @@ +// 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. + +#if !defined(__CLING__) || defined(__ROOTCLING__) + +#include +#include +#include "DataFormatsParameters/GRPMagField.h" +#include "CCDB/CcdbApi.h" +#include "CommonTypes/Units.h" + +#endif + +using timePoint = std::time_t; +using CcdbApi = o2::ccdb::CcdbApi; +using GRPMagField = o2::parameters::GRPMagField; +using current = o2::units::Current_t; + +// Simple macro to exemplify how to fill a GRPMagField object (GRP object containing the information on the magnetic field) + +// e.g. +/* + .L CreateGRPMagFieldObject.C+ + float l3 = 30000 // Ampere + float dipole = 6000 // Ampere + std::time_t tStart = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() + std::time_t tEnd = (tStart + 60 * 60 * 24 * 365) * 1000; // 1 year validity, just an example + bool isUniform = true + int runNb = 123456 + CreateGRPMagFieldObject(l3, dipole, tStart, runNb, tEnd, isUniform) +*/ + +void CreateGRPMagFieldObject(current l3, current dipole, timePoint start, int run, timePoint end = -1, bool isUniform = true, std::string ccdbPath = "http://ccdb-test.cern.ch:8080") +{ + + GRPMagField grp; + grp.setL3Current(l3); + grp.setDipoleCurrent(dipole); + grp.setFieldUniformity(isUniform); + + CcdbApi api; + api.init(ccdbPath); + std::map metadata; + metadata["responsible"] = "DCS"; + metadata["run_number"] = std::to_string(run); + //long ts = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + if (end < 0) { + end = (start + 60 * 60 * 10) * 1000; // start + 10h, in ms + } + api.storeAsTFileAny(&grp, "GLO/Config/GRPMagField", metadata, start * 1000, end); // making it 1-year valid to be sure we have something +} From 535ae49e223be18119ff780799cc89882307e286 Mon Sep 17 00:00:00 2001 From: Chiara Zampolli Date: Tue, 19 Oct 2021 00:13:51 +0200 Subject: [PATCH 4/9] Restructuring a bit object for LHC_IF information --- DataFormats/Parameters/CMakeLists.txt | 4 +- .../DataFormatsParameters/GRPLHCIFData.h | 114 ++++++++++++++++++ .../include/DataFormatsParameters/LHCIFData.h | 74 ------------ DataFormats/Parameters/src/GRPLHCIFData.cxx | 78 ++++++++++++ DataFormats/Parameters/src/LHCIFData.cxx | 15 --- .../Parameters/src/ParametersDataLinkDef.h | 2 +- .../include/GRPWorkflows/GRPLHCIFfileSpec.h | 4 +- .../GRP/workflows/src/GRPLHCIFfileSpec.cxx | 51 +++++--- 8 files changed, 231 insertions(+), 111 deletions(-) create mode 100644 DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h delete mode 100644 DataFormats/Parameters/include/DataFormatsParameters/LHCIFData.h create mode 100644 DataFormats/Parameters/src/GRPLHCIFData.cxx delete mode 100644 DataFormats/Parameters/src/LHCIFData.cxx diff --git a/DataFormats/Parameters/CMakeLists.txt b/DataFormats/Parameters/CMakeLists.txt index 2c3cca3f64594..562d2209c3441 100644 --- a/DataFormats/Parameters/CMakeLists.txt +++ b/DataFormats/Parameters/CMakeLists.txt @@ -11,7 +11,7 @@ o2_add_library(DataFormatsParameters SOURCES src/GRPObject.cxx - src/LHCIFData.cxx + src/GRPLHCIFData.cxx src/GRPECSObject.cxx src/GRPMagField.cxx PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CommonConstants @@ -20,7 +20,7 @@ o2_add_library(DataFormatsParameters o2_target_root_dictionary(DataFormatsParameters HEADERS include/DataFormatsParameters/GRPObject.h - include/DataFormatsParameters/LHCIFData.h + include/DataFormatsParameters/GRPLHCIFData.h include/DataFormatsParameters/GRPECSObject.h include/DataFormatsParameters/GRPMagField.h LINKDEF src/ParametersDataLinkDef.h) diff --git a/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h b/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h new file mode 100644 index 0000000000000..a8497d6259bd3 --- /dev/null +++ b/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h @@ -0,0 +1,114 @@ +// 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 GRPLHCIFData.h +/// \brief container for the LHC InterFace data + +#ifndef O2_GRP_LHCIFDATA_H +#define O2_GRP_LHCIFDATA_H + +#include +#include +#include +#include +#include "CommonTypes/Units.h" +#include "CommonConstants/LHCConstants.h" + +namespace o2 +{ +namespace parameters +{ + +class GRPLHCIFData +{ + + using beamDirection = o2::constants::lhc::BeamDirection; + + public: + GRPLHCIFData() = default; + ~GRPLHCIFData() = default; + + static const std::unordered_map mZtoA; + + std::pair getBeamEnergyPerZWithTime() const { return mBeamEnergyPerZ; } + int32_t getBeamEnergyPerZ() const { return mBeamEnergyPerZ.second; } + long getBeamEnergyPerZTime() const { return mBeamEnergyPerZ.first; } + void setBeamEnergyPerZWithTime(std::pair p) { mBeamEnergyPerZ = p; } + void setBeamEnergyPerZWithTime(long t, int32_t v) { mBeamEnergyPerZ = std::make_pair(t, v); } + + std::pair getFillNumberWithTime() const { return mFillNumber; } + int32_t getFillNumber() const { return mFillNumber.second; } + long getFillNumberTime() const { return mFillNumber.first; } + void setFillNumberWithTime(std::pair p) { mFillNumber = p; } + void setFillNumberWithTime(long t, int32_t v) { mFillNumber = std::make_pair(t, v); } + + std::pair getInjectionSchemeWithTime() const { return mInjectionScheme; } + std::string getInjectionScheme() const { return mInjectionScheme.second; } + long getInjectionSchemeTime() const { return mInjectionScheme.first; } + void setInjectionSchemeWithTime(std::pair p) { mInjectionScheme = p; } + void setInjectionSchemeWithTime(long t, std::string v) { mInjectionScheme = std::make_pair(t, v); } + + std::pair getAtomicNumberB1WithTime() const { return mAtomicNumberB1; } + int32_t getAtomicNumberB1() const { return mAtomicNumberB1.second; } + long getAtomicNumberB1Time() const { return mAtomicNumberB1.first; } + void setAtomicNumberB1WithTime(std::pair p) { mAtomicNumberB1 = p; } + void setAtomicNumberB1WithTime(long t, int32_t v) { mAtomicNumberB1 = std::make_pair(t, v); } + + std::pair getAtomicNumberB2WithTime() const { return mAtomicNumberB2; } + int32_t getAtomicNumberB2() const { return mAtomicNumberB2.second; } + long getAtomicNumberB2Time() const { return mAtomicNumberB2.first; } + void setAtomicNumberB2WithTime(std::pair p) { mAtomicNumberB2 = p; } + void setAtomicNumberB2WithTime(long t, int32_t v) { mAtomicNumberB2 = std::make_pair(t, v); } + + /// further getters and setters, from info from LHC_IF processing + /// getters/setters for beams crossing angle (deviation from 0) + std::pair getCrossingAngleWithTime() const { return mCrossingAngle; } + o2::units::AngleRad_t getCrossingAngle() const { return mCrossingAngle.second; } + long getCrossingAngleTime() const { return mCrossingAngle.first; } + void setCrossingAngleWithTime(std::pair p) { mCrossingAngle = p; } + void setCrossingAngleWithTime(long t, o2::units::AngleRad_t v) { mCrossingAngle = std::make_pair(t, v); } + + /// getters/setters for given beam A and Z info, encoded as A<<16+Z + int getBeamZ(beamDirection beam) const { return mBeamAZ[static_cast(beam)] & 0xffff; } + int getBeamA(beamDirection beam) const { return mBeamAZ[static_cast(beam)] >> 16; } + float getBeamZoverA(beamDirection beam) const; + void setBeamAZ(int a, int z, beamDirection beam) { mBeamAZ[static_cast(beam)] = (a << 16) + z; } + void setBeamAZ(beamDirection beam); + void setBeamAZ(); + /// getters/setters for beam energy per charge and per nucleon + float getBeamEnergyPerNucleon(beamDirection beam) const { return mBeamEnergyPerZ.second * getBeamZoverA(beam); } + /// calculate center of mass energy per nucleon collision + float getSqrtS() const; + + private: + std::pair mBeamEnergyPerZ; // beam energy per charge + std::pair mFillNumber; + std::pair mInjectionScheme; + std::pair mAtomicNumberB1; // clockwise + std::pair mAtomicNumberB2; // anticlockwise + std::pair mCrossingAngle; + int mBeamAZ[beamDirection::NBeamDirections] = {0, 0}; ///< A<<16+Z for each beam + + + ClassDefNV(GRPLHCIFData, 1); +}; + +//______________________________________________ +inline float GRPLHCIFData::getBeamZoverA(beamDirection b) const +{ + // Z/A of beam 0 or 1 + int a = getBeamA(b); + return a ? getBeamZ(b) / static_cast(a) : 0.f; +} + +} // namespace parameters +} // namespace o2 +#endif diff --git a/DataFormats/Parameters/include/DataFormatsParameters/LHCIFData.h b/DataFormats/Parameters/include/DataFormatsParameters/LHCIFData.h deleted file mode 100644 index 0db3953454425..0000000000000 --- a/DataFormats/Parameters/include/DataFormatsParameters/LHCIFData.h +++ /dev/null @@ -1,74 +0,0 @@ -// 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 LHCIFData.h -/// \brief container for the LHC InterFace data - -#ifndef O2_GRP_LHCIFDATA_H -#define O2_GRP_LHCIFDATA_H - -#include -#include -#include - -namespace o2 -{ -namespace parameters -{ - -class LHCIFData -{ - public: - LHCIFData() = default; - ~LHCIFData() = default; - - std::pair getBeamEnergy() const { return mBeamEnergy; } - std::pair getFillNumber() const { return mFillNumber; } - std::pair getInjectionScheme() const { return mInjectionScheme; } - std::pair getAtomicNumberB1() const { return mAtomicNumberB1; } - std::pair getAtomicNumberB2() const { return mAtomicNumberB2; } - - int32_t getBeamEnergyVal() const { return mBeamEnergy.second; } - int32_t getFillNumberVal() const { return mFillNumber.second; } - std::string getInjectionSchemeVal() const { return mInjectionScheme.second; } - int32_t getAtomicNumberB1Val() const { return mAtomicNumberB1.second; } - int32_t getAtomicNumberB2Val() const { return mAtomicNumberB2.second; } - - long getBeamEnergyTime() const { return mBeamEnergy.first; } - long getFillNumberTime() const { return mFillNumber.first; } - long getInjectionSchemeTime() const { return mInjectionScheme.first; } - long getAtomicNumberB1Time() const { return mAtomicNumberB1.first; } - long getAtomicNumberB2Time() const { return mAtomicNumberB2.first; } - - void setBeamEnergy(std::pair p) { mBeamEnergy = p; } - void setFillNumber(std::pair p) { mFillNumber = p; } - void setInjectionScheme(std::pair p) { mInjectionScheme = p; } - void setAtomicNumberB1(std::pair p) { mAtomicNumberB1 = p; } - void setAtomicNumberB2(std::pair p) { mAtomicNumberB2 = p; } - - void setBeamEnergy(long t, int32_t v) { mBeamEnergy = std::make_pair(t, v); } - void setFillNumber(long t, int32_t v) { mFillNumber = std::make_pair(t, v); } - void setInjectionScheme(long t, std::string v) { mInjectionScheme = std::make_pair(t, v); } - void setAtomicNumberB1(long t, int32_t v) { mAtomicNumberB1 = std::make_pair(t, v); } - void setAtomicNumberB2(long t, int32_t v) { mAtomicNumberB2 = std::make_pair(t, v); } - - private: - std::pair mBeamEnergy; - std::pair mFillNumber; - std::pair mInjectionScheme; - std::pair mAtomicNumberB1; - std::pair mAtomicNumberB2; - - ClassDefNV(LHCIFData, 1); -}; -} // namespace parameters -} // namespace o2 -#endif diff --git a/DataFormats/Parameters/src/GRPLHCIFData.cxx b/DataFormats/Parameters/src/GRPLHCIFData.cxx new file mode 100644 index 0000000000000..c6bd6582f9db0 --- /dev/null +++ b/DataFormats/Parameters/src/GRPLHCIFData.cxx @@ -0,0 +1,78 @@ +// 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 GRPLHCIFData.cxx +/// \brief Implementation of the LHC InterFace data + +#include "DataFormatsParameters/GRPLHCIFData.h" +#include "CommonConstants/PhysicsConstants.h" +#include +#include + +using namespace o2::parameters; +using namespace o2::constants::physics; +using namespace o2::constants::lhc; + +const std::unordered_map GRPLHCIFData::mZtoA = + { + {1, 1}, + {82, 208} + }; + +//_______________________________________________ +void GRPLHCIFData::setBeamAZ(beamDirection beam) +{ + // set both A and Z of the beam in direction 'beam' + if (beam == beamDirection::BeamClockWise) { + auto atomicNum = mZtoA.find(getAtomicNumberB1()); + if (atomicNum == mZtoA.end()) { + LOG(FATAL) << "We don't know the Mass Number for Z = " << getAtomicNumberB1(); + } + else { + mBeamAZ[static_cast(beam)] = (atomicNum->second << 16) + getAtomicNumberB1(); + } + } + else { + auto atomicNum = mZtoA.find(getAtomicNumberB2()); + if (atomicNum == mZtoA.end()) { + LOG(FATAL) << "We don't know the Mass Number for Z = " << getAtomicNumberB2(); + } + else { + mBeamAZ[static_cast(beam)] = (atomicNum->second << 16) + getAtomicNumberB2(); + } + } +} + +//_______________________________________________ +void GRPLHCIFData::setBeamAZ() { + + // setting A and Z for both beams + setBeamAZ(BeamClockWise); + setBeamAZ(BeamAntiClockWise); + +} + +//_______________________________________________ +float GRPLHCIFData::getSqrtS() const +{ + // get center of mass energy + double e0 = getBeamEnergyPerNucleon(BeamClockWise); + double e1 = getBeamEnergyPerNucleon(BeamAntiClockWise); + if (e0 <= MassProton || e1 <= MassProton) { + return 0.f; + } + double beta0 = 1. - MassProton * MassProton / (e0 * e0); + double beta1 = 1. - MassProton * MassProton / (e1 * e1); + beta0 = beta0 > 0 ? sqrt(beta0) : 0.; + beta1 = beta1 > 0 ? sqrt(beta1) : 0.; + double ss = 2. * (MassProton * MassProton + e0 * e1 * (1. + beta0 * beta1 * cos(getCrossingAngle()))); + return ss > 0. ? sqrt(ss) : 0.; +} diff --git a/DataFormats/Parameters/src/LHCIFData.cxx b/DataFormats/Parameters/src/LHCIFData.cxx deleted file mode 100644 index 4ae9d0f9d98a8..0000000000000 --- a/DataFormats/Parameters/src/LHCIFData.cxx +++ /dev/null @@ -1,15 +0,0 @@ -// 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 LHCIFData.cxx -/// \brief Implementation of the LHC InterFace data - -#include "DataFormatsParameters/LHCIFData.h" diff --git a/DataFormats/Parameters/src/ParametersDataLinkDef.h b/DataFormats/Parameters/src/ParametersDataLinkDef.h index 72be02b31d514..691eed693eb46 100644 --- a/DataFormats/Parameters/src/ParametersDataLinkDef.h +++ b/DataFormats/Parameters/src/ParametersDataLinkDef.h @@ -24,7 +24,7 @@ #pragma link off all functions; #pragma link C++ class o2::parameters::GRPObject + ; -#pragma link C++ class o2::parameters::LHCIFData + ; +#pragma link C++ class o2::parameters::GRPLHCIFData + ; #pragma link C++ class std::pair < long, std::string> + ; #pragma link C++ class o2::parameters::GRPECSObject + ; #pragma link C++ class o2::parameters::GRPMagField + ; diff --git a/Detectors/GRP/workflows/include/GRPWorkflows/GRPLHCIFfileSpec.h b/Detectors/GRP/workflows/include/GRPWorkflows/GRPLHCIFfileSpec.h index 77a1fd5a2d3d8..8eff98c0a579d 100644 --- a/Detectors/GRP/workflows/include/GRPWorkflows/GRPLHCIFfileSpec.h +++ b/Detectors/GRP/workflows/include/GRPWorkflows/GRPLHCIFfileSpec.h @@ -17,7 +17,7 @@ #include "GRPCalibration/LHCIFfileReader.h" #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" -#include "DataFormatsParameters/LHCIFData.h" +#include "DataFormatsParameters/GRPLHCIFData.h" using namespace o2::framework; @@ -33,7 +33,7 @@ class GRPLHCIFfileProcessor : public Task void endOfStream(o2::framework::EndOfStreamContext& ec) final; private: - void sendOutput(DataAllocator& output, long tf, const o2::parameters::LHCIFData& lhcifdata); + void sendOutput(DataAllocator& output, long tf, const o2::parameters::GRPLHCIFData& lhcifdata); LHCIFfileReader mReader; bool mVerbose = false; // to enable verbose mode diff --git a/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx b/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx index 3719cdcd464ee..d5f2cac6ca0db 100644 --- a/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx +++ b/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx @@ -19,6 +19,7 @@ #include "CCDB/CcdbObjectInfo.h" #include "CommonUtils/MemFileHelper.h" #include "DetectorsCalibration/Utils.h" +#include "CommonTypes/Units.h" #include #include @@ -27,7 +28,7 @@ using namespace o2::framework; using TFType = uint64_t; using HighResClock = std::chrono::high_resolution_clock; using Duration = std::chrono::duration>; -using LHCIFData = o2::parameters::LHCIFData; +using GRPLHCIFData = o2::parameters::GRPLHCIFData; namespace o2 { @@ -54,12 +55,13 @@ void GRPLHCIFfileProcessor::run(o2::framework::ProcessingContext& pc) std::vector>> fillNb; std::vector>> atomicNbB1; std::vector>> atomicNbB2; + std::vector>> crossAngle; - int nEleBeamEn, nEleInjSch, nEleFillNb, nEleAtNbB1, nEleAtNbB2 = 0; - int nMeasBeamEn, nMeasInjSch, nMeasFillNb, nMeasAtNbB1, nMeasAtNbB2 = 0; + int nEleBeamEn, nEleInjSch, nEleFillNb, nEleAtNbB1, nEleAtNbB2, nEleCrossAngle = 0; + int nMeasBeamEn, nMeasInjSch, nMeasFillNb, nMeasAtNbB1, nMeasAtNbB2, nMeasCrossAngle = 0; std::string type{""}; - LHCIFData lhcifdata; + GRPLHCIFData lhcifdata; mReader.readValue("BEAM_ENERGY", type, nEleBeamEn, nMeasBeamEn, beamEnergy); if (nMeasBeamEn == 0) { @@ -69,7 +71,7 @@ void GRPLHCIFfileProcessor::run(o2::framework::ProcessingContext& pc) LOG(ERROR) << "More than one value/measurement found for Beam Energy, keeping the last one"; } LOG(INFO) << "beam energy size = " << beamEnergy.size(); - lhcifdata.setBeamEnergy(beamEnergy.back().first, beamEnergy.back().second.back()); + lhcifdata.setBeamEnergyPerZWithTime(beamEnergy.back().first, beamEnergy.back().second.back()); mReader.readValue("INJECTION_SCHEME", type, nEleInjSch, nMeasInjSch, injScheme); if (nMeasInjSch == 0) { @@ -78,7 +80,7 @@ void GRPLHCIFfileProcessor::run(o2::framework::ProcessingContext& pc) if (nEleInjSch != 1 || nMeasInjSch != 1) { LOG(ERROR) << "More than one value/measurement found for Injection Scheme, keeping the last one"; } - lhcifdata.setInjectionScheme(injScheme.back().first, injScheme.back().second.back()); + lhcifdata.setInjectionSchemeWithTime(injScheme.back().first, injScheme.back().second.back()); mReader.readValue("FILL_NUMBER", type, nEleFillNb, nMeasFillNb, fillNb); if (nMeasFillNb == 0) { @@ -87,25 +89,34 @@ void GRPLHCIFfileProcessor::run(o2::framework::ProcessingContext& pc) if (nEleFillNb != 1 || nMeasFillNb != 1) { LOG(ERROR) << "More than one value/measurement found for Fill Number, keeping the last one"; } - lhcifdata.setFillNumber(fillNb.back().first, atoi(fillNb.back().second.back().c_str())); + lhcifdata.setFillNumberWithTime(fillNb.back().first, atoi(fillNb.back().second.back().c_str())); mReader.readValue("ATOMIC_NUMBER_B1", type, nEleAtNbB1, nMeasAtNbB1, atomicNbB1); if (nMeasAtNbB1 == 0) { - LOG(FATAL) << "Atomic Number Beam 1 not present"; + LOG(FATAL) << "Atomic Number Beam 1 (clockwise) not present"; } if (nEleAtNbB1 != 1 || nMeasAtNbB1 != 1) { - LOG(ERROR) << "More than one value/measurement found for Atomic Number Beam 1, keeping the last one"; + LOG(ERROR) << "More than one value/measurement found for Atomic Number Beam 1 (clockwise), keeping the last one"; } - lhcifdata.setAtomicNumberB1(atomicNbB1.back().first, atomicNbB1.back().second.back()); + lhcifdata.setAtomicNumberB1WithTime(atomicNbB1.back().first, atomicNbB1.back().second.back()); mReader.readValue("ATOMIC_NUMBER_B2", type, nEleAtNbB2, nMeasAtNbB2, atomicNbB2); if (nMeasAtNbB2 == 0) { - LOG(FATAL) << "Atomic Number Beam 2 not present"; + LOG(FATAL) << "Atomic Number Beam 2 (anticlockwise) not present"; } if (nEleAtNbB2 != 1 || nMeasAtNbB2 != 1) { - LOG(ERROR) << "More than one value/measurement found for Atomic Number Beam 2, keeping the last one"; + LOG(ERROR) << "More than one value/measurement found for Atomic Number Beam 2 (anticlockwise), keeping the last one"; } - lhcifdata.setAtomicNumberB2(atomicNbB2.back().first, atomicNbB2.back().second.back()); + lhcifdata.setAtomicNumberB2WithTime(atomicNbB2.back().first, atomicNbB2.back().second.back()); + + mReader.readValue("IP2_XING_V_MURAD", type, nEleCrossAngle, nMeasCrossAngle, crossAngle); + if (nMeasCrossAngle == 0) { + LOG(FATAL) << "Crossing Angle not present"; + } + if (nEleCrossAngle != 1 || nMeasCrossAngle != 1) { + LOG(ERROR) << "More than one value/measurement found for Crossing Angle, keeping the last one"; + } + lhcifdata.setCrossingAngleWithTime(crossAngle.back().first, crossAngle.back().second.back()); if (mVerbose) { LOG(INFO) << " **** Beam Energy ****"; @@ -126,18 +137,24 @@ void GRPLHCIFfileProcessor::run(o2::framework::ProcessingContext& pc) std::cout << el.first << " --> " << elVect << std::endl; } } - LOG(INFO) << " **** Atomic Number Beam 1 ****"; + LOG(INFO) << " **** Atomic Number Beam 1 (clockwise) ****"; for (auto& el : atomicNbB1) { for (auto elVect : el.second) { std::cout << el.first << " --> " << elVect << std::endl; } } - LOG(INFO) << " **** Atomic Number B2 ****"; + LOG(INFO) << " **** Atomic Number B2 (anticlockwise) ****"; for (auto& el : atomicNbB2) { for (auto elVect : el.second) { std::cout << el.first << " --> " << elVect << std::endl; } } + LOG(INFO) << " **** Crossing Angle ****"; + for (auto& el : crossAngle) { + for (auto elVect : el.second) { + std::cout << el.first << " --> " << elVect << std::endl; + } + } } sendOutput(pc.outputs(), timer, lhcifdata); @@ -151,7 +168,7 @@ void GRPLHCIFfileProcessor::endOfStream(o2::framework::EndOfStreamContext& ec) //__________________________________________________________________ -void GRPLHCIFfileProcessor::sendOutput(DataAllocator& output, long tf, const LHCIFData& lhcifdata) +void GRPLHCIFfileProcessor::sendOutput(DataAllocator& output, long tf, const GRPLHCIFData& lhcifdata) { // sending output to CCDB @@ -162,7 +179,7 @@ void GRPLHCIFfileProcessor::sendOutput(DataAllocator& output, long tf, const LHC auto flName = o2::ccdb::CcdbApi::generateFileName(clName); std::map md; md.emplace("created by", "dpl"); - o2::ccdb::CcdbObjectInfo info("GRP/Data/LHCIFData", clName, flName, md, tf, INFINITE_TF); + o2::ccdb::CcdbObjectInfo info("GLO/Config/GRPLHCIFData", clName, flName, md, tf, INFINITE_TF); 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(); From 8993404ded0f9487a0d798e692a1adba437ee538 Mon Sep 17 00:00:00 2001 From: Chiara Zampolli Date: Tue, 19 Oct 2021 00:21:05 +0200 Subject: [PATCH 5/9] clang-format --- .../DataFormatsParameters/GRPLHCIFData.h | 13 ++++++------ DataFormats/Parameters/src/GRPLHCIFData.cxx | 20 ++++++++----------- .../GRP/workflows/src/GRPLHCIFfileSpec.cxx | 2 +- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h b/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h index a8497d6259bd3..d46c918cab31c 100644 --- a/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h +++ b/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h @@ -31,7 +31,7 @@ class GRPLHCIFData { using beamDirection = o2::constants::lhc::BeamDirection; - + public: GRPLHCIFData() = default; ~GRPLHCIFData() = default; @@ -78,7 +78,7 @@ class GRPLHCIFData /// getters/setters for given beam A and Z info, encoded as A<<16+Z int getBeamZ(beamDirection beam) const { return mBeamAZ[static_cast(beam)] & 0xffff; } - int getBeamA(beamDirection beam) const { return mBeamAZ[static_cast(beam)] >> 16; } + int getBeamA(beamDirection beam) const { return mBeamAZ[static_cast(beam)] >> 16; } float getBeamZoverA(beamDirection beam) const; void setBeamAZ(int a, int z, beamDirection beam) { mBeamAZ[static_cast(beam)] = (a << 16) + z; } void setBeamAZ(beamDirection beam); @@ -89,15 +89,14 @@ class GRPLHCIFData float getSqrtS() const; private: - std::pair mBeamEnergyPerZ; // beam energy per charge + std::pair mBeamEnergyPerZ; // beam energy per charge std::pair mFillNumber; std::pair mInjectionScheme; - std::pair mAtomicNumberB1; // clockwise - std::pair mAtomicNumberB2; // anticlockwise + std::pair mAtomicNumberB1; // clockwise + std::pair mAtomicNumberB2; // anticlockwise std::pair mCrossingAngle; int mBeamAZ[beamDirection::NBeamDirections] = {0, 0}; ///< A<<16+Z for each beam - ClassDefNV(GRPLHCIFData, 1); }; @@ -108,7 +107,7 @@ inline float GRPLHCIFData::getBeamZoverA(beamDirection b) const int a = getBeamA(b); return a ? getBeamZ(b) / static_cast(a) : 0.f; } - + } // namespace parameters } // namespace o2 #endif diff --git a/DataFormats/Parameters/src/GRPLHCIFData.cxx b/DataFormats/Parameters/src/GRPLHCIFData.cxx index c6bd6582f9db0..49296830616a3 100644 --- a/DataFormats/Parameters/src/GRPLHCIFData.cxx +++ b/DataFormats/Parameters/src/GRPLHCIFData.cxx @@ -23,9 +23,8 @@ using namespace o2::constants::lhc; const std::unordered_map GRPLHCIFData::mZtoA = { - {1, 1}, - {82, 208} - }; + {1, 1}, + {82, 208}}; //_______________________________________________ void GRPLHCIFData::setBeamAZ(beamDirection beam) @@ -35,29 +34,26 @@ void GRPLHCIFData::setBeamAZ(beamDirection beam) auto atomicNum = mZtoA.find(getAtomicNumberB1()); if (atomicNum == mZtoA.end()) { LOG(FATAL) << "We don't know the Mass Number for Z = " << getAtomicNumberB1(); - } - else { + } else { mBeamAZ[static_cast(beam)] = (atomicNum->second << 16) + getAtomicNumberB1(); } - } - else { + } else { auto atomicNum = mZtoA.find(getAtomicNumberB2()); if (atomicNum == mZtoA.end()) { LOG(FATAL) << "We don't know the Mass Number for Z = " << getAtomicNumberB2(); - } - else { + } else { mBeamAZ[static_cast(beam)] = (atomicNum->second << 16) + getAtomicNumberB2(); } } } //_______________________________________________ -void GRPLHCIFData::setBeamAZ() { +void GRPLHCIFData::setBeamAZ() +{ // setting A and Z for both beams setBeamAZ(BeamClockWise); setBeamAZ(BeamAntiClockWise); - } //_______________________________________________ @@ -75,4 +71,4 @@ float GRPLHCIFData::getSqrtS() const beta1 = beta1 > 0 ? sqrt(beta1) : 0.; double ss = 2. * (MassProton * MassProton + e0 * e1 * (1. + beta0 * beta1 * cos(getCrossingAngle()))); return ss > 0. ? sqrt(ss) : 0.; -} +} diff --git a/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx b/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx index d5f2cac6ca0db..021d2ff012688 100644 --- a/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx +++ b/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx @@ -108,7 +108,7 @@ void GRPLHCIFfileProcessor::run(o2::framework::ProcessingContext& pc) LOG(ERROR) << "More than one value/measurement found for Atomic Number Beam 2 (anticlockwise), keeping the last one"; } lhcifdata.setAtomicNumberB2WithTime(atomicNbB2.back().first, atomicNbB2.back().second.back()); - + mReader.readValue("IP2_XING_V_MURAD", type, nEleCrossAngle, nMeasCrossAngle, crossAngle); if (nMeasCrossAngle == 0) { LOG(FATAL) << "Crossing Angle not present"; From da74b627dad2b8d9264e89b81c74aada594e3101 Mon Sep 17 00:00:00 2001 From: Chiara Zampolli Date: Tue, 19 Oct 2021 00:28:25 +0200 Subject: [PATCH 6/9] adding streaming --- DataFormats/Parameters/src/ParametersDataLinkDef.h | 1 + 1 file changed, 1 insertion(+) diff --git a/DataFormats/Parameters/src/ParametersDataLinkDef.h b/DataFormats/Parameters/src/ParametersDataLinkDef.h index 691eed693eb46..798c3ab5e457a 100644 --- a/DataFormats/Parameters/src/ParametersDataLinkDef.h +++ b/DataFormats/Parameters/src/ParametersDataLinkDef.h @@ -28,5 +28,6 @@ #pragma link C++ class std::pair < long, std::string> + ; #pragma link C++ class o2::parameters::GRPECSObject + ; #pragma link C++ class o2::parameters::GRPMagField + ; +#pragma link C++ class std::unordered_map + ; #endif From 5747b93c3cf668918a0023870aa74711b0ecb35d Mon Sep 17 00:00:00 2001 From: Chiara Zampolli Date: Wed, 20 Oct 2021 00:14:52 +0200 Subject: [PATCH 7/9] Adding bunch filling --- .../DataFormatsParameters/GRPLHCIFData.h | 12 ++- DataFormats/Parameters/src/GRPLHCIFData.cxx | 9 ++ .../include/GRPCalibration/LHCIFfileReader.h | 9 +- .../GRP/workflows/src/GRPLHCIFfileSpec.cxx | 88 ++++++++++++++----- 4 files changed, 92 insertions(+), 26 deletions(-) diff --git a/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h b/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h index d46c918cab31c..e1ca34fa6409b 100644 --- a/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h +++ b/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h @@ -21,6 +21,7 @@ #include #include "CommonTypes/Units.h" #include "CommonConstants/LHCConstants.h" +#include "CommonDataFormat/BunchFilling.h" namespace o2 { @@ -68,14 +69,18 @@ class GRPLHCIFData void setAtomicNumberB2WithTime(std::pair p) { mAtomicNumberB2 = p; } void setAtomicNumberB2WithTime(long t, int32_t v) { mAtomicNumberB2 = std::make_pair(t, v); } - /// further getters and setters, from info from LHC_IF processing - /// getters/setters for beams crossing angle (deviation from 0) std::pair getCrossingAngleWithTime() const { return mCrossingAngle; } o2::units::AngleRad_t getCrossingAngle() const { return mCrossingAngle.second; } long getCrossingAngleTime() const { return mCrossingAngle.first; } void setCrossingAngleWithTime(std::pair p) { mCrossingAngle = p; } void setCrossingAngleWithTime(long t, o2::units::AngleRad_t v) { mCrossingAngle = std::make_pair(t, v); } + std::pair getBunchFillingWithTime() const { return mBunchFilling; } + o2::BunchFilling getBunchFilling() const { return mBunchFilling.second; } + long getBunchFillingTime() const { return mBunchFilling.first; } + void setBunchFillingWithTime(std::pair p) { mBunchFilling = p; } + void setBunchFillingWithTime(long t, o2::BunchFilling v) { mBunchFilling = std::make_pair(t, v); } + /// getters/setters for given beam A and Z info, encoded as A<<16+Z int getBeamZ(beamDirection beam) const { return mBeamAZ[static_cast(beam)] & 0xffff; } int getBeamA(beamDirection beam) const { return mBeamAZ[static_cast(beam)] >> 16; } @@ -87,6 +92,8 @@ class GRPLHCIFData float getBeamEnergyPerNucleon(beamDirection beam) const { return mBeamEnergyPerZ.second * getBeamZoverA(beam); } /// calculate center of mass energy per nucleon collision float getSqrtS() const; + /// helper function for BunchFilling + void translateBucketsToBCNumbers(std::vector& bcNb, std::vector&buckets, int beam); private: std::pair mBeamEnergyPerZ; // beam energy per charge @@ -96,6 +103,7 @@ class GRPLHCIFData std::pair mAtomicNumberB2; // anticlockwise std::pair mCrossingAngle; int mBeamAZ[beamDirection::NBeamDirections] = {0, 0}; ///< A<<16+Z for each beam + std::pair mBunchFilling; ///To hold bunch filling information ClassDefNV(GRPLHCIFData, 1); }; diff --git a/DataFormats/Parameters/src/GRPLHCIFData.cxx b/DataFormats/Parameters/src/GRPLHCIFData.cxx index 49296830616a3..af5cc6263718e 100644 --- a/DataFormats/Parameters/src/GRPLHCIFData.cxx +++ b/DataFormats/Parameters/src/GRPLHCIFData.cxx @@ -72,3 +72,12 @@ float GRPLHCIFData::getSqrtS() const double ss = 2. * (MassProton * MassProton + e0 * e1 * (1. + beta0 * beta1 * cos(getCrossingAngle()))); return ss > 0. ? sqrt(ss) : 0.; } + +//_________________________________________________________________ + +void GRPLHCIFData::translateBucketsToBCNumbers(std::vector& bcNb, std::vector& buckets, int beam) { + // to translate the vector of bucket numbers to BC numbers + for (auto i : buckets) { + bcNb.push_back(i = 0 ? 0 : (i / 10 + o2::constants::lhc::BunchOffsetsP2[beam]) % o2::constants::lhc::LHCMaxBunches); + } +} diff --git a/Detectors/GRP/calibration/include/GRPCalibration/LHCIFfileReader.h b/Detectors/GRP/calibration/include/GRPCalibration/LHCIFfileReader.h index 35bb16ea9db07..92410cf41afe7 100644 --- a/Detectors/GRP/calibration/include/GRPCalibration/LHCIFfileReader.h +++ b/Detectors/GRP/calibration/include/GRPCalibration/LHCIFfileReader.h @@ -16,6 +16,7 @@ #include #include "Framework/Logger.h" #include "CommonUtils/StringUtils.h" +#include "CommonConstants/LHCConstants.h" /// @brief Class to read the LHC InterFace file coming from the DCS filepush service @@ -33,7 +34,7 @@ class LHCIFfileReader void loadLHCIFfile(gsl::span configBuf); // load LHCIF file from buffer template void readValue(const std::string& alias, std::string& type, int& nel, int& nmeas, std::vector>>& meas); - + private: std::string mFileBuffStr; // buffer containing content of LHC IF file @@ -83,7 +84,7 @@ void LHCIFfileReader::readValue(const std::string& alias, std::string& type, int if constexpr (std::is_same::value) { if (type == "i" || type == "b") { for (int iele = 0; iele < nele; ++iele) { - LOG(INFO) << alias << ": value int/bool = " << tokensStr[shift + iele]; + LOG(DEBUG) << alias << ": value int/bool = " << tokensStr[shift + iele]; vect.emplace_back(std::stoi(tokensStr[shift + iele])); } } else { @@ -92,7 +93,7 @@ void LHCIFfileReader::readValue(const std::string& alias, std::string& type, int } else if constexpr (std::is_same::value) { if (type == "f") { for (int iele = 0; iele < nele; ++iele) { - LOG(INFO) << alias << ": value float = " << tokensStr[shift + iele]; + LOG(DEBUG) << alias << ": value float = " << tokensStr[shift + iele]; vect.emplace_back(std::stof(tokensStr[shift + iele])); } } else { @@ -103,7 +104,7 @@ void LHCIFfileReader::readValue(const std::string& alias, std::string& type, int else if constexpr (std::is_same::value) { if (type == "s") { for (int iele = 0; iele < nele; ++iele) { - LOG(INFO) << alias << ": value string = " << tokensStr[shift + iele]; + LOG(DEBUG) << alias << ": value string = " << tokensStr[shift + iele]; vect.emplace_back(tokensStr[shift + iele]); } } else { diff --git a/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx b/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx index 021d2ff012688..538117014be65 100644 --- a/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx +++ b/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx @@ -56,68 +56,116 @@ void GRPLHCIFfileProcessor::run(o2::framework::ProcessingContext& pc) std::vector>> atomicNbB1; std::vector>> atomicNbB2; std::vector>> crossAngle; + std::vector>> bunchConfigB1; + std::vector>> bunchConfigB2; - int nEleBeamEn, nEleInjSch, nEleFillNb, nEleAtNbB1, nEleAtNbB2, nEleCrossAngle = 0; - int nMeasBeamEn, nMeasInjSch, nMeasFillNb, nMeasAtNbB1, nMeasAtNbB2, nMeasCrossAngle = 0; + int nEle = 0; + int nMeas = 0; std::string type{""}; GRPLHCIFData lhcifdata; - mReader.readValue("BEAM_ENERGY", type, nEleBeamEn, nMeasBeamEn, beamEnergy); - if (nMeasBeamEn == 0) { + // Beam Energy + mReader.readValue("BEAM_ENERGY", type, nEle, nMeas, beamEnergy); + if (nMeas == 0) { LOG(FATAL) << "Beam energy not present"; } - if (nEleBeamEn != 1 || nMeasBeamEn != 1) { + if (nEle != 1 || nMeas != 1) { LOG(ERROR) << "More than one value/measurement found for Beam Energy, keeping the last one"; } LOG(INFO) << "beam energy size = " << beamEnergy.size(); lhcifdata.setBeamEnergyPerZWithTime(beamEnergy.back().first, beamEnergy.back().second.back()); - mReader.readValue("INJECTION_SCHEME", type, nEleInjSch, nMeasInjSch, injScheme); - if (nMeasInjSch == 0) { + // Injection scheme + mReader.readValue("INJECTION_SCHEME", type, nEle, nMeas, injScheme); + if (nMeas == 0) { LOG(FATAL) << "Injection scheme not present"; } - if (nEleInjSch != 1 || nMeasInjSch != 1) { + if (nEle != 1 || nMeas != 1) { LOG(ERROR) << "More than one value/measurement found for Injection Scheme, keeping the last one"; } lhcifdata.setInjectionSchemeWithTime(injScheme.back().first, injScheme.back().second.back()); - mReader.readValue("FILL_NUMBER", type, nEleFillNb, nMeasFillNb, fillNb); - if (nMeasFillNb == 0) { + // fill number + mReader.readValue("FILL_NUMBER", type, nEle, nMeas, fillNb); + if (nMeas == 0) { LOG(FATAL) << "Fill Number not present"; } - if (nEleFillNb != 1 || nMeasFillNb != 1) { + if (nEle != 1 || nMeas != 1) { LOG(ERROR) << "More than one value/measurement found for Fill Number, keeping the last one"; } lhcifdata.setFillNumberWithTime(fillNb.back().first, atoi(fillNb.back().second.back().c_str())); - mReader.readValue("ATOMIC_NUMBER_B1", type, nEleAtNbB1, nMeasAtNbB1, atomicNbB1); - if (nMeasAtNbB1 == 0) { + // Atomic Number (Z) for B1 + mReader.readValue("ATOMIC_NUMBER_B1", type, nEle, nMeas, atomicNbB1); + if (nMeas == 0) { LOG(FATAL) << "Atomic Number Beam 1 (clockwise) not present"; } - if (nEleAtNbB1 != 1 || nMeasAtNbB1 != 1) { + if (nEle != 1 || nMeas != 1) { LOG(ERROR) << "More than one value/measurement found for Atomic Number Beam 1 (clockwise), keeping the last one"; } lhcifdata.setAtomicNumberB1WithTime(atomicNbB1.back().first, atomicNbB1.back().second.back()); - mReader.readValue("ATOMIC_NUMBER_B2", type, nEleAtNbB2, nMeasAtNbB2, atomicNbB2); - if (nMeasAtNbB2 == 0) { + // Atomic Number (Z) for B2 + mReader.readValue("ATOMIC_NUMBER_B2", type, nEle, nMeas, atomicNbB2); + if (nMeas == 0) { LOG(FATAL) << "Atomic Number Beam 2 (anticlockwise) not present"; } - if (nEleAtNbB2 != 1 || nMeasAtNbB2 != 1) { + if (nEle != 1 || nMeas != 1) { LOG(ERROR) << "More than one value/measurement found for Atomic Number Beam 2 (anticlockwise), keeping the last one"; } lhcifdata.setAtomicNumberB2WithTime(atomicNbB2.back().first, atomicNbB2.back().second.back()); - mReader.readValue("IP2_XING_V_MURAD", type, nEleCrossAngle, nMeasCrossAngle, crossAngle); - if (nMeasCrossAngle == 0) { + // Crossing Angle + mReader.readValue("IP2_XING_V_MURAD", type, nEle, nMeas, crossAngle); + if (nMeas == 0) { LOG(FATAL) << "Crossing Angle not present"; } - if (nEleCrossAngle != 1 || nMeasCrossAngle != 1) { + if (nEle != 1 || nMeas != 1) { LOG(ERROR) << "More than one value/measurement found for Crossing Angle, keeping the last one"; } lhcifdata.setCrossingAngleWithTime(crossAngle.back().first, crossAngle.back().second.back()); + // Bunch Config for B1 + mReader.readValue("CIRCULATING_BUNCH_CONFIG_BEAM1", type, nEle, nMeas, bunchConfigB1); + if (nMeas == 0) { + LOG(FATAL) << "Bunch Config Beam 1 not present"; + } + if (nEle != 1 || nMeas != 1) { + LOG(ERROR) << "More than one value/measurement found for Bunch Config Beam 1, keeping the last one"; + } + + // Bunch Config for B2 + mReader.readValue("CIRCULATING_BUNCH_CONFIG_BEAM2", type, nEle, nMeas, bunchConfigB2); + if (nMeas == 0) { + LOG(FATAL) << "Bunch Config Beam 2 not present"; + } + if (nEle != 1 || nMeas != 1) { + LOG(ERROR) << "More than one value/measurement found for Bunch Config Beam 2, keeping the last one"; + } + if (nMeas != o2::constants::lhc::LHCMaxBunches) { + LOG(ERROR) << "We don't have the right number of bunches information for Beam 2"; + } + + // Building Bunch Filling + std::vector bcNumbersB1, bcNumbersB2; + lhcifdata.translateBucketsToBCNumbers(bcNumbersB1, bunchConfigB1.back().second, 1); + lhcifdata.translateBucketsToBCNumbers(bcNumbersB2, bunchConfigB2.back().second, 2); + o2::BunchFilling bunchFilling; + for (int i = 0 ; i < bcNumbersB1.size(); ++i) { + int bc = bcNumbersB1[i]; + int val = (bc == 0 ? 0 : 1); + bunchFilling.setBC(bc, val, 0); + } + for (int i = 0 ; i < bcNumbersB2.size(); ++i) { + int bc = bcNumbersB2[i]; + int val = (bc == 0 ? 0 : 1); + bunchFilling.setBC(bc, val, 1); + } + bunchFilling.setInteractingBCsFromBeams(); + + lhcifdata.setBunchFillingWithTime((bunchConfigB1.back().first + bunchConfigB2.back().first) / 2, bunchFilling); + if (mVerbose) { LOG(INFO) << " **** Beam Energy ****"; for (auto& el : beamEnergy) { From e5977486a235f03a467c4d39d5abfb7ca33d39b3 Mon Sep 17 00:00:00 2001 From: Chiara Zampolli Date: Wed, 20 Oct 2021 00:18:23 +0200 Subject: [PATCH 8/9] clang-format --- .../include/DataFormatsParameters/GRPLHCIFData.h | 6 +++--- DataFormats/Parameters/src/GRPLHCIFData.cxx | 3 ++- DataFormats/Parameters/src/ParametersDataLinkDef.h | 2 +- .../include/GRPCalibration/LHCIFfileReader.h | 2 +- Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx | 12 ++++++------ 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h b/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h index e1ca34fa6409b..10a8d440b5b77 100644 --- a/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h +++ b/DataFormats/Parameters/include/DataFormatsParameters/GRPLHCIFData.h @@ -80,7 +80,7 @@ class GRPLHCIFData long getBunchFillingTime() const { return mBunchFilling.first; } void setBunchFillingWithTime(std::pair p) { mBunchFilling = p; } void setBunchFillingWithTime(long t, o2::BunchFilling v) { mBunchFilling = std::make_pair(t, v); } - + /// getters/setters for given beam A and Z info, encoded as A<<16+Z int getBeamZ(beamDirection beam) const { return mBeamAZ[static_cast(beam)] & 0xffff; } int getBeamA(beamDirection beam) const { return mBeamAZ[static_cast(beam)] >> 16; } @@ -93,7 +93,7 @@ class GRPLHCIFData /// calculate center of mass energy per nucleon collision float getSqrtS() const; /// helper function for BunchFilling - void translateBucketsToBCNumbers(std::vector& bcNb, std::vector&buckets, int beam); + void translateBucketsToBCNumbers(std::vector& bcNb, std::vector& buckets, int beam); private: std::pair mBeamEnergyPerZ; // beam energy per charge @@ -103,7 +103,7 @@ class GRPLHCIFData std::pair mAtomicNumberB2; // anticlockwise std::pair mCrossingAngle; int mBeamAZ[beamDirection::NBeamDirections] = {0, 0}; ///< A<<16+Z for each beam - std::pair mBunchFilling; ///To hold bunch filling information + std::pair mBunchFilling; ///To hold bunch filling information ClassDefNV(GRPLHCIFData, 1); }; diff --git a/DataFormats/Parameters/src/GRPLHCIFData.cxx b/DataFormats/Parameters/src/GRPLHCIFData.cxx index af5cc6263718e..235f33884798e 100644 --- a/DataFormats/Parameters/src/GRPLHCIFData.cxx +++ b/DataFormats/Parameters/src/GRPLHCIFData.cxx @@ -75,7 +75,8 @@ float GRPLHCIFData::getSqrtS() const //_________________________________________________________________ -void GRPLHCIFData::translateBucketsToBCNumbers(std::vector& bcNb, std::vector& buckets, int beam) { +void GRPLHCIFData::translateBucketsToBCNumbers(std::vector& bcNb, std::vector& buckets, int beam) +{ // to translate the vector of bucket numbers to BC numbers for (auto i : buckets) { bcNb.push_back(i = 0 ? 0 : (i / 10 + o2::constants::lhc::BunchOffsetsP2[beam]) % o2::constants::lhc::LHCMaxBunches); diff --git a/DataFormats/Parameters/src/ParametersDataLinkDef.h b/DataFormats/Parameters/src/ParametersDataLinkDef.h index 798c3ab5e457a..741cd6cd47787 100644 --- a/DataFormats/Parameters/src/ParametersDataLinkDef.h +++ b/DataFormats/Parameters/src/ParametersDataLinkDef.h @@ -28,6 +28,6 @@ #pragma link C++ class std::pair < long, std::string> + ; #pragma link C++ class o2::parameters::GRPECSObject + ; #pragma link C++ class o2::parameters::GRPMagField + ; -#pragma link C++ class std::unordered_map + ; +#pragma link C++ class std::unordered_map < unsigned int, unsigned int> + ; #endif diff --git a/Detectors/GRP/calibration/include/GRPCalibration/LHCIFfileReader.h b/Detectors/GRP/calibration/include/GRPCalibration/LHCIFfileReader.h index 92410cf41afe7..3951ecbd11d07 100644 --- a/Detectors/GRP/calibration/include/GRPCalibration/LHCIFfileReader.h +++ b/Detectors/GRP/calibration/include/GRPCalibration/LHCIFfileReader.h @@ -34,7 +34,7 @@ class LHCIFfileReader void loadLHCIFfile(gsl::span configBuf); // load LHCIF file from buffer template void readValue(const std::string& alias, std::string& type, int& nel, int& nmeas, std::vector>>& meas); - + private: std::string mFileBuffStr; // buffer containing content of LHC IF file diff --git a/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx b/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx index 538117014be65..5a87f96bf0012 100644 --- a/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx +++ b/Detectors/GRP/workflows/src/GRPLHCIFfileSpec.cxx @@ -152,20 +152,20 @@ void GRPLHCIFfileProcessor::run(o2::framework::ProcessingContext& pc) lhcifdata.translateBucketsToBCNumbers(bcNumbersB1, bunchConfigB1.back().second, 1); lhcifdata.translateBucketsToBCNumbers(bcNumbersB2, bunchConfigB2.back().second, 2); o2::BunchFilling bunchFilling; - for (int i = 0 ; i < bcNumbersB1.size(); ++i) { + for (int i = 0; i < bcNumbersB1.size(); ++i) { int bc = bcNumbersB1[i]; - int val = (bc == 0 ? 0 : 1); + int val = (bc == 0 ? 0 : 1); bunchFilling.setBC(bc, val, 0); } - for (int i = 0 ; i < bcNumbersB2.size(); ++i) { + for (int i = 0; i < bcNumbersB2.size(); ++i) { int bc = bcNumbersB2[i]; - int val = (bc == 0 ? 0 : 1); + int val = (bc == 0 ? 0 : 1); bunchFilling.setBC(bc, val, 1); } bunchFilling.setInteractingBCsFromBeams(); - + lhcifdata.setBunchFillingWithTime((bunchConfigB1.back().first + bunchConfigB2.back().first) / 2, bunchFilling); - + if (mVerbose) { LOG(INFO) << " **** Beam Energy ****"; for (auto& el : beamEnergy) { From 6e30c355713b720536a836a8ae6c3503721a1fd4 Mon Sep 17 00:00:00 2001 From: Chiara Zampolli Date: Tue, 2 Nov 2021 23:43:13 +0100 Subject: [PATCH 9/9] 3-level path for MeanVertex --- Detectors/Calibration/src/MeanVertexCalibrator.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/Calibration/src/MeanVertexCalibrator.cxx b/Detectors/Calibration/src/MeanVertexCalibrator.cxx index 4b169a6c761a9..0d9ddbbf76cce 100644 --- a/Detectors/Calibration/src/MeanVertexCalibrator.cxx +++ b/Detectors/Calibration/src/MeanVertexCalibrator.cxx @@ -146,7 +146,7 @@ void MeanVertexCalibrator::finalizeSlot(Slot& slot) std::map md; auto clName = o2::utils::MemFileHelper::getClassName(mSMAMVobj); auto flName = o2::ccdb::CcdbApi::generateFileName(clName); - mInfoVector.emplace_back("GRP/MeanVertex", clName, flName, md, startValidity, 99999999999999); + mInfoVector.emplace_back("GLO/Calib/MeanVertex", clName, flName, md, startValidity, 99999999999999); mMeanVertexVector.emplace_back(mSMAMVobj); slot.print();