14 #include <trg/gdl/modules/trggdlUnpacker/trggdlUnpackerModule.h>
25 string TRGGDLUnpackerModule::version()
const
27 return string(
"1.00");
30 TRGGDLUnpackerModule::TRGGDLUnpackerModule()
33 string desc =
"TRGGDLUnpackerModule(" +
version() +
")";
37 "Print trigger readout board included in the data.",
40 B2DEBUG(20,
"trggdlunpacker: Constructor done.");
45 store.registerInDataStore();
50 bad_flag = m_dbbadrun->getflag();
58 B2INFO(
"no database of gdl unpacker");
61 nword_header = m_dbunpacker->get_nword_header();
62 n_clocks = m_dbunpacker->getnClks();
63 nBits = m_dbunpacker->getnBits();
64 n_leafs = m_dbunpacker->getnLeafs();
65 n_leafsExtra = m_dbunpacker->getnLeafsExtra();
66 conf = m_dbunpacker->getconf();
67 for (
int i = 0; i < 320; i++) {
68 LeafBitMap[i] = m_dbunpacker->getLeafMap(i);
70 for (
int i = 0; i < 320; i++) {
71 strcpy(LeafNames[i], m_dbunpacker->getLeafnames(i));
76 for (
int i = 0; i < 320; i++) {
77 if (strcmp(LeafNames[i],
"conf") == 0)conf_map = i;
78 if (strcmp(LeafNames[i],
"evt") == 0) evt_map = i;
79 if (strcmp(LeafNames[i],
"clk") == 0) clk_map = i;
82 BitMap = vector<vector<int>>(n_leafs, vector<int>(2, 0));
83 for (
int i = 0; i < n_leafs; i++) {
84 BitMap[i][0] = m_dbunpacker->getBitMap(i, 0);
85 BitMap[i][1] = m_dbunpacker->getBitMap(i, 1);
87 BitMap_extra = vector<vector<int>>(n_leafsExtra, vector<int>(3, 0));
88 for (
int i = 0; i < n_leafsExtra; i++) {
89 BitMap_extra[i][0] = m_dbunpacker->getBitMap_extra(i, 0);
90 BitMap_extra[i][1] = m_dbunpacker->getBitMap_extra(i, 1);
91 BitMap_extra[i][2] = m_dbunpacker->getBitMap_extra(i, 2);
96 int aBitMap[320][2] = {0};
97 int aBitMap_extra[100][3] = { -1};
98 for (
int i = 0; i < n_leafsExtra; i++) {
99 aBitMap_extra[i][0] = m_dbunpacker->getBitMap_extra(i, 0);
100 aBitMap_extra[i][1] = m_dbunpacker->getBitMap_extra(i, 1);
101 aBitMap_extra[i][2] = m_dbunpacker->getBitMap_extra(i, 2);
104 for (
int i = 0; i < 200; i++) {
105 LeafBitMap[i] = m_dbunpacker->getLeafMap(i);
106 std::cout <<
"LeafBitMap[" << i <<
"] = " << m_dbunpacker->getLeafMap(i) << std::endl;
107 strcpy(LeafNames[i], m_dbunpacker->getLeafnames(i));
108 std::cout <<
"LeafNames[" << i <<
"] = " << m_dbunpacker->getLeafnames(i) << std::endl;
110 for (
int i = 0; i < n_leafs; i++) {
111 aBitMap[i][0] = m_dbunpacker->getBitMap(i, 0);
112 aBitMap[i][1] = m_dbunpacker->getBitMap(i, 1);
114 for (
int i = 0; i < 320; i++) {
115 int bin = m_dbunpacker->getLeafMap(i) + 1;
116 if (0 < bin && bin <= n_leafs) {
117 std::cout <<
"leaf(" << i
119 <<
"), LeafNames[leaf](" << LeafNames[i]
120 <<
"), BitMap[bin-1][0](" << aBitMap[bin - 1][0]
121 <<
"), BitMap[bin-1][1](" << aBitMap[bin - 1][1]
126 for (
int i = 0; i < 320; i++) {
127 int bin = m_dbunpacker->getLeafMap(i) + 1;
128 int j = bin - n_leafs - 1;
129 if (n_leafs < bin && bin <= n_leafs + n_leafsExtra) {
130 std::cout <<
"i(" << i
132 <<
"), LeafNames[leaf](" << LeafNames[i]
133 <<
"), BitMap_extra[j][0](buf[" << aBitMap_extra[j][0]
134 <<
"]), BitMap_extra[j][1](downto " << aBitMap_extra[j][1]
135 <<
"), BitMap_extra[j][2](" << aBitMap_extra[j][2]
136 <<
" bit length)" << std::endl;
148 if (unpack_flag == 1) {
150 for (
int i = 0; i < raw_trgarray.
getEntries(); i++) {
151 for (
int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
153 if (raw_trgarray[i]->GetNodeID(j) == 0x15000001) {
154 int nword = raw_trgarray[i]->GetDetectorNwords(j, 0);
156 fillTreeGDLDB(raw_trgarray[i]->GetDetectorBuffer(j, 0),
157 raw_trgarray[i]->GetEveNo(j));
161 unsigned cprid = raw_trgarray[i]->GetNodeID(j);
162 if ((0x15000001 <= cprid && cprid <= 0x15000002) ||
163 (0x11000001 <= cprid && cprid <= 0x11000010)) {
164 int _exp = raw_trgarray[i]->GetExpNo(j);
165 int _run = raw_trgarray[i]->GetRunNo(j);
166 for (
int hslb = 0; hslb < 2; hslb++) {
167 int nword = raw_trgarray[i]->GetDetectorNwords(j, hslb);
168 int* buf = raw_trgarray[i]->GetDetectorBuffer(j, hslb);
169 printf(
"0x%x%c exp(%d), run(%d), nword(%d)",
170 cprid,
'a' + hslb, _exp, _run, nword);
172 printf(
", 0x%x 0x%x 0x%x",
173 buf[0], buf[1], buf[2]);
185 void TRGGDLUnpackerModule::fillTreeGDLDB(
int* buf,
int evt)
191 for (
int clk = 0; clk < n_clocks; clk++) {
195 vector<int*> Bits(n_leafs + n_leafsExtra);
197 for (
int i = 0; i < 320; i++) {
198 if (LeafBitMap[i] != -1) {
199 Bits[LeafBitMap[i]] = &(storeAry[ntups]->m_unpacker[i]);
200 strcpy(storeAry[ntups]->m_unpackername[i], LeafNames[i]);
205 for (
int l = 0; l < n_leafs + n_leafsExtra; l++) *Bits[l] = 0;
207 if (conf_map >= 0) storeAry[ntups]->m_unpacker[conf_map] = conf;
208 if (evt_map >= 0) storeAry[ntups]->m_unpacker[evt_map] = evt;
209 if (clk_map >= 0) storeAry[ntups]->m_unpacker[clk_map] = clk;
211 for (
int i = 0; i < n_leafsExtra; i++) {
212 if (BitMap_extra[i][0] != -1) {
213 if (BitMap_extra[i][1] == -1) *Bits[i + n_leafs] = buf[BitMap_extra[i][0]];
214 else *Bits[i + n_leafs] = (buf[BitMap_extra[i][0]] >> BitMap_extra[i][1]) & ((
215 1 << BitMap_extra[i][2]) - 1);
220 for (
int _wd = 0; _wd < nBits / 32; _wd++) {
221 int wd = buf[clk * (nBits / 32) + _wd + nword_header];
222 for (
int bb = 0; bb < 32; bb++) {
223 if ((wd >> (31 - bb)) & 1) {
224 int bitIn640 = (nBits - 1) - _wd * 32 - bb;
226 leaf < n_leafs; leaf++) {
227 int bitMaxOfTheLeaf = BitMap[leaf][0];
228 int bitWidOfTheLeaf = BitMap[leaf][1];
229 int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
230 if (bitMinOfTheLeaf <= bitIn640 && bitIn640 <= bitMaxOfTheLeaf) {
231 *Bits[leaf] |= (1 << (bitIn640 - bitMinOfTheLeaf));