Skip to content

Commit

Permalink
FIT: some preparations for migration FLP->EPN (#1934)
Browse files Browse the repository at this point in the history
* FIT: some preparations for migration FLP->EPN

* cosmetics
  • Loading branch information
afurs authored Aug 22, 2023
1 parent d23c5b0 commit 4cc0d02
Show file tree
Hide file tree
Showing 23 changed files with 986 additions and 151 deletions.
13 changes: 12 additions & 1 deletion Modules/FIT/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ set(MODULE_NAME "O2QcFITCommon")
set(SRCS
src/HelperFIT.cxx
src/HelperHist.cxx
src/HelperLUT.cxx
src/DigitSync.cxx
)

set(HEADERS
include/FITCommon/HelperCommon.h
include/FITCommon/HelperFIT.h
include/FITCommon/HelperHist.h
include/FITCommon/HelperLUT.h
include/FITCommon/DigitSync.h
)

Expand All @@ -24,7 +27,15 @@ target_include_directories(
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
)

target_link_libraries(${MODULE_NAME} PUBLIC O2QualityControl ROOT::Core ROOT::Hist O2::CommonDataFormat O2::DataFormatsFIT O2QcCommon)
target_link_libraries(${MODULE_NAME} PUBLIC O2QualityControl
ROOT::Core
ROOT::Hist
O2::CommonDataFormat
O2::DataFormatsFIT
O2QcCommon
O2::DataFormatsFDD
O2::DataFormatsFT0
O2::DataFormatsFV0)

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

Expand Down
115 changes: 115 additions & 0 deletions Modules/FIT/Common/include/FITCommon/HelperCommon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file HelperHist.h
/// \author Artur Furs afurs@cern.ch
/// \brief Histogram helper

#ifndef QC_MODULE_FIT_HELPERCOMMON_H
#define QC_MODULE_FIT_HELPERCOMMON_H

#include <map>
#include <vector>
#include <string>
#include <tuple>
#include <utility>
#include <memory>
#include <type_traits>
#include <regex>

#include <boost/property_tree/ptree.hpp>

#include "QualityControl/QcInfoLogger.h"
namespace o2::quality_control_modules::fit
{

namespace helper
{

template <typename ValueType>
inline ValueType getConfigFromPropertyTree(const boost::property_tree::ptree& config, const char* fieldName, ValueType value = {})
{
const auto& node = config.get_child_optional(fieldName);
if (node) {
value = node.get_ptr()->get_child("").get_value<ValueType>();
ILOG(Debug, Support) << fieldName << ": " << value << "\"" << ENDM;
} else {
ILOG(Debug, Support) << "Default " << fieldName << ": " << value << ENDM;
}
return value;
}

template <typename Param_t,
typename = typename std::enable_if<std::is_floating_point<Param_t>::value ||
std::is_same<std::string, Param_t>::value || (std::is_integral<Param_t>::value && !std::is_same<bool, Param_t>::value)>::type>
inline auto parseParameters(const std::string& param, const std::string& del)
{
std::regex reg(del);
std::sregex_token_iterator first{ param.begin(), param.end(), reg, -1 }, last;
std::vector<Param_t> vecResult;
for (auto it = first; it != last; it++) {
if constexpr (std::is_integral<Param_t>::value && !std::is_same<bool, Param_t>::value) {
vecResult.push_back(std::stoi(*it));
} else if constexpr (std::is_floating_point<Param_t>::value) {
vecResult.push_back(std::stod(*it));
} else if constexpr (std::is_same<std::string, Param_t>::value) {
vecResult.push_back(*it);
}
}
return vecResult;
}

// first entry - start BC, second - number of BCs in row
template <typename BitSetBC>
inline std::vector<std::pair<int, int>> getMapBCtrains(const BitSetBC& bitsetBC)
{
std::vector<std::pair<int, int>> vecTrains{};
int nBCs{ 0 };
int firstBC{ -1 };
for (int iBC = 0; iBC < bitsetBC.size(); iBC++) {
if (bitsetBC.test(iBC)) {
// BC in train
nBCs++;
if (firstBC == -1) {
// first BC in train
firstBC = iBC;
}
} else if (nBCs > 0) {
// Next after end of train BC
vecTrains.push_back({ firstBC, nBCs });
firstBC = -1;
nBCs = 0;
}
}
if (nBCs > 0) { // last iteration
vecTrains.push_back({ firstBC, nBCs });
}
return vecTrains;
}

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);

template <typename R, typename... Args, std::size_t... IArgs>
auto funcWithArgsAsTupleBase(std::function<R(Args...)> func, const std::tuple<Args...>& tupleArgs, std::index_sequence<IArgs...>)
{
return func(std::get<IArgs>(tupleArgs)...);
}

template <typename R, typename... Args>
auto funcWithArgsAsTuple(std::function<R(Args...)> func, const std::tuple<Args...>& tupleArgs)
{
return funcWithArgsAsTupleBase(func, tupleArgs, std::make_index_sequence<sizeof...(Args)>{});
}

} // namespace helper
} // namespace o2::quality_control_modules::fit
#endif
76 changes: 76 additions & 0 deletions Modules/FIT/Common/include/FITCommon/HelperFIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@
#define QC_MODULE_FIT_FITHELPER_H

#include <map>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <functional>
#include <array>
#include <vector>
#include <bitset>

#include "TH1D.h"
#include "TH2F.h"

#include <DataFormatsFIT/Triggers.h>
#include "CommonDataFormat/BunchFilling.h"

#include <FITCommon/HelperHist.h>
namespace o2::quality_control_modules::fit
{

Expand Down Expand Up @@ -214,5 +222,73 @@ class TrgValidation
std::function<void(DataTCM_t&)> mFunctorTrgCalc;
};

struct RatioProcessor2D {
RatioProcessor2D() = default;
~RatioProcessor2D() = default;
using SchemaBC_t = o2::BunchFilling::Pattern;
using TF_t = long long;
std::set<int> mBinsCollBC{};
std::set<int> mBinsCollFirstBCinTrain{};
std::set<int> mBinsNonCollBC{};
std::map<int, int> mBinsBCtrains{};

SchemaBC_t mSchemaBC{};
TF_t mNTFs; // processed number of TFs
//
double mLengthTF{}; //
void init()
{
for (const auto& initType : mSetInitTypes) {
(mMapInitFns.find(initType)->second)();
}
}
bool addFnType(const std::string& fnType)
{
if (mMapInitFnNames.find(fnType) == mMapInitFnNames.end()) {
return false;
}
mSetInitTypes.insert(mMapInitFnNames.find(fnType)->second);
}
std::set<std::string> mSetInitTypes{}; // set of projection functors which will participate in calculations
const std::map<std::string, std::function<TH1D*(const TH2F*, std::pair<double, double>, int)>> mMapRatios = {
{ "out_of_coll", [this](const TH2F* histSrc, std::pair<double, double> rangeProj, int axis) {
return helper::makePartialProj(histSrc, "out_of_coll", "out_of_coll", mBinsNonCollBC, rangeProj, axis);
} },
{ "in_coll", [this](const TH2F* histSrc, std::pair<double, double> rangeProj, int axis) {
return helper::makePartialProj(histSrc, "in_coll", "in_coll", mBinsCollBC, rangeProj, axis);
} },

{ "in_coll_norm_train", [this](const TH2F* histSrc, std::pair<double, double> rangeProj, int axis) {
return helper::makePartialProj(histSrc, "in_coll", "in_coll", mBinsCollBC, rangeProj, axis);
} },
{ "proj", [this](const TH2F* histSrc, std::pair<double, double> rangeProj, int axis) {
return helper::makeProj(histSrc, "proj", "proj", rangeProj, axis);
} }
};
const std::map<std::string, std::string> mMapInitFnNames = {
{ "out_of_coll", "bc_schema" },
{ "in_coll", "bc_schema" },
{ "in_coll_norm_train", "bc_schema" },
{ "proj", "none" }
};
std::map<std::string, std::function<void(void)>> mMapInitFns = {
{ "bc_schema", [this]() {
for (int iBC = 0; iBC < mSchemaBC.size(); iBC) {
if (mSchemaBC.test(iBC)) {
mBinsCollBC.insert(iBC + 1);
} else {
mBinsNonCollBC.insert(iBC + 1);
}
}
const auto& mapBCtrains = helper::getMapBCtrains(mSchemaBC);
for (const auto& entry : mapBCtrains) {
mBinsBCtrains.insert({ entry.first + 1, entry.second });
mBinsCollFirstBCinTrain.insert(entry.first + 1);
}
} },
{ "none", [this]() {} }
};
};

} // namespace o2::quality_control_modules::fit
#endif
Loading

0 comments on commit 4cc0d02

Please sign in to comment.