Skip to content

Commit d8a4da5

Browse files
committed
Standard helpers for creating Input and Output Specs for user data
1 parent ffc5fec commit d8a4da5

File tree

8 files changed

+200
-1
lines changed

8 files changed

+200
-1
lines changed

Framework/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ add_library(O2QualityControl
139139
src/ObjectMetadataHelpers.cxx
140140
src/QCInputsAdapters.cxx
141141
src/QCInputsFactory.cxx
142+
src/UserInputOutput.cxx
142143
)
143144

144145
target_include_directories(
@@ -294,6 +295,7 @@ add_executable(o2-qc-test-core
294295
test/testFlagHelpers.cxx
295296
test/testQualitiesToFlagCollectionConverter.cxx
296297
test/testQCInputs.cxx
298+
test/testUserInputOutput.cxx
297299
)
298300
set_property(TARGET o2-qc-test-core
299301
PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)

Framework/include/QualityControl/DataHeaderHelpers.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace o2::quality_control::core
2727
/// Creates DataOrigin for a data source and detector code
2828
header::DataOrigin createDataOrigin(DataSourceType, const std::string& detectorCode);
2929

30-
/// \brief Creates DataDescription from given name for any QC actor
30+
/// \brief Creates DataDescription from given name for a QC actor
3131
///
3232
/// If the length of the name is <= 16 (hardcoded in DataDescription) it creates DataDescription from the original name.
3333
/// However, if the length of the name is > 16, it will create hash of the whole name and replace ending hashLength of bytes
@@ -39,6 +39,19 @@ header::DataOrigin createDataOrigin(DataSourceType, const std::string& detectorC
3939
/// \param hashLength - number of bytes which will overwrite the end of the name
4040
o2::header::DataDescription createDataDescription(const std::string& name, size_t hashLength);
4141

42+
/// \brief Creates DataDescription from given name for a QC actor
43+
///
44+
/// If the length of the name is <= 16 (hardcoded in DataDescription) it creates DataDescription from the original name.
45+
/// However, if the length of the name is > 16, it will create hash of the whole name and replace ending hashLength of bytes
46+
/// of the name with hexa representation of computed hash.
47+
/// eg.: name == "veryLongNameThatIsLongerThan16B" with hashLength == 4 will result in "veryLongNameABCD", where ABCD
48+
/// is the hash create inside the function.
49+
/// This function deduces hash length for the provided data source type.
50+
///
51+
/// \param name - name which should cut and hashed
52+
/// \param type - data source type associated to an actor
53+
o2::header::DataDescription createDataDescription(const std::string& name, DataSourceType type);
54+
4255
} // namespace o2::quality_control::core
4356

4457
#endif
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 UserInputOutput.h
14+
/// \author Piotr Konopka
15+
///
16+
17+
#ifndef QUALITYCONTROL_USERINPUTOUTPUT_H
18+
#define QUALITYCONTROL_USERINPUTOUTPUT_H
19+
20+
#include <string>
21+
22+
#include <Framework/ConcreteDataMatcher.h>
23+
#include <Framework/InputSpec.h>
24+
#include <Framework/OutputSpec.h>
25+
26+
#include "QualityControl/DataHeaderHelpers.h"
27+
#include "QualityControl/DataSourceType.h"
28+
29+
namespace o2::quality_control::core
30+
{
31+
32+
/// \brief returns a standard ConcreteDataMatcher for QC inputs and outputs
33+
framework::ConcreteDataMatcher
34+
createUserDataMatcher(DataSourceType dataSourceType, const std::string& detectorName, const std::string& userCodeName);
35+
36+
/// \brief returns a standard InputSpec for QC inputs and outputs
37+
framework::InputSpec
38+
createUserInputSpec(DataSourceType dataSourceType, const std::string& detectorName, const std::string& userCodeName);
39+
40+
/// \brief returns a standard OutputSpec for QC inputs and outputs
41+
framework::OutputSpec
42+
createUserOutputSpec(DataSourceType dataSourceType, const std::string& detectorName, const std::string& userCodeName);
43+
44+
} // namespace o2::quality_control::core
45+
46+
#endif // QUALITYCONTROL_USERINPUTOUTPUT_H

Framework/src/DataHeaderHelpers.cxx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,29 @@ auto createDataDescription(const std::string& name, size_t hashLength) -> o2::he
100100
}
101101
}
102102

103+
constexpr size_t descriptionHashLengthFor(DataSourceType type)
104+
{
105+
size_t hashLength = 0;
106+
switch (type) {
107+
case DataSourceType::DataSamplingPolicy:
108+
case DataSourceType::Direct:
109+
case DataSourceType::ExternalTask:
110+
throw std::invalid_argument("Provided data source type is not generated by QC, cannot provide a hash length");
111+
case DataSourceType::Task:
112+
case DataSourceType::TaskMovingWindow:
113+
case DataSourceType::Check:
114+
case DataSourceType::Aggregator:
115+
case DataSourceType::PostProcessingTask:
116+
default:
117+
hashLength = 4;
118+
}
119+
assert(hashLength <= o2::header::DataDescription::size);
120+
return hashLength;
121+
}
122+
123+
auto createDataDescription(const std::string& name, DataSourceType type) -> o2::header::DataDescription
124+
{
125+
return createDataDescription(name, descriptionHashLengthFor(type));
126+
}
127+
103128
} // namespace o2::quality_control::core

Framework/src/InfrastructureGenerator.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "QualityControl/TaskRunner.h"
3232
#include "QualityControl/TaskRunnerFactory.h"
3333
#include "QualityControl/Version.h"
34+
#include "QualityControl/UserInputOutput.h"
3435

3536
#include <Framework/DataProcessorSpec.h>
3637
#include <Framework/DataRefUtils.h>

Framework/src/UserInputOutput.cxx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 UserInputOutput.cxx
14+
/// \author Piotr Konopka
15+
///
16+
17+
#include "QualityControl/UserInputOutput.h"
18+
19+
namespace o2::quality_control::core
20+
{
21+
22+
framework::ConcreteDataMatcher
23+
createUserDataMatcher(DataSourceType dataSourceType, const std::string& detectorName, const std::string& userCodeName)
24+
{
25+
return {
26+
createDataOrigin(dataSourceType, detectorName),
27+
createDataDescription(userCodeName, dataSourceType),
28+
0
29+
};
30+
}
31+
32+
framework::InputSpec
33+
createUserInputSpec(DataSourceType dataSourceType, const std::string& detectorName, const std::string& userCodeName)
34+
{
35+
// currently all of our outputs are Lifetime::Sporadic, so we don't allow for customization, but it could be factored out.
36+
// we assume using `userCodeName` as a binding in all cases
37+
return {
38+
userCodeName,
39+
createUserDataMatcher(dataSourceType, detectorName, userCodeName),
40+
framework::Lifetime::Sporadic
41+
};
42+
}
43+
44+
framework::OutputSpec
45+
createUserOutputSpec(DataSourceType dataSourceType, const std::string& detectorName, const std::string& userCodeName)
46+
{
47+
// currently all of our outputs are Lifetime::Sporadic, so we don't allow for customization, but it could be factored out.
48+
// we assume using `userCodeName` as a binding in all cases
49+
return {
50+
framework::OutputLabel{ userCodeName },
51+
createUserDataMatcher(dataSourceType, detectorName, userCodeName),
52+
framework::Lifetime::Sporadic
53+
};
54+
}
55+
56+
} // namespace o2::quality_control::core

Framework/test/testDataHeaderHelpers.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ TEST_CASE("DataDescription")
4444
CHECK(createDataDescription("LOOOOOOOOOOOOOOONG", 4) != DataDescription("LOOOOOOOOOOOOOON"));
4545

4646
CHECK_THROWS(createDataDescription("LOOOOOOOOOOOOOOONG", DataDescription::size + 50));
47+
48+
CHECK(createDataDescription("LOOOOOOOOOOOOOOONG", DataSourceType::Task) != DataDescription("LOOOOOOOOOOOOOON"));
49+
CHECK_THROWS(createDataDescription("WHATEVER", DataSourceType::ExternalTask));
4750
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 testUserInputOutput.cxx
14+
/// \author Piotr Konopka
15+
///
16+
17+
#include <catch_amalgamated.hpp>
18+
19+
#include <Headers/DataHeader.h>
20+
#include <Framework/DataSpecUtils.h>
21+
22+
#include "QualityControl/UserInputOutput.h"
23+
24+
using namespace o2::header;
25+
26+
namespace o2::quality_control::core
27+
{
28+
29+
TEST_CASE("ConcreteDataMatcher")
30+
{
31+
auto dataMatcher = createUserDataMatcher(DataSourceType::Task, "TST", "mytask");
32+
CHECK(dataMatcher.origin == DataOrigin{ "QTST" });
33+
CHECK(dataMatcher.description == DataDescription{ "mytask" });
34+
CHECK(dataMatcher.subSpec == 0);
35+
}
36+
37+
TEST_CASE("InputSpec")
38+
{
39+
auto inputSpec = createUserInputSpec(DataSourceType::Task, "TST", "mytask");
40+
CHECK(inputSpec.binding == "mytask");
41+
CHECK(inputSpec.lifetime == framework::Lifetime::Sporadic);
42+
CHECK(framework::DataSpecUtils::match(inputSpec, framework::ConcreteDataMatcher{ DataOrigin{ "QTST" }, DataDescription{ "mytask" }, 0 }));
43+
}
44+
45+
TEST_CASE("OutputSpec")
46+
{
47+
auto outputSpec = createUserOutputSpec(DataSourceType::Task, "TST", "mytask");
48+
CHECK(outputSpec.binding.value == "mytask");
49+
CHECK(outputSpec.lifetime == framework::Lifetime::Sporadic);
50+
CHECK(framework::DataSpecUtils::match(outputSpec, framework::ConcreteDataMatcher{ DataOrigin{ "QTST" }, DataDescription{ "mytask" }, 0 }));
51+
}
52+
53+
} // namespace o2::quality_control::core

0 commit comments

Comments
 (0)