Skip to content

Commit a57ed54

Browse files
authored
FITreco: new common FIT QC task based on digit synch mechanism (#1762)
* FITreco: new common FIT QC task with digit synch mechanism * Update CMakeLists.txt dummy commit for restarting CICD * Update HelperFIT.h * Update DigitSync.h * Update CMakeLists.txt
1 parent e450bd1 commit a57ed54

14 files changed

Lines changed: 681 additions & 55 deletions

File tree

Modules/FIT/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ---- FIT directories ----
22
add_subdirectory(Common)
33
add_subdirectory(FDD)
4+
add_subdirectory(FIT)
45
add_subdirectory(FT0)
56
add_subdirectory(FV0)

Modules/FIT/Common/CMakeLists.txt

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ set(MODULE_NAME "O2QcFITCommon")
55
set(SRCS
66
src/HelperFIT.cxx
77
src/HelperHist.cxx
8+
src/DigitSync.cxx
89
)
910

1011
set(HEADERS
1112
include/FITCommon/HelperFIT.h
1213
include/FITCommon/HelperHist.h
14+
include/FITCommon/DigitSync.h
1315
)
1416

1517
# ---- Library ----
@@ -22,10 +24,7 @@ target_include_directories(
2224
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
2325
)
2426

25-
target_link_libraries(${MODULE_NAME} PUBLIC O2QualityControl ROOT::Core ROOT::Hist)
26-
27-
#get_target_property(O2_INCLUDE_DIRS O2::CommonDataFormat INTERFACE_INCLUDE_DIRECTORIES)
28-
#get_target_property(ROOT_INCLUDE_DIRS ROOT::Core ROOT::Hist INTERFACE_INCLUDE_DIRECTORIES)
27+
target_link_libraries(${MODULE_NAME} PUBLIC O2QualityControl ROOT::Core ROOT::Hist O2::CommonDataFormat O2::DataFormatsFIT O2QcCommon)
2928

3029
set(CMAKE_REQUIRED_INCLUDES ${O2_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS})
3130

@@ -35,26 +34,3 @@ install(
3534
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
3635
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
3736
)
38-
39-
# ---- ROOT dictionary ----
40-
41-
#add_root_dictionary(${MODULE_NAME}
42-
# HEADERS include/FITCommon/BaseDigitQcTask.h
43-
# include/MUONCommon/MergeableTH2Ratio.h
44-
# LINKDEF include/FITCommon/LinkDef.h)
45-
46-
# ---- Tests ----
47-
48-
set(
49-
TEST_SRCS
50-
)
51-
52-
foreach(test ${TEST_SRCS})
53-
get_filename_component(test_name ${test} NAME)
54-
string(REGEX REPLACE ".cxx" "" test_name ${test_name})
55-
56-
add_executable(${test_name} ${test})
57-
target_link_libraries(${test_name} PRIVATE ${MODULE_NAME} Boost::unit_test_framework)
58-
add_test(NAME ${test_name} COMMAND ${test_name})
59-
set_tests_properties(${test_name} PROPERTIES TIMEOUT 60)
60-
endforeach()
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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 DigitSync.h
14+
/// \author Artur Furs afurs@cern.ch
15+
/// \brief Class for synchronization of FIT detector digits
16+
17+
#ifndef QC_MODULE_FIT_DIGITSYNC_H
18+
#define QC_MODULE_FIT_DIGITSYNC_H
19+
20+
#include <map>
21+
#include <string>
22+
#include <utility>
23+
#include <unordered_map>
24+
#include <type_traits>
25+
#include <functional>
26+
#include <bitset>
27+
#include <array>
28+
29+
#include "CommonDataFormat/InteractionRecord.h"
30+
31+
namespace o2::quality_control_modules::fit
32+
{
33+
34+
template <typename DigitFDDtype, typename DigitFT0type, typename DigitFV0type>
35+
struct DigitSync {
36+
public:
37+
typedef DigitFDDtype DigitFDD;
38+
typedef DigitFT0type DigitFT0;
39+
typedef DigitFV0type DigitFV0;
40+
using Index_t = uint32_t;
41+
typedef std::map<o2::InteractionRecord, DigitSync> MapIR2Digits_t;
42+
enum EDetectorBit { kFDD,
43+
kFT0,
44+
kFV0
45+
};
46+
constexpr static std::size_t sNdetectors = 3;
47+
std::bitset<sNdetectors> mActiveDets;
48+
std::array<Index_t, sNdetectors> mDigitIndexes{};
49+
template <typename DigitType>
50+
static auto getIR(DigitType&& digit) -> std::enable_if_t<std::is_member_function_pointer_v<decltype(&std::decay_t<decltype(digit)>::getInteractionRecord)>, o2::InteractionRecord>
51+
{
52+
return (std::forward<DigitType>(digit)).getInteractionRecord();
53+
}
54+
55+
template <typename DigitType>
56+
static auto getIR(DigitType&& digit) -> std::enable_if_t<std::is_member_function_pointer_v<decltype(&std::decay_t<decltype(digit)>::getIntRecord)>, o2::InteractionRecord>
57+
{
58+
return (std::forward<DigitType>(digit)).getIntRecord();
59+
}
60+
61+
template <typename ContType>
62+
static void fillSyncMap(MapIR2Digits_t& mapIR2Digits, const ContType& vecDigits)
63+
{
64+
uint32_t index{ 0 };
65+
using DigitType = typename ContType::value_type; // span or vector
66+
for (const auto& digit : vecDigits) {
67+
const auto ir = getIR(digit);
68+
auto pairInserted = mapIR2Digits.insert({ ir, {} });
69+
if constexpr (std::is_same<DigitFDD, DigitType>::value) {
70+
pairInserted.first->second.mActiveDets.set(EDetectorBit::kFDD);
71+
pairInserted.first->second.mDigitIndexes[EDetectorBit::kFDD] = index;
72+
} else if (std::is_same<DigitFT0, DigitType>::value) {
73+
pairInserted.first->second.mActiveDets.set(EDetectorBit::kFT0);
74+
pairInserted.first->second.mDigitIndexes[EDetectorBit::kFT0] = index;
75+
} else if (std::is_same<DigitFV0, DigitType>::value) {
76+
pairInserted.first->second.mActiveDets.set(EDetectorBit::kFV0);
77+
pairInserted.first->second.mDigitIndexes[EDetectorBit::kFV0] = index;
78+
} else {
79+
constexpr bool breakCompilation = true;
80+
static_assert(breakCompilation == true, "Unrecognized digit type!");
81+
}
82+
index++;
83+
}
84+
}
85+
template <typename DigitFDDcont, typename DigitFT0cont, typename DigitFV0cont>
86+
static MapIR2Digits_t makeSyncMap(const DigitFDDcont& vecDigitsFDD,
87+
const DigitFT0cont& vecDigitsFT0,
88+
const DigitFV0cont& vecDigitsFV0)
89+
{
90+
MapIR2Digits_t mapIR2Digits{};
91+
fillSyncMap(mapIR2Digits, vecDigitsFDD);
92+
fillSyncMap(mapIR2Digits, vecDigitsFT0);
93+
fillSyncMap(mapIR2Digits, vecDigitsFV0);
94+
return mapIR2Digits;
95+
}
96+
Index_t getIndexFDD() const { return mDigitIndexes[EDetectorBit::kFDD]; }
97+
Index_t getIndexFT0() const { return mDigitIndexes[EDetectorBit::kFT0]; }
98+
Index_t getIndexFV0() const { return mDigitIndexes[EDetectorBit::kFV0]; }
99+
100+
bool isFDD() const { return mActiveDets.test(EDetectorBit::kFDD); }
101+
bool isFT0() const { return mActiveDets.test(EDetectorBit::kFT0); }
102+
bool isFV0() const { return mActiveDets.test(EDetectorBit::kFV0); }
103+
104+
template <typename VecDigitsFDDtype>
105+
const DigitFDD& getDigitFDD(const VecDigitsFDDtype& vecDigitsFDD) const
106+
{
107+
return isFDD() ? vecDigitsFDD[getIndexFDD()] : sDummyDigitFDD;
108+
}
109+
template <typename VecDigitsFT0type>
110+
const DigitFT0& getDigitFT0(const VecDigitsFT0type& vecDigitsFT0) const
111+
{
112+
return isFT0() ? vecDigitsFT0[getIndexFT0()] : sDummyDigitFT0;
113+
}
114+
template <typename VecDigitsFV0type>
115+
const DigitFV0& getDigitFV0(const VecDigitsFV0type& vecDigitsFV0) const
116+
{
117+
return isFV0() ? vecDigitsFV0[getIndexFV0()] : sDummyDigitFV0;
118+
}
119+
120+
private:
121+
static const DigitFDD sDummyDigitFDD;
122+
static const DigitFT0 sDummyDigitFT0;
123+
static const DigitFV0 sDummyDigitFV0;
124+
};
125+
template <typename DigitFDDtype, typename DigitFT0type, typename DigitFV0type>
126+
const typename DigitSync<DigitFDDtype, DigitFT0type, DigitFV0type>::DigitFDD
127+
DigitSync<DigitFDDtype, DigitFT0type, DigitFV0type>::sDummyDigitFDD = typename DigitSync<DigitFDDtype, DigitFT0type, DigitFV0type>::DigitFDD{};
128+
129+
template <typename DigitFDDtype, typename DigitFT0type, typename DigitFV0type>
130+
const typename DigitSync<DigitFDDtype, DigitFT0type, DigitFV0type>::DigitFT0
131+
DigitSync<DigitFDDtype, DigitFT0type, DigitFV0type>::sDummyDigitFT0 = typename DigitSync<DigitFDDtype, DigitFT0type, DigitFV0type>::DigitFT0{};
132+
133+
template <typename DigitFDDtype, typename DigitFT0type, typename DigitFV0type>
134+
const typename DigitSync<DigitFDDtype, DigitFT0type, DigitFV0type>::DigitFV0
135+
DigitSync<DigitFDDtype, DigitFT0type, DigitFV0type>::sDummyDigitFV0 = typename DigitSync<DigitFDDtype, DigitFT0type, DigitFV0type>::DigitFV0{};
136+
137+
} // namespace o2::quality_control_modules::fit
138+
#endif

Modules/FIT/Common/include/FITCommon/HelperFIT.h

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#include <utility>
2323
#include <unordered_map>
2424
#include <functional>
25+
#include <array>
26+
#include <vector>
27+
#include <DataFormatsFIT/Triggers.h>
28+
2529
namespace o2::quality_control_modules::fit
2630
{
2731

@@ -43,24 +47,33 @@ class HelperFIT
4347
{ ChannelData_t::kIsEventInTVDC, "IsEventInTVDC" },
4448
{ ChannelData_t::kIsTimeInfoLost, "IsTimeInfoLost" }
4549
};
46-
const std::map<unsigned int, std::string> mMapTrgBits = {
47-
{ Triggers_t::bitA, "OrA" },
48-
{ Triggers_t::bitC, "OrC" },
49-
{ Triggers_t::bitVertex, "Vertex" },
50-
{ Triggers_t::bitCen, "Central" },
51-
{ Triggers_t::bitSCen, "SemiCentral" },
52-
{ Triggers_t::bitLaser, "Laser" },
53-
{ Triggers_t::bitOutputsAreBlocked, "OutputsAreBlocked" },
54-
{ Triggers_t::bitDataIsValid, "DataIsValid" }
55-
};
56-
const std::map<unsigned int, std::string> mMapBasicTrgBits = {
57-
{ Triggers_t::bitA, "OrA" },
58-
{ Triggers_t::bitC, "OrC" },
59-
{ Triggers_t::bitVertex, "Vertex" },
60-
{ Triggers_t::bitCen, "Central" },
61-
{ Triggers_t::bitSCen, "SemiCentral" }
62-
};
6350
};
51+
52+
class HelperTrgFIT
53+
{
54+
public:
55+
HelperTrgFIT() = delete;
56+
~HelperTrgFIT() = delete;
57+
static const std::map<unsigned int, std::string> sMapTrgBits;
58+
static const std::map<unsigned int, std::string> sMapBasicTrgBitsFDD;
59+
static const std::map<unsigned int, std::string> sMapBasicTrgBitsFT0;
60+
static const std::map<unsigned int, std::string> sMapBasicTrgBitsFV0;
61+
static const std::array<std::vector<uint8_t>, 256> sArrDecomposed1Byte;
62+
inline static std::array<std::vector<uint8_t>, 256> decompose1Byte()
63+
{
64+
std::array<std::vector<uint8_t>, 256> arrBitPos{};
65+
for (int iByteValue = 0; iByteValue < arrBitPos.size(); iByteValue++) {
66+
auto& vec = arrBitPos[iByteValue];
67+
for (int iBit = 0; iBit < 8; iBit++) {
68+
if (iByteValue & (1 << iBit)) {
69+
vec.push_back(iBit);
70+
}
71+
}
72+
}
73+
return arrBitPos;
74+
}
75+
};
76+
6477
template <typename DigitType>
6578
struct DataTCM {
6679
using Digit_t = DigitType;
@@ -202,4 +215,4 @@ class TrgValidation
202215
};
203216

204217
} // namespace o2::quality_control_modules::fit
205-
#endif
218+
#endif

Modules/FIT/Common/include/FITCommon/HelperHist.h

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace helper
3737

3838
// Preparation for map axis -> map with bin labels
3939
template <std::size_t NStep, std::size_t NArgLocal, std::size_t NAxis, typename TupleArgs>
40-
void getMapBinLabelsPerAxis(std::map<unsigned int, std::map<unsigned int, std::string>>& mapAxisToMapBinLabels, const TupleArgs& tupleArgs)
40+
inline void getMapBinLabelsPerAxis(std::map<unsigned int, std::map<unsigned int, std::string>>& mapAxisToMapBinLabels, const TupleArgs& tupleArgs)
4141
{
4242
if constexpr (NStep < std::tuple_size_v<TupleArgs>) {
4343
using ElementType = typename std::tuple_element<NStep, TupleArgs>::type;
@@ -59,7 +59,7 @@ void getMapBinLabelsPerAxis(std::map<unsigned int, std::map<unsigned int, std::s
5959

6060
// For unpacking std::map<unsigned int, std::string> into tuple of bin parameters
6161
template <typename Arg>
62-
auto unpackHistArg(const Arg& arg)
62+
inline auto unpackHistArg(const Arg& arg)
6363
{
6464
if constexpr (std::is_same_v<std::decay_t<Arg>, std::map<unsigned int, std::string>>) {
6565
return std::make_tuple(static_cast<int>(arg.size()), float(0.0), static_cast<float>(arg.size()));
@@ -74,7 +74,7 @@ auto unpackHistArg(const Arg& arg)
7474
// auto h2 = makeHist<TH1F>("hist2","hist2",map1)
7575

7676
template <typename HistType, typename... BinArgs>
77-
auto makeHist(const std::string& name, const std::string& title, BinArgs&&... binArgs)
77+
inline auto makeHist(const std::string& name, const std::string& title, BinArgs&&... binArgs)
7878
{
7979

8080
const auto tupleArgs = std::tuple_cat(std::make_tuple(name, title), unpackHistArg(std::forward<BinArgs>(binArgs))...);
@@ -109,7 +109,7 @@ auto makeHist(const std::string& name, const std::string& title, BinArgs&&... bi
109109
}
110110

111111
template <typename HistType, typename ManagerType, typename... BinArgs>
112-
auto registerHist(ManagerType manager, const std::string& defaultDrawOption, const std::string& name, const std::string& title, BinArgs&&... binArgs)
112+
inline auto registerHist(ManagerType manager, const std::string& defaultDrawOption, const std::string& name, const std::string& title, BinArgs&&... binArgs)
113113
{
114114
auto ptrHist = makeHist<HistType>(name, title, std::forward<BinArgs>(binArgs)...);
115115
manager->startPublishing(ptrHist.get());
@@ -120,7 +120,7 @@ auto registerHist(ManagerType manager, const std::string& defaultDrawOption, con
120120
}
121121

122122
template <typename ValueType>
123-
ValueType getConfigFromPropertyTree(const boost::property_tree::ptree& config, const char* fieldName, ValueType value = {})
123+
inline ValueType getConfigFromPropertyTree(const boost::property_tree::ptree& config, const char* fieldName, ValueType value = {})
124124
{
125125
const auto& node = config.get_child_optional(fieldName);
126126
if (node) {
@@ -134,7 +134,7 @@ ValueType getConfigFromPropertyTree(const boost::property_tree::ptree& config, c
134134

135135
// first entry - start BC, second - number of BCs in row
136136
template <typename BitSetBC>
137-
std::vector<std::pair<int, int>> getMapBCtrains(const BitSetBC& bitsetBC)
137+
inline std::vector<std::pair<int, int>> getMapBCtrains(const BitSetBC& bitsetBC)
138138
{
139139
std::vector<std::pair<int, int>> vecTrains{};
140140
int nBCs{ 0 };
@@ -160,6 +160,49 @@ std::vector<std::pair<int, int>> getMapBCtrains(const BitSetBC& bitsetBC)
160160
return vecTrains;
161161
}
162162

163+
inline std::map<unsigned int, std::string> multiplyMaps(const std::vector<std::tuple<std::string, std::map<unsigned int, std::string>, std::string>>& vecPreffixMapSuffix, bool useMapSizeAsMultFactor = true)
164+
{
165+
166+
auto multiplyPairMaps = [](bool useMapSizeAsMultFactor, const std::tuple<std::string, std::map<unsigned int, std::string>, std::string>& firstPreffixMapSuffix,
167+
const std::tuple<std::string, std::map<unsigned int, std::string>, std::string>& secondPreffixMapSuffix = {}) -> std::map<unsigned int, std::string> {
168+
std::map<unsigned int, std::string> mapResult{};
169+
const auto& firstPreffix = std::get<0>(firstPreffixMapSuffix);
170+
const auto& firstSuffix = std::get<2>(firstPreffixMapSuffix);
171+
const auto& firstMap = std::get<1>(firstPreffixMapSuffix);
172+
173+
const auto& secondPreffix = std::get<0>(secondPreffixMapSuffix);
174+
const auto& secondSuffix = std::get<2>(secondPreffixMapSuffix);
175+
const auto& secondMap = std::get<1>(secondPreffixMapSuffix);
176+
177+
const unsigned int lastPosSecondMap = secondMap.size() > 0 ? (--secondMap.end())->first : 0;
178+
const unsigned int multFactor = (useMapSizeAsMultFactor && secondMap.size() > 0) ? secondMap.size() : lastPosSecondMap + 1;
179+
180+
for (const auto& entryFirst : firstMap) {
181+
const std::string newEntrySecond_preffix = firstPreffix + entryFirst.second + firstSuffix;
182+
const unsigned int startIndex = entryFirst.first * multFactor;
183+
for (const auto& entrySecond : secondMap) {
184+
const std::string newEntrySecond = newEntrySecond_preffix + secondPreffix + entrySecond.second + secondSuffix;
185+
const unsigned int newEntryFirst = startIndex + entrySecond.first;
186+
mapResult.insert({ newEntryFirst, newEntrySecond });
187+
}
188+
if (secondMap.size() == 0) {
189+
// Only add preffix and suffix
190+
mapResult.insert({ startIndex, newEntrySecond_preffix });
191+
}
192+
}
193+
return mapResult;
194+
};
195+
std::map<unsigned int, std::string> mapResult{};
196+
if (vecPreffixMapSuffix.size() > 0) {
197+
mapResult = multiplyPairMaps(useMapSizeAsMultFactor, vecPreffixMapSuffix[0]);
198+
for (int iEntry = 1; iEntry < vecPreffixMapSuffix.size(); iEntry++) {
199+
const std::string s1{ "" }, s2{ "" };
200+
mapResult = multiplyPairMaps(useMapSizeAsMultFactor, std::tie(s1, mapResult, s2), vecPreffixMapSuffix[iEntry]);
201+
}
202+
}
203+
return mapResult;
204+
}
205+
163206
} // namespace helper
164207
} // namespace o2::quality_control_modules::fit
165208
#endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 DigitSync.cxx
14+
/// \author Artur Furs afurs@cern.ch
15+
16+
#include "FITCommon/DigitSync.h"

0 commit comments

Comments
 (0)