Skip to content

Commit eca32ff

Browse files
dstoccoaphecetche
authored andcommitted
Class to convert MID digits masks into a mask for electronics
1 parent 3c2e713 commit eca32ff

3 files changed

Lines changed: 163 additions & 2 deletions

File tree

Detectors/MUON/MID/Filtering/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
o2_add_library(
1212
MIDFiltering
13-
SOURCES src/ChannelMasksHandler.cxx src/ChannelScalers.cxx src/FetToDead.cxx
14-
src/MaskMaker.cxx
13+
SOURCES src/ChannelMasksHandler.cxx src/ChannelScalers.cxx
14+
src/ColumnDataMaskToROMask.cxx src/FetToDead.cxx src/MaskMaker.cxx
1515
PUBLIC_LINK_LIBRARIES O2::DataFormatsMID O2::MIDBase O2::MIDRaw
1616
Microsoft.GSL::GSL)
1717

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 MIDFiltering/ColumnDataMaskToROMask.h
13+
/// \brief Converts ColumnData masks into local board masks
14+
/// \author Diego Stocco <Diego.Stocco at cern.ch>
15+
/// \date 12 October 2021
16+
#ifndef O2_MID_COLUMNDATAMASKTOROMASK_H
17+
#define O2_MID_COLUMNDATAMASKTOROMASK_H
18+
19+
#include <vector>
20+
#include <gsl/span>
21+
#include "DataFormatsMID/ColumnData.h"
22+
#include "MIDRaw/ColumnDataToLocalBoard.h"
23+
#include "MIDRaw/CrateMapper.h"
24+
25+
namespace o2
26+
{
27+
namespace mid
28+
{
29+
30+
class ColumnDataMaskToROMask
31+
{
32+
public:
33+
ColumnDataMaskToROMask();
34+
~ColumnDataMaskToROMask() = default;
35+
36+
std::vector<ROBoard> convert(gsl::span<const ColumnData> colDataMasks);
37+
void write(gsl::span<const ColumnData> colDataMasks, const char* outFilename);
38+
uint32_t makeConfigWord(const ROBoard& mask) const;
39+
40+
private:
41+
bool needsMask(const ROBoard& mask, bool hasDirectInputY) const;
42+
ColumnDataToLocalBoard mColToBoard; /// ColumnData to local board
43+
CrateMapper mCrateMapper; /// Crate mapper
44+
std::vector<ColumnData> mDefaultMasks; /// Default masks
45+
46+
static constexpr uint32_t sTxDataMask = 0x10000;
47+
static constexpr uint32_t sMonmoff = 0x2;
48+
static constexpr uint32_t sXorY = 0x400;
49+
};
50+
51+
} // namespace mid
52+
} // namespace o2
53+
54+
#endif /* O2_MID_COLUMNDATAMASKTOROMASK_H */
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 MID/Filtering/src/ColumnDataMaskToROMask.cxx
13+
/// \brief Converts ColumnData masks into local board masks
14+
/// \author Diego Stocco <Diego.Stocco at cern.ch>
15+
/// \date 12 October 2021
16+
17+
#include "MIDFiltering/ColumnDataMaskToROMask.h"
18+
19+
#include <fstream>
20+
#include "fmt/format.h"
21+
#include "MIDFiltering/MaskMaker.h"
22+
#include "MIDFiltering/ChannelMasksHandler.h"
23+
24+
namespace o2
25+
{
26+
namespace mid
27+
{
28+
ColumnDataMaskToROMask::ColumnDataMaskToROMask()
29+
{
30+
// Default ctr
31+
mDefaultMasks = makeDefaultMasks();
32+
mColToBoard.setDebugMode(true);
33+
}
34+
35+
bool ColumnDataMaskToROMask::needsMask(const ROBoard& mask, bool hasDirectInputY) const
36+
{
37+
/// Returns true if the local board is masked
38+
if (!hasDirectInputY) {
39+
return true;
40+
}
41+
42+
for (int ich = 0; ich < 4; ++ich) {
43+
if (mask.patternsBP[ich] != 0xFFFF || mask.patternsNBP[ich] != 0xFFFF) {
44+
return true;
45+
}
46+
}
47+
return false;
48+
}
49+
50+
uint32_t ColumnDataMaskToROMask::makeConfigWord(const ROBoard& mask) const
51+
{
52+
/// Computes the configuration word for the local board
53+
auto cfgWord = sTxDataMask;
54+
bool hasDirectInputY = mCrateMapper.hasDirectInputY(mask.boardId);
55+
bool isMasked = needsMask(mask, hasDirectInputY);
56+
if (isMasked) {
57+
cfgWord |= sMonmoff;
58+
}
59+
if (!hasDirectInputY) {
60+
cfgWord |= sXorY;
61+
}
62+
return cfgWord;
63+
}
64+
65+
std::vector<ROBoard> ColumnDataMaskToROMask::convert(gsl::span<const ColumnData> colDataMasks)
66+
{
67+
/// Converts ColumnData masks into local board masks
68+
mColToBoard.process(colDataMasks);
69+
70+
std::vector<ROBoard> roMasks;
71+
for (auto& mapIt : mColToBoard.getData()) {
72+
for (auto& board : mapIt.second) {
73+
roMasks.emplace_back(board);
74+
}
75+
}
76+
return roMasks;
77+
}
78+
79+
void ColumnDataMaskToROMask::write(gsl::span<const ColumnData> colDataMasks, const char* outFilename)
80+
{
81+
/// Writes the mask to file
82+
83+
// FIXME: currently, the masks are written to a file that is then read by WinCC
84+
// In the future, this should be moved to ccdb
85+
86+
auto roMasks = convert(colDataMasks);
87+
88+
// We order the masks for easier reading from humans
89+
std::sort(roMasks.begin(), roMasks.end(), [](const ROBoard& loc1, const ROBoard& loc2) { return loc1.boardId < loc2.boardId; });
90+
91+
std::ofstream outFile(outFilename);
92+
for (auto& mask : roMasks) {
93+
auto cfgWord = makeConfigWord(mask);
94+
outFile << fmt::format("{:02x} {:08x}", mask.boardId, cfgWord);
95+
96+
bool isMasked = cfgWord & sMonmoff;
97+
98+
for (int ich = 0; ich < 4; ++ich) {
99+
uint16_t valBP = isMasked ? mask.patternsBP[ich] : 0;
100+
uint16_t valNBP = (isMasked && (cfgWord & sXorY) == 0) ? mask.patternsNBP[ich] : 0;
101+
outFile << fmt::format(" {:04x}{:04x}", valBP, valNBP);
102+
}
103+
outFile << std::endl;
104+
}
105+
}
106+
} // namespace mid
107+
} // namespace o2

0 commit comments

Comments
 (0)