Project
Loading...
Searching...
No Matches
testQualityControlFlagCollection.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 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#define BOOST_TEST_MODULE Test quality_control QualityControlFlagCollection class
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15
16// boost includes
17#include <boost/test/unit_test.hpp>
18// STL
19#include <sstream>
20// o2 includes
23#include "DataFormatsQualityControl/FlagTypeFactory.h"
24
25using namespace o2::quality_control;
26
27BOOST_AUTO_TEST_CASE(test_QualityControlFlagCollection_Methods)
28{
29 QualityControlFlag flag1{12, 34, FlagTypeFactory::BadTracking(), "comment", "source"};
30 QualityControlFlag flag2{10, 34, FlagTypeFactory::BadTracking(), "comment", "source"};
31
32 QualityControlFlagCollection qcfc1{"Raw data checks", "TOF", {10, 20000}, 12345, "LHC22k5", "passMC", "qc_mc"};
33 qcfc1.insert(flag1); // by copy
34 qcfc1.insert(flag2);
35 qcfc1.insert({50, 77, FlagTypeFactory::Invalid()}); // by move
36 BOOST_CHECK_EQUAL(qcfc1.size(), 3);
37 BOOST_CHECK_EQUAL(qcfc1.getName(), "Raw data checks");
38 BOOST_CHECK_EQUAL(qcfc1.getDetector(), "TOF");
39 BOOST_CHECK_EQUAL(qcfc1.getStart(), 10);
40 BOOST_CHECK_EQUAL(qcfc1.getEnd(), 20000);
41 BOOST_CHECK_EQUAL(qcfc1.getRunNumber(), 12345);
42 BOOST_CHECK_EQUAL(qcfc1.getPeriodName(), "LHC22k5");
43 BOOST_CHECK_EQUAL(qcfc1.getPassName(), "passMC");
44 BOOST_CHECK_EQUAL(qcfc1.getProvenance(), "qc_mc");
45
46 QualityControlFlagCollection qcfc2{"Reco checks", "TOF"};
47 qcfc2.insert({50, 77, FlagTypeFactory::Invalid()}); // this is a duplicate to an entry in qcfc1
48 qcfc2.insert({51, 77, FlagTypeFactory::Invalid()});
49 qcfc2.insert({1234, 3434, FlagTypeFactory::LimitedAcceptanceMCNotReproducible()});
50 qcfc2.insert({50, 77, FlagTypeFactory::LimitedAcceptanceMCNotReproducible()});
51 BOOST_CHECK_EQUAL(qcfc2.size(), 4);
52
53 // Try merging. Duplicate entries should be left in the 'other' objects.
54 // Notice that we merge the two partial TRFCs into the third, which covers all cases
55 QualityControlFlagCollection qcfc3{"ALL", "TOF"};
56 qcfc3.merge(qcfc1);
57 qcfc3.merge(qcfc2);
58 BOOST_CHECK_EQUAL(qcfc1.size(), 0);
59 BOOST_CHECK_EQUAL(qcfc2.size(), 1);
60 BOOST_CHECK_EQUAL(qcfc3.size(), 6);
61
62 // Try const merging. It should copy the elements and keep the 'other' intact.
63 QualityControlFlagCollection qcfc4{"ALL", "TOF"};
64 const auto& constTrfc3 = qcfc3;
65 qcfc4.merge(constTrfc3);
66 BOOST_CHECK_EQUAL(qcfc3.size(), 6);
67 BOOST_CHECK_EQUAL(qcfc4.size(), 6);
68
69 // Try merging different detectors - it should throw.
70 QualityControlFlagCollection qcfc5{"ALL", "TPC"};
71 BOOST_CHECK_THROW(qcfc5.merge(qcfc3), std::runtime_error);
72 BOOST_CHECK_THROW(qcfc5.merge(constTrfc3), std::runtime_error);
73
74 // try printing
75 std::cout << qcfc3 << std::endl;
76
77 // iterating
78 for (const auto& flag : qcfc3) {
79 (void)flag;
80 }
81}
82
83BOOST_AUTO_TEST_CASE(test_QualityControlFlagCollection_IO)
84{
85 {
86 QualityControlFlagCollection qcfc1{"xyz", "TST"};
87
88 std::stringstream store;
89 qcfc1.streamTo(store);
90
91 QualityControlFlagCollection qcfc2{"xyz", "TST"};
92 qcfc2.streamFrom(store);
93
94 BOOST_CHECK_EQUAL(qcfc2.size(), 0);
95 }
96 {
97 QualityControlFlagCollection qcfc1{"xyz", "TST"};
98 qcfc1.insert({50, 77, FlagTypeFactory::Invalid(), "a comment", "a source"});
99 qcfc1.insert({51, 77, FlagTypeFactory::Invalid()});
100 qcfc1.insert({1234, 3434, FlagTypeFactory::LimitedAcceptanceMCNotReproducible()});
101 qcfc1.insert({50, 77, FlagTypeFactory::LimitedAcceptanceMCNotReproducible()});
102 qcfc1.insert({43434, 63421, FlagTypeFactory::Good()});
103
104 std::stringstream store;
105 qcfc1.streamTo(store);
106
107 QualityControlFlagCollection qcfc2{"xyz", "TST"};
108 qcfc2.streamFrom(store);
109
110 BOOST_REQUIRE_EQUAL(qcfc1.size(), qcfc2.size());
111 for (auto it1 = qcfc1.begin(), it2 = qcfc2.begin(); it1 != qcfc1.end() && it2 != qcfc2.end(); ++it1, ++it2) {
112 BOOST_CHECK_EQUAL(*it1, *it2);
113 }
114 }
115 {
116 std::stringstream store;
117 store << "start,end,flag_id,invalid,header,format\n";
118 store << R"(123,345,11,"fdsa",1,"comment","source")";
119 QualityControlFlagCollection qcfc1{"A", "TST"};
120 BOOST_CHECK_THROW(qcfc1.streamFrom(store), std::runtime_error);
121 }
122 {
123 std::stringstream store;
124 store << "start,end,flag_id,flag_name,flag_bad,comment,source\n";
125 store << R"(123,345,11,"fdsa",1,"comment","source","toomanycolumns")" << '\n';
126 store << R"(123,345,11,"fdsa",1)" << '\n';
127 store << R"(123,,11,"fdsa",1,"comment","source")" << '\n';
128 store << R"(,345,11,"fdsa",1,"comment","source")" << '\n';
129 store << R"(123,345,,"fdsa",1,"comment","source")" << '\n';
130 store << R"(123,345,11,"",1,"comment","source")" << '\n';
131 store << R"(123,345,11,"fdsa",,"comment","source")" << '\n';
132 QualityControlFlagCollection qcfc1{"A", "TST"};
133 BOOST_CHECK_NO_THROW(qcfc1.streamFrom(store));
134 BOOST_CHECK_EQUAL(qcfc1.size(), 0);
135 }
136}
classes for defining time ranges with a certain mask to be able to cut on
Class to define a flag type with a time range and comments.
void streamTo(std::ostream &output) const
write data to ostream
void streamFrom(std::istream &input)
Read data from instream.
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
BOOST_AUTO_TEST_CASE(test_QualityControlFlagCollection_Methods)
BOOST_CHECK_NO_THROW(algorithm::merge(target, other))
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())