Belle II Software  release-05-01-25
ARICHRawUnpackerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Luka Santelj *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 // Own include
12 #include <arich/modules/arichRawUnpacker/ARICHRawUnpackerModule.h>
13 #include <arich/dataobjects/ARICHRawDigit.h>
14 
15 // framework - DataStore
16 #include <framework/datastore/StoreArray.h>
17 
18 // Dataobject classes
19 #include <rawdata/dataobjects/RawARICH.h>
20 
21 #include <sstream>
22 
23 using namespace std;
24 
25 namespace Belle2 {
31  //-----------------------------------------------------------------
32  // Register module
33  //-----------------------------------------------------------------
34 
35  REG_MODULE(ARICHRawUnpacker);
36 
37  //-----------------------------------------------------------------
38  // Implementation
39  //-----------------------------------------------------------------
40 
41  ARICHRawUnpackerModule::ARICHRawUnpackerModule() : HistoModule()
42  {
43  m_debug = false;
44  }
45 
47  {
48  }
49 
51  {
52  h_rate_a_all = new TH1F("h_rate_a_all", ";Channel ID", 144 * 6, 0, 144 * 6); //yone
53  h_rate_b_all = new TH1F("h_rate_b_all", ";Channel ID", 144 * 6, 0, 144 * 6); //yone
54  h_rate_c_all = new TH1F("h_rate_c_all", ";Channel ID", 144 * 6, 0, 144 * 6); //yone
55  h_rate_d_all = new TH1F("h_rate_d_all", ";Channel ID", 144 * 6, 0, 144 * 6); //yone
56  }
57 
59  {
60  REG_HISTOGRAM;
61  StoreArray<RawARICH> rawdata;
62  rawdata.isRequired();
64  rawdigit.registerInDataStore();
65  }
66 
68  {
69  }
70 
72  {
73  StoreArray<RawARICH> rawdata;
74  StoreArray<ARICHRawDigit> rawdigits;
75  for (auto& raw : rawdata) {
76  for (int finesse = 0; finesse < 4; finesse++) {
77  const int* buf = (const int*)raw.GetDetectorBuffer(0, finesse);
78  int bufSize = raw.GetDetectorNwords(0, finesse);
79  if (bufSize < 1) continue;
80  m_ibyte = 0;
81  // read merger header
82  int type = calbyte(buf);
83  int ver = calbyte(buf);
84  int boardid = calbyte(buf);
85  int febno = calbyte(buf);
86  unsigned int length_all = calword(buf);
87  unsigned int mrg_evtno = calword(buf);
88  ARICHRawDigit* rawdigit = rawdigits.appendNew(type, ver, boardid, febno, length_all, mrg_evtno);
89  rawdigit->setCopperId(raw.GetNodeID(0));
90  rawdigit->setHslbId(finesse);
91  int nfebs = 0;
92  while (m_ibyte < length_all) {
93  int type_feb = calbyte(buf);
94  ver = calbyte(buf);
95  boardid = calbyte(buf);
96  febno = calbyte(buf);
97  unsigned int length = calword(buf);
98  int evtno = calword(buf);
99  unsigned int ibyte = 0;
100  std::stringstream ss;
101  ss << "type=" << type_feb << ", ver=" << ver << " "
102  << ", boardid=" << boardid << ", febno=" << febno
103  << ", length=" << length << ", evtno=" << evtno << " ";
104  bool hasHit = false;
105  long long feb_trigno = 0;
106  for (int i = 0; i < 10; i++) {
107  int val = calbyte(buf);
108  ibyte++;
109  if (i < 6) {
110  feb_trigno |= (0xff & val) << (5 - i) * 8;
111  }
112  }
114  nfebs++;
115  if (type_feb == 0x02) {//Raw mode
116  int ch = 143;
117  //B2INFO("raw mode");
118  while (ibyte < length) {
119  int val = calbyte(buf);
120  if (val != 0) {
121  ibyte++;
122  ss << "ch# " << ch << "(" << val << ") ";
123  hasHit = true;
124  if (febno < 0 || febno > 6) {
125  B2ERROR("FEB is bad : " << febno << " hslb-" << finesse << ":"
126  << " type=" << type_feb << ", ver=" << ver << " "
127  << ", boardid=" << boardid << ", febno=" << febno
128  << ", length=" << length << ", evtno=" << evtno);
129  }
130  feb.push_back(ch, val);
131  }
132  ch--;
133  if (ch < 0) break;
134  }
135  } else if (type_feb == 0x01) { // Suppressed mode
136  if (length > 144 * 2 + 10) B2FATAL("error " << length);
137  //B2INFO("suppreed mode");
138  while (ibyte < length) {
139  int ch = calbyte(buf);
140  ibyte++;
141  int val = calbyte(buf);
142  ibyte++;
143  if (val != 0) {
144  ss << "ch# " << ch << "(" << val << ") ";
145  hasHit = true;
146  if (febno < 0 || febno > 6) {
147  B2ERROR("FEB is bad : " << febno << " hslb-" << finesse << ":"
148  << " type=" << type_feb << ", ver=" << ver << " "
149  << ", boardid=" << boardid << ", febno=" << febno
150  << ", length=" << length << ", evtno=" << evtno);
151  return;
152  }
153  feb.push_back(ch, val);
154  }
155  }
156  }
157  rawdigit->addFEB(feb, type, ver, boardid, febno, length, evtno, feb_trigno);
158  if (m_debug && hasHit) {
159  B2INFO(ss.str());
160  }
161  }
162  }
163  }
164  }
165 
166 
168  {
169  }
170 
172  {
173  }
174 
176 } // end Belle2 namespace
177 
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
Belle2::ARICHRawDigit
Definition: ARICHRawDigit.h:34
Belle2::ARICHRawUnpackerModule::terminate
virtual void terminate() override
Termination action.
Definition: ARICHRawUnpackerModule.cc:171
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::ARICHRawUnpackerModule::event
virtual void event() override
Event processor.
Definition: ARICHRawUnpackerModule.cc:71
Belle2::ARICHRawUnpackerModule::endRun
virtual void endRun() override
End-of-run action.
Definition: ARICHRawUnpackerModule.cc:167
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ARICHRawUnpackerModule::~ARICHRawUnpackerModule
virtual ~ARICHRawUnpackerModule()
Destructor.
Definition: ARICHRawUnpackerModule.cc:46
Belle2::ARICHRawUnpackerModule::initialize
virtual void initialize() override
Initialize the Module.
Definition: ARICHRawUnpackerModule.cc:58
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::ARICHRawDigit::FEBDigit
Definition: ARICHRawDigit.h:37
Belle2::HistoModule
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
Belle2::ARICHRawUnpackerModule::beginRun
virtual void beginRun() override
Called when entering a new run.
Definition: ARICHRawUnpackerModule.cc:67
Belle2::ARICHRawUnpackerModule::defineHisto
virtual void defineHisto() override
Function to define histograms.
Definition: ARICHRawUnpackerModule.cc:50