Belle II Software  release-06-00-14
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 
23 using namespace std;
24 using namespace Belle2;
25 using namespace TRGCDCETFUNPACKERSPACE;
26 
28 REG_MODULE(TRGCDCETFUnpacker);
29 
30 string TRGCDCETFUnpackerModule::version() const
31 {
32  return string("1.00");
33 }
34 
35 TRGCDCETFUnpackerModule::TRGCDCETFUnpackerModule()
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  for (int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
71  if (raw_trgarray[i]->GetNodeID(j) == 0x15000001) {
72  if (raw_trgarray[i]->GetDetectorNwords(j, 1) > 0) {
73  fillTreeTRGCDCETFUnpacker(raw_trgarray[i]->GetDetectorBuffer(j, 1), raw_trgarray[j]->GetEveNo(j));
74  }
75  }
76  }
77  }
78 }
79 
81 {
82 
83  const unsigned nword_header = 3;
84 
85  //StoreArray<TRGCDCETFUnpackerStore> storeAry;
86  for (int clk = 0; clk < nClks; clk++) { // 0..47
87 
88  m_store.appendNew();
89  int ntups = m_store.getEntries() - 1;
90  int* bitArray[nLeafs + nLeafsExtra];
91  setLeafPointersArray(m_store[ntups], bitArray);
92  for (int l = 0; l < nLeafs + nLeafsExtra; l++) *bitArray[l] = 0;
93 
94  m_store[ntups]->m_evt = evt;
95  m_store[ntups]->m_clk = clk;
96  m_store[ntups]->m_firmid = buf[0];
97  m_store[ntups]->m_firmvers = buf[1];
98  //m_store[ntups]->m_etf_firmvers = buf[1];
99 
100  // Print data
101  //cout<<"nClks: "<<nClks<<endl;
102  //cout<<"Up,Left is MSB, Down,Right is LSB"<<endl;
103  //for (unsigned _wd = 0; _wd < nBits / 32 + nword_header; _wd++)
104  //{
105  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd]);
106  // stringstream wd_s;
107  // wd_s << setfill('0') << setw(2) << _wd;
108  // stringstream wd_s_d;
109  // wd_s_d << setfill('0') << setw(2) << _wd-nword_header;
110  // if (_wd < nword_header) cout<<"clk["<<clk<<"] hd["<<wd_s.str()<<"] "<<buf_b<<endl;
111  // else cout<<"clk["<<clk<<"] wd["<<wd_s_d.str()<<"] "<<buf_b<<endl;
112  //}
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 (unsigned _wd = 0; _wd < nBits / 32; _wd++) { // 0..19
122  unsigned wd = buf[clk * (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 }
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.
#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.