Belle II Software development
MakeDumHSLBData.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//#include <daq/rawdata/modules/DAQConsts.h>
10
11#include <rawdata/dataobjects/RawPXD.h>
12#include <rawdata/modules/MakeDumHSLBData.h>
13
14#include <fcntl.h>
15#include <sys/stat.h>
16#include <sys/types.h>
17#include <unistd.h>
18
19
20using namespace std;
21using namespace Belle2;
22
23//#define DEBUG
24
25//-----------------------------------------------------------------
26// Register the Module
27//-----------------------------------------------------------------
28REG_MODULE(MakeDumHSLBData);
29
30//-----------------------------------------------------------------
31// Implementation
32//-----------------------------------------------------------------
33
35{
36 addParam("OutputFileName", m_out_fname, "Name of an output file", string("dumhslb.dat"));
37 m_filefd = 0;
38}
39
40MakeDumHSLBDataModule::~MakeDumHSLBDataModule()
41{
42}
43
45{
46 B2INFO("MakeDumHSLBData: initialize() started.");
47
48 struct stat statbuf;
49 m_filefd = open(m_out_fname.c_str(), O_WRONLY | O_CREAT);
50 if (m_filefd < 0) {
51 printf("Error : cannot open %s: %s\n", m_out_fname.c_str(), strerror(errno));
52 exit(1);
53 }
54 if (fstat(m_filefd, &statbuf) < 0) {
55 perror("fstat");
56 exit(1);
57 }
58
59 B2INFO("MakeDumHSLBData: initialize() done.");
60
61}
62
64{
65 unsigned int eve_num = raw_copper->GetEveNo(i);
66 unsigned int cpr_id = raw_copper->GetNodeID(i);
67 for (int j = 0 ; j < 4; j++) {
68 int nwords = raw_copper->GetDetectorNwords(i, j);
69 if (nwords > 0) {
70 printf("===== Detector Buffer(FINESSE A) 0x%x words \n", raw_copper->GetDetectorNwords(i, 0));
71 int header = 0xCAFEBABE;
72 int len = write(m_filefd, &header, sizeof(int));
73 if (len != sizeof(int)) {
74 perror("write error");
75 exit(1);
76 }
77 len = write(m_filefd, &eve_num, sizeof(int));
78 if (len != sizeof(int)) {
79 perror("write error");
80 exit(1);
81 }
82 len = write(m_filefd, &cpr_id, sizeof(int));
83 if (len != sizeof(int)) {
84 perror("write error");
85 exit(1);
86 }
87 len = write(m_filefd, &nwords, sizeof(int));
88 if (len != sizeof(int)) {
89 perror("write error");
90 exit(1);
91 }
92 write(m_filefd, raw_copper->GetDetectorBuffer(i, 0), sizeof(int)*nwords);
93 printf("hdr 0x%.8x eve %10u cprid 0x%.8x nwrods %d\n", header, eve_num, cpr_id, nwords);
94 }
95 }
96}
97
99{
100
101
102 B2INFO("MakeDumHSLBData: event() started.");
103 //
104 // Data from COPPER ( data from any detectors(e.g. CDC, SVD, ... ))
105 //
106 StoreArray<RawCOPPER> rawcprarray;
107 for (int i = 0; i < rawcprarray.getEntries(); i++) {
108 for (int j = 0; j < rawcprarray[ i ]->GetNumEntries(); j++) {
109 printf("\n===== DataBlock(RawCOPPER): Block # %d ", i);
110 writeData(rawcprarray[ i ], j);
111 }
112 }
113
114 //
115 // Data from COPPER named as RawSVD by software
116 //
117 StoreArray<RawSVD> raw_svdarray;
118 for (int i = 0; i < raw_svdarray.getEntries(); i++) {
119 for (int j = 0; j < raw_svdarray[ i ]->GetNumEntries(); j++) {
120 printf("\n===== DataBlock(RawSVD) : Block # %d ", i);
121 writeData(raw_svdarray[ i ], j);
122 }
123 }
124
125 //
126 // Data from COPPER named as RawCDC by software
127 //
128 StoreArray<RawCDC> raw_cdcarray;
129 for (int i = 0; i < raw_cdcarray.getEntries(); i++) {
130 for (int j = 0; j < raw_cdcarray[ i ]->GetNumEntries(); j++) {
131 printf("\n===== DataBlock(RawCDC) : Block # %d ", i);
132 writeData(raw_cdcarray[ i ], j);
133 }
134 }
135
136 //
137 // Data from COPPER named as RawPXD by software
138 //
139 StoreArray<RawPXD> raw_pxdarray;
140 for (int i = 0; i < raw_pxdarray.getEntries(); i++) {
141 printf("\n===== DataBlock(RawPXD) : Block # %d ", i);
142 printPXDEvent(raw_pxdarray[ i ]);
143 }
144
145 StoreArray<RawTOP> raw_bpidarray;
146 for (int i = 0; i < raw_bpidarray.getEntries(); i++) {
147 for (int j = 0; j < raw_bpidarray[ i ]->GetNumEntries(); j++) {
148 printf("\n===== DataBlock(RawTOP) : Block # %d ", i);
149 writeData(raw_bpidarray[ i ], j);
150 }
151 }
152
153 StoreArray<RawARICH> raw_epidarray;
154 for (int i = 0; i < raw_epidarray.getEntries(); i++) {
155 for (int j = 0; j < raw_epidarray[ i ]->GetNumEntries(); j++) {
156 printf("\n===== DataBlock(RawARICH) : Block # %d ", i);
157 writeData(raw_epidarray[ i ], j);
158 }
159 }
160
161 StoreArray<RawKLM> raw_klmarray;
162 for (int i = 0; i < raw_klmarray.getEntries(); i++) {
163 for (int j = 0; j < raw_klmarray[ i ]->GetNumEntries(); j++) {
164 printf("\n===== DataBlock(RawKLM) : Block # %d ", i);
165 writeData(raw_klmarray[ i ], j);
166 }
167 }
168
169 StoreArray<RawECL> raw_eclarray;
170 for (int i = 0; i < raw_eclarray.getEntries(); i++) {
171 for (int j = 0; j < raw_eclarray[ i ]->GetNumEntries(); j++) {
172 printf("\n===== DataBlock(RawECL) : Block # %d ", i);
173 writeData(raw_eclarray[ i ], j);
174 }
175 }
176
177 StoreArray<RawTRG> raw_trgarray;
178 for (int i = 0; i < raw_trgarray.getEntries(); i++) {
179 for (int j = 0; j < raw_trgarray[ i ]->GetNumEntries(); j++) {
180 printf("\n===== DataBlock(RawTRG) : Block # %d ", i);
181 writeData(raw_trgarray[ i ], j);
182 }
183 }
184
185 // printf("loop %d\n", n_basf2evt);
186 n_basf2evt++;
187
188}
virtual void initialize() override
initialization
virtual void writeData(RawCOPPER *raw_copper, int i)
write data
virtual void event() override
event module
int m_filefd
File descripter.
MakeDumHSLBDataModule()
Constructor / Destructor.
std::string m_out_fname
Output file name.
Module to get data from DataStore and send it to another network node.
int n_basf2evt
No. of sent events.
virtual void printPXDEvent(RawPXD *raw_pxd)
print a PXD event
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
Definition: RawCOPPER.h:52
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
unsigned int GetEveNo(int n)
get subrun #(8bit)
Definition: RawCOPPER.h:390
int GetDetectorNwords(int n, int finesse_num)
get Detector buffer length
Definition: RawCOPPER.h:657
int * GetDetectorBuffer(int n, int finesse_num)
get Detector buffer
Definition: RawCOPPER.h:681
unsigned int GetNodeID(int n)
get node-ID from data
Definition: RawCOPPER.h:397
Abstract base class for different kinds of events.
STL namespace.