Belle II Software  release-05-01-25
TRGCDCETFUnpackerModule.cc
1 //---------------------------------------------------------------
2 // $Id$
3 //---------------------------------------------------------------
4 // Filename : TRGCDCETFUnpackerModule.cc
5 // Section :
6 // Owner :
7 // Email :
8 //---------------------------------------------------------------
9 // Description : TRGCDCETFUnpacker Module
10 //---------------------------------------------------------------
11 // $Log$
12 //---------------------------------------------------------------
13 
14 #include <trg/cdc/modules/trgcdcetfUnpacker/TRGCDCETFUnpackerModule.h>
15 
16 using namespace std;
17 using namespace Belle2;
18 using namespace TRGCDCETFUNPACKERSPACE;
19 
21 REG_MODULE(TRGCDCETFUnpacker);
22 
23 string TRGCDCETFUnpackerModule::version() const
24 {
25  return string("1.00");
26 }
27 
28 TRGCDCETFUnpackerModule::TRGCDCETFUnpackerModule()
29  : Module::Module()
30 {
31 
32  string desc = "TRGCDCETFUnpackerModule(" + version() + ")";
33  setDescription(desc);
34  B2INFO("TRGCDCETFUnpacker: Constructor done.");
35 }
36 
38 {
39 }
40 
42 {
43 }
44 
46 {
47  m_store.registerInDataStore();
48  //StoreArray<TRGCDCETFUnpackerStore>::registerPersistent();
49 }
50 
52 {
53 }
54 
56 {
57 }
58 
60 {
61  StoreArray<RawTRG> raw_trgarray;
62  for (int i = 0; i < raw_trgarray.getEntries(); i++) {
63  for (int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
64  if (raw_trgarray[i]->GetNodeID(j) == 0x15000001) {
65  if (raw_trgarray[i]->GetDetectorNwords(j, 1) > 0) {
66  fillTreeTRGCDCETFUnpacker(raw_trgarray[i]->GetDetectorBuffer(j, 1), raw_trgarray[j]->GetEveNo(j));
67  }
68  }
69  }
70  }
71 }
72 
74 {
75 
76  const unsigned nword_header = 3;
77 
78  //StoreArray<TRGCDCETFUnpackerStore> storeAry;
79  for (int clk = 0; clk < nClks; clk++) { // 0..47
80 
81  m_store.appendNew();
82  int ntups = m_store.getEntries() - 1;
83  int* bitArray[nLeafs + nLeafsExtra];
84  setLeafPointersArray(m_store[ntups], bitArray);
85  for (int l = 0; l < nLeafs + nLeafsExtra; l++) *bitArray[l] = 0;
86 
87  m_store[ntups]->m_evt = evt;
88  m_store[ntups]->m_clk = clk;
89  m_store[ntups]->m_firmid = buf[0];
90  m_store[ntups]->m_firmvers = buf[1];
91  //m_store[ntups]->m_etf_firmvers = buf[1];
92 
93  // Print data
94  //cout<<"nClks: "<<nClks<<endl;
95  //cout<<"Up,Left is MSB, Down,Right is LSB"<<endl;
96  //for (unsigned _wd = 0; _wd < nBits / 32 + nword_header; _wd++)
97  //{
98  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd]);
99  // stringstream wd_s;
100  // wd_s << setfill('0') << setw(2) << _wd;
101  // stringstream wd_s_d;
102  // wd_s_d << setfill('0') << setw(2) << _wd-nword_header;
103  // if (_wd < nword_header) cout<<"clk["<<clk<<"] hd["<<wd_s.str()<<"] "<<buf_b<<endl;
104  // else cout<<"clk["<<clk<<"] wd["<<wd_s_d.str()<<"] "<<buf_b<<endl;
105  //}
106 
107  //cout<<"nClks: "<<nClks<<endl;
108  //for (int _wd = 0; _wd < nBits / 32; _wd++)
109  //{
110  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd + nword_header]);
111  // cout<<"clk["<<clk<<"] wd["<<_wd<<"] "<<buf_b<<endl;
112  //}
113 
114  for (unsigned _wd = 0; _wd < nBits / 32; _wd++) { // 0..19
115  int wd = buf[clk * (nBits / 32) + _wd + nword_header];
116  for (int bb = 0; bb < 32; bb++) { // bit by bit
117  if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
118  int bitPosition = (nBits - 1) - _wd * 32 - bb;
119  for (int leaf = 0; // Find a leaf that covers the bit.
120  leaf < nLeafs; leaf++) {
121  int bitMaxOfTheLeaf = BitMap[leaf][0];
122  int bitWidOfTheLeaf = BitMap[leaf][1];
123  int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
124  if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
125  *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
126  }
127  }
128  }
129  }
130  }
131  }
132 }
Belle2::TRGCDCETFUNPACKERSPACE::TRGCDCETFUnpackerModule::beginRun
virtual void beginRun() override
Called when new run started.
Definition: TRGCDCETFUnpackerModule.cc:51
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::TRGCDCETFUNPACKERSPACE::TRGCDCETFUnpackerModule::event
virtual void event() override
Called event by event.
Definition: TRGCDCETFUnpackerModule.cc:59
Belle2::TRGCDCETFUNPACKERSPACE::TRGCDCETFUnpackerModule::endRun
virtual void endRun() override
Called when run ended.
Definition: TRGCDCETFUnpackerModule.cc:55
Belle2::TRGCDCETFUNPACKERSPACE::TRGCDCETFUnpackerModule::terminate
virtual void terminate() override
Called when processing ended.
Definition: TRGCDCETFUnpackerModule.cc:41
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TRGCDCETFUNPACKERSPACE::TRGCDCETFUnpackerModule::initialize
virtual void initialize() override
Initilizes TRGCDCETFUnpackerUnpackerModule.
Definition: TRGCDCETFUnpackerModule.cc:45
Belle2::TRGCDCETFUNPACKERSPACE::TRGCDCETFUnpackerModule::version
std::string version() const
returns version of TRGCDCETFUnpackerModule.
Definition: TRGCDCETFUnpackerModule.cc:23
Belle2::TRGCDCETFUNPACKERSPACE::TRGCDCETFUnpackerModule::fillTreeTRGCDCETFUnpacker
virtual void fillTreeTRGCDCETFUnpacker(int *buf, int evt)
Unpacker main function.
Definition: TRGCDCETFUnpackerModule.cc:73
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::TRGCDCETFUNPACKERSPACE::TRGCDCETFUnpackerModule::~TRGCDCETFUnpackerModule
virtual ~TRGCDCETFUnpackerModule()
Destructor.
Definition: TRGCDCETFUnpackerModule.cc:37
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226
Belle2::TRGCDCETFUNPACKERSPACE::TRGCDCETFUnpackerModule::m_store
StoreArray< TRGCDCETFUnpackerStore > m_store
Output datastore for unpacker.
Definition: TRGCDCETFUnpackerModule.h:694