Belle II Software  release-08-01-10
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 
21 namespace Belle2 {
27  //-----------------------------------------------------------------
28  // Register module
29  //-----------------------------------------------------------------
30 
31  REG_MODULE(ARICHRawUnpacker);
32 
33  //-----------------------------------------------------------------
34  // Implementation
35  //-----------------------------------------------------------------
36 
38  {
39  m_debug = false;
40  }
41 
43  {
44  }
45 
47  {
48  h_rate_a_all = new TH1F("h_rate_a_all", ";Channel ID", 144 * 6, 0, 144 * 6); //yone
49  h_rate_b_all = new TH1F("h_rate_b_all", ";Channel ID", 144 * 6, 0, 144 * 6); //yone
50  h_rate_c_all = new TH1F("h_rate_c_all", ";Channel ID", 144 * 6, 0, 144 * 6); //yone
51  h_rate_d_all = new TH1F("h_rate_d_all", ";Channel ID", 144 * 6, 0, 144 * 6); //yone
52  }
53 
55  {
56  REG_HISTOGRAM;
57  StoreArray<RawARICH> rawdata;
58  rawdata.isRequired();
60  rawdigit.registerInDataStore();
61  }
62 
64  {
65  StoreArray<RawARICH> rawdata;
66  StoreArray<ARICHRawDigit> rawdigits;
67  for (auto& raw : rawdata) {
68  for (int finesse = 0; finesse < 4; finesse++) {
69  const int* buf = (const int*)raw.GetDetectorBuffer(0, finesse);
70  int bufSize = raw.GetDetectorNwords(0, finesse);
71  if (bufSize < 1) continue;
72  m_ibyte = 0;
73  // read merger header
74  int type = calbyte(buf);
75  int ver = calbyte(buf);
76  int boardid = calbyte(buf);
77  int febno = calbyte(buf);
78  unsigned int length_all = calword(buf);
79  unsigned int mrg_evtno = calword(buf);
80  ARICHRawDigit* rawdigit = rawdigits.appendNew(type, ver, boardid, febno, length_all, mrg_evtno);
81  rawdigit->setCopperId(raw.GetNodeID(0));
82  rawdigit->setHslbId(finesse);
83  while (m_ibyte < length_all) {
84  int type_feb = calbyte(buf);
85  ver = calbyte(buf);
86  boardid = calbyte(buf);
87  febno = calbyte(buf);
88  unsigned int length = calword(buf);
89  int evtno = calword(buf);
90  unsigned int ibyte = 0;
91  std::stringstream ss;
92  ss << "type=" << type_feb << ", ver=" << ver << " "
93  << ", boardid=" << boardid << ", febno=" << febno
94  << ", length=" << length << ", evtno=" << evtno << " ";
95  bool hasHit = false;
96  long long feb_trigno = 0;
97  for (int i = 0; i < 10; i++) {
98  int val = calbyte(buf);
99  ibyte++;
100  if (i > 1 && i < 6) {
101  feb_trigno |= (0xff & val) << (5 - i) * 8;
102  }
103  }
105  if (type_feb == 0x02) {//Raw mode
106  int ch = 143;
107  //B2INFO("raw mode");
108  while (ibyte < length) {
109  int val = calbyte(buf);
110  if (val != 0) {
111  ibyte++;
112  ss << "ch# " << ch << "(" << val << ") ";
113  hasHit = true;
114  if (febno < 0 || febno > 6) {
115  B2ERROR("FEB is bad:" << LogVar("FEB", std::to_string(febno) + " hslb-" + std::to_string(finesse))
116  << LogVar("type", type_feb) << LogVar("ver", ver)
117  << LogVar("boardid", boardid) << LogVar("febno", febno)
118  << LogVar("length", length) << LogVar("evtno", evtno));
119  }
120  feb.push_back(ch, val);
121  }
122  ch--;
123  if (ch < 0) break;
124  }
125  } else if (type_feb == 0x01) { // Suppressed mode
126  if (length > 144 * 2 + 10) B2FATAL("error " << length);
127  //B2INFO("suppreed mode");
128  while (ibyte < length) {
129  int ch = calbyte(buf);
130  ibyte++;
131  int val = calbyte(buf);
132  ibyte++;
133  if (val != 0) {
134  ss << "ch# " << ch << "(" << val << ") ";
135  hasHit = true;
136  if (febno < 0 || febno > 6) {
137  B2ERROR("FEB is bad:" << LogVar("FEB", std::to_string(febno) + " hslb-" + std::to_string(finesse))
138  << LogVar("type", type_feb) << LogVar("ver", ver)
139  << LogVar("boardid", boardid) << LogVar("febno", febno)
140  << LogVar("length", length) << LogVar("evtno", evtno));
141  return;
142  }
143  feb.push_back(ch, val);
144  }
145  }
146  }
147  rawdigit->addFEB(feb, type, ver, boardid, febno, length, evtno, feb_trigno);
148  if (m_debug && hasHit) {
149  B2INFO(ss.str());
150  }
151  }
152  }
153  }
154  }
155 
157 } // end Belle2 namespace
158 
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.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
REG_MODULE(arichBtest)
Register the Module.
virtual ~ARICHRawUnpackerModule()
Destructor.
virtual void defineHisto() override
Function to define histograms.
Abstract base class for different kinds of events.