Belle II Software development
TRGCDCETFUnpackerModule.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// $Id$
10//---------------------------------------------------------------
11// Filename : TRGCDCETFUnpackerModule.cc
12// Section :
13// Owner :
14// Email :
15//---------------------------------------------------------------
16// Description : TRGCDCETFUnpacker Module
17//---------------------------------------------------------------
18// $Log$
19//---------------------------------------------------------------
20
21#include <trg/cdc/modules/trgcdcetfUnpacker/TRGCDCETFUnpackerModule.h>
22
23using namespace std;
24using namespace Belle2;
25using namespace TRGCDCETFUNPACKERSPACE;
26
28REG_MODULE(TRGCDCETFUnpacker);
29
31{
32 return string("1.00");
33}
34
36 : Module::Module()
37{
38
39 string desc = "TRGCDCETFUnpackerModule(" + version() + ")";
40 setDescription(desc);
41 B2INFO("TRGCDCETFUnpacker: Constructor done.");
42}
43
45{
46}
47
49{
50}
51
53{
54 m_store.registerInDataStore();
55 //StoreArray<TRGCDCETFUnpackerStore>::registerPersistent();
56}
57
59{
60}
61
63{
64}
65
67{
68 StoreArray<RawTRG> raw_trgarray;
69 for (int i = 0; i < raw_trgarray.getEntries(); i++) {
70
71 // Check PCIe40 data or Copper data
72 if (raw_trgarray[i]->GetMaxNumOfCh(0) == 48) { m_pciedata = true; }
73 else if (raw_trgarray[i]->GetMaxNumOfCh(0) == 4) { m_pciedata = false; }
74 else { B2FATAL("TRGCDCETFUnpackerModule: Invalid value of GetMaxNumOfCh from raw data: " << LogVar("Number of ch: ", raw_trgarray[i]->GetMaxNumOfCh(0))); }
75
76 unsigned int node_id = 0;
77 unsigned int ch_id = 0;
78 if (m_pciedata) {
79 node_id = m_pcie40_address;
80 ch_id = m_pcie40_ch;
81 } else {
82 node_id = m_copper_address;
83 ch_id = m_copper_ab;
84 }
85
86 for (int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
87 if (raw_trgarray[i]->GetNodeID(j) == node_id) {
88 if (raw_trgarray[i]->GetDetectorNwords(j, ch_id) > 0) {
89 fillTreeTRGCDCETFUnpacker(raw_trgarray[i]->GetDetectorBuffer(j, ch_id), raw_trgarray[j]->GetEveNo(j));
90 }
91 }
92 }
93 }
94}
95
97{
98
99 const unsigned nword_header = 3;
100
101 //StoreArray<TRGCDCETFUnpackerStore> storeAry;
102 for (int clk = 0; clk < nClks; clk++) { // 0..47
103
104 m_store.appendNew();
105 int ntups = m_store.getEntries() - 1;
106 int* bitArray[nLeafs + nLeafsExtra];
107 setLeafPointersArray(m_store[ntups], bitArray);
108 for (int l = 0; l < nLeafs + nLeafsExtra; l++) *bitArray[l] = 0;
109
110 m_store[ntups]->m_evt = evt;
111 m_store[ntups]->m_clk = clk;
112 m_store[ntups]->m_firmid = buf[0];
113 m_store[ntups]->m_firmvers = buf[1];
114 //m_store[ntups]->m_etf_firmvers = buf[1];
115
116 // Print data
117 //cout<<"nClks: "<<nClks<<endl;
118 //cout<<"Up,Left is MSB, Down,Right is LSB"<<endl;
119 //for (unsigned _wd = 0; _wd < nBits / 32 + nword_header; _wd++)
120 //{
121 // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd]);
122 // stringstream wd_s;
123 // wd_s << setfill('0') << setw(2) << _wd;
124 // stringstream wd_s_d;
125 // wd_s_d << setfill('0') << setw(2) << _wd-nword_header;
126 // if (_wd < nword_header) cout<<"clk["<<clk<<"] hd["<<wd_s.str()<<"] "<<buf_b<<endl;
127 // else cout<<"clk["<<clk<<"] wd["<<wd_s_d.str()<<"] "<<buf_b<<endl;
128 //}
129
130 //cout<<"nClks: "<<nClks<<endl;
131 //for (int _wd = 0; _wd < nBits / 32; _wd++)
132 //{
133 // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd + nword_header]);
134 // cout<<"clk["<<clk<<"] wd["<<_wd<<"] "<<buf_b<<endl;
135 //}
136
137 for (unsigned _wd = 0; _wd < nBits / 32; _wd++) { // 0..19
138 unsigned wd = buf[clk * (nBits / 32) + _wd + nword_header];
139 for (int bb = 0; bb < 32; bb++) { // bit by bit
140 if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
141 int bitPosition = (nBits - 1) - _wd * 32 - bb;
142 for (int leaf = 0; // Find a leaf that covers the bit.
143 leaf < nLeafs; leaf++) {
144 int bitMaxOfTheLeaf = BitMap[leaf][0];
145 int bitWidOfTheLeaf = BitMap[leaf][1];
146 int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
147 if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
148 *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
149 }
150 }
151 }
152 }
153 }
154 }
155}
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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
virtual void initialize() override
Initilizes TRGCDCETFUnpackerUnpackerModule.
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.
virtual void fillTreeTRGCDCETFUnpacker(int *buf, int evt)
Unpacker main function.
StoreArray< TRGCDCETFUnpackerStore > m_store
Output datastore for unpacker.
std::string version() const
returns version of TRGCDCETFUnpackerModule.
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.