Project
Loading...
Searching...
No Matches
test_DataSamplingCondition.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#define BOOST_TEST_MODULE Test Framework DataSamplingCondition
12#define BOOST_TEST_MAIN
13#define BOOST_TEST_DYN_LINK
14
15#include <vector>
16#include <boost/test/unit_test.hpp>
17#include <boost/property_tree/ptree.hpp>
18
20#include "Framework/DataRef.h"
22#include "Headers/DataHeader.h"
23#include "Headers/Stack.h"
24
25using namespace o2::framework;
26using namespace o2::utilities;
27using namespace o2::header;
28
30{
31 auto conditionRandom = DataSamplingConditionFactory::create("random");
32 BOOST_REQUIRE(conditionRandom);
33
34 boost::property_tree::ptree config;
35 config.put("fraction", "0.5");
36 config.put("seed", "943753948");
37 conditionRandom->configure(config);
38
39 // PRNG should behave the same every time and on every machine.
40 // Of course, the test does not cover full range of timesliceIDs, but at least gives an idea about its determinism.
41 {
42 std::vector<bool> correctDecision{
43 true, false, true, false, true, false, false, true, false, false, true, true, false, false, true, false, false,
44 true, false, false, true, true, true, false, false, false, true, false, true, true, true, false, false, true,
45 false, false, false, false, false, false, true, false, false, true, false, false, true, false, false};
46 for (DataProcessingHeader::StartTime id = 1; id < 50; id++) {
48 o2::header::Stack headerStack{dph};
49 DataRef dr{nullptr, reinterpret_cast<const char*>(headerStack.data()), nullptr};
50 BOOST_CHECK_EQUAL(correctDecision[id - 1], conditionRandom->decide(dr));
51 }
52 }
53
54 // random access check
55 {
56 std::vector<std::pair<DataProcessingHeader::StartTime, bool>> correctDecision{
57 {222, true},
58 {222, true},
59 {222, true},
60 {230, false},
61 {210, true},
62 {230, false},
63 {250, false},
64 {251, false},
65 {222, true},
66 {230, false}};
67 for (const auto& check : correctDecision) {
68 DataProcessingHeader dph{check.first, 0};
69 o2::header::Stack headerStack{dph};
70 DataRef dr{nullptr, reinterpret_cast<const char*>(headerStack.data()), nullptr};
71 BOOST_CHECK_EQUAL(check.second, conditionRandom->decide(dr));
72 }
73 }
74}
75
77{
78 auto conditionPayloadSize = DataSamplingConditionFactory::create("payloadSize");
79 BOOST_REQUIRE(conditionPayloadSize);
80
81 boost::property_tree::ptree config;
82 config.put("upperLimit", 500);
83 config.put("lowerLimit", 30);
84 conditionPayloadSize->configure(config);
85
86 std::vector<std::pair<size_t, bool>> testCases{
87 {0, false},
88 {29, false},
89 {30, true},
90 {200, true},
91 {500, true},
92 {501, false}};
93
94 for (const auto& t : testCases) {
95 DataHeader dh;
96 dh.payloadSize = t.first;
97 o2::header::Stack headerStack{dh};
98 DataRef dr{nullptr, reinterpret_cast<const char*>(headerStack.data()), nullptr};
99 BOOST_CHECK_EQUAL(conditionPayloadSize->decide(dr), t.second);
100 }
101}
103{
104 auto conditionNConsecutive = DataSamplingConditionFactory::create("nConsecutive");
105 BOOST_REQUIRE(conditionNConsecutive);
106
107 boost::property_tree::ptree config;
108 config.put("samplesNumber", 3);
109 config.put("cycleSize", 10);
110 conditionNConsecutive->configure(config);
111
112 std::vector<std::pair<size_t, bool>> testCases{
113 {0, true},
114 {1, true},
115 {2, true},
116 {3, false},
117 {8, false},
118 {9, false},
119 {9999999999999, false},
120 {10000000000000, true},
121 {10000000000001, true},
122 {10000000000002, true},
123 {10000000000003, false}};
124
125 for (const auto& t : testCases) {
126 DataProcessingHeader dph{t.first, 0};
127 o2::header::Stack headerStack{dph};
128 DataRef dr{nullptr, reinterpret_cast<const char*>(headerStack.data()), nullptr};
129 BOOST_CHECK_EQUAL(conditionNConsecutive->decide(dr), t.second);
130 }
131}
A definition of DataSamplingConditionFactory.
static std::unique_ptr< DataSamplingCondition > create(std::string name)
Creates instance of DataSamplingCondition child, given the name.
A DataSamplingCondition which approves n consecutive samples in defined cycle. It assumes that timesl...
A DataSamplingCondition which makes decisions based on payload size.
A DataSamplingCondition which makes decisions randomly, but with determinism.
GLuint id
Definition glcorearb.h:650
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
void check(const std::vector< std::string > &arguments, const std::vector< ConfigParamSpec > &workflowOptions, const std::vector< DeviceSpec > &deviceSpecs, CheckMatrix &matrix)
O2 data header classes and API, v0.1.
Definition DetID.h:49
BOOST_AUTO_TEST_CASE(Descriptor_test)
A header which contains some meta-data generated by Data Sampling.
the main header struct
Definition DataHeader.h:618
PayloadSizeType payloadSize
Definition DataHeader.h:666
a move-only header stack with serialized headers This is the flat buffer where all the headers in a m...
Definition Stack.h:36
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())