Belle II Software  release-06-02-00
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 
11 using namespace std;
12 using namespace Belle2;
13 using namespace TRGGRLUNPACKERSPACE;
14 
16 REG_MODULE(TRGGRLUnpacker);
17 
18 string TRGGRLUnpackerModule::version() const
19 {
20  return string("1.00");
21 }
22 
23 TRGGRLUnpackerModule::TRGGRLUnpackerModule()
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 (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");
97  TRGGRLUnpackerStore* rawstore = new TRGGRLUnpackerStore();
98  StoreObjPtr<TRGGRLUnpackerStore> evtinfo("TRGGRLUnpackerStore");
99 // evtinfo.registerInDataStore();
100 // storeAry.appendNew();
101 // int ntups = storeAry.getEntries() - 1;
102  int* bitArray[nLeafs + nLeafsExtra];
103  setLeafPointersArray(rawstore, bitArray);
104  for (int l = 0; l < nLeafs + nLeafsExtra; l++) *bitArray[l] = 0;
105 
106  rawstore->m_evt = evt;
107  rawstore->m_clk = 0;
108  rawstore->m_firmid = buf[0];
109  rawstore->m_firmver = buf[1];
110  rawstore->m_coml1 = buf[2] & ((1 << 12) - 1);
111  rawstore->m_b2ldly = (buf[2] >> 12) & ((1 << 9) - 1);
112  rawstore->m_maxrvc = (buf[2] >> 21) & ((1 << 11) - 1);
113 
114  //cout<<"nClks: "<<nClks<<endl;
115  //for (int _wd = 0; _wd < nBits / 32; _wd++)
116  //{
117  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd + nword_header]);
118  // cout<<"clk["<<clk<<"] wd["<<_wd<<"] "<<buf_b<<endl;
119  //}
120 
121  for (int _wd = 0; _wd < nBits / 32; _wd++) { // 0..19
122  unsigned wd = buf[0 * (nBits / 32) + _wd + nword_header];
123  for (int bb = 0; bb < 32; bb++) { // bit by bit
124  if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
125  int bitPosition = (nBits - 1) - _wd * 32 - bb;
126  for (int leaf = 0; // Find a leaf that covers the bit.
127  leaf < nLeafs; leaf++) {
128  int bitMaxOfTheLeaf = BitMap[leaf][0];
129  int bitWidOfTheLeaf = BitMap[leaf][1];
130  int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
131  if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
132  *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
133  }
134  }
135  }
136  }
137  }
138 //----------
139  rawstore->m_N_cluster = rawstore->m_N_cluster_0 + rawstore->m_N_cluster_1;
140  evtinfo.assign(rawstore);
141  std::vector<int> index_ECL;
142  std::vector<int> clkindex_ECL;
143  for (int i = 0; i < rawstore->m_N_cluster_0; i++) {
144  index_ECL.push_back(i); clkindex_ECL.push_back(0);
145  }
146  for (int i = 0; i < rawstore->m_N_cluster_1; i++) {
147  index_ECL.push_back(i + 6); clkindex_ECL.push_back(1);
148  }
149 // for (int i = 0; i < rawstore->m_N_cluster_2; i++) {
150 // index_ECL.push_back(i+12); clkindex_ECL.push_back(2);}
151 
152  evtinfo->m_E_ECL.clear();
153  evtinfo->m_t_ECL.clear();
154  evtinfo->m_clk_ECL.clear();
155  evtinfo->m_theta_ECL.clear();
156  evtinfo->m_phi_ECL.clear();
157  evtinfo->m_1GeV_ECL.clear();
158  evtinfo->m_2GeV_ECL.clear();
159 
160  for (int i = 0; i < rawstore->m_N_cluster; i++) {
161  int index = index_ECL[i];
162  int clkindex = clkindex_ECL[i];
163  evtinfo->m_clk_ECL.push_back(clkindex);
164  evtinfo->m_E_ECL.push_back(rawstore->m_E_ECL[index]);
165  evtinfo->m_t_ECL.push_back(rawstore->m_t_ECL[index]);
166  evtinfo->m_theta_ECL.push_back(rawstore->m_theta_ECL[index]);
167  evtinfo->m_phi_ECL.push_back(rawstore->m_phi_ECL[index]);
168  evtinfo->m_E_ECL.push_back(rawstore->m_E_ECL[index]);
169  evtinfo->m_1GeV_ECL.push_back(rawstore->m_1GeV_ECL[index]);
170  evtinfo->m_2GeV_ECL.push_back(rawstore->m_2GeV_ECL[index]);
171  }
172 
173 //----------
174 
175  for (int i = 0; i < 32; i++) {
176  evtinfo->m_phi_i[i] = ((rawstore->m_phi_i_int[0] & (1u << i)) != 0);
177  evtinfo->m_phi_CDC[i] = ((rawstore->m_phi_CDC_int[0] & (1u << i)) != 0);
178  }
179  for (int i = 32; i < 36; i++) {
180  evtinfo->m_phi_i[i] = ((rawstore->m_phi_i_int[1] & (1 << (i - 32))) != 0);
181  evtinfo->m_phi_CDC[i] = ((rawstore->m_phi_CDC_int[1] & (1 << (i - 32))) != 0);
182  }
183 
184  for (int i = 0; i < 16; i++) {
185  evtinfo->m_slot_CDC[i] = ((rawstore->m_slot_CDC_int & (1 << i)) != 0);
186  evtinfo->m_slot_TOP[i] = ((rawstore->m_slot_TOP_int & (1 << i)) != 0);
187  }
188 
189  for (int i = 0; i < 8; i++) {
190  evtinfo->m_sector_CDC[i] = ((rawstore->m_sector_CDC_int & (1 << i)) != 0);
191  evtinfo->m_sector_KLM[i] = ((rawstore->m_sector_KLM_int & (1 << i)) != 0);
192  }
193 
194  for (int i = 0; i < 32; i++) {
195  evtinfo->m_map_ST[i] = ((rawstore->m_map_ST_int[0] & (1u << i)) != 0);
196  evtinfo->m_map_ST2[i] = ((rawstore->m_map_ST2_int[0] & (1u << i)) != 0);
197  evtinfo->m_map_veto[i] = ((rawstore->m_map_veto_int[0] & (1u << i)) != 0);
198  evtinfo->m_map_TSF0[i] = ((rawstore->m_map_TSF0_int[0] & (1u << i)) != 0);
199  evtinfo->m_map_TSF2[i] = ((rawstore->m_map_TSF2_int[0] & (1u << i)) != 0);
200  evtinfo->m_map_TSF4[i] = ((rawstore->m_map_TSF4_int[0] & (1u << i)) != 0);
201  evtinfo->m_map_TSF1[i] = ((rawstore->m_map_TSF1_int[0] & (1u << i)) != 0);
202  evtinfo->m_map_TSF3[i] = ((rawstore->m_map_TSF3_int[0] & (1u << i)) != 0);
203  }
204  for (int i = 32; i < 64; i++) {
205  evtinfo->m_map_ST[i] = ((rawstore->m_map_ST_int[1] & (1u << (i - 32))) != 0);
206  evtinfo->m_map_ST2[i] = ((rawstore->m_map_ST2_int[1] & (1u << (i - 32))) != 0);
207  evtinfo->m_map_veto[i] = ((rawstore->m_map_veto_int[1] & (1u << (i - 32))) != 0);
208  evtinfo->m_map_TSF0[i] = ((rawstore->m_map_TSF0_int[1] & (1u << (i - 32))) != 0);
209  evtinfo->m_map_TSF2[i] = ((rawstore->m_map_TSF2_int[1] & (1u << (i - 32))) != 0);
210  evtinfo->m_map_TSF4[i] = ((rawstore->m_map_TSF4_int[1] & (1u << (i - 32))) != 0);
211  evtinfo->m_map_TSF1[i] = ((rawstore->m_map_TSF1_int[1] & (1u << (i - 32))) != 0);
212  evtinfo->m_map_TSF3[i] = ((rawstore->m_map_TSF3_int[1] & (1u << (i - 32))) != 0);
213  }
214 
215 
216 }
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
virtual void clear()
Clear contents of this object.
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:95
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.
int m_slot_CDC_int
m_slot_CDC integer leaf
int m_phi_i_int[2]
m_phi_i integer leaf
std::vector< int > m_E_ECL
m_E_ECL leaf
int m_phi_CDC_int[2]
m_phi_CDC integer leaf
int m_map_TSF3_int[2]
m_map_TSF3 integer leaf
std::vector< int > m_t_ECL
m_t_ECL leaf
int m_map_ST_int[2]
m_map_ST integer leaf
std::vector< int > m_phi_ECL
m_phi_ECL leaf
int m_sector_KLM_int
m_sector_KLM integer leaf
int m_slot_TOP_int
m_slot_TOP integer leaf
int m_map_ST2_int[2]
m_map_ST2 integer leaf
std::vector< int > m_1GeV_ECL
m_1GeV_flag_ECL leaf
int m_sector_CDC_int
m_sector_CDC integer leaf
int m_map_TSF0_int[2]
m_map_TSF0 integer leaf
std::vector< int > m_theta_ECL
m_theta_ECL leaf
std::vector< int > m_2GeV_ECL
m_2GeV_flag_ECL leaf
int m_map_veto_int[2]
m_map_veto integer leaf
int m_N_cluster_0
m_N_cluster_0 leaf
int m_map_TSF2_int[2]
m_map_TSF2 integer leaf
int m_N_cluster_1
m_N_cluster_1 leaf
int m_map_TSF1_int[2]
m_map_TSF1 integer leaf
int m_map_TSF4_int[2]
m_map_TSF4 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.