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