QualityControl  1.5.1
O2 Data Quality Control Framework
Modules development

← Go back to Quickstart | ../README.md "↑ Go to the Table of Content ↑" | Continue to Post-processing →


Before developing a module, one should have a bare idea of what the QualityControl is and how it is designed. The following sections explore these aspects.

QC architecture

alt text

The main data flow is represented in blue. Data samples are selected by the Data Sampling (not represented) and sent to the QC tasks, either on the same machines or on other machines. The tasks produce TObjects, usually histograms, encapsulated in a MonitorObject that are merged (if needed) and then checked. The checkers output a QualityObject along with the MonitorObjects which might have been modified. The MonitorObjects and the QualityObjects are stored in the repository. The QualityObjects can also optionally be aggregated by the Aggregators to produce additional QualityObjects that are also saved in the database.

Asynchronously, the Post-processing can retrieve MonitorObjects from the database when certain events happen (new version of an object, new run) and produce new TObjects such as a trending plot.


https://github.com/AliceO2Group/AliceO2/blob/dev/Framework/Core/README.md "Data Processing Layer" is a software framework developed as a part of O2 project. It structurizes the computing into units called Data Processors - processes that communicate with each other via messages. DPL takes care of generating and running the processing topology out of user declaration code, serializing and deserializing messages, providing the data processors with all the anticipated messages for a given timestamp and much more. Each piece of data is characterized by its DataHeader, which consists (among others) of dataOrigin, dataDescription and SubSpecification - for example {"MFT", "TRACKS", 0}.

An example of a workflow definition which describes the processing steps (Data Processors), their inputs and their outputs can be seen in runBasic.cxx. In the QC we define the workflows in files whose names are prefixed with run.

Data Sampling

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 for more details.

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".

1 {
2  "qc": {
3  ...
4  "tasks": {
5  "QcTask": {
6  ...
7  "dataSource": {
8  "type": "dataSamplingPolicy",
9  "name": "its-raw"
10  },
11  ...
12  }
13  }
14  },
15  "dataSamplingPolicies": [
16  {
17  "id": "its-raw",
18  "active": "true",
19  "machines": [],
20  "query_comment" : "query is in the format of binding1:origin1/description1/subSpec1[;binding2:...]",
21  "query": "raw:ITS/RAWDATA/0",
22  "samplingConditions": [
23  {
24  "condition": "random",
25  "fraction": "0.1",
26  "seed": "1234"
27  }
28  ],
29  "blocking": "false"
30  }
31  ]
32 }

An example of using the data sampling in a DPL workflow is visible in runAdvanced.cxx.

Custom Data Sampling Condition

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.

The class ExampleCondition presents the how to write one's own condition, while in example-default.json the policy ex1 shows how it should be configured.

Bypassing the Data Sampling

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 :

1 {
2  "qc": {
3  ...
4  "tasks": {
5  "QcTask": {
6  ...
7  "dataSource": {
8  "type": "direct",
9  "query_comment" : "query is in the format of binding1:origin1/description1/subSpec1[;binding2:...]",
10  "query" : "its-raw-data:ITS/RAWDATA/0"
11  },
12  ...
13  }
14  }
15  },
16  "dataSamplingPolicies": [
17  ]
18 }

The file basic-no-sampling.json is provided as an example. To test it, you can run o2-qc with that configuration file instead of basic.json.

To use multiple direct data sources, just place them one after another in the value of "query", separated with a semicolon. For example:

1 "query" : "emcal-digits:EMC/DIGITS/0;emcal-triggers:EMC/TRIGGERS/0"

Code Organization

The repository QualityControl contains the Framework and the Modules in the respectively named directories.

The Data Sampling code is part of the AliceO2 repository.

Developing with aliBuild/alienv

One can of course build using aliBuild (aliBuild build --defaults o2 QualityControl). However, that will take quite some time as it checks all dependencies and builds everything.

After the initial use of aliBuild, which is necessary, the correct way of building is to load the environment with alienv and then go to the build directory and run make or ninja.

1 alienv load QualityControl/latest
2 cd sw/BUILD/QualityControl-latest/QualityControl
3 make -j8 install # or ninja -j8 install , also adapt to the number of cores available

If you need to use the QCG or Readout, load O2Suite instead of QualityControl.

User-defined modules

The Quality Control uses plugins to load the actual code to be executed by the Tasks, the Checks, the Aggregators and the PostProcessing. A module, or plugin, can contain one or several of these classes. They must subclass the corresponding interfaces, for example TaskInterface.h or CheckInterface.h. We use the Template Method Design Pattern.

The same code, the same class, can be run many times in parallel. It means that one can run several copies of the same qc Task in parallel, each executing the same code but on different data samples, typically on different nodes.


QC results (MonitorObjects and QualityObjects) are stored in a repository that we usually call the QCDB. Indeed, the underlying technology is the one of the CCDB (Condition and Calibration DataBase). As a matter of fact we use the test instance of the CCDB for the tests and development (ccdb-test.cern.ch:8080). In production, we will have a different instance distinct from the CCDB.


We use a consistent system of path for the objects we store in the QCDB:

  • MonitorObjects: qc/<detectorCode>/MO/<taskName>/<moName>
  • QualityObjects: qc/<detectorCode>/QO/<checkName>[/<moName>] The last, optional, part depends on the policy (read more about that later).

Module creation

Before starting to develop the code, one should create a new module if it does not exist yet. Typically each detector team should prepare a module.

The script o2-qc-module-configurator.sh, in the directory Modules, is able to prepare a new module or to add a new Task, Check, Aggregator or PostProcessing task to an existing module. It must be run from within QualityControl/Modules. See the help message below:

1 Usage: ./o2-qc-module-configurator.sh -m MODULE_NAME [OPTION]
3 Generate template QC module and/or tasks, checks, aggregators and postprocessing.
4 If a module with specified name already exists, new tasks, checks, aggregators and postprocessing are inserted to the existing module.
5 Please follow UpperCamelCase convention for modules', tasks' and checks' names.
7 Example:
8 # create new module and some task
9 ./o2-qc-module-configurator.sh -m MyModule -t SuperTask
10 # add one task and two checks
11 ./o2-qc-module-configurator.sh -m MyModule -t EvenBetterTask -c HistoUniformityCheck -c MeanTest
13 Options:
14  -h print this message
15  -m MODULE_NAME create a module named MODULE_NAME or add there some task/checker
16  -t TASK_NAME create a task named TASK_NAME
17  -c CHECK_NAME create a check named CHECK_NAME
18  -p PP_NAME create a postprocessing task named PP_NAME
19  -a AGG_NAME create an aggregator named AGG_NAME

For example, if your detector 3-letter code is TST you might want to do

1 # we are in ~/alice
2 cd QualityControl/Modules
3 ./o2-qc-module-configurator.sh -m TST -t RawDataQcTask # create the module and a task

IMPORTANT: Make sure that your detector code is listed in TaskRunner::validateDetectorName. If it is not, feel free to add it.

We will refer in the following section to the module as Tst and the task as RawDataQcTask. Make sure to use your own code and names.

Test run

Now that there is a module, we can build it and test it. First let's build it :

1 # We are in ~/alice, call alienv if not already done
2 alienv enter QualityControl/latest
3 # Go to the build directory of QualityControl.
4 cd sw/BUILD/QualityControl-latest/QualityControl
5 make -j8 install # or ninja, replace 8 by the number of cores on your machine

To test whether it works, we are going to run a basic workflow made of a producer and the qc, which corresponds to the one we saw in the QuickStart.

We are going to duplicate the config file we used previously, i.e. basic.json:

1 cp ~/alice/QualityControl/Framework/basic.json ~/alice/QualityControl/Modules/TST/basic-tst.json

We need to modify it slightly to indicate our freshly created module and classes. Change the lines as indicated below :

1 "tasks": {
2  "MyRawDataQcTask": {
3  "active": "true",
4  "className": "o2::quality_control_modules::abc::RawDataQcTask",
5  "moduleName": "QcTST",
6  "detectorName": "TST",


1 "detectorName": "TST",
2 "dataSource": [{
3  "type": "Task",
4  "name": "MyRawDataQcTask",

Now we can run it

1 o2-qc-run-producer | o2-qc --config json://$HOME/alice/QualityControl/Modules/TST/basic-tst.json

You should see an object example in /qc/TST/MO/MyRawDataQcTask at qcg-test.cern.ch.

Saving the QC objects in a local file

When debugging and developping, and only in this case, it can be handy to save the objects being produced to a file. Simply add the parameter saveObjectsToFile to the task definition and set it to file name with or without a path. For example:

1 "saveObjectsToFile": "test.root", "": "For debugging, path to the file where to save. If empty it won't save."

Modification of the Task

We are going to modify our task to make it publish a second histogram. Objects must be published only once and they will then be updated automatically every cycle (10 seconds for our example, 1 minute in general). Modify RawDataQcTask.cxx and its header to add a new histogram, build it and publish it with getObjectsManager()->startPublishing(mHistogram);. Once done, recompile it (see section above, make -j8 install in the build directory) and run it (same as above). You should see the second object published in the qcg.


A Check is a function that determines the quality of the Monitor Objects produced in the previous step - Task. It can receive multiple Monitor Objects from several Tasks.


1 {
2  "qc" : {
3  "config" : { ... },
4  "tasks" : { ... },
6  "checks": {
7  "CheckName": {
8  "active": "true",
9  "className": "o2::quality_control_modules::skeleton::SkeletonCheck",
10  "moduleName": "QcSkeleton",
11  "policy": "OnAny",
12  "dataSource": [{
13  "type": "Task",
14  "name": "TaskName"
15  },
16  {
17  "type": "Task",
18  "name": "QcTask",
19  "MOs": ["example", "other"]
20  }]
21  },
22  "QcCheck": {
23  ...
24  }
25  }
27 }
  • active - Boolean to indicate whether the checker is active or not
  • moduleName - Name of the module which implements the check class (like in tasks)
  • className - Name and namespace of the class, which is part of the module specified above (like in tasks)
  • policy - Policy for triggering the check function defined in the class:
    • OnAny (default) - Triggers if ANY of the listed monitor objects changes.
    • OnAnyNonZero - Triggers if ANY of the declared monitor objects changes, but only after all listed objects have been received at least once.
    • OnAll - Triggers if ALL the listed monitor objects have changed.
    • OnEachSeparately - Triggers separately for EACH of the listed objects whenever one of them changes.
    • In case the list of monitor objects is empty, the policy is simply ignored and the check will be triggered whenever a new MonitorObject is received.
  • dataSource - declaration of the check input
    • type - currently only supported is Task
    • name - name of the Task
    • MOs - list of MonitorObjects names or can be omitted to mean that all objects should be taken.


After the creation of the module described in the above section, every Check functionality requires a separate implementation. The module might implement several Check classes.

1 {c++}
2 Quality check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap) {}
4 void beautify(std::shared_ptr<MonitorObject> mo, Quality = Quality::Null) {}

The check function is called whenever the policy is satisfied. It gets a map with all declared MonitorObjects. It is expected to return Quality of the given MonitorObjects.

The beautify function is called after the check function if there is a single dataSource of type Task in the configuration of the check. If there is more than one, the beautify() is not called in this check.

Quality Aggregation

The Aggregators are able to collect the QualityObjects produced by the checks or other Aggregators and to produce new Qualities. This is especially useful to determine the overall quality of a detector or a set of detectors.

alt text

Quick try

One can try it with this simple example:

1 {c++}
2 o2-qc-run-basic --config-path ${QUALITYCONTROL_ROOT}/etc/basic-aggregator.json

Notice the AggregatorRunner after the CheckRunner.

A more complex example with a producer and the o2-qc:

1 o2-qc-run-advanced --no-qc | o2-qc --config json://${QUALITYCONTROL_ROOT}/etc/advanced-aggregator.json


1 {
2  "qc": {
3  "config": {...},
4  "tasks": {...},
5  "checks": {...},
6  "aggregators": {
7  "MyAggregator": {
8  "active": "true",
9  "className": "o2::quality_control_modules::skeleton::SkeletonAggregator",
10  "moduleName": "QcSkeleton",
11  "policy": "OnAll",
12  "detectorName": "TST",
13  "dataSource": [{
14  "type": "Check",
15  "name": "QcCheck", "": "If the check produces multiple objects, specify \"QOs\""
16  },
17  {
18  "type": "Aggregator",
19  "name": "MyOtherAggregator",
20  "QOs": ["newQuality", "another"]
21  }]
22  }
23  }
24  },
25  "dataSamplingPolicies": [...]
26 }
  • active - Boolean to indicate whether the aggregator is active or not
  • moduleName - Name of the module which implements the aggregator class (like in tasks)
  • className - Name and namespace of the class, which is part of the module specified above (like in tasks)
  • policy - Policy for triggering the check function defined in the class:
    • OnAny (default) - Triggers if ANY of the listed quality objects changes.
    • OnAll - Triggers if ALL the listed quality objects have changed.
    • In case the list of QualityObject is empty, the policy is simply ignored and the check will be triggered whenever a new QualityObject is received.
  • dataSource - declaration of the check input
    • type - Check or Aggregator
    • names - name of the Check or Aggregator
    • QOs - list of QualityObjects names or can be omitted to mean that all objects should be taken.


With o2-qc-module-configurator.sh (see here), create a new Aggregator that can be then used in the config file.

An aggregator inherits from AggregatorInterface and in particular this method:

1 {c++}
2  virtual std::vector<Quality> aggregate(std::map<std::string, std::shared_ptr<const o2::quality_control::core::QualityObject>>& qoMap) = 0;

The aggregate method is called whenever the policy is satisfied. It gets a map with all the declared QualityObjects. It is expected to return a new Quality based on the inputs.

Committing code

To commit your new or modified code, please follow this procedure

  1. Fork the QualityControl repo using github webpage or github desktop app.
  1. Clone it : git clone https://github.com/<yourIdentifier>/QualityControl.git
  1. Before you start working on your code, create a branch in your fork : git checkout -b feature-new-stuff
  2. Push the branch : git push --set-upstream origin feature-new-stuff
  1. Add and commit your changes onto this branch : git add Abc.cxx ; git commit Abc.cxx
  2. Push your commits : git push
  3. Once you are satisfied with your changes, make a Pull Request (PR). Go to your branches on the github webpage, and click "New Pull Request". Explain what you did. If you only wanted to share the progress, but your PR is not ready for a review yet, please put [WIP] (Work In Progress) in the beginning of its name.
  4. One of the QC developers will check your code. It will also be automatically tested.
  5. Once approved the changes will be merged in the main repo. You can delete your branch.

For a new feature, just create a new branch for it and use the same procedure. Do not fork again. You can work on several features at the same time by having parallel branches.

General ALICE Git guidelines can be accessed here.

Data sources

In the final system, the qc gets real data from the DPL devices or the readout processes. During development a number of possibilities are available for the detector teams to develop their QC. We list them below.


When connecting the QC directly to the readout using the o2-qc-run-readout proxy, remember to add this consumer to the config file of the readout and to enable it:

1 [consumer-fmq-qc]
2 consumerType=FairMQChannel
3 enableRawFormat=1
4 fmq-name=readout-qc
5 fmq-address=ipc:///tmp/readout-pipe-1
6 fmq-type=pub
7 fmq-transport=zeromq
8 unmanagedMemorySize=2G
9 memoryPoolNumberOfPages=500
10 memoryPoolPageSize=1M
11 enabled=1

Random data

Add one or several dummy equipments:

1 [equipment-dummy-1]
2 name=dummy-1
3 equipmentType=dummy
4 enabled=1
5 eventMaxSize=200
6 eventMinSize=100
7 memoryPoolNumberOfPages=100
8 memoryPoolPageSize=128k
9 fillData=1

Live detector data

If a part or the whole detector is ready and connected to 1 or several CRUs in the FLP, configure the readout to get data from there. The exact configuration items should be discussed with the readout experts.

This is the most realistic test one can do but it is also not very practical as you have to control the data taking and be on the machine equipped with a CRU. See the next section to alleviate this situation.

Detector data file

To record a data file with readout while getting data from a CRU, add the following piece to the readout configuration file:

1 [consumer-rec]
2 enabled=1
3 consumerType=fileRecorder
4 fileName=/tmp/dataRecorder_flp1.raw

To read it back with readout, for instance on another machine, add:

1 [equipment-player-1]
2 equipmentType=player
3 memoryPoolPageSize=1M
4 memoryPoolNumberOfPages=1000
5 filePath=/path/to/dataRecorder_flp1.raw
6 autoChunk=1

DPL workflow

When plugging the QC on a DPL workflow to monitor the output of one or several devices, one should of course have some data producer in the workflow itself. Several options exist, listed below.

Random data

As shown earlier in this documentation we provide a random data generator. The binary is called o2-qc-run-producer and many options are available (use --help to see them).

Data file

To write and read data files in the DPL, please refer to the RawFileWriter and RawFileReader.

On the same page, there are instructions to write such file from Simulation.

Another option to read a raw data file, produced by Simulation or recorded with readout.exe per instance, is to use directly the program o2-raw-file-reader-workflow in O2 as described here (the config file is described earlier in the page).

1 o2-raw-file-reader-workflow --conf myConf.cfg | o2-qc --config json://${QUALITYCONTROL_ROOT}/etc/readout.json

Live detector data

If the detector is ready and connected to the CRU(s), one can of course start the full data taking workflow, including the SubTimeFrameBuilder and the DPL processing and plug the QC onto it.

A more advanced example

A more complete example is available. The config file is called advanced.json. The workflow is made of 3 sources, intermediate processing steps, 3 sinks and a Dispatcher connecting two QC tasks to a number of these steps and 2 checks. The topology doesn't mean to represent any particular physics processing, it is just an example with multiple data processors.

alt text

To run it do either

1 o2-qc-run-advanced


1 o2-qc-run-advanced --no-qc | o2-qc --config json://${QUALITYCONTROL_ROOT}/etc/advanced.json

← Go back to Quickstart | ../README.md "↑ Go to the Table of Content ↑" | Continue to Post-processing →