Skip to content

Commit ef59a77

Browse files
wpierozakwpierozak
authored andcommitted
Add common FIT configuration types, readers and tests
1 parent ab59052 commit ef59a77

14 files changed

Lines changed: 1510 additions & 1 deletion

File tree

‎DataFormats/Detectors/FIT/common/CMakeLists.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ o2_target_root_dictionary(DataFormatsFIT
2323
include/DataFormatsFIT/LookUpTable.h
2424
include/DataFormatsFIT/Triggers.h
2525
include/DataFormatsFIT/ChannelData.h
26-
include/DataFormatsFIT/Digit.h)
26+
include/DataFormatsFIT/Digit.h
27+
include/DataFormatsFIT/Configuration.h)
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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+
// \file Configuration.h
13+
/// \brief Utilities to describe FEE configuration
14+
/// \author wiktor.pierozak@cern.ch
15+
16+
#ifndef O2_FIT_FEE_CONFIGURATION
17+
#define O2_FIT_FEE_CONFIGURATION
18+
19+
#include <gsl/span>
20+
#include <cstddef>
21+
#include <cstdint>
22+
#include <limits>
23+
#include <type_traits>
24+
#include <algorithm>
25+
#include <Rtypes.h>
26+
27+
namespace o2::fit
28+
{
29+
namespace config_helpers
30+
{
31+
struct DefaultValueType {
32+
template <typename T>
33+
requires std::is_arithmetic_v<T>
34+
constexpr operator T() const noexcept
35+
{
36+
if constexpr (std::is_same_v<T, bool>) {
37+
return false;
38+
} else {
39+
return std::numeric_limits<T>::max();
40+
}
41+
}
42+
};
43+
44+
inline constexpr DefaultValueType DefaultValue{};
45+
46+
template <typename T, std::size_t N>
47+
constexpr void fillDefaultArray(T (&array)[N])
48+
{
49+
for (auto& element : array) {
50+
element = DefaultValue;
51+
}
52+
}
53+
} // namespace config_helpers
54+
55+
struct TcmConfig {
56+
float phaseDelayA{config_helpers::DefaultValue};
57+
float phaseDelayC{config_helpers::DefaultValue};
58+
59+
bool operator==(const TcmConfig&) const = default;
60+
ClassDefNV(TcmConfig, 1);
61+
};
62+
63+
struct PmConfig {
64+
uint8_t orGate{config_helpers::DefaultValue};
65+
uint16_t trgChargeHighLevel{config_helpers::DefaultValue};
66+
uint16_t trgChargeLowLevel{config_helpers::DefaultValue};
67+
bool fddCoincidenceMode{config_helpers::DefaultValue};
68+
bool operator==(const PmConfig&) const = default;
69+
ClassDefNV(PmConfig, 1);
70+
};
71+
72+
template <int NChannels>
73+
struct ChannelsConfig {
74+
int16_t timeAlignments[NChannels];
75+
uint16_t cfdThresholds[NChannels];
76+
int16_t cfdZeros[NChannels];
77+
int16_t adcZeros[NChannels];
78+
uint16_t adcDelays[NChannels];
79+
uint16_t rangeCorrectionAdc0[NChannels];
80+
uint16_t rangeCorrectionAdc1[NChannels];
81+
uint16_t thresholdCalibration[NChannels];
82+
bool channelMaskData[NChannels];
83+
bool channelMaskTriggers[NChannels];
84+
85+
constexpr ChannelsConfig()
86+
{
87+
config_helpers::fillDefaultArray(timeAlignments);
88+
config_helpers::fillDefaultArray(cfdThresholds);
89+
config_helpers::fillDefaultArray(cfdZeros);
90+
config_helpers::fillDefaultArray(adcZeros);
91+
config_helpers::fillDefaultArray(adcDelays);
92+
config_helpers::fillDefaultArray(rangeCorrectionAdc0);
93+
config_helpers::fillDefaultArray(rangeCorrectionAdc1);
94+
config_helpers::fillDefaultArray(channelMaskData);
95+
config_helpers::fillDefaultArray(channelMaskTriggers);
96+
config_helpers::fillDefaultArray(thresholdCalibration);
97+
}
98+
99+
template <typename T>
100+
[[nodiscard]] static constexpr bool isDefault(const T& value)
101+
{
102+
return value == static_cast<T>(config_helpers::DefaultValue);
103+
}
104+
105+
gsl::span<const int16_t, NChannels> getTimeAlignments() const { return timeAlignments; }
106+
gsl::span<const uint16_t, NChannels> getCfdThresholds() const { return cfdThresholds; }
107+
gsl::span<const int16_t, NChannels> getCfdZeros() const { return cfdZeros; }
108+
gsl::span<const int16_t, NChannels> getAdcZeros() const { return adcZeros; }
109+
gsl::span<const uint16_t, NChannels> getAdcDelays() const { return adcDelays; }
110+
gsl::span<const uint16_t, NChannels> getRangeCorrectionAdc0() const { return rangeCorrectionAdc0; }
111+
gsl::span<const uint16_t, NChannels> getRangeCorrectionAdc1() const { return rangeCorrectionAdc1; }
112+
gsl::span<const uint16_t, NChannels> getThresholdCalibration() const { return thresholdCalibration; }
113+
gsl::span<const bool, NChannels> getChannelMaskTriggers() const { return channelMaskTriggers; }
114+
gsl::span<const bool, NChannels> getChannelMaskData() const { return channelMaskData; }
115+
116+
bool operator==(const ChannelsConfig& other) const
117+
{
118+
return std::equal(std::begin(timeAlignments), std::end(timeAlignments), std::begin(other.timeAlignments)) &&
119+
std::equal(std::begin(cfdThresholds), std::end(cfdThresholds), std::begin(other.cfdThresholds)) &&
120+
std::equal(std::begin(cfdZeros), std::end(cfdZeros), std::begin(other.cfdZeros)) &&
121+
std::equal(std::begin(adcZeros), std::end(adcZeros), std::begin(other.adcZeros)) &&
122+
std::equal(std::begin(adcDelays), std::end(adcDelays), std::begin(other.adcDelays)) &&
123+
std::equal(std::begin(rangeCorrectionAdc0), std::end(rangeCorrectionAdc0), std::begin(other.rangeCorrectionAdc0)) &&
124+
std::equal(std::begin(rangeCorrectionAdc1), std::end(rangeCorrectionAdc1), std::begin(other.rangeCorrectionAdc1)) &&
125+
std::equal(std::begin(thresholdCalibration), std::end(thresholdCalibration), std::begin(other.thresholdCalibration)) &&
126+
std::equal(std::begin(channelMaskData), std::end(channelMaskData), std::begin(other.channelMaskData)) &&
127+
std::equal(std::begin(channelMaskTriggers), std::end(channelMaskTriggers), std::begin(other.channelMaskTriggers));
128+
}
129+
130+
ClassDefNV(ChannelsConfig<NChannels>, 1);
131+
};
132+
133+
template <std::size_t NChannels>
134+
struct HvChannelsConfig {
135+
float gain[NChannels];
136+
137+
constexpr HvChannelsConfig()
138+
{
139+
config_helpers::fillDefaultArray(gain);
140+
}
141+
bool operator==(const HvChannelsConfig& other) const
142+
{
143+
return std::equal(std::begin(gain), std::end(gain), std::begin(other.gain));
144+
}
145+
ClassDefNV(HvChannelsConfig<NChannels>, 1);
146+
};
147+
} // namespace o2::fit
148+
#endif

‎DataFormats/Detectors/FIT/common/src/DataFormatsFITLinkDef.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
#pragma link C++ std::vector < std::pair < uint64_t, int>> + ;
2727
#pragma link C++ struct o2::fit::DCSDPValues + ;
28+
29+
#pragma link C++ struct o2::fit::TcmConfig + ;
30+
#pragma link C++ struct o2::fit::PmConfig + ;
2831
/*
2932
#include "DetectorsCommonDataFormats/DetID.h"
3033
#pragma link C++ struct o2::fit::ChannelData<o2::detectors::DetID::FDD> + ;

‎Detectors/FIT/common/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ add_subdirectory(calibration)
1313
add_subdirectory(dcsmonitoring)
1414
if(BUILD_TESTING)
1515
add_subdirectory(dcsmonitoring/macros)
16+
add_subdirectory(tests)
1617
endif()

‎Detectors/FIT/common/dcsmonitoring/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
o2_add_library(FITDCSMonitoring
1313
SOURCES src/FITDCSConfigReader.cxx
14+
src/FITDCSBaseConfigReader.cxx
1415
src/FITDCSDataProcessor.cxx
1516
src/FITDCSDataReader.cxx
1617
PUBLIC_LINK_LIBRARIES O2::DataFormatsFIT
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Testing DCS workflow locally
2+
3+
## Local CCDB instance
4+
Local CCDB instance is available here: `http://alimonitor.cern.ch/download/local.jar`
5+
Run it with `java -jar local.jar`.
6+
Configuration is done via environment variables
7+
8+
| Name | Description |
9+
| --- | --- |
10+
| FILE_REPOSITORY_LOCATION | repository directory, default `/tmp/QC` |
11+
| TOMCAT_ADDRESS | CCDB address, default `127.0.0.1` |
12+
| TOMCAT_PORT | CCDB port, default `8080` |
13+
14+
## Compilation of DCS helpers
15+
16+
17+
18+
## Running DCS workflow
19+
20+
21+
```bash
22+
#!/bin/bash
23+
DET="FDD"
24+
CHANFROM="type=sub,method=connect,address=tcp://127.0.0.1:5556,rateLogging=1,transport=zeromq"
25+
CHANACK="type=push,method=connect,address=tcp://127.0.0.1:5557,rateLogging=1,transport=zeromq"
26+
27+
o2-dcs-config-proxy --subscribe-to "${CHANFROM}" --acknowlege-to "${CHANACK}" \
28+
| o2-fdd-dcs-config-workflow \
29+
| o2-calibration-ccdb-populator-workflow --ccdb-path=http://localhost:18080
30+
31+
```
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
#ifndef O2_FIT_DCS_VALIDITY_H
13+
#define O2_FIT_DCS_VALIDITY_H
14+
15+
#include "CCDB/CcdbApi.h"
16+
17+
namespace o2::fit
18+
{
19+
class DcsCcdbInfo
20+
{
21+
public:
22+
DcsCcdbInfo(long validityInDays) : mValidityDays(validityInDays) {}
23+
24+
long getValidityTimestamp(long startTimestamp) const
25+
{
26+
return startTimestamp + mValidityDays * o2::ccdb::CcdbObjectInfo::DAY;
27+
}
28+
29+
void setValidityPeriodInDays(long days)
30+
{
31+
mValidityDays = days;
32+
}
33+
34+
long getValidityPeriodInDays() const
35+
{
36+
return mValidityDays;
37+
}
38+
39+
void setValidateUpload(bool validate)
40+
{
41+
mValidateUpload = validate;
42+
}
43+
44+
bool getValidateUpload() const
45+
{
46+
return mValidateUpload;
47+
}
48+
49+
void setCcdbPath(const std::string path)
50+
{
51+
mCcdbPath = path;
52+
}
53+
54+
const std::string& getCcdbPath() const
55+
{
56+
return mCcdbPath;
57+
}
58+
59+
template <typename DcsConfigType>
60+
o2::ccdb::CcdbObjectInfo createObjectInfo(const DcsConfigType& configObject, long startValidityTimestamp, const std::map<std::string, std::string>& metadata)
61+
{
62+
o2::ccdb::CcdbObjectInfo objectInfo;
63+
o2::calibration::Utils::prepareCCDBobjectInfo(configObject, objectInfo, mCcdbPath, metadata, startValidityTimestamp, getValidityTimestamp(startValidityTimestamp));
64+
objectInfo.setValidateUpload(mValidateUpload);
65+
return objectInfo;
66+
}
67+
68+
private:
69+
long mValidityDays;
70+
bool mValidateUpload{false};
71+
std::string mCcdbPath;
72+
};
73+
} // namespace o2::fit
74+
#endif
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
#ifndef O2_FIT_DCS_BASE_CONFIG_READER_H
13+
#define O2_FIT_DCS_BASE_CONFIG_READER_H
14+
15+
#include <rapidjson/document.h>
16+
#include <rapidjson/schema.h>
17+
#include <gsl/span>
18+
#include "DetectorsCalibration/Utils.h"
19+
20+
namespace o2::fit
21+
{
22+
class FITDCSBaseConfigReader
23+
{
24+
public:
25+
virtual ~FITDCSBaseConfigReader() = default;
26+
template <typename T, int Size>
27+
void parseJsonArray(const rapidjson::Value& node, const char* childName, T (&array)[Size])
28+
{
29+
if (node.HasMember(childName) == false) {
30+
throw std::runtime_error(std::string("Failed to find node of name ") + childName);
31+
}
32+
const auto& childNode = node[childName];
33+
if (childNode.IsArray() == false) {
34+
throw std::runtime_error(std::format("Node {} is not an array!", childName));
35+
}
36+
auto jsonArray = childNode.GetArray();
37+
if (jsonArray.Size() != Size) {
38+
throw std::runtime_error(std::format("Array {}. Expected array of size {}, parsed array of size {}", childName, Size, jsonArray.Size()));
39+
}
40+
for (int idx = 0; idx < Size; idx++) {
41+
const auto& node = jsonArray[idx];
42+
if constexpr (std::is_same_v<T, bool>) {
43+
if (!node.IsBool()) {
44+
throw std::runtime_error(std::format("{} is not a bool array", childName));
45+
}
46+
array[idx] = node.GetBool();
47+
} else if constexpr (std::is_floating_point_v<T>) {
48+
if (!node.IsNumber()) {
49+
throw std::runtime_error(std::format("{} is not an floating point array", childName));
50+
}
51+
array[idx] = node.GetFloat();
52+
} else if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T>) {
53+
if (!node.IsUint()) {
54+
throw std::runtime_error(std::format("{} is not an unsigned integer array", childName));
55+
}
56+
array[idx] = static_cast<T>(node.GetUint());
57+
} else if constexpr (std::is_integral_v<T>) {
58+
if (!node.IsInt()) {
59+
throw std::runtime_error(std::format("{} is not an integer array", childName));
60+
}
61+
array[idx] = static_cast<T>(node.GetInt());
62+
} else {
63+
static_assert(std::is_same_v<T, void>, "Unsupported type");
64+
}
65+
}
66+
}
67+
68+
void setFilename(const std::string& filename)
69+
{
70+
mFilename = filename;
71+
}
72+
73+
const std::string& getFilename() const
74+
{
75+
return mFilename;
76+
}
77+
78+
bool matchFilename(const std::string& filename)
79+
{
80+
return mFilename == filename;
81+
}
82+
83+
bool validateSchema(const rapidjson::Document& docs, std::string& errorMessage);
84+
85+
protected:
86+
void loadSchema(std::string_view schema);
87+
rapidjson::Document parseJsonBuffer(gsl::span<const char> buffer, bool throwOnInvalidSchema = true);
88+
89+
private:
90+
std::string mFilename;
91+
std::unique_ptr<rapidjson::SchemaDocument> mSchema;
92+
};
93+
} // namespace o2::fit
94+
#endif

0 commit comments

Comments
 (0)