Belle II Software development
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 header.
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
21namespace Belle2 {
28 // Register module
29 //-----------------------------------------------------------------
30 REG_MODULE(ARICHRawUnpacker);
31
32 //-----------------------------------------------------------------
33 // Implementation
34 //-----------------------------------------------------------------
35
37 {
38 m_debug = false;
39 }
40
42 {
43 }
44
46 {
47 h_rate_a_all = new TH1F("h_rate_a_all", ";Channel ID", 144 * 6, 0, 144 * 6); //yone
48 h_rate_b_all = new TH1F("h_rate_b_all", ";Channel ID", 144 * 6, 0, 144 * 6); //yone
49 h_rate_c_all = new TH1F("h_rate_c_all", ";Channel ID", 144 * 6, 0, 144 * 6); //yone
50 h_rate_d_all = new TH1F("h_rate_d_all", ";Channel ID", 144 * 6, 0, 144 * 6); //yone
51 }
52
54 {
55 REG_HISTOGRAM;
57 rawdata.isRequired();
59 rawdigit.registerInDataStore();
60 }
61
63 {
66 for (auto& raw : rawdata) {
67 for (int finesse = 0; finesse < 4; finesse++) {
68 const int* buf = (const int*)raw.GetDetectorBuffer(0, finesse);
69 int bufSize = raw.GetDetectorNwords(0, finesse);
70 if (bufSize < 1) continue;
71 m_ibyte = 0;
72 // read merger header
73 int type = calbyte(buf);
74 int ver = calbyte(buf);
75 int boardid = calbyte(buf);
76 int febno = calbyte(buf);
77 unsigned int length_all = calword(buf);
78 unsigned int mrg_evtno = calword(buf);
79 ARICHRawDigit* rawdigit = rawdigits.appendNew(type, ver, boardid, febno, length_all, mrg_evtno);
80 rawdigit->setCopperId(raw.GetNodeID(0));
81 rawdigit->setHslbId(finesse);
82 while (m_ibyte < length_all) {
83 int type_feb = calbyte(buf);
84 ver = calbyte(buf);
85 boardid = calbyte(buf);
86 febno = calbyte(buf);
87 unsigned int length = calword(buf);
88 int evtno = calword(buf);
89 unsigned int ibyte = 0;
90 std::stringstream ss;
91 ss << "type=" << type_feb << ", ver=" << ver << " "
92 << ", boardid=" << boardid << ", febno=" << febno
93 << ", length=" << length << ", evtno=" << evtno << " ";
94 bool hasHit = false;
95 long long feb_trigno = 0;
96 for (int i = 0; i < 10; i++) {
97 int val = calbyte(buf);
98 ibyte++;
99 if (i > 1 && i < 6) {
100 feb_trigno |= (0xff & val) << (5 - i) * 8;
101 }
102 }
104 if (type_feb == 0x02) {//Raw mode
105 int ch = 143;
106 //B2INFO("raw mode");
107 while (ibyte < length) {
108 int val = calbyte(buf);
109 if (val != 0) {
110 ibyte++;
111 ss << "ch# " << ch << "(" << val << ") ";
112 hasHit = true;
113 if (febno < 0 || febno > 6) {
114 B2ERROR("FEB is bad:" << LogVar("FEB", std::to_string(febno) + " hslb-" + std::to_string(finesse))
115 << LogVar("type", type_feb) << LogVar("ver", ver)
116 << LogVar("boardid", boardid) << LogVar("febno", febno)
117 << LogVar("length", length) << LogVar("evtno", evtno));
118 }
119 feb.push_back(ch, val);
120 }
121 ch--;
122 if (ch < 0) break;
123 }
124 } else if (type_feb == 0x01) { // Suppressed mode
125 if (length > 144 * 2 + 10) B2FATAL("error " << length);
126 //B2INFO("suppreed mode");
127 while (ibyte < length) {
128 int ch = calbyte(buf);
129 ibyte++;
130 int val = calbyte(buf);
131 ibyte++;
132 if (val != 0) {
133 ss << "ch# " << ch << "(" << val << ") ";
134 hasHit = true;
135 if (febno < 0 || febno > 6) {
136 B2ERROR("FEB is bad:" << LogVar("FEB", std::to_string(febno) + " hslb-" + std::to_string(finesse))
137 << LogVar("type", type_feb) << LogVar("ver", ver)
138 << LogVar("boardid", boardid) << LogVar("febno", febno)
139 << LogVar("length", length) << LogVar("evtno", evtno));
140 return;
141 }
142 feb.push_back(ch, val);
143 }
144 }
145 }
146 rawdigit->addFEB(feb, type, ver, boardid, febno, length, evtno, feb_trigno);
147 if (m_debug && hasHit) {
148 B2INFO(ss.str());
149 }
150 }
151 }
152 }
153 }
154
156} // end Belle2 namespace
157
Class of ARICH raw digits.
Definition: ARICHRawDigit.h:27
void setCopperId(int id)
Set COPPER ID.
void setHslbId(int id)
Set HSLB ID.
void addFEB(FEBDigit &feb, int type, int ver, int boardid, int febno, unsigned int length, unsigned int trgno, unsigned int febtrgno)
Add properties of FEB.
TH1 * h_rate_d_all
Rate histogram (unused).
TH1 * h_rate_b_all
Rate histogram (unused).
unsigned int m_ibyte
Current byte number.
TH1 * h_rate_a_all
Rate histogram (unused).
TH1 * h_rate_c_all
Rate histogram (unused).
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
Class to store variables with their name which were sent to the logging service.
unsigned int calbyte(const int *buf)
Read byte with number m_ibyte from the buffer and increase the number by 1.
virtual void initialize() override
Initialize the Module.
unsigned int calword(const int *buf)
Read word (4 bytes) from the buffer and increase the byte number m_ibyte by 4.
virtual void event() override
Event processor.
virtual ~ARICHRawUnpackerModule()
Destructor.
virtual void defineHisto() override
Definition of the 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.
Struct for front-end board.
Definition: ARICHRawDigit.h:33
void push_back(unsigned char ich, unsigned char val)
Add channel.
Definition: ARICHRawDigit.h:76