Belle II Software development
TRGGRLUnpackerModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <trg/grl/modules/TRGGRLUnpacker/TRGGRLUnpackerModule.h>
10
11using namespace std;
12using namespace Belle2;
13using namespace TRGGRLUNPACKERSPACE;
14
16REG_MODULE(TRGGRLUnpacker);
17
19{
20 return string("1.00");
21}
22
24 : Module::Module()
25{
26
27 string desc = "TRGGRLUnpackerModule(" + version() + ")";
28 setDescription(desc);
30 B2DEBUG(20, "TRGGRLUnpacker: Constructor done.");
31}
32
36
40
42{
43 StoreObjPtr<TRGGRLUnpackerStore> evtinfo("TRGGRLUnpackerStore");
44 evtinfo.registerInDataStore();
45}
46
50
54
56{
57 StoreArray<RawTRG> raw_trgarray;
58
59 for (int i = 0; i < raw_trgarray.getEntries(); i++) {
60
61 // Check PCIe40 data or Copper data
62 if (raw_trgarray[i]->GetMaxNumOfCh(0) == 48) { m_pciedata = true; }
63 else if (raw_trgarray[i]->GetMaxNumOfCh(0) == 4) { m_pciedata = false; }
64 else { B2FATAL("TRGGRLUnpackerModule: Invalid value of GetMaxNumOfCh from raw data: " << LogVar("Number of ch: ", raw_trgarray[i]->GetMaxNumOfCh(0))); }
65
66 int node_id = 0;
67 int ch_id = 0;
68 if (m_pciedata) {
69 node_id = 0x10000001;
70 ch_id = 22;
71 } else {
72 node_id = 0x15000002;
73 ch_id = 0;
74 }
75
76
77 if (raw_trgarray[i]->GetTRGType(0) == 7) {continue;}
78
79 for (int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
80 if ((int)raw_trgarray[i]->GetNodeID(j) == node_id) {
81 //cout << raw_trgarray[i]->GetDetectorNwords(j, 0) << endl;
82 //if (raw_trgarray[i]->GetDetectorNwords(j, 0) == 0xC03)
83 if (raw_trgarray[i]->GetDetectorNwords(j, ch_id) > 0) {
84 fillTreeTRGGRLUnpacker(raw_trgarray[i]->GetDetectorBuffer(j, ch_id), raw_trgarray[i]->GetEveNo(j));
85 }
86 }
87 }
88 }
89}
90
92{
93
94 const unsigned nword_header = 3;
95
96// StoreArray<TRGGRLUnpackerStore> storeAry("GRLclk");
98 StoreObjPtr<TRGGRLUnpackerStore> evtinfo("TRGGRLUnpackerStore");
99// evtinfo.registerInDataStore();
100// storeAry.appendNew();
101// int ntups = storeAry.getEntries() - 1;
102//
103 //int* bitArray[nLeafs + nLeafsExtra];
104 //setLeafPointersArray(rawstore, bitArray);
105 //for (int l = 0; l < nLeafs + nLeafsExtra; l++) *bitArray[l] = 0;
106 for (int l = 0; l < nLeafs + nLeafsExtra; l++) {
107 SetStoreLeaf(rawstore, l, 0);
108 }
109
110 //set or get?
111 rawstore->set_evt(evt);
112 rawstore->set_clk(0);
113 rawstore->set_firmid(buf[0]);
114 rawstore->set_firmver(buf[1]);
115 rawstore->set_coml1(buf[2] & ((1 << 12) - 1));
116 rawstore->set_b2ldly((buf[2] >> 12) & ((1 << 9) - 1));
117 rawstore->set_maxrvc((buf[2] >> 21) & ((1 << 11) - 1));
118
119 //cout<<"nClks: "<<nClks<<endl;
120 //for (int _wd = 0; _wd < nBits / 32; _wd++)
121 //{
122 // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd + nword_header]);
123 // cout<<"clk["<<clk<<"] wd["<<_wd<<"] "<<buf_b<<endl;
124 //}
125
126 for (int _wd = 0; _wd < nBits / 32; _wd++) { // 0..19
127 unsigned wd = buf[0 * (nBits / 32) + _wd + nword_header];
128 for (int bb = 0; bb < 32; bb++) { // bit by bit
129 if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
130 int bitPosition = (nBits - 1) - _wd * 32 - bb;
131 for (int leaf = 0; // Find a leaf that covers the bit.
132 leaf < nLeafs; leaf++) {
133 int bitMaxOfTheLeaf = BitMap[leaf][0];
134 int bitWidOfTheLeaf = BitMap[leaf][1];
135 int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
136 if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
137 const int bitOffset = bitPosition - bitMinOfTheLeaf;
138 if (leaf == e_ml_tau_nn_input) {
139 const int inputID = bitOffset / 12;
140 const int inputBit = bitOffset % 12;
141 rawstore->set_ml_tau_nn_input(inputID,
142 rawstore->get_ml_tau_nn_input(inputID) | static_cast<int>(1u << inputBit));
143 } else {
144 SetStoreLeaf(rawstore, leaf, GetStoreLeaf(rawstore, leaf) | static_cast<int>(1u << bitOffset));
145 }
146 }
147 }
148 }
149 }
150 }
151//----------
152 rawstore->set_N_cluster(rawstore->get_N_cluster_0() + rawstore->get_N_cluster_1());
153 evtinfo.assign(rawstore);
154 std::vector<int> index_ECL;
155 std::vector<int> clkindex_ECL;
156 index_ECL.clear();
157 clkindex_ECL.clear();
158 for (int i = 0; i < rawstore->get_N_cluster_0(); i++) {
159 index_ECL.push_back(i); clkindex_ECL.push_back(0);
160 }
161 for (int i = 0; i < rawstore->get_N_cluster_1(); i++) {
162 index_ECL.push_back(i + 6); clkindex_ECL.push_back(1);
163 }
164// for (int i = 0; i < rawstore->m_N_cluster_2; i++) {
165// index_ECL.push_back(i+12); clkindex_ECL.push_back(2);}
166
167 evtinfo->ClearVectors();
168 for (int i = 0; i < rawstore->get_N_cluster(); i++) {
169 int index = index_ECL[i];
170 int clkindex = clkindex_ECL[i];
171
172 evtinfo->Addto_clk_ECL(clkindex);
173 evtinfo->Addto_E_ECL(rawstore->get_E_ECL(index));
174 evtinfo->Addto_t_ECL(rawstore->get_t_ECL(index));
175 evtinfo->Addto_theta_ECL(rawstore->get_theta_ECL(index));
176 evtinfo->Addto_phi_ECL(rawstore->get_phi_ECL(index));
177 evtinfo->Addto_E_ECL(rawstore->get_E_ECL(index));
178 evtinfo->Addto_1GeV_ECL(rawstore->get_1GeV_ECL(index));
179 evtinfo->Addto_2GeV_ECL(rawstore->get_2GeV_ECL(index));
180 }
181
182//----------
183
184 for (int i = 0; i < 32; i++) {
185 evtinfo->set_phi_i(i, (rawstore->get_phi_i_int(0) & (1u << i)) != 0);
186 evtinfo->set_phi_CDC(i, (rawstore->get_phi_CDC_int(0) & (1u << i)) != 0);
187 }
188 for (int i = 32; i < 36; i++) {
189 evtinfo->set_phi_i(i, (rawstore->get_phi_i_int(1) & (1 << (i - 32))) != 0);
190 evtinfo->set_phi_CDC(i, (rawstore->get_phi_CDC_int(1) & (1 << (i - 32))) != 0);
191 }
192
193 for (int i = 0; i < 16; i++) {
194 evtinfo->set_slot_CDC(i, (rawstore->get_slot_CDC_int() & (1 << i)) != 0);
195 evtinfo->set_slot_TOP(i, (rawstore->get_slot_TOP_int() & (1 << i)) != 0);
196 }
197
198 for (int i = 0; i < 8; i++) {
199 evtinfo->set_sector_CDC(i, (rawstore->get_sector_CDC_int() & (1 << i)) != 0);
200 evtinfo->set_sector_KLM(i, (rawstore->get_sector_KLM_int() & (1 << i)) != 0);
201 }
202
203 for (int i = 0; i < 32; i++) {
204 evtinfo->set_map_ST(i, (rawstore->get_map_ST_int(0) & (1u << i)) != 0);
205 evtinfo->set_map_ST2(i, (rawstore->get_map_ST2_int(0) & (1u << i)) != 0);
206 evtinfo->set_map_veto(i, (rawstore->get_map_veto_int(0) & (1u << i)) != 0);
207 evtinfo->set_map_TSF0(i, (rawstore->get_map_TSF0_int(0) & (1u << i)) != 0);
208 evtinfo->set_map_TSF2(i, (rawstore->get_map_TSF2_int(0) & (1u << i)) != 0);
209 evtinfo->set_map_TSF4(i, (rawstore->get_map_TSF4_int(0) & (1u << i)) != 0);
210 evtinfo->set_map_TSF1(i, (rawstore->get_map_TSF1_int(0) & (1u << i)) != 0);
211 evtinfo->set_map_TSF3(i, (rawstore->get_map_TSF3_int(0) & (1u << i)) != 0);
212 }
213 for (int i = 32; i < 64; i++) {
214 evtinfo->set_map_ST(i, (rawstore->get_map_ST_int(1) & (1u << (i - 32))) != 0);
215 evtinfo->set_map_ST2(i, (rawstore->get_map_ST2_int(1) & (1u << (i - 32))) != 0);
216 evtinfo->set_map_veto(i, (rawstore->get_map_veto_int(1) & (1u << (i - 32))) != 0);
217 evtinfo->set_map_TSF0(i, (rawstore->get_map_TSF0_int(1) & (1u << (i - 32))) != 0);
218 evtinfo->set_map_TSF2(i, (rawstore->get_map_TSF2_int(1) & (1u << (i - 32))) != 0);
219 evtinfo->set_map_TSF4(i, (rawstore->get_map_TSF4_int(1) & (1u << (i - 32))) != 0);
220 evtinfo->set_map_TSF1(i, (rawstore->get_map_TSF1_int(1) & (1u << (i - 32))) != 0);
221 evtinfo->set_map_TSF3(i, (rawstore->get_map_TSF3_int(1) & (1u << (i - 32))) != 0);
222 }
223
224
225}
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition Module.cc:208
Module()
Constructor.
Definition Module.cc:30
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition Module.h:80
bool assign(TObject *object, bool replace=false)
Assign 'object' to this accessor.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition StoreArray.h:216
Type-safe access to single objects in the data store.
Definition StoreObjPtr.h:96
virtual void initialize() override
Initializes TRGGRLUnpackerUnpackerModule.
virtual void event() override
Called event by event.
virtual void endRun() override
Called when run ended.
virtual void terminate() override
Called when processing ended.
virtual void beginRun() override
Called when new run started.
std::string version() const
returns version of TRGGRLUnpackerModule.
virtual void fillTreeTRGGRLUnpacker(int *buf, int evt)
Unpacker main function.
void set_b2ldly(int b2ldly)
m_b2ldly leafs
int get_N_cluster_0() const
m_N_cluster_0 leaf
int get_phi_CDC_int(int i) const
m_phi_CDC integer leaf
int get_2GeV_ECL(int i) const
m_2GeV_flag_ECL leaf
int get_map_TSF2_int(int i) const
m_map_TSF2 integer leaf
int get_map_TSF0_int(int i) const
m_map_TSF0 integer leaf
int get_t_ECL(int i) const
m_t_ECL leaf
void set_firmid(int firmid)
m_firmid leafs
void set_ml_tau_nn_input(int ml_tau_nn_input)
ECLTRG ML tau nn input.
int get_sector_CDC_int() const
m_sector_CDC integer leaf
int get_phi_i_int(int i) const
m_phi_i integer leaf
void set_evt(int evt)
m_evt leafs
int get_map_TSF3_int(int i) const
m_map_TSF3 integer leaf
int get_slot_TOP_int() const
m_slot_TOP integer leaf
int get_map_ST_int(int i) const
m_map_ST integer leaf
int get_map_TSF1_int(int i) const
m_map_TSF1 integer leaf
int get_map_TSF4_int(int i) const
m_map_TSF4 integer leaf
int get_map_ST2_int(int i) const
m_map_ST2 integer leaf
void set_firmver(int firmver)
m_firmver leafs
int get_N_cluster_1() const
m_N_cluster_1 leaf
int get_phi_ECL(int i) const
m_phi_ECL leaf
int get_sector_KLM_int() const
m_sector_KLM integer leaf
int get_map_veto_int(int i) const
m_map_veto integer leaf
void set_N_cluster(int N_cluster)
m_N_cluster leaf
void set_coml1(int coml1)
m_coml1 leafs
int get_N_cluster() const
m_N_cluster leaf
void set_maxrvc(int maxrvc)
m_maxrvc leafs
int get_ml_tau_nn_input() const
ECLTRG ML tau nn input.
int get_theta_ECL(int i) const
m_theta_ECL leaf
void set_clk(int clk)
m_clk leafs
int get_E_ECL(int i) const
m_E_ECL leaf
int get_1GeV_ECL(int i) const
m_1GeV_flag_ECL leaf
int get_slot_CDC_int() const
m_slot_CDC integer leaf
Class to store variables with their name which were sent to the logging service.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Abstract base class for different kinds of events.
STL namespace.