From be979c82f57680c6a0b08b20f01e3dd271536fbd Mon Sep 17 00:00:00 2001 From: Piotr Konopka Date: Wed, 24 Apr 2024 17:06:49 +0200 Subject: [PATCH] QC-1160 Move to the new names for QC flags Needs new QC release. The documentation will be updated in a separate PR. --- DataFormats/QualityControl/CMakeLists.txt | 60 ++++---- .../etc/{flagReasons.csv => flagTypes.csv} | 0 .../DataFormatsQualityControl/FlagReasons.h | 73 ---------- .../DataFormatsQualityControl/FlagType.h | 50 ++++++- .../FlagTypeFactory.h | 22 --- ...easonFactory.h.in => FlagTypeFactory.h.in} | 18 +-- .../QualityControlFlag.h | 73 +++++++++- .../QualityControlFlagCollection.h | 88 +++++++++++- .../DataFormatsQualityControl/TimeRangeFlag.h | 88 ------------ .../TimeRangeFlagCollection.h | 102 ------------- .../src/DataFormatsQualityControlLinkDef.h | 6 +- .../src/{FlagReasons.cxx => FlagType.cxx} | 18 +-- ...meRangeFlag.cxx => QualityControlFlag.cxx} | 18 +-- ...n.cxx => QualityControlFlagCollection.cxx} | 68 ++++----- ...{testFlagReasons.cxx => testFlagTypes.cxx} | 48 +++---- ...ngeFlag.cxx => testQualityControlFlag.cxx} | 20 +-- .../test/testQualityControlFlagCollection.cxx | 136 ++++++++++++++++++ .../test/testTimeRangeFlagCollection.cxx | 136 ------------------ 18 files changed, 461 insertions(+), 563 deletions(-) rename DataFormats/QualityControl/etc/{flagReasons.csv => flagTypes.csv} (100%) delete mode 100644 DataFormats/QualityControl/include/DataFormatsQualityControl/FlagReasons.h delete mode 100644 DataFormats/QualityControl/include/DataFormatsQualityControl/FlagTypeFactory.h rename DataFormats/QualityControl/include/DataFormatsQualityControl/{FlagReasonFactory.h.in => FlagTypeFactory.h.in} (67%) delete mode 100644 DataFormats/QualityControl/include/DataFormatsQualityControl/TimeRangeFlag.h delete mode 100644 DataFormats/QualityControl/include/DataFormatsQualityControl/TimeRangeFlagCollection.h rename DataFormats/QualityControl/src/{FlagReasons.cxx => FlagType.cxx} (70%) rename DataFormats/QualityControl/src/{TimeRangeFlag.cxx => QualityControlFlag.cxx} (74%) rename DataFormats/QualityControl/src/{TimeRangeFlagCollection.cxx => QualityControlFlagCollection.cxx} (65%) rename DataFormats/QualityControl/test/{testFlagReasons.cxx => testFlagTypes.cxx} (62%) rename DataFormats/QualityControl/test/{testTimeRangeFlag.cxx => testQualityControlFlag.cxx} (58%) create mode 100644 DataFormats/QualityControl/test/testQualityControlFlagCollection.cxx delete mode 100644 DataFormats/QualityControl/test/testTimeRangeFlagCollection.cxx diff --git a/DataFormats/QualityControl/CMakeLists.txt b/DataFormats/QualityControl/CMakeLists.txt index 03a3b0ed49f69..c0f40a88f88c1 100644 --- a/DataFormats/QualityControl/CMakeLists.txt +++ b/DataFormats/QualityControl/CMakeLists.txt @@ -10,33 +10,32 @@ # or submit itself to any jurisdiction. file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include) -### Prepare the list of methods in FlagReasonFactory -file(READ "etc/flagReasons.csv" CSV_FLAG_REASONS) +### Prepare the list of methods in FlagTypeFactory +file(READ "etc/flagTypes.csv" CSV_FLAG_TYPES) # delete the CSV file header -string(REPLACE \"id\",\"method\",\"name\",\"bad\",\"obsolete\" "" CSV_FLAG_REASONS ${CSV_FLAG_REASONS}) +string(REPLACE \"id\",\"method\",\"name\",\"bad\",\"obsolete\" "" CSV_FLAG_TYPES ${CSV_FLAG_TYPES}) # detects if there is obsolete flag '1' in the last column, adds [[deprecated]] if so and retains the rest of the string string(REGEX REPLACE \([0-9]+,\".[^\"]*.\",.[^\"]*.,[0-1]\),1 "[[deprecated]] \\1,1" - CSV_FLAG_REASONS - ${CSV_FLAG_REASONS}) + CSV_FLAG_TYPES + ${CSV_FLAG_TYPES}) # replaces the flag reason entry with a c++ method to create it string(REGEX REPLACE \([0-9]+\),\"\(.[^\"]*.\)\",\(.[^\"]*.\),\([0-1]\),[0-1] - "static FlagReason \\2\(\) { return { static_cast\(\\1\), \\3, static_cast\(\\4\) }; }" - CSV_FLAG_REASONS - ${CSV_FLAG_REASONS}) + "static FlagType \\2\(\) { return { static_cast\(\\1\), \\3, static_cast\(\\4\) }; }" + CSV_FLAG_TYPES + ${CSV_FLAG_TYPES}) # put the method lists inside the template -configure_file("include/DataFormatsQualityControl/FlagReasonFactory.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/include/DataFormatsQualityControl/FlagReasonFactory.h" +configure_file("include/DataFormatsQualityControl/FlagTypeFactory.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/include/DataFormatsQualityControl/FlagTypeFactory.h" @ONLY) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/DataFormatsQualityControl/FlagReasonFactory.h" +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/DataFormatsQualityControl/FlagTypeFactory.h" DESTINATION include/DataFormatsQualityControl) o2_add_library(DataFormatsQualityControl - SOURCES src/FlagReasons.cxx - src/TimeRangeFlag.cxx - src/TimeRangeFlagCollection.cxx - PUBLIC_LINK_LIBRARIES O2::Headers - O2::FrameworkLogger + SOURCES src/FlagType.cxx + src/QualityControlFlag.cxx + src/QualityControlFlagCollection.cxx + PUBLIC_LINK_LIBRARIES O2::FrameworkLogger O2::DetectorsCommonDataFormats PUBLIC_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/include include @@ -44,35 +43,32 @@ o2_add_library(DataFormatsQualityControl o2_target_root_dictionary(DataFormatsQualityControl HEADERS include/DataFormatsQualityControl/FlagType.h - include/DataFormatsQualityControl/FlagReasons.h include/DataFormatsQualityControl/QualityControlFlag.h - include/DataFormatsQualityControl/TimeRangeFlag.h - include/DataFormatsQualityControl/TimeRangeFlagCollection.h) - + include/DataFormatsQualityControl/QualityControlFlagCollection.h) if(BUILD_TESTING) -o2_add_test(FlagReasons - SOURCES test/testFlagReasons.cxx +o2_add_test(FlagTypes + SOURCES test/testFlagTypes.cxx COMPONENT_NAME DataFormatsQualityControl PUBLIC_LINK_LIBRARIES O2::DataFormatsQualityControl - TARGETVARNAME flagreasons) + TARGETVARNAME flagtypes) -target_include_directories(${flagreasons} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include) +target_include_directories(${flagtypes} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include) -o2_add_test(TimeRangeFlag - SOURCES test/testTimeRangeFlag.cxx +o2_add_test(QualityControlFlag + SOURCES test/testQualityControlFlag.cxx COMPONENT_NAME DataFormatsQualityControl PUBLIC_LINK_LIBRARIES O2::DataFormatsQualityControl - TARGETVARNAME timerangeflag) + TARGETVARNAME qualitycontrolflag) -target_include_directories(${timerangeflag} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include) +target_include_directories(${qualitycontrolflag} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include) -o2_add_test(TimeRangeFlagCollection - SOURCES test/testTimeRangeFlagCollection.cxx +o2_add_test(QualityControlFlagCollection + SOURCES test/testQualityControlFlagCollection.cxx COMPONENT_NAME DataFormatsQualityControl PUBLIC_LINK_LIBRARIES O2::DataFormatsQualityControl - TARGETVARNAME timerangeflagcollection) + TARGETVARNAME qualitycontrolflagcollection) -target_include_directories(${timerangeflagcollection} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include) +target_include_directories(${qualitycontrolflagcollection} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include) endif() diff --git a/DataFormats/QualityControl/etc/flagReasons.csv b/DataFormats/QualityControl/etc/flagTypes.csv similarity index 100% rename from DataFormats/QualityControl/etc/flagReasons.csv rename to DataFormats/QualityControl/etc/flagTypes.csv diff --git a/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagReasons.h b/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagReasons.h deleted file mode 100644 index 67f5b4cc27cde..0000000000000 --- a/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagReasons.h +++ /dev/null @@ -1,73 +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. - -#ifndef ALICEO2_ANALYSIS_FLAGREASONS -#define ALICEO2_ANALYSIS_FLAGREASONS - -/// \file FlagReasons.h -/// \brief classes keeping reasons for flagging time ranges -/// \author Jens Wiechula, jens.wiechula@ikf.uni-frankfurt.de -/// \author Piotr Konopka, piotr.jan.konopka@cern.ch - -// STL -#include -#include - -// ROOT includes -#include - -namespace o2 -{ -namespace quality_control -{ - -class FlagReasonFactory; -class TimeRangeFlagCollection; - -class FlagReason -{ - private: - uint16_t mId; - std::string mName; - bool mBad; // if true, data should become bad by default - - // By making the constructor private and FlagReasons available only in the FlagReasonFactory - // we forbid to declare any flags in the user code. If you need a new FlagReason, please add it FlagReasonFactory. - private: - FlagReason(uint16_t id, const char* name, bool bad) : mId(id), mName(name), mBad(bad) {} - - public: - FlagReason(); - FlagReason& operator=(const FlagReason&) = default; - FlagReason(const FlagReason&) = default; - bool operator==(const FlagReason& rhs) const; - bool operator!=(const FlagReason& rhs) const; - bool operator<(const FlagReason& rhs) const; - bool operator>(const FlagReason& rhs) const; - - uint16_t getID() const { return mId; } - const std::string& getName() const { return mName; } - bool getBad() const { return mBad; } - - friend std::ostream& operator<<(std::ostream& os, FlagReason const& me); - friend class FlagReasonFactory; - friend class TimeRangeFlagCollection; - - ClassDefNV(FlagReason, 1); -}; - -} // namespace quality_control -} // namespace o2 - -// TODO: remove once we include it in QualityControl -#include "DataFormatsQualityControl/FlagReasonFactory.h" - -#endif diff --git a/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagType.h b/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagType.h index c862835530de6..94e4a301a1784 100644 --- a/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagType.h +++ b/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagType.h @@ -12,11 +12,53 @@ #ifndef O2_QUALITYCONTROL_FLAGTYPE_H #define O2_QUALITYCONTROL_FLAGTYPE_H -#include "DataFormatsQualityControl/FlagReasons.h" +// STL +#include +#include -namespace o2::quality_control +// ROOT includes +#include + +namespace o2 +{ +namespace quality_control +{ + +class FlagTypeFactory; +class QualityControlFlagCollection; + +class FlagType { -using FlagType = o2::quality_control::FlagReason; -} + private: + uint16_t mId; + std::string mName; + bool mBad; // if true, data should become bad by default + + // By making the constructor private and FlagTypes available only in the FlagTypeFactory + // we forbid to declare any flags in the user code. If you need a new FlagType, please add it FlagTypeFactory. + private: + FlagType(uint16_t id, const char* name, bool bad) : mId(id), mName(name), mBad(bad) {} + + public: + FlagType(); + FlagType& operator=(const FlagType&) = default; + FlagType(const FlagType&) = default; + bool operator==(const FlagType& rhs) const; + bool operator!=(const FlagType& rhs) const; + bool operator<(const FlagType& rhs) const; + bool operator>(const FlagType& rhs) const; + + uint16_t getID() const { return mId; } + const std::string& getName() const { return mName; } + bool getBad() const { return mBad; } + + friend std::ostream& operator<<(std::ostream& os, FlagType const& me); + friend class FlagTypeFactory; + friend class QualityControlFlagCollection; + + ClassDefNV(FlagType, 1); +}; +} // namespace quality_control +} // namespace o2 #endif // O2_QUALITYCONTROL_FLAGTYPE_H diff --git a/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagTypeFactory.h b/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagTypeFactory.h deleted file mode 100644 index ea28ffbd3d944..0000000000000 --- a/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagTypeFactory.h +++ /dev/null @@ -1,22 +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. - -#ifndef O2_QUALITYCONTROL_FLAGTYPEFACTORY_H -#define O2_QUALITYCONTROL_FLAGTYPEFACTORY_H - -#include "DataFormatsQualityControl/FlagReasonFactory.h" - -namespace o2::quality_control -{ -using FlagTypeFactory = o2::quality_control::FlagReasonFactory; -} - -#endif // O2_QUALITYCONTROL_FLAGTYPEFACTORY_H diff --git a/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagReasonFactory.h.in b/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagTypeFactory.h.in similarity index 67% rename from DataFormats/QualityControl/include/DataFormatsQualityControl/FlagReasonFactory.h.in rename to DataFormats/QualityControl/include/DataFormatsQualityControl/FlagTypeFactory.h.in index 59bd7b4c5628f..38b6c463d239f 100644 --- a/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagReasonFactory.h.in +++ b/DataFormats/QualityControl/include/DataFormatsQualityControl/FlagTypeFactory.h.in @@ -9,23 +9,23 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// \file FlagReasonFactory.h -/// \brief A class to create FlagReasons based on the predefined CSV list. +/// \file FlagTypeFactory.h +/// \brief A class to create FlagTypes based on the predefined CSV list. /// \author Piotr Konopka, piotr.jan.konopka@cern.ch -#ifndef O2_FLAGREASONFACTORY_H -#define O2_FLAGREASONFACTORY_H +#ifndef O2_FLAGTYPEFACTORY_H +#define O2_FLAGTYPEFACTORY_H -#include "DataFormatsQualityControl/FlagReasons.h" +#include "DataFormatsQualityControl/FlagType.h" namespace o2::quality_control { -class FlagReasonFactory { +class FlagTypeFactory { public: -FlagReasonFactory() = delete; -@CSV_FLAG_REASONS@ +FlagTypeFactory() = delete; +@CSV_FLAG_TYPES@ }; } // namespace o2::quality_control -#endif // O2_FLAGREASONFACTORY_H \ No newline at end of file +#endif // O2_FLAGTYPEFACTORY_H \ No newline at end of file diff --git a/DataFormats/QualityControl/include/DataFormatsQualityControl/QualityControlFlag.h b/DataFormats/QualityControl/include/DataFormatsQualityControl/QualityControlFlag.h index 96c778220f617..16123b74895ab 100644 --- a/DataFormats/QualityControl/include/DataFormatsQualityControl/QualityControlFlag.h +++ b/DataFormats/QualityControl/include/DataFormatsQualityControl/QualityControlFlag.h @@ -12,11 +12,76 @@ #ifndef O2_QUALITYCONTROL_QCFLAG_H #define O2_QUALITYCONTROL_QCFLAG_H -#include "DataFormatsQualityControl/TimeRangeFlag.h" +/// \file QualityControlFlag.h +/// \brief Class to define a flag type with a time range and comments +/// \author Jens Wiechula, jens.wiechula@ikf.uni-frankfurt.de +/// \author Piotr Konopka, piotr.jan.konopka@cern.ch -namespace o2::quality_control +// System includes +#include +#include + +// ROOT includes +#include + +#include + +#include "DataFormatsQualityControl/FlagType.h" +#include "DataFormatsQualityControl/FlagTypeFactory.h" + +namespace o2 { -using QualityControlFlag = o2::quality_control::TimeRangeFlag; -} +namespace quality_control +{ + +/// \class QualityControlFlag +/// A Class for associating a bit mask with a time range +class QualityControlFlag +{ + public: + using time_type = uint64_t; + using RangeInterval = o2::math_utils::detail::Bracket; + + QualityControlFlag() = default; + QualityControlFlag(QualityControlFlag const&) = default; + QualityControlFlag(time_type start, time_type end, FlagType flag, std::string comment = "", std::string source = "Unknown"); + + time_type getStart() const { return mInterval.getMin(); } + time_type getEnd() const { return mInterval.getMax(); } + RangeInterval& getInterval() { return mInterval; } + FlagType getFlag() const { return mFlag; } + const std::string& getComment() const { return mComment; } + const std::string& getSource() const { return mSource; } + + void setStart(time_type start) { mInterval.setMin(start); } + void setEnd(time_type end) { mInterval.setMax(end); } + void setInterval(RangeInterval interval) { mInterval = interval; } + void setFlag(FlagType flag) { mFlag = flag; } + void setComment(const std::string& comment) { mComment = comment; } + void setSource(const std::string& source) { mSource = source; } + + /// equal operator + bool operator==(const QualityControlFlag& rhs) const; + + /// comparison operators + bool operator<(const QualityControlFlag& rhs) const; + bool operator>(const QualityControlFlag& rhs) const; + + /// write data to ostream + void streamTo(std::ostream& output) const; + + /// overloading output stream operator + friend std::ostream& operator<<(std::ostream& output, const QualityControlFlag& data); + + private: + RangeInterval mInterval = {}; ///< time interval of the masked range + FlagType mFlag; ///< flag reason + std::string mComment = ""; ///< optional comment, which may extend the reason + std::string mSource = "Unknown"; ///< optional (but encouraged) source of the flag (e.g. Qc Check name) + + ClassDefNV(QualityControlFlag, 1); +}; +} // namespace quality_control +} // namespace o2 #endif // O2_QUALITYCONTROL_QCFLAG_H diff --git a/DataFormats/QualityControl/include/DataFormatsQualityControl/QualityControlFlagCollection.h b/DataFormats/QualityControl/include/DataFormatsQualityControl/QualityControlFlagCollection.h index 04cd74f09444e..120605f048cbe 100644 --- a/DataFormats/QualityControl/include/DataFormatsQualityControl/QualityControlFlagCollection.h +++ b/DataFormats/QualityControl/include/DataFormatsQualityControl/QualityControlFlagCollection.h @@ -11,12 +11,92 @@ #ifndef O2_QUALITYCONTROL_QCFLAGCOLLECTION_H #define O2_QUALITYCONTROL_QCFLAGCOLLECTION_H +/// \file QualityControlFlagCollection.h +/// \brief classes for defining time ranges with a certain mask to be able to cut on +/// \author Jens Wiechula, jens.wiechula@ikf.uni-frankfurt.de -#include "DataFormatsQualityControl/TimeRangeFlagCollection.h" +// System includes +#include -namespace o2::quality_control +// ROOT includes +#include "Rtypes.h" + +// O2 includes +#include "MathUtils/detail/Bracket.h" +#include "DataFormatsQualityControl/QualityControlFlag.h" + +// STL +#include + +namespace o2 +{ +namespace quality_control +{ + +/// \class QualityControlFlagCollection +/// A Class for keeping several time ranges of type QualityControlFlag +class QualityControlFlagCollection { -using QualityControlFlagCollection = o2::quality_control::TimeRangeFlagCollection; -} + public: + using collection_t = std::set; + using time_type = uint64_t; + using RangeInterval = o2::math_utils::detail::Bracket; + + explicit QualityControlFlagCollection(std::string name, std::string detector = "TST", RangeInterval validityRange = {}, + int runNumber = 0, std::string periodName = "Invalid", std::string passName = "Invalid", + std::string provenance = "qc"); + + void insert(QualityControlFlag&&); + void insert(const QualityControlFlag&); + + size_t size() const; + + // moves all non-repeating QualityControlFlags from other to this + void merge(QualityControlFlagCollection& other); + // add all non-repeating QualityControlFlags from other to this. + void merge(const QualityControlFlagCollection& other); + + collection_t::const_iterator begin() const; + collection_t::const_iterator end() const; + + const std::string& getName() const; + const std::string& getDetector() const; + int getRunNumber() const; + const std::string& getPeriodName() const; + const std::string& getPassName() const; + const std::string& getProvenance() const; + + time_type getStart() const { return mValidityRange.getMin(); } + time_type getEnd() const { return mValidityRange.getMax(); } + RangeInterval& getInterval() { return mValidityRange; } + + void setStart(time_type start) { mValidityRange.setMin(start); } + void setEnd(time_type end) { mValidityRange.setMax(end); } + void setInterval(RangeInterval interval) { mValidityRange = interval; } + + /// write data to ostream + void streamTo(std::ostream& output) const; + /// Read data from instream + void streamFrom(std::istream& input); + + /// overloading output stream operator + friend std::ostream& operator<<(std::ostream& output, const QualityControlFlagCollection& data); + + private: + std::string mDetID; // three letter detector code + std::string mName; // some description of the collection, e.g. "Raw data checks", "QA Expert masks" + // with std::set we can sort the flags in time and have merge() for granted. + collection_t mQualityControlFlags; + RangeInterval mValidityRange; // we need a validity range to e.g. state that there are no TRFs for given time interval + int mRunNumber; + std::string mPeriodName; + std::string mPassName; + std::string mProvenance; + + ClassDefNV(QualityControlFlagCollection, 1); +}; + +} // namespace quality_control +} // namespace o2 #endif // O2_QUALITYCONTROL_QCFLAGCOLLECTION_H diff --git a/DataFormats/QualityControl/include/DataFormatsQualityControl/TimeRangeFlag.h b/DataFormats/QualityControl/include/DataFormatsQualityControl/TimeRangeFlag.h deleted file mode 100644 index b8e1efbce1f40..0000000000000 --- a/DataFormats/QualityControl/include/DataFormatsQualityControl/TimeRangeFlag.h +++ /dev/null @@ -1,88 +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. - -#ifndef ALICEO2_ANALYSIS_TIMERANGEFLAGS -#define ALICEO2_ANALYSIS_TIMERANGEFLAGS - -/// \file TimeRangeFlag.h -/// \brief Class to define a time range of a flag type -/// \author Jens Wiechula, jens.wiechula@ikf.uni-frankfurt.de -/// \author Piotr Konopka, piotr.jan.konopka@cern.ch - -// System includes -#include -#include - -// ROOT includes -#include - -#include - -#include "DataFormatsQualityControl/FlagReasons.h" -#include "DataFormatsQualityControl/FlagReasonFactory.h" - -namespace o2 -{ -namespace quality_control -{ - -/// \class TimeRangeFlag -/// A Class for associating a bit mask with a time range -class TimeRangeFlag -{ - public: - using time_type = uint64_t; - using flag_type = FlagReason; - using RangeInterval = o2::math_utils::detail::Bracket; - - TimeRangeFlag() = default; - TimeRangeFlag(TimeRangeFlag const&) = default; - TimeRangeFlag(time_type start, time_type end, flag_type flag, std::string comment = "", std::string source = "Unknown"); - - time_type getStart() const { return mInterval.getMin(); } - time_type getEnd() const { return mInterval.getMax(); } - RangeInterval& getInterval() { return mInterval; } - flag_type getFlag() const { return mFlag; } - const std::string& getComment() const { return mComment; } - const std::string& getSource() const { return mSource; } - - void setStart(time_type start) { mInterval.setMin(start); } - void setEnd(time_type end) { mInterval.setMax(end); } - void setInterval(RangeInterval interval) { mInterval = interval; } - void setFlag(flag_type flag) { mFlag = flag; } - void setComment(const std::string& comment) { mComment = comment; } - void setSource(const std::string& source) { mSource = source; } - - /// equal operator - bool operator==(const TimeRangeFlag& rhs) const; - - /// comparison operators - bool operator<(const TimeRangeFlag& rhs) const; - bool operator>(const TimeRangeFlag& rhs) const; - - /// write data to ostream - void streamTo(std::ostream& output) const; - - /// overloading output stream operator - friend std::ostream& operator<<(std::ostream& output, const TimeRangeFlag& data); - - private: - RangeInterval mInterval = {}; ///< time interval of the masked range - flag_type mFlag; ///< flag reason - std::string mComment = ""; ///< optional comment, which may extend the reason - std::string mSource = "Unknown"; ///< optional (but encouraged) source of the flag (e.g. Qc Check name) - - ClassDefNV(TimeRangeFlag, 1); -}; - -} // namespace quality_control -} // namespace o2 -#endif diff --git a/DataFormats/QualityControl/include/DataFormatsQualityControl/TimeRangeFlagCollection.h b/DataFormats/QualityControl/include/DataFormatsQualityControl/TimeRangeFlagCollection.h deleted file mode 100644 index 30a8230fc66e2..0000000000000 --- a/DataFormats/QualityControl/include/DataFormatsQualityControl/TimeRangeFlagCollection.h +++ /dev/null @@ -1,102 +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. - -#ifndef ALICEO2_ANALYSIS_TIMERANGEMASK -#define ALICEO2_ANALYSIS_TIMERANGEMASK - -/// \file TimeRangeFlagCollection.h -/// \brief classes for defining time ranges with a certain mask to be able to cut on -/// \author Jens Wiechula, jens.wiechula@ikf.uni-frankfurt.de - -// System includes -#include - -// ROOT includes -#include "Rtypes.h" - -// O2 includes -#include "MathUtils/detail/Bracket.h" -#include "DataFormatsQualityControl/TimeRangeFlag.h" - -// STL -#include - -namespace o2 -{ -namespace quality_control -{ - -/// \class TimeRangeFlagCollection -/// A Class for keeping several time ranges of type TimeRangeFlag -class TimeRangeFlagCollection -{ - public: - using collection_t = std::set; - using time_type = uint64_t; - using RangeInterval = o2::math_utils::detail::Bracket; - - explicit TimeRangeFlagCollection(std::string name, std::string detector = "TST", RangeInterval validityRange = {}, - int runNumber = 0, std::string periodName = "Invalid", std::string passName = "Invalid", - std::string provenance = "qc"); - - void insert(TimeRangeFlag&&); - void insert(const TimeRangeFlag&); - - size_t size() const; - - // moves all non-repeating TimeRangeFlags from other to this - void merge(TimeRangeFlagCollection& other); - // add all non-repeating TimeRangeFlags from other to this. - void merge(const TimeRangeFlagCollection& other); - - collection_t::const_iterator begin() const; - collection_t::const_iterator end() const; - - const std::string& getName() const; - const std::string& getDetector() const; - int getRunNumber() const; - const std::string& getPeriodName() const; - const std::string& getPassName() const; - const std::string& getProvenance() const; - - time_type getStart() const { return mValidityRange.getMin(); } - time_type getEnd() const { return mValidityRange.getMax(); } - RangeInterval& getInterval() { return mValidityRange; } - - void setStart(time_type start) { mValidityRange.setMin(start); } - void setEnd(time_type end) { mValidityRange.setMax(end); } - void setInterval(RangeInterval interval) { mValidityRange = interval; } - - /// write data to ostream - void streamTo(std::ostream& output) const; - /// Read data from instream - void streamFrom(std::istream& input); - - /// overloading output stream operator - friend std::ostream& operator<<(std::ostream& output, const TimeRangeFlagCollection& data); - - private: - std::string mDetID; // three letter detector code - std::string mName; // some description of the collection, e.g. "Raw data checks", "QA Expert masks" - // with std::set we can sort the flags in time and have merge() for granted. - collection_t mTimeRangeFlags; - RangeInterval mValidityRange; // we need a validity range to e.g. state that there are no TRFs for given time interval - int mRunNumber; - std::string mPeriodName; - std::string mPassName; - std::string mProvenance; - - ClassDefNV(TimeRangeFlagCollection, 1); -}; - -} // namespace quality_control -} // namespace o2 -#endif diff --git a/DataFormats/QualityControl/src/DataFormatsQualityControlLinkDef.h b/DataFormats/QualityControl/src/DataFormatsQualityControlLinkDef.h index 8d77bccef4b7c..ab10c361b29f9 100644 --- a/DataFormats/QualityControl/src/DataFormatsQualityControlLinkDef.h +++ b/DataFormats/QualityControl/src/DataFormatsQualityControlLinkDef.h @@ -15,8 +15,8 @@ #pragma link off all classes; #pragma link off all functions; -#pragma link C++ class o2::quality_control::FlagReason + ; -#pragma link C++ class o2::quality_control::TimeRangeFlag + ; -#pragma link C++ class o2::quality_control::TimeRangeFlagCollection + ; +#pragma link C++ class o2::quality_control::FlagType + ; +#pragma link C++ class o2::quality_control::QualityControlFlag + ; +#pragma link C++ class o2::quality_control::QualityControlFlagCollection + ; #endif diff --git a/DataFormats/QualityControl/src/FlagReasons.cxx b/DataFormats/QualityControl/src/FlagType.cxx similarity index 70% rename from DataFormats/QualityControl/src/FlagReasons.cxx rename to DataFormats/QualityControl/src/FlagType.cxx index e85a0d0c7faa7..27e59911ed775 100644 --- a/DataFormats/QualityControl/src/FlagReasons.cxx +++ b/DataFormats/QualityControl/src/FlagType.cxx @@ -9,8 +9,8 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -#include "DataFormatsQualityControl/FlagReasons.h" -#include "DataFormatsQualityControl/FlagReasonFactory.h" +#include "DataFormatsQualityControl/FlagType.h" +#include "DataFormatsQualityControl/FlagTypeFactory.h" #include #include @@ -18,29 +18,29 @@ namespace o2::quality_control { -FlagReason::FlagReason() +FlagType::FlagType() { - *this = FlagReasonFactory::Invalid(); + *this = FlagTypeFactory::Invalid(); } -std::ostream& operator<<(std::ostream& os, FlagReason const& my) +std::ostream& operator<<(std::ostream& os, FlagType const& my) { os << "Flag Reason: id - " << my.mId << ", name - " << my.mName << ", bad - " << (my.mBad ? "true" : "false"); return os; } -bool FlagReason::operator==(const FlagReason& rhs) const +bool FlagType::operator==(const FlagType& rhs) const { return std::tie(mId, mName, mBad) == std::tie(rhs.mId, rhs.mName, rhs.mBad); } -bool FlagReason::operator!=(const FlagReason& rhs) const +bool FlagType::operator!=(const FlagType& rhs) const { return std::tie(mId, mName, mBad) != std::tie(rhs.mId, rhs.mName, rhs.mBad); } -bool FlagReason::operator<(const FlagReason& rhs) const +bool FlagType::operator<(const FlagType& rhs) const { return std::tie(mId, mName, mBad) < std::tie(rhs.mId, rhs.mName, rhs.mBad); } -bool FlagReason::operator>(const FlagReason& rhs) const +bool FlagType::operator>(const FlagType& rhs) const { return std::tie(mId, mName, mBad) > std::tie(rhs.mId, rhs.mName, rhs.mBad); } diff --git a/DataFormats/QualityControl/src/TimeRangeFlag.cxx b/DataFormats/QualityControl/src/QualityControlFlag.cxx similarity index 74% rename from DataFormats/QualityControl/src/TimeRangeFlag.cxx rename to DataFormats/QualityControl/src/QualityControlFlag.cxx index f96d5bc9b7b72..ce749cad5315f 100644 --- a/DataFormats/QualityControl/src/TimeRangeFlag.cxx +++ b/DataFormats/QualityControl/src/QualityControlFlag.cxx @@ -9,7 +9,7 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -#include "DataFormatsQualityControl/TimeRangeFlag.h" +#include "DataFormatsQualityControl/QualityControlFlag.h" #include #include @@ -17,20 +17,20 @@ namespace o2::quality_control { -TimeRangeFlag::TimeRangeFlag(time_type start, time_type end, flag_type flag, std::string comment, std::string source) +QualityControlFlag::QualityControlFlag(time_type start, time_type end, FlagType flag, std::string comment, std::string source) : mInterval(start, end), mFlag(flag), mComment(comment), mSource(source) { if (mInterval.isInvalid()) { - throw std::runtime_error("TimeRangeFlag start time '" + std::to_string(mInterval.getMin()) + "' is larger than end time '" + std::to_string(mInterval.getMax()) + "'"); + throw std::runtime_error("QualityControlFlag start time '" + std::to_string(mInterval.getMin()) + "' is larger than end time '" + std::to_string(mInterval.getMax()) + "'"); } } -bool TimeRangeFlag::operator==(const TimeRangeFlag& rhs) const +bool QualityControlFlag::operator==(const QualityControlFlag& rhs) const { return std::tie(mInterval, mFlag, mComment, mSource) == std::tie(rhs.mInterval, rhs.mFlag, rhs.mComment, rhs.mSource); } -bool TimeRangeFlag::operator<(const TimeRangeFlag& rhs) const +bool QualityControlFlag::operator<(const QualityControlFlag& rhs) const { // We don't use the comparison mechanism in Bracket, // because std::set which is used in TRFCollection assumes that a < b, a > b <=> a == b. @@ -38,16 +38,16 @@ bool TimeRangeFlag::operator<(const TimeRangeFlag& rhs) const return std::tie(static_cast(mInterval.getMin()), static_cast(mInterval.getMax()), mFlag, mComment, mSource) < std::tie(static_cast(rhs.mInterval.getMin()), static_cast(rhs.mInterval.getMax()), rhs.mFlag, rhs.mComment, rhs.mSource); } -bool TimeRangeFlag::operator>(const TimeRangeFlag& rhs) const +bool QualityControlFlag::operator>(const QualityControlFlag& rhs) const { // we don't use the comparison mechanism in Bracket, // because std::set which is used in TRFCollection assumes that a < b, a > b <=> a == b return std::tie(static_cast(mInterval.getMin()), static_cast(mInterval.getMax()), mFlag, mComment, mSource) > std::tie(static_cast(rhs.mInterval.getMin()), static_cast(rhs.mInterval.getMax()), rhs.mFlag, rhs.mComment, rhs.mSource); } -void TimeRangeFlag::streamTo(std::ostream& output) const +void QualityControlFlag::streamTo(std::ostream& output) const { - output << "TimeRangeFlag:\n"; + output << "QualityControlFlag:\n"; output << "- Start: " << mInterval.getMin() << "\n"; output << "- End: " << mInterval.getMax() << "\n"; output << "- " << mFlag << "\n"; @@ -55,7 +55,7 @@ void TimeRangeFlag::streamTo(std::ostream& output) const output << "- Source: " << mSource; } -std::ostream& operator<<(std::ostream& output, const TimeRangeFlag& data) +std::ostream& operator<<(std::ostream& output, const QualityControlFlag& data) { data.streamTo(output); return output; diff --git a/DataFormats/QualityControl/src/TimeRangeFlagCollection.cxx b/DataFormats/QualityControl/src/QualityControlFlagCollection.cxx similarity index 65% rename from DataFormats/QualityControl/src/TimeRangeFlagCollection.cxx rename to DataFormats/QualityControl/src/QualityControlFlagCollection.cxx index ee3adc8dc7f2f..042ef2f218d09 100644 --- a/DataFormats/QualityControl/src/TimeRangeFlagCollection.cxx +++ b/DataFormats/QualityControl/src/QualityControlFlagCollection.cxx @@ -10,8 +10,8 @@ // or submit itself to any jurisdiction. // O2 include -#include "DataFormatsQualityControl/TimeRangeFlagCollection.h" -#include "DataFormatsQualityControl/FlagReasonFactory.h" +#include "DataFormatsQualityControl/QualityControlFlagCollection.h" +#include "DataFormatsQualityControl/FlagTypeFactory.h" #include "Framework/Logger.h" #include @@ -25,56 +25,56 @@ namespace o2::quality_control constexpr const char* csvHeader = "start,end,flag_id,flag_name,flag_bad,comment,source"; constexpr size_t csvColumns = 7; -TimeRangeFlagCollection::TimeRangeFlagCollection(std::string name, std::string detector, RangeInterval validityRange, - int runNumber, std::string periodName, std::string passName, - std::string provenance) +QualityControlFlagCollection::QualityControlFlagCollection(std::string name, std::string detector, RangeInterval validityRange, + int runNumber, std::string periodName, std::string passName, + std::string provenance) : mName(std::move(name)), mDetID(std::move(detector)), mValidityRange(validityRange), mRunNumber(runNumber), mPeriodName(std::move(periodName)), mPassName(passName), mProvenance(std::move(provenance)) { } -void TimeRangeFlagCollection::insert(TimeRangeFlag&& trf) +void QualityControlFlagCollection::insert(QualityControlFlag&& trf) { - mTimeRangeFlags.insert(std::move(trf)); + mQualityControlFlags.insert(std::move(trf)); } -void TimeRangeFlagCollection::insert(const TimeRangeFlag& trf) +void QualityControlFlagCollection::insert(const QualityControlFlag& trf) { - mTimeRangeFlags.insert(trf); + mQualityControlFlags.insert(trf); } -size_t TimeRangeFlagCollection::size() const +size_t QualityControlFlagCollection::size() const { - return mTimeRangeFlags.size(); + return mQualityControlFlags.size(); } -void TimeRangeFlagCollection::merge(TimeRangeFlagCollection& other) +void QualityControlFlagCollection::merge(QualityControlFlagCollection& other) { if (mDetID != other.mDetID) { - // We assume that one TimeRangeFlagCollection should correspond to one detector at most. + // We assume that one QualityControlFlagCollection should correspond to one detector at most. // However, if this becomes annoying, we can reconsider it. throw std::runtime_error( "The detector ID of the target collection '" + mDetID + "' is different than the other '" + mDetID); } - mTimeRangeFlags.merge(other.mTimeRangeFlags); + mQualityControlFlags.merge(other.mQualityControlFlags); } -void TimeRangeFlagCollection::merge(const TimeRangeFlagCollection& other) +void QualityControlFlagCollection::merge(const QualityControlFlagCollection& other) { - TimeRangeFlagCollection otherCopy{other}; + QualityControlFlagCollection otherCopy{other}; merge(otherCopy); } -TimeRangeFlagCollection::collection_t::const_iterator TimeRangeFlagCollection::begin() const +QualityControlFlagCollection::collection_t::const_iterator QualityControlFlagCollection::begin() const { - return mTimeRangeFlags.begin(); + return mQualityControlFlags.begin(); } -TimeRangeFlagCollection::collection_t::const_iterator TimeRangeFlagCollection::end() const +QualityControlFlagCollection::collection_t::const_iterator QualityControlFlagCollection::end() const { - return mTimeRangeFlags.end(); + return mQualityControlFlags.end(); } -void TimeRangeFlagCollection::streamTo(std::ostream& output) const +void QualityControlFlagCollection::streamTo(std::ostream& output) const { auto escapeComma = [](const std::string& str) { return boost::algorithm::replace_all_copy(str, ",", "\\,"); @@ -88,7 +88,7 @@ void TimeRangeFlagCollection::streamTo(std::ostream& output) const } } -void TimeRangeFlagCollection::streamFrom(std::istream& input) +void QualityControlFlagCollection::streamFrom(std::istream& input) { std::string line; std::getline(input, line); @@ -100,9 +100,9 @@ void TimeRangeFlagCollection::streamFrom(std::istream& input) while (std::getline(input, line)) { boost::tokenizer> tok(line); - TimeRangeFlag::time_type start = 0; - TimeRangeFlag::time_type end = 0; - FlagReason flag = FlagReasonFactory::Invalid(); + QualityControlFlag::time_type start = 0; + QualityControlFlag::time_type end = 0; + FlagType flag = FlagTypeFactory::Invalid(); std::string comment; std::string source; auto it = tok.begin(); @@ -115,7 +115,7 @@ void TimeRangeFlagCollection::streamFrom(std::istream& input) LOG(error) << "Invalid line, empty start time of a flag, skipping..."; valid = false; } else { - start = static_cast(std::stoull(*it)); + start = static_cast(std::stoull(*it)); } break; } @@ -124,7 +124,7 @@ void TimeRangeFlagCollection::streamFrom(std::istream& input) LOG(error) << "Invalid line, empty end time of a flag, skipping..."; valid = false; } else { - end = static_cast(std::stoull(*it)); + end = static_cast(std::stoull(*it)); } break; } @@ -179,37 +179,37 @@ void TimeRangeFlagCollection::streamFrom(std::istream& input) } } -std::ostream& operator<<(std::ostream& output, const TimeRangeFlagCollection& data) +std::ostream& operator<<(std::ostream& output, const QualityControlFlagCollection& data) { data.streamTo(output); return output; } -const std::string& TimeRangeFlagCollection::getName() const +const std::string& QualityControlFlagCollection::getName() const { return mName; } -const std::string& TimeRangeFlagCollection::getDetector() const +const std::string& QualityControlFlagCollection::getDetector() const { return mDetID; } -int TimeRangeFlagCollection::getRunNumber() const +int QualityControlFlagCollection::getRunNumber() const { return mRunNumber; } -const std::string& TimeRangeFlagCollection::getPeriodName() const +const std::string& QualityControlFlagCollection::getPeriodName() const { return mPeriodName; } -const std::string& TimeRangeFlagCollection::getPassName() const +const std::string& QualityControlFlagCollection::getPassName() const { return mPassName; } -const std::string& TimeRangeFlagCollection::getProvenance() const +const std::string& QualityControlFlagCollection::getProvenance() const { return mProvenance; } diff --git a/DataFormats/QualityControl/test/testFlagReasons.cxx b/DataFormats/QualityControl/test/testFlagTypes.cxx similarity index 62% rename from DataFormats/QualityControl/test/testFlagReasons.cxx rename to DataFormats/QualityControl/test/testFlagTypes.cxx index ebcd409ed3d46..e1587825a323a 100644 --- a/DataFormats/QualityControl/test/testFlagReasons.cxx +++ b/DataFormats/QualityControl/test/testFlagTypes.cxx @@ -29,28 +29,28 @@ BOOST_AUTO_TEST_CASE(FlagTypes) static_assert(std::is_constructible::value == false, "FlagType should not be constructible outside of its static methods and the factory."); - FlagType rDefault; - BOOST_CHECK_EQUAL(rDefault, FlagTypeFactory::Invalid()); - - auto r1 = FlagTypeFactory::Unknown(); - BOOST_CHECK_EQUAL(r1.getID(), 1); - BOOST_CHECK_EQUAL(r1.getName(), "Unknown"); - BOOST_CHECK_EQUAL(r1.getBad(), true); - - std::cout << r1 << std::endl; - - auto r2 = r1; - BOOST_CHECK_EQUAL(r2.getID(), 1); - BOOST_CHECK_EQUAL(r1.getName(), r2.getName()); - BOOST_CHECK_EQUAL(r2.getName(), "Unknown"); - BOOST_CHECK_EQUAL(r2.getBad(), true); - - BOOST_CHECK_EQUAL(r1, r2); - BOOST_CHECK((r1 != r2) == false); - BOOST_CHECK(!(r1 < r2)); - BOOST_CHECK(!(r1 > r2)); - - auto r3 = FlagTypeFactory::LimitedAcceptance(); - BOOST_CHECK(r3 > r1); - BOOST_CHECK(!(r3 < r1)); + FlagType fDefault; + BOOST_CHECK_EQUAL(fDefault, FlagTypeFactory::Invalid()); + + auto f1 = FlagTypeFactory::Unknown(); + BOOST_CHECK_EQUAL(f1.getID(), 1); + BOOST_CHECK_EQUAL(f1.getName(), "Unknown"); + BOOST_CHECK_EQUAL(f1.getBad(), true); + + std::cout << f1 << std::endl; + + auto f2 = f1; + BOOST_CHECK_EQUAL(f2.getID(), 1); + BOOST_CHECK_EQUAL(f1.getName(), f2.getName()); + BOOST_CHECK_EQUAL(f2.getName(), "Unknown"); + BOOST_CHECK_EQUAL(f2.getBad(), true); + + BOOST_CHECK_EQUAL(f1, f2); + BOOST_CHECK((f1 != f2) == false); + BOOST_CHECK(!(f1 < f2)); + BOOST_CHECK(!(f1 > f2)); + + auto f3 = FlagTypeFactory::LimitedAcceptance(); + BOOST_CHECK(f3 > f1); + BOOST_CHECK(!(f3 < f1)); } diff --git a/DataFormats/QualityControl/test/testTimeRangeFlag.cxx b/DataFormats/QualityControl/test/testQualityControlFlag.cxx similarity index 58% rename from DataFormats/QualityControl/test/testTimeRangeFlag.cxx rename to DataFormats/QualityControl/test/testQualityControlFlag.cxx index 0b912db2c1f42..2990b3bbd355f 100644 --- a/DataFormats/QualityControl/test/testTimeRangeFlag.cxx +++ b/DataFormats/QualityControl/test/testQualityControlFlag.cxx @@ -23,18 +23,18 @@ using namespace o2::quality_control; BOOST_AUTO_TEST_CASE(test_QualityControlFlag) { - QualityControlFlag trf1{12, 34, FlagReasonFactory::BadTracking(), "comment", "source"}; + QualityControlFlag qcFlag1{12, 34, FlagTypeFactory::BadTracking(), "comment", "source"}; - BOOST_CHECK_EQUAL(trf1.getStart(), 12); - BOOST_CHECK_EQUAL(trf1.getEnd(), 34); - BOOST_CHECK_EQUAL(trf1.getFlag(), FlagReasonFactory::BadTracking()); - BOOST_CHECK_EQUAL(trf1.getComment(), "comment"); - BOOST_CHECK_EQUAL(trf1.getSource(), "source"); + BOOST_CHECK_EQUAL(qcFlag1.getStart(), 12); + BOOST_CHECK_EQUAL(qcFlag1.getEnd(), 34); + BOOST_CHECK_EQUAL(qcFlag1.getFlag(), FlagTypeFactory::BadTracking()); + BOOST_CHECK_EQUAL(qcFlag1.getComment(), "comment"); + BOOST_CHECK_EQUAL(qcFlag1.getSource(), "source"); - BOOST_CHECK_THROW((QualityControlFlag{12, 0, FlagReasonFactory::BadTracking()}), std::runtime_error); + BOOST_CHECK_THROW((QualityControlFlag{12, 0, FlagTypeFactory::BadTracking()}), std::runtime_error); - QualityControlFlag trf2{10, 34, FlagReasonFactory::BadTracking(), "comment", "source"}; + QualityControlFlag qcFlag2{10, 34, FlagTypeFactory::BadTracking(), "comment", "source"}; - BOOST_CHECK(trf1 > trf2); - BOOST_CHECK(!(trf1 < trf2)); + BOOST_CHECK(qcFlag1 > qcFlag2); + BOOST_CHECK(!(qcFlag1 < qcFlag2)); } \ No newline at end of file diff --git a/DataFormats/QualityControl/test/testQualityControlFlagCollection.cxx b/DataFormats/QualityControl/test/testQualityControlFlagCollection.cxx new file mode 100644 index 0000000000000..e069776e84907 --- /dev/null +++ b/DataFormats/QualityControl/test/testQualityControlFlagCollection.cxx @@ -0,0 +1,136 @@ +// 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. + +#define BOOST_TEST_MODULE Test quality_control QualityControlFlagCollection class +#define BOOST_TEST_MAIN +#define BOOST_TEST_DYN_LINK + +// boost includes +#include +// STL +#include +// o2 includes +#include "DataFormatsQualityControl/QualityControlFlagCollection.h" +#include "DataFormatsQualityControl/QualityControlFlag.h" +#include "DataFormatsQualityControl/FlagTypeFactory.h" + +using namespace o2::quality_control; + +BOOST_AUTO_TEST_CASE(test_QualityControlFlagCollection_Methods) +{ + QualityControlFlag flag1{12, 34, FlagTypeFactory::BadTracking(), "comment", "source"}; + QualityControlFlag flag2{10, 34, FlagTypeFactory::BadTracking(), "comment", "source"}; + + QualityControlFlagCollection qcfc1{"Raw data checks", "TOF", {10, 20000}, 12345, "LHC22k5", "passMC", "qc_mc"}; + qcfc1.insert(flag1); // by copy + qcfc1.insert(flag2); + qcfc1.insert({50, 77, FlagTypeFactory::Invalid()}); // by move + BOOST_CHECK_EQUAL(qcfc1.size(), 3); + BOOST_CHECK_EQUAL(qcfc1.getName(), "Raw data checks"); + BOOST_CHECK_EQUAL(qcfc1.getDetector(), "TOF"); + BOOST_CHECK_EQUAL(qcfc1.getStart(), 10); + BOOST_CHECK_EQUAL(qcfc1.getEnd(), 20000); + BOOST_CHECK_EQUAL(qcfc1.getRunNumber(), 12345); + BOOST_CHECK_EQUAL(qcfc1.getPeriodName(), "LHC22k5"); + BOOST_CHECK_EQUAL(qcfc1.getPassName(), "passMC"); + BOOST_CHECK_EQUAL(qcfc1.getProvenance(), "qc_mc"); + + QualityControlFlagCollection qcfc2{"Reco checks", "TOF"}; + qcfc2.insert({50, 77, FlagTypeFactory::Invalid()}); // this is a duplicate to an entry in qcfc1 + qcfc2.insert({51, 77, FlagTypeFactory::Invalid()}); + qcfc2.insert({1234, 3434, FlagTypeFactory::LimitedAcceptance()}); + qcfc2.insert({50, 77, FlagTypeFactory::LimitedAcceptance()}); + BOOST_CHECK_EQUAL(qcfc2.size(), 4); + + // Try merging. Duplicate entries should be left in the 'other' objects. + // Notice that we merge the two partial TRFCs into the third, which covers all cases + QualityControlFlagCollection qcfc3{"ALL", "TOF"}; + qcfc3.merge(qcfc1); + qcfc3.merge(qcfc2); + BOOST_CHECK_EQUAL(qcfc1.size(), 0); + BOOST_CHECK_EQUAL(qcfc2.size(), 1); + BOOST_CHECK_EQUAL(qcfc3.size(), 6); + + // Try const merging. It should copy the elements and keep the 'other' intact. + QualityControlFlagCollection qcfc4{"ALL", "TOF"}; + const auto& constTrfc3 = qcfc3; + qcfc4.merge(constTrfc3); + BOOST_CHECK_EQUAL(qcfc3.size(), 6); + BOOST_CHECK_EQUAL(qcfc4.size(), 6); + + // Try merging different detectors - it should throw. + QualityControlFlagCollection qcfc5{"ALL", "TPC"}; + BOOST_CHECK_THROW(qcfc5.merge(qcfc3), std::runtime_error); + BOOST_CHECK_THROW(qcfc5.merge(constTrfc3), std::runtime_error); + + // try printing + std::cout << qcfc3 << std::endl; + + // iterating + for (const auto& flag : qcfc3) { + (void)flag; + } +} + +BOOST_AUTO_TEST_CASE(test_QualityControlFlagCollection_IO) +{ + { + QualityControlFlagCollection qcfc1{"xyz", "TST"}; + + std::stringstream store; + qcfc1.streamTo(store); + + QualityControlFlagCollection qcfc2{"xyz", "TST"}; + qcfc2.streamFrom(store); + + BOOST_CHECK_EQUAL(qcfc2.size(), 0); + } + { + QualityControlFlagCollection qcfc1{"xyz", "TST"}; + qcfc1.insert({50, 77, FlagTypeFactory::Invalid(), "a comment", "a source"}); + qcfc1.insert({51, 77, FlagTypeFactory::Invalid()}); + qcfc1.insert({1234, 3434, FlagTypeFactory::LimitedAcceptance()}); + qcfc1.insert({50, 77, FlagTypeFactory::LimitedAcceptance()}); + qcfc1.insert({43434, 63421, FlagTypeFactory::NotBadFlagExample()}); + + std::stringstream store; + qcfc1.streamTo(store); + + QualityControlFlagCollection qcfc2{"xyz", "TST"}; + qcfc2.streamFrom(store); + + BOOST_REQUIRE_EQUAL(qcfc1.size(), qcfc2.size()); + for (auto it1 = qcfc1.begin(), it2 = qcfc2.begin(); it1 != qcfc1.end() && it2 != qcfc2.end(); ++it1, ++it2) { + BOOST_CHECK_EQUAL(*it1, *it2); + } + } + { + std::stringstream store; + store << "start,end,flag_id,invalid,header,format\n"; + store << R"(123,345,11,"fdsa",1,"comment","source")"; + QualityControlFlagCollection qcfc1{"A", "TST"}; + BOOST_CHECK_THROW(qcfc1.streamFrom(store), std::runtime_error); + } + { + std::stringstream store; + store << "start,end,flag_id,flag_name,flag_bad,comment,source\n"; + store << R"(123,345,11,"fdsa",1,"comment","source","toomanycolumns")" << '\n'; + store << R"(123,345,11,"fdsa",1)" << '\n'; + store << R"(123,,11,"fdsa",1,"comment","source")" << '\n'; + store << R"(,345,11,"fdsa",1,"comment","source")" << '\n'; + store << R"(123,345,,"fdsa",1,"comment","source")" << '\n'; + store << R"(123,345,11,"",1,"comment","source")" << '\n'; + store << R"(123,345,11,"fdsa",,"comment","source")" << '\n'; + QualityControlFlagCollection qcfc1{"A", "TST"}; + BOOST_CHECK_NO_THROW(qcfc1.streamFrom(store)); + BOOST_CHECK_EQUAL(qcfc1.size(), 0); + } +} diff --git a/DataFormats/QualityControl/test/testTimeRangeFlagCollection.cxx b/DataFormats/QualityControl/test/testTimeRangeFlagCollection.cxx deleted file mode 100644 index bf8ce2cab0fbd..0000000000000 --- a/DataFormats/QualityControl/test/testTimeRangeFlagCollection.cxx +++ /dev/null @@ -1,136 +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. - -#define BOOST_TEST_MODULE Test quality_control QualityControlFlagCollection class -#define BOOST_TEST_MAIN -#define BOOST_TEST_DYN_LINK - -// boost includes -#include -// STL -#include -// o2 includes -#include "DataFormatsQualityControl/QualityControlFlagCollection.h" -#include "DataFormatsQualityControl/QualityControlFlag.h" -#include "DataFormatsQualityControl/FlagTypeFactory.h" - -using namespace o2::quality_control; - -BOOST_AUTO_TEST_CASE(test_QualityControlFlagCollection_Methods) -{ - QualityControlFlag trf1{12, 34, FlagTypeFactory::BadTracking(), "comment", "source"}; - QualityControlFlag trf2{10, 34, FlagTypeFactory::BadTracking(), "comment", "source"}; - - QualityControlFlagCollection trfc1{"Raw data checks", "TOF", {10, 20000}, 12345, "LHC22k5", "passMC", "qc_mc"}; - trfc1.insert(trf1); // by copy - trfc1.insert(trf2); - trfc1.insert({50, 77, FlagTypeFactory::Invalid()}); // by move - BOOST_CHECK_EQUAL(trfc1.size(), 3); - BOOST_CHECK_EQUAL(trfc1.getName(), "Raw data checks"); - BOOST_CHECK_EQUAL(trfc1.getDetector(), "TOF"); - BOOST_CHECK_EQUAL(trfc1.getStart(), 10); - BOOST_CHECK_EQUAL(trfc1.getEnd(), 20000); - BOOST_CHECK_EQUAL(trfc1.getRunNumber(), 12345); - BOOST_CHECK_EQUAL(trfc1.getPeriodName(), "LHC22k5"); - BOOST_CHECK_EQUAL(trfc1.getPassName(), "passMC"); - BOOST_CHECK_EQUAL(trfc1.getProvenance(), "qc_mc"); - - QualityControlFlagCollection trfc2{"Reco checks", "TOF"}; - trfc2.insert({50, 77, FlagTypeFactory::Invalid()}); // this is a duplicate to an entry in trfc1 - trfc2.insert({51, 77, FlagTypeFactory::Invalid()}); - trfc2.insert({1234, 3434, FlagTypeFactory::LimitedAcceptance()}); - trfc2.insert({50, 77, FlagTypeFactory::LimitedAcceptance()}); - BOOST_CHECK_EQUAL(trfc2.size(), 4); - - // Try merging. Duplicate entries should be left in the 'other' objects. - // Notice that we merge the two partial TRFCs into the third, which covers all cases - QualityControlFlagCollection trfc3{"ALL", "TOF"}; - trfc3.merge(trfc1); - trfc3.merge(trfc2); - BOOST_CHECK_EQUAL(trfc1.size(), 0); - BOOST_CHECK_EQUAL(trfc2.size(), 1); - BOOST_CHECK_EQUAL(trfc3.size(), 6); - - // Try const merging. It should copy the elements and keep the 'other' intact. - QualityControlFlagCollection trfc4{"ALL", "TOF"}; - const auto& constTrfc3 = trfc3; - trfc4.merge(constTrfc3); - BOOST_CHECK_EQUAL(trfc3.size(), 6); - BOOST_CHECK_EQUAL(trfc4.size(), 6); - - // Try merging different detectors - it should throw. - QualityControlFlagCollection trfc5{"ALL", "TPC"}; - BOOST_CHECK_THROW(trfc5.merge(trfc3), std::runtime_error); - BOOST_CHECK_THROW(trfc5.merge(constTrfc3), std::runtime_error); - - // try printing - std::cout << trfc3 << std::endl; - - // iterating - for (const auto& trf : trfc3) { - (void)trf; - } -} - -BOOST_AUTO_TEST_CASE(test_QualityControlFlagCollection_IO) -{ - { - QualityControlFlagCollection trfc1{"xyz", "TST"}; - - std::stringstream store; - trfc1.streamTo(store); - - QualityControlFlagCollection trfc2{"xyz", "TST"}; - trfc2.streamFrom(store); - - BOOST_CHECK_EQUAL(trfc2.size(), 0); - } - { - QualityControlFlagCollection trfc1{"xyz", "TST"}; - trfc1.insert({50, 77, FlagTypeFactory::Invalid(), "a comment", "a source"}); - trfc1.insert({51, 77, FlagTypeFactory::Invalid()}); - trfc1.insert({1234, 3434, FlagTypeFactory::LimitedAcceptance()}); - trfc1.insert({50, 77, FlagTypeFactory::LimitedAcceptance()}); - trfc1.insert({43434, 63421, FlagTypeFactory::NotBadFlagExample()}); - - std::stringstream store; - trfc1.streamTo(store); - - QualityControlFlagCollection trfc2{"xyz", "TST"}; - trfc2.streamFrom(store); - - BOOST_REQUIRE_EQUAL(trfc1.size(), trfc2.size()); - for (auto it1 = trfc1.begin(), it2 = trfc2.begin(); it1 != trfc1.end() && it2 != trfc2.end(); ++it1, ++it2) { - BOOST_CHECK_EQUAL(*it1, *it2); - } - } - { - std::stringstream store; - store << "start,end,flag_id,invalid,header,format\n"; - store << R"(123,345,11,"fdsa",1,"comment","source")"; - QualityControlFlagCollection trfc1{"A", "TST"}; - BOOST_CHECK_THROW(trfc1.streamFrom(store), std::runtime_error); - } - { - std::stringstream store; - store << "start,end,flag_id,flag_name,flag_bad,comment,source\n"; - store << R"(123,345,11,"fdsa",1,"comment","source","toomanycolumns")" << '\n'; - store << R"(123,345,11,"fdsa",1)" << '\n'; - store << R"(123,,11,"fdsa",1,"comment","source")" << '\n'; - store << R"(,345,11,"fdsa",1,"comment","source")" << '\n'; - store << R"(123,345,,"fdsa",1,"comment","source")" << '\n'; - store << R"(123,345,11,"",1,"comment","source")" << '\n'; - store << R"(123,345,11,"fdsa",,"comment","source")" << '\n'; - QualityControlFlagCollection trfc1{"A", "TST"}; - BOOST_CHECK_NO_THROW(trfc1.streamFrom(store)); - BOOST_CHECK_EQUAL(trfc1.size(), 0); - } -}