Skip to content

Commit 14566b5

Browse files
knopers8wiechula
andauthored
Initial data formats for tagging data quality (#5554)
* First version for flagging time ranges for analysis Conflicts: DataFormats/CMakeLists.txt * Add detector ranges * Reworked FlagReasons and Time-Ranges * Add codeowners * typo in codeowners * Use Bracket from MathUtils for the time interval * Allow for persistent storage of FlagReasons Unfortunately, it implies larger memory footprint and no constexpr construction, but i don't see other way to achieve it ATM. * Delete unneeded ClassImp and fix typo Co-authored-by: wiechula <Jens.Wiechula@cern.ch>
1 parent 0ff7a0e commit 14566b5

15 files changed

Lines changed: 747 additions & 1 deletion

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#/DataFormats/Legacy
5151
#/DataFormats/MemoryResources
5252
/DataFormats/Parameters @shahor02
53+
/DataFormats/QualityControl @knopers8 @Barthelemy @chiarazampolli
5354
/DataFormats/Reconstruction @shahor02
5455
#/DataFormats/TimeFrame
5556
/DataFormats/common @shahor02

DataFormats/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ add_subdirectory(simulation)
77
add_subdirectory(TimeFrame)
88
add_subdirectory(Parameters)
99
add_subdirectory(Calibration)
10-
10+
add_subdirectory(QualityControl)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright CERN and copyright holders of ALICE O2. This software is distributed
2+
# under the terms of the GNU General Public License v3 (GPL Version 3), copied
3+
# verbatim in the file "COPYING".
4+
#
5+
# See http://alice-o2.web.cern.ch/license for full licensing information.
6+
#
7+
# In applying this license CERN does not waive the privileges and immunities
8+
# granted to it by virtue of its status as an Intergovernmental Organization or
9+
# submit itself to any jurisdiction.
10+
11+
o2_add_library(DataFormatsQualityControl
12+
SOURCES src/FlagReasons.cxx
13+
src/TimeRangeFlag.cxx
14+
src/TimeRangeFlagCollection.cxx
15+
PUBLIC_LINK_LIBRARIES O2::Headers
16+
O2::FrameworkLogger
17+
O2::DetectorsCommonDataFormats)
18+
19+
o2_target_root_dictionary(DataFormatsQualityControl
20+
HEADERS include/DataFormatsQualityControl/FlagReasons.h
21+
include/DataFormatsQualityControl/TimeRangeFlag.h
22+
include/DataFormatsQualityControl/TimeRangeFlagCollection.h)
23+
24+
o2_add_test(FlagReasons
25+
SOURCES test/testFlagReasons.cxx
26+
COMPONENT_NAME DataFormatsQualityControl
27+
PUBLIC_LINK_LIBRARIES O2::DataFormatsQualityControl)
28+
29+
o2_add_test(TimeRangeFlag
30+
SOURCES test/testTimeRangeFlag.cxx
31+
COMPONENT_NAME DataFormatsQualityControl
32+
PUBLIC_LINK_LIBRARIES O2::DataFormatsQualityControl)
33+
34+
o2_add_test(TimeRangeFlagCollection
35+
SOURCES test/testTimeRangeFlagCollection.cxx
36+
COMPONENT_NAME DataFormatsQualityControl
37+
PUBLIC_LINK_LIBRARIES O2::DataFormatsQualityControl)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
\page refDataFormatsQualityControl Data Formats Quality Control
2+
3+
Data formats for tagging good quality data for analysis.
4+
5+
# Flagging time ranges
6+
## General idea
7+
* Each detector has its own CCDB (QCDB) entry - TimeRangeFlagCollection
8+
* The CCDB Entry validity will be run or fill, depending on the final data taking granularity
9+
* Each entry can define sub ranges (TimeRangeFlags) of certain data characteristics (FlagReasons) inside the CCDB Entry validity
10+
* Flags are defined in a common store, they are used to derive the Data Tags - the final filters for good quality data during analysis.
11+
* Data Tag are stored as CCDB entries. They might require different detectors and may suppress different flags dependent on the analysis type.
12+
13+
## Implementation
14+
15+
[Flag Reason](include/DataFormatsQualityControl/FlagReasons.h) is defined with an identifier number, a name and a 'bad quality' determinant.
16+
The latter decides if such a flag should mark the data quality as bad by default.
17+
FlagReasons can be created only with FlagReasonFactory, so that the list of available reasons is common and centralised.
18+
For example:
19+
```
20+
id: 10
21+
name: Limited Acceptance
22+
bad: true
23+
```
24+
25+
With [TimeRangeFlags](include/DataFormatsQualityControl/TimeRangeFlag.h) we can define the time range of a chosen FlagReason, add an additional comment and specify the source of this flag.
26+
For example:
27+
```
28+
start: 1612707603626
29+
end: 1613999652000
30+
flag: Limited Acceptance
31+
comment: Sector B in TPC inactive
32+
source: o2::quality_control_modules::tpc::ClustersCheck
33+
```
34+
35+
[TimeRangeFlagCollection](include/DataFormatsQualityControl/TimeRangeFlagCollection.h) contains all TimeRangeFlags for the validity range (run or fill).
36+
TimeRangeFlags may overlap, e.g. if they use different FlagReasons and they are sorted by their start time.
37+
If certain period does not include any TimeRangeFlags with *bad* FlagReasons, then the data quality can be considered as good.
38+
The [TimeRangeFlagCollection test](test/testTimeRangeFlagCollection.cxx) shows the usage example.
39+
40+
TimeRangeFlagCollections are supposed to be created automatically with QC Post-processing Tasks based on Quality Objects created by QC Checks.
41+
However, they might be created manually by QA experts as well.
42+
The procedure to do that has to be defined.
43+
44+
## TODO
45+
* Define the complete list of available Flag Reasons
46+
* implement CCDB storage and access
47+
- define CCDB storage place e.g.
48+
* `<Detector>/QC/QualityFlags`
49+
* `Analysis/QualityFlags/<Detector>`
50+
* Data Tags Definitions and Data Tags
51+
52+
### Notes on plans for Data Tags
53+
54+
Data Tag definition has:
55+
* name
56+
* global suppression list for bad flag reasons (applies to all detectors)
57+
* global requirement list for not bad flag reasons
58+
* list of needed detectors,
59+
* list of suppression list and requirement list specific to detectors
60+
61+
Example configurations
62+
```json
63+
{
64+
"name": "CentralBarrelTrackingLimitedAcceptance",
65+
"globalRequiredDetectors" : [ "TPC", "ITS" ],
66+
"globalIgnoredFlags" : ["Limited acceptance", "asdf"],
67+
"globalRequiredFlags" : [],
68+
"detectorSpecificFlags" : [
69+
{
70+
"name" : "TPC",
71+
"ignoredFlags" : [ "Reason X" ]
72+
}
73+
]
74+
},
75+
{
76+
"name": "CentralBarrelTracking",
77+
"globalRequiredDetectors" : [ "TPC", "ITS" ],
78+
"globalIgnoredFlags" : [],
79+
"globalRequiredFlags" : [],
80+
"detectorSpecificFlags" : []
81+
},
82+
{
83+
"name": "CentralBarrelTrackingOnlyLimitedAcceptanceinTPC",
84+
"globalRequiredDetectors" : [ "TPC", "ITS" ],
85+
"globalIgnoredFlags" : [],
86+
"detectorSpecificFlags" : [
87+
{
88+
"name" : "TPC",
89+
"requiredFlags" : [ "Limited acceptance" ]
90+
}
91+
}
92+
]
93+
```
94+
95+
## Wishlist / Ideas
96+
* executable to add flags to the flag store
97+
* executable to extrags the flag store
98+
* summary of all masks for one TimeRangeFlagCollection
99+
* functionality to extract flags for a specific detector (from CCDB)
100+
* cut class to specify detectors and flags which to exclude
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef ALICEO2_ANALYSIS_FLAGREASONS
12+
#define ALICEO2_ANALYSIS_FLAGREASONS
13+
14+
/// \file FlagReasons.h
15+
/// \brief classes keeping reasons for flagging time ranges
16+
/// \author Jens Wiechula, jens.wiechula@ikf.uni-frankfurt.de
17+
/// \author Piotr Konopka, piotr.jan.konopka@cern.ch
18+
19+
// STL
20+
#include <iosfwd>
21+
#include <cstdint>
22+
23+
// ROOT includes
24+
#include <Rtypes.h>
25+
26+
namespace o2
27+
{
28+
namespace quality_control
29+
{
30+
31+
struct FlagReasonFactory;
32+
33+
class FlagReason
34+
{
35+
private:
36+
uint16_t mId;
37+
std::string mName;
38+
bool mBad; // if true, data should become bad by default
39+
40+
// By making the constructor private and FlagReasons available only in the FlagReasonFactory
41+
// we forbid to declare any flags in the user code. If you need a new FlagReason, please add it FlagReasonFactory.
42+
private:
43+
FlagReason(uint16_t id, const char* name, bool bad) : mId(id), mName(name), mBad(bad) {}
44+
45+
public:
46+
FlagReason& operator=(const FlagReason&) = default;
47+
FlagReason(const FlagReason&) = default;
48+
bool operator==(const FlagReason& rhs) const;
49+
bool operator!=(const FlagReason& rhs) const;
50+
bool operator<(const FlagReason& rhs) const;
51+
bool operator>(const FlagReason& rhs) const;
52+
53+
uint16_t getID() { return mId; }
54+
const std::string& getName() { return mName; }
55+
bool getBad() { return mBad; }
56+
57+
friend std::ostream& operator<<(std::ostream& os, FlagReason const& me);
58+
friend FlagReasonFactory;
59+
60+
ClassDefNV(FlagReason, 1);
61+
};
62+
63+
struct FlagReasonFactory {
64+
FlagReasonFactory() = delete;
65+
66+
// TODO: migrate the flag list from RCT
67+
// TODO: find a way to have a nicely formatted list of reasons.
68+
69+
// !!! NEVER MODIFY OR DELETE EXISTING FLAGS AFTER RUN 3 STARTS !!!
70+
static FlagReason Invalid() { return {static_cast<uint16_t>(-1), "Invalid", true}; }
71+
72+
static FlagReason Unknown() { return {1, "Unknown", true}; }
73+
static FlagReason ProcessingError() { return {2, "Processing error", true}; }
74+
// it can be used when there are no required Quality Objects in QCDB in certain time range.
75+
static FlagReason MissingQualityObject() { return {3, "Missing Quality Object", true}; }
76+
// Quality Object is there, but it has Quality::Null
77+
static FlagReason MissingQuality() { return {4, "Missing Quality", true}; }
78+
79+
// TODO: to be seen if we should actively do anything when a detector was off.
80+
static FlagReason DetectorOff() { return {10, "Detector off", true}; }
81+
static FlagReason LimitedAcceptance() { return {11, "Limited acceptance", true}; }
82+
};
83+
84+
} // namespace quality_control
85+
} // namespace o2
86+
#endif
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef ALICEO2_ANALYSIS_TIMERANGEFLAGS
12+
#define ALICEO2_ANALYSIS_TIMERANGEFLAGS
13+
14+
/// \file TimeRangeFlag.h
15+
/// \brief Class to define a time range of a flag type
16+
/// \author Jens Wiechula, jens.wiechula@ikf.uni-frankfurt.de
17+
/// \author Piotr Konopka, piotr.jan.konopka@cern.ch
18+
19+
// System includes
20+
#include <iosfwd>
21+
#include <string>
22+
23+
// ROOT includes
24+
#include <Rtypes.h>
25+
26+
#include <MathUtils/detail/Bracket.h>
27+
28+
#include "DataFormatsQualityControl/FlagReasons.h"
29+
30+
namespace o2
31+
{
32+
namespace quality_control
33+
{
34+
35+
/// \class TimeRangeFlag
36+
/// A Class for associating a bit mask with a time range
37+
class TimeRangeFlag
38+
{
39+
public:
40+
using time_type = uint64_t;
41+
using flag_type = FlagReason;
42+
using RangeInterval = o2::math_utils::detail::Bracket<time_type>;
43+
44+
TimeRangeFlag() = default;
45+
TimeRangeFlag(TimeRangeFlag const&) = default;
46+
TimeRangeFlag(time_type start, time_type end, flag_type flag, std::string comment = "", std::string source = "Unknown");
47+
48+
time_type getStart() const { return mInterval.getMin(); }
49+
time_type getEnd() const { return mInterval.getMax(); }
50+
RangeInterval& getInterval() { return mInterval; }
51+
flag_type getFlag() const { return mFlag; }
52+
const std::string& getComment() const { return mComment; }
53+
const std::string& getSource() const { return mSource; }
54+
55+
void setStart(time_type start) { mInterval.setMin(start); }
56+
void setEnd(time_type end) { mInterval.setMax(end); }
57+
void setInterval(RangeInterval interval) { mInterval = interval; }
58+
void setFlag(flag_type flag) { mFlag = flag; }
59+
void setComment(const std::string& comment) { mComment = comment; }
60+
void setSource(const std::string& source) { mSource = source; }
61+
62+
/// equal operator
63+
bool operator==(const TimeRangeFlag& rhs) const;
64+
65+
/// comparison operators
66+
bool operator<(const TimeRangeFlag& rhs) const;
67+
bool operator>(const TimeRangeFlag& rhs) const;
68+
69+
/// write data to ostream
70+
void streamTo(std::ostream& output) const;
71+
72+
/// overloading output stream operator
73+
friend std::ostream& operator<<(std::ostream& output, const TimeRangeFlag& data);
74+
75+
private:
76+
RangeInterval mInterval = {}; ///< time interval of the masked range
77+
flag_type mFlag = FlagReasonFactory::Invalid(); ///< flag reason
78+
std::string mComment = ""; ///< optional comment, which may extend the reason
79+
std::string mSource = "Unknown"; ///< optional (but encouraged) source of the flag (e.g. Qc Check name)
80+
81+
ClassDefNV(TimeRangeFlag, 1);
82+
};
83+
84+
} // namespace quality_control
85+
} // namespace o2
86+
#endif

0 commit comments

Comments
 (0)