|
| 1 | +// Copyright 2025 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +/// |
| 13 | +/// \file DataAdapters.h |
| 14 | +/// \author Michal Tichak |
| 15 | +/// |
| 16 | + |
| 17 | +#ifndef QC_CORE_DATA_ADAPTERS_IMPL_H |
| 18 | +#define QC_CORE_DATA_ADAPTERS_IMPL_H |
| 19 | + |
| 20 | +#include <optional> |
| 21 | +#include <string_view> |
| 22 | +#include "QualityControl/Data.h" |
| 23 | +#include "QualityControl/MonitorObject.h" |
| 24 | +#include "QualityControl/QualityObject.h" |
| 25 | +// #include "QualityControl/DataAdapters.h" |
| 26 | + |
| 27 | +namespace o2::quality_control::core |
| 28 | +{ |
| 29 | + |
| 30 | +template <typename Result, typename DataContainer> |
| 31 | +auto iterateMonitorObjects(const DataGeneric<DataContainer>& data, std::string_view moName) |
| 32 | +{ |
| 33 | + return data.template iterateByTypeFilterAndTransform<MonitorObject, Result>( |
| 34 | + [name = std::string{ moName }](const std::pair<std::string_view, const MonitorObject*>& pair) -> bool { return std::string_view{ pair.second->GetName() } == name; }, |
| 35 | + [](const MonitorObject* ptr) -> const Result* { return dynamic_cast<const Result*>(ptr->getObject()); }); |
| 36 | +} |
| 37 | + |
| 38 | +inline auto iterateMonitorObjects(const o2::quality_control::core::Data& data) |
| 39 | +{ |
| 40 | + return data.iterateByType<o2::quality_control::core::MonitorObject>(); |
| 41 | +} |
| 42 | + |
| 43 | +template <typename StoredType> |
| 44 | +std::optional<std::reference_wrapper<const StoredType>> getMonitorObject(const Data& data, std::string_view objectName) |
| 45 | +{ |
| 46 | + if constexpr (std::same_as<StoredType, MonitorObject>) { |
| 47 | + for (const auto& mo : data.iterateByTypeAndFilter<o2::quality_control::core::MonitorObject>( |
| 48 | + [&objectName](const auto& pair) { |
| 49 | + return pair.second->GetName() == objectName; |
| 50 | + })) { |
| 51 | + return { mo }; |
| 52 | + } |
| 53 | + } else { |
| 54 | + for (const auto& v : data.template iterateByTypeFilterAndTransform<MonitorObject, StoredType>( |
| 55 | + [&objectName](const std::pair<std::string_view, const MonitorObject*>& pair) -> bool { return std::string_view{ pair.second->GetName() } == objectName; }, |
| 56 | + [](const MonitorObject* ptr) -> const auto* { return dynamic_cast<const StoredType*>(ptr->getObject()); })) { |
| 57 | + return { v }; |
| 58 | + } |
| 59 | + } |
| 60 | + return std::nullopt; |
| 61 | +} |
| 62 | + |
| 63 | +// inline auto iterateMonitorObjects(const o2::quality_control::core::Data& data, std::string_view taskName) |
| 64 | +// { |
| 65 | +// return data.iterateByTypeAndFilter<o2::quality_control::core::MonitorObject>([taskName = std::string{ taskName }](const auto& pair) { return pair.second->getTaskName() == taskName; }); |
| 66 | +// } |
| 67 | +// |
| 68 | +// std::optional<std::reference_wrapper<const o2::quality_control::core::MonitorObject>> getMonitorObject(const o2::quality_control::core::Data& data, std::string_view objectName, std::string_view taskName) |
| 69 | +// { |
| 70 | +// for (const auto& mo : data.iterateByTypeAndFilter<o2::quality_control::core::MonitorObject>( |
| 71 | +// [&taskName, &objectName](const auto& pair) { |
| 72 | +// return std::tuple(pair.second->getTaskName(), pair.second->GetName()) == std::tuple(taskName, objectName); |
| 73 | +// })) { |
| 74 | +// return { mo }; |
| 75 | +// } |
| 76 | +// return std::nullopt; |
| 77 | +// } |
| 78 | + |
| 79 | +// std::optional<std::reference_wrapper<const o2::quality_control::core::MonitorObject>> getMonitorObject(const o2::quality_control::core::Data& data, std::string_view objectName) |
| 80 | +// { |
| 81 | +// for (const auto& mo : data.iterateByTypeAndFilter<o2::quality_control::core::MonitorObject>( |
| 82 | +// [&objectName](const auto& pair) { |
| 83 | +// return objectName == pair.second->GetName(); |
| 84 | +// })) { |
| 85 | +// return { mo }; |
| 86 | +// } |
| 87 | +// return std::nullopt; |
| 88 | +// } |
| 89 | + |
| 90 | +} // namespace o2::quality_control::core |
| 91 | + |
| 92 | +#endif |
0 commit comments