21 #include <trg/gdl/modules/trggdlUnpacker/trggdlUnpackerModule.h>
32 string TRGGDLUnpackerModule::version()
const
34 return string(
"1.00");
37 TRGGDLUnpackerModule::TRGGDLUnpackerModule()
40 string desc =
"TRGGDLUnpackerModule(" +
version() +
")";
44 "Print trigger readout board included in the data.",
47 B2DEBUG(20,
"trggdlunpacker: Constructor done.");
52 store.registerInDataStore();
57 bad_flag = m_dbbadrun->getflag();
65 B2INFO(
"no database of gdl unpacker");
68 nword_header = m_dbunpacker->get_nword_header();
69 n_clocks = m_dbunpacker->getnClks();
70 nBits = m_dbunpacker->getnBits();
71 n_leafs = m_dbunpacker->getnLeafs();
72 n_leafsExtra = m_dbunpacker->getnLeafsExtra();
73 conf = m_dbunpacker->getconf();
74 for (
int i = 0; i < 320; i++) {
75 LeafBitMap[i] = m_dbunpacker->getLeafMap(i);
77 for (
int i = 0; i < 320; i++) {
78 strcpy(LeafNames[i], m_dbunpacker->getLeafnames(i));
83 for (
int i = 0; i < 320; i++) {
84 if (strcmp(LeafNames[i],
"conf") == 0)conf_map = i;
85 if (strcmp(LeafNames[i],
"evt") == 0) evt_map = i;
86 if (strcmp(LeafNames[i],
"clk") == 0) clk_map = i;
89 BitMap = vector<vector<int>>(n_leafs, vector<int>(2, 0));
90 for (
int i = 0; i < n_leafs; i++) {
91 BitMap[i][0] = m_dbunpacker->getBitMap(i, 0);
92 BitMap[i][1] = m_dbunpacker->getBitMap(i, 1);
94 BitMap_extra = vector<vector<int>>(n_leafsExtra, vector<int>(3, 0));
95 for (
int i = 0; i < n_leafsExtra; i++) {
96 BitMap_extra[i][0] = m_dbunpacker->getBitMap_extra(i, 0);
97 BitMap_extra[i][1] = m_dbunpacker->getBitMap_extra(i, 1);
98 BitMap_extra[i][2] = m_dbunpacker->getBitMap_extra(i, 2);
103 int aBitMap[320][2] = {0};
104 int aBitMap_extra[100][3] = { -1};
105 for (
int i = 0; i < n_leafsExtra; i++) {
106 aBitMap_extra[i][0] = m_dbunpacker->getBitMap_extra(i, 0);
107 aBitMap_extra[i][1] = m_dbunpacker->getBitMap_extra(i, 1);
108 aBitMap_extra[i][2] = m_dbunpacker->getBitMap_extra(i, 2);
111 for (
int i = 0; i < 200; i++) {
112 LeafBitMap[i] = m_dbunpacker->getLeafMap(i);
113 std::cout <<
"LeafBitMap[" << i <<
"] = " << m_dbunpacker->getLeafMap(i) << std::endl;
114 strcpy(LeafNames[i], m_dbunpacker->getLeafnames(i));
115 std::cout <<
"LeafNames[" << i <<
"] = " << m_dbunpacker->getLeafnames(i) << std::endl;
117 for (
int i = 0; i < n_leafs; i++) {
118 aBitMap[i][0] = m_dbunpacker->getBitMap(i, 0);
119 aBitMap[i][1] = m_dbunpacker->getBitMap(i, 1);
121 for (
int i = 0; i < 320; i++) {
122 int bin = m_dbunpacker->getLeafMap(i) + 1;
123 if (0 < bin && bin <= n_leafs) {
124 std::cout <<
"leaf(" << i
126 <<
"), LeafNames[leaf](" << LeafNames[i]
127 <<
"), BitMap[bin-1][0](" << aBitMap[bin - 1][0]
128 <<
"), BitMap[bin-1][1](" << aBitMap[bin - 1][1]
133 for (
int i = 0; i < 320; i++) {
134 int bin = m_dbunpacker->getLeafMap(i) + 1;
135 int j = bin - n_leafs - 1;
136 if (n_leafs < bin && bin <= n_leafs + n_leafsExtra) {
137 std::cout <<
"i(" << i
139 <<
"), LeafNames[leaf](" << LeafNames[i]
140 <<
"), BitMap_extra[j][0](buf[" << aBitMap_extra[j][0]
141 <<
"]), BitMap_extra[j][1](downto " << aBitMap_extra[j][1]
142 <<
"), BitMap_extra[j][2](" << aBitMap_extra[j][2]
143 <<
" bit length)" << std::endl;
155 if (unpack_flag == 1) {
157 for (
int i = 0; i < raw_trgarray.
getEntries(); i++) {
158 for (
int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
160 if (raw_trgarray[i]->GetNodeID(j) == 0x15000001) {
161 int nword = raw_trgarray[i]->GetDetectorNwords(j, 0);
163 fillTreeGDLDB(raw_trgarray[i]->GetDetectorBuffer(j, 0),
164 raw_trgarray[i]->GetEveNo(j));
168 unsigned cprid = raw_trgarray[i]->GetNodeID(j);
169 if ((0x15000001 <= cprid && cprid <= 0x15000002) ||
170 (0x11000001 <= cprid && cprid <= 0x11000010)) {
171 int _exp = raw_trgarray[i]->GetExpNo(j);
172 int _run = raw_trgarray[i]->GetRunNo(j);
173 for (
int hslb = 0; hslb < 2; hslb++) {
174 int nword = raw_trgarray[i]->GetDetectorNwords(j, hslb);
175 int* buf = raw_trgarray[i]->GetDetectorBuffer(j, hslb);
176 printf(
"0x%x%c exp(%d), run(%d), nword(%d)",
177 cprid,
'a' + hslb, _exp, _run, nword);
179 printf(
", 0x%x 0x%x 0x%x",
180 buf[0], buf[1], buf[2]);
192 void TRGGDLUnpackerModule::fillTreeGDLDB(
int* buf,
int evt)
198 for (
int clk = 0; clk < n_clocks; clk++) {
202 vector<int*> Bits(n_leafs + n_leafsExtra);
204 for (
int i = 0; i < 320; i++) {
205 if (LeafBitMap[i] != -1) {
206 Bits[LeafBitMap[i]] = &(storeAry[ntups]->m_unpacker[i]);
207 strcpy(storeAry[ntups]->m_unpackername[i], LeafNames[i]);
212 for (
int l = 0; l < n_leafs + n_leafsExtra; l++) *Bits[l] = 0;
214 if (conf_map >= 0) storeAry[ntups]->m_unpacker[conf_map] = conf;
215 if (evt_map >= 0) storeAry[ntups]->m_unpacker[evt_map] = evt;
216 if (clk_map >= 0) storeAry[ntups]->m_unpacker[clk_map] = clk;
218 for (
int i = 0; i < n_leafsExtra; i++) {
219 if (BitMap_extra[i][0] != -1) {
220 if (BitMap_extra[i][1] == -1) *Bits[i + n_leafs] = buf[BitMap_extra[i][0]];
221 else *Bits[i + n_leafs] = (buf[BitMap_extra[i][0]] >> BitMap_extra[i][1]) & ((
222 1 << BitMap_extra[i][2]) - 1);
227 for (
int _wd = 0; _wd < nBits / 32; _wd++) {
228 unsigned wd = buf[clk * (nBits / 32) + _wd + nword_header];
229 for (
int bb = 0; bb < 32; bb++) {
230 if ((wd >> (31 - bb)) & 1) {
231 int bitIn640 = (nBits - 1) - _wd * 32 - bb;
233 leaf < n_leafs; leaf++) {
234 int bitMaxOfTheLeaf = BitMap[leaf][0];
235 int bitWidOfTheLeaf = BitMap[leaf][1];
236 int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
237 if (bitMinOfTheLeaf <= bitIn640 && bitIn640 <= bitMaxOfTheLeaf) {
238 *Bits[leaf] |= (1 << (bitIn640 - bitMinOfTheLeaf));
virtual void initialize() override
Initilizes TRGGDLUnpackerModuel.
virtual void event() override
Called event by event.
bool m_trgReadoutBoardSearch
flag to select board search mode
bool m_print_dbmap
flag to dump data base map
std::string version() const
returns version of TRGGDLUnpackerModule.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Accessor to arrays stored in the data store.
T * appendNew()
Construct a new T object at the end of the array.
bool isValid() const
Check wether the array was registered.
int getEntries() const
Get the number of objects in the array.
void clear() override
Delete all entries in this array.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.