forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_digi2raw_mft.C
More file actions
135 lines (121 loc) · 5.47 KB
/
run_digi2raw_mft.C
File metadata and controls
135 lines (121 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include <TTree.h>
#include <TChain.h>
#include <TFile.h>
#include <TStopwatch.h>
#include <FairLogger.h>
#include <vector>
#include <string>
#include <iomanip>
#include "ITSMFTReconstruction/ChipMappingMFT.h"
#include "ITSMFTReconstruction/GBTWord.h"
#include "ITSMFTReconstruction/PayLoadCont.h"
#include "DataFormatsITSMFT/ROFRecord.h"
#include "DataFormatsITSMFT/Digit.h"
#endif
#include "ITSMFTReconstruction/RawPixelReader.h"
void run_digi2raw_mft(std::string outName = "rawmft.bin", // name of the output binary file
std::string inpName = "mftdigits.root", // name of the input MFT digits
std::string digTreeName = "o2sim", // name of the digits tree
std::string digBranchName = "MFTDigit", // name of the digits branch
std::string rofRecName = "MFTDigitROF", // name of the ROF records branch
uint8_t ruSWMin = 0, uint8_t ruSWMax = 0xff, // seq.ID of 1st and last RU (stave) to convert
uint16_t superPageSize = o2::itsmft::NCRUPagesPerSuperpage // CRU superpage size, max = 256
)
{
TStopwatch swTot;
swTot.Start();
using ROFR = o2::itsmft::ROFRecord;
using ROFRVEC = std::vector<o2::itsmft::ROFRecord>;
///-------> input
TChain digTree(digTreeName.c_str());
digTree.AddFile(inpName.c_str());
std::vector<o2::itsmft::Digit> digiVec, *digiVecP = &digiVec;
if (!digTree.GetBranch(digBranchName.c_str())) {
LOG(FATAL) << "Failed to find the branch " << digBranchName << " in the tree " << digTreeName;
}
digTree.SetBranchAddress(digBranchName.c_str(), &digiVecP);
// ROF record entries in the digit tree
ROFRVEC rofRecVec, *rofRecVecP = &rofRecVec;
if (!digTree.GetBranch(rofRecName.c_str())) {
LOG(FATAL) << "Failed to find the branch " << rofRecName << " in the tree " << digTreeName;
}
digTree.SetBranchAddress(rofRecName.c_str(), &rofRecVecP);
///-------< input
///-------> output
if (outName.empty()) {
outName = "raw" + digBranchName + ".raw";
LOG(INFO) << "Output file name is not provided, set to " << outName;
}
auto outFl = fopen(outName.c_str(), "wb");
if (!outFl) {
LOG(FATAL) << "failed to open raw data output file " << outName;
;
} else {
LOG(INFO) << "opened raw data output file " << outName;
}
o2::itsmft::PayLoadCont outBuffer;
///-------< output
o2::itsmft::RawPixelReader<o2::itsmft::ChipMappingMFT> rawReader;
rawReader.setPadding128(true);
rawReader.setVerbosity(0);
//------------------------------------------------------------------------------->>>>
// just as an example, we require here that the IB staves are read via 3 links,
// while OB staves use only 1 link.
// Note, that if the RU container is not defined, it will be created automatically
// during encoding.
// If the links of the container are not defined, a single link readout will be assigned
const auto& mp = rawReader.getMapping();
LOG(INFO) << "Number of RUs = " << mp.getNRUs();
for (int ir = 0; ir < mp.getNRUs(); ir++) {
auto& ru = rawReader.getCreateRUDecode(ir); // create RU container
uint32_t lanes = mp.getCablesOnRUType(ru.ruInfo->ruType); // lanes patter of this RU
ru.links[0] = rawReader.addGBTLink();
auto* link = rawReader.getGBTLink(ru.links[0]);
link->lanes = lanes; // single link reads all lanes
LOG(INFO) << "RU " << std::setw(3) << ir << " type " << int(ru.ruInfo->ruType) << " on lr" << int(ru.ruInfo->layer)
<< " : FEEId 0x" << std::hex << std::setfill('0') << std::setw(6) << mp.RUSW2FEEId(ir, int(ru.ruInfo->layer))
<< " reads lanes " << std::bitset<25>(link->lanes);
}
//-------------------------------------------------------------------------------<<<<
for (int i = 0; i < digTree.GetEntries(); i++) {
digTree.GetEntry(i);
for (const auto& rofRec : rofRecVec) {
int rofEntry = rofRec.getFirstEntry();
int nDigROF = rofRec.getNEntries();
LOG(INFO) << "Processing ROF:" << rofRec.getROFrame() << " with " << nDigROF << " entries";
rofRec.print();
if (!nDigROF) {
LOG(INFO) << "Frame is empty"; // ??
continue;
}
int maxDigIndex = rofEntry + nDigROF;
LOG(INFO) << "BV===== 1stEntry " << rofEntry << " maxDigIndex " << maxDigIndex << "\n";
int nPagesCached = rawReader.digits2raw(digiVec, rofEntry, nDigROF, rofRec.getBCData(),
ruSWMin, ruSWMax);
LOG(INFO) << "Pages chached " << nPagesCached << " superpage: " << int(superPageSize);
if (nPagesCached >= superPageSize) {
int nPagesFlushed = rawReader.flushSuperPages(superPageSize, outBuffer);
fwrite(outBuffer.data(), 1, outBuffer.getSize(), outFl); //write to file
outBuffer.clear();
LOG(INFO) << "Flushed " << nPagesFlushed << " CRU pages";
}
//printf("BV===== stop after the first ROF!\n");
//break;
}
} // loop over multiple ROFvectors (in case of chaining)
// flush the rest
int flushed = 0;
do {
flushed = rawReader.flushSuperPages(superPageSize, outBuffer, false);
fwrite(outBuffer.data(), 1, outBuffer.getSize(), outFl); //write to file
if (flushed) {
LOG(INFO) << "Flushed final " << flushed << " CRU pages";
}
outBuffer.clear();
} while (flushed);
fclose(outFl);
//
swTot.Stop();
swTot.Print();
}