Skip to content

Commit 4f9ff2f

Browse files
knopers8Barthelemy
authored andcommitted
An example of custom sampling condition (#211)
1 parent cce0862 commit 4f9ff2f

File tree

6 files changed

+100
-3
lines changed

6 files changed

+100
-3
lines changed

Framework/example-default.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@
7373
}
7474
],
7575
"subSpec": "0",
76-
"samplingConditions": []
76+
"samplingConditions": [
77+
{
78+
"condition": "custom",
79+
"moduleName": "QcExample",
80+
"className": "o2::quality_control_modules::example::ExampleCondition",
81+
"threshold": "120"
82+
}
83+
]
7784
},
7885
{
7986
"id": "mftclusters",

Modules/Example/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ---- Library ----
22

33
add_library(QcExample src/BenchmarkTask.cxx src/ExampleTask.cxx
4-
src/FakeCheck.cxx)
4+
src/FakeCheck.cxx src/ExampleCondition.cxx)
55

66
target_include_directories(
77
QcExample
@@ -15,6 +15,7 @@ add_root_dictionary(QcExample
1515
HEADERS include/Example/BenchmarkTask.h
1616
include/Example/ExampleTask.h
1717
include/Example/FakeCheck.h
18+
include/Example/ExampleCondition.h
1819
LINKDEF include/Example/LinkDef.h
1920
BASENAME QcExample)
2021

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
///
12+
/// \file ExampleCondition.h
13+
/// \author Piotr Konopka
14+
///
15+
16+
#ifndef QC_MODULE_EXAMPLE_EXAMPLECONDITION_H
17+
#define QC_MODULE_EXAMPLE_EXAMPLECONDITION_H
18+
19+
#include "QualityControl/TaskInterface.h"
20+
#include <Framework/DataSamplingCondition.h>
21+
#include <TROOT.h>
22+
23+
namespace o2::quality_control_modules::example
24+
{
25+
26+
/// \brief Example of custom Data Sampling Condition
27+
/// \author Piotr Konopka
28+
29+
/// \brief A DataSamplingCondition which approves messages which have their first byte in the payload higher than
30+
/// specified value.
31+
class ExampleCondition : public o2::framework::DataSamplingCondition
32+
{
33+
public:
34+
/// \brief Constructor.
35+
ExampleCondition() : DataSamplingCondition(){};
36+
/// \brief Default destructor
37+
~ExampleCondition() override = default;
38+
39+
/// \brief Reads 'threshold'
40+
void configure(const boost::property_tree::ptree& config) override;
41+
/// \brief Makes a positive decision if first byte is higher than 'threshold'
42+
bool decide(const o2::framework::DataRef& dataRef) override;
43+
44+
private:
45+
uint8_t mThreshold;
46+
};
47+
48+
} // namespace o2::quality_control_modules::example
49+
50+
#endif //QC_MODULE_EXAMPLE_EXAMPLECONDITION_H

Modules/Example/include/Example/LinkDef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
#pragma link C++ class o2::quality_control_modules::example::ExampleTask + ;
77
#pragma link C++ class o2::quality_control_modules::example::FakeCheck + ;
88
#pragma link C++ class o2::quality_control_modules::example::BenchmarkTask + ;
9+
#pragma link C++ class o2::quality_control_modules::example::ExampleCondition + ;
10+
911
#endif
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
///
12+
/// \file ExampleCondition.cxx
13+
/// \author Piotr Konopka
14+
///
15+
16+
#include "Example/ExampleCondition.h"
17+
18+
namespace o2::quality_control_modules::example
19+
{
20+
21+
void ExampleCondition::configure(const boost::property_tree::ptree& config)
22+
{
23+
mThreshold = config.get<uint8_t>("threshold");
24+
}
25+
26+
bool ExampleCondition::decide(const o2::framework::DataRef& dataRef)
27+
{
28+
return dataRef.payload != nullptr ? dataRef.payload[0] > mThreshold : false;
29+
}
30+
31+
} // namespace o2::quality_control_modules::example

doc/ModulesDevelopment.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ An example of a workflow definition which describes the processing steps (_Data
4444

4545
### Data Sampling
4646

47-
The Data Sampling provides the possibility to sample data in DPL workflows, based on certain conditions ( 5% randomly, when payload is greater than 4234 bytes, etc.). The job of passing the right data is done by a data processor called `Dispatcher`. A desired data stream is specified in the form of Data Sampling Policies, defined in the QC JSON configuration file. Please refer to the main [Data Sampling readme](https://github.com/AliceO2Group/AliceO2/blob/dev/Framework/Core/README.md#data-sampling) for more details.
47+
The Data Sampling provides the possibility to sample data in DPL workflows, based on certain conditions ( 5% randomly, when payload is greater than 4234 bytes or others, including custom conditions). The job of passing the right data is done by a data processor called `Dispatcher`. A desired data stream is specified in the form of Data Sampling Policies, defined in the QC JSON configuration file. Please refer to the main [Data Sampling readme](https://github.com/AliceO2Group/AliceO2/blob/dev/Framework/Core/README.md#data-sampling) for more details.
4848

4949
Data Sampling is used by Quality Control to feed the tasks with data. Below we present an example of a configuration file. It instructs Data Sampling to provide a QC task with 10% randomly selected data that has the header `{"ITS", "RAWDATA", 0}`. The data will be accessible inside the QC task by the binding `"raw"`.
5050
```json
@@ -90,6 +90,12 @@ Data Sampling is used by Quality Control to feed the tasks with data. Below we p
9090

9191
An example of using the data sampling in a DPL workflow is visible in [runAdvanced.cxx](https://github.com/AliceO2Group/QualityControl/blob/master/Framework/runAdvanced.cxx).
9292

93+
#### Custom Data Sampling Condition
94+
95+
If needed, a custom data selection can be performed by inheriting the `DataSamplingCondition` class and implementing the `configure` and `decide` methods. Then, to use it, one needs to specify the library and class names in the config file.
96+
97+
The class [ExampleCondition](https://github.com/AliceO2Group/QualityControl/blob/master/Modules/Example/include/Example/ExampleCondition.h) presents the how to write one's own condition, while in [example-default.json](https://github.com/AliceO2Group/QualityControl/blob/master/Framework/example-default.json) the policy `ex1` shows how it should be configured.
98+
9399
#### Bypassing the Data Sampling
94100

95101
In case one needs to sample at a very high rate, or even monitor 100% of the data, the Data Sampling can be omitted altogether. As a result the task is connected directly to the the Device producing the data to be monitored. To do so, change the _dataSource's_ type in the config file from `dataSamplingPolicy` to `direct`. In addition, add the information about the type of data that is expected (dataOrigin, binding, etc...) and remove the dataSamplingPolicies :

0 commit comments

Comments
 (0)