Skip to content

Commit ffc5fec

Browse files
committed
Standard helper to create DataOrigin for QC data sources
1 parent c4d6848 commit ffc5fec

File tree

11 files changed

+144
-24
lines changed

11 files changed

+144
-24
lines changed

Framework/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ add_library(O2QualityControl
9898
src/InfrastructureSpecReader.cxx
9999
src/Check.cxx
100100
src/Aggregator.cxx
101-
src/HashDataDescription.cxx
101+
src/DataHeaderHelpers.cxx
102102
src/Triggers.cxx
103103
src/TriggerHelpers.cxx
104104
src/PostProcessingRunner.cxx
@@ -276,6 +276,7 @@ add_executable(o2-qc-test-core
276276
test/testCheckInterface.cxx
277277
test/testCheckRunner.cxx
278278
test/testCustomParameters.cxx
279+
test/testDataHeaderHelpers.cxx
279280
test/testInfrastructureGenerator.cxx
280281
test/testMonitorObject.cxx
281282
test/testPolicyManager.cxx

Framework/include/QualityControl/HashDataDescription.h renamed to Framework/include/QualityControl/DataHeaderHelpers.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,34 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#ifndef QC_HASH_DATA_DESCRIPTION_H
13-
#define QC_HASH_DATA_DESCRIPTION_H
12+
#ifndef QC_DATA_HEADER_HELPERS_H
13+
#define QC_DATA_HEADER_HELPERS_H
1414

1515
#include <cstddef>
1616
#include <string>
1717

1818
#include <Headers/DataHeader.h>
1919

20+
#include "QualityControl/DataSourceType.h"
21+
2022
namespace o2::quality_control::core
2123
{
2224

23-
/// \brief Creates DataDescription from given name.
25+
/// \brief Creates DataOrigin for a QC Actor.
26+
///
27+
/// Creates DataOrigin for a data source and detector code
28+
header::DataOrigin createDataOrigin(DataSourceType, const std::string& detectorCode);
29+
30+
/// \brief Creates DataDescription from given name for any QC actor
2431
///
2532
/// If the length of the name is <= 16 (hardcoded in DataDescription) it creates DataDescription from the original name.
2633
/// However, if the length of the name is > 16, it will create hash of the whole name and replace ending hashLength of bytes
2734
/// of the name with hexa representation of computed hash.
28-
/// eg.: name == "veryLongNameThatIsLongerThan16B" with hashLengh == 4 will result in "veryLongNameABCD", where ABCD
35+
/// eg.: name == "veryLongNameThatIsLongerThan16B" with hashLength == 4 will result in "veryLongNameABCD", where ABCD
2936
/// is the hash create inside the function
3037
///
3138
/// \param name - name which should cut and hashed
32-
/// \param hashLenght - number of bytes which will overwrite the end of the name
39+
/// \param hashLength - number of bytes which will overwrite the end of the name
3340
o2::header::DataDescription createDataDescription(const std::string& name, size_t hashLength);
3441

3542
} // namespace o2::quality_control::core

Framework/include/QualityControl/DataSourceSpec.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,11 @@
2121
#include <Framework/InputSpec.h>
2222
#include <type_traits>
2323

24+
#include "QualityControl/DataSourceType.h"
25+
2426
namespace o2::quality_control::core
2527
{
2628

27-
enum class DataSourceType {
28-
DataSamplingPolicy,
29-
Direct,
30-
Task,
31-
TaskMovingWindow,
32-
Check,
33-
Aggregator,
34-
PostProcessingTask,
35-
ExternalTask,
36-
Invalid
37-
};
38-
3929
// this should allow us to represent all data sources which come from DPL (and maybe CCDB).
4030
struct DataSourceSpec {
4131
explicit DataSourceSpec(DataSourceType type = DataSourceType::Invalid);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
///
13+
/// \file DataSourceType.h
14+
/// \author Piotr Konopka
15+
///
16+
17+
#ifndef QUALITYCONTROL_DATASOURCETYPE_H
18+
#define QUALITYCONTROL_DATASOURCETYPE_H
19+
20+
namespace o2::quality_control::core
21+
{
22+
23+
enum class DataSourceType {
24+
DataSamplingPolicy,
25+
Direct,
26+
Task,
27+
TaskMovingWindow,
28+
Check,
29+
Aggregator,
30+
PostProcessingTask,
31+
ExternalTask,
32+
Invalid
33+
};
34+
35+
}
36+
37+
#endif // QUALITYCONTROL_DATASOURCETYPE_H

Framework/src/Aggregator.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "QualityControl/Activity.h"
2727
#include <Common/Exceptions.h>
2828
#include "QualityControl/CommonSpec.h"
29-
#include "QualityControl/HashDataDescription.h"
29+
#include "QualityControl/DataHeaderHelpers.h"
3030

3131
#include <utility>
3232
#include <algorithm>

Framework/src/AggregatorRunner.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include "QualityControl/ConfigParamGlo.h"
4242
#include "QualityControl/Bookkeeping.h"
4343
#include "QualityControl/WorkflowType.h"
44-
#include "QualityControl/HashDataDescription.h"
44+
#include "QualityControl/DataHeaderHelpers.h"
4545

4646
using namespace AliceO2::Common;
4747
using namespace AliceO2::InfoLogger;

Framework/src/Check.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "QualityControl/RootClassFactory.h"
3030
#include "QualityControl/QcInfoLogger.h"
3131
#include "QualityControl/Quality.h"
32-
#include "QualityControl/HashDataDescription.h"
32+
#include "QualityControl/DataHeaderHelpers.h"
3333
#include "QualityControl/ObjectMetadataHelpers.h"
3434

3535
#include <QualityControl/AggregatorRunner.h>
Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,50 @@
1212
#include <iomanip>
1313
#include <sstream>
1414

15-
#include "QualityControl/HashDataDescription.h"
15+
#include "QualityControl/DataHeaderHelpers.h"
1616
#include "QualityControl/QcInfoLogger.h"
1717

1818
namespace o2::quality_control::core
1919
{
2020

21+
constexpr char CharIdFrom(DataSourceType type)
22+
{
23+
switch (type) {
24+
case DataSourceType::DataSamplingPolicy:
25+
case DataSourceType::Direct:
26+
case DataSourceType::ExternalTask:
27+
throw std::invalid_argument("Provided data source type is not generated by QC, cannot provide a corresponding character");
28+
case DataSourceType::Task:
29+
return 'Q';
30+
case DataSourceType::TaskMovingWindow:
31+
return 'W';
32+
case DataSourceType::Check:
33+
return 'C';
34+
case DataSourceType::Aggregator:
35+
return 'A';
36+
case DataSourceType::PostProcessingTask:
37+
return 'P';
38+
default:
39+
throw std::invalid_argument("Unrecognized data source type");
40+
}
41+
}
42+
43+
header::DataOrigin createDataOrigin(DataSourceType dataSourceType, const std::string& detectorCode)
44+
{
45+
std::string originStr{ CharIdFrom(dataSourceType) };
46+
if (detectorCode.empty()) {
47+
throw std::invalid_argument{ "empty detector code for a data source origin" };
48+
} else if (detectorCode.size() > 3) {
49+
ILOG(Warning, Support) << "too long detector code for a task data origin: " + detectorCode + ", trying to survive with: " + detectorCode.substr(0, 3) << ENDM;
50+
originStr += detectorCode.substr(0, 3);
51+
} else {
52+
originStr += detectorCode;
53+
}
54+
o2::header::DataOrigin origin;
55+
origin.runtimeInit(originStr.c_str());
56+
return origin;
57+
}
58+
2159
namespace hash
2260
{
2361

Framework/src/PostProcessingDevice.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "QualityControl/PostProcessingInterface.h"
2222
#include "QualityControl/PostProcessingRunnerConfig.h"
2323
#include "QualityControl/QcInfoLogger.h"
24-
#include "QualityControl/HashDataDescription.h"
24+
#include "QualityControl/DataHeaderHelpers.h"
2525
#include "QualityControl/runnerUtils.h"
2626

2727
#include <Common/Exceptions.h>

Framework/src/TaskRunner.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#include "QualityControl/TimekeeperFactory.h"
5050
#include "QualityControl/ActivityHelpers.h"
5151
#include "QualityControl/WorkflowType.h"
52-
#include "QualityControl/HashDataDescription.h"
52+
#include "QualityControl/DataHeaderHelpers.h"
5353
#include "QualityControl/runnerUtils.h"
5454

5555
#include <string>

0 commit comments

Comments
 (0)