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
34{
35}
36
38{
39}
40
42{
43 StoreObjPtr<TRGGRLUnpackerStore> evtinfo("TRGGRLUnpackerStore");
44 evtinfo.registerInDataStore();
45}
46
48{
49}
50
52{
53}
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 SetStoreLeaf(rawstore, leaf, GetStoreLeaf(rawstore, leaf) | (1 << (bitPosition - bitMinOfTheLeaf)));
138 }
139 }
140 }
141 }
142 }
143//----------
144 rawstore->set_N_cluster(rawstore->get_N_cluster_0() + rawstore->get_N_cluster_1());
145 evtinfo.assign(rawstore);
146 std::vector<int> index_ECL;
147 std::vector<int> clkindex_ECL;
148 index_ECL.clear();
149 clkindex_ECL.clear();
150 for (int i = 0; i < rawstore->get_N_cluster_0(); i++) {
151 index_ECL.push_back(i); clkindex_ECL.push_back(0);
152 }
153 for (int i = 0; i < rawstore->get_N_cluster_1(); i++) {
154 index_ECL.push_back(i + 6); clkindex_ECL.push_back(1);
155 }
156// for (int i = 0; i < rawstore->m_N_cluster_2; i++) {
157// index_ECL.push_back(i+12); clkindex_ECL.push_back(2);}
158
159 evtinfo->ClearVectors();
160 for (int i = 0; i < rawstore->get_N_cluster(); i++) {
161 int index = index_ECL[i];
162 int clkindex = clkindex_ECL[i];
163
164 evtinfo->Addto_clk_ECL(clkindex);
165 evtinfo->Addto_E_ECL(rawstore->get_E_ECL(index));
166 evtinfo->Addto_t_ECL(rawstore->get_t_ECL(index));
167 evtinfo->Addto_theta_ECL(rawstore->get_theta_ECL(index));
168 evtinfo->Addto_phi_ECL(rawstore->get_phi_ECL(index));
169 evtinfo->Addto_E_ECL(rawstore->get_E_ECL(index));
170 evtinfo->Addto_1GeV_ECL(rawstore->get_1GeV_ECL(index));
171 evtinfo->Addto_2GeV_ECL(rawstore->get_2GeV_ECL(index));
172 }
173
174//----------
175
176 for (int i = 0; i < 32; i++) {
177 evtinfo->set_phi_i(i, (rawstore->get_phi_i_int(0) & (1u << i)) != 0);
178 evtinfo->set_phi_CDC(i, (rawstore->get_phi_CDC_int(0) & (1u << i)) != 0);
179 }
180 for (int i = 32; i < 36; i++) {
181 evtinfo->set_phi_i(i, (rawstore->get_phi_i_int(1) & (1 << (i - 32))) != 0);
182 evtinfo->set_phi_CDC(i, (rawstore->get_phi_CDC_int(1) & (1 << (i - 32))) != 0);
183 }
184
185 for (int i = 0; i < 16; i++) {
186 evtinfo->set_slot_CDC(i, (rawstore->get_slot_CDC_int() & (1 << i)) != 0);
187 evtinfo->set_slot_TOP(i, (rawstore->get_slot_TOP_int() & (1 << i)) != 0);
188 }
189
190 for (int i = 0; i < 8; i++) {
191 evtinfo->set_sector_CDC(i, (rawstore->get_sector_CDC_int() & (1 << i)) != 0);
192 evtinfo->set_sector_KLM(i, (rawstore->get_sector_KLM_int() & (1 << i)) != 0);
193 }
194
195 for (int i = 0; i < 32; i++) {
196 evtinfo->set_map_ST(i, (rawstore->get_map_ST_int(0) & (1u << i)) != 0);
197 evtinfo->set_map_ST2(i, (rawstore->get_map_ST2_int(0) & (1u << i)) != 0);
198 evtinfo->set_map_veto(i, (rawstore->get_map_veto_int(0) & (1u << i)) != 0);
199 evtinfo->set_map_TSF0(i, (rawstore->get_map_TSF0_int(0) & (1u << i)) != 0);
200 evtinfo->set_map_TSF2(i, (rawstore->get_map_TSF2_int(0) & (1u << i)) != 0);
201 evtinfo->set_map_TSF4(i, (rawstore->get_map_TSF4_int(0) & (1u << i)) != 0);
202 evtinfo->set_map_TSF1(i, (rawstore->get_map_TSF1_int(0) & (1u << i)) != 0);
203 evtinfo->set_map_TSF3(i, (rawstore->get_map_TSF3_int(0) & (1u << i)) != 0);
204 }
205 for (int i = 32; i < 64; i++) {
206 evtinfo->set_map_ST(i, (rawstore->get_map_ST_int(1) & (1u << (i - 32))) != 0);
207 evtinfo->set_map_ST2(i, (rawstore->get_map_ST2_int(1) & (1u << (i - 32))) != 0);
208 evtinfo->set_map_veto(i, (rawstore->get_map_veto_int(1) & (1u << (i - 32))) != 0);
209 evtinfo->set_map_TSF0(i, (rawstore->get_map_TSF0_int(1) & (1u << (i - 32))) != 0);
210 evtinfo->set_map_TSF2(i, (rawstore->get_map_TSF2_int(1) & (1u << (i - 32))) != 0);
211 evtinfo->set_map_TSF4(i, (rawstore->get_map_TSF4_int(1) & (1u << (i - 32))) != 0);
212 evtinfo->set_map_TSF1(i, (rawstore->get_map_TSF1_int(1) & (1u << (i - 32))) != 0);
213 evtinfo->set_map_TSF3(i, (rawstore->get_map_TSF3_int(1) & (1u << (i - 32))) != 0);
214 }
215
216
217}
Base class for Modules.
Definition: Module.h:72
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
@ 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
Initilizes 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
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_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:650
Abstract base class for different kinds of events.
STL namespace.