12#ifndef O2_MCH_RAW_ELECMAP_ELECTRONIC_MAPPER_IMPL_HELPER_H
13#define O2_MCH_RAW_ELECMAP_ELECTRONIC_MAPPER_IMPL_HELPER_H
22#include <fmt/format.h>
36 auto it = elec2det.find(
encode(
id));
37 if (it == elec2det.end()) {
49 auto it = det2elec.find(
encode(
id));
50 if (it == det2elec.end()) {
58std::function<std::optional<FeeLinkId>(uint16_t)>
61 return [solar2cruLink](uint16_t solarId) -> std::optional<FeeLinkId> {
62 auto it = solar2cruLink.find(solarId);
63 if (it == solar2cruLink.end()) {
71std::function<std::optional<uint16_t>(
FeeLinkId)>
75 auto it = cruLink2solar.find(
encode(
id));
76 if (it == cruLink2solar.end()) {
83template <
typename KEY,
typename VALUE>
86 std::map<VALUE, KEY> dest;
88 dest.emplace(p.second, p.first);
96 static auto d2e = o2::mch::raw::createDet2ElecMapper<T>();
97 std::set<uint16_t> solarsForDE;
99 for (
auto dsid :
dslist(deid)) {
100 DsDetId id{
static_cast<uint16_t
>(deid),
static_cast<uint16_t
>(dsid)};
102 if (dsel.has_value()) {
103 solarsForDE.insert(dsel->solarId());
112 std::set<uint16_t> solarUIDs;
115 std::set<uint16_t> solarsForDE = getSolarUIDs<T>(deid);
116 for (
auto s : solarsForDE) {
126 std::set<uint16_t> solars;
127 static auto feeLink2Solar = createFeeLink2SolarMapper<T>();
128 for (uint8_t link = 0; link < 12; link++) {
129 auto solar = feeLink2Solar(
FeeLinkId{feeid, link});
130 if (solar.has_value()) {
131 solars.insert(solar.value());
140 auto solarIds = getSolarUIDsPerFeeId<T>(feeId);
142 std::set<DsDetId> allDualSampas;
143 for (
auto solarId : solarIds) {
144 auto solarDualSampas = getDualSampas<T>(solarId);
145 allDualSampas.insert(solarDualSampas.begin(), solarDualSampas.end());
147 return allDualSampas;
153 std::vector<std::string> errors;
156 std::set<uint16_t> solarIds = getSolarUIDs<T>();
157 static auto solar2feeLink = createSolar2FeeLinkMapper<T>();
158 std::vector<o2::mch::raw::FeeLinkId> feeLinkIds;
159 for (
auto s : solarIds) {
160 auto p = solar2feeLink(s);
161 if (!p.has_value()) {
162 errors.push_back(fmt::format(
"Got no feelinkId for solarId {}", s));
164 feeLinkIds.push_back(p.value());
169 auto feeLinkId2SolarId = createFeeLink2SolarMapper<T>();
170 for (
auto f : feeLinkIds) {
171 auto p = feeLinkId2SolarId(
f);
172 if (!p.has_value()) {
173 errors.push_back(fmt::format(
"Got no solarId for FeeLinkId {}",
asString(
f)));
182 std::set<DsElecId> dsElecIds;
185 static auto det2ElecMapper = createDet2ElecMapper<T>();
188 for (
auto dsId :
dslist(deId)) {
189 auto dsElecId = det2ElecMapper(
DsDetId{deId, dsId});
190 if (dsElecId.has_value()) {
191 dsElecIds.insert(dsElecId.value());
202 std::set<DsDetId> dualSampas;
204 static auto elec2det = o2::mch::raw::createElec2DetMapper<T>();
208 auto dsDetId = elec2det(dsElecId);
209 if (dsDetId.has_value()) {
210 dualSampas.insert(dsDetId.value());
220 std::set<uint16_t> solarIds = raw::getSolarUIDs<T>();
221 std::map<uint16_t, uint16_t>
m;
223 for (
const auto& solarId : solarIds) {
233 static std::map<uint16_t, uint16_t> ix2id = generateSolarIndex2IdMap<T>();
234 auto it = ix2id.find(solarIndex);
235 if (it == ix2id.end()) {
244 static std::map<uint16_t, uint16_t> id2ix =
246 auto it = id2ix.find(solarId);
247 if (it == id2ix.end()) {
A DsDetId is just a pair (detection element id, dual sampa id)
std::function< std::set< int >(int deId)> createDualSampaMapper()
std::array< int, 156 > deIdsForAllMCH
std::set< DsDetId > getDualSampasPerFeeId(uint16_t feeId)
std::function< std::optional< o2::mch::raw::DsDetId >(o2::mch::raw::DsElecId)> mapperElec2Det(const std::map< uint32_t, uint32_t > &elec2det)
std::function< std::optional< FeeLinkId >(uint16_t)> mapperSolar2FeeLink(const std::map< uint16_t, uint32_t > &solar2cruLink)
std::function< std::optional< o2::mch::raw::DsElecId >(o2::mch::raw::DsDetId)> mapperDet2Elec(const std::map< uint32_t, uint32_t > &det2elec)
std::optional< uint16_t > solarIndex2Id(uint16_t solarIndex)
std::set< DsElecId > getAllDs()
std::set< uint16_t > getSolarUIDsPerFeeId(uint16_t feeid)
std::vector< std::string > solar2FeeLinkConsistencyCheck()
std::set< uint16_t > getSolarUIDs()
std::set< DsDetId > getDualSampas(uint16_t solarId)
std::optional< uint16_t > solarId2Index(uint16_t solarId)
std::map< uint16_t, uint16_t > generateSolarIndex2IdMap()
std::map< VALUE, KEY > inverseMap(const std::map< KEY, VALUE > &src)
std::function< std::optional< uint16_t >(FeeLinkId)> mapperFeeLink2Solar(const std::map< uint32_t, uint16_t > &cruLink2solar)
FeeLinkId decodeFeeLinkId(uint32_t code)
std::string asString(const SampaCluster &sc)
std::optional< DsElecId > decodeDsElecId(uint32_t code)
DsDetId decodeDsDetId(uint32_t code)
Create a DsDetId object from a integer code.
uint32_t encode(const DsDetId &id)
Create an integer code for the given id.