Skip to content

Commit c705a6f

Browse files
afursAllaMaevskaya
andauthored
FIT: Large opitmisation(RawReader) and type checking(DataBlockWrapper) for FITRaw, 'expired message' mechanism for FT0 DPL workflow (#5858)
* FT0 LUT prepared as Singleton for DigitBlockFT0 usage * Large optimization for RawReader in FITRaw library * Use 'expired messages' mechanism for FT0 raw data decoder (taken from ITS/MFT) * Mechanism for type checking in DataBlockWrapper, within FITRaw lib * new LUT * Test executable for FT0(raw2digit) Test executable for FT0(raw2digit) * Hotfix for newLUT branch Hotfix for newLUT branch * Hotfix(braces added) Hotfix(braces added) Hotfix(braces added) Hotfix(braces added) Co-authored-by: Alla Maevskaya <Alla.Maevskaya@cern.ch>
1 parent 3555308 commit c705a6f

File tree

25 files changed

+711
-170
lines changed

25 files changed

+711
-170
lines changed

DataFormats/Detectors/FIT/FDD/include/DataFormatsFDD/RawEventData.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace fdd
3232
struct EventHeader {
3333
static constexpr size_t PayloadSize = 16; //should be equal to 10
3434
static constexpr size_t PayloadPerGBTword = 16; //should be equal to 10
35-
static constexpr int MinNelements = 1;
36-
static constexpr int MaxNelements = 1;
35+
static constexpr size_t MinNelements = 1;
36+
static constexpr size_t MaxNelements = 1;
3737
union {
3838
uint64_t word[2] = {};
3939
struct {
@@ -55,8 +55,8 @@ struct EventHeader {
5555
struct EventData {
5656
static constexpr size_t PayloadSize = 5;
5757
static constexpr size_t PayloadPerGBTword = 10;
58-
static constexpr int MinNelements = 1; //additional static field
59-
static constexpr int MaxNelements = 12;
58+
static constexpr size_t MinNelements = 1; //additional static field
59+
static constexpr size_t MaxNelements = 12;
6060
//
6161
static constexpr int BitFlagPos = 25; // position of first bit flag(numberADC)
6262

@@ -103,8 +103,8 @@ struct EventData {
103103
struct TCMdata {
104104
static constexpr size_t PayloadSize = 16; //should be equal to 10
105105
static constexpr size_t PayloadPerGBTword = 16; //should be equal to 10
106-
static constexpr int MinNelements = 1;
107-
static constexpr int MaxNelements = 1;
106+
static constexpr size_t MinNelements = 1;
107+
static constexpr size_t MaxNelements = 1;
108108
union {
109109
uint64_t word[2] = {0};
110110
struct {

DataFormats/Detectors/FIT/FT0/include/DataFormatsFT0/LookUpTable.h

Lines changed: 70 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <map>
3434
#include <string_view>
3535
#include <vector>
36+
#include <cstdlib>
3637

3738
namespace o2
3839
{
@@ -41,7 +42,8 @@ namespace ft0
4142
struct Topo {
4243
int mPM = 0;
4344
int mMCP = 0;
44-
ClassDefNV(Topo, 1);
45+
int mEP = 0;
46+
ClassDefNV(Topo, 2);
4547
};
4648

4749
// enum class Side : char { A, C };
@@ -51,39 +53,55 @@ struct Topo {
5153
// };
5254

5355
struct HVchannel {
54-
enum class HVBoard : uint8_t { NA,
56+
/* enum class HVBoard : uint8_t { NA,
5557
A_out,
5658
A_in,
5759
C_up,
5860
C_down,
59-
C_mid };
61+
C_mid };*/
62+
6063
uint8_t channel;
6164
Topo pm;
62-
HVBoard HV_board;
65+
std::string HV_board;
6366
uint8_t HV_channel;
6467
std::string MCP_SN;
6568
std::string HV_cabel;
6669
std::string signal_cable;
70+
std::string EP;
6771

68-
ClassDefNV(HVchannel, 1);
72+
ClassDefNV(HVchannel, 2);
6973
};
7074

7175
inline bool operator<(Topo const& a, Topo const& b)
7276
{
73-
return (a.mPM < b.mPM || (a.mPM == b.mPM && a.mMCP < b.mMCP));
77+
/* return (a.mPM < b.mPM || (a.mPM == b.mPM && a.mMCP < b.mMCP)); */
78+
auto t = [](Topo const& x) -> decltype(auto) { return std::tie(x.mPM, x.mMCP, x.mEP); };
79+
return t(a) < t(b);
7480
}
7581

7682
inline o2::ft0::Topo read_Topo(std::string_view str)
7783
{
78-
assert(str.substr(0, 2) == "PM" && str[4] == '/' && str[5] == 'C' && str[6] == 'h');
84+
assert(str.substr(0, 2) == "PM"); // && str[4] == '/' && str[5] == 'C' && str[6] == 'h');
7985
char side = str[2];
80-
uint8_t pm_num = str[3] - '0';
81-
uint8_t pm_ch = (str[7] - '0') * 10 + (str[8] - '0') - 1;
82-
assert(side == 'A' || side == 'C');
83-
if (str.substr(0, 4) == "PMA9") {
84-
pm_num = 18;
86+
char* ptr;
87+
uint8_t pm_num = std::strtol(str.data() + 3, &ptr, 10); // = str[3] - '0';
88+
/* auto res = std::from_chars(str.data()+3, str.data()+3+str.size(), pm_num); */
89+
/* if (res.ec != std::errc() || res.ptr[0] != '/') */
90+
if (errno || ptr[0] != '/') {
91+
throw std::invalid_argument("Cannot read pm_num");
92+
}
93+
if (ptr[1] != 'C' || ptr[2] != 'h') {
94+
throw std::invalid_argument("Expected 'Ch'");
95+
}
96+
uint8_t pm_ch = std::strtol(ptr + 3, &ptr, 10);
97+
// = (str[7] - '0') * 10 + (str[8] - '0') - 1;
98+
/* res = std::from_chars(res.ptr+3, res.ptr+3+str.size(), pm_ch); */
99+
uint8_t ep = side == 'C' ? 1 : 0;
100+
if (errno) {
101+
throw std::invalid_argument("Cannot read pm_ch");
85102
}
86-
return Topo{(side == 'C' ? 8 : 0) + pm_num, pm_ch};
103+
assert(side == 'A' || side == 'C');
104+
return Topo{pm_num, pm_ch, ep};
87105
}
88106

89107
class LookUpTable
@@ -92,6 +110,7 @@ class LookUpTable
92110
using CcdbApi = o2::ccdb::CcdbApi;
93111
static constexpr int NUMBER_OF_MCPs = 12;
94112
static constexpr int NUMBER_OF_PMs = 19;
113+
static constexpr int TCM_channel = 228;
95114

96115
public:
97116
///
@@ -101,33 +120,32 @@ class LookUpTable
101120
// LookUpTable() = default;
102121

103122
explicit LookUpTable(std::vector<Topo> const& topoVector)
104-
: mTopoVector(topoVector), mInvTopo(topoVector.size())
123+
: mTopoVector(topoVector), mInvTopo(NUMBER_OF_MCPs * 16 * 2)
105124
{
106125
for (size_t channel = 0; channel < mTopoVector.size(); ++channel) {
107-
mInvTopo.at(getIdx(mTopoVector[channel].mPM, mTopoVector[channel].mMCP)) =
126+
mInvTopo.at(getIdx(mTopoVector[channel].mPM, mTopoVector[channel].mMCP, mTopoVector[channel].mEP)) =
108127
channel;
109128
}
110129
}
111130
LookUpTable() = default;
112131
~LookUpTable() = default;
113132

114-
HVchannel mHVchannel;
133+
int getTCMchannel() const
134+
{
135+
return TCM_channel;
136+
}
115137

116138
void printFullMap() const
117139
{
118140
for (size_t channel = 0; channel < mTopoVector.size(); ++channel) {
119141
std::cout << channel << "\t : PM \t" << mTopoVector[channel].mPM
120-
<< " MCP \t" << mTopoVector[channel].mMCP << std::endl;
121-
}
122-
for (size_t idx = 0; idx < mInvTopo.size(); ++idx) {
123-
std::cout << "PM \t" << getLinkFromIdx(mInvTopo[idx]) << " MCP \t"
124-
<< getMCPFromIdx(mInvTopo[idx]) << std::endl;
142+
<< " MCP \t" << mTopoVector[channel].mMCP << " EP \t " << mTopoVector[channel].mEP << std::endl;
125143
}
126144
}
127145

128-
int getChannel(int link, int mcp) const
146+
int getChannel(int link, int mcp, int ep) const
129147
{
130-
return mInvTopo[getIdx(link, mcp)];
148+
return mInvTopo[getIdx(link, mcp, ep)];
131149
}
132150

133151
int getLink(int channel) const
@@ -138,6 +156,10 @@ class LookUpTable
138156
{
139157
return mTopoVector[channel].mMCP;
140158
}
159+
int getEP(int channel) const
160+
{
161+
return mTopoVector[channel].mEP;
162+
}
141163

142164
static o2::ft0::LookUpTable linear()
143165
{
@@ -174,7 +196,8 @@ class LookUpTable
174196
int channel;
175197
std::string pm, pm_channel, hv_board, hv_channel, mcp_sn, hv_cable, signal_cable;
176198
std::getline(infile, pm); // skip one line
177-
while (infile >> channel >> pm >> pm_channel >> hv_board >> hv_channel >> mcp_sn >> hv_cable >> signal_cable) {
199+
std::string line;
200+
while (std::getline(infile, line) && std::istringstream(line) >> channel >> pm >> pm_channel >> hv_board >> hv_channel >> mcp_sn >> hv_cable >> signal_cable) {
178201
lut_data[channel] = read_Topo(pm_channel);
179202
}
180203
return o2::ft0::LookUpTable{lut_data};
@@ -197,20 +220,39 @@ class LookUpTable
197220
o2::ft0::Topo topo = chan.pm;
198221
lut_data[chan.channel] = topo;
199222
}
223+
std::cout << "lut_data.size " << lut_data.size() << std::endl;
200224
return o2::ft0::LookUpTable{lut_data};
201225
}
202226

203227
private:
204228
std::vector<Topo> mTopoVector;
205229
std::vector<int> mInvTopo;
206230

207-
static int getIdx(int link, int mcp)
231+
static int getIdx(int link, int mcp, int ep)
208232
{
209233
assert(mcp < NUMBER_OF_MCPs);
210-
return link * NUMBER_OF_MCPs + mcp;
234+
return (link + ep * 16) * NUMBER_OF_MCPs + mcp;
235+
}
236+
static int getLinkFromIdx(int idx)
237+
{
238+
int link;
239+
if (idx > 95) {
240+
link = (idx - 96) / NUMBER_OF_MCPs;
241+
} else {
242+
link = idx / NUMBER_OF_MCPs;
243+
}
244+
return link;
245+
}
246+
static int getEPFromIdx(int idx)
247+
{
248+
if (idx < 96 || idx > 215) {
249+
return 0;
250+
} else {
251+
return 1;
252+
}
211253
}
212-
static int getLinkFromIdx(int idx) { return idx / NUMBER_OF_MCPs; }
213-
static int getMCPFromIdx(int idx) { return idx % NUMBER_OF_MCPs; }
254+
255+
static int getMCPFromIdx(int idx) { return idx % NUMBER_OF_MCPs + 1; }
214256

215257
ClassDefNV(LookUpTable, 2);
216258
};
@@ -222,7 +264,6 @@ class SingleLUT : public LookUpTable
222264
SingleLUT() : LookUpTable(LookUpTable::readTable()) {}
223265
SingleLUT(const SingleLUT&) = delete;
224266
SingleLUT& operator=(SingleLUT&) = delete;
225-
226267
public:
227268
static SingleLUT& Instance()
228269
{

DataFormats/Detectors/FIT/FT0/include/DataFormatsFT0/RawEventData.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ constexpr size_t sizeWord = 16;
3838
struct EventHeader {
3939
static constexpr size_t PayloadSize = 16; //should be equal to 10
4040
static constexpr size_t PayloadPerGBTword = 16; //should be equal to 10
41-
static constexpr int MinNelements = 1;
42-
static constexpr int MaxNelements = 1;
41+
static constexpr size_t MinNelements = 1;
42+
static constexpr size_t MaxNelements = 1;
4343
union {
4444
uint64_t word[2] = {};
4545
struct {
@@ -62,8 +62,8 @@ struct EventHeader {
6262
struct EventData {
6363
static constexpr size_t PayloadSize = 5;
6464
static constexpr size_t PayloadPerGBTword = 10;
65-
static constexpr int MinNelements = 1; //additional static field
66-
static constexpr int MaxNelements = 12;
65+
static constexpr size_t MinNelements = 1; //additional static field
66+
static constexpr size_t MaxNelements = 12;
6767
//
6868
static constexpr int BitFlagPos = 25; // position of first bit flag(numberADC)
6969

@@ -115,8 +115,8 @@ struct EventData {
115115
struct TCMdata {
116116
static constexpr size_t PayloadSize = 16; //should be equal to 10
117117
static constexpr size_t PayloadPerGBTword = 16; //should be equal to 10
118-
static constexpr int MinNelements = 1;
119-
static constexpr int MaxNelements = 1;
118+
static constexpr size_t MinNelements = 1;
119+
static constexpr size_t MaxNelements = 1;
120120
uint64_t orA : 1, // 0 bit (0 byte)
121121
orC : 1, //1 bit
122122
sCen : 1, //2 bit
@@ -163,8 +163,8 @@ struct TCMdata {
163163
struct TCMdataExtended {
164164
static constexpr size_t PayloadSize = 4;
165165
static constexpr size_t PayloadPerGBTword = 10;
166-
static constexpr int MinNelements = 0;
167-
static constexpr int MaxNelements = 20;
166+
static constexpr size_t MinNelements = 0;
167+
static constexpr size_t MaxNelements = 20;
168168
union {
169169
uint32_t word[1] = {};
170170
uint32_t triggerWord;
@@ -259,6 +259,7 @@ class DataPageWriter
259259
str.write(reinterpret_cast<const char*>(&mRDH), sizeof(mRDH));
260260
str.write(mPages[page].data(), mPages[page].size());
261261
mRDH.pageCnt++;
262+
LOG(INFO) << " header " << mRDH.linkID << " end " << mRDH.endPointID;
262263
}
263264
if (!mPages.empty()) {
264265
mRDH.memorySize = mRDH.headerSize;

DataFormats/Detectors/FIT/FV0/include/DataFormatsFV0/RawEventData.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace o2
2929
namespace fv0
3030
{
3131
struct EventHeader {
32-
static constexpr int PayloadSize = 16;
32+
static constexpr size_t PayloadSize = 16;
3333
union {
3434
uint64_t word[2] = {};
3535
struct {
@@ -82,7 +82,7 @@ struct EventData {
8282
};
8383

8484
struct TCMdata {
85-
static constexpr int PayloadSize = 16;
85+
static constexpr size_t PayloadSize = 16;
8686
union {
8787
uint64_t word[2] = {0};
8888
struct {

Detectors/FIT/FDD/raw/include/FDDRaw/DigitBlockFDD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class DigitBlockFDD : public DigitBlockBase<DigitBlockFDD>
5757
static int sEventID;
5858

5959
template <class DataBlockType>
60-
void processDigits(DataBlockType& dataBlock, int linkID)
60+
void processDigits(DataBlockType& dataBlock, int linkID, int ep)
6161
{
6262
if constexpr (std::is_same<DataBlockType, DataBlockPM>::value) { //Filling data from PM
6363
for (int iEventData = 0; iEventData < dataBlock.DataBlockWrapper<RawDataPM>::mNelements; iEventData++) {

Detectors/FIT/FDD/raw/include/FDDRaw/RawReaderFDDBase.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ namespace fdd
4141

4242
// Common raw reader for FDD
4343
template <class DigitBlockFDDtype, class DataBlockPMtype, class DataBlockTCMtype>
44-
class RawReaderFDDBase : public RawReaderBase<DigitBlockFDDtype>
44+
class RawReaderFDDBase : public RawReaderBase<DigitBlockFDDtype, DataBlockPMtype, DataBlockTCMtype>
4545
{
4646
public:
47-
typedef RawReaderBase<DigitBlockFDDtype> RawReaderBaseType;
47+
typedef RawReaderBase<DigitBlockFDDtype, DataBlockPMtype, DataBlockTCMtype> RawReaderBaseType;
4848
RawReaderFDDBase() = default;
4949
~RawReaderFDDBase() = default;
5050
//deserialize payload to raw data blocks and proccesss them to digits
51-
void process(int linkID, gsl::span<const uint8_t> payload)
51+
void process(int linkID, gsl::span<const uint8_t> payload, int ep)
5252
{
5353
if (0 <= linkID && linkID < 2) {
5454
//PM data proccessing
55-
RawReaderBaseType::template processBinaryData<DataBlockPMtype>(payload, linkID);
55+
RawReaderBaseType::template processBinaryData<DataBlockPMtype>(payload, linkID, 0);
5656
} else if (linkID == 2) {
5757
//TCM data proccessing
58-
RawReaderBaseType::template processBinaryData<DataBlockTCMtype>(payload, linkID);
58+
RawReaderBaseType::template processBinaryData<DataBlockTCMtype>(payload, linkID, 0);
5959
} else {
6060
//put here code in case of bad rdh.linkID value
6161
LOG(INFO) << "WARNING! WRONG LINK ID! " << linkID;

Detectors/FIT/FDD/workflow/include/FDDWorkflow/RawDataReaderSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class RawDataReaderSpec : public Task
5252
count++;
5353
auto rdhPtr = it.get_if<o2::header::RAWDataHeader>();
5454
gsl::span<const uint8_t> payload(it.data(), it.size());
55-
mRawReader.process(rdhPtr->linkID, payload);
55+
mRawReader.process(rdhPtr->linkID, payload, int(0));
5656
}
5757
LOG(INFO) << "Pages: " << count;
5858
mRawReader.accumulateDigits();

0 commit comments

Comments
 (0)