Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QC-1160 Move to the new names for QC flags #13073

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 28 additions & 32 deletions DataFormats/QualityControl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,69 +10,65 @@
# 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<uint16_t>\(\\1\), \\3, static_cast<bool>\(\\4\) }; }"
CSV_FLAG_REASONS
${CSV_FLAG_REASONS})
"static FlagType \\2\(\) { return { static_cast<uint16_t>\(\\1\), \\3, static_cast<bool>\(\\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
)

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()

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,53 @@
#ifndef O2_QUALITYCONTROL_FLAGTYPE_H
#define O2_QUALITYCONTROL_FLAGTYPE_H

#include "DataFormatsQualityControl/FlagReasons.h"
// STL
#include <iosfwd>
#include <cstdint>

namespace o2::quality_control
// ROOT includes
#include <Rtypes.h>

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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, [email protected]

#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
#endif // O2_FLAGTYPEFACTORY_H
Original file line number Diff line number Diff line change
Expand Up @@ -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, [email protected]
/// \author Piotr Konopka, [email protected]

namespace o2::quality_control
// System includes
#include <iosfwd>
#include <string>

// ROOT includes
#include <Rtypes.h>

#include <MathUtils/detail/Bracket.h>

#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<time_type>;

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
Loading
Loading