From ffc5fec471526ed293d506dcdd77c753398fa280 Mon Sep 17 00:00:00 2001 From: Piotr Konopka Date: Mon, 9 Feb 2026 15:25:34 +0100 Subject: [PATCH] Standard helper to create DataOrigin for QC data sources --- Framework/CMakeLists.txt | 3 +- ...hDataDescription.h => DataHeaderHelpers.h} | 17 +++++-- .../include/QualityControl/DataSourceSpec.h | 14 +----- .../include/QualityControl/DataSourceType.h | 37 +++++++++++++++ Framework/src/Aggregator.cxx | 2 +- Framework/src/AggregatorRunner.cxx | 2 +- Framework/src/Check.cxx | 2 +- ...aDescription.cxx => DataHeaderHelpers.cxx} | 40 +++++++++++++++- Framework/src/PostProcessingDevice.cxx | 2 +- Framework/src/TaskRunner.cxx | 2 +- Framework/test/testDataHeaderHelpers.cxx | 47 +++++++++++++++++++ 11 files changed, 144 insertions(+), 24 deletions(-) rename Framework/include/QualityControl/{HashDataDescription.h => DataHeaderHelpers.h} (72%) create mode 100644 Framework/include/QualityControl/DataSourceType.h rename Framework/src/{HashDataDescription.cxx => DataHeaderHelpers.cxx} (61%) create mode 100644 Framework/test/testDataHeaderHelpers.cxx diff --git a/Framework/CMakeLists.txt b/Framework/CMakeLists.txt index 89be5a43d4..4b24f09dbb 100644 --- a/Framework/CMakeLists.txt +++ b/Framework/CMakeLists.txt @@ -98,7 +98,7 @@ add_library(O2QualityControl src/InfrastructureSpecReader.cxx src/Check.cxx src/Aggregator.cxx - src/HashDataDescription.cxx + src/DataHeaderHelpers.cxx src/Triggers.cxx src/TriggerHelpers.cxx src/PostProcessingRunner.cxx @@ -276,6 +276,7 @@ add_executable(o2-qc-test-core test/testCheckInterface.cxx test/testCheckRunner.cxx test/testCustomParameters.cxx + test/testDataHeaderHelpers.cxx test/testInfrastructureGenerator.cxx test/testMonitorObject.cxx test/testPolicyManager.cxx diff --git a/Framework/include/QualityControl/HashDataDescription.h b/Framework/include/QualityControl/DataHeaderHelpers.h similarity index 72% rename from Framework/include/QualityControl/HashDataDescription.h rename to Framework/include/QualityControl/DataHeaderHelpers.h index 0cd61a6ee7..7aad96ab53 100644 --- a/Framework/include/QualityControl/HashDataDescription.h +++ b/Framework/include/QualityControl/DataHeaderHelpers.h @@ -9,27 +9,34 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -#ifndef QC_HASH_DATA_DESCRIPTION_H -#define QC_HASH_DATA_DESCRIPTION_H +#ifndef QC_DATA_HEADER_HELPERS_H +#define QC_DATA_HEADER_HELPERS_H #include #include #include +#include "QualityControl/DataSourceType.h" + namespace o2::quality_control::core { -/// \brief Creates DataDescription from given name. +/// \brief Creates DataOrigin for a QC Actor. +/// +/// Creates DataOrigin for a data source and detector code +header::DataOrigin createDataOrigin(DataSourceType, const std::string& detectorCode); + +/// \brief Creates DataDescription from given name for any QC actor /// /// If the length of the name is <= 16 (hardcoded in DataDescription) it creates DataDescription from the original name. /// However, if the length of the name is > 16, it will create hash of the whole name and replace ending hashLength of bytes /// of the name with hexa representation of computed hash. -/// eg.: name == "veryLongNameThatIsLongerThan16B" with hashLengh == 4 will result in "veryLongNameABCD", where ABCD +/// eg.: name == "veryLongNameThatIsLongerThan16B" with hashLength == 4 will result in "veryLongNameABCD", where ABCD /// is the hash create inside the function /// /// \param name - name which should cut and hashed -/// \param hashLenght - number of bytes which will overwrite the end of the name +/// \param hashLength - number of bytes which will overwrite the end of the name o2::header::DataDescription createDataDescription(const std::string& name, size_t hashLength); } // namespace o2::quality_control::core diff --git a/Framework/include/QualityControl/DataSourceSpec.h b/Framework/include/QualityControl/DataSourceSpec.h index 61ac4da7cb..fd0629cd00 100644 --- a/Framework/include/QualityControl/DataSourceSpec.h +++ b/Framework/include/QualityControl/DataSourceSpec.h @@ -21,21 +21,11 @@ #include #include +#include "QualityControl/DataSourceType.h" + namespace o2::quality_control::core { -enum class DataSourceType { - DataSamplingPolicy, - Direct, - Task, - TaskMovingWindow, - Check, - Aggregator, - PostProcessingTask, - ExternalTask, - Invalid -}; - // this should allow us to represent all data sources which come from DPL (and maybe CCDB). struct DataSourceSpec { explicit DataSourceSpec(DataSourceType type = DataSourceType::Invalid); diff --git a/Framework/include/QualityControl/DataSourceType.h b/Framework/include/QualityControl/DataSourceType.h new file mode 100644 index 0000000000..8250fdac6b --- /dev/null +++ b/Framework/include/QualityControl/DataSourceType.h @@ -0,0 +1,37 @@ +// 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 DataSourceType.h +/// \author Piotr Konopka +/// + +#ifndef QUALITYCONTROL_DATASOURCETYPE_H +#define QUALITYCONTROL_DATASOURCETYPE_H + +namespace o2::quality_control::core +{ + +enum class DataSourceType { + DataSamplingPolicy, + Direct, + Task, + TaskMovingWindow, + Check, + Aggregator, + PostProcessingTask, + ExternalTask, + Invalid +}; + +} + +#endif // QUALITYCONTROL_DATASOURCETYPE_H \ No newline at end of file diff --git a/Framework/src/Aggregator.cxx b/Framework/src/Aggregator.cxx index 42551ea064..5a6934dd60 100644 --- a/Framework/src/Aggregator.cxx +++ b/Framework/src/Aggregator.cxx @@ -26,7 +26,7 @@ #include "QualityControl/Activity.h" #include #include "QualityControl/CommonSpec.h" -#include "QualityControl/HashDataDescription.h" +#include "QualityControl/DataHeaderHelpers.h" #include #include diff --git a/Framework/src/AggregatorRunner.cxx b/Framework/src/AggregatorRunner.cxx index ddcea3ae4f..09422d4029 100644 --- a/Framework/src/AggregatorRunner.cxx +++ b/Framework/src/AggregatorRunner.cxx @@ -41,7 +41,7 @@ #include "QualityControl/ConfigParamGlo.h" #include "QualityControl/Bookkeeping.h" #include "QualityControl/WorkflowType.h" -#include "QualityControl/HashDataDescription.h" +#include "QualityControl/DataHeaderHelpers.h" using namespace AliceO2::Common; using namespace AliceO2::InfoLogger; diff --git a/Framework/src/Check.cxx b/Framework/src/Check.cxx index f9d12ad2d3..d0f151b314 100644 --- a/Framework/src/Check.cxx +++ b/Framework/src/Check.cxx @@ -29,7 +29,7 @@ #include "QualityControl/RootClassFactory.h" #include "QualityControl/QcInfoLogger.h" #include "QualityControl/Quality.h" -#include "QualityControl/HashDataDescription.h" +#include "QualityControl/DataHeaderHelpers.h" #include "QualityControl/ObjectMetadataHelpers.h" #include diff --git a/Framework/src/HashDataDescription.cxx b/Framework/src/DataHeaderHelpers.cxx similarity index 61% rename from Framework/src/HashDataDescription.cxx rename to Framework/src/DataHeaderHelpers.cxx index 9b62ba4e57..ab0b71133d 100644 --- a/Framework/src/HashDataDescription.cxx +++ b/Framework/src/DataHeaderHelpers.cxx @@ -12,12 +12,50 @@ #include #include -#include "QualityControl/HashDataDescription.h" +#include "QualityControl/DataHeaderHelpers.h" #include "QualityControl/QcInfoLogger.h" namespace o2::quality_control::core { +constexpr char CharIdFrom(DataSourceType type) +{ + switch (type) { + case DataSourceType::DataSamplingPolicy: + case DataSourceType::Direct: + case DataSourceType::ExternalTask: + throw std::invalid_argument("Provided data source type is not generated by QC, cannot provide a corresponding character"); + case DataSourceType::Task: + return 'Q'; + case DataSourceType::TaskMovingWindow: + return 'W'; + case DataSourceType::Check: + return 'C'; + case DataSourceType::Aggregator: + return 'A'; + case DataSourceType::PostProcessingTask: + return 'P'; + default: + throw std::invalid_argument("Unrecognized data source type"); + } +} + +header::DataOrigin createDataOrigin(DataSourceType dataSourceType, const std::string& detectorCode) +{ + std::string originStr{ CharIdFrom(dataSourceType) }; + if (detectorCode.empty()) { + throw std::invalid_argument{ "empty detector code for a data source origin" }; + } else if (detectorCode.size() > 3) { + ILOG(Warning, Support) << "too long detector code for a task data origin: " + detectorCode + ", trying to survive with: " + detectorCode.substr(0, 3) << ENDM; + originStr += detectorCode.substr(0, 3); + } else { + originStr += detectorCode; + } + o2::header::DataOrigin origin; + origin.runtimeInit(originStr.c_str()); + return origin; +} + namespace hash { diff --git a/Framework/src/PostProcessingDevice.cxx b/Framework/src/PostProcessingDevice.cxx index 8c29897a87..4b004357d5 100644 --- a/Framework/src/PostProcessingDevice.cxx +++ b/Framework/src/PostProcessingDevice.cxx @@ -21,7 +21,7 @@ #include "QualityControl/PostProcessingInterface.h" #include "QualityControl/PostProcessingRunnerConfig.h" #include "QualityControl/QcInfoLogger.h" -#include "QualityControl/HashDataDescription.h" +#include "QualityControl/DataHeaderHelpers.h" #include "QualityControl/runnerUtils.h" #include diff --git a/Framework/src/TaskRunner.cxx b/Framework/src/TaskRunner.cxx index 3c16548207..61e19f95b2 100644 --- a/Framework/src/TaskRunner.cxx +++ b/Framework/src/TaskRunner.cxx @@ -49,7 +49,7 @@ #include "QualityControl/TimekeeperFactory.h" #include "QualityControl/ActivityHelpers.h" #include "QualityControl/WorkflowType.h" -#include "QualityControl/HashDataDescription.h" +#include "QualityControl/DataHeaderHelpers.h" #include "QualityControl/runnerUtils.h" #include diff --git a/Framework/test/testDataHeaderHelpers.cxx b/Framework/test/testDataHeaderHelpers.cxx new file mode 100644 index 0000000000..0cb9a7bc31 --- /dev/null +++ b/Framework/test/testDataHeaderHelpers.cxx @@ -0,0 +1,47 @@ +// Copyright 2019-2024 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 testDataHeaderHelpers.h +/// \author Piotr Konopka +/// + +#include + +#include + +#include "QualityControl/DataHeaderHelpers.h" +#include "QualityControl/DataSourceType.h" + +using namespace o2::quality_control::core; +using namespace o2::header; + +TEST_CASE("DataOrigin") +{ + CHECK_THROWS(createDataOrigin(DataSourceType::Direct, "TST")); // non-QC data source + CHECK_THROWS(createDataOrigin(DataSourceType::Task, "")); // empty detector is wrong + + CHECK(createDataOrigin(DataSourceType::Task, "TST") == DataOrigin{ "QTST" }); + CHECK(createDataOrigin(DataSourceType::TaskMovingWindow, "TST") == DataOrigin{ "WTST" }); + + CHECK(createDataOrigin(DataSourceType::Task, "TOO_LONG") == DataOrigin{ "QTOO" }); + CHECK(createDataOrigin(DataSourceType::Task, "X") == DataOrigin{ "QX" }); +} + +TEST_CASE("DataDescription") +{ + CHECK(createDataDescription("", 10) == DataDescription("")); + CHECK(createDataDescription("ABC", 10) == DataDescription("ABC")); + CHECK(createDataDescription("ABCDEABCDEABCDEA", 10) == DataDescription("ABCDEABCDEABCDEA")); + CHECK(createDataDescription("LOOOOOOOOOOOOOOONG", 4) != DataDescription("LOOOOOOOOOOOOOON")); + + CHECK_THROWS(createDataDescription("LOOOOOOOOOOOOOOONG", DataDescription::size + 50)); +} \ No newline at end of file